@@ -93,7 +93,7 @@ function createTabObj(title) {
9393// 1. param 'obj' : arg request.payload, which is an object containing a tree from snapShot.ts and a route property
9494// 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
9595class HistoryNode {
96- constructor ( obj , tabObj ) {
96+ constructor ( tabObj , newStateSnapshot , newAxSnapshot ) {
9797 // continues the order of number of total state changes
9898 this . index = tabObj . index ;
9999 tabObj . index += 1 ;
@@ -102,8 +102,8 @@ class HistoryNode {
102102 this . name = tabObj . currParent ;
103103 // marks from what branch this node is originated
104104 this . branch = tabObj . currBranch ;
105- this . stateSnapshot = obj ;
106- this . axSnapshot = tabObj . axSnapshots [ tabObj . axSnapshots . length - 1 ] ;
105+ this . stateSnapshot = newStateSnapshot ;
106+ this . axSnapshot = newAxSnapshot ;
107107 this . children = [ ] ;
108108 }
109109}
@@ -250,9 +250,11 @@ chrome.runtime.onConnect.addListener((port) => {
250250 case 'import' : // create a snapshot property on tabId and set equal to tabs object
251251 // may need do something like filter payload from stateless
252252 tabsObj [ tabId ] . snapshots = payload . snapshots ; // reset snapshots to page last state recorded
253+ tabsObj [ tabId ] . axSnapshots = payload . axSnapshots ; // TRYING to import axsnapshots
253254 // tabsObj[tabId].hierarchy = savedSnapshot.hierarchy; // why don't we just use hierarchy? Because it breaks everything...
254255 tabsObj [ tabId ] . hierarchy . children = payload . hierarchy . children ; // resets hierarchy to last state recorded
255256 tabsObj [ tabId ] . hierarchy . stateSnapshot = payload . hierarchy . stateSnapshot ; // resets hierarchy to last state recorded
257+ tabsObj [ tabId ] . hierarchy . axSnapshot = payload . hierarchy . axSnapshot ; // TRYING to import hierarchy axsnapshot
256258 tabsObj [ tabId ] . currLocation = payload . currLocation ; // resets currLocation to last state recorded
257259 tabsObj [ tabId ] . index = payload . index ; //reset index to last state recorded
258260 tabsObj [ tabId ] . currParent = payload . currParent ; // reset currParent to last state recorded
@@ -268,10 +270,17 @@ chrome.runtime.onConnect.addListener((port) => {
268270 // resets hierarchy to page last state recorded
269271 ...tabsObj [ tabId ] . snapshots [ 0 ] ,
270272 } ;
273+ tabsObj [ tabId ] . axSnapshots =
274+ tabsObj [ tabId ] . axSnapshots [ tabsObj [ tabId ] . axSnapshots . length - 1 ] ;
275+ tabsObj [ tabId ] . hierarchy . axSnapshot = tabsObj [ tabId ] . axSnapshots [ 0 ] ; //what about other hierarchy properties? Shouldn't those be reset as well?
271276 tabsObj [ tabId ] . currLocation = tabsObj [ tabId ] . hierarchy ; // resets currLocation to page last state recorded
272277 tabsObj [ tabId ] . index = 1 ; //reset index
273278 tabsObj [ tabId ] . currParent = 0 ; // reset currParent
274279 tabsObj [ tabId ] . currBranch = 1 ; // reset currBranch
280+ console . log (
281+ 'background.js: bottom of emptySnap: tabsObj[tabId]:' ,
282+ JSON . parse ( JSON . stringify ( tabsObj [ tabId ] ) ) ,
283+ ) ;
275284 return true ; // return true so that port remains open
276285
277286 case 'setPause' : // Pause = lock on tab
@@ -405,6 +414,7 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
405414 function addAxSnap ( snap ) {
406415 const pruned = pruneAxTree ( snap ) ;
407416 tabsObj [ tabId ] . axSnapshots . push ( pruned ) ;
417+ return pruned ;
408418 }
409419
410420 function attachDebugger ( tabId , version ) {
@@ -448,8 +458,9 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
448458 await attachDebugger ( tabId , '1.3' ) ;
449459 await sendDebuggerCommand ( tabId , 'Accessibility.enable' ) ;
450460 const response = await sendDebuggerCommand ( tabId , 'Accessibility.getFullAXTree' ) ;
451- addAxSnap ( response . nodes ) ;
461+ const addedAxSnap = addAxSnap ( response . nodes ) ;
452462 await detachDebugger ( tabId ) ;
463+ return addedAxSnap ;
453464 } catch ( error ) {
454465 console . error ( 'axRecord debugger command failed:' , error ) ;
455466 }
@@ -458,12 +469,19 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
458469 tabsObj [ tabId ] . webMetrics = metrics ;
459470
460471 if ( ! firstSnapshotReceived [ tabId ] ) {
461- await axRecord ( tabId ) ;
462472 firstSnapshotReceived [ tabId ] = true ;
463473 reloaded [ tabId ] = false ;
464474 tabsObj [ tabId ] . webMetrics = metrics ;
465475 tabsObj [ tabId ] . snapshots . push ( request . payload ) ;
466- sendToHierarchy ( tabsObj [ tabId ] , new HistoryNode ( request . payload , tabsObj [ tabId ] ) ) ;
476+ const addedAxSnap = await axRecord ( tabId ) ;
477+ sendToHierarchy (
478+ tabsObj [ tabId ] ,
479+ new HistoryNode ( tabsObj [ tabId ] , request . payload , addedAxSnap ) ,
480+ ) ;
481+ console . log (
482+ 'background.js: bottom of recordSnap: tabsObj[tabId]:' ,
483+ JSON . parse ( JSON . stringify ( tabsObj [ tabId ] ) ) ,
484+ ) ;
467485 if ( portsArr . length > 0 ) {
468486 portsArr . forEach ( ( bg ) =>
469487 bg . postMessage ( {
@@ -492,8 +510,15 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
492510 tabsObj [ tabId ] . snapshots . push ( request . payload ) ;
493511 // INVOKING buildHierarchy FIGURE OUT WHAT TO PASS IN
494512 if ( ! tabsObj [ tabId ] [ index ] ) {
495- await axRecord ( tabId ) ;
496- sendToHierarchy ( tabsObj [ tabId ] , new HistoryNode ( request . payload , tabsObj [ tabId ] ) ) ;
513+ const addedAxSnap = await axRecord ( tabId ) ;
514+ sendToHierarchy (
515+ tabsObj [ tabId ] ,
516+ new HistoryNode ( tabsObj [ tabId ] , request . payload , addedAxSnap ) ,
517+ ) ;
518+ console . log (
519+ 'background.js: bottom of recordSnap: tabsObj[tabId]:' ,
520+ JSON . parse ( JSON . stringify ( tabsObj [ tabId ] ) ) ,
521+ ) ;
497522 }
498523 }
499524
0 commit comments