1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-07-05 11:37:01 +02:00

Rework behavior of "Suspend network activity until ..."

The setting will default to the natural capability of the browser:

- Checked for Firefox
- Unchecked for Chromium-based browsers

For Chromium-based browser, if checked, network requests will be
redirected to an empty resources instead of blocking the
connection.

Related feedback:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1973
- https://www.reddit.com/r/uBlockOrigin/comments/squo8n/latest_update_blocks_network_connections_at/
This commit is contained in:
Raymond Hill 2022-02-13 09:24:57 -05:00
parent 3ea92f87a3
commit 2933016d4b
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
7 changed files with 23 additions and 9 deletions

View File

@ -183,7 +183,9 @@ vAPI.Tabs = class extends vAPI.Tabs {
suspendOneRequest(details) {
this.suspendedTabIds.add(details.tabId);
return { cancel: true };
return {
redirectUrl: vAPI.getURL(`web_accessible_resources/empty?secret=${vAPI.warSecret()}`)
};
}
unsuspendAllRequests(discard = false) {

View File

@ -1249,7 +1249,7 @@ vAPI.Net = class {
if ( this.suspendDepth !== 0 ) { return; }
this.unsuspendAllRequests(discard);
}
canSuspend() {
static canSuspend() {
return false;
}
};

View File

@ -303,7 +303,7 @@ import {
);
}
}
canSuspend() {
static canSuspend() {
return true;
}
};

View File

@ -110,7 +110,7 @@ const userSettingsDefault = {
prefetchingDisabled: true,
requestLogMaxEntries: 1000,
showIconBadge: true,
suspendUntilListsAreLoaded: true,
suspendUntilListsAreLoaded: vAPI.Net.canSuspend(),
tooltipsDisabled: false,
webrtcIPAddressHidden: false,
};

View File

@ -201,10 +201,20 @@ const onNetWhitelistReady = function(netWhitelistRaw, adminExtra) {
const onUserSettingsReady = function(fetched) {
// Terminate suspended state?
if ( fetched.suspendUntilListsAreLoaded === false ) {
const tnow = Date.now() - vAPI.T0;
if (
vAPI.Net.canSuspend() &&
fetched.suspendUntilListsAreLoaded === false
) {
vAPI.net.unsuspend({ all: true, discard: true });
ubolog(`Unsuspend network activity listener`);
µb.supportStats.unsuspendAfter = `${Date.now() - vAPI.T0} ms`;
ubolog(`Unsuspend network activity listener at ${tnow} ms`);
µb.supportStats.unsuspendAfter = `${tnow} ms`;
} else if (
vAPI.Net.canSuspend() === false &&
fetched.suspendUntilListsAreLoaded
) {
vAPI.net.suspend();
ubolog(`Suspend network activity listener at ${tnow} ms`);
}
// `externalLists` will be deprecated in some future, it is kept around

View File

@ -805,7 +805,7 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
const onFilterListsReady = function(lists) {
this.availableFilterLists = lists;
if ( vAPI.net.canSuspend() ) {
if ( vAPI.Net.canSuspend() ) {
vAPI.net.suspend();
}
redirectEngine.reset();

View File

@ -1136,7 +1136,9 @@ const webRequest = {
start: (( ) => {
vAPI.net = new vAPI.Net();
vAPI.net.suspend();
if ( vAPI.Net.canSuspend() ) {
vAPI.net.suspend();
}
return async ( ) => {
vAPI.net.setSuspendableListener(onBeforeRequest);