@@ -93,7 +93,8 @@ function createTabObj(title) {
93
93
// 1. param 'obj' : arg request.payload, which is an object containing a tree from snapShot.ts and a route property
94
94
// 2. param tabObj: arg tabsObj[tabId], which is an object that holds info about a specific tab. Should change the name of tabObj to tabCollection or something
95
95
class HistoryNode {
96
- constructor ( obj , tabObj ) {
96
+ constructor ( obj , tabObj , axSnap ) {
97
+ console . log ( 'background.js: HistoryNode constructor: obj:\n' , obj , '\n' , 'tabObj:' , tabObj ) ;
97
98
// continues the order of number of total state changes
98
99
this . index = tabObj . index ;
99
100
tabObj . index += 1 ;
@@ -103,7 +104,8 @@ class HistoryNode {
103
104
// marks from what branch this node is originated
104
105
this . branch = tabObj . currBranch ;
105
106
this . stateSnapshot = obj ;
106
- this . axSnapshot ;
107
+ this . axSnapshot = axSnap ;
108
+ console . log ( 'this.axSnapshot:' , this . axSnapshot ) ;
107
109
this . children = [ ] ;
108
110
}
109
111
}
@@ -128,6 +130,7 @@ function countCurrName(rootNode, name) {
128
130
// 1. param tabObj : arg tabObj[tabId]
129
131
// 2. param newNode : arg an instance of the Node class
130
132
function sendToHierarchy ( tabObj , newNode ) {
133
+ // newNode.axSnapshot = tabObj.axSnapshots[tabObj.axSnapshots.length - 1];
131
134
if ( ! tabObj . currLocation ) {
132
135
tabObj . currLocation = newNode ;
133
136
tabObj . hierarchy = newNode ;
@@ -285,9 +288,9 @@ chrome.runtime.onConnect.addListener((port) => {
285
288
return true ;
286
289
287
290
case 'jumpToSnap' :
288
- console . log ( 'background.js: tabsObj before jump:' , tabsObj ) ;
291
+ // console.log('background.js: tabsObj before jump:', tabsObj);
289
292
chrome . tabs . sendMessage ( tabId , msg ) ;
290
- console . log ( 'background.js: tabsObj after jump:' , tabsObj ) ;
293
+ // console.log('background.js: tabsObj after jump:', tabsObj);
291
294
return true ; // attempt to fix message port closing error, consider return Promise
292
295
293
296
case 'toggleRecord' :
@@ -306,7 +309,7 @@ chrome.runtime.onConnect.addListener((port) => {
306
309
307
310
// INCOMING MESSAGE FROM CONTENT SCRIPT TO BACKGROUND.JS
308
311
// background.js listening for a message from contentScript.js
309
- chrome . runtime . onMessage . addListener ( ( request , sender , sendResponse ) => {
312
+ chrome . runtime . onMessage . addListener ( async ( request , sender , sendResponse ) => {
310
313
// AUTOMATIC MESSAGE SENT BY CHROME WHEN CONTENT SCRIPT IS FIRST LOADED: set Content
311
314
if ( request . type === 'SIGN_CONNECT' ) {
312
315
return true ;
@@ -399,14 +402,93 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
399
402
break ;
400
403
}
401
404
case 'recordSnap' : {
405
+ function addAxSnap ( snap ) {
406
+ const pruned = pruneAxTree ( snap ) ;
407
+ tabsObj [ tabId ] . axSnapshots . push ( pruned ) ;
408
+ console . log ( 'addAxSnap axSnapshot:' , pruned ) ;
409
+ // return new HistoryNode();
410
+ }
411
+
412
+ function attachDebugger ( tabId , version ) {
413
+ return new Promise ( ( resolve , reject ) => {
414
+ chrome . debugger . attach ( { tabId : tabId } , version , ( ) => {
415
+ if ( chrome . runtime . lastError ) {
416
+ reject ( chrome . runtime . lastError ) ;
417
+ } else {
418
+ resolve ( ) ;
419
+ }
420
+ } ) ;
421
+ } ) ;
422
+ }
423
+
424
+ function sendDebuggerCommand ( tabId , command , params = { } ) {
425
+ return new Promise ( ( resolve , reject ) => {
426
+ chrome . debugger . sendCommand ( { tabId : tabId } , command , params , ( response ) => {
427
+ if ( chrome . runtime . lastError ) {
428
+ reject ( chrome . runtime . lastError ) ;
429
+ } else {
430
+ resolve ( response ) ;
431
+ }
432
+ } ) ;
433
+ } ) ;
434
+ }
435
+
436
+ function detachDebugger ( tabId ) {
437
+ return new Promise ( ( resolve , reject ) => {
438
+ chrome . debugger . detach ( { tabId : tabId } , ( ) => {
439
+ if ( chrome . runtime . lastError ) {
440
+ reject ( chrome . runtime . lastError ) ;
441
+ } else {
442
+ resolve ( ) ;
443
+ }
444
+ } ) ;
445
+ } ) ;
446
+ }
447
+
448
+ async function axRecord ( tabId ) {
449
+ try {
450
+ await attachDebugger ( tabId , '1.3' ) ;
451
+ await sendDebuggerCommand ( tabId , 'Accessibility.enable' ) ;
452
+ const response = await sendDebuggerCommand ( tabId , 'Accessibility.getFullAXTree' ) ;
453
+ addAxSnap ( response . nodes ) ;
454
+ await detachDebugger ( tabId ) ;
455
+ } catch ( error ) {
456
+ console . error ( 'Debugger command failed:' , error ) ;
457
+ }
458
+ }
402
459
const sourceTab = tabId ;
403
460
tabsObj [ tabId ] . webMetrics = metrics ;
461
+
462
+ // console.log('after chrome.debugger axSnap:', axSnap);
404
463
if ( ! firstSnapshotReceived [ tabId ] ) {
464
+ console . log ( '!firstSnapshotReceived[tabId]:' , true ) ;
465
+ // chrome.debugger.attach({ tabId: tabId }, '1.3', () => {
466
+ // chrome.debugger.sendCommand({ tabId: tabId }, 'Accessibility.enable', () => {
467
+ // chrome.debugger.sendCommand(
468
+ // { tabId: tabId },
469
+ // 'Accessibility.getFullAXTree',
470
+ // {},
471
+ // (response) => {
472
+ // addAxSnap(response.nodes);
473
+ // chrome.debugger.detach({ tabId: tabId });
474
+ // },
475
+ // );
476
+ // });
477
+ // });
478
+ await axRecord ( tabId ) ;
405
479
firstSnapshotReceived [ tabId ] = true ;
406
480
reloaded [ tabId ] = false ;
407
481
tabsObj [ tabId ] . webMetrics = metrics ;
408
482
tabsObj [ tabId ] . snapshots . push ( request . payload ) ;
409
- sendToHierarchy ( tabsObj [ tabId ] , new HistoryNode ( request . payload , tabsObj [ tabId ] ) ) ;
483
+ sendToHierarchy (
484
+ tabsObj [ tabId ] ,
485
+ new HistoryNode (
486
+ request . payload ,
487
+ tabsObj [ tabId ] ,
488
+ tabsObj [ tabId ] . axSnapshots [ tabsObj [ tabId ] . axSnapshots . length - 1 ] ,
489
+ ) ,
490
+ ) ;
491
+ console . log ( 'first snap tabsObj[tabId].axSnapshots' , tabsObj [ tabId ] . axSnapshots ) ;
410
492
if ( portsArr . length > 0 ) {
411
493
portsArr . forEach ( ( bg ) =>
412
494
bg . postMessage ( {
@@ -415,19 +497,7 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
415
497
} ) ,
416
498
) ;
417
499
}
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
- } ) ;
500
+
431
501
break ;
432
502
}
433
503
@@ -445,25 +515,48 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
445
515
reloaded [ tabId ] = false ;
446
516
} else {
447
517
tabsObj [ tabId ] . snapshots . push ( request . payload ) ;
518
+ // console.log('push subsequent axSnap:', axSnap);
448
519
// INVOKING buildHierarchy FIGURE OUT WHAT TO PASS IN
449
520
if ( ! tabsObj [ tabId ] [ index ] ) {
450
- sendToHierarchy ( tabsObj [ tabId ] , new HistoryNode ( request . payload , tabsObj [ tabId ] ) ) ;
521
+ console . log ( '!tabsObj[tabId][index]:' , true ) ;
522
+ // chrome.debugger.attach({ tabId: tabId }, '1.3', () => {
523
+ // chrome.debugger.sendCommand({ tabId: tabId }, 'Accessibility.enable', () => {
524
+ // chrome.debugger.sendCommand(
525
+ // { tabId: tabId },
526
+ // 'Accessibility.getFullAXTree',
527
+ // {},
528
+ // (response) => {
529
+ // addAxSnap(response.nodes);
530
+ // chrome.debugger.detach({ tabId: tabId });
531
+ // },
532
+ // );
533
+ // });
534
+ // });
535
+ await axRecord ( tabId ) ;
536
+ sendToHierarchy (
537
+ tabsObj [ tabId ] ,
538
+ new HistoryNode (
539
+ request . payload ,
540
+ tabsObj [ tabId ] ,
541
+ tabsObj [ tabId ] . axSnapshots [ tabsObj [ tabId ] . axSnapshots . length - 1 ] ,
542
+ ) ,
543
+ ) ;
451
544
}
452
545
}
453
546
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
- } ) ;
547
+ // chrome.debugger.attach({ tabId: tabId }, '1.3', () => {
548
+ // chrome.debugger.sendCommand({ tabId: tabId }, 'Accessibility.enable', () => {
549
+ // chrome.debugger.sendCommand(
550
+ // { tabId: tabId },
551
+ // 'Accessibility.getFullAXTree',
552
+ // {},
553
+ // (response) => {
554
+ // console.log(response);
555
+ // chrome.debugger.detach({ tabId: tabId });
556
+ // },
557
+ // );
558
+ // });
559
+ // });
467
560
468
561
// sends new tabs obj to devtools
469
562
if ( portsArr . length > 0 ) {
0 commit comments