From aa4c276f88b78aa1b2fc37191d2355e49fda8356 Mon Sep 17 00:00:00 2001 From: lanyue-llk <270302213+lanyue-llk@users.noreply.github.com> Date: Thu, 12 Nov 2026 19:05:44 +0700 Subject: [PATCH 1/4] fix(dump): include and strip shadow roots in html dumps --- .../child_frame_snapshots/document_lookup.rs | 23 +++++++++---- moli-renderer-v8/src/runtime/page_dom.rs | 13 +++++--- moli-renderer-v8/src/runtime/page_dump.rs | 18 +++++++++- .../src/script_vm/child_frame_runtime.rs | 10 ++++++ moli/tests/fetch_cli.rs | 33 +++++++++++++++++++ 5 files changed, 86 insertions(+), 11 deletions(-) diff --git a/moli-renderer-v8/src/native_bridge/context_host/child_frame_snapshots/document_lookup.rs b/moli-renderer-v8/src/native_bridge/context_host/child_frame_snapshots/document_lookup.rs index d33a9a05bab..bb72cf4addb 100644 --- a/moli-renderer-v8/src/native_bridge/context_host/child_frame_snapshots/document_lookup.rs +++ b/moli-renderer-v8/src/native_bridge/context_host/child_frame_snapshots/document_lookup.rs @@ -14,6 +14,21 @@ impl JsContextHost { let handle = self.child_browsing_context_owner_node_id_by_frame_id(frame_id)?; let document_handle = self.child_browsing_context_document_handle(handle)?; let url = self.child_browsing_context_current_url(handle)?; + let markup = self.document_markup_from_copy(document_handle, dom)?; + Some(ChildBrowsingContextDocumentSnapshot { + url: url.as_str().to_owned(), + markup, + }) + } + + /// Serializes `document_handle` (the page or a child frame Document) from + /// `dom`, an export copy of the live DOM, including that Document's + /// shadow roots and with its scripting flag. + pub(crate) fn document_markup_from_copy( + &self, + document_handle: crate::document_runtime::DomHandle, + dom: &NativeDom, + ) -> Option { let explicit_shadow_roots = self .dom_host() .snapshot_shadow_root_bindings() @@ -28,15 +43,11 @@ impl JsContextHost { }) .collect::>(); let scripting_enabled_for_node = |node| self.node_document_scripting_enabled(node); - let markup = self.dom_host().get_html_from_copy( + self.dom_host().get_html_from_copy( dom, document_handle, &scripting_enabled_for_node, &explicit_shadow_roots, - )?; - Some(ChildBrowsingContextDocumentSnapshot { - url: url.as_str().to_owned(), - markup, - }) + ) } } diff --git a/moli-renderer-v8/src/runtime/page_dom.rs b/moli-renderer-v8/src/runtime/page_dom.rs index 5645cf11bdd..ce0f38ec396 100644 --- a/moli-renderer-v8/src/runtime/page_dom.rs +++ b/moli-renderer-v8/src/runtime/page_dom.rs @@ -3525,11 +3525,16 @@ impl PageVm { } pub(crate) fn serialize_html(&self) -> String { + let host = self.vm().document_runtime.dom_host(); + let dom = host.dom(); + if host.snapshot_shadow_root_bindings().is_empty() { + return dom.serialize_document(); + } + // Include shadow roots as `