@@ -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 ) {
0 commit comments