[w3c/ServiceWorker] clients.claim() with a blob URL worker (#1554)

[claim() in the spec](https://w3c.github.io/ServiceWorker/#clients-claim) doesn’t explicitly say how to handle blob URL workers.

Is a blob URL worker expected to be handled by a SW or not in the following case?

1. Register sw.js
2. Call clients.claim() once a SW is activated
3. Start to call fetch() from a blob URL worker
4. The result of fetch() should be what?

### Blob URL worker

I expect to use the following code as a blob URL worker. 

```
const workerScript =
  `fetch(url)
      .then(response => /* fetch() should be handled by a service worker or not? */ ); 
  `;
const blob = new Blob([workerScript], { type: 'text/javascript' });
const blobUrl = URL.createObjectURL(blob);
// This is a blob URL worker and it exists inside the service worker scope
const worker = new Worker(blobUrl);
```

### Test on Chrome/Firefox/Safari

**Step:**
1. Access [https://clients-claim-blob-url-worker.glitch.me/](https://clients-claim-blob-url-worker.glitch.me/). This access should be the first time. If a SW is already registered, it should be unregistered.
2. If a blob URL worker is handled by a SW after clients.claim() is called, show “OK: blob worker is handled by sw with clients.claim()” in the developer’s console

**Result:**
Chrome: A blob URL worker is handled by a SW after calling clients.claim()
Firefox: A blob URL worker is **NOT** handled by a SW after calling clients.claim()
Safari: A blob URL worker is handled by a SW after calling clients.claim()

Currently, in Chrome and Safari, a blob URL worker after calling claim() is handled by a SW. In Firefox, it’s not handled by a SW.

### Expectation

I expect a blob URL worker client should be handled by a SW after clients.claim() because a blob URL worker can be a client of a service worker based on the [2.4.2 The worker client case](https://w3c.github.io/ServiceWorker/#control-and-use-worker-client).

> the request's URL is a blob URL and the worker client's origin is not the same as the origin of the last item in the worker client's global object's owner set, the worker client's active service worker is set to null.

>  Window clients and worker clients with a blob URL can inherit the active service worker of their creator document or owner

I want to keep the active service worker the same as the owner in claim() too. So I’d like to suggest explicitly updating registration (or only an active service worker?) when the owner's active service worker changes in the blob URL worker case.


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

Received on Friday, 20 November 2020 02:06:51 UTC