[w3c/ServiceWorker] Chrome: serviceWorker.ready() resolves before service worker is active after unregistering (#1505)

This seems like this issue: https://github.com/w3c/ServiceWorker/issues/1139 but I am wondering why I only see this error on Chrome?

My scenario is this:

I click a button to register which does the following:
```
navigator.serviceWorker.register('./sw.js', { scope: './' }).then(...)
navigator.serviceWorker.ready.then(registration => {
    registration.pushManager.subscribe...
    ....
}
```
Then I later click a button to unregister which does the following:
```
navigator.serviceWorker.getRegistrations().then(registrations => {
    for (let registration of registrations) {
        registeration.unregister()
    }
})
```

Then, I re-click the button to register. But this time the the `.ready()` resolves before the `.register()` resolves leading to an error when subscribing for push (no active service worker).

When I tried this same scenario on Firefox, it worked as expected. If it is a bug on Chrome, is there any workaround I could do to wait until the registration is ready before subscribing?

-- 
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/1505

Received on Wednesday, 19 February 2020 19:14:05 UTC