Skip to content

Add HTML setters features - #4318

Open
tunetheweb wants to merge 6 commits into
web-platform-dx:mainfrom
tunetheweb:html-setters
Open

Add HTML setters features#4318
tunetheweb wants to merge 6 commits into
web-platform-dx:mainfrom
tunetheweb:html-setters

Conversation

@tunetheweb

Copy link
Copy Markdown
Contributor

Fixes #4117

Due for launch in Chrome 154

Spec updates still WIP but have added commented out lines for them in the meantime.

@github-actions github-actions Bot added the feature definition Creating or defining new features or groups of features. label Sep 4, 2026
Comment thread features/html-setters.yml
@@ -0,0 +1,44 @@
name: HTML positional setters
description: The setHTML(), replaceWithHTML(), beforeHTML(), prependHTML(), appendHTML() and afterHTML() methods, and unsafe equivalents, insert HTML into an existing tree.
spec: https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-parsing-and-serialization

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually waiting on whatwg/html#12753 before it's added to this section of the HTML spec. But that's pretty close now and is just waiting on some final reviews.

@@ -0,0 +1,43 @@
name: HTML streaming setters
description: The streamHTML(), streamReplaceWithHTML(), streamBeforeHTML(), streamPrependHTML(), streamAppendHTML() and streamAfterHTML() methods, and unsafe equivalents, return writeable streams that incrementally insert HTML into an existing tree.
spec: https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-parsing-and-serialization

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for this one that's waiting on whatwg/html#12758 also pretty close to landing

Comment thread features/html-setters.yml Outdated
@@ -0,0 +1,44 @@
name: HTML positional setters
description: The setHTML(), replaceWithHTML(), beforeHTML(), prependHTML(), appendHTML() and afterHTML() methods, and unsafe equivalents, insert HTML into an existing tree.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description: The setHTML(), replaceWithHTML(), beforeHTML(), prependHTML(), appendHTML() and afterHTML() methods, and unsafe equivalents, insert HTML into an existing tree.
description: The `setHTML()`, `replaceWithHTML()`, `beforeHTML()`, `prependHTML()`, `appendHTML()` and `afterHTML()` methods, and unsafe equivalents, insert HTML into an existing tree.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to say what these are methods on?

Also, there seems to be some overlap with sanitizer and parse-html-unsafe - some of the methods mentioned here are in the other features. I'm not quite sure what the solution is there.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a bit of discussion on this in the issue (#4117) with @ddbeck .

Only the setHTMLUnsafe and setHTMLUnsafe overlap, which is why I've only added api.Element.setHTMLUnsafe.options_runscripts_parameter here. Think of this feature as expanding on that initial implementation, both in those methods and in creating additional, adjacent methods.

Personally I disagree with setHTML being part of Sanitzer. It was the first use of Sanitizing so added as part of that, but it's more a user of it, than part of the API IMHO (as are these).

Ultimately I'd like to see both those methods brought in here, but while this is early, and Chrome-only, and those are supported by other browsers that's likely to cause more confusion. So, while I agree this is not ideal, I think it's the best option for now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to say what these are methods on?

Sorry forgot to answer this bit. That was @ddbeck 's original suggestion in #4117 (comment).

Personally I think this is a bit verbose:

The setHTML(), replaceWithHTML(), beforeHTML(), prependHTML(), appendHTML() and afterHTML() methods of the CharacterData, Element, DocumentType, and ShadowRoot (and their unsafe equivalents), insert HTML into an existing tree.

It's also not accurate since only half of them apply to all and the other half to just Element and ShadowRoot.

I think it's fairly obvious these are DOM methods and apply to the appropriate places and MDN, the spec or other documentation sites are the best place to get this level of detail.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could say "DOM methods" if preferred?

The setHTML(), replaceWithHTML(), beforeHTML(), prependHTML(), appendHTML() and afterHTML() DOM methods, and their unsafe equivalents, insert HTML into an existing tree.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also also take a slightly more aggressive stance here and:

  • Move setHTML out of the sanitizer.yml feature and into here (leaving the rest of the Sanitzer API in there). As I say it's not quite right being in there IMHO. Firefox would still show as supporting the Sanitizer API, but no longer show support of setHTML since it would now be part of this wider feature that they haven't fully implemented.
  • Move setHTMLUnsafe out of parse-html-unsafe into here (leaving api.Document.parseHTMLUnsafe_static in there). Firefox and Safari would still show as supporting parseHTMLUnsafe but no longer show support of setHTMLUnsafe since it would now be part of this wider feature that they haven't fully implemented.

That would be less confusing and ultimately where we want to go longer term.

Then longer, longer term this feature gets folded into dom anyway.

WDYT?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the feature composition as you have it makes sense- sorry for rehashing existing conversations!

We could say "DOM methods" if preferred?

The setHTML(), replaceWithHTML(), beforeHTML(), prependHTML(), appendHTML() and afterHTML() DOM methods, and their unsafe equivalents, insert HTML into an existing tree.

This sounds good to me. And you're right that this isn't the place for the amount of specificity needed to full describe the API.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated description to "DOM methods".

I'm actually more and more thinking we should just bite the bullet and move setHTML and setHTMLUnsafe. Especially as we are merging these into the HTML spec, so this is not just some Chrome proposal. I've added that to this PR in de89f56 so you can see what that looks like. Let's also see what @ddbeck thinks here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature definition Creating or defining new features or groups of features.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTML enhanced setter and streaming methods

2 participants