Skip to content

Commit

Permalink
Detect discarded tabs to avoid bad message passing to content scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
deanoemcke committed Jul 25, 2017
1 parent 27f5926 commit 72567c4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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';
Expand Down
2 changes: 2 additions & 0 deletions src/js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down

0 comments on commit 72567c4

Please sign in to comment.