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(html): expose obsolete no-op methods
ldm0089a899e6fb6
diff --git a/moli-renderer-v8/src/context_bootstrap/window_runtime.rs b/moli-renderer-v8/src/context_bootstrap/window_runtime.rsindex 7377e7cad..68c8d6ca6 100644--- a/moli-renderer-v8/src/context_bootstrap/window_runtime.rs+++ b/moli-renderer-v8/src/context_bootstrap/window_runtime.rs@@ -4,6 +4,7 @@ mod base64;mod date_locale;mod dialogs;mod navigator;+mod obsolete;mod performance;mod service_worker;mod structured_clone;@@ -47,6 +48,7 @@ pub(super) use navigator::{storage_bucket_persist_callback, storage_bucket_persisted_callback,storage_bucket_set_expires_callback,};+pub(super) use obsolete::window_obsolete_noop_callback;pub(super) use performance::performance_now_callback;pub(crate) use service_worker::{ServiceWorkerClientMessageCallbackDispatchEffect, ServiceWorkerClientMessageDispatchEffect,diff --git a/moli-renderer-v8/src/context_bootstrap/window_runtime/obsolete.rs b/moli-renderer-v8/src/context_bootstrap/window_runtime/obsolete.rsnew file mode 100644index 000000000..3f0e95386--- /dev/null+++ b/moli-renderer-v8/src/context_bootstrap/window_runtime/obsolete.rs@@ -0,0 +1,31 @@+use crate::util::{context_host_ptr_from_window_object, throw_type_error};++fn receiver_is_window(+ scope: &mut v8::PinScope<'_, '_>,+ receiver: v8::Local<'_, v8::Object>,+) -> bool {+ if context_host_ptr_from_window_object(scope, receiver).is_none() {+ return false;+ }+ let global = scope.get_current_context().global(scope);+ if receiver.strict_equals(global.into()) {+ return true;+ }+ receiver+ .get_internal_field(scope, 1)+ .and_then(|value| v8::Local::<v8::Value>::try_from(value).ok())+ .and_then(|value| value.number_value(scope))+ .is_some_and(|marker| marker.is_finite() && marker.fract() == 0.0 && marker == 0.0)+}++pub(in crate::context_bootstrap) fn window_obsolete_noop_callback<'s>(+ scope: &mut v8::PinScope<'s, '_>,+ args: v8::FunctionCallbackArguments<'s>,+ mut rv: v8::ReturnValue<'s, v8::Value>,+) {+ if !receiver_is_window(scope, args.this()) {+ throw_type_error(scope, "Illegal invocation");+ return;+ }+ rv.set_undefined();+}diff --git a/moli-renderer-v8/src/context_bootstrap/window_template.rs b/moli-renderer-v8/src/context_bootstrap/window_template.rsindex 05755dbfe..81328e6e5 100644--- a/moli-renderer-v8/src/context_bootstrap/window_template.rs+++ b/moli-renderer-v8/src/context_bootstrap/window_template.rs@@ -81,6 +81,16 @@ struct WindowEarlyTemplateMethodsDeclaration {find: (),}+#[derive(WebApiFunctionTemplate)]+#[webapi(name = "Window", enumerable)]+struct WindowObsoleteTemplateMethodsDeclaration {+ #[webapi(method, length = 0, callback = window_obsolete_noop_callback)]+ capture_events: (),++ #[webapi(method, length = 0, callback = window_obsolete_noop_callback)]+ release_events: (),+}+#[derive(WebApiFunctionTemplate)]#[webapi(name = "Window", enumerable)]struct WindowPostNetworkTemplateMethodsDeclaration {@@ -335,6 +345,7 @@ pub(crate) fn install_window_own_template_bindings<'s>(// functions the actual WindowProxy as `this`.WindowIdentityAccessorsDeclaration::initialize_prototype_template(scope, window_template);WindowEarlyTemplateMethodsDeclaration::initialize_prototype_template(scope, window_template);+ WindowObsoleteTemplateMethodsDeclaration::initialize_prototype_template(scope, window_template);network_host::install_window_network_bindings(scope, window_template);WindowPostNetworkTemplateMethodsDeclaration::initialize_prototype_template(scope,diff --git a/moli-renderer-v8/src/native_bridge/document.rs b/moli-renderer-v8/src/native_bridge/document.rsindex d447b08a7..946c9e932 100644--- a/moli-renderer-v8/src/native_bridge/document.rs+++ b/moli-renderer-v8/src/native_bridge/document.rs@@ -461,6 +461,17 @@ struct DocumentCollectionQueryPrototypeDeclaration {get_elements_by_name: (),}+#[derive(WebApiFunctionTemplate)]+#[webapi(name = "Document", enumerable)]+struct DocumentObsoleteMethodsPrototypeDeclaration {+ #[webapi(method, length = 0, callback = document_obsolete_noop_callback)]+ clear: (),+ #[webapi(method, length = 0, callback = document_obsolete_noop_callback)]+ capture_events: (),+ #[webapi(method, length = 0, callback = document_obsolete_noop_callback)]+ release_events: (),+}+#[derive(WebApiFunctionTemplate)]#[webapi(name = "DocumentFragment")]struct DocumentFragmentCollectionQueryPrototypeDeclaration {@@ -507,6 +518,18 @@ fn document_receiver_runtime_and_handle<'s>(Some((runtime_ptr, handle))}+fn document_obsolete_noop_callback<'s>(+ scope: &mut v8::PinScope<'s, '_>,+ args: v8::FunctionCallbackArguments<'s>,+ mut rv: v8::ReturnValue<'s, v8::Value>,+) {+ if document_receiver_runtime_and_handle(scope, args.this()).is_none() {+ throw_type_error(scope, "Illegal invocation");+ return;+ }+ rv.set_undefined();+}+fn set_document_string_return_value(scope: &mut v8::PinScope<'_, '_>,rv: &mut v8::ReturnValue<'_, v8::Value>,@@ -1342,6 +1365,9 @@ pub(crate) fn install_document_template_bindings<'s>(DocumentCollectionQueryPrototypeDeclaration::initialize_prototype_template(scope, prototype,);+ DocumentObsoleteMethodsPrototypeDeclaration::initialize_prototype_template(+ scope, prototype,+ );}if matches!(interface_name, "DocumentFragment" | "ShadowRoot") {DocumentFragmentCollectionQueryPrototypeDeclaration::initialize_prototype_template(diff --git a/moli-renderer-v8/src/script_vm/tests/dom_elements/detached.rs b/moli-renderer-v8/src/script_vm/tests/dom_elements/detached.rsindex 7c37a32ff..c60878169 100644--- a/moli-renderer-v8/src/script_vm/tests/dom_elements/detached.rs+++ b/moli-renderer-v8/src/script_vm/tests/dom_elements/detached.rs@@ -123,6 +123,69 @@ fn detached_document_write_preserves_existing_noscript_text() {);}+#[test]+fn obsolete_document_and_window_event_methods_are_branded_noops() {+ let mut vm = new_storage_test_vm("https://obsolete-noop-methods.test/");++ let result = vm+ .eval(+ r#"+(() => {+ const html = document.implementation.createHTMLDocument("");+ const xml = document.implementation.createDocument("urn:test", "root");+ const marker = document.createElement("p");+ const markerParent = document.body || document.documentElement || document;+ markerParent.append(marker);+ const error = callback => {+ try {+ callback();+ return "none";+ } catch (exception) {+ return exception.name;+ }+ };+ const shape = (prototype, name) => {+ const descriptor = Object.getOwnPropertyDescriptor(prototype, name);+ return [+ typeof descriptor?.value,+ descriptor?.value?.name,+ descriptor?.value?.length,+ descriptor?.writable,+ descriptor?.enumerable,+ descriptor?.configurable+ ].join(":");+ };++ const values = [];+ for (const name of ["clear", "captureEvents", "releaseEvents"]) {+ values.push(shape(Document.prototype, name));+ values.push(String(Document.prototype[name].call(document)));+ values.push(String(Document.prototype[name].call(html, { ignored: true })));+ values.push(String(Document.prototype[name].call(xml)));+ values.push(error(() => Document.prototype[name].call({})));+ }+ for (const name of ["captureEvents", "releaseEvents"]) {+ values.push(shape(window, name));+ values.push(String(window[name].call(window, { ignored: true })));+ values.push(error(() => window[name].call({})));+ values.push(error(() => window[name].call(document)));+ const forged = document.createElement("div");+ Object.setPrototypeOf(forged, Window.prototype);+ values.push(error(() => window[name].call(forged)));+ }+ values.push(String(marker.isConnected), String(markerParent.contains(marker)));+ return values.join("|");+})()+"#,+ )+ .expect("obsolete Document and Window no-op methods should evaluate");++ assert_eq!(+ result,+ "function:clear:0:true:true:true|undefined|undefined|undefined|TypeError|function:captureEvents:0:true:true:true|undefined|undefined|undefined|TypeError|function:releaseEvents:0:true:true:true|undefined|undefined|undefined|TypeError|function:captureEvents:0:true:true:true|undefined|TypeError|TypeError|TypeError|function:releaseEvents:0:true:true:true|undefined|TypeError|TypeError|TypeError|true|true"+ );+}+#[test]fn detached_domparser_query_and_element_collections_use_native_handles() {let mut vm = new_storage_test_vm("https://detached-domparser-query.test/");