Re: [w3c/ServiceWorker] Provide a one-line way to listen for a waiting Service Worker (#1222)

In a comment on #1247 that I think was directed at this proposal, @jakearchibald wrote:
> A promise doesn't really work in this case, as many service workers can pass through the waiting phase during the life of a page.

If a promise is entirely off the table, then that entails that the best hope for an improvement here is for `statechange` events to bubble up to the registration; that's issue #1247.

```js
navigator.serviceWorker.ready.then(function(reg) {
  if (reg.waiting) return alertUser(reg);
  return reg.addEventListener('statechange', function(e) {
    if (e.target.state === 'installed') alertUser(reg);
  });
});
```

As I said above in this thread, this isn't what I'd prefer, but at this point, I'm going to give up on my favorite thing in favor of something (_anything_) getting done here.

-- 
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/1222#issuecomment-463344039

Received on Wednesday, 13 February 2019 19:55:40 UTC