Summary: | Setting outerHTML on child of DocumentFragment throws error | ||||||
---|---|---|---|---|---|---|---|
Product: | WebKit | Reporter: | Nolan Lawson <nlawson> | ||||
Component: | DOM | Assignee: | Nobody <webkit-unassigned> | ||||
Status: | RESOLVED FIXED | ||||||
Severity: | Normal | CC: | ahmad.saleem792, cdumez, jarhar, karlcow, rniwa, webkit-bug-importer | ||||
Priority: | P2 | Keywords: | BrowserCompat, InRadar | ||||
Version: | Safari Technology Preview | ||||||
Hardware: | Unspecified | ||||||
OS: | Unspecified | ||||||
See Also: | https://bugs.webkit.org/show_bug.cgi?id=226808 | ||||||
Attachments: |
|
Description
Nolan Lawson
2022-12-21 12:15:41 PST
Blink error: > Uncaught DOMException: Failed to set the 'outerHTML' property on 'Element': This element's parent is of type '#document-fragment', which is not an element node. > at <anonymous>:1:31 WebKit error: > nomodificationallowederror: Cannot set outerHTML on element because its parent is not an Element Firefox returns: '' https://searchfox.org/wubkat/rev/9ced63bbda6ac9231451b1ca549a16f397e28c78/Source/WebCore/dom/Element.cpp#3554-3589 ``` ExceptionOr<void> Element::setOuterHTML(const String& html) { // The specification allows setting outerHTML on an Element whose parent is a DocumentFragment and Gecko supports this. // However, as of June 2021, Blink matches our behavior and throws a NoModificationAllowedError for non-Element parents. RefPtr parent = parentElement(); if (UNLIKELY(!parent)) { if (!parentNode()) return Exception { NoModificationAllowedError, "Cannot set outerHTML on element because it doesn't have a parent"_s }; return Exception { NoModificationAllowedError, "Cannot set outerHTML on element because its parent is not an Element"_s }; } // … cut for brevity } ``` This was added by Chris Dumez in June 2021 https://bugs.webkit.org/show_bug.cgi?id=226808 https://github.com/WebKit/WebKit/commit/dc33e397532ef8140d9e3fa80b7723e16b863746 I opened a spec issue: https://github.com/whatwg/html/issues/8657 (In reply to Joey Arhar from comment #3) > I opened a spec issue: https://github.com/whatwg/html/issues/8657 As per following, Safari should align with Gecko behavior and should not throw. So I think we might need to revert Chris's patch, which made us match Blink. https://w3c.github.io/DOM-Parsing/#dom-element-outerhtml (In reply to Ahmad Saleem from comment #4) > (In reply to Joey Arhar from comment #3) > > I opened a spec issue: https://github.com/whatwg/html/issues/8657 > > As per following, Safari should align with Gecko behavior and should not > throw. > > So I think we might need to revert Chris's patch, which made us match Blink. > > https://w3c.github.io/DOM-Parsing/#dom-element-outerhtml Yes, looks like Blink agreed on the spec issue to stop throwing so we should do the same. Do you want to do it or should I? PR with revert + not throw error: https://github.com/WebKit/WebKit/pull/15575 Committed 266086@main (b41af45ee409): <https://commits.webkit.org/266086@main> Reviewed commits have been landed. Closing PR #15575 and removing active labels. |