mirror of
https://github.com/gorhill/uBlock.git
synced 2026-03-11 09:04:36 +00:00
[mv3][safari] Force-reload rulesets when new browsing realm is seen
Workaround for Safari-specific issue: - https://github.com/uBlockOrigin/uBOL-home/issues/515 - https://bugs.webkit.org/show_bug.cgi?id=300236
This commit is contained in:
parent
6fb58f8599
commit
8cc18c1089
1 changed files with 40 additions and 0 deletions
|
|
@ -181,3 +181,43 @@ export const dnr = {
|
|||
return nativeDNR.setExtensionActionOptions(...args);
|
||||
},
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
// Workaround for:
|
||||
// https://github.com/uBlockOrigin/uBOL-home/issues/515
|
||||
// https://bugs.webkit.org/show_bug.cgi?id=300236
|
||||
//
|
||||
// For each realm, we will force-reload registered rulesets once.
|
||||
|
||||
const { windows } = webext;
|
||||
const NORMAL_REALM = 0b01;
|
||||
const PRIVATE_REALM = 0b10;
|
||||
const ALL_REALMS = NORMAL_REALM | PRIVATE_REALM;
|
||||
let seenRealms = 0b00;
|
||||
|
||||
async function forceEnableRulesets(windowId) {
|
||||
if ( seenRealms === ALL_REALMS ) { return; }
|
||||
if ( windowId === windows.WINDOW_ID_NONE ) { return; }
|
||||
const details = await windows.get(windowId, { windowTypes: [ 'normal' ] });
|
||||
const incognito = details?.incognito;
|
||||
if ( typeof incognito !== 'boolean' ) { return; }
|
||||
const currentRealm = incognito ? PRIVATE_REALM : NORMAL_REALM;
|
||||
if ( (seenRealms & currentRealm) !== 0 ) { return; }
|
||||
seenRealms |= currentRealm;
|
||||
webext.storage.session.set({ __seenRealms: seenRealms });
|
||||
const ids = await nativeDNR.getEnabledRulesets();
|
||||
if ( ids.length === 0 ) { return; }
|
||||
nativeDNR.updateEnabledRulesets({
|
||||
disableRulesetIds: ids.slice(),
|
||||
enableRulesetIds: ids.slice(),
|
||||
});
|
||||
}
|
||||
|
||||
windows.onFocusChanged.addListener(forceEnableRulesets);
|
||||
|
||||
webext.storage.session.get('__seenRealms').then(bin => {
|
||||
seenRealms |= bin?.__seenRealms ?? 0;
|
||||
}).catch(( ) => {
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue