Skip to content

Commit 4d6b503

Browse files
committed
Bump addon to manifest v3
Due to manifest incompatibilities between Mozilla and Chrome different packages are built for each browser vendor.
1 parent 149411b commit 4d6b503

File tree

6 files changed

+68
-21
lines changed

6 files changed

+68
-21
lines changed

.github/workflows/release.yaml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ name: Build release
22

33
on:
44
push:
5-
tags:
6-
- 'v*'
7-
branches:
8-
- main
95

106
jobs:
117
main:
@@ -32,15 +28,15 @@ jobs:
3228
run: tools/package
3329

3430
# ref: https://github.com/actions/upload-artifact
35-
- name: Upload build artifact
36-
uses: actions/upload-artifact@v2
31+
- name: Upload build artifacts
32+
uses: actions/upload-artifact@v4
3733
with:
38-
name: json-bookmarks.zip
39-
path: out/json-bookmarks-*.zip
34+
name: json-bookmarks
35+
path: out/
4036

4137
# ref: https://github.com/softprops/action-gh-release
4238
- name: Create release
4339
uses: softprops/action-gh-release@v1
44-
if: startsWith(github.ref, 'refs/tags/')
40+
if: startsWith(github.ref, 'refs/tags/v')
4541
with:
4642
files: out/json-bookmarks-*.zip

background.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
browser.browserAction.onClicked.addListener((tab) => {
1+
// Entrypoint for extension in Mozilla which only supports background script in
2+
// manifest version 3.
3+
browser.action.onClicked.addListener((tab) => {
24
browser.tabs.create({ url: "bookmarks.html" });
3-
});
5+
});

manifest.chrome.json.in

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"manifest_version": 3,
3+
"name": "Json Bookmarks",
4+
"version": "${version}",
5+
"homepage_url": "https://github.com/1nfiniteloop/json-bookmarks",
6+
"description": "Import and export bookmarks between browsers with a json file",
7+
"permissions": ["bookmarks"],
8+
"action": {
9+
"default_title": "JSON Bookmarks"
10+
},
11+
"icons": {
12+
"16": "icon/16.png",
13+
"32": "icon/32.png",
14+
"48": "icon/48.png",
15+
"96": "icon/96.png",
16+
"128": "icon/128.png"
17+
},
18+
"background": {
19+
"service_worker": "service_worker.js",
20+
"type": "module"
21+
}
22+
}

manifest.json.in renamed to manifest.mozilla.json.in

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
{
2-
"manifest_version": 2,
2+
"manifest_version": 3,
33
"name": "Json Bookmarks",
44
"version": "${version}",
55
"homepage_url": "https://github.com/1nfiniteloop/json-bookmarks",
66
"description": "Import and export bookmarks between browsers with a json file",
7+
"browser_specific_settings": {
8+
"gecko": {
9+
"id": "{c46bac9d-a680-46b9-ab8f-15dc7f5a8c71}"
10+
}
11+
},
712
"permissions": ["bookmarks"],
8-
"browser_action": {
13+
"action": {
914
"default_title": "JSON Bookmarks"
1015
},
1116
"icons": {

service_worker.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Entrypoint for extension in Chrome which only supports service workers in
2+
// manifest version 3.
3+
import "./third_party/browser-polyfill.min.js";
4+
5+
browser.action.onClicked.addListener((tab) => {
6+
browser.tabs.create({ url: "bookmarks.html" });
7+
});

tools/package

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2+
set -ue
23

34
readonly ext_name="json-bookmarks"
45

@@ -13,16 +14,30 @@ get_mainfest_version()
1314
echo "${semver#v}"
1415
}
1516

16-
create_manifest()
17+
create_manifest_for()
1718
{
18-
version="$(get_mainfest_version)" envsubst < manifest.json.in > manifest.json
19+
browser_vendor="${1}"
20+
version="$(get_mainfest_version)" envsubst < manifest.${browser_vendor}.json.in > manifest.json
1921
}
2022

21-
create_manifest \
22-
&& mkdir --parents out/ \
23-
&& zip \
23+
create_package_for()
24+
{
25+
browser_vendor="${1}"
26+
create_manifest_for "${browser_vendor}"
27+
mkdir --parents "out/"
28+
zip \
2429
--recurse-paths \
2530
--filesync \
26-
out/${ext_name}-$(get_version).zip \
27-
* \
28-
--exclude .git icon/src/\* out/\* TODO.md manifest.json.in
31+
out/${ext_name}-${browser_vendor}-$(get_version).zip \
32+
bookmark \
33+
icon \
34+
third_party \
35+
*.js \
36+
*.html \
37+
*.css \
38+
LICENSE \
39+
manifest.json
40+
}
41+
42+
create_package_for "mozilla"
43+
create_package_for "chrome"

0 commit comments

Comments
 (0)