diff --git a/platform/mv3/chromium/manifest.json b/platform/mv3/chromium/manifest.json index ff981f7c3..72760301c 100644 --- a/platform/mv3/chromium/manifest.json +++ b/platform/mv3/chromium/manifest.json @@ -41,15 +41,5 @@ "storage": { "managed_schema": "managed_storage.json" }, - "version": "1.0", - "web_accessible_resources": [ - { - "resources": [ - "/strict-block.html" - ], - "matches": [ - "" - ] - } - ] + "version": "1.0" } diff --git a/platform/mv3/extension/js/background.js b/platform/mv3/extension/js/background.js index 5461d671a..087df6101 100644 --- a/platform/mv3/extension/js/background.js +++ b/platform/mv3/extension/js/background.js @@ -37,7 +37,6 @@ import { dnr, localRead, localRemove, localWrite, runtime, - sessionRemove, windows, } from './ext.js'; @@ -369,10 +368,6 @@ function onMessage(request, sender, callback) { async function start() { await loadRulesetConfig(); - if ( process.wakeupRun === false ) { - sessionRemove('excludedStrictBlockHostnames'); - } - const rulesetsUpdated = process.wakeupRun === false && await enableRulesets(rulesetConfig.enabledRulesets); diff --git a/platform/mv3/extension/js/ruleset-manager.js b/platform/mv3/extension/js/ruleset-manager.js index fba403e42..c881d20f8 100644 --- a/platform/mv3/extension/js/ruleset-manager.js +++ b/platform/mv3/extension/js/ruleset-manager.js @@ -72,30 +72,6 @@ function getRulesetDetails() { /******************************************************************************/ -function getDynamicRules(...args) { - if ( getDynamicRules.promise !== undefined ) { - return getDynamicRules.promise; - } - getDynamicRules.promise = dnr.getDynamicRules(...args).then(rules => { - getDynamicRules.promise = undefined; - return rules; - }); - return getDynamicRules.promise; -} - -function getSessionRules(...args) { - if ( getSessionRules.promise !== undefined ) { - return getSessionRules.promise; - } - getSessionRules.promise = dnr.getSessionRules(...args).then(rules => { - getSessionRules.promise = undefined; - return rules; - }); - return getSessionRules.promise; -} - -/******************************************************************************/ - async function pruneInvalidRegexRules(realm, rulesIn) { const rejectedRegexRules = []; @@ -329,12 +305,21 @@ async function updateStrictBlockRules(dynamicRules, sessionRules) { toStrictBlock.delete(hn); } if ( toStrictBlock.size === 0 ) { return; } + const manifest = runtime.getManifest(); + let strictblockPath = ''; + for ( const war of manifest.web_accessible_resources ) { + if ( war.resources.length !== 1 ) { continue; } + if ( war.resources[0].startsWith('/strict-block.') === false ) { continue; } + strictblockPath = runtime.getURL(war.resources[0]); + break; + } + if ( strictblockPath === '' ) { return; } const dynamicRule = { id: dynamicRuleId++, action: { type: 'redirect', redirect: { - regexSubstitution: `${runtime.getURL('/strict-block.html')}#\\0`, + regexSubstitution: `${strictblockPath}#\\0`, }, }, condition: { @@ -368,19 +353,18 @@ async function updateStrictBlockRules(dynamicRules, sessionRules) { /******************************************************************************/ async function updateDynamicRules() { - dynamicRuleId = 1; - sessionRuleId = 1; + dynamicRuleId = sessionRuleId = 1; const dynamicRules = []; const sessionRules = []; const [ dynamicRuleIds, sessionRuleIds, ] = await Promise.all([ - getDynamicRules().then(rules => + dnr.getDynamicRules().then(rules => rules.map(rule => rule.id) .filter(id => id < TRUSTED_DIRECTIVE_BASE_RULE_ID) ), - getSessionRules().then(rules => rules.map(rule => rule.id)), + dnr.getSessionRules().then(rules => rules.map(rule => rule.id)), updateRegexRules(dynamicRules), updateRemoveparamRules(dynamicRules), updateRedirectRules(dynamicRules), @@ -429,7 +413,7 @@ async function updateDynamicRules() { /******************************************************************************/ async function filteringModesToDNR(modes) { - const trustedRules = await getDynamicRules({ + const trustedRules = await dnr.getDynamicRules({ ruleIds: [ TRUSTED_DIRECTIVE_BASE_RULE_ID+0 ], }); const trustedRule = trustedRules.length !== 0 && trustedRules[0] || undefined; diff --git a/platform/mv3/extension/js/strict-block.js b/platform/mv3/extension/js/strict-block.js index 651b4b50e..616ef6ddb 100644 --- a/platform/mv3/extension/js/strict-block.js +++ b/platform/mv3/extension/js/strict-block.js @@ -160,9 +160,7 @@ if ( window.history.length > 1 ) { qs$('#bye').style.display = 'none'; } else { dom.on('#bye', 'click', ( ) => { - sendMessage({ - what: 'closeThisTab', - }); + window.close(); }); qs$('#back').style.display = 'none'; } diff --git a/platform/mv3/firefox/manifest.json b/platform/mv3/firefox/manifest.json index 9b6deb4b4..703f652b2 100644 --- a/platform/mv3/firefox/manifest.json +++ b/platform/mv3/firefox/manifest.json @@ -50,15 +50,5 @@ "storage" ], "short_name": "uBO Lite", - "version": "1.0", - "web_accessible_resources": [ - { - "resources": [ - "/strict-block.html" - ], - "matches": [ - "" - ] - } - ] + "version": "1.0" } diff --git a/platform/mv3/make-rulesets.js b/platform/mv3/make-rulesets.js index cb519e134..6fbe1f6e1 100644 --- a/platform/mv3/make-rulesets.js +++ b/platform/mv3/make-rulesets.js @@ -1361,6 +1361,15 @@ async function main() { // Patch declarative_net_request key manifest.declarative_net_request = { rule_resources: ruleResources }; // Patch web_accessible_resources key + manifest.web_accessible_resources = manifest.web_accessible_resources || []; + // Strict-block-related resource + const strictblockDocument = `strict-block.${secret}.html`; + copyFile('./strict-block.html', `${outputDir}/${strictblockDocument}`); + manifest.web_accessible_resources.push({ + resources: [ `/${strictblockDocument}` ], + matches: [ '' ], + }); + // Secondary resources const web_accessible_resources = { resources: Array.from(requiredRedirectResources).map(path => `/${path}`), matches: [ '' ], diff --git a/platform/mv3/extension/strict-block.html b/platform/mv3/strict-block.html similarity index 100% rename from platform/mv3/extension/strict-block.html rename to platform/mv3/strict-block.html diff --git a/tools/make-mv3.sh b/tools/make-mv3.sh index c6b02abdd..287a7b08b 100755 --- a/tools/make-mv3.sh +++ b/tools/make-mv3.sh @@ -107,6 +107,7 @@ if [ "$QUICK" != "yes" ]; then cp platform/mv3/package.json "$TMPDIR"/ cp platform/mv3/*.js "$TMPDIR"/ cp platform/mv3/*.mjs "$TMPDIR"/ + cp platform/mv3/*.html "$TMPDIR"/ cp platform/mv3/extension/js/utils.js "$TMPDIR"/js/ cp -R "$UBO_DIR"/src/js/resources "$TMPDIR"/js/ cp "$UBO_DIR"/assets/assets.dev.json "$TMPDIR"/