@@ -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 ;
@@ -57,6 +60,55 @@ const pruneAxTree = (axTree) => {
57
60
return axArr ;
58
61
} ;
59
62
63
+ function attachDebugger ( tabId , version ) {
64
+ return new Promise ( ( resolve , reject ) => {
65
+ chrome . debugger . attach ( { tabId : tabId } , version , ( ) => {
66
+ if ( chrome . runtime . lastError ) {
67
+ reject ( chrome . runtime . lastError ) ;
68
+ } else {
69
+ resolve ( ) ;
70
+ }
71
+ } ) ;
72
+ } ) ;
73
+ }
74
+
75
+ function sendDebuggerCommand ( tabId , command , params = { } ) {
76
+ return new Promise ( ( resolve , reject ) => {
77
+ chrome . debugger . sendCommand ( { tabId : tabId } , command , params , ( response ) => {
78
+ if ( chrome . runtime . lastError ) {
79
+ reject ( chrome . runtime . lastError ) ;
80
+ } else {
81
+ resolve ( response ) ;
82
+ }
83
+ } ) ;
84
+ } ) ;
85
+ }
86
+
87
+ function detachDebugger ( tabId ) {
88
+ return new Promise ( ( resolve , reject ) => {
89
+ chrome . debugger . detach ( { tabId : tabId } , ( ) => {
90
+ if ( chrome . runtime . lastError ) {
91
+ reject ( chrome . runtime . lastError ) ;
92
+ } else {
93
+ resolve ( ) ;
94
+ }
95
+ } ) ;
96
+ } ) ;
97
+ }
98
+
99
+ async function axRecord ( tabId ) {
100
+ try {
101
+ await attachDebugger ( tabId , '1.3' ) ;
102
+ await sendDebuggerCommand ( tabId , 'Accessibility.enable' ) ;
103
+ const response = await sendDebuggerCommand ( tabId , 'Accessibility.getFullAXTree' ) ;
104
+ const pruned = pruneAxTree ( response . nodes ) ;
105
+ await detachDebugger ( tabId ) ;
106
+ return pruned ;
107
+ } catch ( error ) {
108
+ console . error ( 'axRecord debugger command failed:' , error ) ;
109
+ }
110
+ }
111
+
60
112
// This function will create the first instance of the test app's tabs object
61
113
// which will hold test app's snapshots, link fiber tree info, chrome tab info, etc.
62
114
function createTabObj ( title ) {
@@ -318,6 +370,10 @@ chrome.runtime.onConnect.addListener((port) => {
318
370
chrome . tabs . sendMessage ( tabId , msg ) ;
319
371
return true ;
320
372
373
+ case 'toggleAxRecord' :
374
+ toggleAxRecord = ! toggleAxRecord ;
375
+ return true ;
376
+
321
377
case 'reinitialize' :
322
378
chrome . tabs . sendMessage ( tabId , msg ) ;
323
379
return true ;
@@ -369,6 +425,17 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
369
425
}
370
426
case 'jumpToSnap' : {
371
427
changeCurrLocation ( tabsObj [ tabId ] , tabsObj [ tabId ] . hierarchy , index , name ) ;
428
+ // hack to test without message from mainSlice
429
+ toggleAxRecord = true ;
430
+ // record ax tree snapshot of the state that has now been jumped to if user did not toggle button on
431
+ if ( tabsObj [ tabId ] . currLocation . axSnapshot === 'emptyAxSnap' && toggleAxRecord === true ) {
432
+ // add new ax snapshot to currlocation
433
+ const addedAxSnap = await axRecord ( tabId ) ;
434
+ tabsObj [ tabId ] . currLocation . axSnapshot = addedAxSnap ;
435
+ // modify array to include the new recorded ax snapshot
436
+ tabsObj [ tabId ] . axSnapshots [ tabsObj [ tabId ] . currLocation . index ] = addedAxSnap ;
437
+ }
438
+
372
439
if ( portsArr . length > 0 ) {
373
440
portsArr . forEach ( ( bg ) =>
374
441
bg . postMessage ( {
@@ -379,6 +446,7 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
379
446
}
380
447
break ;
381
448
}
449
+
382
450
// Confirmed React Dev Tools installed, send this info to frontend
383
451
case 'devToolsInstalled' : {
384
452
tabsObj [ tabId ] . status . reactDevToolsInstalled = true ;
@@ -427,60 +495,7 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
427
495
'background.js: top of recordSnap: tabsObj[tabId]:' ,
428
496
JSON . parse ( JSON . stringify ( tabsObj [ tabId ] ) ) ,
429
497
) ;
430
- function addAxSnap ( snap ) {
431
- const pruned = pruneAxTree ( snap ) ;
432
- tabsObj [ tabId ] . axSnapshots . push ( pruned ) ;
433
- return pruned ;
434
- }
435
-
436
- function attachDebugger ( tabId , version ) {
437
- return new Promise ( ( resolve , reject ) => {
438
- chrome . debugger . attach ( { tabId : tabId } , version , ( ) => {
439
- if ( chrome . runtime . lastError ) {
440
- reject ( chrome . runtime . lastError ) ;
441
- } else {
442
- resolve ( ) ;
443
- }
444
- } ) ;
445
- } ) ;
446
- }
447
-
448
- function sendDebuggerCommand ( tabId , command , params = { } ) {
449
- return new Promise ( ( resolve , reject ) => {
450
- chrome . debugger . sendCommand ( { tabId : tabId } , command , params , ( response ) => {
451
- if ( chrome . runtime . lastError ) {
452
- reject ( chrome . runtime . lastError ) ;
453
- } else {
454
- resolve ( response ) ;
455
- }
456
- } ) ;
457
- } ) ;
458
- }
459
-
460
- function detachDebugger ( tabId ) {
461
- return new Promise ( ( resolve , reject ) => {
462
- chrome . debugger . detach ( { tabId : tabId } , ( ) => {
463
- if ( chrome . runtime . lastError ) {
464
- reject ( chrome . runtime . lastError ) ;
465
- } else {
466
- resolve ( ) ;
467
- }
468
- } ) ;
469
- } ) ;
470
- }
471
498
472
- async function axRecord ( tabId ) {
473
- try {
474
- await attachDebugger ( tabId , '1.3' ) ;
475
- await sendDebuggerCommand ( tabId , 'Accessibility.enable' ) ;
476
- const response = await sendDebuggerCommand ( tabId , 'Accessibility.getFullAXTree' ) ;
477
- const addedAxSnap = addAxSnap ( response . nodes ) ;
478
- await detachDebugger ( tabId ) ;
479
- return addedAxSnap ;
480
- } catch ( error ) {
481
- console . error ( 'axRecord debugger command failed:' , error ) ;
482
- }
483
- }
484
499
const sourceTab = tabId ;
485
500
tabsObj [ tabId ] . webMetrics = metrics ;
486
501
@@ -489,7 +504,16 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
489
504
reloaded [ tabId ] = false ;
490
505
tabsObj [ tabId ] . webMetrics = metrics ;
491
506
tabsObj [ tabId ] . snapshots . push ( request . payload ) ;
492
- const addedAxSnap = await axRecord ( tabId ) ;
507
+
508
+ // check if accessibility recording has been toggled on
509
+ let addedAxSnap ;
510
+ if ( toggleAxRecord === true ) {
511
+ addedAxSnap = await axRecord ( tabId ) ;
512
+ tabsObj [ tabId ] . axSnapshots . push ( addedAxSnap ) ;
513
+ } else {
514
+ addedAxSnap = 'emptyAxSnap' ;
515
+ tabsObj [ tabId ] . axSnapshots . push ( addedAxSnap ) ;
516
+ }
493
517
sendToHierarchy (
494
518
tabsObj [ tabId ] ,
495
519
new HistoryNode ( tabsObj [ tabId ] , request . payload , addedAxSnap ) ,
@@ -530,7 +554,16 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
530
554
tabsObj [ tabId ] . snapshots . push ( request . payload ) ;
531
555
// INVOKING buildHierarchy FIGURE OUT WHAT TO PASS IN
532
556
if ( ! tabsObj [ tabId ] [ index ] ) {
533
- const addedAxSnap = await axRecord ( tabId ) ;
557
+ // check if accessibility recording has been toggled on
558
+ let addedAxSnap ;
559
+ if ( toggleAxRecord === true ) {
560
+ addedAxSnap = await axRecord ( tabId ) ;
561
+ tabsObj [ tabId ] . axSnapshots . push ( addedAxSnap ) ;
562
+ } else {
563
+ addedAxSnap = 'emptyAxSnap' ;
564
+ tabsObj [ tabId ] . axSnapshots . push ( addedAxSnap ) ;
565
+ }
566
+
534
567
sendToHierarchy (
535
568
tabsObj [ tabId ] ,
536
569
new HistoryNode ( tabsObj [ tabId ] , request . payload , addedAxSnap ) ,
0 commit comments