antfu / vitesse-webext

⚡️ WebExtension Vite Starter Template

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Content scripts in dev mode don't work in Firefox

caudurodev opened this issue · comments

Great work on this project! But since I mainly develop in FF I thought I would mention that there is an issue specific to FF which works fine in chromium browsers. If dev mode is enabled (HMR) the content scripts don't even load in the page. Build works fine in FF. Without delete manifest.content_scripts the development mode works, but requires the extension to be reloaded manually.

  1. FF browser.tabs.executeScript() requires file path starts with '/'.
  2. FF will cache files in memory until the extension is reloaded, instead of reading them from hard drive every time.

OK - so might be worth noting this in the readme or comment in files somewhere? I've switched over to a chromium browser for now to be able to take advantage of all the features in this repo.

@caudurodev for now, you can install web-ext and run web-ext run --source-dir ./extension --browser-console --target=firefox-desktop from project root. web-ext will reload firefox extension automatically.

I'm unable to get content scripts working in dev mode in Chrome, too.

Able to reproduce by:

  1. Cloning
  2. Installing dependencies
  3. Running the dev script
  4. Running start:chromium
  5. Seeing that the content script is not being included
  6. Running the build script
  7. Running start:chromium
  8. Seeing that the content script IS being included

@mattrothenberg In my test, web-ext has a delay in loading extension, if open a url at browser startup quickly(often occurs when web-ext run with --start-url command), the extension's background script is not yet executed, so contentscript is not injected. You can open the url in dev mode, wait a moment to refresh the page and see if the extension loads properly.

If it is not the case above, you can open the chrome://extensions/ page, enable developer mode, and click the view dist/background/index.html console tab to see if there is an error message.