@@ -244,6 +244,7 @@ chrome.runtime.onMessage.addListener((request, sender) => {
244
244
tabsObj [ tabId ] . snapshots . splice ( 1 ) ;
245
245
// gabi :: reset hierarchy to page initial state
246
246
if ( tabsObj [ tabId ] . hierarchy ) {
247
+ //test
247
248
tabsObj [ tabId ] . hierarchy . children = [ ] ;
248
249
// gabi :: reset currParent plus current state
249
250
tabsObj [ tabId ] . currParent = 1 ;
@@ -278,26 +279,6 @@ chrome.runtime.onMessage.addListener((request, sender) => {
278
279
firstSnapshotReceived [ tabId ] = true ;
279
280
reloaded [ tabId ] = false ;
280
281
281
- // if (tabsObj[tabId].snapshots[tabsObj[tabId].snapshots.length - 1]) {
282
- // let sameState = true;
283
- // const testState = (array, compare) => {
284
- // array.forEach((element, elIndex) => {
285
- // const test1 = JSON.stringify(element.state);
286
- // const test2 = JSON.stringify(compare[elIndex].state);
287
- // if (JSON.stringify(element.state) !== JSON.stringify(compare[elIndex].state)) {
288
- // sameState = false;
289
- // }
290
- // if (element.children) {
291
- // testState(element.children, compare[elIndex].children);
292
- // }
293
- // });
294
- // };
295
- // testState(tabsObj[tabId].snapshots[tabsObj[tabId].snapshots.length - 1].children, request.payload.children);
296
- // if (sameState) {
297
- // break;
298
- // }
299
- // }
300
-
301
282
tabsObj [ tabId ] . snapshots . push ( request . payload ) ;
302
283
303
284
sendToHierarchy (
@@ -362,6 +343,49 @@ chrome.tabs.onRemoved.addListener(tabId => {
362
343
delete firstSnapshotReceived [ tabId ] ;
363
344
} ) ;
364
345
346
+ // when a new url is loaded on the same tab, this remove the tabid from the tabsObj, recreate the tab and inject the script
347
+ chrome . tabs . onUpdated . addListener ( ( tabId , changeInfo ) => {
348
+
349
+ // check if the tab title changed to see if tab need to restart
350
+ if ( changeInfo && tabsObj [ tabId ] ) {
351
+ if ( changeInfo . title && changeInfo . title !== tabsObj [ tabId ] . title ) {
352
+
353
+ // tell devtools which tab to delete
354
+ if ( portsArr . length > 0 ) {
355
+ portsArr . forEach ( bg =>
356
+ bg . postMessage ( {
357
+ action : 'deleteTab' ,
358
+ payload : tabId ,
359
+ } ) ,
360
+ ) ;
361
+ }
362
+
363
+ // delete the tab from the tabsObj
364
+ delete tabsObj [ tabId ] ;
365
+ delete reloaded [ tabId ] ;
366
+ delete firstSnapshotReceived [ tabId ] ;
367
+
368
+ // recreate the tab on the tabsObj
369
+ tabsObj [ tabId ] = createTabObj ( changeInfo . title ) ;
370
+
371
+ // reinject the script to the tab
372
+ chrome . tabs . executeScript ( tabId , {
373
+ code : `
374
+ // Function will attach script to the dom
375
+ const injectScript = (file, tag) => {
376
+ const htmlBody = document.getElementsByTagName(tag)[0];
377
+ const script = document.createElement('script');
378
+ script.setAttribute('type', 'text/javascript');
379
+ script.setAttribute('src', file);
380
+ htmlBody.appendChild(script);
381
+ };
382
+ injectScript(chrome.runtime.getURL('bundles/backend.bundle.js'), 'body');
383
+ ` ,
384
+ } ) ;
385
+ }
386
+ }
387
+ } ) ;
388
+
365
389
// when tab is view change, put the tabid as the current tab
366
390
chrome . tabs . onActivated . addListener ( info => {
367
391
// tell devtools which tab to be the current
0 commit comments