Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

how do you build a single browser extension and then have compatible firefox/chrome files that are different in what they require for their own thing.

i mean currently we are doing terribly stupid thing. two folders /firefox and /chrome and do the updates manually in both. there should be something easier.



The only really difference sometimes is in the manifest. If you target the webextension api and use the Mozilla poly fill library, your code base does not need to be duplicated at all.

It adds the benefit of being able to use all API calls in a promise based manner instead of needing to use callbacks.

Edit:

To give it a bit more context (although you can find that in other comments I left under this post).

The polyfill library itself: https://github.com/mozilla/webextension-polyfill

Which if included allows you to swap out `chrome` callback based calls for promise based `browser` calls.

So instead of using `chrome.extension.api.call(() => { // callback})` you do something like `await browser.extension.api.call()` with the same results working in both browsers.

Then the only thing where you still need some separation is for the manifest as some keys are Firefox specific and vice versa.

An example you can find here: https://github.com/toolbox-team/reddit-moderator-toolbox

Where all code lives in one directory and there is just two manifest files, one for chrome and firefox: https://github.com/toolbox-team/reddit-moderator-toolbox/tre...

Building is nothing more than rollup packaging the code and grabbing the right manifest to put in the build directory for each browser: https://github.com/toolbox-team/reddit-moderator-toolbox/blo...


https://github.com/PlasmoHQ/plasmo/discussions/803

From my personal experience; most stuff just works cross platform. Currently building an extension and it just works in edge, chrome, Firefox, safari.

You can use poly fill or custom code for when it’s really needed of course


Wxt was mentioned elsewhere in this thread and will build from a single codebase for multiple target browsers. It's built on top of a polyfill from Mozilla. Their docs on that: https://wxt.dev/guide/key-concepts/web-extension-polyfill.ht...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: