w3c / w3c/ServiceWorker

should document.open() inherit the controller?

Open
#1,313 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

TPAC2026
Dominant language
Bikeshed
Stars
3.6k
Forks
324
Avg merge
14d 22h
Merged PRs (30d)
1

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the HTML spec behavior for document.open() and compare it with the service worker controller results in the linked demo. Check how the iframe controller and the dynamic.js fetch event behave in Firefox, Chrome, Safari, and Edge; done means the intended controller behavior is decided and documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
html, javascript
Domain
documentation, web-dev
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.