Skip to content

fix(dump): nest and strip child frame documents in html dumps - #2801

Merged
ldm0 merged 3 commits into
mainfrom
fix/dump-nested-frames
Nov 12, 2026
Merged

ldm0 merged 3 commits into
mainfrom
fix/dump-nested-frames

Conversation

@lanyue-llk

@lanyue-llk lanyue-llk commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

PR #2801 at a glance

**Track:** Web Fetch (Browser Eval). Replaces part of #1592.

Closes #2758.
Replaces part of #1592.

Problem. moli fetch URL --dump html --with-frames lost nested frame content: an outer frame's srcdoc held a bare <iframe src="inner.html"> even though the inner frame was loaded. In addition, --strip-mode full left <script> and <style> inside every child srcdoc. Repro (from the issue): moli fetch http://127.0.0.1:8000/nested.html --dump html --with-frames and moli fetch http://127.0.0.1:8000/strip.html --dump html --with-frames --strip-mode full.

Change. Each srcdoc was serialized from the live DOM, while every edit (nested srcdoc, stripping) went into the export copy. Child Documents already live in that same NativeDom copy, so the dump now does the following:

  • runtime/page_dump.rs applies the strip options to the top Document and to each child Document root in the copy (apply_strip_options takes a root).
  • It then serializes each child Document from the copy, walking frames from the last in snapshot order to the first, so a nested owner's srcdoc is already set when its parent is serialized.
  • The child serialization keeps the live path's shadow roots and per-node scripting flag (<template shadowrootmode>, <noscript> in sandboxed frames). DomHost::get_html_from_copy (moli-dom) is the existing get_html pointed at a DOM copy. It is used by child_browsing_context_document_snapshot_from_copy (native_bridge/.../document_lookup.rs), which replaces the live-only lookup.
  • The frame-id lookup that re-parsed detached snapshot markup had no other production caller, so it is removed together with the one test assertion that covered it.

Verification.

  • nested.html: v1.1.23 gives ...&lt;p&gt;OUTER&lt;/p&gt;&lt;iframe src=&quot;inner.html&quot;&gt;&lt;/iframe&gt;.... This branch gives ...&lt;iframe src=&quot;inner.html&quot; srcdoc=&quot;...&amp;lt;p&amp;gt;INNER&amp;lt;/p&amp;gt;...&quot; data-moli-frame-url=&quot;http://127.0.0.1:18758/sub/inner.html&quot;&gt;....
  • strip.html --strip-mode full: v1.1.23 child srcdoc contains &lt;script&gt;var secret=1&lt;/script&gt;&lt;style&gt;p{color:red}&lt;/style&gt;. This branch gives &lt;p&gt;CHILD&lt;/p&gt; with no script or style. Without --strip-mode the script is still kept.
  • Frame shadow root (review repro <iframe srcdoc="<div id=h></div><script>h.attachShadow(...).innerHTML='<p>SHADOWTEXT</p>'</script>">): ...div id=&quot;h&quot;&gt;&lt;template shadowrootmode=&quot;open&quot;&gt;&lt;p&gt;SHADOWTEXT..., same as v1.1.23.
  • New test cli_dump_html_with_frames_nests_and_strips_child_documents (moli/tests/fetch_cli.rs). The inner frame's text and the outer frame's shadow tree are produced by script, so they exist only in the live child Documents. With that setup, the nesting and strip assertions fail on the old code. The shadow-root assertion passes on v1.1.23 as well; it guards against losing child shadow roots, a regression in an earlier revision of this PR.
  • cargo nextest run -p moli --test fetch_cli: 221 passed. cargo nextest run -p moli-renderer-v8 -E 'test(child_document_lifecycle) | test(markdown_dump) | test(child_frame)': 108 passed.
  • cargo fmt --all clean; cargo clippy -p moli-dom -p moli-renderer-v8 -p moli --all-targets --all-features -- -D warnings clean (workspace clippy not run locally).
  • Not run locally: the full workspace nextest (the renderer test binary does not link within local RAM); left to CI.

Cost. Nothing changes without --with-frames. With it, each child Document is serialized once, from the copy instead of the live DOM, with the same serializer and shadow-root provider. Stripping a child Document is the same walk the top Document already gets. Debug builds of origin/main (cbf4d01) and this branch, same profile, /usr/bin/time -l, alternating runs, median of 7:

case main wall / max RSS branch wall / max RSS
nested.html --with-frames 0.11 s / 86.6 MB 0.11 s / 86.6 MB
strip.html --with-frames --strip-mode full 0.14 s / 90.1 MB 0.15 s / 90.1 MB
ordinary local article --with-frames 0.11 s / 88.3 MB 0.10 s / 88.3 MB
ordinary local article --strip-mode full 0.10 s / 88.4 MB 0.11 s / 88.4 MB

@lanyue-llk lanyue-llk left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent review of c5c7f42

Changes needed (2)

  1. Child-frame shadow DOM is now dropped from srcdoc (moli-renderer-v8/src/runtime/page_dump.rs:127). Before this PR, loaded frames were serialized by live_child_browsing_context_document_snapshot (document_lookup.rs:50-79). That path calls DomHost::get_html with every shadow root in the child document as an explicit root and with each node's scripting flag. NativeDom::inner_html uses serialize_html with no shadow-root provider and always treats scripting as enabled (moli-dom/src/native/html_serialization/engine.rs:444-459). Repro: <iframe srcdoc="<div id=h></div><script>h.attachShadow({mode:'open'}).innerHTML='<p>SHADOWTEXT</p>'</script>">. With --dump html --with-frames, v1.1.23 emits <div id="h"><template shadowrootmode="open"><p>SHADOWTEXT</p></template></div> in the srcdoc. This branch emits <div id="h"></div>, so web-component content inside every loaded frame disappears from HTML and JSON exports, with or without --strip-mode. The scripting flag also changes <noscript> text escaping in sandboxed frames that do not allow scripts. Smallest fix: serialize the child Document from the copy with the same shadow-root list and per-node scripting callback the snapshot used, e.g. a NativeDom-level get_html variant that accepts the provider. Then remove the redundant live snapshot serialization for loaded frames. Add a frame shadow-root case to the new test.

  2. The regression test does not cover the nesting half of the fix (moli/tests/fetch_cli.rs:1144-1163). The inner frame's content is already present as the inner owner's original srcdoc attribute, so &amp;lt;p&amp;gt;INNER also appears on v1.1.23 (verified with the released binary). Only the strip assertions fail without the fix. A regression in the reverse-order serialization (page_dump.rs:117-120) would still pass. Smallest fix: make the inner content exist only in the live DOM, e.g. inner srcdoc <p id=x></p><script>x.textContent='IN'+'NER'</script>, and assert on the double-escaped INNER in the no-strip run.

Checked with no findings: snapshot order is a pre-order DFS (child_frames/lookup.rs:76-103), so walking it in reverse serializes innermost frames first at any depth. Strip options apply to each child Document root exactly as to the top document, and apply_strip_options still returns early when no strip mode is set. Frames without a live document handle (failed or not yet loaded) are filtered out exactly as on main. Every edit goes to the cloned NativeDom, not the live DOM. Pages without --with-frames, and pages with no child contexts, do no extra work.

CI: Format, Node, Python and Windows passed. Nextest, Clippy, CDP smoke and Release builds were still pending at review time.

Picture: pending (the body still has the <!-- picture --> placeholder).

@lanyue-llk lanyue-llk left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent review of a35ea88

Changes needed (2)

Both round-1 findings are fixed. Child frames are serialized from the export copy through DomHost::get_html_from_copy, which is a thin entry into the existing serialize_html_with_shadow_roots, so no serializer logic is duplicated. Shadow roots come from the live host's explicit bindings, and the per-node scripting flag is the live node_document_scripting_enabled. Node ids are shared with the clone, so sandboxed or script-disabled frames get the same <noscript> treatment as before. Reverse snapshot order (pre-order reversed) serializes every descendant before its ancestor. The removed frame-id fallback was unreachable from the dump, because live_child_document_handles_in_snapshot_order only yields frames that have a live Document. The nesting assertion fails on v1.1.23: I checked it with the released binary.

  1. moli-renderer-v8/src/runtime/page_dump.rs:37-40 (with collect_node_ids, around l.260): --strip-mode does not reach shadow trees in child frames, but the child srcdoc now emits them through <template shadowrootmode>. A shadow root is a separate document fragment, not a child of its host (moli-dom/src/native/host/document.rs:1797), so collect_node_ids(dom, child_document) never visits it. Repro: <iframe srcdoc="<div id=h></div><script>h.attachShadow({mode:'open'}).innerHTML='<style>b{color:red}</style><b>X</b>'</script>"> with --with-frames --strip-mode full still outputs <template shadowrootmode="open"><style>b{color:red}</style>.... I observed this on v1.1.23, and this branch's strip walk has the same gap. Web components inside frames normally keep their <style> in the shadow root, so the issue's "strip child srcdoc" claim stays only partly true. Smallest fix: when stripping each child Document, also call apply_strip_options on the shadow-root handles whose host belongs to that Document. These are the same snapshot_shadow_root_bindings() filter that document_lookup.rs:17-29 already computes, and the fragments exist in the clone. Add a shadow <style> to the new test's strip half.

  2. PR body, Verification: "This makes the nesting and shadow-root assertions fail on the old code" is only half true. The shadow-root assertion passes on v1.1.23 (checked with the release binary: shadowrootmode=&quot;open&quot;&gt;&lt;b&gt;SHADOWTEXT is present). It guards against the round-1 regression, not against old behavior. Only the nesting and strip assertions fail on the old code. Please reword. The picture otherwise matches the body. It omits the fourth Cost row (--strip-mode full on the ordinary article), and "live DOM no longer used for srcdoc" should say that shadow-root bindings and scripting flags still come from the live host.

CI at this head: Format, Clippy, Python/Node harness and Windows checks pass. Nextest, CDP smoke and both Build release jobs are still pending.

@github-actions

Copy link
Copy Markdown

CI Regression Report

Source CI run · source state at render: in_progress · artifacts: 6/6

Check Status Signal
Release regression ✅ HEAD/base failures 0/0; raw binary +0.000064%
Frontend differential ✅ 1,020/1,020 cases matched; 0 issues
Agent episodes ✅ 8/8 Moli episodes passed; 0 failures
Runtime/CDP contracts ✅ 26 contract cases; 0 failures
CDP smoke ✅ 116/116 groups passed; 1,680 scenarios
WebMainBench ✅ 545/545 completed; 0 unexpected failures
Release regression — ✅ HEAD/base failures 0/0; raw binary +0.000064%

Package and image size

Metric Base HEAD Delta Delta %
Raw binary 154.10 MiB 154.10 MiB +104 B +0.000064%
Stripped binary 106.56 MiB 106.56 MiB 0 B 0.00%
gzip binary 53.19 MiB 53.19 MiB +112 B +0.000201%
Rootfs 161.00 MiB 161.00 MiB 0 B 0.00%
gzip rootfs 62.27 MiB 62.27 MiB +1.13 KiB +0.001770%

Startup latency and PSS

Case Base p50 HEAD p50 Delta Base PSS HEAD PSS Delta
Serve ready 28.05 ms 27.60 ms −0.45 ms 6.04 MiB 5.80 MiB −252.00 KiB
CDP first page 65.34 ms 57.10 ms −8.24 ms 8.38 MiB 6.15 MiB −2.22 MiB
CDP warm page 19.34 ms 15.81 ms −3.53 ms 52.72 MiB 53.54 MiB +836.50 KiB
CLI about:blank 19.24 ms 15.90 ms −3.34 ms 4.74 MiB 5.33 MiB +604.00 KiB
CLI local JS 25.45 ms 28.89 ms +3.43 ms 5.48 MiB 4.43 MiB −1.05 MiB

Concurrency matrix

Concurrency Base p50 HEAD p50 Delta Base PSS HEAD PSS Delta HEAD failures Unstable B/H
1 28.46 ms 27.43 ms −1.03 ms 1.04 MiB 1.10 MiB +69.00 KiB 0 0/0
5 30.28 ms 28.47 ms −1.81 ms 14.63 MiB 14.86 MiB +242.50 KiB 0 0/0
10 42.85 ms 29.35 ms −13.50 ms 4.88 MiB 12.45 MiB +7.57 MiB 0 0/0
25 41.18 ms 28.72 ms −12.47 ms 3.76 MiB 30.22 MiB +26.46 MiB 0 0/0
100 32.69 ms 27.86 ms −4.83 ms 13.03 MiB 14.44 MiB +1.41 MiB 0 0/0
Frontend differential — ✅ 1,020/1,020 cases matched; 0 issues
Match DOM mismatch Diagnostic mismatch Moli error Reference error Infrastructure error Mismatched frames Duration
1,020 0 0 0 0 0 0 7m 4.50s
Agent episodes · Moli vs Chromium — ✅ 8/8 Moli episodes passed; 0 failures
Fast contract Episodes Passed Assertions Ready p50 Episode p50
Moli 8 8 47/47 5.02 ms 31.35 ms
Chromium 8 8 47/47 249.29 ms 100.93 ms
Operation p50 Chromium Moli Delta Delta %
navigate 44.40 ms 6.35 ms −38.05 ms −85.69%
observe 0.80 ms 0.90 ms +0.10 ms +11.86%
fill 4.20 ms 3.57 ms −0.63 ms −15.10%
click 6.68 ms 4.37 ms −2.32 ms −34.67%
Idle-resource episode Peak RSS Peak PSS Average CPU Peak CPU Peak processes Sampler
Moli 69.57 MiB 67.89 MiB 1.03% 22.19% 1 ✅
Chromium 1270.10 MiB 425.19 MiB 1.42% 29.96% 13 ⚠️ PSS partial
Runtime and CDP session contracts — ✅ 26 contract cases; 0 failures
Suite Cases Failures Median case p50 Median case p95 Median peak PSS p50
Synthetic fetch 13 0 33.05 ms 37.49 ms 453.00 KiB
Long-lived CDP session 13 0 21.63 ms 23.12 ms —
CDP smoke — ✅ 116/116 groups passed; 1,680 scenarios

Workers: 4 · cumulative group time: 498.73 s · failed groups: 0

Slowest group Scenarios Duration Status
scrollbar-visibility 22 26.63 s ✅
scrollbar-visibility 22 26.63 s ✅
dom-input 62 26.61 s ✅
dom-input 62 26.59 s ✅
fetch-resource-dispatch 72 25.26 s ✅
WebMainBench · 545 pages — ✅ 545/545 completed; 0 unexpected failures
Completed Successful Expected DNS failure Unexpected failures Panics Crashes Timeouts Empty output
545/545 544 1 0 0 0 0 0

Frozen HTML · Linux · --wait done · 45 seconds per page · no retries. Content quality is evaluated separately.

Diagnostics: webmainbench-results — every page's Markdown, stderr, and exit status. Source run and artifacts

All artifact fields are parsed by the trusted default-branch renderer; missing or invalid inputs remain visible as unavailable.

@ldm0
ldm0 merged commit d529fe2 into main Nov 12, 2026
6 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

moli fetch --dump html --with-frames drops nested frame content and keeps frame scripts/styles under --strip-mode

2 participants