@@ -280,26 +280,6 @@ chrome.runtime.onMessage.addListener((request, sender) => {
280280 firstSnapshotReceived [ tabId ] = true ;
281281 reloaded [ tabId ] = false ;
282282
283- // if (tabsObj[tabId].snapshots[tabsObj[tabId].snapshots.length - 1]) {
284- // let sameState = true;
285- // const testState = (array, compare) => {
286- // array.forEach((element, elIndex) => {
287- // const test1 = JSON.stringify(element.state);
288- // const test2 = JSON.stringify(compare[elIndex].state);
289- // if (JSON.stringify(element.state) !== JSON.stringify(compare[elIndex].state)) {
290- // sameState = false;
291- // }
292- // if (element.children) {
293- // testState(element.children, compare[elIndex].children);
294- // }
295- // });
296- // };
297- // testState(tabsObj[tabId].snapshots[tabsObj[tabId].snapshots.length - 1].children, request.payload.children);
298- // if (sameState) {
299- // break;
300- // }
301- // }
302-
303283 tabsObj [ tabId ] . snapshots . push ( request . payload ) ;
304284
305285 sendToHierarchy (
@@ -364,8 +344,8 @@ chrome.tabs.onRemoved.addListener(tabId => {
364344 delete firstSnapshotReceived [ tabId ] ;
365345} ) ;
366346
367- // when tab is reload, remove the tabid from the tabsObj
368- chrome . tabs . onUpdated . addListener ( ( tabId , changeInfo , tab ) => {
347+ // when a new url is loaded on the same tab, this remove the tabid from the tabsObj, recreate the tab and inject the script
348+ chrome . tabs . onUpdated . addListener ( ( tabId , changeInfo ) => {
369349 console . log ( 'this is tabId from background on Updates' , tabId )
370350 console . log ( 'this is changeInfo from background on Updates' , changeInfo )
371351 console . log ( 'this is tabsObj[tabId].title from background on Updates' , tabsObj [ tabId ] . title )
@@ -380,12 +360,16 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
380360 } ) ,
381361 ) ;
382362 }
363+
383364 // delete the tab from the tabsObj
384365 delete tabsObj [ tabId ] ;
385366 delete reloaded [ tabId ] ;
386367 delete firstSnapshotReceived [ tabId ] ;
387- console . log ( 'deleted tab' )
368+
369+ // recreate the tab on the tabsObj
388370 tabsObj [ tabId ] = createTabObj ( changeInfo . title ) ;
371+
372+ // reinject the script to the tab
389373 chrome . tabs . executeScript ( tabId , {
390374 code : `
391375 // Function will attach script to the dom
@@ -399,22 +383,7 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
399383 injectScript(chrome.runtime.getURL('bundles/backend.bundle.js'), 'body');
400384 ` ,
401385 } ) ;
402- console . log ( 'recreate tab' )
403386 }
404- // tell devtools which tab to delete
405- // if (portsArr.length > 0) {
406- // portsArr.forEach(bg =>
407- // bg.postMessage({
408- // action: 'deleteTab',
409- // payload: tabId,
410- // }),
411- // );
412- // }
413-
414- // // delete the tab from the tabsObj
415- // delete tabsObj[tabId];
416- // delete reloaded[tabId];
417- // delete firstSnapshotReceived[tabId];
418387} ) ;
419388
420389// when tab is view change, put the tabid as the current tab
0 commit comments