michmich112 / sveltekit-adapter-chrome-extension

Sveltekit adapter for making chrome extensions
MIT License
108 stars 17 forks source link

Develop for Firefox and Chrome #34

Open socketopp opened 5 months ago

socketopp commented 5 months ago

What steps are necessary to make this adapter work both with chrome and firefox?

Jack-Barry commented 3 months ago

I'm new here, just getting started trying to build a cross-browser extension with SvelteKit, so take this all with a big fat grain of salt.

From the looks of it in the README, you'd have several <PLATFORM>_manifest.json files in static, only one of which will be used each time you build.

In svelte.config.js, the adapter function accepts a manifest attribute as part of its options. So you'd likely need to do something like have an environment variable for PLATFORM_TARGET, set it to "chrome" or "firefox", then have the manifest set accordingly, maybe the pages and/or assets attributes as well (if you want to output to different folders for each version).

Doesn't have to work exactly like that, but that seems like how to do it. Aside from that, may want to look into mozilla/webextention-polyfill for cross-browser compatible plugin APIs.

michmich112 commented 3 months ago

It should work for all chromium based clients but @Jack-Barry's response is accurate. We could make a generic fork for all browsers with polyfills

Jack-Barry commented 3 months ago

I've got a somewhat crude version of this working now leveraging unplugin-auto-import, not sure if it'll pan out all the way though.

I came up with the approach by taking a look at chrome-ext-mv3-starter which is using Vite.

As of now, there's a build warning and VS Code complains that browser is not defined, but when I tested the extension in both Chrome and Firefox it works fine. I haven't had any luck once browser referenced in a script tag, though, so I'll probably end up digging into that whole thing later.