From 19a3de901cee162f7e403b0d18f8fd466491dff9 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sun, 10 Aug 2025 11:40:08 -0400 Subject: [PATCH] [mv3] Disable "strict blocking" by default in Safari Related issue: https://github.com/uBlockOrigin/uBOL-home/issues/428#issuecomment-3172663563 --- platform/mv3/extension/js/background.js | 20 ++++++++++++++++++++ platform/mv3/extension/js/config.js | 3 ++- platform/mv3/extension/js/ext.js | 6 ++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/platform/mv3/extension/js/background.js b/platform/mv3/extension/js/background.js index 56d6e176b..adf0e649c 100644 --- a/platform/mv3/extension/js/background.js +++ b/platform/mv3/extension/js/background.js @@ -58,6 +58,7 @@ import { browser, localRead, localRemove, localWrite, runtime, + webextFlavor, } from './ext.js'; import { @@ -106,6 +107,18 @@ function getCurrentVersion() { return runtime.getManifest().version; } +// The goal is just to be able to find out whether a specific version is older +// than another one. + +function intFromVersion(version) { + const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(version); + if ( match === null ) { return 0; } + const year = parseInt(match[1], 10); + const monthday = parseInt(match[2], 10); + const min = parseInt(match[3], 10); + return (year - 2022) * (1232 * 2400) + monthday * 2400 + min; +} + /******************************************************************************/ async function onPermissionsRemoved() { @@ -542,6 +555,13 @@ async function startSession() { // obsolete ruleset to remove. if ( isNewVersion ) { ubolLog(`Version change: ${rulesetConfig.version} => ${currentVersion}`); + // https://github.com/uBlockOrigin/uBOL-home/issues/428#issuecomment-3172663563 + if ( webextFlavor === 'safari' && rulesetConfig.strictBlockMode ) { + const before = intFromVersion(rulesetConfig.version); + if ( before <= intFromVersion('2025.804.2359') ) { + rulesetConfig.strictBlockMode = false; + } + } rulesetConfig.version = currentVersion; await patchDefaultRulesets(); saveRulesetConfig(); diff --git a/platform/mv3/extension/js/config.js b/platform/mv3/extension/js/config.js index f48533473..b0c393794 100644 --- a/platform/mv3/extension/js/config.js +++ b/platform/mv3/extension/js/config.js @@ -22,6 +22,7 @@ import { localRead, localWrite, sessionRead, sessionWrite, + webextFlavor, } from './ext.js'; /******************************************************************************/ @@ -31,7 +32,7 @@ export const rulesetConfig = { enabledRulesets: [], autoReload: true, showBlockedCount: true, - strictBlockMode: true, + strictBlockMode: webextFlavor !== 'safari', developerMode: false, hasBroadHostPermissions: true, }; diff --git a/platform/mv3/extension/js/ext.js b/platform/mv3/extension/js/ext.js index ea0f90425..18c88f878 100644 --- a/platform/mv3/extension/js/ext.js +++ b/platform/mv3/extension/js/ext.js @@ -27,6 +27,12 @@ export const browser = webext; export const i18n = browser.i18n; export const runtime = browser.runtime; +export const webextFlavor = (( ) => { + const extURL = runtime.getURL(''); + if ( extURL.startsWith('safari-web-extension:') ) { return 'safari'; } + return extURL.startsWith('moz-extension:') ? 'firefox' : 'chromium'; +})(); + /******************************************************************************/ // The extension's service worker can be evicted at any time, so when we