Open gingerchew opened 3 years ago
That's a great idea, it would be really handy to be able to use ESM.
Regarding the first two, I'm not aware of any mechanism that would allow resolving those imports. However if we get the third one working, a bit of string replacement might work well enough...
As far as standard ESM, Chrome doesn't let extensions directly execute "module" scripts, but I have an idea:
Instead of using chrome.devtools.inspectedWindow.eval
to directly run the code, it should be possible to eval a script like:
const s = document.createElement("script")
s.setAttribute("type", "module")
s.innerText = snippetContent
document.body.appendChild(s)
After some quick testing, it seems to work!
However there are a few limitations:
Feel free to take a stab at this if you're interested. Otherwise I'll try it when I get around to it.
Yeah the first two were long shots for sure!
My laptop is in the shop right now, but I'll take a crack at it once I get it back 😊
I haven't been able to get any actual coding started with this, work has been swamped, but I figured I'd share the resources I've found so far.
How to use ES6 import
with Chrome Extension (~late 2018) attached repo
A series of StackOverflow workarounds (some outdated)
runtime.getURL
as a src
that goes to a JS file inside the extension (~Oct. 2018)
background.page
link (~Oct. 2018)globalThis
to workaround the context isolation inherent with web extensions (~Sep. 2019)
globalThis
docsWeb/Service Workers? There's no notes besides that, just something I wrote down I guess
Maybe this will be useful to someone else who comes along and wants to give it a shot too.
I don't know what the limitations are, but it would be nice to be able to use
import
andexport
syntax inside of the snippets. Getting to use SkyPack inside of a snippet or snippet imports, like this.