diff --git a/.browserslistrc b/.browserslistrc index ad9f6c9..0779126 100644 --- a/.browserslistrc +++ b/.browserslistrc @@ -14,8 +14,8 @@ FirefoxAndroid >= 115 Opera >= 109 [safari] -Safari >= 16.4 -iOS >= 16.4 +Safari >= 17 +iOS >= 17 [samsung] Samsung >= 14 diff --git a/gulpfile.js b/gulpfile.js index eec28e9..57d9421 100755 --- a/gulpfile.js +++ b/gulpfile.js @@ -24,7 +24,7 @@ const isProduction = process.env.NODE_ENV === 'production'; const enableContributions = (process.env.ENABLE_CONTRIBUTIONS || 'true') === 'true'; -const mv3 = ['chrome', 'edge', 'opera'].includes(targetEnv); +const mv3 = ['chrome', 'edge', 'opera', 'safari'].includes(targetEnv); const distDir = path.join(__dirname, 'dist', targetEnv); @@ -51,7 +51,7 @@ function js(done) { function html() { const htmlSrc = ['src/**/*.html']; - if (mv3) { + if (mv3 && !['safari'].includes(targetEnv)) { htmlSrc.push('!src/background/*.html'); } diff --git a/src/assets/manifest/safari.json b/src/assets/manifest/safari.json index d7e3dbf..7570613 100755 --- a/src/assets/manifest/safari.json +++ b/src/assets/manifest/safari.json @@ -1,5 +1,5 @@ { - "manifest_version": 2, + "manifest_version": 3, "name": "__MSG_extensionName__", "description": "__MSG_extensionDescription__", "version": "0.1.0", @@ -9,7 +9,7 @@ "browser_specific_settings": { "safari": { - "strict_min_version": "16.4" + "strict_min_version": "17.0" } }, @@ -22,9 +22,11 @@ "activeTab", "nativeMessaging", "webNavigation", - "" + "scripting" ], + "host_permissions": [""], + "icons": { "16": "src/assets/icons/app/icon-16.png", "19": "src/assets/icons/app/icon-19.png", @@ -40,7 +42,7 @@ "1024": "src/assets/icons/app/icon-1024.png" }, - "browser_action": { + "action": { "default_icon": { "16": "src/assets/icons/app/icon-16.png", "19": "src/assets/icons/app/icon-19.png", diff --git a/src/utils/common.js b/src/utils/common.js index 1e79fdd..abaa1e2 100644 --- a/src/utils/common.js +++ b/src/utils/common.js @@ -22,9 +22,13 @@ async function executeScript({ code = '' }) { if (mv3) { - const params = {target: {tabId, allFrames}, world}; + const params = {target: {tabId}, world}; - if (!allFrames) { + // Safari 17: allFrames and frameIds cannot both be specified, + // fixed in Safari 18. + if (allFrames) { + params.target.allFrames = true; + } else { params.target.frameIds = frameIds; } @@ -323,11 +327,9 @@ function getDayPrecisionEpoch(epoch) { } function isBackgroundPageContext() { - const backgroundUrl = mv3 - ? browser.runtime.getURL('/src/background/script.js') - : browser.runtime.getURL('/src/background/index.html'); - - return self.location.href === backgroundUrl; + return self.location.href.startsWith( + browser.runtime.getURL('/src/background/') + ); } function getExtensionDomain() { diff --git a/webpack.config.js b/webpack.config.js index 9dfd0d2..9ac2f1c 100755 --- a/webpack.config.js +++ b/webpack.config.js @@ -14,7 +14,7 @@ const isProduction = process.env.NODE_ENV === 'production'; const enableContributions = (process.env.ENABLE_CONTRIBUTIONS || 'true') === 'true'; -const mv3 = ['chrome', 'edge', 'opera'].includes(targetEnv); +const mv3 = ['chrome', 'edge', 'opera', 'safari'].includes(targetEnv); const provideExtApi = !['firefox', 'safari'].includes(targetEnv);