Skip to content

Commit

Permalink
[mv3] Mind service workers for sites in "no filtering" mode
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Jan 31, 2024
1 parent ad88ff2 commit 0e8ff10
Showing 1 changed file with 32 additions and 13 deletions.
45 changes: 32 additions & 13 deletions platform/mv3/extension/js/mode-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down

0 comments on commit 0e8ff10

Please sign in to comment.