From 0e8ff10e9209d1134c5163a97514af2c88d723a3 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Wed, 31 Jan 2024 09:59:45 -0500 Subject: [PATCH] [mv3] Mind service workers for sites in "no filtering" mode Related issue: https://github.com/uBlockOrigin/uBOL-home/issues/114 --- platform/mv3/extension/js/mode-manager.js | 45 ++++++++++++++++------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/platform/mv3/extension/js/mode-manager.js b/platform/mv3/extension/js/mode-manager.js index bc7619918..e75dbeef5 100644 --- a/platform/mv3/extension/js/mode-manager.js +++ b/platform/mv3/extension/js/mode-manager.js @@ -288,34 +288,53 @@ async function writeFilteringModeDetails(afterDetails) { async function filteringModesToDNR(modes) { const dynamicRuleMap = await getDynamicRules(); - const presentRule = dynamicRuleMap.get(TRUSTED_DIRECTIVE_BASE_RULE_ID); + const presentRule = dynamicRuleMap.get(TRUSTED_DIRECTIVE_BASE_RULE_ID+0); const presentNone = new Set( presentRule && presentRule.condition.requestDomains ); if ( eqSets(presentNone, modes.none) ) { return; } const removeRuleIds = []; if ( presentRule !== undefined ) { - removeRuleIds.push(TRUSTED_DIRECTIVE_BASE_RULE_ID); - dynamicRuleMap.delete(TRUSTED_DIRECTIVE_BASE_RULE_ID); + removeRuleIds.push(TRUSTED_DIRECTIVE_BASE_RULE_ID+0); + removeRuleIds.push(TRUSTED_DIRECTIVE_BASE_RULE_ID+1); + dynamicRuleMap.delete(TRUSTED_DIRECTIVE_BASE_RULE_ID+0); + dynamicRuleMap.delete(TRUSTED_DIRECTIVE_BASE_RULE_ID+1); } const addRules = []; - if ( modes.none.size !== 0 ) { - const rule = { - id: TRUSTED_DIRECTIVE_BASE_RULE_ID, + const noneHostnames = [ ...modes.none ]; + const notNoneHostnames = [ ...modes.basic, ...modes.optimal, ...modes.complete ]; + if ( noneHostnames.length !== 0 ) { + const rule0 = { + id: TRUSTED_DIRECTIVE_BASE_RULE_ID+0, action: { type: 'allowAllRequests' }, condition: { resourceTypes: [ 'main_frame' ], }, priority: 100, }; - if ( - modes.none.size !== 1 || - modes.none.has('all-urls') === false - ) { - rule.condition.requestDomains = Array.from(modes.none); + if ( modes.none.has('all-urls') === false ) { + rule0.condition.requestDomains = noneHostnames.slice(); + } else if ( notNoneHostnames.length !== 0 ) { + rule0.condition.excludedRequestDomains = notNoneHostnames.slice(); } - addRules.push(rule); - dynamicRuleMap.set(TRUSTED_DIRECTIVE_BASE_RULE_ID, rule); + addRules.push(rule0); + dynamicRuleMap.set(TRUSTED_DIRECTIVE_BASE_RULE_ID+0, rule0); + // https://github.com/uBlockOrigin/uBOL-home/issues/114 + const rule1 = { + id: TRUSTED_DIRECTIVE_BASE_RULE_ID+1, + action: { type: 'allow' }, + condition: { + resourceTypes: [ 'script' ], + }, + priority: 100, + }; + if ( modes.none.has('all-urls') === false ) { + rule1.condition.initiatorDomains = noneHostnames.slice(); + } else if ( notNoneHostnames.length !== 0 ) { + rule1.condition.excludedInitiatorDomains = notNoneHostnames.slice(); + } + addRules.push(rule1); + dynamicRuleMap.set(TRUSTED_DIRECTIVE_BASE_RULE_ID+1, rule1); } const updateOptions = {}; if ( addRules.length ) {