Repository navigation
fix(dump): nest and strip child frame documents in html dumps - #2801
Conversation
lanyue-llk
left a comment
There was a problem hiding this comment.
Independent review of c5c7f42
Changes needed (2)
-
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 bylive_child_browsing_context_document_snapshot(document_lookup.rs:50-79). That path callsDomHost::get_htmlwith every shadow root in the child document as an explicit root and with each node's scripting flag.NativeDom::inner_htmlusesserialize_htmlwith 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. aNativeDom-levelget_htmlvariant that accepts the provider. Then remove the redundant live snapshot serialization for loaded frames. Add a frame shadow-root case to the new test. -
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 originalsrcdocattribute, so&lt;p&gt;INNERalso 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-escapedINNERin 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
left a comment
There was a problem hiding this comment.
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.
-
moli-renderer-v8/src/runtime/page_dump.rs:37-40(withcollect_node_ids, around l.260):--strip-modedoes not reach shadow trees in child frames, but the childsrcdocnow 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), socollect_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 fullstill 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 callapply_strip_optionson the shadow-root handles whose host belongs to that Document. These are the samesnapshot_shadow_root_bindings()filter thatdocument_lookup.rs:17-29already computes, and the fragments exist in the clone. Add a shadow<style>to the new test's strip half. -
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="open"><b>SHADOWTEXTis 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 fullon 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.
CI Regression ReportSource CI run · source state at render:
Release regression — ✅ HEAD/base failures 0/0; raw binary +0.000064%Package and image size
Startup latency and PSS
Concurrency matrix
Frontend differential — ✅ 1,020/1,020 cases matched; 0 issues
Agent episodes · Moli vs Chromium — ✅ 8/8 Moli episodes passed; 0 failures
Runtime and CDP session contracts — ✅ 26 contract cases; 0 failures
CDP smoke — ✅ 116/116 groups passed; 1,680 scenariosWorkers: 4 · cumulative group time: 498.73 s · failed groups: 0
WebMainBench · 545 pages — ✅ 545/545 completed; 0 unexpected failures
Frozen HTML · Linux · Diagnostics: All artifact fields are parsed by the trusted default-branch renderer; missing or invalid inputs remain visible as unavailable. |

**Track:** Web Fetch (Browser Eval). Replaces part of #1592.Closes #2758.
Replaces part of #1592.
Problem.
moli fetch URL --dump html --with-frameslost nested frame content: an outer frame'ssrcdocheld a bare<iframe src="inner.html">even though the inner frame was loaded. In addition,--strip-mode fullleft<script>and<style>inside every childsrcdoc. Repro (from the issue):moli fetch http://127.0.0.1:8000/nested.html --dump html --with-framesandmoli fetch http://127.0.0.1:8000/strip.html --dump html --with-frames --strip-mode full.Change. Each
srcdocwas serialized from the live DOM, while every edit (nestedsrcdoc, stripping) went into the export copy. Child Documents already live in that sameNativeDomcopy, so the dump now does the following:runtime/page_dump.rsapplies the strip options to the top Document and to each child Document root in the copy (apply_strip_optionstakes a root).srcdocis already set when its parent is serialized.<template shadowrootmode>,<noscript>in sandboxed frames).DomHost::get_html_from_copy(moli-dom) is the existingget_htmlpointed at a DOM copy. It is used bychild_browsing_context_document_snapshot_from_copy(native_bridge/.../document_lookup.rs), which replaces the live-only lookup.Verification.
...<p>OUTER</p><iframe src="inner.html"></iframe>.... This branch gives...<iframe src="inner.html" srcdoc="...&lt;p&gt;INNER&lt;/p&gt;..." data-moli-frame-url="http://127.0.0.1:18758/sub/inner.html">....--strip-mode full: v1.1.23 childsrcdoccontains<script>var secret=1</script><style>p{color:red}</style>. This branch gives<p>CHILD</p>with no script or style. Without--strip-modethe script is still kept.<iframe srcdoc="<div id=h></div><script>h.attachShadow(...).innerHTML='<p>SHADOWTEXT</p>'</script>">):...div id="h"><template shadowrootmode="open"><p>SHADOWTEXT..., same as v1.1.23.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 --allclean;cargo clippy -p moli-dom -p moli-renderer-v8 -p moli --all-targets --all-features -- -D warningsclean (workspace clippy not run locally).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 oforigin/main(cbf4d01) and this branch, same profile,/usr/bin/time -l, alternating runs, median of 7:--with-frames--with-frames --strip-mode full--with-frames--strip-mode full