samrum / vite-plugin-web-extension

A vite plugin for generating cross browser platform, ES module based web extensions.
MIT License
325 stars 32 forks source link

Need synchronous content script import #56

Closed nomi-san closed 1 year ago

nomi-san commented 1 year ago

I found the generated content script index:

(async () => { await import('https://localhost:../.../content.ts') })();

So my content script is injected asynchronously, sometimes it's initialized after DOM although "run_at" prop is set to document_start.

samrum commented 1 year ago

Not sure what the solution would be for dev builds like your code snippet implies. But there may be a way to generate self contained bundles for content scripts that have run_at set to document_start so they're guaranteed to load synchronously.

One possible workaround until then would be to ensure the code that you need to run at document_start is in its own content script that's not using any imports.