Skip to content

Commit 1b8dcb6

Browse files
authored
fix: Make extension using Manifest V3 compatible with Firefox (#1388)
* updated README * changed Manifest.json to scripts * split manifest.json into manifest_chrome.json and manifest_firefox.json * updated build script * updated regular build scripts * fixed CI build * updated zip scripts * updated .gitignore * updated scripts * updated docs * updated CI * revert extension-base's README.md
1 parent eb014d6 commit 1b8dcb6

File tree

8 files changed

+130
-31
lines changed

8 files changed

+130
-31
lines changed

.github/workflows/push-master.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
2525
GH_PAT: ${{ secrets.GH_PAT_BOT }}
2626
GH_RELEASE_GITHUB_API_TOKEN: ${{ secrets.GH_PAT_BOT }}
27-
GH_RELEASE_FILES: master-build.zip,master-src.zip
27+
GH_RELEASE_FILES: master-ff-build.zip,master-ff-src.zip,master-chrome-build.zip,master-chrome-src.zip
2828
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
2929
run: |
3030
corepack enable

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ NOTES.md
1616
.pnp.*
1717
cc-test-reporter
1818
lerna-debug.log*
19-
master-build.zip
20-
master-src.zip
19+
master-chrome-build.zip
20+
master-chrome-src.zip
21+
master-ff-build.zip
22+
master-ff-src.zip
2123
npm-debug.log*
2224
tsconfig.*buildinfo
2325
yarn-debug.log*

README.md

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@ Find out more about how to use the extension as a Dapp developper, cookbook, as
1616

1717
## Firefox installation from source instructions.
1818

19-
1. Uncompress `master-src.zip`
19+
1. Uncompress `master-ff-src.zip`
2020
2. Run `corepack enable` [More information](https://github.com/nodejs/corepack?tab=readme-ov-file#corepack-enable--name)
2121
2. Install dependencies via `yarn install`
2222
3. Build all packages via `yarn build`
23-
- The `/packages/extension/build` directory will contain the exact code used in the add-on, and should exactly match the uncompressed `master-build`.
23+
- The `/packages/extension/build` directory will contain the exact code used in the add-on, and should exactly match the uncompressed `master-ff-build`.
2424

25-
NOTE: If you would like to regenerate the compressed `master-build.zip`, and `master-src.zip` files run: `yarn build:zip`
25+
NOTE: If you would like to regenerate the compressed `master-ff-build.zip`, and `master-ff-src.zip` files run: `yarn build:zip:ff`
2626

27-
## Ensuring `master-build` and `master-src` dont have any diffs (For maintainers)
27+
## Ensuring `master-<TARGET-BROWSER>-build` and `master-<TARGET_BROWSER>-src` dont have any diffs (For maintainers)
2828

2929
Summary: These are the steps to ensure the following builds don't have any diffs so that the firefox review goes smoothly.
3030

31-
1. Run `yarn build`
32-
2. Run `yarn build:zip` - This will generate a `master-build.zip`, and `master-src.zip`.
33-
3. Move `master-src.zip`, and `master-build.zip` to its own enviornment/folder.
34-
4. Uncompress `master-src.zip` to `master-zrc` and inside of `master-src` run `yarn && yarn build`.
35-
5. Uncompress `master-build.zip` to `master-build`.
31+
1. Run `yarn build:ff` or `yarn build:chrome`, depending on your target browser.
32+
2. Run `yarn build:zip:ff` or `yarn build:zip:chrome` - This will generate a `master-<TARGET_BROWSER>-build.zip`, and `master-<TARGET_BROWSER>-src.zip`.
33+
3. Move `master-<TARGET_BROWSER>-src.zip`, and `master-<TARGET_BROWSER>-build.zip` to its own enviornment/folder.
34+
4. Uncompress `master-<TARGET_BROWSER>-src.zip` to `master-src` and inside of `master-src` run `yarn && yarn build:<ff|chrome>`, depending on your target browser.
35+
5. Uncompress `master-<TARGET_BROWSER>-build.zip` to `master-build`.
3636
6. Now we can compare the two builds using `diff`, and `comm`
3737
- Run `diff -qr <path-to-master-build>/master-build <path-to-master-src>/packages/extension/build | sort`
3838
7. To sanity check important files (`background.js`, and `extension.js`) you can also run:
@@ -43,19 +43,22 @@ Summary: These are the steps to ensure the following builds don't have any diffs
4343

4444
Steps to build the extension and view your changes in a browser:
4545

46-
1. Build via `yarn build`
47-
- NOTE: You may need to enable corepack by running `corepack enable`
48-
2. Install the extension
49-
- Chrome:
50-
- go to `chrome://extensions/`
51-
- ensure you have the Development flag set
52-
- "Load unpacked" and point to `packages/extension/build`
53-
- if developing, after making changes - refresh the extension
54-
- Firefox:
55-
- go to `about:debugging#addons`
56-
- check "Enable add-on debugging"
57-
- click on "Load Temporary Add-on" and point to `packages/extension/build/manifest.json`
58-
- if developing, after making changes - reload the extension
46+
1. Chrome:
47+
1. Build via `yarn build:chrome`
48+
- NOTE: You may need to enable corepack by running `corepack enable`
49+
2. Install the extension
50+
- go to `chrome://extensions/`
51+
- ensure you have the Development flag set
52+
- "Load unpacked" and point to `packages/extension/build`
53+
- if developing, after making changes - refresh the extension
54+
2. Firefox
55+
1. Build via `yarn build:ff`
56+
- NOTE: You may need to enable corepack by running `corepack enable`
57+
2. Install the extension
58+
- go to `about:debugging#addons`
59+
- check "Enable add-on debugging"
60+
- click on "Load Temporary Add-on" and point to `packages/extension/build/manifest.json`
61+
- if developing, after making changes - reload the extension
5962
3. When visiting `https://polkadot.js.org/apps/` it will inject the extension
6063

6164
Once added, you can create an account (via a generated seed) or import via an existing seed. The [apps UI](https://github.com/polkadot-js/apps/), when loaded, will show these accounts as `<account name> (extension)`
@@ -69,6 +72,8 @@ The repo is split into a number of packages -
6972
- [extension-dapp](packages/extension-dapp/) - A convenience wrapper to work with the injected objects, simplifying data extraction for any dapp that wishes to integrate the extension (or any extension that supports the interface)
7073
- [extension-inject](packages/extension-inject/) - A convenience wrapper that allows extension developers to inject their extension for use by any dapp
7174

75+
It also contains a [`manifest_chrome.json`](packages/extension/manifest_chrome.json) file which contains the manifest configuration for Chrome and another [`manifest_firefox.json`](packages/extension/manifest_firefox.json) with the configuration for Firefox, for compatibility reasons, and a dummy `manifest.json` file that's only used by the build.
76+
7277
## Dapp developers
7378

7479
The actual in-depth technical breakdown is given in the next section for any dapp developer wishing to work with the raw objects injected into the window. However, convenience wrappers are provided that allows for any dapp to use this extension (or any other extension that conforms to the interface) without having to manage any additional info.

package.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,20 @@
2323
"packages/*"
2424
],
2525
"scripts": {
26-
"build": "polkadot-dev-build-ts && yarn build:zip && yarn build:rollup",
26+
"build": "yarn build:chrome && yarn build:ff",
2727
"build:before": "yarn build:i18n",
28+
"build:chrome": "cp ./packages/extension/manifest_chrome.json ./packages/extension/manifest.json && polkadot-dev-build-ts && yarn build:zip:chrome && yarn build:rollup",
29+
"build:ff": "cp ./packages/extension/manifest_firefox.json ./packages/extension/manifest.json && polkadot-dev-build-ts && yarn build:zip:ff && yarn build:rollup",
2830
"build:i18n": "i18next-scanner --config i18next-scanner.config.cjs",
2931
"build:release": "polkadot-ci-ghact-build",
3032
"build:rollup": "polkadot-exec-rollup --config",
31-
"build:zip": "yarn build:zip:dst && yarn build:zip:src",
32-
"build:zip:dst": "rm -rf ./master-build.zip && cd packages/extension/build && zip -r -FS ../../../master-build.zip .",
33-
"build:zip:src": "rm -rf ./master-src.zip && zip -r -x '*build/*' -x '*node_modules*' -FS ./master-src.zip packages .editorconfig eslint.config.js rollup.config.js CHANGELOG.md CONTRIBUTING.md i18next-scanner.config.cjs LICENSE package.json README.md tsconfig.json yarn.lock .yarnrc.yml tsconfig.base.json tsconfig.build.json tsconfig.eslint.json tsconfig.webpack.json",
33+
"build:zip": "yarn build:zip:chrome && yarn build:zip:ff",
34+
"build:zip:chrome": "cp ./packages/extension/manifest_chrome.json ./packages/extension/manifest.json && yarn build:zip:dst:chrome && yarn build:zip:src:chrome",
35+
"build:zip:dst:chrome": "rm -rf ./master-chrome-build.zip && cd packages/extension/build && zip -r -FS ../../../master-chrome-build.zip .",
36+
"build:zip:dst:ff": "rm -rf ./master-ff-build.zip && cd packages/extension/build && zip -r -FS ../../../master-ff-build.zip .",
37+
"build:zip:ff": "cp ./packages/extension/manifest_firefox.json ./packages/extension/manifest.json && yarn build:zip:dst:ff && yarn build:zip:src:ff",
38+
"build:zip:src:chrome": "rm -rf ./master-chrome-src.zip && zip -r -x '*build/*' -x '*node_modules*' -FS ./master-chrome-src.zip packages .editorconfig eslint.config.js rollup.config.js CHANGELOG.md CONTRIBUTING.md i18next-scanner.config.cjs LICENSE package.json README.md tsconfig.json yarn.lock .yarnrc.yml tsconfig.base.json tsconfig.build.json tsconfig.eslint.json tsconfig.webpack.json",
39+
"build:zip:src:ff": "rm -rf ./master-ff-src.zip && zip -r -x '*build/*' -x '*node_modules*' -FS ./master-ff-src.zip packages .editorconfig eslint.config.js rollup.config.js CHANGELOG.md CONTRIBUTING.md i18next-scanner.config.cjs LICENSE package.json README.md tsconfig.json yarn.lock .yarnrc.yml tsconfig.base.json tsconfig.build.json tsconfig.eslint.json tsconfig.webpack.json",
3440
"clean": "polkadot-dev-clean-build",
3541
"lint": "polkadot-dev-run-lint",
3642
"postinstall": "polkadot-dev-yarn-only",

packages/extension-base/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ Functions, classes and other utilities used in `@polkadot/extension`. These incl
77

88
They are primarily meant to be used in `@polkadot/extension`, and can be broken without any notice to cater for `@polkadot/extension`'s needs.
99

10-
They are exported here if you wish to use part of them in the development of your own extension. Don't forget to add `process.env.EXTENSION_PREFIX` to separate ports and stores from the current extension's ones.
10+
They are exported here if you wish to use part of them in the development of your
11+
own extension. Don't forget to add `process.env.EXTENSION_PREFIX` to separate
12+
ports and stores from the current extension's ones.

packages/extension/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"manifest_version": 3,
88
"permissions": ["storage", "tabs", "alarms"],
99
"background": {
10-
"service_worker": "background.js",
10+
"scripts": ["background.js"],
1111
"type": "module"
1212
},
1313
"action": {
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"author": "polkadot.{js}",
3+
"description": "Manage your Polkadot accounts outside of dapps. Injects the accounts and allows signing transactions for a specific account.",
4+
"homepage_url": "https://github.com/polkadot-js/extension",
5+
"name": "polkadot{.js} extension",
6+
"short_name": "polkadot{.js}",
7+
"manifest_version": 3,
8+
"permissions": ["storage", "tabs", "alarms"],
9+
"background": {
10+
"service_worker": "background.js",
11+
"type": "module"
12+
},
13+
"action": {
14+
"default_title": "polkadot{.js}",
15+
"default_popup": "index.html"
16+
},
17+
"content_scripts": [{
18+
"js": ["content.js"],
19+
"matches": ["http://*/*", "https://*/*"],
20+
"run_at": "document_start"
21+
}],
22+
"icons": {
23+
"16": "images/icon-16.png",
24+
"32": "images/icon-32.png",
25+
"48": "images/icon-48.png",
26+
"64": "images/icon-64.png",
27+
"128": "images/icon-128.png"
28+
},
29+
"web_accessible_resources": [
30+
{
31+
"resources": [
32+
"page.js"
33+
],
34+
"matches": [
35+
"*://*/*"
36+
]
37+
}
38+
],
39+
"content_security_policy": {
40+
"extension_pages": "script-src 'self' 'wasm-unsafe-eval'; object-src 'self'"
41+
}
42+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"author": "polkadot.{js}",
3+
"description": "Manage your Polkadot accounts outside of dapps. Injects the accounts and allows signing transactions for a specific account.",
4+
"homepage_url": "https://github.com/polkadot-js/extension",
5+
"name": "polkadot{.js} extension",
6+
"short_name": "polkadot{.js}",
7+
"manifest_version": 3,
8+
"permissions": ["storage", "tabs", "alarms"],
9+
"background": {
10+
"scripts": ["background.js"],
11+
"type": "module"
12+
},
13+
"action": {
14+
"default_title": "polkadot{.js}",
15+
"default_popup": "index.html"
16+
},
17+
"content_scripts": [{
18+
"js": ["content.js"],
19+
"matches": ["http://*/*", "https://*/*"],
20+
"run_at": "document_start"
21+
}],
22+
"icons": {
23+
"16": "images/icon-16.png",
24+
"32": "images/icon-32.png",
25+
"48": "images/icon-48.png",
26+
"64": "images/icon-64.png",
27+
"128": "images/icon-128.png"
28+
},
29+
"web_accessible_resources": [
30+
{
31+
"resources": [
32+
"page.js"
33+
],
34+
"matches": [
35+
"*://*/*"
36+
]
37+
}
38+
],
39+
"content_security_policy": {
40+
"extension_pages": "script-src 'self' 'wasm-unsafe-eval'; object-src 'self'"
41+
}
42+
}

0 commit comments

Comments
 (0)