Skip to content

Commit 0e8ff10

Browse files
committed
[mv3] Mind service workers for sites in "no filtering" mode
Related issue: uBlockOrigin/uBOL-home#114
1 parent ad88ff2 commit 0e8ff10

1 file changed

Lines changed: 32 additions & 13 deletions

File tree

platform/mv3/extension/js/mode-manager.js

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -288,34 +288,53 @@ async function writeFilteringModeDetails(afterDetails) {
288288

289289
async function filteringModesToDNR(modes) {
290290
const dynamicRuleMap = await getDynamicRules();
291-
const presentRule = dynamicRuleMap.get(TRUSTED_DIRECTIVE_BASE_RULE_ID);
291+
const presentRule = dynamicRuleMap.get(TRUSTED_DIRECTIVE_BASE_RULE_ID+0);
292292
const presentNone = new Set(
293293
presentRule && presentRule.condition.requestDomains
294294
);
295295
if ( eqSets(presentNone, modes.none) ) { return; }
296296
const removeRuleIds = [];
297297
if ( presentRule !== undefined ) {
298-
removeRuleIds.push(TRUSTED_DIRECTIVE_BASE_RULE_ID);
299-
dynamicRuleMap.delete(TRUSTED_DIRECTIVE_BASE_RULE_ID);
298+
removeRuleIds.push(TRUSTED_DIRECTIVE_BASE_RULE_ID+0);
299+
removeRuleIds.push(TRUSTED_DIRECTIVE_BASE_RULE_ID+1);
300+
dynamicRuleMap.delete(TRUSTED_DIRECTIVE_BASE_RULE_ID+0);
301+
dynamicRuleMap.delete(TRUSTED_DIRECTIVE_BASE_RULE_ID+1);
300302
}
301303
const addRules = [];
302-
if ( modes.none.size !== 0 ) {
303-
const rule = {
304-
id: TRUSTED_DIRECTIVE_BASE_RULE_ID,
304+
const noneHostnames = [ ...modes.none ];
305+
const notNoneHostnames = [ ...modes.basic, ...modes.optimal, ...modes.complete ];
306+
if ( noneHostnames.length !== 0 ) {
307+
const rule0 = {
308+
id: TRUSTED_DIRECTIVE_BASE_RULE_ID+0,
305309
action: { type: 'allowAllRequests' },
306310
condition: {
307311
resourceTypes: [ 'main_frame' ],
308312
},
309313
priority: 100,
310314
};
311-
if (
312-
modes.none.size !== 1 ||
313-
modes.none.has('all-urls') === false
314-
) {
315-
rule.condition.requestDomains = Array.from(modes.none);
315+
if ( modes.none.has('all-urls') === false ) {
316+
rule0.condition.requestDomains = noneHostnames.slice();
317+
} else if ( notNoneHostnames.length !== 0 ) {
318+
rule0.condition.excludedRequestDomains = notNoneHostnames.slice();
316319
}
317-
addRules.push(rule);
318-
dynamicRuleMap.set(TRUSTED_DIRECTIVE_BASE_RULE_ID, rule);
320+
addRules.push(rule0);
321+
dynamicRuleMap.set(TRUSTED_DIRECTIVE_BASE_RULE_ID+0, rule0);
322+
// https://github.com/uBlockOrigin/uBOL-home/issues/114
323+
const rule1 = {
324+
id: TRUSTED_DIRECTIVE_BASE_RULE_ID+1,
325+
action: { type: 'allow' },
326+
condition: {
327+
resourceTypes: [ 'script' ],
328+
},
329+
priority: 100,
330+
};
331+
if ( modes.none.has('all-urls') === false ) {
332+
rule1.condition.initiatorDomains = noneHostnames.slice();
333+
} else if ( notNoneHostnames.length !== 0 ) {
334+
rule1.condition.excludedInitiatorDomains = notNoneHostnames.slice();
335+
}
336+
addRules.push(rule1);
337+
dynamicRuleMap.set(TRUSTED_DIRECTIVE_BASE_RULE_ID+1, rule1);
319338
}
320339
const updateOptions = {};
321340
if ( addRules.length ) {

0 commit comments

Comments
 (0)