Skip to content

Commit 6d5165e

Browse files
committed
commented console.logs in timeJump and masterState. Toggle is functioning without frontend button
1 parent a02dee0 commit 6d5165e

File tree

3 files changed

+94
-55
lines changed

3 files changed

+94
-55
lines changed

src/backend/controllers/timeJump.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import componentActionsRecord from '../models/masterState';
22
import { Status } from '../types/backendTypes';
33
import Tree from '../models/tree';
4+
import { update } from 'lodash';
45

56
// THIS FILE CONTAINS NECCESSARY FUNCTIONALITY FOR TIME-TRAVEL FEATURE
67

@@ -48,6 +49,12 @@ async function updateReactFiberTree(
4849
targetSnapshot,
4950
circularComponentTable: Set<any> = new Set(),
5051
): Promise<void> {
52+
console.log(
53+
'updateReactFiberTree: targetSnapshot:',
54+
targetSnapshot,
55+
'circularComponentTable:',
56+
circularComponentTable,
57+
);
5158
if (!targetSnapshot) return;
5259
// Base Case: if has visited, return
5360
if (circularComponentTable.has(targetSnapshot)) {

src/backend/models/masterState.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default {
1111
* @function clear - Clears componentActionsRecord
1212
*/
1313
clear: (): void => {
14+
// console.log(componentActionsRecord);
1415
componentActionsRecord = [];
1516
},
1617

src/extension/background.js

Lines changed: 86 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ const portsArr = [];
77
const reloaded = {};
88
const firstSnapshotReceived = {};
99

10+
// Toggle for recording accessibility snapshots
11+
let toggleAxRecord = false;
12+
1013
// There will be the same number of objects in here as there are
1114
// Reactime tabs open for each user application being worked on.
1215
let activeTab;
@@ -46,6 +49,55 @@ const pruneAxTree = (axTree) => {
4649
return axArr;
4750
};
4851

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+
49101
// This function will create the first instance of the test app's tabs object
50102
// which will hold test app's snapshots, link fiber tree info, chrome tab info, etc.
51103
function createTabObj(title) {
@@ -307,6 +359,10 @@ chrome.runtime.onConnect.addListener((port) => {
307359
chrome.tabs.sendMessage(tabId, msg);
308360
return true;
309361

362+
case 'toggleAxRecord':
363+
toggleAxRecord = !toggleAxRecord;
364+
return true;
365+
310366
case 'reinitialize':
311367
chrome.tabs.sendMessage(tabId, msg);
312368
return true;
@@ -358,6 +414,15 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
358414
}
359415
case 'jumpToSnap': {
360416
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+
361426
if (portsArr.length > 0) {
362427
portsArr.forEach((bg) =>
363428
bg.postMessage({
@@ -368,6 +433,7 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
368433
}
369434
break;
370435
}
436+
371437
// Confirmed React Dev Tools installed, send this info to frontend
372438
case 'devToolsInstalled': {
373439
tabsObj[tabId].status.reactDevToolsInstalled = true;
@@ -416,60 +482,7 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
416482
'background.js: top of recordSnap: tabsObj[tabId]:',
417483
JSON.parse(JSON.stringify(tabsObj[tabId])),
418484
);
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-
}
460485

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-
}
473486
const sourceTab = tabId;
474487
tabsObj[tabId].webMetrics = metrics;
475488

@@ -478,7 +491,16 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
478491
reloaded[tabId] = false;
479492
tabsObj[tabId].webMetrics = metrics;
480493
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+
}
482504
sendToHierarchy(
483505
tabsObj[tabId],
484506
new HistoryNode(tabsObj[tabId], request.payload, addedAxSnap),
@@ -519,7 +541,16 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
519541
tabsObj[tabId].snapshots.push(request.payload);
520542
// INVOKING buildHierarchy FIGURE OUT WHAT TO PASS IN
521543
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+
523554
sendToHierarchy(
524555
tabsObj[tabId],
525556
new HistoryNode(tabsObj[tabId], request.payload, addedAxSnap),

0 commit comments

Comments
 (0)