From 72567c471f4e0a49872e7b21934589193dafa512 Mon Sep 17 00:00:00 2001 From: deanoemcke Date: Tue, 25 Jul 2017 00:01:52 -0400 Subject: [PATCH] Detect discarded tabs to avoid bad message passing to content scripts --- src/js/background.js | 14 ++++++++++++-- src/js/popup.js | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/js/background.js b/src/js/background.js index dd9bcd86..e0c71c0d 100644 --- a/src/js/background.js +++ b/src/js/background.js @@ -69,6 +69,10 @@ var tgs = (function () { }); } + function isDiscardedTab(tab) { + return tab.discarded; + } + //tests for non-standard web pages. does not check for suspended pages! function isSpecialTab(tab) { var url = tab.url; @@ -127,7 +131,7 @@ var tgs = (function () { if (typeof(tab) === 'undefined') return; if (forceLevel >= 1) { - if (isSuspended(tab) || isSpecialTab(tab)) { + if (isSuspended(tab) || isSpecialTab(tab) || isDiscardedTab(tab)) { return; } } @@ -562,7 +566,7 @@ var tgs = (function () { var timeout = gsUtils.getOption(gsUtils.SUSPEND_TIME); tabs.forEach(function (currentTab) { - if (!isSpecialTab(currentTab) && !isSuspended(currentTab)) { + if (!isSpecialTab(currentTab) && !isSuspended(currentTab) && !isDiscardedTab(currentTab)) { var tabId = currentTab.id; chrome.tabs.executeScript(tabId, {file: 'js/contentscript.js'}, function () { @@ -669,6 +673,7 @@ var tgs = (function () { //normal: a tab that will be suspended //special: a tab that cannot be suspended //suspended: a tab that is suspended + //discarded: a tab that has been discarded //never: suspension timer set to 'never suspend' //formInput: a tab that has a partially completed form (and IGNORE_FORMS is true) //audible: a tab that is playing audio (and IGNORE_AUDIO is true) @@ -709,6 +714,11 @@ var tgs = (function () { info.status = 'special'; callback(info); + //check if tab has been discarded + } else if (isDiscardedTab(tab)) { + info.status = 'discarded'; + callback(info); + //check if it has already been suspended } else if (isSuspended(tab)) { info.status = 'suspended'; diff --git a/src/js/popup.js b/src/js/popup.js index e2b23e1a..f7ed642b 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -56,6 +56,8 @@ } else if (status === 'charging') { statusDetail = 'Connected to power source.'; statusIconClass = 'fa fa-pause'; + } else { + console.log('Could not process tab status of: ' + status); } if (document.getElementsByTagName('a')[0]) {