From 3c386c36f6f1d177ae2ed400668f21ea2ada5db3 Mon Sep 17 00:00:00 2001 From: Luke Warlow Date: Mon, 10 Jun 2024 04:05:54 +0200 Subject: [PATCH] Add initial content for setHTMLUnsafe and parseHTMLUnsafe (#33492) * Add initial content for setHTMLUnsafe and parseHTMLUnsafe * Remove erroneous secure context banner * Apply suggestions from (my own) code review * Updates to parseHTMLUnsafe(), parent topic, cross link * Apply suggestions from code review * Element.setHTMLUnsafe * ShadowRoot.setHTMLUnsafe() * Apply suggestions from code review - remove untrusted Co-authored-by: Luke Warlow --------- Co-authored-by: Hamish Willee --- files/en-us/web/api/document/index.md | 8 +++ .../document/parsehtmlunsafe_static/index.md | 47 ++++++++++++++ .../api/domparser/parsefromstring/index.md | 2 + files/en-us/web/api/element/index.md | 4 +- .../web/api/element/sethtmlunsafe/index.md | 64 +++++++++++++++++++ files/en-us/web/api/shadowroot/index.md | 2 + .../web/api/shadowroot/sethtmlunsafe/index.md | 51 +++++++++++++++ 7 files changed, 177 insertions(+), 1 deletion(-) create mode 100644 files/en-us/web/api/document/parsehtmlunsafe_static/index.md create mode 100644 files/en-us/web/api/element/sethtmlunsafe/index.md create mode 100644 files/en-us/web/api/shadowroot/sethtmlunsafe/index.md diff --git a/files/en-us/web/api/document/index.md b/files/en-us/web/api/document/index.md index 1a334d06ac8b03e..6592b38d8db382c 100644 --- a/files/en-us/web/api/document/index.md +++ b/files/en-us/web/api/document/index.md @@ -305,6 +305,14 @@ The `Document` interface for HTML documents inherit from the {{DOMxRef("HTMLDocu - {{DOMxRef("Document.writeln()")}} - : Writes a line of text in a document. +## Static methods + +_This interface also inherits from the {{DOMxRef("Node")}} and {{DOMxRef("EventTarget")}} interfaces._ + +- {{domxref("Document/parseHTMLUnsafe_static", "Document.parseHTMLUnsafe()")}} + - : Creates a new `Document` object from a string of HTML without performing sanitization. + The string may contain declarative shadow roots. + ## Events Listen to these events using `addEventListener()` or by assigning an event listener to the `oneventname` property of this interface. In addition to the events listed below, many events can bubble from {{domxref("Node", "nodes", "", "nocode")}} contained in the document tree. diff --git a/files/en-us/web/api/document/parsehtmlunsafe_static/index.md b/files/en-us/web/api/document/parsehtmlunsafe_static/index.md new file mode 100644 index 000000000000000..d5ef29ba0b04591 --- /dev/null +++ b/files/en-us/web/api/document/parsehtmlunsafe_static/index.md @@ -0,0 +1,47 @@ +--- +title: "Document: parseHTMLUnsafe() static method" +short-title: parseHTMLUnsafe() +slug: Web/API/Document/parseHTMLUnsafe_static +page-type: web-api-static-method +browser-compat: api.Document.parseHTMLUnsafe_static +--- + +{{APIRef("DOM")}} + +The **`parseHTMLUnsafe()`** static method of the {{domxref("Document")}} object is used to parse a string of HTML, which may contain [declarative shadow roots](/en-US/docs/Web/HTML/Element/template#declarative_shadow_dom), in order to create a new {{domxref("Document")}} instance. + +The suffix "Unsafe" in the method name indicates that, while `