@@ -245,6 +245,7 @@ chrome.runtime.onMessage.addListener((request, sender) => {
245245 tabsObj [ tabId ] . snapshots . splice ( 1 ) ;
246246 // gabi :: reset hierarchy to page initial state
247247 if ( tabsObj [ tabId ] . hierarchy ) {
248+ //test
248249 tabsObj [ tabId ] . hierarchy . children = [ ] ;
249250 // gabi :: reset currParent plus current state
250251 tabsObj [ tabId ] . currParent = 1 ;
@@ -363,6 +364,59 @@ chrome.tabs.onRemoved.addListener(tabId => {
363364 delete firstSnapshotReceived [ tabId ] ;
364365} ) ;
365366
367+ // when tab is reload, remove the tabid from the tabsObj
368+ chrome . tabs . onUpdated . addListener ( ( tabId , changeInfo , tab ) => {
369+ console . log ( 'this is tabId from background on Updates' , tabId )
370+ console . log ( 'this is changeInfo from background on Updates' , changeInfo )
371+ console . log ( 'this is tabsObj[tabId].title from background on Updates' , tabsObj [ tabId ] . title )
372+ if ( changeInfo . title && changeInfo . title !== tabsObj [ tabId ] . title ) {
373+ console . log ( 'need restart tab object' )
374+ // tell devtools which tab to delete
375+ if ( portsArr . length > 0 ) {
376+ portsArr . forEach ( bg =>
377+ bg . postMessage ( {
378+ action : 'deleteTab' ,
379+ payload : tabId ,
380+ } ) ,
381+ ) ;
382+ }
383+ // delete the tab from the tabsObj
384+ delete tabsObj [ tabId ] ;
385+ delete reloaded [ tabId ] ;
386+ delete firstSnapshotReceived [ tabId ] ;
387+ console . log ( 'deleted tab' )
388+ tabsObj [ tabId ] = createTabObj ( changeInfo . title ) ;
389+ chrome . tabs . executeScript ( tabId , {
390+ code : `
391+ // Function will attach script to the dom
392+ const injectScript = (file, tag) => {
393+ const htmlBody = document.getElementsByTagName(tag)[0];
394+ const script = document.createElement('script');
395+ script.setAttribute('type', 'text/javascript');
396+ script.setAttribute('src', file);
397+ htmlBody.appendChild(script);
398+ };
399+ injectScript(chrome.runtime.getURL('bundles/backend.bundle.js'), 'body');
400+ ` ,
401+ } ) ;
402+ console . log ( 'recreate tab' )
403+ }
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+ } ) ;
419+
366420// when tab is view change, put the tabid as the current tab
367421chrome . tabs . onActivated . addListener ( info => {
368422 // tell devtools which tab to be the current
0 commit comments