@@ -347,40 +347,42 @@ chrome.tabs.onRemoved.addListener(tabId => {
347
347
chrome . tabs . onUpdated . addListener ( ( tabId , changeInfo ) => {
348
348
349
349
// check if the tab title changed to see if tab need to restart
350
- if ( changeInfo . title && changeInfo . title !== tabsObj [ tabId ] . title ) {
351
-
352
- // tell devtools which tab to delete
353
- if ( portsArr . length > 0 ) {
354
- portsArr . forEach ( bg =>
355
- bg . postMessage ( {
356
- action : 'deleteTab' ,
357
- payload : tabId ,
358
- } ) ,
359
- ) ;
360
- }
350
+ if ( changeInfo && tabsObj [ tabId ] ) {
351
+ if ( changeInfo . title && changeInfo . title !== tabsObj [ tabId ] . title ) {
361
352
362
- // delete the tab from the tabsObj
363
- delete tabsObj [ tabId ] ;
364
- delete reloaded [ tabId ] ;
365
- delete firstSnapshotReceived [ tabId ] ;
366
-
367
- // recreate the tab on the tabsObj
368
- tabsObj [ tabId ] = createTabObj ( changeInfo . title ) ;
369
-
370
- // reinject the script to the tab
371
- chrome . tabs . executeScript ( tabId , {
372
- code : `
373
- // Function will attach script to the dom
374
- const injectScript = (file, tag) => {
375
- const htmlBody = document.getElementsByTagName(tag)[0];
376
- const script = document.createElement('script');
377
- script.setAttribute('type', 'text/javascript');
378
- script.setAttribute('src', file);
379
- htmlBody.appendChild(script);
380
- };
381
- injectScript(chrome.runtime.getURL('bundles/backend.bundle.js'), 'body');
382
- ` ,
383
- } ) ;
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
+ }
384
386
}
385
387
} ) ;
386
388
0 commit comments