[service-workers] Exposing parent client ID for iframe navigations

I've been developing a Service Worker with a fairly straightforward goal of
serving Blobs via a map of URL to Blob. For example the map might associate
"myimage.png" with a Blob of a PNG image. Then this can be served for a
request to example.com/myimage.png. The map is stored per client ID, so
each client has its own independent map of blobs to serve.

The trickier part is I'd like this to propagate through iframes too - so if
a client using that map opens a (same-origin, same path) iframe, then
content in that iframe can also successfully request example.com/myimage.png
.

The main problem I've come across is when a client opens an iframe, it
makes a "navigate" mode fetch with an empty clientId, instead only having a
resultingClientId. However I need to know the clientId of the parent
client, so I can propagate the parent's map of blobs to also apply to the
resultingClientId. But it seems there's no way to get the parent client
from an iframe's FetchEvent.

I can hack around this by passing a clientId in the iframe query string,
but that is further complicated by the fact clients don't appear to know
their own clientIds - only the Service Worker does, so there has to be an
async postMessage to identify it (plus careful management of lifecycles to
make sure the message works).

So it seems there are two things that are missing from SWs:
- the parent clientId for an iframe navigation (why not fill the clientId
field of FetchEvent with that instead of leaving it blank?)
- clients to know their own clientId

I'm not 100% clear but are these not exposed by the spec? And if not, could
they be added?

Ashley

Received on Tuesday, 10 November 2020 11:37:03 UTC