Re: [w3c/ServiceWorker] Promise on navigator.serviceWorker that resolves when page is controlled (#799)

> controlling



> @jeffposnick
> 
> > there could be a new promise, perhaps named .controlled
> 
> This could be implemented as:
> 
> ```js
> const p = new Promise(r => {
>   if (navigator.serviceWorker.controller) return r();
>   navigator.serviceWorker.addEventListener('controllerchange', e => r());
> });
> ```
> 
> I think we need more evidence that this is a common enough pattern to add to the platform.

this not work when chrome refresh
I use this 
```
<!DOCTYPE html><html><head><meta content="width=device-width,initial-scale=1" name="viewport"><meta charset="UTF-8"><script>(async S=>{await S.register("/S.js");S.controller?eval(await(await fetch("/_")).text()):location.reload()})(navigator.serviceWorker)</script></head><body></body></html>

```


-- 
Reply to this email directly or view it on GitHub:
https://github.com/w3c/ServiceWorker/issues/799#issuecomment-2132434741
You are receiving this because you are subscribed to this thread.

Message ID: <w3c/ServiceWorker/issues/799/2132434741@github.com>

Received on Sunday, 26 May 2024 23:40:00 UTC