Skip to content

Commit f54e534

Browse files
committed
improved comments for the bug fixes and cleaned up the old, refactored code
1 parent c80d006 commit f54e534

File tree

2 files changed

+6
-38
lines changed

2 files changed

+6
-38
lines changed

src/extension/background.js

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -340,18 +340,9 @@ chrome.runtime.onConnect.addListener(async (port) => {
340340
});
341341
}
342342

343-
// every time devtool is closed, remove the port from portsArr
344-
// port.onDisconnect.addListener((e) => {
345-
// for (let i = 0; i < portsArr.length; i += 1) {
346-
// if (portsArr[i] === e) {
347-
// portsArr.splice(i, 1);
348-
// chrome.runtime.sendMessage({ action: 'portDisconnect', port: e.name });
349-
// break;
350-
// }
351-
// }
352-
// }); //ellie commented out
343+
// Handles port disconnection by removing the disconnected port and attempting reconnection after 1s delay
344+
// This prevents permanent connection loss during idle periods or temporary disconnects -ellie
353345
port.onDisconnect.addListener((e) => {
354-
//ellie added reconnection attempt
355346
for (let i = 0; i < portsArr.length; i += 1) {
356347
if (portsArr[i] === e) {
357348
portsArr.splice(i, 1);
@@ -448,18 +439,15 @@ chrome.runtime.onConnect.addListener(async (port) => {
448439
toggleAxRecord = !toggleAxRecord;
449440

450441
await replaceEmptySnap(tabsObj, tabId, toggleAxRecord);
451-
452442
// sends new tabs obj to devtools
453443
if (portsArr.length > 0) {
454-
console.log('Sending snapshots to frontend:', tabsObj[tabId].snapshots); //ellie
455444
portsArr.forEach((bg) =>
456445
bg.postMessage({
457446
action: 'sendSnapshots',
458447
payload: tabsObj,
459448
tabId,
460449
}),
461450
);
462-
console.log('Current tabsObj:', tabsObj); //ellie
463451
}
464452
return true; // return true so that port remains open
465453

@@ -621,16 +609,7 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
621609
break;
622610
}
623611

624-
// DUPLICATE SNAPSHOT CHECK
625-
// This may be where the bug is coming from that when Reactime fails to collect
626-
// state. If they happen to take the same actual duration, it won't record the snapshot.
627-
// const previousSnap = //ellie commented out
628-
// tabsObj[tabId]?.currLocation?.stateSnapshot?.children[0]?.componentData?.actualDuration;
629-
// const incomingSnap = request.payload.children[0].componentData.actualDuration;
630-
// if (previousSnap === incomingSnap) {
631-
// break;
632-
// }
633-
// ellie added new duplicate snapshot check
612+
// DUPLICATE SNAPSHOT CHECK -ellie
634613
const isDuplicateSnapshot = (previous, incoming) => {
635614
if (!previous || !incoming) return false;
636615
const prevData = previous?.componentData;
@@ -658,7 +637,6 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
658637
// don't add anything to snapshot storage if tab is reloaded for the initial snapshot
659638
reloaded[tabId] = false;
660639
} else {
661-
console.log('Adding new snapshot to snapshots array.'); //ellie
662640
tabsObj[tabId].snapshots.push(request.payload);
663641
// INVOKING buildHierarchy FIGURE OUT WHAT TO PASS IN
664642
if (!tabsObj[tabId][index]) {
@@ -671,12 +649,10 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
671649
addedAxSnap = 'emptyAxSnap';
672650
tabsObj[tabId].axSnapshots.push(addedAxSnap);
673651
}
674-
console.log('Updating hierarchy with new snapshot.'); //ellie
675652
sendToHierarchy(
676653
tabsObj[tabId],
677654
new HistoryNode(tabsObj[tabId], request.payload, addedAxSnap),
678655
);
679-
console.log('Updated hierarchy:', tabsObj[tabId].hierarchy); //ellie
680656
}
681657
}
682658

@@ -751,15 +727,10 @@ chrome.tabs.onActivated.addListener((info) => {
751727
if (!tab.pendingUrl?.match('^chrome-extension')) {
752728
activeTab = tab;
753729

754-
/**this setInterval is here to make sure that the app does not stop working even
755-
* if chrome pauses to save energy. There is probably a better solution, but v25 did
756-
* not have time to complete.
730+
/**this setKeepAlive is here to make sure that the app does not stop working even
731+
* if chrome pauses to save energy.
757732
*/
758-
// setInterval(() => {
759-
// console.log(activeTab);
760-
// }, 10000); //ellie commented out
761733
chrome.runtime.onStartup.addListener(() => {
762-
//ellie replaced with this
763734
chrome.runtime.setKeepAlive(true);
764735
});
765736
if (portsArr.length > 0) {

src/extension/contentScript.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,8 @@ window.addEventListener('message', (msg) => {
2626
// will send snapshots of the test app's link fiber tree.
2727
const { action }: { action: string } = msg.data;
2828
if (action === 'recordSnap') {
29-
// if (isRecording) { //ellie commented out
30-
// chrome.runtime.sendMessage(msg.data);
31-
// }
3229
if (isRecording) {
33-
// ellie added, add timestamp to payload
30+
// add timestamp to payload for the purposes of duplicate screenshot check in backgroundscript -ellie
3431
msg.data.payload.children[0].componentData.timestamp = Date.now();
3532
chrome.runtime.sendMessage(msg.data);
3633
}

0 commit comments

Comments
 (0)