fregante / browser-extension-template

📕 Barebones boilerplate with Parcel 2, options handler and auto-publishing
788 stars 75 forks source link

Firefox support discussion (MV2, MV3) #78

Closed fregante closed 4 months ago

fregante commented 2 years ago

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:

fregante commented 2 years 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

fregante commented 2 years ago

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
  3. Save that version just for Firefox
psiinon commented 2 years ago

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

aspiers commented 2 years ago

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

Stvad commented 2 years ago

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

milangress commented 1 year ago

@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

fregante commented 1 year ago

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.
  3. Parcel doesn't recognize background scripts in MV3 yet (edit: fixed)

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.

f-person commented 1 year ago

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

fregante commented 1 year ago

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 commented 1 year ago

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:

f-person commented 1 year ago

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.

fregante commented 11 months ago

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:

Schedule for Chrome 121:

Tue, Jan 23, 2024

aspiers commented 9 months ago

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?

fregante commented 9 months ago

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 commented 9 months ago

We're just blocked by Parcel at the moment:

I forgot I already tried it:

fregante commented 4 months ago

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