diff --git a/platform/chromium/vapi-background-ext.js b/platform/chromium/vapi-background-ext.js index d860f1669..b5771a711 100644 --- a/platform/chromium/vapi-background-ext.js +++ b/platform/chromium/vapi-background-ext.js @@ -105,11 +105,6 @@ vAPI.Tabs = class extends vAPI.Tabs { // Extend base class to normalize as per platform. vAPI.Net = class extends vAPI.Net { - constructor() { - super(); - this.suspendedTabIds = new Set(); - } - normalizeDetails(details) { // Chromium 63+ supports the `initiator` property, which contains // the URL of the origin from which the network request was made. @@ -184,20 +179,21 @@ vAPI.Tabs = class extends vAPI.Tabs { // https://github.com/uBlockOrigin/uBlock-issues/issues/2063 // Do not interfere with root document suspendOneRequest(details) { - this.suspendedTabIds.add(details.tabId); + this.onBeforeSuspendableRequest(details); if ( details.type === 'main_frame' ) { return; } - return { - redirectUrl: vAPI.getURL(`web_accessible_resources/empty?secret=${vAPI.warSecret()}`) - }; + return { cancel: true }; } unsuspendAllRequests(discard = false) { - if ( discard !== true ) { - for ( const tabId of this.suspendedTabIds ) { - vAPI.tabs.reload(tabId); - } + if ( discard === true ) { return; } + const toReload = []; + for ( const tabId of this.unprocessedTabs.keys() ) { + toReload.push(tabId); + } + this.removeUnprocessedRequest(); + for ( const tabId of toReload ) { + vAPI.tabs.reload(tabId); } - this.suspendedTabIds.clear(); } }; } diff --git a/platform/common/vapi-background.js b/platform/common/vapi-background.js index 24196d572..ca905fe5f 100644 --- a/platform/common/vapi-background.js +++ b/platform/common/vapi-background.js @@ -1252,6 +1252,7 @@ vAPI.Net = class { this.listenerMap = new WeakMap(); this.suspendDepth = 0; this.unprocessedTabs = new Map(); + this.lastUnprocessedRequestTime = Number.MAX_SAFE_INTEGER; browser.webRequest.onBeforeRequest.addListener( details => { @@ -1316,7 +1317,7 @@ vAPI.Net = class { let i = requests.length; while ( i-- ) { const r = listener(requests[i]); - if ( r === undefined || r.cancel === false ) { + if ( r === undefined || r.cancel !== true ) { requests.splice(i, 1); } } @@ -1366,18 +1367,26 @@ vAPI.Net = class { this.unprocessedTabs.set(tabId, (requests = [])); } requests.push(Object.assign({}, details)); + this.lastUnprocessedRequestTime = Date.now(); } hasUnprocessedRequest(tabId) { + if ( (Date.now() - this.lastUnprocessedRequestTime) > 60000 ) { + this.removeUnprocessedRequest(); + } return this.unprocessedTabs.size !== 0 && this.unprocessedTabs.has(tabId); } - // https://github.com/uBlockOrigin/uBlock-issues/issues/2589 - // - Aggressively clear the unprocessed-request status of all tabs as - // soon as there is a call to clear for one tab. - removeUnprocessedRequest() { - if ( this.unprocessedTabs.size === 0 ) { return true; } - this.unprocessedTabs.clear(); - if ( this.deferredSuspendableListener === undefined ) { return true; } + removeUnprocessedRequest(tabId) { + if ( this.deferredSuspendableListener === undefined ) { + this.unprocessedTabs.clear(); + return true; + } + if ( tabId !== undefined ) { + this.unprocessedTabs.delete(tabId); + } else { + this.unprocessedTabs.clear(); + } + if ( this.unprocessedTabs.size !== 0 ) { return false; } this.suspendableListener = this.deferredSuspendableListener; this.deferredSuspendableListener = undefined; return true;