w3c / ServiceWorker

Service Workers
https://w3c.github.io/ServiceWorker/
Other
3.63k stars 315 forks source link

consider how clients.claim() should work with srcdoc iframes #1093

Open wanderview opened 7 years ago

wanderview commented 7 years ago

Currently the spec says that srcdoc iframes should inherit their parent's controlling service worker. When a window client is controlled via clients.claim(), should we also claim any immediate child srcdoc iframes?

jakearchibald commented 7 years ago

I think so. Does the srcdoc client inherit the client url from the parent? If so, it should just work.

wanderview commented 7 years ago

I think so. Does the srcdoc client inherit the client url from the parent? If so, it should just work.

No. I think the srcdoc client.url should be 'about:blank'.

jungkees commented 7 years ago

I think it's 'about:srcdoc'. I agree 'clients.claim()' should also claim the child iframes that inherited the parent's controller.

wanderview commented 7 years ago

Oh, so it is. A dynamically created iframe with no src or srcdoc has a URL of about:blank. In any case, the explicit inheritance needs to be spec'd here since the URL matching won't work.

wanderview commented 7 years ago

Blob URL iframes may be an issue as well. And blob URL dedicated workers.

jakearchibald commented 7 years ago
humphd commented 7 years ago

I wonder if I'm hitting this. I'm trying to rewrite https://thimble.mozilla.org to use SW for serving all user generated content. I currently do it with Blob URLs and rewriting of relative path URLs to Blob URLs, but it can't handle things like JS dynamically doing things.

Given a page running on http://localhost:8000/dist/hosted.html, and a SW running at http://localhost:8000/dist/sw.js. I've got various request/response pairs already placed in CacheStorage, for example http://localhost:8000/dist/vfs/image.png. I then create an HTML page, and a Blob URL for it:

<html>
    <head>
        <title>This will load in the iframe</title>
        <base href="http://localhost:8000/dist/vfs">
    </head>
    <body>
        <img src="http://localhost:8000/dist/vfs/image.png">
    </body>
</html>

I then add <iframe src="blob:http://localhost:8000/e843c3b9-5da7-4cbf-b782-ba3c6fafdbd9"> in the page running at http://localhost:8000/dist/hosted.html. My SW is set up to return anything it matches in the caches, and I can see that there is a cache entry for http://localhost:8000/dist/vfs/image.png.

When the iframe loads, I get 404s for http://localhost:8000/dist/vfs/image.png. However, if I just try to load that same URL in my address bar, it loads no problem.

At first I assumed it was something else I was doing, but I now suspect the fact that it's running in a page via the Blob URL. I had hoped that by it being a child iframe, and setting the <base> I might be able to inherit the parent's controller, too. Or perhaps there is some CORS issue I don't know about, and need in my cached headers?

I'm thinking I should abandon the Blob URL for the iframe as well, and also load that from cache; it was just surprising to me that this didn't work, and I wanted to investigate.

Thanks for any thoughts, even if only to tell me that I'm wrong.