Repository navigation
fix(dump): inline child frame documents in markdown with --with-frames - #2808
lanyue-llk wants to merge 1 commit into
Conversation
lanyue-llk
left a comment
There was a problem hiding this comment.
Independent review of 3b30348
No blocking findings
Checked against origin/main:
- Root cause:
page_dump.rs:16now passeswith_framesthrough. Frames come fromlive_child_document_handles_in_snapshot_order, the same list the HTML dump uses. Each owner projects exactly one child (its child Document's<body>,live_dom.rs:228-234), so the text lands at the iframe's DOM position. Nested owners are already in that list, and no document can be emitted twice: the owner's own children and itssrcdocattribute are replaced, not added to. - Failed / empty frames: a frame that fails to connect has no child document, so it is not in the list and keeps
[Embedded content](src). I checked this with v1.1.23--dump html --with-frameson the same list:http://127.0.0.1:9/...gets no srcdoc.about:blank, an iframe with nosrc, and a frame whose body is empty contribute nothing. Script-filled and 404 frames show their live document, as in Chromium. - Base URL:
frame_base_urlreads the child Document's base URL. That covers a child<base>, and srcdoc/about:blank inherit the parent's base throughDocumentBaseUrlState.visibility.rs:297applies it per node, and nested documents are keyed separately. - Visibility:
document_snapshot_style_context(styles.rs:718-744) computes child-document nodes in their own document context. Adisplay:noneowner yieldsHiddenChildFrameand is suppressed through the projected parent. - Shadow DOM in frames: child documents are marked connected (
mark_subtree_connected_preserving_owner_document), sohas_shadow_rootssees their shadow roots. - Without
--with-frames,framesis empty,is_projected()reduces to the oldhas_shadow_roots, andframe_base_urlreturns at theis_empty()guard, so the output is byte-identical. A page with no iframes does no new work, becausechild_browsing_context_handles_in_document_orderreturns early when the registry is empty. - Test: without the fix, the new CLI test fails (no
CHILD TEXT). The child<base>checks the per-document base URL, and the no-flag assertion locks the old output. - CI: still pending at review time (Format, Node, Python and Windows pass). Nothing has failed yet.
- Body: title,
Closes #2757, and an honest Cost table and run scope. Picture: pending.
Spider Bench A/B✅ All benchmark browser service runs completed; results are informational. Public HEAD: 184 / 240 rows; 38 / 48 sites produced rows; 10 unexpected empty sites. ✅ Deterministic fixture contract is clean. Common ancestor Public 48-site run · informational
Public-site content, timing, and memory are noisy. This single A/B run reports evidence only; site outcome counts explain missing rows without treating them as a deterministic regression. CPU and memory timelinesThese are bounded 40-point views of the same complete process-tree samples used by the HTML report. CPU uses 100% per occupied logical core; memory lines are RSS first and PSS second when complete PSS samples are available. Basexychart-beta
title "Base CPU"
x-axis "Elapsed seconds" [1.537, 3.04, 5.045, 6.545, 8.046, 9.548, 11.551, 13.055, 14.556, 16.059, 17.56, 19.561, 21.065, 21.565, 22.566, 24.067, 26.069, 27.07, 27.571, 29.072, 30.573, 32.075, 34.078, 35.579, 37.081, 38.583, 40.586, 42.088, 43.592, 45.093, 46.595, 48.598, 50.101, 51.603, 53.105, 54.607, 55.108, 56.61]
y-axis "CPU percent" 0 --> 200
line [77.91, 2, 89.8, 127.97, 93.94, 125.77, 129.74, 137.62, 3.99, 3.99, 44.01, 77.9, 5.99, 0, 0, 133.68, 117.69, 99.84, 105.94, 101.8, 115.83, 121.79, 105.88, 43.96, 47.95, 111.69, 29.97, 25.93, 25.93, 2, 25.98, 9.97, 89.93, 5.99, 99.88, 153.7, 119.88, 121.82]
xychart-beta
title "Base memory: RSS then PSS"
x-axis "Elapsed seconds" [0.036, 1.537, 3.04, 5.045, 6.545, 8.046, 9.548, 11.551, 13.055, 14.556, 16.059, 17.56, 19.561, 21.065, 21.565, 22.566, 24.067, 26.069, 27.07, 27.571, 29.072, 30.573, 32.075, 34.078, 35.579, 37.081, 38.583, 40.586, 42.088, 43.592, 45.093, 46.595, 48.598, 50.101, 51.603, 53.105, 54.607, 55.108, 56.61, 57.677]
y-axis "Memory MiB" 0 --> 500
line [13.68, 101.78, 100.65, 129.87, 142.83, 130.78, 154.46, 155.23, 136.32, 121.51, 120.36, 130.54, 147.29, 125.18, 125.18, 124.02, 148.48, 139.42, 243.48, 220.79, 202.72, 138.38, 180.57, 138.76, 139.98, 150.22, 235.9, 224.56, 234.75, 229.8, 232.14, 230.68, 131.5, 149.37, 130.42, 149.62, 142.64, 152.82, 148.61, 0]
line [10.2, 98.22, 96.95, 126.18, 139.22, 127.09, 150.84, 151.54, 132.58, 117.77, 116.62, 126.8, 143.55, 121.44, 121.44, 120.28, 144.74, 135.6, 239.77, 216.62, 199, 134.64, 176.82, 135, 136.24, 146.48, 232.06, 220.82, 231.01, 226.06, 228.4, 226.93, 127.76, 145.65, 126.68, 145.99, 139.32, 149.18, 144.89, 0]
HEADxychart-beta
title "HEAD CPU"
x-axis "Elapsed seconds" [2.038, 4.041, 6.544, 8.546, 10.549, 12.552, 14.054, 15.056, 17.059, 19.06, 21.063, 23.066, 25.568, 27.571, 29.574, 31.577, 34.079, 36.082, 38.084, 39.587, 40.087, 42.089, 44.593, 46.596, 48.6, 50.603, 53.105, 55.107, 57.109, 59.111, 61.114, 63.618, 65.621, 67.624, 69.627, 72.13, 74.133, 75.634]
y-axis "CPU percent" 0 --> 200
line [107.81, 133.7, 91.92, 107.9, 135.89, 23.94, 0, 8, 3.99, 111.95, 2, 2, 67.91, 99.91, 103.76, 63.92, 69.92, 105.84, 45.94, 105.92, 139.8, 23.98, 41.91, 27.96, 25.98, 23.97, 0, 0, 2, 0, 2, 23.97, 23.97, 21.96, 15.97, 125.81, 49.93, 162.04]
xychart-beta
title "HEAD memory: RSS then PSS"
x-axis "Elapsed seconds" [0.036, 2.038, 4.041, 6.544, 8.546, 10.549, 12.552, 14.054, 15.056, 17.059, 19.06, 21.063, 23.066, 25.568, 27.571, 29.574, 31.577, 34.079, 36.082, 38.084, 39.587, 40.087, 42.089, 44.593, 46.596, 48.6, 50.603, 53.105, 55.107, 57.109, 59.111, 61.114, 63.618, 65.621, 67.624, 69.627, 72.13, 74.133, 75.634, 75.931]
y-axis "Memory MiB" 0 --> 500
line [13.61, 113.45, 156.77, 128.02, 142.57, 132.18, 124.35, 123.46, 124.81, 125.66, 150.08, 127.35, 126.39, 144.01, 220.86, 202.1, 147.2, 163.7, 148.1, 171.52, 248.65, 247.4, 226.77, 233.83, 232.33, 232.45, 232.42, 232.45, 232.49, 231.89, 231.32, 231.33, 231.25, 231.3, 231.3, 142.39, 160.54, 149.15, 155.64, 0]
line [10.26, 109.96, 153.35, 124.41, 138.98, 128.66, 120.75, 119.85, 121.21, 122.19, 146.59, 123.71, 122.75, 141.68, 217.26, 198.5, 143.58, 160.08, 144.46, 167.92, 245.02, 243.81, 223.29, 230.35, 228.7, 228.82, 228.78, 228.82, 228.85, 228.2, 227.69, 227.7, 227.62, 227.67, 227.68, 138.77, 156.93, 145.54, 152.87, 0]
Deterministic fixture · required contractThe fixture exercises 15 routes: 8 are expected to emit rows and 7 intentionally exercise empty, loading, or timeout behavior.
Full HTML, JSON, CSV, logs, and page snapshots: workflow run and full The public-web A/B is informational. The exact HEAD fixture contract runs as a separate required CI check; timing and public-site content deltas remain non-blocking. |
CI Regression ReportSource CI run · source state at render:
Release regression — ✅ HEAD/base failures 0/0; raw binary +0.002913%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 — ✅ 118/118 groups passed; 1,754 scenariosWorkers: 4 · cumulative group time: 559.80 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. |
Sequential Navigation Soak A/B✅ HEAD completed the 200-navigation resilience and memory observation. One browser process, one target, and one CDP session navigate CSDN → SegmentFault → Huaban → example.com repeatedly. This run issued 200 Common ancestor Session resilience
A public-page failure is reported separately from an unrecoverable session. The soak requires all navigation attempts, zero failed recovery, zero lifecycle/network ordering violations, and complete resource evidence. Process-tree memory
HEAD memory by 50-navigation quarter
Raw reports and per-navigation boundary samples: workflow run and full Public-site timing and memory are observational. Use the A/B deltas and trend shape as evidence, not as a deterministic performance threshold. |
3b30348 to
622b0fb
Compare
lanyue-llk
left a comment
There was a problem hiding this comment.
Independent review of 622b0fb
No blocking findings
Checked against origin/main 885432b (merge-base 16861c2, which already contains #2836 / cbbcf11).
- #2836 design. Followed. There is no DOM copy and no second traversal.
LiveDomasks the sameHtmlEmbeddedDocumentProvider(PageScriptHost) for each element, in the html2md walk that already runs (markdown_dump/live_dom.rs:87-109,:226-252). That provider validates the host handle, active state and theFrameOwnerStorecurrent document, and it is the same gate the writer uses through the extractedembedded_documents_for_export(context_host/html_serialization.rs:59-71).sole_owneris read once and applied as inengine.rs:634. Nothing #2836 removed comes back: the Markdownwith_framesargument #2836 dropped was ignored, and this one is honoured. - Correctness.
parent_nodemaps the inlined body back to its owner (live_dom.rs:172-176). Inheriteddisplay:nonetherefore hides a hidden frame's content, andHiddenChildFramestyles stay empty.- Child-document links use
Document::base_url()only for documents this export actually inlined (live_dom.rs:160-170,visibility.rs:297). Top-document nodes keep the page base URL. - The new CLI test fails without the change: the srcdoc frame produces no text. It covers a nested frame, a child
<base>, and unchanged output without the flag.
- Default cost. With
with_frames=false, or when no child Documents exist, the provider isNone.is_projected()then reduces to the oldhas_shadow_rootscheck, and the nativeNativeDompath is used exactly as before. The only additions are one immutable_context_hostborrow and earlyself.frames?returns. - Scope/merit.
--with-framesis a documented CLI flag that--dump htmlandsemantic_tree_textalready honour; Markdown silently ignored it. Supporting it here is worthwhile in its own right, and the diff is small: 10 files, +132/-17. - CI. Nextest, Clippy, Format, Python, Node and Windows pass. The release builds and CDP smoke were still pending when I checked.
Non-blocking note: the body says "inlined under one owner at most, which also rules out cycles". That rule covers a Document claimed by two owners. It does not cover an owner whose recorded Document is its own owner document or the top document. The writer rejects both cases (engine.rs:792-793, CyclicEmbeddedDocument). Here, collect_node_ids would loop without bound. FrameOwnerStore cannot currently produce either record, so this is not a finding. If you want parity with the writer, a single guard in frame_root would do: document != host.document_handle() && owner_document(owner) != Some(document).

**Track:** Web Fetch (Browser Eval). Replaces part of #1592.Closes #2757.
Replaces part of #1592.
Problem.
moli fetch URL --dump markdown --with-framesignored--with-frames. An iframe withsrccame out as[Embedded content](src), and asrcdociframe produced nothing.--dump htmlandsemantic_tree_textdo inline frames. Repro (issue fixture):moli fetch http://127.0.0.1:8000/index.html --dump markdown --with-frames.Reproduce (steps from #2757)
Expected
The frame's current document appears at the iframe position, and child links resolve against the child URL. This is what the
moli-webfetchskill describes ("Add--with-framesif the content is in an iframe"), and it is what--dump html --with-framesand--dump semantic_tree_text --with-framesalready do:Actual
The output is the same with and without
--with-frames:An
<iframe srcdoc="<p>SRCDOC TEXT</p>">produces no output at all.Change. Rebased onto #2836 and reworked to use its export design: Markdown reaches child Documents through the same borrowed lookup as the HTML writer, with no DOM copy and no separate frame traversal.
RendererMarkdownOptionsgainswith_frames, mirroringRendererHtmlSerializeOptions.fetch_dumpforwards the CLI flag through it the same way it does for--dump html.context_host/html_serialization.rs: the existing "with frames and child Documents exist" gate becomesembedded_documents_for_export, shared by the HTML writer and Markdown. Both receive the sameHtmlEmbeddedDocumentProvider, which validates eachFrameOwnerStorerecord.ScriptVm::with_embedded_documents_for_exportlends it for one export.markdown_dump/live_dom.rs:LiveDomasks the provider for an owner's Document while html2md walks the tree. This is the per-element lookup the writer also makes, and it honourssole_ownertoo. The owner then reads as a plaindivwhose only child is that Document's<body>(or root element). The export-local projection cache maps the body's parent back to the owner. A Document is inlined under one owner at most, which also rules out cycles. A hidden iframe still hides its content through the existing inherited visibility.MarkdownSource::frame_base_url(defaultNone) borrows the base URL of an inlined Document.markdown_dump/visibility.rsuses it to resolvehref/src, so child links resolve against the child URL.--with-framesis off or the page has no child Documents, the provider isNone. The adapter and every lookup behave exactly as on main.Verification. Rebased build (main 16861c2 + this commit), issue fixture
index.htmlandmd.html(asrcdocframe, adisplay:noneframe and a nested frame):md.html --with-frameson this branch gives# Root / SRCDOC TEXT / OUTER / INNER / End; the hidden frame's text is omitted. Without--with-framesthe output matches main.cargo nextest run -p moli --test fetch_cli -E 'test(markdown) | test(with_frames)': 10 passed, includingmarkdown_with_frames_inlines_child_documents_with_their_own_base_url. That test covers a nestedsrcdocframe, a child<base href>that must win over the parent URL, and unchanged output without the flag. It also includescli_dump_html_with_frames_nests_and_strips_child_documents.cargo nextest run -p moli-renderer-v8 -E 'test(markdown) | test(html_dump) | test(html_serialization) | test(virtual_base) | test(lazy_main_world)': 65 passed. This covers refactor(html): serialize page exports without DOM copies #2836's serializer neighbours and theLiveDomprojection test.cargo nextest run -p moli --lib -E 'test(fetch_dump)': 18 passed.cargo fmt --allis clean, and so iscargo clippy -p moli-renderer-v8 -p moli --all-targets --all-features -- -D warnings. Workspace clippy was not run locally.Cost. Without
--with-frames, or with no child Documents, the change adds oneOptioncheck per lookup. No map is built. With frames, each element gets the same provider lookup the HTML writer already makes, and each inlined frame adds one cache entry. Child Document nodes are styled and converted once, like top-document nodes. Both sides are debug builds of the same profile: main 16861c2 and this branch. Each was measured with/usr/bin/time -lover 5 alternating runs; the table shows the median. Another build was running on the host, so differences of ±0.02 s are noise.--dump markdown --with-frames--dump markdown --with-frames--dump markdown--dump markdown --with-frames