From 0b0915526817ce1b0dd2a32cfeaff3f1b647b737 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Thu, 30 Mar 2023 17:12:45 -0400 Subject: [PATCH] Clear unprocessed requests status on webNavigation reload event Related feedback: - https://github.com/uBlockOrigin/uBlock-issues/discussions/2564 --- platform/common/vapi-background.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/platform/common/vapi-background.js b/platform/common/vapi-background.js index aa60cda58..00912e8db 100644 --- a/platform/common/vapi-background.js +++ b/platform/common/vapi-background.js @@ -211,6 +211,12 @@ vAPI.Tabs = class { this.onCreatedNavigationTargetHandler(details); }); browser.webNavigation.onCommitted.addListener(details => { + const { frameId, tabId } = details; + if ( frameId === 0 && tabId > 0 && details.transitionType === 'reload' ) { + if ( vAPI.net && vAPI.net.hasUnprocessedRequest(tabId) ) { + vAPI.net.removeUnprocessedRequest(tabId); + } + } this.onCommittedHandler(details); }); browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { @@ -1268,10 +1274,7 @@ vAPI.Net = class { listener = details => { const { tabId, type } = details; if ( type === 'main_frame' && this.unprocessedTabs.has(tabId) ) { - this.unprocessedTabs.delete(tabId); - if ( this.unprocessedTabs.size === 0 ) { - this.suspendableListener = this.deferredSuspendableListener; - this.deferredSuspendableListener = undefined; + if ( this.removeUnprocessedRequest(tabId) ) { return this.suspendableListener(details); } } @@ -1311,6 +1314,13 @@ vAPI.Net = class { return this.unprocessedTabs.size !== 0 && this.unprocessedTabs.has(tabId); } + removeUnprocessedRequest(tabId) { + this.unprocessedTabs.delete(tabId); + if ( this.unprocessedTabs.size !== 0 ) { return false; } + this.suspendableListener = this.deferredSuspendableListener; + this.deferredSuspendableListener = undefined; + return true; + } suspendOneRequest() { } unsuspendAllRequests() {