Skip to content

fix(dump): include and strip shadow roots in html dumps - #2821

Merged
ldm0 merged 4 commits into
fix/dump-nested-framesfrom
fix/dump-shadow-roots
Nov 12, 2026
Merged

ldm0 merged 4 commits into
fix/dump-nested-framesfrom
fix/dump-shadow-roots

Conversation

@lanyue-llk

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

Copy link
Copy Markdown
Contributor

Track: Web Fetch (Browser Eval). Closes #2804. Replaces part of #1592. Stacked on #2801 (fix/dump-nested-frames).

PR #2821 at a glance

HTML dumps now include author Shadow DOM at the top level and inside loaded child frames. CSS/JS/UI stripping applies to the export copy before nested frame markup is folded into srcdoc.

  • Serialize author shadow roots as <template shadowrootmode> through the existing shadow-root provider. Plain HTML dumps and CDP MHTML snapshots use the same representation; ordinary shadow-excluding DOM outerHTML retains its contract.
  • Discover live frames inside shadow trees through the existing candidate index and shadow-including ordering. Preserve parent-before-child frame order for bottom-up inlining, and exclude inert template.content owners from connected frame queries.
  • Strip every included child Document and shadow fragment before serialization. --strip-mode css/full also omits shadowrootadoptedstylesheets from generated shadow templates, at both top level and inside frames. Ordinary exports, JS-only stripping, and Web getHTML() retain authored stylesheet metadata.
  • Keep all filtering in the export copy or temporary serialization metadata. Live DOM, ShadowRootInit, and stylesheet state remain intact; no new serialization engine or DOM clone is introduced.

Regression coverage waits for the actual child DOM update (AFTER, absent from the authored markup) and adopted stylesheet computed color before exporting. It covers shadow → iframe, iframe → closed shadow → iframe, frame reordering and detachment, inert template candidates, plain versus CSS/full/JS stripping, and live metadata preservation.

Validation on the final tree (Rust 1.96.1, 24 build jobs/test threads, retries disabled):

  • Both new CLI regressions failed on aa4c276f88 with production code unchanged: stale before markup despite live AFTER, and adopted CSS metadata retained under CSS stripping.
  • The initial full baseline was 22,973 passed, 1 failed, 20 skipped. The existing outerHTML/SerializeHtml test failed 10/10 isolated baseline runs because it still equated shadow-excluding outerHTML with serialization that now includes author roots. A separate test commit aligns that assertion while retaining author-only/UA exclusion checks.
  • 24 focused tests passed.
  • 37 serialization, frame lifecycle, and HTML dump tests passed 20 stress iterations (740 test executions), with --flaky-result fail.
  • cargo fmt --all
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo nextest run --no-fail-fast: 22,978 passed, 20 skipped, 0 failed.

The review fixes are separate English commits. Baseline failures and the inactive-template probe are retained with the local investigation logs in target/dump-shadow-review-20261112/.

@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 aa4c276

No blocking findings

Reviewed against base fix/dump-nested-frames (#2801), one commit.

  • Root cause fixed in both paths. The post-process dump (page_dump.rs:37-59) strips every shadow fragment in the copy before frames are inlined and then serializes the top document through the same get_html_from_copy provider that child frames use. The fast path (page_dom.rs:3527-3537) does the same. --dump json goes through render_html, so it picks up the fix too.
  • Open and closed roots are both emitted. The roots are passed as explicit roots with serializable: false. That is consistent with moli's frame path and Markdown output, and it is the right default for an agent dump. Nested roots are covered because the serializer engine queries the provider for every element (engine.rs:292). Slotted nodes stay as light children and are not duplicated. delegatesfocus, serializable, clonable and slotassignment are written by the existing write_shadow_root_template_start.
  • Strip: apply_strip_options returns early when no flag is set, so the new per-root loop does nothing without --strip-mode. With a flag, js, css and ui all apply inside the shadow fragments.
  • Cost: a page without shadow roots still goes through serialize_document() unchanged. The only extra work is an empty-map snapshot. The numbers in the body are plausible.
  • Test: cli_dump_html_includes_and_strips_shadow_roots would fail without the fix on all three asserts.

Non-blocking note: serialize_html also backs CDP Page.captureSnapshot (moli-protocol/src/domains/page/capture.rs:172). MHTML snapshots of shadow pages now contain <template shadowrootmode>. Chrome's MHTML serializer also writes shadow roots, so this moves toward Chrome, but the body should list this consumer.

CI: Clippy, Format, Node, Python and Windows pass. Nextest, CDP smoke and the release builds are still pending.
Picture: pending.

@ldm0
ldm0 added this pull request to stack #2824 November 12, 2026 12:53
@ldm0
ldm0 merged commit 1c00ef7 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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--dump html omits shadow DOM at the top level (frames and Markdown include it) and --strip-mode does not reach shadow trees

2 participants