write-active-document.html expects document.write() on an inactive document to be ignored; the spec has no such check and no engine ignores it

Open Beginner friendly
#65,402 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
html, javascript

Research direction

Read html/webappapis/dynamic-markup-insertion/document-write/write-active-document.html and compare its first assertion with the reported behavior and the HTML Standard steps described in the issue. Update the expectation for writing to the inactive document to match the observed result, then run that test; it is done when the test passes and its second half still checks the active but not fully active document case.

Written by the indexing model from the issue text.

Description

html/webappapis/dynamic-markup-insertion/document-write/write-active-document.html navigates an iframe away with a link click to a data: URL. In the frame's next load event it calls write() on the frame's previous document, which is now inactive, and expects the write to be ignored:

// This is a write to an inactive document
child1.write('WRITE HAPPENED');
assert_equals(child1.body.lastChild.tagName, "IFRAME");

Neither the document write steps nor the document open steps in the HTML Standard check whether the document is active or fully active. Their only early returns are:

  • write steps 8-9: the active parser was aborted; or the insertion point is undefined and the unload counter or the ignore-destructive-writes counter is nonzero.
  • open steps 5-7: an active parser whose script nesting level is nonzero, a nonzero unload counter, or the active parser was aborted.

None of these applies to child1, whose parser finished before the navigation. So the write runs the document open steps on child1, which replace all of its children, and the written text becomes the body's last child. The only part of the open steps restricted to fully active documents is step 12, the URL and history update.

That is what every engine does. lastChild is the text node, so its tagName is undefined:

assert_equals: expected (string) "IFRAME" but got (undefined) undefined

The message is the same in all six wpt.fyi runs aligned at 71b58bb191. Stable: Chrome 158.0.8127.36 (run 5091530419994624), Firefox 160.0.1 (5102456061820928), Safari 27.2 (5121161130934272). Experimental: Chrome 160.0.8168.0 (5165587534446592), Firefox 162.0a1 (5188734707040256), Safari Technology Preview 256 (5096019650674688).

https://wpt.fyi/results/html/webappapis/dynamic-markup-insertion/document-write/write-active-document.html?run_id=5091530419994624&run_id=5102456061820928&run_id=5121161130934272

The test's second half agrees with the spec: a write to an active but not fully active document replaces its content.

Suggested fix

Expect the write to happen, for example assert_equals(child1.body.textContent, "WRITE HAPPENED"). If writes to inactive documents should be ignored, that needs a whatwg/html issue first. As written, the test asserts behaviour that no specification states and no engine has.

Dominant language
HTML
Stars
6.3k
Forks
4.1k
Avg merge
17h 20m
Merged PRs (30d)
841

Getting set up

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.

More from web-platform-tests/wpt

All issues in web-platform-tests/wpt

Similar issues

More Testing & QA issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.