From b8c02818cb56bc6c4233afbade8d9fa39eae6f02 Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Thu, 2 Jul 2026 10:50:23 +0100 Subject: [PATCH 1/4] createParserOptions --- source | 298 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 145 insertions(+), 153 deletions(-) diff --git a/source b/source index a6b93957fa3..61453fece6e 100644 --- a/source +++ b/source @@ -4994,6 +4994,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
  • data
  • TrustedScriptURL
  • get trusted type compliant string
  • +
  • get trusted type compliant input
  • @@ -125727,8 +125728,12 @@ enum DOMParserSupportedType {
  • Let target be this's template contents if this is a template element; otherwise this.

  • -
  • Set and filter HTML given target, html, - options, and true.

  • +
  • Let fragment be the result of invoking the fragment parsing algorithm + steps given target, html, options, and "remove".

  • + +
  • If fragment is non-null, then replace + all with fragment within target.

  • @@ -125738,8 +125743,12 @@ enum DOMParserSupportedType { steps are:

      -
    1. Set and filter HTML given this, html, - options, and true.

    2. +
    3. Let fragment be the result of invoking the fragment parsing algorithm + steps given this, html, options, and "remove".

    4. + +
    5. If fragment is non-null, then replace + all with fragment within this.

    @@ -125749,17 +125758,21 @@ enum DOMParserSupportedType { method steps are:

      -
    1. Let compliantHTML be the result of invoking the get trusted type compliant string algorithm with

      Let (compliantHTML, compliantOptions) be the result of invoking the + get trusted type compliant input algorithm with TrustedHTML, this's relevant global - object, html, "Element setHTMLUnsafe", and "script".

    2. + object, html, options, and "Element + setHTMLUnsafe".

    3. Let target be this's template contents if this is a template element; otherwise this.

    4. -
    5. Set and filter HTML given target, compliantHTML, - options, and false.

    6. +
    7. Let fragment be the result of invoking the fragment parsing algorithm + steps given target, compliantHTML, compliantOptions, and + "keep".

    8. + +
    9. If fragment is non-null, then replace + all with fragment within target.

    @@ -125769,14 +125782,18 @@ enum DOMParserSupportedType { options) method steps are:

      -
    1. Let compliantHTML be the result of invoking the get trusted type compliant string algorithm with

      Let (compliantHTML, compliantOptions) be the result of invoking the + get trusted type compliant input algorithm with TrustedHTML, this's relevant global - object, html, "ShadowRoot setHTMLUnsafe", and "script".

    2. + object, html, options, and "ShadowRoot + setHTMLUnsafe".

      + +
    3. Let fragment be the result of invoking the fragment parsing algorithm + steps given this, compliantHTML, compliantOptions, and + "keep".

    4. -
    5. Set and filter HTML given this, compliantHTML, - options, and false.

    6. +
    7. If fragment is non-null, then replace + all with fragment within this.

    @@ -125820,11 +125837,11 @@ enum DOMParserSupportedType { method steps are:

      -
    1. Let compliantHTML be the result of invoking the get trusted type compliant string algorithm with

      Let (compliantHTML, compliantOptions) be the result of invoking the + get trusted type compliant input algorithm with TrustedHTML, this's relevant global - object, html, "Document parseHTMLUnsafe", and "script".

    2. + object, html, options, and "Document + parseHTMLUnsafe".

    3. Let document be a new Document, whose DOMParserSupportedType { compliantHTML.

    4. Let sanitizer be the result of calling get a sanitizer instance from - options with options and false.

    5. + options with compliantOptions and false.

    6. Call sanitize on document with sanitizer and false.

    7. @@ -125957,21 +125974,66 @@ enum DOMParserSupportedType {

      The fragment parsing algorithm steps, given an Element or - DocumentFragment target, a string markup, and an optional - parser scripting mode scriptingMode (default Inert), are:

      + DocumentFragment target, a string markup, a dictionary + options, and unsafeMarkupHandling, which is one of "remove", "keep", or "legacy", + are:

        -
      1. Assert: scriptingMode is either Inert or Fragment. +

      2. Let context be target if target is an + Element; otherwise target's host.

      3. + +
      4. Assert: context is non-null.

      5. + +
      6. +

        If all of the following are true:

        +
          +
        • unsafeMarkupHandling is "remove";
        • +
        • context's local name is + "script"; and
        • +
        • context's namespace is the + HTML namespace or the SVG namespace,
        • +
        +

        then return null.

        +
      7. + +
      8. Let safe be true if unsafeMarkupHandling is "remove"; otherwise false.

      9. + +
      10. Let sanitizer be the result of calling getting a sanitizer from options given safe.

      11. -
      12. If target's node document is an XML +

      13. Let scriptingMode be Inert.

      14. + +
      15. +

        If options["runScripts"] + is true:

        +
          +
        1. Assert: unsafeMarkupHandling is not "remove".

        2. + +
        3. Set scriptingMode to Fragment.

        4. +
        +
      16. + +
      17. Let allowDeclarativeShadowRoots be false if unsafeMarkupHandling is + "legacy"; otherwise true.

      18. + +
      19. If unsafeMarkupHandling is "legacy" and + target's node document is an XML document, then return the result of invoking the XML fragment parsing algorithm given target and markup.

      20. -
      21. Return the result of the HTML fragment parsing algorithm given - target, markup, false, and scriptingMode.

      22. +
      23. Let fragment be the result of the HTML fragment parsing algorithm + given target, markup, allowDeclarativeShadowRoots, and + scriptingMode.

      24. + +
      25. Sanitize fragment given sanitizer and + safe.

      26. + +
      27. Return fragment.

      @@ -125992,29 +126054,18 @@ enum DOMParserSupportedType { are:

        -
      1. Let compliantString be the result of invoking the get trusted type compliant string algorithm with TrustedHTML, this's relevant global - object, the given value, "Element innerHTML", and "script".

      2. - -
      3. Let target be this.

      4. - -
      5. -

        If target is a template element, then set target to the - template element's template contents (a - DocumentFragment).

        - -

        Setting innerHTML on a - template element will replace all the nodes in its template contents - rather than its children.

        -
      6. +
      7. Let (compliantString, compliantOptions) be the result of invoking + the get trusted type compliant input algorithm with + TrustedHTML, this's relevant global + object, the given value, a new SetHTMLUnsafeOptions dictionary, and "Element innerHTML".

      8. -
      9. Let fragment be the result of invoking the fragment parsing algorithm - steps with target and compliantString.

      10. +
      11. Let fragment be the result of invoking the fragment parsing algorithm + steps given this, compliantString, compliantOptions, + and "legacy".

      12. -
      13. Replace all with fragment - within target.

      14. +
      15. Replace all with fragment within + this.

      @@ -126023,14 +126074,15 @@ enum DOMParserSupportedType { steps are:

        -
      1. Let compliantString be the result of invoking the get trusted type compliant string algorithm with TrustedHTML, this's relevant global - object, the given value, "ShadowRoot innerHTML", and "script".

      2. +
      3. Let (compliantString, compliantOptions) be the result of invoking + the get trusted type compliant input algorithm with + TrustedHTML, this's relevant global + object, the given value, a new SetHTMLUnsafeOptions dictionary, and "ShadowRoot innerHTML".

      4. Let fragment be the result of invoking the fragment parsing algorithm - steps with this and compliantString.

      5. + steps given this, compliantString, compliantOptions, + and "legacy".

      6. Replace all with fragment within this.

      7. @@ -126088,30 +126140,31 @@ enum DOMParserSupportedType { are:

          -
        1. Let compliantString be the result of invoking the get trusted type compliant string algorithm with TrustedHTML, this's relevant global - object, the given value, "Element outerHTML", and "script".

        2. +
        3. Let (compliantString, compliantOptions) be the result of invoking + the get trusted type compliant input algorithm with + TrustedHTML, this's relevant global + object, the given value, a new SetHTMLUnsafeOptions dictionary, and "Element outerHTML".

        4. -
        5. Let parent be this's parent.

        6. +
        7. Let parent be this's parent.

        8. -
        9. If parent is null, return. There would be no way to obtain a - reference to the nodes created even if the remaining steps were run.

        10. +
        11. If parent is null, return. There would be no way to obtain a reference to the + nodes created even if the remaining steps were run.

        12. -
        13. If parent is a Document, throw a - "NoModificationAllowedError" DOMException.

        14. +
        15. If parent is a Document, throw a + "NoModificationAllowedError" DOMException.

        16. -
        17. If parent is a DocumentFragment, set parent to the - result of creating an element given this's - node document, "body", and the HTML - namespace.

        18. +
        19. If parent is a DocumentFragment, set parent to the + result of creating an element given this's + node document, "body", and the HTML + namespace.

        20. -
        21. Let fragment be the result of invoking the fragment parsing algorithm - steps given parent and compliantString.

        22. +
        23. Let fragment be the result of invoking the fragment parsing algorithm + steps given parent, compliantString, compliantOptions, + and "legacy".

        24. -
        25. Replace this with - fragment within this's parent.

        26. +
        27. Replace this with + fragment within this's parent.

        @@ -126165,11 +126218,11 @@ enum DOMParserSupportedType { string)
        method steps are:

          -
        1. Let compliantString be the result of invoking the get trusted type compliant string algorithm with TrustedHTML, this's relevant global - object, string, "Element insertAdjacentHTML", and "script".

        2. +
        3. Let (compliantString, compliantOptions) be the result of invoking + the get trusted type compliant input algorithm with + TrustedHTML, this's relevant global + object, the given value, a new SetHTMLUnsafeOptions dictionary, and "Element insertAdjacentHTML".

        4. Let context be null.

        5. @@ -126212,10 +126265,9 @@ enum DOMParserSupportedType { data-x="">body
          ", and the HTML namespace.

          -
        6. -

          Let fragment be the result of invoking the fragment parsing algorithm - steps with context and compliantString.

          -
        7. +
        8. Let fragment be the result of invoking the fragment parsing algorithm + steps given context, compliantString, compliantOptions, + and "legacy".

        9. Use the first matching item from this list:
          @@ -126291,11 +126343,12 @@ enum DOMParserSupportedType { method steps are:

            -
          1. Let compliantString be the result of invoking the get - trusted type compliant string algorithm with TrustedHTML, this's relevant global - object, string, "Range createContextualFragment", and - "script".

          2. +
          3. Let (compliantString, compliantOptions) be the result of invoking + the get trusted type compliant input algorithm with + TrustedHTML, this's relevant global + object, string, a new SetHTMLUnsafeOptions whose runScripts is true, and "Range createContextualFragment".

          4. Let node be this's start node.

          5. @@ -126327,9 +126380,9 @@ enum DOMParserSupportedType { data-x="">body", and the HTML namespace.

            -
          6. Return the result of invoking the fragment parsing algorithm steps with - element, compliantString, and Fragment.

          7. +
          8. Return the result of invoking the fragment parsing algorithm steps given + element, compliantString, compliantOptions, and "legacy".

          @@ -127694,67 +127747,6 @@ dictionary SanitizerConfig {

          Sanitization algorithms

          -
          -

          To set and filter HTML, given an Element or - DocumentFragment target, a string html, a - dictionary options, and a boolean safe:

          - -
            -
          1. Let context be target if target is an - Element; otherwise target's host.

          2. - -
          3. Assert: context is non-null.

          4. - -
          5. -

            If all of the following are true:

            - -
              -
            • safe;

            • - -
            • context's local name is - "script"; and

            • - -
            • context's namespace is the - HTML namespace or the SVG namespace,

            • -
            - -

            then return.

            -
          6. - -
          7. Let sanitizer be the result of calling getting a sanitizer from options given safe.

          8. - -
          9. Let scriptingMode be Inert.

          10. - -
          11. -

            If options["runScripts"] - is true:

            - -
              -
            1. Assert: safe is false.

            2. - -
            3. Set scriptingMode to Fragment.

              -
            -
          12. - -
          13. -

            Let fragment be the result of invoking the HTML fragment parsing - algorithm given target, html, true, and - scriptingMode.

            - -

            Scripts in fragment will only execute once inserted into - target.

            -
          14. - -
          15. Sanitize fragment given sanitizer and - safe.

          16. - -
          17. Replace all with fragment within - target.

          18. -
          -

          To get a sanitizer instance from options from a dictionary options with a From 90a398292f0775d9d68993f1e4bcf333916dd1aa Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Mon, 13 Jul 2026 20:35:42 +0100 Subject: [PATCH 2/4] TrustedParseOptions in IDL --- source | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source b/source index 61453fece6e..561c5cdfea0 100644 --- a/source +++ b/source @@ -4993,6 +4993,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute

        10. TrustedScript
        11. data
        12. TrustedScriptURL
        13. +
        14. TrustedParserOptions
        15. get trusted type compliant string
        16. get trusted type compliant input
        17. @@ -11635,7 +11636,7 @@ typedef (HTMLScriptElement or SVGScriptElement) LegacyOverrideBuiltIns] partial interface Document { - static Document parseHTMLUnsafe((TrustedHTML or DOMString) html, optional ParseHTMLUnsafeOptions options = {}); + static Document parseHTMLUnsafe((TrustedHTML or DOMString) html, optional (ParseHTMLUnsafeOptions or TrustedParserOptions) options = {}); static Document parseHTML(DOMString html, optional SetHTMLOptions options = {}); // resource metadata management @@ -125448,7 +125449,7 @@ document.body.appendChild(frame)
          partial interface Element {
             [CEReactions] undefined setHTML(DOMString html, optional SetHTMLOptions options = {});
          -  [CEReactions] undefined setHTMLUnsafe((TrustedHTML or DOMString) html, optional SetHTMLUnsafeOptions options = {});
          +  [CEReactions] undefined setHTMLUnsafe((TrustedHTML or DOMString) html, optional (SetHTMLUnsafeOptions or TrustedParserOptions) options = {});
             DOMString getHTML(optional GetHTMLOptions options = {});
           
             [CEReactions] attribute (TrustedHTML or [LegacyNullToEmptyString] DOMString) innerHTML;
          @@ -125458,7 +125459,7 @@ document.body.appendChild(frame)
          partial interface ShadowRoot { [CEReactions] undefined setHTML(DOMString html, optional SetHTMLOptions options = {}); - [CEReactions] undefined setHTMLUnsafe((TrustedHTML or DOMString) html, optional SetHTMLUnsafeOptions options = {}); + [CEReactions] undefined setHTMLUnsafe((TrustedHTML or DOMString) html, optional (SetHTMLUnsafeOptions or TrustedParserOptions) options = {}); DOMString getHTML(optional GetHTMLOptions options = {}); [CEReactions] attribute (TrustedHTML or [LegacyNullToEmptyString] DOMString) innerHTML; From a9a953594521ca0f9f7c0f85d3b18cd275e17d2d Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Mon, 13 Jul 2026 22:22:10 +0100 Subject: [PATCH 3/4] Still wrap things in set and filter HTML --- source | 124 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 69 insertions(+), 55 deletions(-) diff --git a/source b/source index 561c5cdfea0..1757016ef49 100644 --- a/source +++ b/source @@ -125729,12 +125729,8 @@ enum DOMParserSupportedType {
        18. Let target be this's template contents if this is a template element; otherwise this.

        19. -
        20. Let fragment be the result of invoking the fragment parsing algorithm - steps given target, html, options, and "remove".

        21. - -
        22. If fragment is non-null, then replace - all with fragment within target.

        23. +
        24. Set and filter HTML given target, + html, and options.

        @@ -125744,12 +125740,8 @@ enum DOMParserSupportedType { steps are:

          -
        1. Let fragment be the result of invoking the fragment parsing algorithm - steps given this, html, options, and "remove".

        2. - -
        3. If fragment is non-null, then replace - all with fragment within this.

        4. +
        5. Set and filter HTML given this, + html, and options.

        @@ -125768,12 +125760,9 @@ enum DOMParserSupportedType {
      8. Let target be this's template contents if this is a template element; otherwise this.

      9. -
      10. Let fragment be the result of invoking the fragment parsing algorithm - steps given target, compliantHTML, compliantOptions, and - "keep".

      11. - -
      12. If fragment is non-null, then replace - all with fragment within target.

      13. +
      14. Set and filter HTML given target, + compliantHTML, compliantOptions, and Unsafe.

      @@ -125789,12 +125778,9 @@ enum DOMParserSupportedType { object, html, options, and "ShadowRoot setHTMLUnsafe".

      -
    8. Let fragment be the result of invoking the fragment parsing algorithm - steps given this, compliantHTML, compliantOptions, and - "keep".

    9. - -
    10. If fragment is non-null, then replace - all with fragment within this.

    11. +
    12. Set and filter HTML given this, + compliantHTML, compliantOptions, and Unsafe.

    @@ -125973,12 +125959,46 @@ enum DOMParserSupportedType { +

    A fragment parser mode is one of the following:

    + +
    +
    Legacy
    +
    Unsafe elements and attributes are allowed, + while declarative shadow roots are ignored. + XML documents are parsed using the XML parser.
    + +
    Unsafe
    +
    Unsafe elements and attributes are allowed, + alongside declarative shadow roots.
    + +
    Normal
    +
    Unsafe elements and attributes are removed, + while declarative shadow roots are + allowed.
    +
    + +
    +

    To set and filter HTML, given an Element or + DocumentFragment target, a string html, a dictionary or TrustedParserOptions object options, and an + optional fragment parser mode mode (default Normal):

    + +
      +
    1. Let fragment be the result of invoking the fragment parsing algorithm + steps given target, html, options, and + mode.

    2. + +
    3. If fragment is non-null, then replace + all with fragment within target.

    4. +
    +
    +

    The fragment parsing algorithm steps, given an Element or - DocumentFragment target, a string markup, a dictionary - options, and unsafeMarkupHandling, which is one of "remove", "keep", or "legacy", - are:

    + DocumentFragment target, a string markup, a dictionary or TrustedParserOptions object options, and a + fragment parser mode mode, are:

    1. Let context be target if target is an @@ -125990,17 +126010,17 @@ enum DOMParserSupportedType {

    2. If all of the following are true:

        -
      • unsafeMarkupHandling is "remove";
      • +
      • mode is Normal;
      • context's local name is - "script"; and
      • -
      • context's namespace is the - HTML namespace or the SVG namespace,
      • + "script"; and
      • context's namespace is the HTML namespace or the + SVG namespace,

      then return null.

    3. -
    4. Let safe be true if unsafeMarkupHandling is "remove"; otherwise false.

    5. +
    6. Let safe be true if mode is Normal; otherwise false.

    7. Let sanitizer be the result of calling getting a sanitizer from options given safe.

    8. @@ -126011,18 +126031,18 @@ enum DOMParserSupportedType {

      If options["runScripts"] is true:

        -
      1. Assert: unsafeMarkupHandling is not "remove".

      2. +
      3. Assert: mode is not Normal.

      4. Set scriptingMode to Fragment.

      -
    9. Let allowDeclarativeShadowRoots be false if unsafeMarkupHandling is - "legacy"; otherwise true.

    10. +
    11. Let allowDeclarativeShadowRoots be false if mode is Legacy; otherwise true.

    12. -
    13. If unsafeMarkupHandling is "legacy" and +

    14. If mode is Legacy and target's node document is an XML document, then return the result of invoking the XML fragment parsing algorithm given target and markup.

    15. @@ -126061,12 +126081,9 @@ enum DOMParserSupportedType { object, the given value, a new SetHTMLUnsafeOptions dictionary, and "Element innerHTML".

      -
    16. Let fragment be the result of invoking the fragment parsing algorithm - steps given this, compliantString, compliantOptions, - and "legacy".

    17. - -
    18. Replace all with fragment within - this.

    19. +
    20. Set and filter HTML given this, + compliantString, compliantOptions, and Legacy.

    @@ -126081,12 +126098,9 @@ enum DOMParserSupportedType { object, the given value, a new SetHTMLUnsafeOptions dictionary, and "ShadowRoot innerHTML".

    -
  • Let fragment be the result of invoking the fragment parsing algorithm - steps given this, compliantString, compliantOptions, - and "legacy".

  • - -
  • Replace all with fragment - within this.

  • +
  • Set and filter HTML given this, + compliantString, compliantOptions, and Legacy.

  • @@ -126162,7 +126176,7 @@ enum DOMParserSupportedType {
  • Let fragment be the result of invoking the fragment parsing algorithm steps given parent, compliantString, compliantOptions, - and "legacy".

  • + and Legacy.

  • Replace this with fragment within this's parent.

  • @@ -126268,7 +126282,7 @@ enum DOMParserSupportedType {
  • Let fragment be the result of invoking the fragment parsing algorithm steps given context, compliantString, compliantOptions, - and "legacy".

  • + and Legacy.

  • Use the first matching item from this list:
    @@ -126382,8 +126396,8 @@ enum DOMParserSupportedType {
  • Return the result of invoking the fragment parsing algorithm steps given - element, compliantString, compliantOptions, and "legacy".

  • + element, compliantString, compliantOptions, and Legacy.

    From 91e333c0284d084023439358cf37ef181bda969e Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Fri, 17 Jul 2026 14:13:19 +0100 Subject: [PATCH 4/4] Add clarification about XMLL vs HTML --- source | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source b/source index 1757016ef49..439edb92726 100644 --- a/source +++ b/source @@ -125969,12 +125969,13 @@ enum DOMParserSupportedType {
    Unsafe
    Unsafe elements and attributes are allowed, - alongside declarative shadow roots.
    + alongside declarative shadow roots. The + HTML parser is used regardless of the type of document.
    Normal
    Unsafe elements and attributes are removed, - while declarative shadow roots are - allowed.
    + while declarative shadow roots are allowed. + The HTML parser is used regardless of the type of document.