@@ -103,7 +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 ;
106
+ this . axSnapshot = tabObj . axSnapshots [ tabObj . axSnapshots . length - 1 ] ;
107
107
this . children = [ ] ;
108
108
}
109
109
}
@@ -128,6 +128,7 @@ function countCurrName(rootNode, name) {
128
128
// 1. param tabObj : arg tabObj[tabId]
129
129
// 2. param newNode : arg an instance of the Node class
130
130
function sendToHierarchy ( tabObj , newNode ) {
131
+ // newNode.axSnapshot = tabObj.axSnapshots[tabObj.axSnapshots.length - 1];
131
132
if ( ! tabObj . currLocation ) {
132
133
tabObj . currLocation = newNode ;
133
134
tabObj . hierarchy = newNode ;
@@ -285,9 +286,7 @@ chrome.runtime.onConnect.addListener((port) => {
285
286
return true ;
286
287
287
288
case 'jumpToSnap' :
288
- console . log ( 'background.js: tabsObj before jump:' , tabsObj ) ;
289
289
chrome . tabs . sendMessage ( tabId , msg ) ;
290
- console . log ( 'background.js: tabsObj after jump:' , tabsObj ) ;
291
290
return true ; // attempt to fix message port closing error, consider return Promise
292
291
293
292
case 'toggleRecord' :
@@ -306,7 +305,7 @@ chrome.runtime.onConnect.addListener((port) => {
306
305
307
306
// INCOMING MESSAGE FROM CONTENT SCRIPT TO BACKGROUND.JS
308
307
// background.js listening for a message from contentScript.js
309
- chrome . runtime . onMessage . addListener ( ( request , sender , sendResponse ) => {
308
+ chrome . runtime . onMessage . addListener ( async ( request , sender , sendResponse ) => {
310
309
// AUTOMATIC MESSAGE SENT BY CHROME WHEN CONTENT SCRIPT IS FIRST LOADED: set Content
311
310
if ( request . type === 'SIGN_CONNECT' ) {
312
311
return true ;
@@ -399,9 +398,67 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
399
398
break ;
400
399
}
401
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
+ }
402
457
const sourceTab = tabId ;
403
458
tabsObj [ tabId ] . webMetrics = metrics ;
459
+
404
460
if ( ! firstSnapshotReceived [ tabId ] ) {
461
+ await axRecord ( tabId ) ;
405
462
firstSnapshotReceived [ tabId ] = true ;
406
463
reloaded [ tabId ] = false ;
407
464
tabsObj [ tabId ] . webMetrics = metrics ;
@@ -415,19 +472,7 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
415
472
} ) ,
416
473
) ;
417
474
}
418
- chrome . debugger . attach ( { tabId : tabId } , '1.3' , ( ) => {
419
- chrome . debugger . sendCommand ( { tabId : tabId } , 'Accessibility.enable' , ( ) => {
420
- chrome . debugger . sendCommand (
421
- { tabId : tabId } ,
422
- 'Accessibility.getFullAXTree' ,
423
- { } ,
424
- ( response ) => {
425
- console . log ( response ) ;
426
- chrome . debugger . detach ( { tabId : tabId } ) ;
427
- } ,
428
- ) ;
429
- } ) ;
430
- } ) ;
475
+
431
476
break ;
432
477
}
433
478
@@ -447,24 +492,11 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
447
492
tabsObj [ tabId ] . snapshots . push ( request . payload ) ;
448
493
// INVOKING buildHierarchy FIGURE OUT WHAT TO PASS IN
449
494
if ( ! tabsObj [ tabId ] [ index ] ) {
495
+ await axRecord ( tabId ) ;
450
496
sendToHierarchy ( tabsObj [ tabId ] , new HistoryNode ( request . payload , tabsObj [ tabId ] ) ) ;
451
497
}
452
498
}
453
499
454
- chrome . debugger . attach ( { tabId : tabId } , '1.3' , ( ) => {
455
- chrome . debugger . sendCommand ( { tabId : tabId } , 'Accessibility.enable' , ( ) => {
456
- chrome . debugger . sendCommand (
457
- { tabId : tabId } ,
458
- 'Accessibility.getFullAXTree' ,
459
- { } ,
460
- ( response ) => {
461
- console . log ( response ) ;
462
- chrome . debugger . detach ( { tabId : tabId } ) ;
463
- } ,
464
- ) ;
465
- } ) ;
466
- } ) ;
467
-
468
500
// sends new tabs obj to devtools
469
501
if ( portsArr . length > 0 ) {
470
502
portsArr . forEach ( ( bg ) =>
0 commit comments