@@ -18,25 +18,26 @@ const metrics = {};
18
18
const pruneAxTree = ( axTree ) => {
19
19
const axArr = [ ] ;
20
20
for ( const node of axTree ) {
21
- const {
22
- backendDOMNodeId,
23
- childIds,
24
- ignored,
25
- name,
26
- nodeId,
27
- ignoredReasons,
28
- parentId,
29
- properties } = node ;
21
+ const {
22
+ backendDOMNodeId,
23
+ childIds,
24
+ ignored,
25
+ name,
26
+ nodeId,
27
+ ignoredReasons,
28
+ parentId,
29
+ properties,
30
+ } = node ;
30
31
31
32
const axNode = {
32
- " backendDOMNodeId" : backendDOMNodeId ,
33
- " childIds" : childIds ,
34
- " ignored" : ignored ,
35
- " name" : name ,
36
- " nodeId" : nodeId ,
37
- " ignoredReasons" : ignoredReasons ,
38
- " parentId" : parentId ,
39
- " properties" : properties
33
+ backendDOMNodeId : backendDOMNodeId ,
34
+ childIds : childIds ,
35
+ ignored : ignored ,
36
+ name : name ,
37
+ nodeId : nodeId ,
38
+ ignoredReasons : ignoredReasons ,
39
+ parentId : parentId ,
40
+ properties : properties ,
40
41
} ;
41
42
42
43
axArr . push ( axNode ) ;
@@ -45,7 +46,6 @@ const pruneAxTree = (axTree) => {
45
46
return axArr ;
46
47
} ;
47
48
48
-
49
49
// This function will create the first instance of the test app's tabs object
50
50
// which will hold test app's snapshots, link fiber tree info, chrome tab info, etc.
51
51
function createTabObj ( title ) {
@@ -60,7 +60,7 @@ function createTabObj(title) {
60
60
// components the Reactime tab working on a specific user application
61
61
snapshots : [ ] ,
62
62
// axSnapshots is an array of the chrome ax tree at different points for state and stateless applications
63
- // functionality to add snapshots is done later
63
+ // functionality to add snapshots is done later
64
64
axSnapshots : [ ] ,
65
65
// index here is the tab index that shows total amount of state changes
66
66
index : 0 ,
@@ -103,6 +103,7 @@ class HistoryNode {
103
103
// marks from what branch this node is originated
104
104
this . branch = tabObj . currBranch ;
105
105
this . stateSnapshot = obj ;
106
+ this . axSnapshot = tabObj . axSnapshots [ tabObj . axSnapshots . length - 1 ] ;
106
107
this . children = [ ] ;
107
108
}
108
109
}
@@ -127,6 +128,7 @@ function countCurrName(rootNode, name) {
127
128
// 1. param tabObj : arg tabObj[tabId]
128
129
// 2. param newNode : arg an instance of the Node class
129
130
function sendToHierarchy ( tabObj , newNode ) {
131
+ // newNode.axSnapshot = tabObj.axSnapshots[tabObj.axSnapshots.length - 1];
130
132
if ( ! tabObj . currLocation ) {
131
133
tabObj . currLocation = newNode ;
132
134
tabObj . hierarchy = newNode ;
@@ -303,7 +305,7 @@ chrome.runtime.onConnect.addListener((port) => {
303
305
304
306
// INCOMING MESSAGE FROM CONTENT SCRIPT TO BACKGROUND.JS
305
307
// background.js listening for a message from contentScript.js
306
- chrome . runtime . onMessage . addListener ( ( request , sender , sendResponse ) => {
308
+ chrome . runtime . onMessage . addListener ( async ( request , sender , sendResponse ) => {
307
309
// AUTOMATIC MESSAGE SENT BY CHROME WHEN CONTENT SCRIPT IS FIRST LOADED: set Content
308
310
if ( request . type === 'SIGN_CONNECT' ) {
309
311
return true ;
@@ -324,8 +326,7 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
324
326
action === 'jumpToSnap' ||
325
327
action === 'injectScript' ||
326
328
action === 'devToolsInstalled' ||
327
- action === 'aReactApp' ||
328
- action === 'recordAXSnap'
329
+ action === 'aReactApp'
329
330
) {
330
331
isReactTimeTravel = true ;
331
332
} else {
@@ -336,22 +337,6 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
336
337
tabsObj [ tabId ] = createTabObj ( tabTitle ) ;
337
338
}
338
339
switch ( action ) {
339
- case 'recordAXSnap' : {
340
- chrome . debugger . attach ( { tabId : tabId } , '1.3' , ( ) => {
341
- chrome . debugger . sendCommand ( { tabId : tabId } , 'Accessibility.enable' , ( ) => {
342
- chrome . debugger . sendCommand (
343
- { tabId : tabId } ,
344
- 'Accessibility.getFullAXTree' ,
345
- { } ,
346
- ( response ) => {
347
- // function pruning the ax tree
348
- tabsObj [ tabId ] . axSnapshots = pruneAxTree ( response . nodes ) ;
349
- chrome . debugger . detach ( { tabId : tabId } ) ;
350
- } ,
351
- ) ;
352
- } ) ;
353
- } ) ;
354
- }
355
340
case 'attemptReconnect' : {
356
341
const success = 'portSuccessfullyConnected' ;
357
342
sendResponse ( { success } ) ;
@@ -413,9 +398,67 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
413
398
break ;
414
399
}
415
400
case 'recordSnap' : {
401
+ console . log (
402
+ 'background.js: top of recordSnap: tabsObj[tabId]:' ,
403
+ JSON . parse ( JSON . stringify ( tabsObj [ tabId ] ) ) ,
404
+ ) ;
405
+ function addAxSnap ( snap ) {
406
+ const pruned = pruneAxTree ( snap ) ;
407
+ tabsObj [ tabId ] . axSnapshots . push ( pruned ) ;
408
+ }
409
+
410
+ function attachDebugger ( tabId , version ) {
411
+ return new Promise ( ( resolve , reject ) => {
412
+ chrome . debugger . attach ( { tabId : tabId } , version , ( ) => {
413
+ if ( chrome . runtime . lastError ) {
414
+ reject ( chrome . runtime . lastError ) ;
415
+ } else {
416
+ resolve ( ) ;
417
+ }
418
+ } ) ;
419
+ } ) ;
420
+ }
421
+
422
+ function sendDebuggerCommand ( tabId , command , params = { } ) {
423
+ return new Promise ( ( resolve , reject ) => {
424
+ chrome . debugger . sendCommand ( { tabId : tabId } , command , params , ( response ) => {
425
+ if ( chrome . runtime . lastError ) {
426
+ reject ( chrome . runtime . lastError ) ;
427
+ } else {
428
+ resolve ( response ) ;
429
+ }
430
+ } ) ;
431
+ } ) ;
432
+ }
433
+
434
+ function detachDebugger ( tabId ) {
435
+ return new Promise ( ( resolve , reject ) => {
436
+ chrome . debugger . detach ( { tabId : tabId } , ( ) => {
437
+ if ( chrome . runtime . lastError ) {
438
+ reject ( chrome . runtime . lastError ) ;
439
+ } else {
440
+ resolve ( ) ;
441
+ }
442
+ } ) ;
443
+ } ) ;
444
+ }
445
+
446
+ async function axRecord ( tabId ) {
447
+ try {
448
+ await attachDebugger ( tabId , '1.3' ) ;
449
+ await sendDebuggerCommand ( tabId , 'Accessibility.enable' ) ;
450
+ const response = await sendDebuggerCommand ( tabId , 'Accessibility.getFullAXTree' ) ;
451
+ addAxSnap ( response . nodes ) ;
452
+ await detachDebugger ( tabId ) ;
453
+ } catch ( error ) {
454
+ console . error ( 'axRecord debugger command failed:' , error ) ;
455
+ }
456
+ }
416
457
const sourceTab = tabId ;
417
458
tabsObj [ tabId ] . webMetrics = metrics ;
459
+
418
460
if ( ! firstSnapshotReceived [ tabId ] ) {
461
+ await axRecord ( tabId ) ;
419
462
firstSnapshotReceived [ tabId ] = true ;
420
463
reloaded [ tabId ] = false ;
421
464
tabsObj [ tabId ] . webMetrics = metrics ;
@@ -429,6 +472,7 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
429
472
} ) ,
430
473
) ;
431
474
}
475
+
432
476
break ;
433
477
}
434
478
@@ -448,9 +492,11 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
448
492
tabsObj [ tabId ] . snapshots . push ( request . payload ) ;
449
493
// INVOKING buildHierarchy FIGURE OUT WHAT TO PASS IN
450
494
if ( ! tabsObj [ tabId ] [ index ] ) {
495
+ await axRecord ( tabId ) ;
451
496
sendToHierarchy ( tabsObj [ tabId ] , new HistoryNode ( request . payload , tabsObj [ tabId ] ) ) ;
452
497
}
453
498
}
499
+
454
500
// sends new tabs obj to devtools
455
501
if ( portsArr . length > 0 ) {
456
502
portsArr . forEach ( ( bg ) =>
0 commit comments