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

should document.open() inherit the controller? #1313

Open
wanderview opened this issue May 15, 2018 · 5 comments
Open

should document.open() inherit the controller? #1313

wanderview opened this issue May 15, 2018 · 5 comments

Comments

@wanderview
Copy link
Member

What should happen if the current window is controlled by a service worker and script then calls document.open()? Should the service worker controller by inherited or not?

Per the html spec a new window should be created for document.open(). AFAIK, though, only firefox implements this and there is some discussion around aligning with the behavior where the window is preserved. @annevk has been looking at this recently.

Even with that in mind, though, should the controller be preserved or cleared?

I wrote a demo here:

https://sw-document-open.glitch.me/

The iframe shows its controller after the document.open(). You can also open the console to see if the "dynamic.js" script load inserted by the document.write() is intercepted.

Results are:

  • Firefox: no controller, no dynamic.js fetch event
  • Chrome: controller is inherited, dynamic.js fetch event is received
  • Safari: controller is inherited, dynamic.js fetch event is received
  • Edge: no controller, no dynamic.js fetch event

What is the desired behavior? My gut feeling is that it should probably be inherited similar to what we do for about:blank iframes, etc.

@wanderview wanderview changed the title should document.open() inherit the controller should document.open() inherit the controller? May 15, 2018
@annevk
Copy link
Member

annevk commented May 15, 2018

Aside: is the controller associated with a document or a Window object?

I'd argue for preserving it. The less we reset during document.open() the better.

@wanderview
Copy link
Member Author

wanderview commented May 15, 2018

Aside: is the controller associated with a document or a Window object?

No. The service worker controller is part of the environment:

https://html.spec.whatwg.org/#concept-environment-active-service-worker

Edit: The "no" is to the question about document. Its part of the window since its associated with the environment (I believe).

@annevk
Copy link
Member

annevk commented May 15, 2018

Okay, note that the global never changes with initial about:blank, but the document does. And with document.open() the document never changes and ideally it also never changes the global (but currently does in the specification and Firefox).

@wanderview
Copy link
Member Author

Right. We have a related issue to the controller inheritance for about:blank when the final load is not controlled:

#1232

I don't think it impact this, but wanted to mention it as a current issue with inheritance.

@futurist
Copy link

futurist commented May 15, 2018

From a developer's point of view, I believe most of developer want to keep current environment if they wrote document.open, and want to patch something instead of recreate for all.

At lease, all the global vars/functions are preserved, and the code may depend on the inherit behavior if they depend on some features in the global env.

For me, the global env should include both window & service worker, but I don't read the specs deeply, maybe mismatched with that.

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

3 participants