Skip to content

Commit

Permalink
Rework behavior of "Suspend network activity until ..."
Browse files Browse the repository at this point in the history
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:
- uBlockOrigin/uBlock-issues#1973
- https://www.reddit.com/r/uBlockOrigin/comments/squo8n/latest_update_blocks_network_connections_at/
  • Loading branch information
gorhill committed Feb 16, 2022
1 parent 35a9e2b commit 3455552
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 9 deletions.
4 changes: 3 additions & 1 deletion platform/chromium/vapi-background-ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion platform/common/vapi-background.js
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,7 @@ vAPI.Net = class {
if ( this.suspendDepth !== 0 ) { return; }
this.unsuspendAllRequests(discard);
}
canSuspend() {
static canSuspend() {
return false;
}
};
Expand Down
2 changes: 1 addition & 1 deletion platform/firefox/vapi-background-ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ import {
);
}
}
canSuspend() {
static canSuspend() {
return true;
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const userSettingsDefault = {
prefetchingDisabled: true,
requestLogMaxEntries: 1000,
showIconBadge: true,
suspendUntilListsAreLoaded: true,
suspendUntilListsAreLoaded: vAPI.Net.canSuspend(),
tooltipsDisabled: false,
webrtcIPAddressHidden: false,
};
Expand Down
16 changes: 13 additions & 3 deletions src/js/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/js/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion src/js/traffic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3455552

Please sign in to comment.