@@ -7,6 +7,9 @@ const portsArr = [];
7
7
const reloaded = { } ;
8
8
const firstSnapshotReceived = { } ;
9
9
10
+ // Toggle for recording accessibility snapshots
11
+ let toggleAxRecord = false ;
12
+
10
13
// There will be the same number of objects in here as there are
11
14
// Reactime tabs open for each user application being worked on.
12
15
let activeTab ;
@@ -30,15 +33,14 @@ const pruneAxTree = (axTree) => {
30
33
role
31
34
} = node ;
32
35
33
- if ( ! name ) {
34
- if ( ignored ) {
35
- name = { value : `ignored node: ${ ignoredReasons [ 0 ] . name } ` } ;
36
- }
37
- else {
38
- name = { value : 'visible node with no name' } ;
36
+ if ( ! name ) {
37
+ if ( ignored ) {
38
+ name = { value : `ignored node: ${ ignoredReasons [ 0 ] . name } ` } ;
39
+ } else {
40
+ name = { value : 'visible node with no name' } ;
39
41
}
40
42
}
41
- if ( ! name . value ) {
43
+ if ( ! name . value ) {
42
44
name . value = 'visible node with no name' ;
43
45
}
44
46
@@ -61,6 +63,73 @@ const pruneAxTree = (axTree) => {
61
63
return axArr ;
62
64
} ;
63
65
66
+ function attachDebugger ( tabId , version ) {
67
+ return new Promise ( ( resolve , reject ) => {
68
+ chrome . debugger . attach ( { tabId : tabId } , version , ( ) => {
69
+ if ( chrome . runtime . lastError ) {
70
+ reject ( chrome . runtime . lastError ) ;
71
+ } else {
72
+ resolve ( ) ;
73
+ }
74
+ } ) ;
75
+ } ) ;
76
+ }
77
+
78
+ function sendDebuggerCommand ( tabId , command , params = { } ) {
79
+ return new Promise ( ( resolve , reject ) => {
80
+ chrome . debugger . sendCommand ( { tabId : tabId } , command , params , ( response ) => {
81
+ if ( chrome . runtime . lastError ) {
82
+ reject ( chrome . runtime . lastError ) ;
83
+ } else {
84
+ resolve ( response ) ;
85
+ }
86
+ } ) ;
87
+ } ) ;
88
+ }
89
+
90
+ function detachDebugger ( tabId ) {
91
+ return new Promise ( ( resolve , reject ) => {
92
+ chrome . debugger . detach ( { tabId : tabId } , ( ) => {
93
+ if ( chrome . runtime . lastError ) {
94
+ reject ( chrome . runtime . lastError ) ;
95
+ } else {
96
+ resolve ( ) ;
97
+ }
98
+ } ) ;
99
+ } ) ;
100
+ }
101
+
102
+ async function axRecord ( tabId ) {
103
+ try {
104
+ await attachDebugger ( tabId , '1.3' ) ;
105
+ await sendDebuggerCommand ( tabId , 'Accessibility.enable' ) ;
106
+ const response = await sendDebuggerCommand ( tabId , 'Accessibility.getFullAXTree' ) ;
107
+ const pruned = pruneAxTree ( response . nodes ) ;
108
+ await detachDebugger ( tabId ) ;
109
+ return pruned ;
110
+ } catch ( error ) {
111
+ console . error ( 'axRecord debugger command failed:' , error ) ;
112
+ }
113
+ }
114
+
115
+ async function replaceEmptySnap ( tabsObj , tabId , toggleAxRecord ) {
116
+ console . log (
117
+ 'background.js: top of replaceEmptySnap: tabsObj[tabId]:' ,
118
+ JSON . parse ( JSON . stringify ( tabsObj [ tabId ] ) ) ,
119
+ ) ;
120
+ if ( tabsObj [ tabId ] . currLocation . axSnapshot === 'emptyAxSnap' && toggleAxRecord === true ) {
121
+ // add new ax snapshot to currlocation
122
+ const addedAxSnap = await axRecord ( tabId ) ;
123
+ tabsObj [ tabId ] . currLocation . axSnapshot = addedAxSnap ;
124
+ // modify array to include the new recorded ax snapshot
125
+ tabsObj [ tabId ] . axSnapshots [ tabsObj [ tabId ] . currLocation . index ] = addedAxSnap ;
126
+ }
127
+ console . log (
128
+ 'background.js: bottom of replaceEmptySnap: tabsObj[tabId]:' ,
129
+ JSON . parse ( JSON . stringify ( tabsObj [ tabId ] ) ) ,
130
+ ) ;
131
+ }
132
+
64
133
// This function will create the first instance of the test app's tabs object
65
134
// which will hold test app's snapshots, link fiber tree info, chrome tab info, etc.
66
135
function createTabObj ( title ) {
@@ -248,7 +317,7 @@ chrome.runtime.onConnect.addListener((port) => {
248
317
// INCOMING MESSAGE FROM FRONTEND (MainContainer) TO BACKGROUND.js
249
318
// listen for message containing a snapshot from devtools and send it to contentScript -
250
319
// (i.e. they're all related to the button actions on Reactime)
251
- port . onMessage . addListener ( ( msg ) => {
320
+ port . onMessage . addListener ( async ( msg ) => {
252
321
// msg is action denoting a time jump in devtools
253
322
// ---------------------------------------------------------------
254
323
// message incoming from devTools should look like this:
@@ -322,6 +391,25 @@ chrome.runtime.onConnect.addListener((port) => {
322
391
chrome . tabs . sendMessage ( tabId , msg ) ;
323
392
return true ;
324
393
394
+ case 'toggleAxRecord' :
395
+ toggleAxRecord = ! toggleAxRecord ;
396
+
397
+ await replaceEmptySnap ( tabsObj , tabId , toggleAxRecord ) ;
398
+
399
+ // sends new tabs obj to devtools
400
+ if ( portsArr . length > 0 ) {
401
+ portsArr . forEach ( ( bg ) =>
402
+ bg . postMessage ( {
403
+ action : 'sendSnapshots' ,
404
+ payload : tabsObj ,
405
+ tabId,
406
+ } ) ,
407
+ ) ;
408
+ } else {
409
+ console . log ( 'background.js: portsArr.length < 0' ) ;
410
+ }
411
+ return true ; // return true so that port remains open
412
+
325
413
case 'reinitialize' :
326
414
chrome . tabs . sendMessage ( tabId , msg ) ;
327
415
return true ;
@@ -372,7 +460,34 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
372
460
break ;
373
461
}
374
462
case 'jumpToSnap' : {
463
+ console . log (
464
+ 'background.js: top of jumpToSnap: tabsObj[tabId]:' ,
465
+ JSON . parse ( JSON . stringify ( tabsObj [ tabId ] ) ) ,
466
+ ) ;
375
467
changeCurrLocation ( tabsObj [ tabId ] , tabsObj [ tabId ] . hierarchy , index , name ) ;
468
+ // hack to test without message from mainSlice
469
+ // toggleAxRecord = true;
470
+ // record ax tree snapshot of the state that has now been jumped to if user did not toggle button on
471
+ await replaceEmptySnap ( tabsObj , tabId , toggleAxRecord ) ;
472
+
473
+ console . log (
474
+ 'background.js: bottom of jumpToSnap: tabsObj[tabId]:' ,
475
+ JSON . parse ( JSON . stringify ( tabsObj [ tabId ] ) ) ,
476
+ ) ;
477
+
478
+ // sends new tabs obj to devtools
479
+ if ( portsArr . length > 0 ) {
480
+ portsArr . forEach ( ( bg ) =>
481
+ bg . postMessage ( {
482
+ action : 'sendSnapshots' ,
483
+ payload : tabsObj ,
484
+ tabId,
485
+ } ) ,
486
+ ) ;
487
+ } else {
488
+ console . log ( 'background.js: portsArr.length < 0' ) ;
489
+ }
490
+
376
491
if ( portsArr . length > 0 ) {
377
492
portsArr . forEach ( ( bg ) =>
378
493
bg . postMessage ( {
@@ -383,6 +498,7 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
383
498
}
384
499
break ;
385
500
}
501
+
386
502
// Confirmed React Dev Tools installed, send this info to frontend
387
503
case 'devToolsInstalled' : {
388
504
tabsObj [ tabId ] . status . reactDevToolsInstalled = true ;
@@ -431,61 +547,9 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
431
547
'background.js: top of recordSnap: tabsObj[tabId]:' ,
432
548
JSON . parse ( JSON . stringify ( tabsObj [ tabId ] ) ) ,
433
549
) ;
434
- function addAxSnap ( snap ) {
435
- const pruned = pruneAxTree ( snap ) ;
436
- tabsObj [ tabId ] . axSnapshots . push ( pruned ) ;
437
- return pruned ;
438
- }
439
-
440
- function attachDebugger ( tabId , version ) {
441
- return new Promise ( ( resolve , reject ) => {
442
- chrome . debugger . attach ( { tabId : tabId } , version , ( ) => {
443
- if ( chrome . runtime . lastError ) {
444
- reject ( chrome . runtime . lastError ) ;
445
- } else {
446
- resolve ( ) ;
447
- }
448
- } ) ;
449
- } ) ;
450
- }
451
-
452
- function sendDebuggerCommand ( tabId , command , params = { } ) {
453
- return new Promise ( ( resolve , reject ) => {
454
- chrome . debugger . sendCommand ( { tabId : tabId } , command , params , ( response ) => {
455
- if ( chrome . runtime . lastError ) {
456
- reject ( chrome . runtime . lastError ) ;
457
- } else {
458
- resolve ( response ) ;
459
- }
460
- } ) ;
461
- } ) ;
462
- }
463
550
464
- function detachDebugger ( tabId ) {
465
- return new Promise ( ( resolve , reject ) => {
466
- chrome . debugger . detach ( { tabId : tabId } , ( ) => {
467
- if ( chrome . runtime . lastError ) {
468
- reject ( chrome . runtime . lastError ) ;
469
- } else {
470
- resolve ( ) ;
471
- }
472
- } ) ;
473
- } ) ;
474
- }
551
+ console . log ( 'background.js: recordSnap case: toggleAxRecord:' , toggleAxRecord ) ;
475
552
476
- async function axRecord ( tabId ) {
477
- try {
478
- await attachDebugger ( tabId , '1.3' ) ;
479
- await sendDebuggerCommand ( tabId , 'Accessibility.enable' ) ;
480
- const response = await sendDebuggerCommand ( tabId , 'Accessibility.getFullAXTree' ) ;
481
- console . log ( 'response: ' , response ) ;
482
- const addedAxSnap = addAxSnap ( response . nodes ) ;
483
- await detachDebugger ( tabId ) ;
484
- return addedAxSnap ;
485
- } catch ( error ) {
486
- console . error ( 'axRecord debugger command failed:' , error ) ;
487
- }
488
- }
489
553
const sourceTab = tabId ;
490
554
tabsObj [ tabId ] . webMetrics = metrics ;
491
555
@@ -494,7 +558,16 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
494
558
reloaded [ tabId ] = false ;
495
559
tabsObj [ tabId ] . webMetrics = metrics ;
496
560
tabsObj [ tabId ] . snapshots . push ( request . payload ) ;
497
- const addedAxSnap = await axRecord ( tabId ) ;
561
+
562
+ // check if accessibility recording has been toggled on
563
+ let addedAxSnap ;
564
+ if ( toggleAxRecord === true ) {
565
+ addedAxSnap = await axRecord ( tabId ) ;
566
+ tabsObj [ tabId ] . axSnapshots . push ( addedAxSnap ) ;
567
+ } else {
568
+ addedAxSnap = 'emptyAxSnap' ;
569
+ tabsObj [ tabId ] . axSnapshots . push ( addedAxSnap ) ;
570
+ }
498
571
sendToHierarchy (
499
572
tabsObj [ tabId ] ,
500
573
new HistoryNode ( tabsObj [ tabId ] , request . payload , addedAxSnap ) ,
@@ -535,7 +608,16 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
535
608
tabsObj [ tabId ] . snapshots . push ( request . payload ) ;
536
609
// INVOKING buildHierarchy FIGURE OUT WHAT TO PASS IN
537
610
if ( ! tabsObj [ tabId ] [ index ] ) {
538
- const addedAxSnap = await axRecord ( tabId ) ;
611
+ // check if accessibility recording has been toggled on
612
+ let addedAxSnap ;
613
+ if ( toggleAxRecord === true ) {
614
+ addedAxSnap = await axRecord ( tabId ) ;
615
+ tabsObj [ tabId ] . axSnapshots . push ( addedAxSnap ) ;
616
+ } else {
617
+ addedAxSnap = 'emptyAxSnap' ;
618
+ tabsObj [ tabId ] . axSnapshots . push ( addedAxSnap ) ;
619
+ }
620
+
539
621
sendToHierarchy (
540
622
tabsObj [ tabId ] ,
541
623
new HistoryNode ( tabsObj [ tabId ] , request . payload , addedAxSnap ) ,
0 commit comments