@@ -20,10 +20,9 @@ const metrics = {};
20
20
// function pruning the chrome ax tree and pulling the relevant properties
21
21
const pruneAxTree = ( axTree ) => {
22
22
const axArr = [ ] ;
23
- let orderCounter = 0
24
-
25
- for ( const node of axTree ) {
23
+ let orderCounter = 0 ;
26
24
25
+ for ( const node of axTree ) {
27
26
let {
28
27
backendDOMNodeId,
29
28
childIds,
@@ -36,26 +35,17 @@ const pruneAxTree = (axTree) => {
36
35
role,
37
36
} = node ;
38
37
39
- // let order;
40
-
41
- if ( ! name ) {
42
- if ( ignored ) {
43
- name = { value : 'ignored node' } ;
44
- }
45
- else {
46
- name = { value : 'no name' } ;
38
+ if ( ! name ) {
39
+ if ( ignored ) {
40
+ name = { value : 'ignored node' } ;
41
+ } else {
42
+ name = { value : 'no name' } ;
47
43
}
48
44
}
49
- if ( ! name . value ) {
45
+ if ( ! name . value ) {
50
46
name . value = 'no name' ;
51
47
}
52
48
//if the node is ignored, it should be given an order number as it won't be read at all
53
- // if(ignored){
54
- // order = null;
55
- // }
56
- // else{
57
- // order = orderCounter++;
58
- // }
59
49
if ( role . type === 'role' ) {
60
50
const axNode = {
61
51
backendDOMNodeId : backendDOMNodeId ,
@@ -67,33 +57,26 @@ const pruneAxTree = (axTree) => {
67
57
ignoredReasons : ignoredReasons ,
68
58
parentId : parentId ,
69
59
properties : properties ,
70
- // order: order,
71
60
} ;
72
61
axArr . push ( axNode ) ;
73
62
}
74
63
}
75
-
64
+
76
65
// Sort nodes by backendDOMNodeId in ascending order
77
- //try with deep copy
78
- // //aria properties
79
- // console.log('axArr before : ', axArr);
80
- // axArr.sort((a, b) => b.backendDOMNodeId - a.backendDOMNodeId);
81
-
66
+
82
67
// Assign order based on sorted position
83
68
for ( const axNode of axArr ) {
84
- // console.log('current axnode order number: ', axNode.order)
85
- // console.log('this iterations node', axNode);
86
- if ( ! axNode . ignored ) { // Assuming you only want to assign order to non-ignored nodes
69
+ if ( ! axNode . ignored ) {
70
+ // Assuming you only want to assign order to non-ignored nodes
87
71
axNode . order = orderCounter ++ ;
88
72
} else {
89
73
axNode . order = null ; // Or keep it undefined, based on your requirement
90
74
}
91
- // console.log('current axnode order number: ', axNode.order)
92
75
}
93
- // console.log('axArr after: ', axArr);
94
76
return axArr ;
95
77
} ;
96
78
79
+ // attaches Chrome Debugger API to tab for running future commands
97
80
function attachDebugger ( tabId , version ) {
98
81
return new Promise ( ( resolve , reject ) => {
99
82
chrome . debugger . attach ( { tabId : tabId } , version , ( ) => {
@@ -106,6 +89,7 @@ function attachDebugger(tabId, version) {
106
89
} ) ;
107
90
}
108
91
92
+ // sends commands with Chrome Debugger API
109
93
function sendDebuggerCommand ( tabId , command , params = { } ) {
110
94
return new Promise ( ( resolve , reject ) => {
111
95
chrome . debugger . sendCommand ( { tabId : tabId } , command , params , ( response ) => {
@@ -118,6 +102,7 @@ function sendDebuggerCommand(tabId, command, params = {}) {
118
102
} ) ;
119
103
}
120
104
105
+ // detaches Chrome Debugger API from tab
121
106
function detachDebugger ( tabId ) {
122
107
return new Promise ( ( resolve , reject ) => {
123
108
chrome . debugger . detach ( { tabId : tabId } , ( ) => {
@@ -130,6 +115,7 @@ function detachDebugger(tabId) {
130
115
} ) ;
131
116
}
132
117
118
+ // returns a pruned accessibility tree obtained using the Chrome Debugger API
133
119
async function axRecord ( tabId ) {
134
120
try {
135
121
await attachDebugger ( tabId , '1.3' ) ;
@@ -143,6 +129,8 @@ async function axRecord(tabId) {
143
129
}
144
130
}
145
131
132
+ // Chrome Debugger API is unused unless accessibility features are toggled on with UI.
133
+ // This function will replace the current empty snapshot if accessibility features are toggled on and the current location's accessibility snapshot has not yet been recorded.
146
134
async function replaceEmptySnap ( tabsObj , tabId , toggleAxRecord ) {
147
135
if ( tabsObj [ tabId ] . currLocation . axSnapshot === 'emptyAxSnap' && toggleAxRecord === true ) {
148
136
// add new ax snapshot to currlocation
@@ -166,8 +154,7 @@ function createTabObj(title) {
166
154
// snapshots is an array of ALL state snapshots for stateful and stateless
167
155
// components the Reactime tab working on a specific user application
168
156
snapshots : [ ] ,
169
- // axSnapshots is an array of the chrome ax tree at different points for state and stateless applications
170
- // functionality to add snapshots is done later
157
+ // axSnapshots is an array of the chrome accessibility tree at different points for state and stateless applications
171
158
axSnapshots : [ ] ,
172
159
// index here is the tab index that shows total amount of state changes
173
160
index : 0 ,
@@ -413,7 +400,6 @@ chrome.runtime.onConnect.addListener((port) => {
413
400
414
401
case 'toggleAxRecord' :
415
402
toggleAxRecord = ! toggleAxRecord ;
416
- console . log ( 'background.js: toggleAxRecord:' , toggleAxRecord ) ;
417
403
418
404
await replaceEmptySnap ( tabsObj , tabId , toggleAxRecord ) ;
419
405
@@ -620,11 +606,7 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
620
606
) ;
621
607
}
622
608
}
623
- console . log ( 'postMessage sending snapshots from background js:' , {
624
- action : 'sendSnapshots' ,
625
- payload : tabsObj ,
626
- sourceTab,
627
- } )
609
+
628
610
// sends new tabs obj to devtools
629
611
if ( portsArr . length > 0 ) {
630
612
portsArr . forEach ( ( bg ) =>
0 commit comments