From f46b75440f745438dc496b1a1c4dcf6a5b4fdc3e Mon Sep 17 00:00:00 2001 From: dessant Date: Thu, 26 Sep 2024 19:15:52 +0300 Subject: [PATCH] feat: upgrade to Manifest V3 in Safari BREAKING CHANGE: browser versions older than Safari 17 are no longer supported --- .browserslistrc | 4 ++-- gulpfile.js | 4 ++-- src/assets/manifest/safari.json | 27 +++++++++++++++++---------- src/utils/common.js | 8 +++----- webpack.config.js | 2 +- 5 files changed, 25 insertions(+), 20 deletions(-) diff --git a/.browserslistrc b/.browserslistrc index ad9f6c9..5217361 100644 --- a/.browserslistrc +++ b/.browserslistrc @@ -14,8 +14,8 @@ FirefoxAndroid >= 115 Opera >= 109 [safari] -Safari >= 16.4 -iOS >= 16.4 +Safari >= 17.0 +iOS >= 17.0 [samsung] Samsung >= 14 diff --git a/gulpfile.js b/gulpfile.js index 68a05c9..1f0d697 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 40a5437..98f233b 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,10 +22,12 @@ "activeTab", "nativeMessaging", "webNavigation", - "", - "declarativeNetRequestWithHostAccess" + "declarativeNetRequestWithHostAccess", + "scripting" ], + "host_permissions": [""], + "icons": { "16": "src/assets/icons/app/icon-16.png", "19": "src/assets/icons/app/icon-19.png", @@ -41,7 +43,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", @@ -74,10 +76,15 @@ ], "web_accessible_resources": [ - "src/content/style.css", - "src/select/pointer.css", - "src/select/index.html", - "src/capture/index.html", - "src/confirm/index.html" + { + "resources": [ + "src/content/style.css", + "src/select/pointer.css", + "src/select/index.html", + "src/capture/index.html", + "src/confirm/index.html" + ], + "matches": ["http://*/*", "https://*/*"] + } ] } diff --git a/src/utils/common.js b/src/utils/common.js index 922da94..19dc5e9 100644 --- a/src/utils/common.js +++ b/src/utils/common.js @@ -375,11 +375,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 0310b49..bc14008 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);