Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how does service worker interact with html imports? #1095

Closed
wanderview opened this issue Mar 29, 2017 · 5 comments
Closed

how does service worker interact with html imports? #1095

wanderview opened this issue Mar 29, 2017 · 5 comments

Comments

@wanderview
Copy link
Member

I know chrome is the only browser to implement html imports at the moment, but I found myself wondering a bit how it interacts with service workers:

  1. Is the service worker controller inherited from the master document similar to the inherited controller for srcdoc iframes?
  2. Or is each imported document considered a separate non-subresource load and controlled independently? I assume this is not the case since window.navigator.serviceWorker.controller would be inconsistent across the documents.
  3. I assume all the imported documents map to the same Client since they have a shared global. What is the creation URL of that Client? I assume its the master document URL.
  4. What happens if an import calls navigator.serviceWorker.register()? Do the scope rules and restrictions get applied based on the import URL or the master document URL?
@mfalken
Copy link
Member

mfalken commented Mar 29, 2017

I'm not very familiar with HTML Imports. I think all our SW + HTML Imports test coverage is in this file:
https://cs.chromium.org/chromium/src/third_party/WebKit/LayoutTests/http/tests/serviceworker/fetch-request-html-imports.html

@TakayoshiKochi
Copy link
Member

I am not very familiar with Service Worker either ;)
Here's what I understand, but could be wrong.

As navigator.serviceWorker interface is shared between the master document and its imported document, I think it is natural to assume the service worker controller is shared among all imports with the master document.

FWIW, document.URL is same for all (the master document and all dependent imports).
An idiomatic way to access from script inside an import is to use document.currentScript.ownerDocument. So document.currentScript.ownerDocument.URL returns the real URL for the import in which script is running.

So using any service worker APIs in the master document or imports doesn't make any difference basically - though CORS handling etc. could have some subtlety.

So answers would be (be careful - I haven't verified):

  1. YES
  2. NO
  3. the master document URL
  4. the master document URL

I don't think it's worth spending time to update specs for HTML Imports or Service Worker for clarification of this, but do think it is enough to let the current Chrome behavior be de facto standard (as no other vendor cares). @wanderview do you have any particular concern (e.g. security) for this uncertainty of HTML Imports + Service Worker integration?

@wanderview
Copy link
Member Author

@wanderview do you have any particular concern (e.g. security) for this uncertainty of HTML Imports + Service Worker integration?

No. It just caught my eye because I know we have had poor support for the "inherited service worker" case with <iframe srcdoc>. It got me wondering how html imports works in chrome and if that behavior matched what people would expect.

If the answer to (1) is "yes", then I have a follow-on question:

If clients.claim() starts controlling the master document, do the imported documents correctly start getting controlled as well? For example, if an imported document <script> does setInterval(_ => fetch(url, 1000) will those fetches start getting controlled when the master document is claimed in chrome?

@jakearchibald
Copy link
Contributor

FWIW I agree with @TakayoshiKochi's answers. An HTML import isn't a separate client like an iframe.

@jakearchibald
Copy link
Contributor

Closing, especially given that HTML imports are effectively deprecated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants