Skip to content

Commit 5c2c92f

Browse files
committed
merging developMerge branch 'develop' into eva/axComponents
2 parents c0bd206 + 300ad6d commit 5c2c92f

File tree

3 files changed

+84
-58
lines changed

3 files changed

+84
-58
lines changed

src/backend/routers/linkFiber.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,6 @@ export default function linkFiber(mode: Status): () => Promise<void> {
100100
},
101101
'*',
102102
);
103-
window.postMessage(
104-
{
105-
action: 'recordAXSnap',
106-
payload: 'recordAXSnap',
107-
},
108-
'*',
109-
);
110103
// --------------INITIATE EVENT LISTENER FOR VISIBILITY CHANGE--------------
111104
/**
112105
* Initiate an event listener for when there is a change to the visibility of the react target application (the browser tab)
@@ -142,14 +135,6 @@ export default function linkFiber(mode: Status): () => Promise<void> {
142135
// If the target React application is visible, send a request to update the snapShot tree displayed on Chrome Extension
143136
if (isVisible) {
144137
throttledUpdateSnapshot(fiberRoot, mode);
145-
// SEND COMMAND TO FRONT END TO GET NEW AX TREE
146-
window.postMessage(
147-
{
148-
action: 'recordAXSnap',
149-
payload: 'recordAXSnap',
150-
},
151-
'*',
152-
);
153138
}
154139
// After our added work is completed we invoke the original onComitFiberRoot function
155140
return onCommitFiberRoot(...args);

src/extension/background.js

Lines changed: 84 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,26 @@ const metrics = {};
1818
const pruneAxTree = (axTree) => {
1919
const axArr = [];
2020
for (const node of axTree) {
21-
const {
22-
backendDOMNodeId,
23-
childIds,
24-
ignored,
25-
name,
26-
nodeId,
27-
ignoredReasons,
28-
parentId,
29-
properties } = node;
21+
const {
22+
backendDOMNodeId,
23+
childIds,
24+
ignored,
25+
name,
26+
nodeId,
27+
ignoredReasons,
28+
parentId,
29+
properties,
30+
} = node;
3031

3132
const axNode = {
32-
"backendDOMNodeId": backendDOMNodeId,
33-
"childIds": childIds,
34-
"ignored": ignored,
35-
"name": name,
36-
"nodeId": nodeId,
37-
"ignoredReasons": ignoredReasons,
38-
"parentId": parentId,
39-
"properties": properties
33+
backendDOMNodeId: backendDOMNodeId,
34+
childIds: childIds,
35+
ignored: ignored,
36+
name: name,
37+
nodeId: nodeId,
38+
ignoredReasons: ignoredReasons,
39+
parentId: parentId,
40+
properties: properties,
4041
};
4142

4243
axArr.push(axNode);
@@ -45,7 +46,6 @@ const pruneAxTree = (axTree) => {
4546
return axArr;
4647
};
4748

48-
4949
// This function will create the first instance of the test app's tabs object
5050
// which will hold test app's snapshots, link fiber tree info, chrome tab info, etc.
5151
function createTabObj(title) {
@@ -60,7 +60,7 @@ function createTabObj(title) {
6060
// components the Reactime tab working on a specific user application
6161
snapshots: [],
6262
// axSnapshots is an array of the chrome ax tree at different points for state and stateless applications
63-
// functionality to add snapshots is done later
63+
// functionality to add snapshots is done later
6464
axSnapshots: [],
6565
// index here is the tab index that shows total amount of state changes
6666
index: 0,
@@ -103,6 +103,7 @@ class HistoryNode {
103103
// marks from what branch this node is originated
104104
this.branch = tabObj.currBranch;
105105
this.stateSnapshot = obj;
106+
this.axSnapshot = tabObj.axSnapshots[tabObj.axSnapshots.length - 1];
106107
this.children = [];
107108
}
108109
}
@@ -127,6 +128,7 @@ function countCurrName(rootNode, name) {
127128
// 1. param tabObj : arg tabObj[tabId]
128129
// 2. param newNode : arg an instance of the Node class
129130
function sendToHierarchy(tabObj, newNode) {
131+
// newNode.axSnapshot = tabObj.axSnapshots[tabObj.axSnapshots.length - 1];
130132
if (!tabObj.currLocation) {
131133
tabObj.currLocation = newNode;
132134
tabObj.hierarchy = newNode;
@@ -303,7 +305,7 @@ chrome.runtime.onConnect.addListener((port) => {
303305

304306
// INCOMING MESSAGE FROM CONTENT SCRIPT TO BACKGROUND.JS
305307
// background.js listening for a message from contentScript.js
306-
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
308+
chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
307309
// AUTOMATIC MESSAGE SENT BY CHROME WHEN CONTENT SCRIPT IS FIRST LOADED: set Content
308310
if (request.type === 'SIGN_CONNECT') {
309311
return true;
@@ -324,8 +326,7 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
324326
action === 'jumpToSnap' ||
325327
action === 'injectScript' ||
326328
action === 'devToolsInstalled' ||
327-
action === 'aReactApp' ||
328-
action === 'recordAXSnap'
329+
action === 'aReactApp'
329330
) {
330331
isReactTimeTravel = true;
331332
} else {
@@ -336,22 +337,6 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
336337
tabsObj[tabId] = createTabObj(tabTitle);
337338
}
338339
switch (action) {
339-
case 'recordAXSnap': {
340-
chrome.debugger.attach({ tabId: tabId }, '1.3', () => {
341-
chrome.debugger.sendCommand({ tabId: tabId }, 'Accessibility.enable', () => {
342-
chrome.debugger.sendCommand(
343-
{ tabId: tabId },
344-
'Accessibility.getFullAXTree',
345-
{},
346-
(response) => {
347-
// function pruning the ax tree
348-
tabsObj[tabId].axSnapshots = pruneAxTree(response.nodes);
349-
chrome.debugger.detach({ tabId: tabId });
350-
},
351-
);
352-
});
353-
});
354-
}
355340
case 'attemptReconnect': {
356341
const success = 'portSuccessfullyConnected';
357342
sendResponse({ success });
@@ -413,9 +398,67 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
413398
break;
414399
}
415400
case 'recordSnap': {
401+
console.log(
402+
'background.js: top of recordSnap: tabsObj[tabId]:',
403+
JSON.parse(JSON.stringify(tabsObj[tabId])),
404+
);
405+
function addAxSnap(snap) {
406+
const pruned = pruneAxTree(snap);
407+
tabsObj[tabId].axSnapshots.push(pruned);
408+
}
409+
410+
function attachDebugger(tabId, version) {
411+
return new Promise((resolve, reject) => {
412+
chrome.debugger.attach({ tabId: tabId }, version, () => {
413+
if (chrome.runtime.lastError) {
414+
reject(chrome.runtime.lastError);
415+
} else {
416+
resolve();
417+
}
418+
});
419+
});
420+
}
421+
422+
function sendDebuggerCommand(tabId, command, params = {}) {
423+
return new Promise((resolve, reject) => {
424+
chrome.debugger.sendCommand({ tabId: tabId }, command, params, (response) => {
425+
if (chrome.runtime.lastError) {
426+
reject(chrome.runtime.lastError);
427+
} else {
428+
resolve(response);
429+
}
430+
});
431+
});
432+
}
433+
434+
function detachDebugger(tabId) {
435+
return new Promise((resolve, reject) => {
436+
chrome.debugger.detach({ tabId: tabId }, () => {
437+
if (chrome.runtime.lastError) {
438+
reject(chrome.runtime.lastError);
439+
} else {
440+
resolve();
441+
}
442+
});
443+
});
444+
}
445+
446+
async function axRecord(tabId) {
447+
try {
448+
await attachDebugger(tabId, '1.3');
449+
await sendDebuggerCommand(tabId, 'Accessibility.enable');
450+
const response = await sendDebuggerCommand(tabId, 'Accessibility.getFullAXTree');
451+
addAxSnap(response.nodes);
452+
await detachDebugger(tabId);
453+
} catch (error) {
454+
console.error('axRecord debugger command failed:', error);
455+
}
456+
}
416457
const sourceTab = tabId;
417458
tabsObj[tabId].webMetrics = metrics;
459+
418460
if (!firstSnapshotReceived[tabId]) {
461+
await axRecord(tabId);
419462
firstSnapshotReceived[tabId] = true;
420463
reloaded[tabId] = false;
421464
tabsObj[tabId].webMetrics = metrics;
@@ -429,6 +472,7 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
429472
}),
430473
);
431474
}
475+
432476
break;
433477
}
434478

@@ -448,9 +492,11 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
448492
tabsObj[tabId].snapshots.push(request.payload);
449493
// INVOKING buildHierarchy FIGURE OUT WHAT TO PASS IN
450494
if (!tabsObj[tabId][index]) {
495+
await axRecord(tabId);
451496
sendToHierarchy(tabsObj[tabId], new HistoryNode(request.payload, tabsObj[tabId]));
452497
}
453498
}
499+
454500
// sends new tabs obj to devtools
455501
if (portsArr.length > 0) {
456502
portsArr.forEach((bg) =>

src/extension/contentScript.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ window.addEventListener('message', (msg) => {
3636
if (action === 'aReactApp') {
3737
chrome.runtime.sendMessage(msg.data);
3838
}
39-
if (action === 'recordAXSnap') {
40-
console.log('contentScript.ts: window received recordAXSnap');
41-
// chrome.runtime.sendMessage({ action: 'recordAXSnap' });
42-
chrome.runtime.sendMessage(msg.data);
43-
}
4439
});
4540

4641
// FROM BACKGROUND TO CONTENT SCRIPT

0 commit comments

Comments
 (0)