Closed fregante closed 4 months ago
The one that makes the most sense so far is a solution originally posted by @Stvad in https://github.com/fregante/browser-extension-template/issues/75#issuecomment-1124540086
- create 2 manifests (under
/mv2/manifest.json
and/mv3/manifest.json
)- Update paths in them
- add commands in package.json to deal with that
- beware the path change for the resources used via runtime.getURL (https://github.com/transclude-me/extension/commit/78b529ef1af32ba076b3b852f21145f48dfdb1b9#diff-ebd593fb607241eb184425ae1ae5b98a4c44f5ffc0355b2d0e485ad423caa29bR12)
Alternatively, the extension can be changed to use Manifest v2 after the build runs, originally posted in https://github.com/fregante/browser-extension-template/issues/55#issuecomment-1109165720
- Run
npm run build
- In the
distribution/manifest.json
file, revert the same changes you see in #75:
- set
manifest_version
to 2- move
host_permissions
items back topermissions
- restore the previous
background
key- Save that version just for Firefox
Would have liked to use this repo but the lack of Firefox support is a blocker for me. I wouldnt have minded how it was supported but manually editing files just seems too fragile to me - it indicates that Firefox support is not a priority and so I'd expect such hacks to break at short notice :(
@stvad Thanks a lot for sharing your double-manifest approach - is there any chance you could submit a PR to this repo for that? :grin:
@aspiers I was planning to do that, but not sure if I get around it before I want to use this template for another extension 😅
@fregante I believe that since January 17, 2023 (FF 109) V3 Manifests are supported, right?
Do you think it makes sense to reintroduce the polyfill? #88
I believe that since January 17, 2023 (FF 109) V3 Manifests are supported, right?
These issues mean that there's still no way to build a cross-browser extension with a single manifest.json.
Do you think it makes sense to reintroduce the polyfill? #88
The polyfill is no longer needed because Chrome also has promisified APIs in MV3. You can just use chrome.*
APIs in every browser.
You can just use
chrome.*
APIs in every browser.
What about Safari, though? I know the template doesn't officially support Safari, but from what I understand, it'd be easier to build for Safari with the polyfill enabled
You can just use
chrome.*
APIs in every browser.
That includes Safari.
The “polyfill” is something Firefox came up with and it doesn’t officially even support Safari.
By the way, Firefox now accepts MV3 extensions, with the exception that background workers are not supported (background scripts are).
I think that Parcel 2.9 supports setting both background.worker and background.script in the manifest, but Chrome will reject such manifest.
In short, you can now build cross-browser MV3 extensions:
That includes Safari.
My bad! I did a wrong "check" for that :) (Apparently, Safari also supports both promise- and callback-based APIs; link for interested folks)
By the way, Firefox now accepts MV3 extensions
Yup! I decided to change the version to 2
before building for Firefox, though, since what I'm building doesn't require new APIs, and I'd like to support older versions as long as it doesn't add too much overhead.
Mozilla themselves put a compatibility warning when you want to upload an extension :)
Warning: Firefox is adding support for manifest version 3 (MV3) extensions in Firefox 109.0, however, older versions of Firefox are only compatible with manifest version 2 (MV2) extensions. We recommend uploading Manifest V3 extensions as self-hosted for now to not break compatibility for your users.
Maybe we're close here. It seems that Chrome 121 will finally allow background.scripts
in its manifest (just allow, not use):
This means that it will finally be possible restore Firefox support by this template:
I note that https://github.com/Jonghakseo/chrome-extension-boilerplate-react-vite/ (which is another extension template) takes a slightly different approach of specifying the manifest in manifest.js
and then automatically generating manifest.json
from that, in the process converting it to be Firefox-capable when building for Firefox.
Is it worth considering a similar approach here, or are we close enough to being able to craft a single manifest.json
which works with both that it's not worth changing course now?
Given that Chrome 121 is out, this should already work out of the box, just specify background.scripts and make sure you're using the latest parcel version
We're just blocked by Parcel at the moment:
I forgot I already tried it:
If anyone is already using the template and is looking to add support for Firefox, use the latest version of Parcel and restore the background.scripts
array in the manifest file.
npm i -D @parcel/config-webextension@canary parcel@canary
See the PR #97
Firefox doesn't yet support
Manifest v3background workers (update March 2023)_ but this build works exclusively on that. You can use this issue to discuss alternative methods of supporting both Firefox and Chrome.Refer to these links for official MV3 support in Firefox:
latest update: https://blog.mozilla.org/addons/2022/05/18/manifest-v3-in-firefox-recap-next-steps/
provisional migration guide: https://extensionworkshop.com/documentation/develop/manifest-v3-migration-guide/
tracking bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1578284
complete roadmap: https://bugzilla.mozilla.org/showdependencytree.cgi?id=1578284&hide_resolved=1