webpack-extension-reloader
webpack-extension-reloader copied to clipboard
Background scripts required?
Type:
- [ ] bug
- [ ] feature
- [ ] enhancement
- [x] question
Environment:
- OS: Windows 10 / Subsystem Linux
- Browser: Firefox
- Library Version:
I'm going to open a PR:
- [ ] yes
- [x] no
Description: I saw this one in the "contribution"-section, and was wondering why a background script is needed?
Note: You must have both background and content scripts for this plugin to work, and they must be specified in separate entry chunks in your webpack config.
Is it that abnormal to build content-scripts only?
I did encounter an error indicating what the statement above when adding the ExtensionReloader with a manifest without background.
Really interested to know why, too! What's more, background scripts make extensions pretty laggy in some cases: https://stackoverflow.com/questions/56500742/why-is-my-google-chrome-extensions-popup-ui-laggy-on-external-monitors-but-not
For reference, here's the section about this in this repo wiki: https://github.com/rubenspgcavalcante/webpack-extension-reloader/wiki/General-Information#wcer-e2
I bumped into same problem and was not actually notified that the background page was missing from manifest...because I didn't provide the optional manifest option.
@nicooprat Really interested to know why
The code that is running in the extension pages is actually really simple.
wer
uses the following template that is injected into all files matching the entries
option.
https://github.com/rubenspgcavalcante/webpack-extension-reloader/blob/4f9aa5e80142709d83c9f20570072d432835cee7/src/middleware/wer-middleware.raw.ts#L39-L89
You can see that the background script connects to WebSocket
instance, and the content scripts and extension pages connect to the background script.
This makes sense as there is only one websocket connection to manage, and the background script takes care of reloading any tabs that have changed content scripts running in them.