Hi, I'm working on a
web extension framework and I want to be able to reload the background's service worker without reloading the entire extension, like when a file changes that was imported by the service worker.
I saw
here, that it was possible through the devtools:
> Also, if you have made changes to the service worker code, you can use
the Update button and skipWaiting to apply the changes immediately.
So I attempted to access the "update" and "skipWaiting" function from the service worker by running the following code in the top level scope of the service worker.
addEventListener('install', (event) => {
const sw = event.target;
const { registration, skipWaiting } = sw;
const update = registration.update;
globalThis.reloadBackground = async () => {
await update();
await skipWaiting();
};
});
The install event fires correctly and I'm able to extract the "update" and "skipWaiting" functions. However, when I call them, I get an error:
TypeError: Failed to execute 'update' on 'ServiceWorkerRegistration': Illegal invocationI assume I can't call these API from inside a web worker, and that's why it's throwing an error. I can't find any docs anywhere about this problem specifically.
Here's a minimal reproduction of this behavior.
Is there a different way to update the service worker without reloading the entire extension?
If not, this would be a great MV3 feature to improve DX. Right now, I reload the entire extension, but that causes any tabs open
to an extension HTML page to close. This is really annoying
when you update a shared util while working on a UI, and suddenly the
tab/popup closes because that util was also
used by the service worker, triggering an extension reload.