Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
fix(dom): resolve detached nodes in their owning host
ldm0910fbed1d545
diff --git a/moli-renderer-v8/src/native_bridge/node.rs b/moli-renderer-v8/src/native_bridge/node.rsindex 195f07ccb..d497265e7 100644--- a/moli-renderer-v8/src/native_bridge/node.rs+++ b/moli-renderer-v8/src/native_bridge/node.rs@@ -10,7 +10,7 @@ use moli_webapi_declare::WebApiFunctionTemplate;use super::super::{document_runtime::DomHandle,util::{- call_global_bridge_method, context_host_ptr_from_global_bridge, get_private_value,+ call_global_bridge_method, context_host_ptr_from_context_slot, get_private_value,throw_type_error, v8_string, v8str,},};@@ -1251,8 +1251,13 @@ pub(crate) fn node_runtime_and_handle_from_object_or_detached<'s>(if let Ok(node) = node_runtime_and_handle_from_object(scope, object) {return Ok(node);}- let runtime_ptr = context_host_ptr_from_global_bridge(scope)- .context("current context has no JsContextHost")?;+ // Detached node indices are host-local too. Borrowed bindings and+ // structuredClone can run in another Page, so resolve the producer's+ // lifecycle-checked context instead of looking in the caller's arena.+ let runtime_ptr = object+ .get_creation_context(scope)+ .and_then(context_host_ptr_from_context_slot)+ .context("detached node's context has no JsContextHost")?;let handle = super::document::detached_native_handle_for_runtime(scope, runtime_ptr, object).context("object is neither a Node wrapper nor a detached node")?;Ok((runtime_ptr, handle))diff --git a/moli-renderer-v8/src/script_vm/tests/detached_node_producer_host.rs b/moli-renderer-v8/src/script_vm/tests/detached_node_producer_host.rsnew file mode 100644index 000000000..50d50d439--- /dev/null+++ b/moli-renderer-v8/src/script_vm/tests/detached_node_producer_host.rs@@ -0,0 +1,24 @@+use super::*;++#[test]+fn borrowed_node_accessors_resolve_windowless_nodes_in_the_producing_host() {+ let mut vm = new_storage_page_task_executor_test_vm("https://detached-producer-host.test/");+ let result = vm.eval(r#"(() => {+ document.body.innerHTML = '<iframe></iframe>';+ const other = document.querySelector('iframe').contentWindow;+ const docs = [other.document.implementation.createHTMLDocument(''),+ other.document.implementation.createDocument('urn:child', 'root')];+ for (const doc of docs) {+ const element = doc.createElementNS('urn:child', 'owned');+ element.setAttribute('data-owner', 'child');+ for (let i = 0; i < 40; ++i) document.createElement('unrelated');+ const getName = Object.getOwnPropertyDescriptor(Node.prototype, 'nodeName').get;+ if (getName.call(element) !== 'owned') throw Error('wrong native node');+ if (Element.prototype.getAttribute.call(element, 'data-owner') !== 'child') throw Error('wrong owner arena');+ Element.prototype.setAttribute.call(element, 'data-owner', 'borrowed');+ if (element.getAttribute('data-owner') !== 'borrowed') throw Error('wrong mutation owner');+ }+ return true;+ })()"#).unwrap();+ assert_eq!(result, "true");+}diff --git a/moli-renderer-v8/src/script_vm/tests/mod.rs b/moli-renderer-v8/src/script_vm/tests/mod.rsindex a7c9917b3..b413f3041 100644--- a/moli-renderer-v8/src/script_vm/tests/mod.rs+++ b/moli-renderer-v8/src/script_vm/tests/mod.rs@@ -2248,3 +2248,5 @@ mod domrect_receiver_consolidation;mod resize_observer_entries;mod payment_events;++mod detached_node_producer_host;