Open socketopp opened 10 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.
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
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.
Is what this adapter does even related to Chrome?
As far as I understand, it only takes care of not shipping any server side logic (like adapter-static), not overwriting the manifest file with an app manifest and (very important) no inline <script>
tags being used to comply with the browser's CSP (which is the same in Firefox).
So couldn't this library just be renamed to sveltekit-adapter-browser-extension
?
What steps are necessary to make this adapter work both with chrome and firefox?