Open
Bug 2096516
Opened 5 days ago
Custom element constructor can call document.open() or document.write() on a new owner document during HTML parsing
Categories
(Core :: DOM: HTML Parser, enhancement)
Core
DOM: HTML Parser
Tracking
()
NEW
People
(Reporter: noam.j.rosenthal, Unassigned)
References
Details
While the HTML parser synchronously runs a custom element constructor, document.open() and document.write() must throw InvalidStateError so script cannot wipe out or write into a document mid-parse.
If an earlier script moved an open parent element into another document, Gecko only blocks document.open() and document.write() on the parser's original document, allowing the constructor to wipe out or write into the new owner document while the element is being constructed in it.
Spec PR: https://github.com/whatwg/html/pull/13319
Spec issue: https://github.com/whatwg/html/issues/13317
(<template for> support is tracked in bug 2053472.)
Repro:
<!doctype html>
<iframe id="parserFrame"></iframe>
<iframe id="targetFrame"></iframe>
<script>
const doc = parserFrame.contentDocument;
const otherWin = targetFrame.contentWindow;
otherWin.customElements.define("x-probe", class extends otherWin.HTMLElement {
constructor() {
super();
otherWin.document.open(); // Expected: throws InvalidStateError. Actual: succeeds.
}
});
doc.open();
doc.write(`<div id="d"><script>parent.targetFrame.contentDocument.body.append(document.getElementById("d"));<\/script><x-probe></x-probe></div>`);
doc.close();
</script>
You need to log in
before you can comment on or make changes to this bug.
Description
•