mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-06 09:37:12 +02:00
Move early blocking of requests out of experimental status on Firefox
Related issues: - https://github.com/gorhill/uBlock/issues/2067 - https://github.com/uBlockOrigin/uBlock-issues/issues/128 Related mozbug issue: - https://bugzilla.mozilla.org/show_bug.cgi?id=1503721
This commit is contained in:
parent
99cdec5ba6
commit
41548be6be
@ -148,3 +148,44 @@
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
// https://github.com/gorhill/uBlock/issues/2067
|
||||||
|
// Experimental: Block everything until uBO is fully ready.
|
||||||
|
|
||||||
|
vAPI.net.onBeforeReady = (function() {
|
||||||
|
let pendings;
|
||||||
|
|
||||||
|
const handler = function(details) {
|
||||||
|
if ( pendings === undefined ) { return; }
|
||||||
|
if ( details.tabId < 0 ) { return; }
|
||||||
|
|
||||||
|
pendings.add(details.tabId);
|
||||||
|
|
||||||
|
return { cancel: true };
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
experimental: true,
|
||||||
|
start: function() {
|
||||||
|
pendings = new Set();
|
||||||
|
browser.webRequest.onBeforeRequest.addListener(
|
||||||
|
handler,
|
||||||
|
{ urls: [ 'http://*/*', 'https://*/*' ] },
|
||||||
|
[ 'blocking' ]
|
||||||
|
);
|
||||||
|
},
|
||||||
|
// https://github.com/gorhill/uBlock/issues/2067
|
||||||
|
// Force-reload tabs for which network requests were blocked
|
||||||
|
// during launch. This can happen only if tabs were "suspended".
|
||||||
|
stop: function() {
|
||||||
|
if ( pendings === undefined ) { return; }
|
||||||
|
browser.webRequest.onBeforeRequest.removeListener(handler);
|
||||||
|
for ( const tabId of pendings ) {
|
||||||
|
vAPI.tabs.reload(tabId);
|
||||||
|
}
|
||||||
|
pendings = undefined;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
@ -130,3 +130,52 @@
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
// Related issues:
|
||||||
|
// - https://github.com/gorhill/uBlock/issues/2067
|
||||||
|
// - https://github.com/uBlockOrigin/uBlock-issues/issues/128
|
||||||
|
// - https://bugzilla.mozilla.org/show_bug.cgi?id=1503721
|
||||||
|
|
||||||
|
vAPI.net.onBeforeReady = (function() {
|
||||||
|
let pendings;
|
||||||
|
|
||||||
|
const handler = function(details) {
|
||||||
|
if ( pendings === undefined ) { return; }
|
||||||
|
if ( details.tabId < 0 ) { return; }
|
||||||
|
|
||||||
|
const pending = {
|
||||||
|
details: Object.assign({}, details),
|
||||||
|
resolve: undefined,
|
||||||
|
promise: undefined
|
||||||
|
};
|
||||||
|
|
||||||
|
pending.promise = new Promise(function(resolve) {
|
||||||
|
pending.resolve = resolve;
|
||||||
|
});
|
||||||
|
|
||||||
|
pendings.push(pending);
|
||||||
|
|
||||||
|
return pending.promise;
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
start: function() {
|
||||||
|
pendings = [];
|
||||||
|
browser.webRequest.onBeforeRequest.addListener(
|
||||||
|
handler,
|
||||||
|
{ urls: [ 'http://*/*', 'https://*/*' ] },
|
||||||
|
[ 'blocking' ]
|
||||||
|
);
|
||||||
|
},
|
||||||
|
stop: function(resolver) {
|
||||||
|
if ( pendings === undefined ) { return; }
|
||||||
|
for ( const pending of pendings ) {
|
||||||
|
const result = resolver(pending.details);
|
||||||
|
pending.resolve(result);
|
||||||
|
}
|
||||||
|
pendings = undefined;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
@ -53,6 +53,8 @@ vAPI.app.onShutdown = function() {
|
|||||||
// - Schedule next update operation.
|
// - Schedule next update operation.
|
||||||
|
|
||||||
var onAllReady = function() {
|
var onAllReady = function() {
|
||||||
|
µb.webRequest.start();
|
||||||
|
|
||||||
// Ensure that the resources allocated for decompression purpose (likely
|
// Ensure that the resources allocated for decompression purpose (likely
|
||||||
// large buffers) are garbage-collectable immediately after launch.
|
// large buffers) are garbage-collectable immediately after launch.
|
||||||
// Otherwise I have observed that it may take quite a while before the
|
// Otherwise I have observed that it may take quite a while before the
|
||||||
@ -60,7 +62,6 @@ var onAllReady = function() {
|
|||||||
// as possible ensure minimal memory usage baseline.
|
// as possible ensure minimal memory usage baseline.
|
||||||
µb.lz4Codec.relinquish();
|
µb.lz4Codec.relinquish();
|
||||||
|
|
||||||
µb.webRequest.start();
|
|
||||||
initializeTabs();
|
initializeTabs();
|
||||||
|
|
||||||
// https://github.com/chrisaljoudi/uBlock/issues/184
|
// https://github.com/chrisaljoudi/uBlock/issues/184
|
||||||
|
@ -992,28 +992,17 @@ const strictBlockBypasser = {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
start: (function() {
|
start: (function() {
|
||||||
const suspendedTabs = new Set();
|
if (
|
||||||
const onBeforeReady = function(details) {
|
vAPI.net.onBeforeReady instanceof Object &&
|
||||||
if ( details.type !== 'main_frame' && details.tabId > 0 ) {
|
(
|
||||||
suspendedTabs.add(details.tabId);
|
vAPI.net.onBeforeReady.experimental !== true ||
|
||||||
console.info('uBO suspend tab %d, block %s', details.tabId, details.url);
|
µBlock.hiddenSettings.suspendTabsUntilReady
|
||||||
return { cancel: true };
|
)
|
||||||
}
|
) {
|
||||||
};
|
vAPI.net.onBeforeReady.start();
|
||||||
// https://github.com/gorhill/uBlock/issues/2067
|
|
||||||
// Experimental: Block everything until uBO is fully ready.
|
|
||||||
// https://github.com/gorhill/uBlock/issues/3130
|
|
||||||
// Don't block root frame.
|
|
||||||
if ( µBlock.hiddenSettings.suspendTabsUntilReady ) {
|
|
||||||
vAPI.net.addListener(
|
|
||||||
'onBeforeRequest',
|
|
||||||
onBeforeReady,
|
|
||||||
{ urls: [ 'http://*/*', 'https://*/*' ] },
|
|
||||||
[ 'blocking' ]
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return function() {
|
return function() {
|
||||||
vAPI.net.removeListener('onBeforeRequest', onBeforeReady);
|
|
||||||
vAPI.net.addListener(
|
vAPI.net.addListener(
|
||||||
'onBeforeRequest',
|
'onBeforeRequest',
|
||||||
onBeforeRequest,
|
onBeforeRequest,
|
||||||
@ -1040,14 +1029,9 @@ return {
|
|||||||
[ 'blocking', 'requestBody' ]
|
[ 'blocking', 'requestBody' ]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// https://github.com/gorhill/uBlock/issues/2067
|
if ( vAPI.net.onBeforeReady instanceof Object ) {
|
||||||
// Force-reload tabs for which network requests were blocked
|
vAPI.net.onBeforeReady.stop(onBeforeRequest);
|
||||||
// during launch. This can happen only if tabs were "suspended".
|
|
||||||
for ( const tabId of suspendedTabs ) {
|
|
||||||
console.info('uBO suspend tab %d, force reload', tabId);
|
|
||||||
vAPI.tabs.reload(tabId);
|
|
||||||
}
|
}
|
||||||
suspendedTabs.clear();
|
|
||||||
};
|
};
|
||||||
})(),
|
})(),
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user