Skip to content

Commit

Permalink
feat: upgrade to Manifest V3 in Safari
Browse files Browse the repository at this point in the history
BREAKING CHANGE: browser versions older than Safari 17
are no longer supported
  • Loading branch information
dessant committed Sep 26, 2024
1 parent 4a03948 commit f46b754
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 20 deletions.
4 changes: 2 additions & 2 deletions .browserslistrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ FirefoxAndroid >= 115
Opera >= 109

[safari]
Safari >= 16.4
iOS >= 16.4
Safari >= 17.0
iOS >= 17.0

[samsung]
Samsung >= 14
4 changes: 2 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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');
}

Expand Down
27 changes: 17 additions & 10 deletions src/assets/manifest/safari.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"manifest_version": 2,
"manifest_version": 3,
"name": "__MSG_extensionName__",
"description": "__MSG_extensionDescription__",
"version": "0.1.0",
Expand All @@ -9,7 +9,7 @@

"browser_specific_settings": {
"safari": {
"strict_min_version": "16.4"
"strict_min_version": "17.0"
}
},

Expand All @@ -22,10 +22,12 @@
"activeTab",
"nativeMessaging",
"webNavigation",
"<all_urls>",
"declarativeNetRequestWithHostAccess"
"declarativeNetRequestWithHostAccess",
"scripting"
],

"host_permissions": ["<all_urls>"],

"icons": {
"16": "src/assets/icons/app/icon-16.png",
"19": "src/assets/icons/app/icon-19.png",
Expand All @@ -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",
Expand Down Expand Up @@ -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://*/*"]
}
]
}
8 changes: 3 additions & 5 deletions src/utils/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit f46b754

Please sign in to comment.