browser-extension-template icon indicating copy to clipboard operation
browser-extension-template copied to clipboard

Firefox support discussion (MV2, MV3)

Open fregante opened this issue 3 years ago • 15 comments

Firefox doesn't yet support ~~Manifest v3~~ background 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

fregante avatar May 12 '22 09:05 fregante

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)

fregante avatar May 12 '22 09:05 fregante

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

  1. Run npm run build
  2. In the distribution/manifest.json file, revert the same changes you see in #75:
  • set manifest_version to 2
  • move host_permissions items back to permissions
  • restore the previous background key
  1. Save that version just for Firefox

fregante avatar May 12 '22 09:05 fregante

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 :(

psiinon avatar May 23 '22 10:05 psiinon

@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 avatar May 23 '22 16:05 aspiers

@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 😅

Stvad avatar May 23 '22 18:05 Stvad

@fregante I believe that since January 17, 2023 (FF 109) V3 Manifests are supported, right?

  • Release Notes: https://www.mozilla.org/en-US/firefox/109.0/releasenotes/
  • Migration Guide: https://extensionworkshop.com/documentation/develop/manifest-v3-migration-guide/

Do you think it makes sense to reintroduce the polyfill? #88

milangress avatar Mar 22 '23 14:03 milangress

I believe that since January 17, 2023 (FF 109) V3 Manifests are supported, right?

  1. Firefox still does not support background workers: https://bugzilla.mozilla.org/show_bug.cgi?id=1573659
  2. Chrome refuses to load a manifest that specifies both backgrounds scripts and workers.
    • https://github.com/w3c/webextensions/issues/282#issuecomment-1570045164
  3. Parcel doesn't recognize background scripts in MV3 yet (edit: fixed)
    • https://github.com/parcel-bundler/parcel/issues/8785

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.

fregante avatar Mar 22 '23 15:03 fregante

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

f-person avatar Jun 11 '23 07:06 f-person

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.

fregante avatar Jun 11 '23 11:06 fregante

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:

  • set both background.worker and background.script in your manifest
  • remove background.script before opening the extension in Chrome.

fregante avatar Jun 11 '23 11:06 fregante

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.

f-person avatar Jun 11 '23 11:06 f-person

Maybe we're close here. It seems that Chrome 121 will finally allow background.scripts in its manifest (just allow, not use):

  • https://github.com/w3c/webextensions/issues/282#issuecomment-1786857524

This means that it will finally be possible restore Firefox support by this template:

  • [ ] Add a background script for Firefox
  • [ ] Restore all mentions to Firefox support in the docs and deployment

Schedule for Chrome 121:

Tue, Jan 23, 2024

fregante avatar Dec 10 '23 10:12 fregante

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?

aspiers avatar Jan 31 '24 13:01 aspiers

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

fregante avatar Jan 31 '24 13:01 fregante

We're just blocked by Parcel at the moment:

  • https://github.com/parcel-bundler/parcel/issues/9458

I forgot I already tried it:

  • https://github.com/fregante/browser-extension-template/pull/97

fregante avatar Feb 01 '24 10:02 fregante