Appending an iframe to its own document throws HierarchyRequestError

Confirmed Issue #9184253 • Assigned to Bo C.

Details

Created
Oct 4, 2016
Privacy
This issue is public.
Found in
  • Microsoft Edge
  • Internet Explorer
Standard affected
DOM Standard

Reports
Reported by 1 person

Sign in to watch or report this issue.

Steps to reproduce

<iframe id=x></iframe>
<script>
x.contentDocument.body.appendChild(x);
</script>

In Edge this throws HierarchyRequestError. This violates the DOM spec. Other browsers don’t throw.

Nothing prevents the iframe element from being moved to its own document (about:blank is same-origin). So the iframe element is removed from its original document.

https://dom.spec.whatwg.org/#dom-node-appendchild

When an iframe is removed from a document, its browsing context disappears. So the child document does not have a browsing context when the iframe element is inserted into it. Therefore the iframe, after the move, does not have a new child browsing context (there’s no infinite recursion happening).

[[
When an iframe element is inserted into a document that has a browsing context, the user agent must create a new browsing context, set the element’s nested browsing context to the newly-created browsing context, and then process the iframe attributes for the "first time".

When an iframe element is removed from a document, the user agent must discard the element’s nested browsing context, if it is not null, and then set the element’s nested browsing context to null.
]]
https://html.spec.whatwg.org/multipage/embedded-content.html#the-iframe-element

web-platform-test PR:
https://github.com/w3c/web-platform-tests/pull/3744

Run test:
http://w3c-test.org/html/semantics/embedded-content/the-iframe-element/iframe-append-to-child-document.html

Attachments

0 attachments

    Comments and activity

    • Microsoft Edge Team

      Changed Assigned To to “Brad E.”

      Changed Assigned To to “Travis L.”

      Changed Assigned To from “Travis L.” to “Bo C.”

      Changed Status to “Confirmed”

    You need to sign in to your Microsoft account to add a comment.

    Sign in