diff --git a/source b/source index f5b92937f43..66c1b6281fb 100644 --- a/source +++ b/source @@ -2119,12 +2119,12 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute

Conformance checkers must check that the input document conforms when parsed without a browsing context (meaning that no scripts are run, and - that the parser's scripting mode is Disabled), and should also check that the input document - conforms when parsed with a browsing context in which - scripts execute, and that the scripts never cause non-conforming states to occur other than - transiently during script execution itself. (This is only a "SHOULD" and not a "MUST" - requirement because it has been proven to be impossible. COMPUTABLE)

+ that the parser's scripting is disabled), and + should also check that the input document conforms when parsed with a browsing context in which scripts execute, and that the + scripts never cause non-conforming states to occur other than transiently during script + execution itself. (This is only a "SHOULD" and not a "MUST" requirement because it has been + proven to be impossible. COMPUTABLE)

The term "HTML validator" can be used to refer to a conformance checker that itself conforms to the applicable requirements of this specification.

@@ -2905,6 +2905,17 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute +
Streams
+ +
+

The following terms are defined in the Streams Standard: STREAMS

+ + +
+
Web IDL
@@ -4996,6 +5007,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
  • TrustedParserOptions
  • get trusted type compliant string
  • get trusted type compliant input
  • +
  • get trusted type compliant parser options
  • TrustedParserOptions sanitizer config
  • @@ -66452,7 +66464,7 @@ interface HTMLDialogElement : HTMLElement {

    The close(returnValue) method steps are: + data-x="dom-dialog-close">close(returnValue) method steps are:

    1. If returnValue is not given, then set it to null.

    2. @@ -67849,6 +67861,9 @@ o............A....e documents during preparation from executing.

      +

      A script element has an intended document, which is either null or a + Document, initially null.

      +

      A script element has a force async boolean, initially true. It is set to false by the HTML parser and the XML parser on script elements they insert, and when the element gets an @@ -68081,9 +68096,10 @@ document.body.append(script1, script2);

    3. -

      If parser document is non-null and el does not have an async attribute, then set el's force async to true.

      +

      If parser document is non-null, parser document has a browsing + context, and el does not have an async + attribute, then set el's force async to + true.

      This is done so that if a parser-inserted script element fails to run when the parser tries to run it, but it is later executed after a script dynamically @@ -68166,8 +68182,9 @@ document.body.append(script1, script2);

    4. Set el's preparation-time document to its node document.

      -
    5. If parser document is non-null, and parser document is not equal to - el's preparation-time document, then return.

    6. +
    7. If el's intended document is non-null and el's + intended document is not equal to el's preparation-time + document, then return.

    8. If scripting is disabled for el, then return.

      @@ -69073,8 +69090,8 @@ not-slash = %x0000-002E / %x0030-10FFFF

      All these contortions are required because, for historical reasons, the noscript element is handled differently by the HTML parser based on - whether scripting mode was Disabled - when the parser was invoked.

      + whether scripting was disabled when the parser was + invoked.

      The noscript element must not be used in XML documents.

      @@ -125484,6 +125501,12 @@ partial interface mixin ChildNode { [CEReactions] undefined beforeHTMLUnsafe((TrustedHTML or DOMString) html, optional (SetHTMLUnsafeOptions or TrustedParserOptions) options = {}); [CEReactions] undefined afterHTMLUnsafe((TrustedHTML or DOMString) html, optional (SetHTMLUnsafeOptions or TrustedParserOptions) options = {}); [CEReactions] undefined replaceWithHTMLUnsafe((TrustedHTML or DOMString) html, optional (SetHTMLUnsafeOptions or TrustedParserOptions) options = {}); + [CEReactions] WritableStream streamBeforeHTML(optional SetHTMLOptions options = {}); + [CEReactions] WritableStream streamBeforeHTMLUnsafe(optional SetHTMLUnsafeOptions options = {}); + [CEReactions] WritableStream streamAfterHTML(optional SetHTMLOptions options = {}); + [CEReactions] WritableStream streamAfterHTMLUnsafe(optional SetHTMLUnsafeOptions options = {}); + [CEReactions] WritableStream streamReplaceWithHTML(optional SetHTMLOptions options = {}); + [CEReactions] WritableStream streamReplaceWithHTMLUnsafe(optional SetHTMLUnsafeOptions options = {}); }; enum SanitizerPresets { "default" }; @@ -125647,7 +125670,7 @@ enum DOMParserSupportedType {

      To parse HTML from a string, given a Document document, a string html, an optional SanitizerConfig or null - configuration (default null), and an optional boolean safe (default + sanitizerConfig (default null), and an optional boolean safe (default false):

        @@ -125659,8 +125682,8 @@ enum DOMParserSupportedType { data-x="concept-document-allow-declarative-shadow-roots">allow declarative shadow roots, associated with document.

        -
      1. If configuration is not null, then set parser's parser - sanitizer configuration to configuration and set parser's +

      2. If sanitizerConfig is not null, then set parser's parser + sanitizer configuration to sanitizerConfig and set parser's remove javascript navigation URLs to safe.

      3. Place html into the input stream for parser. The @@ -125899,7 +125922,7 @@ enum DOMParserSupportedType {

        Element's prependHTML(html, options) - method steps are: + method steps are:

        1. Let firstChild be the first child of this's @@ -125934,7 +125957,7 @@ enum DOMParserSupportedType {

          ChildNode's beforeHTML(html, options) - method steps are: + method steps are:

          1. Let parent be the result of getting the parent for HTML insertion @@ -125950,7 +125973,7 @@ enum DOMParserSupportedType {

            ChildNode's afterHTML(html, options) - method steps are: + method steps are:

            1. Let parent be the result of getting the parent for HTML insertion @@ -126146,7 +126169,6 @@ enum DOMParserSupportedType { data-x="fragment-parser-mode-unsafe">Unsafe.

            -
            @@ -126213,6 +126235,657 @@ enum DOMParserSupportedType {
          +
        + +
        HTML streaming methods
        + + + +

        The HTML streaming methods (e.g. streamHTML()) + allow authors to insert chunks of HTML asynchronously using a WritableStream. As + chunks are written to the stream, the HTML parser incrementally processes the input + and inserts the resulting DOM nodes into the target element.

        + +

        Unlike synchronous methods such as setHTML(), + streaming methods can parse and execute scripts concurrently with the rest of the document + lifecycle, provided the method used allows unsafe content (e.g. streamHTMLUnsafe()) and the runScripts option is set to true. Scripts will + execute as soon as their end tag is parsed, like in main document parsing. Because the tree is + constructed incrementally, scripts can observe partial markup and DOM elements appended before the + stream is closed. Scripts marked with the defer attribute + will delay execution until the stream is closed, and will be ignored if it is aborted.

        + +
        +
        stream = element.streamHTML([options])
        +

        Returns a WritableStream that, as strings are written to it, parses them + using the HTML parser, and incrementally replaces the children of element with the + result. element provides context for the HTML parser. The parsed fragments are sanitized based on the options's "sanitizer" member, and unsafe content is removed.

        + +
        stream = shadowRoot.streamHTML([options])
        +

        Returns a WritableStream that, as strings are written to it, parses them + using the HTML parser, and incrementally replaces the children of shadowRoot with the + result. shadowRoot's host provides + context for the HTML parser. The parsed fragments are sanitized + based on the options's "sanitizer" + member, and unsafe content is removed.

        + +
        stream = element.streamAppendHTML([options])
        +

        Returns a WritableStream that, as strings are written to it, parses them + using the HTML parser, and incrementally inserts the result after the last child of + element. element provides context for the HTML parser. The parsed fragments + are sanitized based on the options's "sanitizer" member, and unsafe content is removed.

        + +
        stream = shadowRoot.streamAppendHTML([options])
        +

        Returns a WritableStream that, as strings are written to it, parses them + using the HTML parser, and incrementally inserts the result after the last child of + shadowRoot. shadowRoot's host provides context for the HTML parser. The + parsed fragments are sanitized based on the options's + "sanitizer" member, and unsafe content is removed.

        + +
        stream = element.streamPrependHTML([options])
        +

        Returns a WritableStream that, as strings are written to it, parses them + using the HTML parser, and incrementally inserts the result before the first child of + element. element provides context for the HTML parser. The parsed fragments + are sanitized based on the options's "sanitizer" member, and unsafe content is removed. While streaming, content is + inserted before element's first child, at the time of calling the method. + Throws a "HierarchyRequestError" DOMException if that node + is no longer a child of element.

        + +
        stream = shadowRoot.streamPrependHTML([options])
        +

        Returns a WritableStream that, as strings are written to it, parses them + using the HTML parser, and incrementally inserts the result before the first child of + shadowRoot. shadowRoot's host provides context for the HTML parser. The + parsed fragments are sanitized based on the options's + "sanitizer" member, and unsafe content is removed. While streaming, content is + inserted before shadowRoot's first child, at the time of calling the + method. Throws a "HierarchyRequestError" DOMException if + that node is no longer a child of shadowRoot.

        + +
        stream = childNode.streamBeforeHTML([options])
        +

        Returns a WritableStream that, as strings are written to it, parses them + using the HTML parser, and incrementally inserts the result before childNode. + childNode's parent provides context for the HTML parser. The parsed fragments are + sanitized based on the options's "sanitizer" member, and unsafe content is removed. Throws a + "HierarchyRequestError" DOMException if + childNode's parent is neither a DocumentFragment nor an + Element. While streaming, content is inserted before childNode, at the + time of calling the method. Throws a "HierarchyRequestError" + DOMException if that node is no longer a child of its parent.

        + +
        stream = childNode.streamAfterHTML([options])
        +

        Returns a WritableStream that, as strings are written to it, parses them + using the HTML parser, and incrementally inserts the result after childNode. + childNode's parent provides context for the HTML parser. The parsed fragments are + sanitized based on the options's "sanitizer" member, and unsafe content is removed. Throws a + "HierarchyRequestError" DOMException if + childNode's parent is neither a DocumentFragment nor an + Element. While streaming, content is inserted before childNode's + next sibling, at the time of calling the method. Throws a + "HierarchyRequestError" DOMException if that node is no + longer a child of childNode's parent.

        + +
        stream = childNode.streamReplaceWithHTML([options])
        +

        Returns a WritableStream that, as strings are written to it, parses them + using the HTML parser, and incrementally replaces childNode with the result. + childNode's parent provides context for the HTML parser. The parsed fragments are + sanitized based on the options's "sanitizer" member, and unsafe content is removed. Throws a + "HierarchyRequestError" DOMException if + childNode's parent is neither a DocumentFragment nor an + Element. While streaming, content is inserted before childNode's + next sibling, at the time of calling the method. Throws a + "HierarchyRequestError" DOMException if that node is no + longer a child of childNode's former parent.

        + +
        stream = element.streamHTMLUnsafe([options])
        +

        Returns a WritableStream that, as strings are written to it, parses them + using the HTML parser, and incrementally replaces the children of element with the + result. element provides context for the HTML parser. If the options + dictionary contains a "sanitizer" + member, it is used to sanitize the parsed fragments before they are inserted into + element. If the options dictionary's "runScripts" member is true, scripts contained + in the stream will be executed immediately after they are parsed and the node tree is + updated.

        + +
        stream = shadowRoot.streamHTMLUnsafe([options])
        +

        Returns a WritableStream that, as strings are written to it, parses them + using the HTML parser, and incrementally replaces the children of shadowRoot with the + result. shadowRoot's host provides + context for the HTML parser. If the options dictionary contains a "sanitizer" member, it is used to + sanitize the parsed fragments before they are inserted into shadowRoot. + If the options dictionary's "runScripts" member is true, scripts contained + in the stream will be executed immediately after they are parsed and the node tree is + updated.

        + +
        stream = element.streamAppendHTMLUnsafe([options])
        +

        Returns a WritableStream that, as strings are written to it, parses them + using the HTML parser, and incrementally inserts the result after the last child of + element. element provides context for the HTML parser. If the + options dictionary contains a "sanitizer" member, it is used to + sanitize the parsed fragments before they are inserted into element. If + the options dictionary's "runScripts" member is true, scripts contained + in the stream will be executed immediately after they are parsed and the node tree is + updated.

        + +
        stream = shadowRoot.streamAppendHTMLUnsafe([options])
        +

        Returns a WritableStream that, as strings are written to it, parses them + using the HTML parser, and incrementally inserts the result after the last child of + shadowRoot. shadowRoot's host provides context for the HTML parser. If the + options dictionary contains a "sanitizer" member, it is used to + sanitize the parsed fragments before they are inserted into shadowRoot. + If the options dictionary's "runScripts" member is true, scripts contained + in the stream will be executed immediately after they are parsed and the node tree is + updated.

        + +
        stream = element.streamPrependHTMLUnsafe([options])
        +

        Returns a WritableStream that, as strings are written to it, parses them + using the HTML parser, and incrementally inserts the result before the first child of + element. element provides context for the HTML parser. If the + options dictionary contains a "sanitizer" member, it is used to + sanitize the parsed fragments before they are inserted into element. If + the options dictionary's "runScripts" member is true, scripts contained + in the stream will be executed immediately after they are parsed and the node tree is updated. + While streaming, content is inserted before element's first child, at the + time of calling the method. The stream rejects with a + "HierarchyRequestError" DOMException if that node is no + longer a child of element.

        + +
        stream = shadowRoot.streamPrependHTMLUnsafe([options])
        +

        Returns a WritableStream that, as strings are written to it, parses them + using the HTML parser, and incrementally inserts the result before the first child of + shadowRoot. shadowRoot's host provides context for the HTML parser. If the + options dictionary contains a "sanitizer" member, it is used to + sanitize the parsed fragments before they are inserted into shadowRoot. + If the options dictionary's "runScripts" member is true, scripts contained + in the stream will be executed immediately after they are parsed and the node tree is updated. + While streaming, content is inserted before shadowRoot's first child, at + the time of calling the method. The stream rejects with a + "HierarchyRequestError" DOMException if that node is no + longer a child of shadowRoot.

        + +
        stream = childNode.streamBeforeHTMLUnsafe([options])
        +

        Returns a WritableStream that, as strings are written to it, parses them + using the HTML parser, and incrementally inserts the result before childNode. + childNode's parent provides context for the HTML parser. If the options + dictionary contains a "sanitizer" + member, it is used to sanitize the parsed fragments before they are inserted into + the node tree. If the options dictionary's "runScripts" member is true, scripts contained + in the stream will be executed immediately after they are parsed and the node tree is updated. + Throws a "HierarchyRequestError" DOMException if + childNode's parent is neither a DocumentFragment nor an + Element. While streaming, content is inserted before childNode, at the + time of calling the method. The stream rejects with a + "HierarchyRequestError" DOMException if that node is no + longer a child of its parent.

        + +
        stream = childNode.streamAfterHTMLUnsafe([options])
        +

        Returns a WritableStream that, as strings are written to it, parses them + using the HTML parser, and incrementally inserts the result after childNode. + childNode's parent provides context for the HTML parser. If the options + dictionary contains a "sanitizer" + member, it is used to sanitize the parsed fragments before they are inserted into + the node tree. If the options dictionary's "runScripts" member is true, scripts contained + in the stream will be executed immediately after they are parsed and the node tree is updated. + Throws a "HierarchyRequestError" DOMException if + childNode's parent is neither a DocumentFragment nor an + Element. While streaming, content is inserted before childNode's + next sibling, at the time of calling the method. The stream rejects with a + "HierarchyRequestError" DOMException if that node is no + longer a child of childNode's parent.

        + +
        stream = childNode.streamReplaceWithHTMLUnsafe([options])
        +

        Returns a WritableStream that, as strings are written to it, parses them + using the HTML parser, and incrementally replaces childNode with the result. + childNode's parent provides context for the HTML parser. If the options + dictionary contains a "sanitizer" + member, it is used to sanitize the parsed fragments before they are inserted into + the node tree. If the options dictionary's "runScripts" member is true, scripts contained + in the stream will be executed immediately after they are parsed and the node tree is updated. + Throws a "HierarchyRequestError" DOMException if + childNode's parent is neither a DocumentFragment nor an + Element. While streaming, content is inserted before childNode's + next sibling, at the time of calling the method. The stream rejects with a + "HierarchyRequestError" DOMException if that node is no + longer a child of childNode's former parent.

        +
        + +
        + +
        +

        Element's streamHTML(options) method steps are:

        + +
          +
        1. Let target be the HTML insertion target given + this.

        2. + +
        3. Let stream be the result of running stream HTML given + target, null, and options.

        4. + +
        5. Replace all with null within + target.

        6. + +
        7. Return stream.

        8. +
        +
        + +
        +

        Element's streamAppendHTML(options) method + steps are:

        + +
          +
        1. Let target be the HTML insertion target given + this.

        2. + +
        3. Return the result of running stream HTML given target, null, and + options.

        4. +
        +
        + +
        +

        Element's streamPrependHTML(options) method + steps are:

        + +
          +
        1. Let target be the HTML insertion target given + this.

        2. + +
        3. Return the result of running stream HTML given target, + target's first child, and options.

        4. +
        +
        + +
        +

        Element's streamHTMLUnsafe(options) method + steps are:

        + +
          +
        1. Let compliantOptions be the result of invoking the get trusted type compliant parser options algorithm + with this's relevant global object, options, "Element streamHTMLUnsafe", and true.

        2. + +
        3. Let target be the HTML insertion target given + this.

        4. + +
        5. Let stream be the result of running stream HTML given + target, null, compliantOptions, and Unsafe.

        6. + +
        7. Replace all with null within + target. + +

        8. Return stream.

        9. +
        +
        + +
        +

        Element's streamAppendHTMLUnsafe(options) + method steps are:

        + +
          +
        1. Let compliantOptions be the result of invoking the get trusted type compliant parser options algorithm + with this's relevant global object, options, "Element streamAppendHTMLUnsafe", and true.

        2. + +
        3. Let target be the HTML insertion target given + this.

        4. + +
        5. Return the result of running stream HTML given target, null, + compliantOptions, and Unsafe.

        6. +
        +
        + +
        +

        Element's streamPrependHTMLUnsafe(options) + method steps are:

        + +
          +
        1. Let compliantOptions be the result of invoking the get trusted type compliant parser options algorithm + with this's relevant global object, options, "Element streamPrependHTMLUnsafe", and true.

        2. + +
        3. Let target be the HTML insertion target given + this.

        4. + +
        5. Let refChild be target's first child.

        6. + +
        7. Return the result of running stream HTML given target, + refChild, compliantOptions, and Unsafe.

        8. +
        +
        + +
        +

        ShadowRoot's streamHTML(options) method steps + are:

        + +
          +
        1. Let stream be the result of running stream HTML given + this, null, and options.

        2. + +
        3. Replace all with null within + this.

        4. + +
        5. Return stream.

        6. +
        +
        + +
        +

        ShadowRoot's streamAppendHTML(options) method + steps are to return the result of running stream HTML given this, null, + and options.

        +
        + +
        +

        ShadowRoot's streamPrependHTML(options) + method steps are to return the result of running stream HTML given this, + this's first child, and options.

        +
        + +
        +

        ShadowRoot's streamHTMLUnsafe(options) method + steps are:

        + +
          +
        1. Let compliantOptions be the result of invoking the get trusted type compliant parser options algorithm + with this's relevant global object, options, "ShadowRoot streamHTMLUnsafe", and true.

        2. + +
        3. Let stream be the result of running stream HTML given + this, null, compliantOptions, and Unsafe.

        4. + +
        5. Replace all with null within + this.

        6. + +
        7. Return stream.

        8. +
        +
        + +
        +

        ShadowRoot's streamAppendHTMLUnsafe(options) + method steps are:

        + +
          +
        1. Let compliantOptions be the result of invoking the get trusted type compliant parser options algorithm + with this's relevant global object, options, "ShadowRoot streamAppendHTMLUnsafe", and true.

        2. + +
        3. Return the result of running stream HTML given this, null, + compliantOptions, and Unsafe.

        4. +
        +
        + +
        +

        ShadowRoot's streamPrependHTMLUnsafe(options) + method steps are:

        + +
          +
        1. Let compliantOptions be the result of invoking the get trusted type compliant parser options algorithm + with this's relevant global object, options, "ShadowRoot streamPrependHTMLUnsafe", and true.

        2. + +
        3. Return the result of running stream HTML given this, + this's first child, compliantOptions, and Unsafe.

        4. +
        +
        + +
        +

        ChildNode's streamBeforeHTML(options) method + steps are to return the result of running stream HTML given this's + parent for HTML streaming, this, and options.

        +
        + +
        +

        ChildNode's streamAfterHTML(options) method + steps are to return the result of running stream HTML given this's + parent for HTML streaming, this's next sibling, and + options.

        +
        + +
        +

        ChildNode's streamReplaceWithHTML(options) + method steps are:

        + +
          +
        1. Let stream be the result of running stream HTML given + this's parent for HTML streaming, this's next + sibling, and options.

        2. + +
        3. Remove this.

        4. + +
        5. Return stream.

        6. +
        +
        + +
        +

        ChildNode's streamBeforeHTMLUnsafe(options) + method steps are:

        + +
          +
        1. Let compliantOptions be the result of invoking the get trusted type compliant parser options algorithm + with this's relevant global object, options, "Node streamBeforeHTMLUnsafe", and true.

        2. + +
        3. Return the result of running stream HTML given this's + parent for HTML streaming, this, compliantOptions, and Unsafe.

        4. +
        +
        + +
        +

        ChildNode's streamAfterHTMLUnsafe(options) + method steps are:

        + +
          +
        1. Let compliantOptions be the result of invoking the get trusted type compliant parser options algorithm + with this's relevant global object, options, "Node streamAfterHTMLUnsafe", and true.

        2. + +
        3. Return the result of running stream HTML given this's + parent for HTML streaming, this's next sibling, + compliantOptions, and Unsafe.

        4. +
        +
        + +
        +

        ChildNode's streamReplaceWithHTMLUnsafe(options) + method steps are:

        + +
          +
        1. Let compliantOptions be the result of invoking the get trusted type compliant parser options algorithm + with this's relevant global object, options, "Node streamReplaceWithHTMLUnsafe", and true.

        2. + +
        3. Let refChild be this's next sibling.

        4. + +
        5. Let stream be the result of running stream HTML given + this's parent for HTML streaming, refChild, + compliantOptions, and Unsafe.

        6. + +
        7. Remove this.

        8. + +
        9. Return stream.

        10. +
        +
        + +
        +

        To get the parent for HTML streaming, given a Node node:

        + +
          +
        1. Let parent be node's parent for HTML + insertion.

        2. + +
        3. If parent is null, then throw a + "HierarchyRequestError" DOMException.

        4. + +
        5. Return parent.

        6. +
        +
        + +
        +

        To stream HTML into an Element or DocumentFragment + target, given a Node or null referenceChild, a dictionary or + TrustedParserOptionsoptions, and a + mode, which is either Normal or Unsafe + (default Normal):

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

        2. + +
        3. Let sanitizerConfig be the result of calling get a sanitizer config from + options with options and safe.

        4. + +
        5. Let contextElement be the result of determining the parser context element given target.

        6. + +
        7. Assert: contextElement is non-null.

        8. + +
        9. +

          If all of the following are true:

          +
            +
          • safe is true;
          • +
          • contextElement's local name is + "script"; and
          • +
          • contextElement's namespace is + the HTML namespace or the SVG namespace,
          • +
          +

          then throw a "NotSupportedError" DOMException.

          +
        10. + +
        11. Let runScripts be true if safe is false and + options["runScripts"] is + true; otherwise false.

        12. + +
        13. Let document be a Document node whose type is "html".

        14. + +
        15. Let parser be the result of initializing an HTML fragment parser with document, target, + target, referenceChild, runScripts, false, + sanitizerConfig, and safe.

        16. + +
        17. Let stream be a new WritableStream in target's relevant realm.

        18. + +
        19. +

          Let writeAlgorithm be the following steps given chunk:

          + +
            +
          1. If chunk is a Symbol, then return a promise + rejected with a TypeError.

          2. + +
          3. Let chunkString be the result of converting chunk to a DOMString.

          4. + +
          5. If referenceChild is non-null and referenceChild's + parent is not target, then abort + parser and return a promise rejected with a + "HierarchyRequestError" DOMException.

          6. + +
          7. Place chunkString into the input stream for parser. + The encoding confidence is + irrelevant.

          8. + +
          9. Have parser run until it has consumed all the characters just inserted into + the input stream.

          10. + +
          11. Return a promise resolved with undefined.

          12. +
          +
        20. + +
        21. +

          Let closeAlgorithm be the following steps:

          +
            +
          1. If referenceChild is non-null and referenceChild's + parent is not target, then abort + parser and return a promise rejected with a + "HierarchyRequestError" DOMException.

          2. + +
          3. Insert an end-of-file token into parser's tokenizer input stream.

          4. + +
          5. Have parser run until it has consumed the end-of-file token.

          6. + +
          7. Return a promise resolved with undefined.

          8. +
          +
        22. + +
        23. +

          Let abortAlgorithm be the following steps given reason:

          + +
            +
          1. Abort parser.

          2. + +
          3. Return a promise resolved with undefined.

          4. +
          +
        24. + +
        25. Set up stream with + writeAlgorithm, closeAlgorithm, and abortAlgorithm.

        26. + +
        27. Return stream.

        28. +
        +
        + +

        HTML serialization methods

        @@ -126450,22 +127123,12 @@ enum DOMParserSupportedType { data-x="fragment-parser-mode-normal">Normal; otherwise false.

      4. Let sanitizerConfig be the result of calling getting a sanitizer from options give + config from options">getting a sanitizer config from options given safe.

      5. -
      6. Let scriptingMode be Inert.

      7. - -
      8. -

        If options["runScripts"] - is true:

        -
          -
        1. Assert: mode is not Normal.

        2. - -
        3. Set scriptingMode to Fragment.

        4. -
        -
      9. +
      10. Let runScripts be true if safe is false and + options["runScripts"] is + true; otherwise false.

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

      12. @@ -126477,7 +127140,7 @@ enum DOMParserSupportedType {
        1. -

          If sanitizer is non-null, then throw a TypeError.

          +

          If sanitizerConfig is non-null, then throw a TypeError.

          Sanitization is only supported on HTML documents.

        2. @@ -126489,7 +127152,7 @@ enum DOMParserSupportedType {
        3. Return the result of invoking the HTML fragment parsing algorithm given target, markup, allowDeclarativeShadowRoots, - scriptingMode, sanitizerConfig, and safe.

        4. + runScripts, sanitizerConfig, and safe.

      @@ -128310,22 +128973,16 @@ dictionary SanitizerConfig {
    -

    To sanitize an Element element given a - SanitizerConfig configuration and a boolean - removeJavascriptNavigationUrls:

    +

    To check the sanitizer action for element name given a + SanitizerElementNamespace elementName and a SanitizerConfig + configuration:

      -
    1. Let elementName be a SanitizerElementNamespace with - element's local name and namespace.

    2. - -
    3. -

      If configuration["replaceWithChildrenElements"] - exists and configuration["replaceWithChildrenElements"] - contains elementName, then return "Replace with children".

      -
    4. +
    5. If configuration["replaceWithChildrenElements"] + exists and configuration["replaceWithChildrenElements"] + contains elementName, then return "Replace with children".

    6. If configuration["elements"] @@ -128340,11 +128997,29 @@ dictionary SanitizerConfig {

    -
  • -

    Otherwise, if configuration["removeElements"] contains elementName, return "Remove".

    -
  • +
  • Otherwise, if configuration["removeElements"] contains elementName, return "Remove".

  • + +
  • Return "Keep".

  • + +
    + +
    +

    To sanitize an Element element given a + SanitizerConfig configuration and a boolean + removeJavascriptNavigationUrls:

    +
      +
    1. Let elementName be a SanitizerElementNamespace with + element's local name and namespace.

    2. + +
    3. Let action be the sanitizer action for element name given + elementName and configuration.

    4. + +
    5. If action is not "Keep", then return + action.

    6. For each attribute of element's @@ -130983,7 +131658,7 @@ interface Navigator {

      The unregisterProtocolHandler(scheme, - url) method steps are: + url) method steps are:

      1. Let (normalizedScheme, normalizedURLString) be the result of running @@ -141928,32 +142603,9 @@ dictionary StorageEventInit : EventInit {

        A boolean allow declarative shadow roots (initially false).

        -

        The scripting mode, which is a parser scripting mode.

        - -

        A parser scripting mode is one of the following:

        - -
        -
        Normal
        -
        Scripts are processed when inserted, respecting async - and defer attributes and blocking the parser when - encountering a classic script.
        - -
        Disabled
        -
        Scripts are disabled, and the noscript element can represent fallback - content.
        +

        A boolean parser scripting disabled, initially false.

        -
        Inert
        -
        Scripts are enabled, however they are marked as already started, essentially - preventing them from executing. This is the default mode of the HTML fragment parsing - algorithm.
        - -
        Fragment
        -
        Scripts are executed as soon as they are inserted into the document as part of a the - HTML fragment parsing algorithm, ignoring async and defer - attributes. This mode is used by createContextualFragment().
        -
        +

        A Document-or-null script target document, initially null.

        The frameset-ok flag is set to "ok" when the parser is created. It is set to "not ok" after certain tokens are seen.

        @@ -144880,6 +145532,27 @@ dictionary StorageEventInit : EventInit {
      2. Let localName be token's tag name.

      3. +
      4. Let sanitizerConfig be the parser's parser sanitizer + configuration.

      5. + +
      6. +

        If document is fully active and sanitizerConfig is not + null:

        + +
          +
        1. Let elementName be a SanitizerElementNamespace with + localName and namespace.

        2. + +
        3. If the sanitizer action for element name given elementName and + config is not "Keep", then set document to + document's appropriate template contents owner document.

        4. +
        + +

        This ensures that elements removed by the sanitizer are still on the stack + of open elements when streaming, but do not invoke side effects such as loading + images.

        +
      7. +
      8. Let is be the value of the "is" attribute in token, if such an attribute exists; otherwise null.

        @@ -145824,15 +146497,13 @@ document.body.appendChild(text);

        Follow the generic RCDATA element parsing algorithm.

        -
        A start tag whose tag name is "noscript", if scripting mode is not Disabled
        +
        A start tag whose tag name is "noscript", if parser scripting disabled is false
        A start tag whose tag name is one of: "noframes", "style"

        Follow the generic raw text element parsing algorithm.

        -
        A start tag whose tag name is "noscript", if scripting mode is Disabled
        +
        A start tag whose tag name is "noscript", if parser scripting disabled is true

        Insert an HTML element for the token.

        @@ -145853,16 +146524,12 @@ document.body.appendChild(text); the intended parent being the element in which the adjustedInsertionLocation finds itself.

      9. -
      10. -

        If the scripting mode is not Fragment, then set the element's - parser document to the Document.

        - -

        The Fragment - scripting mode treats parser-inserted scripts as if they were not - parser-inserted, allowing, for example, executing scripts when applying a fragment created by - createContextualFragment().

        -
      11. +
      12. Set the element's parser document to the Document.

      13. + +
      14. If the parser's script target document is non-null, then + set the element's intended document to the parser's + script target document; otherwise set it to the + Document.

      15. Set the element's force async to false.

        @@ -145873,10 +146540,6 @@ document.body.appendChild(text); the script from executing until the end tag is seen.

      16. -
      17. If the parser's scripting mode is Inert, then set the script element's - already started to true. (fragment case)

      18. -
      19. If the parser was invoked via the document.write() or document.writeln() methods, then optionally set the @@ -147142,8 +147805,7 @@ document.body.appendChild(text);

        A start tag whose tag name is "noembed"
        -
        A start tag whose tag name is "noscript", if scripting mode is not Disabled
        +
        A start tag whose tag name is "noscript", if parser scripting disabled is false

        Follow the generic raw text element parsing algorithm.

        @@ -147302,8 +147964,8 @@ document.body.appendChild(text); "hr", "iframe", "image", "img", "input", "keygen", "link", "meta", "noembed", "noframes", "param", "script", "select", "source", "style", "table", "textarea", "title", "track", "wbr"--> - +

        Parse error. Ignore the token.

        @@ -147319,8 +147981,8 @@ document.body.appendChild(text);

        Insert an HTML element for the token.

        This element will be an ordinary element. With one exception: if - scripting mode is Disabled, it can - also be a noscript element.

        + scripting is disabled, it can also be a + noscript element.

        Any other end tag
        @@ -150206,156 +150868,170 @@ console.assert(container.firstChild instanceof SuperP);
      -

      Parsing HTML fragments

      -
      -

      The HTML fragment parsing algorithm, given an Element or - DocumentFragment target, a string input, an - optional boolean allowDeclarativeShadowRoots (default false), an optional - parser scripting mode scriptingMode (default Inert), an optional SanitizerConfig or null - configuration (default null), and an optional boolean safe (default false), - is the following steps. They return a DocumentFragment.

      - -

      Parts marked fragment case in algorithms in the HTML - parser section are parts that only occur if the parser was created for the purposes of this - algorithm. The algorithms have been annotated with such markings for informational purposes only; - such markings have no normative weight. If it is possible for a condition described as a - fragment case to occur even when the parser wasn't created for the purposes of - handling this algorithm, then that is an error in the specification.

      +

      To determine the parser context element given a Node target:

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

      2. +

        Return the result of the first matching statement:

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

      4. +
        +
        target is an Element
        +
        target
        -
      5. Assert: context is - non-null.

      6. +
        target is a ShadowRoot
        +
        target's shadow host
        -
      7. Let document be a Document node whose type is "html".

      8. +
        target is a DocumentFragment whose host is a template element
        +
        target's host
        -
      9. Let contextDocument be context's node document.

      10. +
        Otherwise
        +
        target's parent
        +
        + +
      +
      + +

      Parsing HTML fragments

      + +
      +

      To initialize an HTML fragment parser + given a Document tempDocument, a Node target, + a Node or null redirectTarget, a Node or null + referenceChild, a boolean runScripts, a Boolean + allowDeclarativeShadowRoots, a SanitizerConfig or null + sanitizerConfig, and a boolean safe, run these steps. They return a new + HTML parser.

      + +
        +
      1. Let contextElement be the + parser context element given + target.

      2. + +
      3. Assert: contextElement is not null.

      4. + +
      5. Let contextDocument be contextElement's node + document.

      6. If contextDocument is in quirks mode, then set document's mode to "quirks".

      7. Otherwise, if contextDocument is in limited-quirks mode, then set - document's mode to "tempDocument's mode to "limited-quirks".

      8. -
      9. Create a new HTML parser whose parser sanitizer configuration is - configuration, allow declarative shadow roots is - allowDeclarativeShadowRoots, scripting mode is - scriptingMode, and remove javascript navigation URLs - is safe, and associate it with document.

      10. +
      11. Create a new HTML parser, and associate it with + tempDocument.

      12. -
      13. If contextDocument's scripting is - disabled, then set scriptingMode to Disabled.

      14. +
      15. Set the parser's parser sanitizer configuration to + sanitizerConfig.

      16. -
      17. -

        Set the state of the HTML parser's tokenization stage as - follows, switching on context:

        +
      18. Set the parser's remove javascript navigation URLs to + safe.

      19. -
        -
        title
        -
        textarea
        -
        Switch the tokenizer to the RCDATA state.
        - -
        style
        -
        xmp
        -
        iframe
        -
        noembed
        -
        noframes
        -
        Switch the tokenizer to the RAWTEXT state.
        - -
        script
        -
        Switch the tokenizer to the script data state.
        - -
        noscript
        -
        If scripting mode is not Disabled, switch the tokenizer to the RAWTEXT - state. Otherwise, leave the tokenizer in the data state.
        - -
        plaintext
        -
        Switch the tokenizer to the PLAINTEXT state.
        - -
        Any other element
        -
        Leave the tokenizer in the data state.
        -
        +
      20. Set the parser's script target document to contextDocument if + runScripts is true; otherwise tempDocument.

      21. -

        For performance reasons, an implementation that does not report errors and - that uses the actual state machine described in this specification directly could use the - PLAINTEXT state instead of the RAWTEXT and script data states where those are mentioned in the - list above. Except for rules regarding parse errors, they are equivalent, since there is no - appropriate end tag token in the fragment case, yet they involve far fewer state - transitions.

        - +
      22. Set the parser's parser scripting disabled to contextDocument's + scripting is disabled.

      23. + +
      24. If allowDeclarativeShadowRoots is true, then set the parser's + allow declarative shadow roots to true.

      25. Let root be the result of creating an - element given document, "html", the HTML + element given tempDocument, "html", the HTML namespace, null, null, false, and the result of looking up a custom element registry given target.

      26. Append root to - document.

      27. + tempDocument.

      28. Set up the HTML parser's stack of open elements so that it contains just the single element root.

      29. -

        Let fragment be the result of creating - a document fragment given document.

        +

        If redirectTarget is non-null, then:

        -

        The DocumentFragment is created as part of the inert document to - avoid creation time side effects before sanitization.

        -
      30. +
          +
        1. If referenceChild is non-null, then set the parser's insertion target + redirection map[root] to be inside redirectTarget, immediately + before referenceChild.

        2. -
        3. Set the parser's insertion target redirection map[root] to - fragment, right after its last child (if exists).

        4. +
        5. Otherwise, set the parser's insertion target redirection + map[root] to be inside redirectTarget, right after its last + child (if exists).

        6. +
        + -
      31. If context is a template +

      32. If contextElement is a template element, then push "in template" onto the stack of template insertion modes so that it is the new current template insertion mode.

      33. Create a start tag token whose name is the local name of context and whose attributes are the attributes of - context.

        + data-x="concept-frag-parse-context">contextElement and whose attributes are the attributes of + contextElement.

        Let this start tag token be the start tag token of context; e.g. for the purposes of determining if it is + data-x="concept-frag-parse-context">contextElement; e.g. for the purposes of determining if it is an HTML integration point.

      34. Reset the parser's insertion mode appropriately.

        - -

        The parser will reference the context element as part of that algorithm.

      35. Set the HTML parser's form element pointer to the - nearest node to context that is a + nearest node to contextElement that is a form element (going straight up the ancestor chain, and including the element itself, if it is a form element), if any. (If there is no such form element, the form element pointer keeps its initial value, null.)

      36. -
      37. Place the input into the input stream for the HTML - parser just created. The encoding confidence is irrelevant.

      38. +
      39. Return the HTML parser.

      40. +
      +
      + +
      +

      The HTML fragment parsing algorithm, given an Element or + DocumentFragment target, a string input, an + optional boolean allowDeclarativeShadowRoots (default false), an optional boolean + runScripts (default false), an optional SanitizerConfig or null + sanitizerConfig (default null), and an optional boolean safe (default + false), is the following steps. They return a DocumentFragment.

      + +

      Parts marked fragment case in algorithms in the HTML + parser section are parts that only occur if the parser was created for the purposes of this + algorithm. The algorithms have been annotated with such markings for informational purposes only; + such markings have no normative weight. If it is possible for a condition described as a + fragment case to occur even when the parser wasn't created for the purposes of + handling this algorithm, then that is an error in the specification.

      -
    7. Start the HTML parser and let it run until it has consumed all the characters +

        +
      1. Let document be a Document node whose type is "html".

      2. + +
      3. +

        Let fragment be the result of creating + a document fragment given document.

        + +

        The DocumentFragment is created as part of the inert document to + avoid creation time side effects before sanitization.

        +
      4. + +
      5. Let parser be the result of invoking initialize an HTML fragment parser with document, target, + fragment, null, runScripts, allowDeclarativeShadowRoots, + sanitizerConfig, and safe.

      6. + +
      7. Place the input into the input stream for parser. + The encoding confidence is irrelevant.

      8. + +
      9. Start parser and let it run until it has consumed all the characters just inserted into the input stream.

      10. Return fragment.

      11. @@ -161694,6 +162370,9 @@ INSERT INTERFACES HERE
        [STORAGE]
        Storage, A. van Kesteren. WHATWG.
        +
        [STREAMS]
        +
        Streams, Adam Rice. WHATWG.
        +
        [SVG]
        Scalable Vector Graphics (SVG) 2, N Andronikos, R. Atanassov, T. Bah, B. Birtles, B. Brinza, C. Concolato, E. Dahlström, C. Lilley, C. McCormack, D. Schepers, R. Schwerdtfeger, D. Storey, S. Takagi, J. Watt. W3C.