[w3c/ServiceWorker] SharedWorker script interception after redirects (#1289)

Suppose '/redirect' redirects to '/in-scope/shared-worker.js', and the page does new SharedWorker('/redirect'). And there is a service worker with scope 'in-scope'.

In Chrome today, you end up with a shared worker script served by the service worker.

In Firefox today, you end up with a shared worker script served from network from 'in-scope/shared-worker.js' .

Also, subresource requests from the shared worker are intercepted by the service worker for both browsers. So I think the implementation intent is for the initial request and each redirect to look up the appropriate service worker to intercept that URL, and finally to make the SharedWorker client be controlled if the final URL was in-scope.

I have a basic test at https://sw-shared-worker.glitch.me/ showing this.

Somewhat related, `self.location` in Chrome is 'redirect' and 'in-scope/shared-worker.js' in Firefox.

The spec seems to say to intercept only for the initial request URL, because service worker registration matching is based on "Creation URL" in [2.4 Selection and Use](https://w3c.github.io/ServiceWorker/#selection): "That is, the service worker client attempts to consult a service worker registration whose scope url matches its creation URL." Creation URL is a concept from HTML. It looks like Creation URL is set at [set up a worker environment settings object](https://html.spec.whatwg.org/multipage/workers.html#script-settings-for-workers), which is called from "[run a worker](https://html.spec.whatwg.org/multipage/workers.html#run-a-worker)" in Step 9, which is before any network fetch which happens in Step 13.

I've not really tested other redirect hooks like AppCache.

I was looking at this for our new "servicified" service worker architecture. I'm not very motivated to invest a lot of time in this since Shared Workers don't have much usage or browser support, but will try to implement something reasonable.

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

Received on Monday, 19 March 2018 05:52:49 UTC