by falafelite on 2/12/22, 4:40 PM with 51 comments
As someone new to writing extensions and trying to write something for at least both Firefox and Chrome, how should I go about it? Or do I have to accept writing separate background.js files, separate manifest.json files, etc.?
by bambax on 2/12/22, 5:22 PM
So maybe you can just wait? Although it may take a long time.
Also, FF said in May of last year (2021) that they would start accepting V3 extensions in "early 2022" [0] but I don't know if they have kept their schedule.
[0] https://blog.mozilla.org/addons/2021/05/27/manifest-v3-updat...
by klntsky on 2/12/22, 5:35 PM
I managed to have it done with only a few places where I branch on navigator.vendor, but If I wanted to ship different versions to AMO and CWS, I'd make use of something like DefinePlugin[1] for webpack to include/exclude code based on build target.
[0] https://github.com/mozilla/webextension-polyfill/
[1] https://github.com/webpack/docs/wiki/list-of-plugins#definep...
by bunya017 on 2/12/22, 5:34 PM
[0] https://quasar.dev/quasar-cli/developing-browser-extensions/...
by gnicholas on 2/12/22, 8:56 PM
by isodev on 2/12/22, 5:45 PM
by azeirah on 2/12/22, 5:13 PM
Otherwise, what I did to support v2 for firefox and v3 for chrome is fairly straightforward.
You write your code and compile it all with webpack into a single file, all you have to do is write two manifest files which are 70% the same.
There are some incompatibilities between v2 and v3, like v3 having promises for the extension api. I wrote wrappers for the non-promise versions myself (I'm sure there are packages that do this for you). Webpack takes care of a lot of the other inconsistencies like module support.
Also note that you should 100% make sure that you follow the guidelines for how to structure a plugin for the v3 version, ie that it is event based. Your background scripts will be shut down randomly every now and then and you will get insanely buggy code when running in v3 if you don't follow the guidelines strictly.
For now, I just ship v2 to both firefox and chrome, it's easiest for me. Note though I have had this plugin for a couple years now, maybe it's not possible to create _new_ plugins with v2.
by dotproto on 2/15/22, 6:00 PM
First up, no, you don't need to maintain two completely different code bases. I'd recommend having a separate manifest.json for each browser or having a build step generate the per-browser manifest.json. A lot of the manifest changes are relatively small, like splitting "host_permissions" out from "permissions" and should be automatable. For example, a build step would merge these two arrays for the MV2 manifest.
As for your background scripts, if possible I'd recommend limiting the JS capabilities you use to the intersection of what all browsers support.
- Chrome supports background service workers - Safari supports event pages and I believe has service worker support in beta builds of their OSs - Firefox supports persistent background pages
In other words, target the capabilities available in both worker and page contexts. You'll also want to design your background logic to embrace ephemerality. This is required by Chrome, but it also benefits Firefox users in that it helps keep the browser responsive.
Best of luck!
by Glench on 2/12/22, 6:40 PM
by L1quid on 2/12/22, 9:42 PM
It lets me use Ruby in my html/css/js files, and also sass in the css, letting us use one codebase for all target browsers.
Definitely a work in progress, and lacks the exciting auto-reload functionality of other similar projects, but it works for us. Issuing one build command and having an extension for all our target browsers is pretty nice.
by onassar on 2/12/22, 6:32 PM
This will become harder when mv3 gets pushed out broadly, but it's def not pretty :(
by dewey on 2/12/22, 6:58 PM
My initial plan to have a private package that I just import in my extensions but turns out you can't really do that as imports don't work. Right now I'm kinda stuck in copy pasting code back and fort hand keeping a V2 Extension for Firefox (and Safari) and a V3 Extension for Chrome. I also keep separate manifest files as they have different features.
[1] https://blog.notmyhostna.me/posts/building-web-extensions-fo...
by porkbrain on 2/12/22, 10:05 PM
While I can't share the framework, I have designed a code base architecture which allows incremental abstraction of APIs, uses typed message passing between scripts (with errors being propagated too), unit and integration tests or automation for compilation of the extension for each store according to their respective rules. This architecture is my IP and although I don't actively work with extensions on day to day basis anymore, I still do take on contracts to lay foundations or migrate existing projects.
If this is something you're interested in, reach out to me via email in my bio.
by BugWatch on 2/13/22, 4:10 AM
I remember making a cursory search a year ago, and hardly found anything remarkable. (Might have been a case of Google's-bad-search-results syndrome.)
by kiru_io on 2/12/22, 8:44 PM
by Bilal_io on 2/12/22, 9:35 PM
Can someone provide a source for this please?
My company has an extension with the old manifest V1 and I'd like to propose upgrading or getting rid of the extension all together.
by zerr on 2/12/22, 8:46 PM
by gnicholas on 2/12/22, 10:45 PM
by Animats on 2/12/22, 8:47 PM
by nextlevelwizard on 2/12/22, 7:17 PM