Dynamically reload 3p css when noop-ing "3rd-party" cell

This should improve usability of uBO's hard-mode
and "relax blocking mode" operations. This is the
new default behavior.

The previous behavior of forcing a reload of the
page can be re-enabled by simply setting the `3p`
bit of the advanced setting `blockingProfiles`
to 1.
This commit is contained in:
Raymond Hill 2020-12-12 14:33:49 -05:00
parent 64571a336e
commit b779f1f7c9
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
4 changed files with 85 additions and 2 deletions

View File

@ -43,7 +43,7 @@ const µBlock = (( ) => { // jshint ignore:line
autoUpdateDelayAfterLaunch: 180,
autoUpdatePeriod: 7,
benchmarkDatasetURL: 'unset',
blockingProfiles: '11111/#F00 11011/#C0F 11001/#00F 00001',
blockingProfiles: '11111/#F00 11010/#C0F 11001/#00F 00001',
cacheStorageAPI: 'unset',
cacheStorageCompression: true,
cacheControlForFirefox1376932: 'no-cache, no-store, must-revalidate',

View File

@ -88,6 +88,8 @@ const relaxBlockingMode = (( ) => {
// TODO: Reset to original blocking profile?
if ( newProfileBits === undefined ) { return; }
const noReload = (newProfileBits & 0b00000001) === 0;
if (
(curProfileBits & 0b00000010) !== 0 &&
(newProfileBits & 0b00000010) === 0
@ -104,6 +106,7 @@ const relaxBlockingMode = (( ) => {
(newProfileBits & 0b00000100) === 0
) {
µb.toggleFirewallRule({
tabId: noReload ? tab.id : undefined,
srcHostname: hn,
desHostname: '*',
requestType: '3p',
@ -135,7 +138,7 @@ const relaxBlockingMode = (( ) => {
}
// Reload the target tab?
if ( (newProfileBits & 0b00000001) === 0 ) { return; }
if ( noReload ) { return; }
// Reload: use a timer to coalesce bursts of reload commands.
let timer = reloadTimers.get(tab.id);

View File

@ -0,0 +1,70 @@
/*******************************************************************************
uBlock Origin - a browser extension to block requests.
Copyright (C) 2020-present Raymond Hill
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see {http://www.gnu.org/licenses/}.
Home: https://github.com/gorhill/uBlock
*/
'use strict';
/******************************************************************************/
(( ) => {
if ( typeof vAPI !== 'object' ) { return; }
if ( vAPI.load3rdPartyCSS ) { return; }
vAPI.load3rdPartyCSS = true;
const links = document.querySelectorAll('link[rel="stylesheet"]');
if ( links.length === 0 ) { return; }
const toLoadMaybe = new Map(Array.from(links).map(a => [ a.href, a ]));
for ( const sheet of Array.from(document.styleSheets) ) {
let loaded = false;
try {
loaded = sheet.rules.length !== 0;
} catch(ex) {
}
if ( loaded ) { continue; }
const link = toLoadMaybe.get(sheet.href);
if ( link === undefined ) { continue; }
toLoadMaybe.delete(sheet.href);
const clone = link.cloneNode(true);
link.replaceWith(clone);
}
})();
/*******************************************************************************
DO NOT:
- Remove the following code
- Add code beyond the following code
Reason:
- https://github.com/gorhill/uBlock/pull/3721
- uBO never uses the return value from injected content scripts
**/
void 0;

View File

@ -509,9 +509,19 @@ const matchBucket = function(url, hostname, bucket, start) {
// https://github.com/chrisaljoudi/uBlock/issues/420
this.cosmeticFilteringEngine.removeFromSelectorCache(srcHostname, 'net');
if ( details.tabId === undefined ) { return; }
if ( requestType.startsWith('3p') ) {
this.updateToolbarIcon(details.tabId, 0b100);
}
if ( requestType === '3p' && action === 3 ) {
vAPI.tabs.executeScript(details.tabId, {
file: '/js/scriptlets/load-3p-css.js',
allFrames: true,
runAt: 'document_idle',
});
}
};
/******************************************************************************/