Skip to content

Commit 3fecc20

Browse files
committed
feat: upgrade to Manifest V3 in Safari
BREAKING CHANGE: browser versions older than Safari 17 are no longer supported
1 parent eb7bbdd commit 3fecc20

File tree

5 files changed

+20
-16
lines changed

5 files changed

+20
-16
lines changed

.browserslistrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ FirefoxAndroid >= 115
1414
Opera >= 109
1515

1616
[safari]
17-
Safari >= 16.4
18-
iOS >= 16.4
17+
Safari >= 17
18+
iOS >= 17
1919

2020
[samsung]
2121
Samsung >= 14

gulpfile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const isProduction = process.env.NODE_ENV === 'production';
2424
const enableContributions =
2525
(process.env.ENABLE_CONTRIBUTIONS || 'true') === 'true';
2626

27-
const mv3 = ['chrome', 'edge', 'opera'].includes(targetEnv);
27+
const mv3 = ['chrome', 'edge', 'opera', 'safari'].includes(targetEnv);
2828

2929
const distDir = path.join(__dirname, 'dist', targetEnv);
3030

@@ -51,7 +51,7 @@ function js(done) {
5151
function html() {
5252
const htmlSrc = ['src/**/*.html'];
5353

54-
if (mv3) {
54+
if (mv3 && !['safari'].includes(targetEnv)) {
5555
htmlSrc.push('!src/background/*.html');
5656
}
5757

src/assets/manifest/safari.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"manifest_version": 2,
2+
"manifest_version": 3,
33
"name": "__MSG_extensionName__",
44
"description": "__MSG_extensionDescription__",
55
"version": "0.1.0",
@@ -9,7 +9,7 @@
99

1010
"browser_specific_settings": {
1111
"safari": {
12-
"strict_min_version": "16.4"
12+
"strict_min_version": "17.0"
1313
}
1414
},
1515

@@ -22,9 +22,11 @@
2222
"activeTab",
2323
"nativeMessaging",
2424
"webNavigation",
25-
"<all_urls>"
25+
"scripting"
2626
],
2727

28+
"host_permissions": ["<all_urls>"],
29+
2830
"icons": {
2931
"16": "src/assets/icons/app/icon-16.png",
3032
"19": "src/assets/icons/app/icon-19.png",
@@ -40,7 +42,7 @@
4042
"1024": "src/assets/icons/app/icon-1024.png"
4143
},
4244

43-
"browser_action": {
45+
"action": {
4446
"default_icon": {
4547
"16": "src/assets/icons/app/icon-16.png",
4648
"19": "src/assets/icons/app/icon-19.png",

src/utils/common.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@ async function executeScript({
2222
code = ''
2323
}) {
2424
if (mv3) {
25-
const params = {target: {tabId, allFrames}, world};
25+
const params = {target: {tabId}, world};
2626

27-
if (!allFrames) {
27+
// Safari 17: allFrames and frameIds cannot both be specified,
28+
// fixed in Safari 18.
29+
if (allFrames) {
30+
params.target.allFrames = true;
31+
} else {
2832
params.target.frameIds = frameIds;
2933
}
3034

@@ -323,11 +327,9 @@ function getDayPrecisionEpoch(epoch) {
323327
}
324328

325329
function isBackgroundPageContext() {
326-
const backgroundUrl = mv3
327-
? browser.runtime.getURL('/src/background/script.js')
328-
: browser.runtime.getURL('/src/background/index.html');
329-
330-
return self.location.href === backgroundUrl;
330+
return self.location.href.startsWith(
331+
browser.runtime.getURL('/src/background/')
332+
);
331333
}
332334

333335
function getExtensionDomain() {

webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const isProduction = process.env.NODE_ENV === 'production';
1414
const enableContributions =
1515
(process.env.ENABLE_CONTRIBUTIONS || 'true') === 'true';
1616

17-
const mv3 = ['chrome', 'edge', 'opera'].includes(targetEnv);
17+
const mv3 = ['chrome', 'edge', 'opera', 'safari'].includes(targetEnv);
1818

1919
const provideExtApi = !['firefox', 'safari'].includes(targetEnv);
2020

0 commit comments

Comments
 (0)