diff --git a/source b/source index 631f655f890..ca6e72728ab 100644 --- a/source +++ b/source @@ -123478,7 +123478,7 @@ document.body.appendChild(frame)

DOM parsing and serialization APIs

-
partial interface Element {
+  
partial interface Element {
   [CEReactions] undefined setHTMLUnsafe((TrustedHTML or DOMString) html);
   DOMString getHTML(optional GetHTMLOptions options = {});
 
@@ -123487,7 +123487,7 @@ document.body.appendChild(frame)
[CEReactions] undefined insertAdjacentHTML(DOMString position, (TrustedHTML or DOMString) string); }; -partial interface ShadowRoot { +partial interface ShadowRoot { [CEReactions] undefined setHTMLUnsafe((TrustedHTML or DOMString) html); DOMString getHTML(optional GetHTMLOptions options = {}); @@ -124357,6 +124357,98 @@ interface XMLSerializer { +

Patching

+ +

TODO: introduction, what's all this?

+ +
partial interface Element {
+  WritableStream streamHTMLUnsafe(optional StreamHTMLUnsafeOptions options = {});
+};
+
+partial interface ShadowRoot {
+  WritableStream streamHTMLUnsafe(optional StreamHTMLUnsafeOptions options = {});
+};
+
+dictionary StreamHTMLUnsafeOptions {
+  boolean runScripts = false;
+};
+ +
+ +
+

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

+ +
    +
  1. Let writable be a new WritableStream.

  2. + +
  3. +

    👋 Sketch of the streams setup:

    + +
      +
    1. Incoming chunks must all be of the same type, either strings or a trusted types + wrapper. Check this on every chunk and treat mixing as an error.

    2. + +
    3. If the first chunk is not a trusted types wrapper and there is a default TT policy, + create a transform stream using createTransformStream from the default + policy. Then pipe chunks through that transform stream.

    4. + +
    5. For trusted types handled "outside" (not by the internal transform stream) check that + the chunks are in the same order and not duplicated/filtered/reordered.

    6. +
    +
  4. + +
  5. +

    👋 Sketch of the parser setup:

    + +
      +
    1. Let parser be a new fragment parser.

    2. + +
    3. Add this to the stack of open elements.

    4. + +
    5. If options["runScripts"], + don't mark scripts as already executed.

    6. + +
    7. Write chunks into the parser as they are written to writable.

    8. +
    +
  6. + +
  7. Return writable.

  8. +
+
+ +
+

Do a thing like this:

+
const policy = trustedTypes.createPolicy("my-policy", {
+  createTransformStream() {
+    return new TransformStream({
+      transform(chunk, controller) {
+        // TODO: some buffering
+        controller.enqueue(sanitize(chunk));
+      }
+    });
+  }
+});
+
+const response = await fetch('/fragments/something');
+const transform = policy.createTransformStream();
+const writable = element.streamHTMLUnsafe();
+await response.body.pipeThrough(transform).pipeTo(writable);
+
+ +
+

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

+ +
    +
  1. TODO
  2. +
+
+ +
+

Timers

The setTimeout() and