@@ -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 ;
@@ -46,6 +49,55 @@ const pruneAxTree = (axTree) => {
46
49
return axArr ;
47
50
} ;
48
51
52
+ function attachDebugger ( tabId , version ) {
53
+ return new Promise ( ( resolve , reject ) => {
54
+ chrome . debugger . attach ( { tabId : tabId } , version , ( ) => {
55
+ if ( chrome . runtime . lastError ) {
56
+ reject ( chrome . runtime . lastError ) ;
57
+ } else {
58
+ resolve ( ) ;
59
+ }
60
+ } ) ;
61
+ } ) ;
62
+ }
63
+
64
+ function sendDebuggerCommand ( tabId , command , params = { } ) {
65
+ return new Promise ( ( resolve , reject ) => {
66
+ chrome . debugger . sendCommand ( { tabId : tabId } , command , params , ( response ) => {
67
+ if ( chrome . runtime . lastError ) {
68
+ reject ( chrome . runtime . lastError ) ;
69
+ } else {
70
+ resolve ( response ) ;
71
+ }
72
+ } ) ;
73
+ } ) ;
74
+ }
75
+
76
+ function detachDebugger ( tabId ) {
77
+ return new Promise ( ( resolve , reject ) => {
78
+ chrome . debugger . detach ( { tabId : tabId } , ( ) => {
79
+ if ( chrome . runtime . lastError ) {
80
+ reject ( chrome . runtime . lastError ) ;
81
+ } else {
82
+ resolve ( ) ;
83
+ }
84
+ } ) ;
85
+ } ) ;
86
+ }
87
+
88
+ async function axRecord ( tabId ) {
89
+ try {
90
+ await attachDebugger ( tabId , '1.3' ) ;
91
+ await sendDebuggerCommand ( tabId , 'Accessibility.enable' ) ;
92
+ const response = await sendDebuggerCommand ( tabId , 'Accessibility.getFullAXTree' ) ;
93
+ const pruned = pruneAxTree ( response . nodes ) ;
94
+ await detachDebugger ( tabId ) ;
95
+ return pruned ;
96
+ } catch ( error ) {
97
+ console . error ( 'axRecord debugger command failed:' , error ) ;
98
+ }
99
+ }
100
+
49
101
// This function will create the first instance of the test app's tabs object
50
102
// which will hold test app's snapshots, link fiber tree info, chrome tab info, etc.
51
103
function createTabObj ( title ) {
@@ -307,6 +359,10 @@ chrome.runtime.onConnect.addListener((port) => {
307
359
chrome . tabs . sendMessage ( tabId , msg ) ;
308
360
return true ;
309
361
362
+ case 'toggleAxRecord' :
363
+ toggleAxRecord = ! toggleAxRecord ;
364
+ return true ;
365
+
310
366
case 'reinitialize' :
311
367
chrome . tabs . sendMessage ( tabId , msg ) ;
312
368
return true ;
@@ -358,6 +414,15 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
358
414
}
359
415
case 'jumpToSnap' : {
360
416
changeCurrLocation ( tabsObj [ tabId ] , tabsObj [ tabId ] . hierarchy , index , name ) ;
417
+ toggleAxRecord = true ;
418
+ if ( tabsObj [ tabId ] . currLocation . axSnapshot === 'emptyAxSnap' && toggleAxRecord === true ) {
419
+ // add new ax snapshot to currlocation
420
+ const addedAxSnap = await axRecord ( tabId ) ;
421
+ tabsObj [ tabId ] . currLocation . axSnapshot = addedAxSnap ;
422
+ // modify array to include the new recorded ax snapshot
423
+ tabsObj [ tabId ] . axSnapshots [ tabsObj [ tabId ] . currLocation . index ] = addedAxSnap ;
424
+ }
425
+
361
426
if ( portsArr . length > 0 ) {
362
427
portsArr . forEach ( ( bg ) =>
363
428
bg . postMessage ( {
@@ -368,6 +433,7 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
368
433
}
369
434
break ;
370
435
}
436
+
371
437
// Confirmed React Dev Tools installed, send this info to frontend
372
438
case 'devToolsInstalled' : {
373
439
tabsObj [ tabId ] . status . reactDevToolsInstalled = true ;
@@ -416,60 +482,7 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
416
482
'background.js: top of recordSnap: tabsObj[tabId]:' ,
417
483
JSON . parse ( JSON . stringify ( tabsObj [ tabId ] ) ) ,
418
484
) ;
419
- function addAxSnap ( snap ) {
420
- const pruned = pruneAxTree ( snap ) ;
421
- tabsObj [ tabId ] . axSnapshots . push ( pruned ) ;
422
- return pruned ;
423
- }
424
-
425
- function attachDebugger ( tabId , version ) {
426
- return new Promise ( ( resolve , reject ) => {
427
- chrome . debugger . attach ( { tabId : tabId } , version , ( ) => {
428
- if ( chrome . runtime . lastError ) {
429
- reject ( chrome . runtime . lastError ) ;
430
- } else {
431
- resolve ( ) ;
432
- }
433
- } ) ;
434
- } ) ;
435
- }
436
-
437
- function sendDebuggerCommand ( tabId , command , params = { } ) {
438
- return new Promise ( ( resolve , reject ) => {
439
- chrome . debugger . sendCommand ( { tabId : tabId } , command , params , ( response ) => {
440
- if ( chrome . runtime . lastError ) {
441
- reject ( chrome . runtime . lastError ) ;
442
- } else {
443
- resolve ( response ) ;
444
- }
445
- } ) ;
446
- } ) ;
447
- }
448
-
449
- function detachDebugger ( tabId ) {
450
- return new Promise ( ( resolve , reject ) => {
451
- chrome . debugger . detach ( { tabId : tabId } , ( ) => {
452
- if ( chrome . runtime . lastError ) {
453
- reject ( chrome . runtime . lastError ) ;
454
- } else {
455
- resolve ( ) ;
456
- }
457
- } ) ;
458
- } ) ;
459
- }
460
485
461
- async function axRecord ( tabId ) {
462
- try {
463
- await attachDebugger ( tabId , '1.3' ) ;
464
- await sendDebuggerCommand ( tabId , 'Accessibility.enable' ) ;
465
- const response = await sendDebuggerCommand ( tabId , 'Accessibility.getFullAXTree' ) ;
466
- const addedAxSnap = addAxSnap ( response . nodes ) ;
467
- await detachDebugger ( tabId ) ;
468
- return addedAxSnap ;
469
- } catch ( error ) {
470
- console . error ( 'axRecord debugger command failed:' , error ) ;
471
- }
472
- }
473
486
const sourceTab = tabId ;
474
487
tabsObj [ tabId ] . webMetrics = metrics ;
475
488
@@ -478,7 +491,16 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
478
491
reloaded [ tabId ] = false ;
479
492
tabsObj [ tabId ] . webMetrics = metrics ;
480
493
tabsObj [ tabId ] . snapshots . push ( request . payload ) ;
481
- const addedAxSnap = await axRecord ( tabId ) ;
494
+
495
+ // check if accessibility recording has been toggled on
496
+ let addedAxSnap ;
497
+ if ( toggleAxRecord === true ) {
498
+ addedAxSnap = await axRecord ( tabId ) ;
499
+ tabsObj [ tabId ] . axSnapshots . push ( addedAxSnap ) ;
500
+ } else {
501
+ addedAxSnap = 'emptyAxSnap' ;
502
+ tabsObj [ tabId ] . axSnapshots . push ( addedAxSnap ) ;
503
+ }
482
504
sendToHierarchy (
483
505
tabsObj [ tabId ] ,
484
506
new HistoryNode ( tabsObj [ tabId ] , request . payload , addedAxSnap ) ,
@@ -519,7 +541,16 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
519
541
tabsObj [ tabId ] . snapshots . push ( request . payload ) ;
520
542
// INVOKING buildHierarchy FIGURE OUT WHAT TO PASS IN
521
543
if ( ! tabsObj [ tabId ] [ index ] ) {
522
- const addedAxSnap = await axRecord ( tabId ) ;
544
+ // check if accessibility recording has been toggled on
545
+ let addedAxSnap ;
546
+ if ( toggleAxRecord === true ) {
547
+ addedAxSnap = await axRecord ( tabId ) ;
548
+ tabsObj [ tabId ] . axSnapshots . push ( addedAxSnap ) ;
549
+ } else {
550
+ addedAxSnap = 'emptyAxSnap' ;
551
+ tabsObj [ tabId ] . axSnapshots . push ( addedAxSnap ) ;
552
+ }
553
+
523
554
sendToHierarchy (
524
555
tabsObj [ tabId ] ,
525
556
new HistoryNode ( tabsObj [ tabId ] , request . payload , addedAxSnap ) ,
0 commit comments