Skip to content

Commit 4ee7a1c

Browse files
Add Element.setHTML() from Sanitizer API
The setHTML() method is defined in the Sanitizer API spec (https://wicg.github.io/sanitizer-api/) but is currently missing from @webref/idl. Browser support: Chrome 146+ (Blink) and Firefox 148+ (Gecko), meeting the 2-engine requirement for inclusion. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 4a002c9 commit 4ee7a1c

File tree

5 files changed

+60
-0
lines changed

5 files changed

+60
-0
lines changed

baselines/dom.generated.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2694,6 +2694,10 @@ interface SecurityPolicyViolationEventInit extends EventInit {
26942694
violatedDirective?: string;
26952695
}
26962696

2697+
interface SetHTMLOptions {
2698+
sanitizer?: Sanitizer | SanitizerConfig | SanitizerPresets;
2699+
}
2700+
26972701
interface ShadowRootInit {
26982702
clonable?: boolean;
26992703
customElementRegistry?: CustomElementRegistry | null;
@@ -13999,6 +14003,12 @@ interface Element extends Node, ARIAMixin, Animatable, ChildNode, NonDocumentTyp
1399914003
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/setAttributeNodeNS)
1400014004
*/
1400114005
setAttributeNodeNS(attr: Attr): Attr | null;
14006+
/**
14007+
* The **`setHTML()`** method of the Element interface provides an XSS-safe method to parse and sanitize a string of HTML and insert it into the DOM as a subtree of the element.
14008+
*
14009+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/setHTML)
14010+
*/
14011+
setHTML(html: string, options?: SetHTMLOptions): void;
1400214012
/**
1400314013
* The **`setHTMLUnsafe()`** method of the Element interface is used to parse HTML input into a DocumentFragment, optionally filtering out unwanted elements and attributes, and those that don't belong in the context, and then using it to replace the element's subtree in the DOM.
1400414014
*

baselines/ts5.5/dom.generated.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2691,6 +2691,10 @@ interface SecurityPolicyViolationEventInit extends EventInit {
26912691
violatedDirective?: string;
26922692
}
26932693

2694+
interface SetHTMLOptions {
2695+
sanitizer?: Sanitizer | SanitizerConfig | SanitizerPresets;
2696+
}
2697+
26942698
interface ShadowRootInit {
26952699
clonable?: boolean;
26962700
customElementRegistry?: CustomElementRegistry | null;
@@ -13986,6 +13990,12 @@ interface Element extends Node, ARIAMixin, Animatable, ChildNode, NonDocumentTyp
1398613990
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/setAttributeNodeNS)
1398713991
*/
1398813992
setAttributeNodeNS(attr: Attr): Attr | null;
13993+
/**
13994+
* The **`setHTML()`** method of the Element interface provides an XSS-safe method to parse and sanitize a string of HTML and insert it into the DOM as a subtree of the element.
13995+
*
13996+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/setHTML)
13997+
*/
13998+
setHTML(html: string, options?: SetHTMLOptions): void;
1398913999
/**
1399014000
* The **`setHTMLUnsafe()`** method of the Element interface is used to parse HTML input into a DocumentFragment, optionally filtering out unwanted elements and attributes, and those that don't belong in the context, and then using it to replace the element's subtree in the DOM.
1399114001
*

baselines/ts5.6/dom.generated.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2691,6 +2691,10 @@ interface SecurityPolicyViolationEventInit extends EventInit {
26912691
violatedDirective?: string;
26922692
}
26932693

2694+
interface SetHTMLOptions {
2695+
sanitizer?: Sanitizer | SanitizerConfig | SanitizerPresets;
2696+
}
2697+
26942698
interface ShadowRootInit {
26952699
clonable?: boolean;
26962700
customElementRegistry?: CustomElementRegistry | null;
@@ -13996,6 +14000,12 @@ interface Element extends Node, ARIAMixin, Animatable, ChildNode, NonDocumentTyp
1399614000
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/setAttributeNodeNS)
1399714001
*/
1399814002
setAttributeNodeNS(attr: Attr): Attr | null;
14003+
/**
14004+
* The **`setHTML()`** method of the Element interface provides an XSS-safe method to parse and sanitize a string of HTML and insert it into the DOM as a subtree of the element.
14005+
*
14006+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/setHTML)
14007+
*/
14008+
setHTML(html: string, options?: SetHTMLOptions): void;
1399914009
/**
1400014010
* The **`setHTMLUnsafe()`** method of the Element interface is used to parse HTML input into a DocumentFragment, optionally filtering out unwanted elements and attributes, and those that don't belong in the context, and then using it to replace the element's subtree in the DOM.
1400114011
*

baselines/ts5.9/dom.generated.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2691,6 +2691,10 @@ interface SecurityPolicyViolationEventInit extends EventInit {
26912691
violatedDirective?: string;
26922692
}
26932693

2694+
interface SetHTMLOptions {
2695+
sanitizer?: Sanitizer | SanitizerConfig | SanitizerPresets;
2696+
}
2697+
26942698
interface ShadowRootInit {
26952699
clonable?: boolean;
26962700
customElementRegistry?: CustomElementRegistry | null;
@@ -13996,6 +14000,12 @@ interface Element extends Node, ARIAMixin, Animatable, ChildNode, NonDocumentTyp
1399614000
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/setAttributeNodeNS)
1399714001
*/
1399814002
setAttributeNodeNS(attr: Attr): Attr | null;
14003+
/**
14004+
* The **`setHTML()`** method of the Element interface provides an XSS-safe method to parse and sanitize a string of HTML and insert it into the DOM as a subtree of the element.
14005+
*
14006+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/setHTML)
14007+
*/
14008+
setHTML(html: string, options?: SetHTMLOptions): void;
1399914009
/**
1400014010
* The **`setHTMLUnsafe()`** method of the Element interface is used to parse HTML input into a DocumentFragment, optionally filtering out unwanted elements and attributes, and those that don't belong in the context, and then using it to replace the element's subtree in the DOM.
1400114011
*

inputfiles/addedTypes.jsonc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,26 @@
213213
"get textContent(): string",
214214
"set textContent(value: string | null)"
215215
]
216+
},
217+
"setHTML": {
218+
"name": "setHTML",
219+
"mdnUrl": "https://developer.mozilla.org/docs/Web/API/Element/setHTML",
220+
"signature": [
221+
{
222+
"param": [
223+
{
224+
"name": "html",
225+
"type": "DOMString"
226+
},
227+
{
228+
"name": "options",
229+
"type": "SetHTMLOptions",
230+
"optional": true
231+
}
232+
],
233+
"type": "undefined"
234+
}
235+
]
216236
}
217237
}
218238
},

0 commit comments

Comments
 (0)