@@ -280,26 +280,6 @@ chrome.runtime.onMessage.addListener((request, sender) => {
280
280
firstSnapshotReceived [ tabId ] = true ;
281
281
reloaded [ tabId ] = false ;
282
282
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
-
303
283
tabsObj [ tabId ] . snapshots . push ( request . payload ) ;
304
284
305
285
sendToHierarchy (
@@ -364,8 +344,8 @@ chrome.tabs.onRemoved.addListener(tabId => {
364
344
delete firstSnapshotReceived [ tabId ] ;
365
345
} ) ;
366
346
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 ) => {
369
349
console . log ( 'this is tabId from background on Updates' , tabId )
370
350
console . log ( 'this is changeInfo from background on Updates' , changeInfo )
371
351
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) => {
380
360
} ) ,
381
361
) ;
382
362
}
363
+
383
364
// delete the tab from the tabsObj
384
365
delete tabsObj [ tabId ] ;
385
366
delete reloaded [ tabId ] ;
386
367
delete firstSnapshotReceived [ tabId ] ;
387
- console . log ( 'deleted tab' )
368
+
369
+ // recreate the tab on the tabsObj
388
370
tabsObj [ tabId ] = createTabObj ( changeInfo . title ) ;
371
+
372
+ // reinject the script to the tab
389
373
chrome . tabs . executeScript ( tabId , {
390
374
code : `
391
375
// Function will attach script to the dom
@@ -399,22 +383,7 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
399
383
injectScript(chrome.runtime.getURL('bundles/backend.bundle.js'), 'body');
400
384
` ,
401
385
} ) ;
402
- console . log ( 'recreate tab' )
403
386
}
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];
418
387
} ) ;
419
388
420
389
// when tab is view change, put the tabid as the current tab
0 commit comments