(Note: other issues here, and here, are not the same as this)
Hi folks,
I don’t seem to be able to get the ready
property of the ServiceWorkerContainer to resolve:
const serviceWorkerScriptPath = new URL('./worker.js', import.meta.url);
const registration = await navigator.serviceWorker.register(serviceWorkerScriptPath, {
scope: serviceWorkerScriptPath.pathname,
});
if(registration.active) {
console.log("Service worker active"); // <== This is logged
}
console.log(`Waiting for service worker ready...`);
const readyReg = await navigator.serviceWorker.ready; // <== Never resolves
console.log(`Service worker ready`); // <== Never logged
(my worker.js
is not in the root path, so I’m just using the URL
to avoid hard coding the path)
Documentation seems to imply that this ready
promise should resolve when “the current page has an active worker”
Is there some reason this ready
promise would not resolve in this case? I’ve found this whole API to be pretty confusing, and I don’t even know if I need this promise to resolve, but I’m ultimately trying to use the periodicSync API, and all the examples there seem to want this ready
promise to be resolved.