- From: Perry Jiang <notifications@github.com>
- Date: Mon, 16 Dec 2019 13:49:22 -0800
- To: w3c/ServiceWorker <ServiceWorker@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <w3c/ServiceWorker/issues/1491@github.com>
Suppose there's not a registration for `scope` and we run the following: ``` const scope = "./"; navigator.serviceWorker.register("/path/doesnt/exist", { scope }); const registration = await navigator.serviceWorker.getRegistration(scope); ``` Registering a ServiceWorker with an invalid script URL will first place its associated service worker registration in the scope to registration map ([step 6 of Register](https://w3c.github.io/ServiceWorker/#register-algorithm)), but this service worker registration is later evicted from the scope to registration map when [Update fails to fetch the script](https://w3c.github.io/ServiceWorker/#update-algorithm). This all happens before the `navigator.serviceWorker.register` promise settles, but if we don't wait for it to settle (like the snippet above), `getRegistration`/`getRegistrations` can possibly resolve with a "bad" registration (for lack of a better term). Calling [`update`](https://w3c.github.io/ServiceWorker/#service-worker-registration-update) on one of these bad registrations throws, because there won't be a newest worker (step 3), but calling [`unregister`](https://w3c.github.io/ServiceWorker/#navigator-service-worker-unregister), according to the spec, will work fine because it only uses the scope URL of the service worker registration. This seems inconsistent; should there be a way to deal with such registrations or prevent this situation from occurring? @asutherland -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/w3c/ServiceWorker/issues/1491
Received on Monday, 16 December 2019 21:49:24 UTC