Forcefully clear unprocessed-request status after a minute

Related feedback:
- https://github.com/uBlockOrigin/uBlock-issues/issues/2589#issuecomment-1507084473
This commit is contained in:
Raymond Hill 2023-04-13 11:41:52 -04:00
parent e5e8e0d443
commit c97d0ab062
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 11 additions and 7 deletions

View File

@ -890,7 +890,7 @@ if ( webext.browserAction instanceof Object ) {
});
browserAction.setBadgeText({ text });
browserAction.setBadgeBackgroundColor({
color: text === '!' ? '#FFCC00' : '#666'
color: text === '!' ? '#FC0' : '#666'
});
};
}
@ -1252,7 +1252,6 @@ vAPI.Net = class {
this.listenerMap = new WeakMap();
this.suspendDepth = 0;
this.unprocessedTabs = new Map();
this.processRequestStartTime = Number.MAX_SAFE_INTEGER;
browser.webRequest.onBeforeRequest.addListener(
details => {
@ -1335,7 +1334,6 @@ vAPI.Net = class {
}
return this.deferredSuspendableListener(details);
};
this.processRequestStartTime = Date.now();
}
this.suspendableListener = listener;
vAPI.setDefaultIcon('', '');
@ -1371,9 +1369,7 @@ vAPI.Net = class {
}
hasUnprocessedRequest(tabId) {
if ( this.unprocessedTabs.size === 0 ) { return false; }
if ( (Date.now() - this.processRequestStartTime) > 60000 ) {
this.removeUnprocessedRequest();
}
if ( tabId === undefined ) { return true; }
return this.unprocessedTabs.has(tabId);
}
removeUnprocessedRequest(tabId) {

View File

@ -982,7 +982,7 @@ const injectCSP = function(fctxt, pageStore, responseHeaders) {
if ( cspSubsets.length === 0 ) { return; }
µb.updateToolbarIcon(fctxt.tabId, 0x02);
µb.updateToolbarIcon(fctxt.tabId, 0b0010);
// Use comma to merge CSP directives.
// Ref.: https://www.w3.org/TR/CSP2/#implementation-considerations
@ -1133,6 +1133,14 @@ const webRequest = {
urls: [ 'http://*/*', 'https://*/*' ]
}
);
vAPI.defer.once({ min: 1 }).then(( ) => {
if ( vAPI.net.hasUnprocessedRequest() === false ) { return; }
vAPI.net.removeUnprocessedRequest();
vAPI.tabs.getCurrent().then(tab => {
if ( tab === null ) { return; }
µb.updateToolbarIcon(tab.id, 0b0110);
});
});
vAPI.net.unsuspend({ all: true });
};
})(),