Unsanitized HTML parsing methods
The parseHTMLUnsafe() static method of the Document object is used to parse HTML input, optionally filtering unwanted HTML elements and attributes, in order to create a new Document instance.
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 124 | 124 | 128 | 26 | 124 | 26 | |
| 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. | 124 | 124 | 123 | 26 | 124 | 26 |
| The setHTMLUnsafe() method of the ShadowRoot interface can be used to parse HTML input into a DocumentFragment, optionally filtering out unwanted elements and attributes, and then use it to replace the existing tree in the Shadow DOM. | 124 | 124 | 123 | 26 | 124 | 26 |
- This browser only partially implements this feature
- This feature was removed in a later browser version (127)
- Throws error `NS_ERROR_UNEXPECTED` (bug 1887817.)
- This browser only partially implements this feature
- This feature was removed in a later browser version (26)
- If there are custom elements in a declarative shadow root in the parsed HTML, then the elements' constructors and `connectedCallback()` methods are not called (bug 296420).
- This browser only partially implements this feature
- This feature was removed in a later browser version (26)
- If there are custom elements in a declarative shadow root in the parsed HTML, then the elements' constructors and `connectedCallback()` methods are not called (bug 296420).
- This browser only partially implements this feature
- This feature was removed in a later browser version (26)
- If there are custom elements in a declarative shadow root in the parsed HTML, then the elements' constructors and `connectedCallback()` methods are not called (bug 296420).
- This browser only partially implements this feature
- This feature was removed in a later browser version (26)
- If there are custom elements in a declarative shadow root in the parsed HTML, then the elements' constructors and `connectedCallback()` methods are not called (bug 296420).
- This browser only partially implements this feature
- This feature was removed in a later browser version (26)
- If there are custom elements in a declarative shadow root in the parsed HTML, then the elements' constructors and `connectedCallback()` methods are not called (bug 296420).
- This browser only partially implements this feature
- This feature was removed in a later browser version (26)
- If there are custom elements in a declarative shadow root in the parsed HTML, then the elements' constructors and `connectedCallback()` methods are not called (bug 296420).
Syntax
Document.parseHTMLUnsafe(input)
Document.parseHTMLUnsafe(input, options) Use cases
-
Using Unsanitized HTML parsing methods
The parseHTMLUnsafe() static method of the Document object is used to parse HTML input, optionally filtering unwanted HTML elements and attributes, in order to create a new Document instance.
Cautions
- May not be supported in older browsers.
Implementation notes
- Some APIs require a secure context (HTTPS) or user activation. Check the requirements before use.