Skip to content

armgit / moli

Public Imported from GitHub
0

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

fix(popups): expose DOMException constructor

ldm05c536d903ede
diff --git a/moli-renderer-v8/src/native_bridge/context_host/popups.rs b/moli-renderer-v8/src/native_bridge/context_host/popups.rs
index aca7a2856..e0d71c035 100644
--- a/moli-renderer-v8/src/native_bridge/context_host/popups.rs
+++ b/moli-renderer-v8/src/native_bridge/context_host/popups.rs
@@ -38,8 +38,9 @@ use crate::{
PopupDocumentLoadCompletion, PopupDocumentLoadOutcome,
},
util::{
- context_host_ptr_from_global_bridge, get_private_value, set_private_value,
- throw_type_error, v8_string, v8str,
+ context_host_ptr_from_global_bridge, define_non_enumerable_static_property,
+ get_private_value, global_constructor_object, set_private_value, throw_type_error,
+ v8_string, v8str,
},
window_document_identity::{
LightweightPopupDocumentId, LightweightPopupDocumentOwner, LightweightPopupLocalWindowId,
@@ -711,6 +712,17 @@ impl JsContextHost {
.bridge
.bindings
.instantiate_window_shell(scope, host_ptr);
+ if let Some(dom_exception) = global_constructor_object(scope, "DOMException") {
+ // Lightweight popups share the opener's V8 realm, so their
+ // synthetic Window shell must expose the same realm constructor
+ // used by DOM exceptions thrown from popup-owned callbacks.
+ define_non_enumerable_static_property(
+ scope,
+ window,
+ "DOMException",
+ dom_exception.into(),
+ );
+ }
let popup_id_private_value = v8::BigInt::new_from_u64(scope, popup_id);
set_private_value(
scope,
diff --git a/moli-renderer-v8/src/script_vm/tests/browser_api/misc.rs b/moli-renderer-v8/src/script_vm/tests/browser_api/misc.rs
index 4202df96a..10e883122 100644
--- a/moli-renderer-v8/src/script_vm/tests/browser_api/misc.rs
+++ b/moli-renderer-v8/src/script_vm/tests/browser_api/misc.rs
@@ -23452,6 +23452,51 @@ fn window_open_lightweight_popup_location_assignment_uses_window_setter() {
);
}
+#[test]
+fn lightweight_popup_location_uses_its_exposed_dom_exception_constructor() {
+ let mut vm = new_storage_test_vm("https://example.com/");
+
+ let result = vm
+ .eval(
+ r##"
+ (() => {
+ const popup = open("about:blank");
+ const originalHref = popup.location.href;
+ const descriptor = Object.getOwnPropertyDescriptor(popup, "DOMException");
+ let thrown;
+ try {
+ popup.location.href = "https://example.com:notaport/common/blank.html";
+ } catch (error) {
+ thrown = [
+ error.name,
+ error.code,
+ error.constructor === popup.DOMException,
+ error instanceof popup.DOMException
+ ].join(":");
+ }
+ return [
+ typeof popup.DOMException,
+ descriptor.enumerable,
+ descriptor.configurable,
+ descriptor.writable,
+ thrown,
+ popup.location.href === originalHref
+ ].join("|");
+ })()
+ "##,
+ )
+ .expect("popup invalid Location URL probe should evaluate");
+
+ assert_eq!(
+ result,
+ "function|false|true|true|SyntaxError:12:true:true|true"
+ );
+ assert!(
+ vm.take_pending_location_navigation_with_seed().is_none(),
+ "invalid popup Location navigation must not escape to the opener"
+ );
+}
+
#[tokio::test]
async fn lightweight_popup_fragment_navigation_dispatches_popstate_and_hashchange() {
let loader = ResourceRequestClient::new(&moli_fetch::FetchConfig::default()).expect("loader");