Skip to content

armgit / moli

Public Imported from GitHub
0

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

fix(iframe): dispatch one initial load for adopted frames

ldm0e806cfbeb311
diff --git a/moli-protocol-server/src/protocol_server/tests/cdp_dynamic_page/auxiliary_page_identity.rs b/moli-protocol-server/src/protocol_server/tests/cdp_dynamic_page/auxiliary_page_identity.rs
index 9921c4a47..b77ff5d50 100644
--- a/moli-protocol-server/src/protocol_server/tests/cdp_dynamic_page/auxiliary_page_identity.rs
+++ b/moli-protocol-server/src/protocol_server/tests/cdp_dynamic_page/auxiliary_page_identity.rs
@@ -1204,6 +1204,43 @@ async fn initial_same_origin_popup_commit_preserves_window_and_replaces_document
);
}
+#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
+async fn auxiliary_adopted_iframe_loads_once_after_native_connection() {
+ let (fixture_addr, _fixture) = spawn_dedicated_fixture_server(
+ Router::new().fallback(get(|| async {
+ axum::response::Html("<!doctype html><p>loaded</p>")
+ })),
+ "auxiliary-adopted-iframe-load",
+ );
+ let (addr, server) = spawn_test_protocol_server().await;
+ let (mut browser, _) =
+ connect_async(format!("ws://{addr}/devtools/browser/{DEFAULT_BROWSER_ID}"))
+ .await
+ .unwrap();
+ let opener_id = create_dynamic_target(&mut browser, 1).await;
+ let mut opener = connect_dynamic_page(addr, &opener_id).await;
+ send_cdp_command(&mut opener, 1, "Page.enable", None, json!({})).await;
+ navigate_dynamic_page_and_wait_for_load(
+ &mut opener,
+ 2,
+ &format!("http://{fixture_addr}/parent"),
+ )
+ .await;
+ let (_, mut child) = open_auxiliary(addr, &mut opener, "").await;
+ navigate_dynamic_page_and_wait_for_load(&mut child, 2, &format!("http://{fixture_addr}/popup"))
+ .await;
+ evaluate_window_name_probe(&mut opener, 3, r#"window.adoptedIframeLoaded=false;window.adoptedLoadCount=0;
+ window.adoptedFrame=document.createElement('iframe');
+ adoptedFrame.onload=function(){adoptedLoadCount++;adoptedIframeLoaded=this===adoptedFrame&&this.ownerDocument===p.document};
+ p.document.body.append(adoptedFrame);true"#).await;
+ wait_for_value(&mut opener, "adoptedIframeLoaded", json!(true)).await;
+ assert_eq!(
+ evaluate_window_name_probe(&mut opener, 4, "adoptedLoadCount").await,
+ json!(1)
+ );
+ abort_test_cdp_server(server).await;
+}
+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn initial_popup_commit_recreates_isolated_worlds_for_all_frontends() {
let release = Arc::new(tokio::sync::Notify::new());
diff --git a/moli-renderer-v8/src/native_bridge/node/mutation/core.rs b/moli-renderer-v8/src/native_bridge/node/mutation/core.rs
index f284fc717..a6cec8c62 100644
--- a/moli-renderer-v8/src/native_bridge/node/mutation/core.rs
+++ b/moli-renderer-v8/src/native_bridge/node/mutation/core.rs
@@ -64,6 +64,11 @@ fn dispatch_detached_post_insert_events(
handles: &[DomHandle],
) {
for handle in handles {
+ // A connected native iframe already owns its initial load delivery.
+ // A paired foreign reflector must not add a second synthetic event.
+ if unsafe { &*runtime_ptr }.child_browsing_context_host_is_active(*handle) {
+ continue;
+ }
if !unsafe { &*runtime_ptr }
.dom_host()
.is_html_element_named(*handle, "iframe")