Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

fix(renderer): keep pending child navigation uncommitted

ldm0f2a2e021e4b4
diff --git a/moli-renderer-v8/src/native_bridge/context_host/child_frames/registry.rs b/moli-renderer-v8/src/native_bridge/context_host/child_frames/registry.rs
index 5c0c206fe..f8b52bdc8 100644
--- a/moli-renderer-v8/src/native_bridge/context_host/child_frames/registry.rs
+++ b/moli-renderer-v8/src/native_bridge/context_host/child_frames/registry.rs
@@ -147,7 +147,17 @@ impl JsContextHost {
Self::child_browsing_context_single_entry_seed(&attribute_bootstrap)
})
};
- let committed_navigation_entry_seed = if attribute_bootstrap_changed {
+ let committed_navigation_entry_seed = if is_new {
+ // The target entry is planned when a frame owner with a
+ // non-blank navigation attribute is discovered, but its
+ // live Document is still the synchronous initial empty
+ // document. Keep the committed projection pinned to that
+ // actual Document until NavigationCommit installs the
+ // fetched/srcdoc target. Otherwise a pending iframe can
+ // expose the target URL together with the old complete
+ // about:blank Document.
+ Self::child_browsing_context_single_entry_seed(&live_bootstrap)
+ } else if attribute_bootstrap_changed {
existing
.as_ref()
.map(|entry| entry.committed_navigation_entry_seed())
diff --git a/moli-renderer-v8/src/script_vm/tests/mod.rs b/moli-renderer-v8/src/script_vm/tests/mod.rs
index 9dca853a2..39cbb41ee 100644
--- a/moli-renderer-v8/src/script_vm/tests/mod.rs
+++ b/moli-renderer-v8/src/script_vm/tests/mod.rs
@@ -6210,6 +6210,58 @@ async fn child_parser_resumes_write_queued_during_external_script_block() {
assert_eq!(result, "true|true");
}
+#[test]
+fn pending_initial_child_navigation_keeps_initial_empty_window_surface() {
+ let mut vm = new_storage_test_vm("https://child-pending-window.test/");
+
+ vm.eval(
+ r#"
+(() => {
+ const frame = document.createElement("iframe");
+ frame.id = "pending-window";
+ frame.src = "https://child-pending-window.test/target.html";
+ (document.body || document.documentElement || document).appendChild(frame);
+})()
+"#,
+ )
+ .expect("pending child Window setup should evaluate");
+
+ assert!(
+ vm.has_pending_child_navigation_commit_for_test(),
+ "the target navigation must remain pending before its typed commit turn"
+ );
+ assert_eq!(
+ vm.eval(
+ r#"
+(() => {
+ const child = document.getElementById("pending-window").contentWindow;
+ return [
+ child.location.href,
+ child.navigation.currentEntry?.url ?? "null",
+ child.document.URL,
+ child.document.readyState,
+ ].join("|");
+})()
+"#,
+ )
+ .expect("pending child Window state should evaluate"),
+ "about:blank|about:blank|about:blank|complete",
+ "a planned target must not be projected as committed while the initial empty Document is still live"
+ );
+
+ let child_handle = vm
+ ._context_host
+ .borrow()
+ .child_browsing_context_handles_in_document_order()[0];
+ assert!(
+ vm._context_host
+ .borrow()
+ .child_browsing_context_current_url(child_handle)
+ .is_some_and(|url| moli_url::is_about_blank(&url)),
+ "native current-Document state must agree with the initial empty Window surface"
+ );
+}
+
#[tokio::test]
async fn pending_child_navigation_does_not_materialize_initial_empty_preload_realm() {
let mut vm = new_storage_test_vm("https://child-preload-lazy.test/");