Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
feat(window): expose native BarProp objects and popup visibility
ldm0992b9f110435
diff --git a/moli-protocol-server/src/protocol_server/tests/websocket.rs b/moli-protocol-server/src/protocol_server/tests/websocket.rsindex 6cad96951..02bc970ca 100644--- a/moli-protocol-server/src/protocol_server/tests/websocket.rs+++ b/moli-protocol-server/src/protocol_server/tests/websocket.rs@@ -249,3 +249,5 @@ mod frame_network_and_automation_events;mod navigation_and_load_progress;mod parser_replacement_and_debugger;mod profiles_cache_and_interrupts;++mod bar_prop_visibility;diff --git a/moli-protocol-server/src/protocol_server/tests/websocket/bar_prop_visibility.rs b/moli-protocol-server/src/protocol_server/tests/websocket/bar_prop_visibility.rsnew file mode 100644index 000000000..6e989f0c3--- /dev/null+++ b/moli-protocol-server/src/protocol_server/tests/websocket/bar_prop_visibility.rs@@ -0,0 +1,62 @@+use super::*;++#[tokio::test]+async fn bar_props_follow_shared_popup_state_across_independent_pages() {+ let (fixture_addr, fixture_server) = spawn_local_storage_fixture_server().await;+ let (cdp_addr, protocol_server) = spawn_test_protocol_server().await;+ let (mut socket, _) = connect_async(format!(+ "ws://{cdp_addr}/devtools/browser/{DEFAULT_BROWSER_ID}"+ ))+ .await+ .expect("connect to browser websocket");+ let session_id = cdp_create_default_session_and_navigate(+ &mut socket,+ &format!("http://{fixture_addr}/page"),+ )+ .await;+ let expression = r#"(async () => {+ const names = ['locationbar', 'menubar', 'personalbar', 'scrollbars', 'statusbar', 'toolbar'];+ const readVisible = Object.getOwnPropertyDescriptor(BarProp.prototype, 'visible').get;+ const failures = [];+ let total = 0;+ const check = (name, pass) => {total++; if (!pass) failures.push(name);};+ for (const [features, expected] of [['', true], ['popup', false], ['popup=0,width=300', true]]) {+ const popup = window.open('about:blank', '_blank', features);+ for (let attempt = 0; attempt < 100 && (!popup.EventTarget || popup.Function === Function || !popup.document.body); attempt++)+ await new Promise(resolve => setTimeout(resolve, 10));+ check(features + ': independent realm', typeof popup.EventTarget === 'function' && popup.Function !== Function);+ const bars = names.map(name => popup[name]);+ check(features + ': own getters', bars.every(bar => bar.visible === expected));+ check(features + ': borrowed getters', bars.every(bar => readVisible.call(bar) === expected));+ const child = popup.document.createElement('iframe');+ popup.document.body.appendChild(child);+ check(features + ': child', names.every(name => child.contentWindow[name].visible === expected));+ popup.close();+ check(features + ': retired', bars.every(bar => readVisible.call(bar) === false));+ }+ return {total, failures};+ })()"#;+ let messages = send_cdp_command(+ &mut socket,+ 10,+ "Runtime.evaluate",+ Some(&session_id),+ json!({"expression":expression, "awaitPromise":true, "returnByValue":true}),+ )+ .await;+ let response = messages+ .iter()+ .find(|message| message["id"] == json!(10_u64))+ .expect("probe response");+ assert!(+ response["error"].is_null() && response["result"]["exceptionDetails"].is_null(),+ "probe must complete without exceptions: {response:#}"+ );+ assert_eq!(+ response["result"]["result"]["value"],+ json!({"total":15,"failures":[]})+ );+ let _ = socket.close(None).await;+ protocol_server.abort();+ fixture_server.abort();+}diff --git a/moli-renderer-v8/src/context_bootstrap.rs b/moli-renderer-v8/src/context_bootstrap.rsindex d2d7a922a..9b2886f99 100644--- a/moli-renderer-v8/src/context_bootstrap.rs+++ b/moli-renderer-v8/src/context_bootstrap.rs@@ -2,8 +2,10 @@ pub(crate) mod abort_signal;pub(crate) mod abort_signal_events;mod animation_runtime;mod assets;+mod bar_prop;pub(crate) mod bridge_descriptor;mod external;+pub(crate) use bar_prop::install_window_bar_props;pub(crate) use runtime_state::{install_lightweight_popup_legacy_objects, window_realm_secure_context_available,};diff --git a/moli-renderer-v8/src/context_bootstrap/assets/prototype_bindings.rs b/moli-renderer-v8/src/context_bootstrap/assets/prototype_bindings.rsindex 99ba84d8b..747afd416 100644--- a/moli-renderer-v8/src/context_bootstrap/assets/prototype_bindings.rs+++ b/moli-renderer-v8/src/context_bootstrap/assets/prototype_bindings.rs@@ -541,6 +541,11 @@ pub(super) fn install_constructor_template_bindings<'s>(install_crypto_template_bindings(scope, template, spec.interface.name());install_navigator_template_bindings(scope, template, spec.interface.name());install_screen_template_bindings(scope, template, spec.interface.name());+ crate::context_bootstrap::bar_prop::install_bar_prop_template_bindings(+ scope,+ template,+ spec.interface.name(),+ );crate::context_bootstrap::external::install_external_template_bindings(scope,template,diff --git a/moli-renderer-v8/src/context_bootstrap/bar_prop.rs b/moli-renderer-v8/src/context_bootstrap/bar_prop.rsnew file mode 100644index 000000000..0b31ddcd7--- /dev/null+++ b/moli-renderer-v8/src/context_bootstrap/bar_prop.rs@@ -0,0 +1,262 @@+use anyhow::{Result, anyhow};+use moli_webapi_declare::{WebApiFunctionTemplate, WebApiObject};++use super::shared::throw_error;+use crate::{+ native_bridge::OwnerDispatchScope,+ util::{context_host_ptr_from_global_bridge, get_private_value, set_private_value},+ web_api_interfaces,+};++const NAMES: &[&str] = &[+ "locationbar",+ "menubar",+ "personalbar",+ "scrollbars",+ "statusbar",+ "toolbar",+];+const WINDOW_CACHE_SLOT: &str = "__moliWindowBarProps";+const OWNER_SLOT: &str = "__moliBarPropOwner";+const POPUP_SLOT: &str = "__moliBarPropPopup";+const POPUP_WINDOW_SLOT: &str = "__moliBarPropPopupWindow";++#[derive(WebApiObject)]+#[webapi(interface = web_api_interfaces::BarProp)]+struct BarPropObjectDeclaration<'s> {+ #[webapi(prototype)]+ prototype: v8::Local<'s, v8::Object>,+ #[webapi(slot = OWNER_SLOT)]+ owner: v8::Local<'s, v8::Array>,+}++#[derive(WebApiFunctionTemplate)]+#[webapi(interface = web_api_interfaces::BarProp, enumerable, receiver)]+struct BarPropPrototypeDeclaration {+ #[webapi(accessor_property, getter = visible_getter)]+ visible: (),+}++#[derive(WebApiObject)]+#[webapi(plain)]+struct WindowBarPropsDeclaration<'s> {+ locationbar_data: v8::Local<'s, v8::Value>,+ menubar_data: v8::Local<'s, v8::Value>,+ personalbar_data: v8::Local<'s, v8::Value>,+ scrollbars_data: v8::Local<'s, v8::Value>,+ statusbar_data: v8::Local<'s, v8::Value>,+ toolbar_data: v8::Local<'s, v8::Value>,+ #[webapi(accessor_property, enumerable, getter = bar_getter, setter = bar_setter,+ data = self.locationbar_data, setter_data = self.locationbar_data)]+ locationbar: (),+ #[webapi(accessor_property, enumerable, getter = bar_getter, setter = bar_setter,+ data = self.menubar_data, setter_data = self.menubar_data)]+ menubar: (),+ #[webapi(accessor_property, enumerable, getter = bar_getter, setter = bar_setter,+ data = self.personalbar_data, setter_data = self.personalbar_data)]+ personalbar: (),+ #[webapi(accessor_property, enumerable, getter = bar_getter, setter = bar_setter,+ data = self.scrollbars_data, setter_data = self.scrollbars_data)]+ scrollbars: (),+ #[webapi(accessor_property, enumerable, getter = bar_getter, setter = bar_setter,+ data = self.statusbar_data, setter_data = self.statusbar_data)]+ statusbar: (),+ #[webapi(accessor_property, enumerable, getter = bar_getter, setter = bar_setter,+ data = self.toolbar_data, setter_data = self.toolbar_data)]+ toolbar: (),+}++pub(super) fn install_bar_prop_template_bindings<'s>(+ scope: &mut v8::PinScope<'s, '_, ()>,+ template: v8::Local<'s, v8::FunctionTemplate>,+ name: &str,+) {+ if name == "BarProp" {+ BarPropPrototypeDeclaration::initialize_prototype_template(+ scope,+ template.prototype_template(scope),+ );+ }+}++// Keep the cache in its original realm, including after V8 detaches the+// WindowProxy. Each accessor retains this anchor; BarProp remains lazy.+pub(crate) fn install_window_bar_props<'s>(+ scope: &mut v8::PinScope<'s, '_>,+ window: v8::Local<'s, v8::Object>,+ popup: Option<(+ u64,+ crate::window_document_identity::LightweightPopupLocalWindowId,+ )>,+) -> Result<()> {+ let empty = v8::undefined(scope).into();+ let cache = v8::Array::new_with_elements(scope, &[empty; 6]);+ if let Some((popup_id, local_window_id)) = popup {+ set_private_value(+ scope,+ cache.into(),+ POPUP_SLOT,+ v8::BigInt::new_from_u64(scope, popup_id).into(),+ );+ set_private_value(+ scope,+ cache.into(),+ POPUP_WINDOW_SLOT,+ v8::BigInt::new_from_u64(scope, local_window_id.as_u64()).into(),+ );+ let constructor = super::ensure_intrinsic_interface_constructor(scope, "BarProp")?;+ crate::util::define_non_enumerable_static_property(+ scope,+ window,+ "BarProp",+ constructor.into(),+ );+ }+ set_private_value(scope, window, WINDOW_CACHE_SLOT, cache.into());+ let locationbar_data =+ super::window_receiver::bound_callback_data(scope, 0, window, cache.into());+ let menubar_data = super::window_receiver::bound_callback_data(scope, 1, window, cache.into());+ let personalbar_data =+ super::window_receiver::bound_callback_data(scope, 2, window, cache.into());+ let scrollbars_data =+ super::window_receiver::bound_callback_data(scope, 3, window, cache.into());+ let statusbar_data =+ super::window_receiver::bound_callback_data(scope, 4, window, cache.into());+ let toolbar_data = super::window_receiver::bound_callback_data(scope, 5, window, cache.into());+ WindowBarPropsDeclaration {+ locationbar_data,+ locationbar: (),+ menubar_data,+ menubar: (),+ personalbar_data,+ personalbar: (),+ scrollbars_data,+ scrollbars: (),+ statusbar_data,+ statusbar: (),+ toolbar_data,+ toolbar: (),+ }+ .initialize(scope, window)?;+ Ok(())+}++fn bar_getter<'s>(+ scope: &mut v8::PinScope<'s, '_>,+ args: v8::FunctionCallbackArguments<'s>,+ mut rv: v8::ReturnValue<'s, v8::Value>,+) {+ let Some((name, detached_cache)) =+ super::window_receiver::bound_callback_data_item(scope, &args, NAMES, "Window BarProp")+ else {+ return;+ };+ let Some(cache) = get_private_value(scope, args.this(), WINDOW_CACHE_SLOT)+ .or(detached_cache)+ .and_then(|value| v8::Local::<v8::Array>::try_from(value).ok())+ else {+ return;+ };+ let index = NAMES+ .iter()+ .position(|candidate| *candidate == name)+ .unwrap() as u32;+ let result = (|| -> Result<v8::Local<'s, v8::Object>> {+ if let Some(value) = cache+ .get_index(scope, index)+ .and_then(|value| v8::Local::<v8::Object>::try_from(value).ok())+ {+ return Ok(value);+ }+ let context = cache+ .get_creation_context(scope)+ .ok_or_else(|| anyhow!("BarProp cache has no realm"))?;+ let scope = &mut v8::ContextScope::new(scope, context);+ let prototype = super::ensure_intrinsic_interface_prototype(scope, "BarProp")?;+ let object = BarPropObjectDeclaration::new(prototype, cache).bind(scope)?;+ cache.set_index(scope, index, object.into());+ Ok(object)+ })();+ match result {+ Ok(object) => rv.set(object.into()),+ Err(error) => throw_error(scope, &format!("Failed to create BarProp: {error}")),+ }+}++fn bar_setter<'s>(+ scope: &mut v8::PinScope<'s, '_>,+ args: v8::FunctionCallbackArguments<'s>,+ _rv: v8::ReturnValue<'s, v8::Value>,+) {+ let Some((name, _)) =+ super::window_receiver::bound_callback_data_item(scope, &args, NAMES, "Window BarProp")+ else {+ return;+ };+ super::runtime_state::define_replaceable_window_property(scope, args.this(), name, args.get(0));+}++fn private_id<'s>(+ scope: &mut v8::PinScope<'s, '_>,+ object: v8::Local<'s, v8::Object>,+ slot: &str,+) -> Option<u64> {+ get_private_value(scope, object, slot)+ .and_then(|value| v8::Local::<v8::BigInt>::try_from(value).ok())+ .map(|value| value.u64_value().0)+}++fn visible_getter<'s>(+ scope: &mut v8::PinScope<'s, '_>,+ args: v8::FunctionCallbackArguments<'s>,+ mut rv: v8::ReturnValue<'s, v8::Value>,+) {+ let visible = (|| {+ let owner = get_private_value(scope, args.this(), OWNER_SLOT)+ .and_then(|value| v8::Local::<v8::Object>::try_from(value).ok())?;+ let context = owner.get_creation_context(scope)?;+ let scope = &mut v8::ContextScope::new(scope, context);+ let host_ptr = context_host_ptr_from_global_bridge(scope)?;+ let host = unsafe { &*host_ptr };+ if let Some(popup_id) = private_id(scope, owner, POPUP_SLOT) {+ let local_window_id = private_id(scope, owner, POPUP_WINDOW_SLOT)?;+ return Some(+ host.current_lightweight_popup_local_window_id(popup_id)+ .is_some_and(|current| current.as_u64() == local_window_id)+ && host.lightweight_popup_bar_props_visible(popup_id),+ );+ }+ let identity = host.window_execution_context_identity_for_access_check(context)?;+ if !host.window_execution_context_identity_is_current(identity) {+ return Some(false);+ }+ let mut dispatch = identity.dispatch_scope();+ loop {+ match dispatch {+ OwnerDispatchScope::Top => {+ return Some(+ host.auxiliary_window()+ .is_none_or(|window| !window.is_closed() && !window.is_popup()),+ );+ }+ OwnerDispatchScope::LightweightPopup(id) => {+ return Some(host.lightweight_popup_bar_props_visible(id));+ }+ OwnerDispatchScope::Child(handle) => {+ if !host.child_browsing_context_is_live(handle) {+ return Some(false);+ }+ if let Some(id) = host.child_browsing_context_popup_owner_id(handle) {+ return Some(host.lightweight_popup_bar_props_visible(id));+ }+ dispatch = host+ .child_browsing_context_parent_handle(handle)+ .map(OwnerDispatchScope::Child)+ .unwrap_or(OwnerDispatchScope::Top);+ }+ }+ }+ })()+ .unwrap_or(false);+ rv.set_bool(visible);+}diff --git a/moli-renderer-v8/src/context_bootstrap/runtime_state.rs b/moli-renderer-v8/src/context_bootstrap/runtime_state.rsindex 2de484bd2..08559fa5a 100644--- a/moli-renderer-v8/src/context_bootstrap/runtime_state.rs+++ b/moli-renderer-v8/src/context_bootstrap/runtime_state.rs@@ -2164,6 +2164,7 @@ fn install_window_runtime_state<'s>(install_storage_runtime_state(scope, global)?;network_host::initialize_fetch_realm_helpers(scope)?;install_public_window_surface_accessors(scope, global)?;+ super::install_window_bar_props(scope, global, None)?;Ok(())}diff --git a/moli-renderer-v8/src/context_bootstrap/specs/registry.rs b/moli-renderer-v8/src/context_bootstrap/specs/registry.rsindex 7df7c5801..14dd1a488 100644--- a/moli-renderer-v8/src/context_bootstrap/specs/registry.rs+++ b/moli-renderer-v8/src/context_bootstrap/specs/registry.rs@@ -60,6 +60,10 @@ const CONSTRUCTOR_SPECS_BEFORE_STREAMS: &[ConstructorSpec] = &[interface: web_api_interfaces::External::DESCRIPTOR,kind: ConstructorKind::Illegal,},+ ConstructorSpec {+ interface: web_api_interfaces::BarProp::DESCRIPTOR,+ kind: ConstructorKind::Illegal,+ },ConstructorSpec {interface: web_api_interfaces::NodeList::DESCRIPTOR,kind: ConstructorKind::Illegal,diff --git a/moli-renderer-v8/src/context_bootstrap/window_runtime/dialogs.rs b/moli-renderer-v8/src/context_bootstrap/window_runtime/dialogs.rsindex 1ad059145..131bbefc0 100644--- a/moli-renderer-v8/src/context_bootstrap/window_runtime/dialogs.rs+++ b/moli-renderer-v8/src/context_bootstrap/window_runtime/dialogs.rs@@ -319,6 +319,11 @@ pub(crate) fn window_open_callback<'s>(true,) {Ok(opened) => {+ if opened.pending_page.is_some()+ && let Some(window) = opened.window.as_ref()+ {+ window.set_is_popup(parsed_features.is_popup());+ }let renderer_navigation = opened.queue_javascript_navigation(scope, &url);let disposition = if opened.pending_page.is_some()|| host.protocol_user_gesture_activation()@@ -391,6 +396,9 @@ pub(crate) fn window_open_callback<'s>(crate::RendererPopupDisposition::Background};let popup_id = opened_popup.popup_id;+ if opened_popup.created_new_browsing_context {+ host.set_lightweight_popup_is_popup(popup_id, parsed_features.is_popup());+ }let session_storage_store = host.lightweight_popup_session_storage_store(popup_id);let initial_empty_document_storage_key =host.lightweight_popup_initial_empty_document_storage_key(popup_id);diff --git a/moli-renderer-v8/src/native_bridge/context_host/popups.rs b/moli-renderer-v8/src/native_bridge/context_host/popups.rsindex f8a53e3fd..dcb29d407 100644--- a/moli-renderer-v8/src/native_bridge/context_host/popups.rs+++ b/moli-renderer-v8/src/native_bridge/context_host/popups.rs@@ -950,6 +950,12 @@ impl JsContextHost {navigation_id: LightweightPopupNavigationId::new(1),},);+ crate::context_bootstrap::install_window_bar_props(+ scope,+ window,+ Some((popup_id, initial_local_window_id)),+ )+ .ok()?;self.register_committed_document_resource_loader(crate::network::context::DocumentFetchContext::new(super::WindowDocumentOwner::LightweightPopup(initial_document_owner),@@ -1514,6 +1520,17 @@ impl JsContextHost {})}+ pub(crate) fn set_lightweight_popup_is_popup(&self, popup_id: u64, is_popup: bool) {+ if let Some(record) = self.lightweight_popup_record(popup_id) {+ record.auxiliary_window.set_is_popup(is_popup);+ }+ }++ pub(crate) fn lightweight_popup_bar_props_visible(&self, popup_id: u64) -> bool {+ self.lightweight_popup_record(popup_id)+ .is_some_and(|record| record.is_open() && !record.auxiliary_window.is_popup())+ }+pub(crate) fn lightweight_popup_is_open(&self, popup_id: u64) -> bool {self.lightweight_popup_record(popup_id).is_some_and(LightweightPopupBrowsingContextRecord::is_open)@@ -2025,6 +2042,13 @@ impl JsContextHost {}};if changed_document {+ if let Err(error) = crate::context_bootstrap::install_window_bar_props(+ scope,+ window,+ Some((popup_id, current_local_window_id)),+ ) {+ tracing::warn!(%error, "failed to initialize popup BarProp objects");+ }clear_lightweight_popup_window_document_event_state(scope, window);}if let Some(retired_document_handle) = transition.retired_document_handle {diff --git a/moli-renderer-v8/src/runtime/browser_context_runtime/auxiliary_window.rs b/moli-renderer-v8/src/runtime/browser_context_runtime/auxiliary_window.rsindex d1d5bc0c5..9e5aa199a 100644--- a/moli-renderer-v8/src/runtime/browser_context_runtime/auxiliary_window.rs+++ b/moli-renderer-v8/src/runtime/browser_context_runtime/auxiliary_window.rs@@ -12,6 +12,7 @@ pub struct RendererAuxiliaryWindow(Arc<AuxiliaryWindowState>);struct AuxiliaryWindowState {id: u64,closed: AtomicBool,+ is_popup: AtomicBool,frame_sandbox: crate::document_runtime::DocumentSandboxPolicy,}@@ -23,6 +24,7 @@ impl RendererAuxiliaryWindow {Self(Arc::new(AuxiliaryWindowState {id,closed: AtomicBool::new(false),+ is_popup: AtomicBool::new(false),frame_sandbox,}))}@@ -35,6 +37,16 @@ impl RendererAuxiliaryWindow {self.0.closed.load(Ordering::Acquire)}+ /// Popup UI state belongs to the browsing context, including after its+ /// initial Document is transferred from the opener to an independent Page.+ pub(crate) fn is_popup(&self) -> bool {+ self.0.is_popup.load(Ordering::Acquire)+ }++ pub(crate) fn set_is_popup(&self, is_popup: bool) {+ self.0.is_popup.store(is_popup, Ordering::Release);+ }+pub(crate) fn frame_sandbox(&self) -> crate::document_runtime::DocumentSandboxPolicy {self.0.frame_sandbox}diff --git a/moli-renderer-v8/src/script_vm/tests/browser_api/bar_prop.rs b/moli-renderer-v8/src/script_vm/tests/browser_api/bar_prop.rsnew file mode 100644index 000000000..8a1fd346b--- /dev/null+++ b/moli-renderer-v8/src/script_vm/tests/browser_api/bar_prop.rs@@ -0,0 +1,125 @@+use super::*;++#[test]+fn bar_prop_identity_brand_and_replaceable_surface() {+ let mut vm = new_storage_test_vm("https://barprop.test/");+ assert_eq!(+ vm.lazy_constructor_materialization_count_for_test("BarProp")+ .unwrap(),+ 0+ );+ let result = vm.eval(r#"+(() => {+ const names = ['locationbar', 'menubar', 'personalbar', 'scrollbars', 'statusbar', 'toolbar'];+ Array.prototype[0] = {visible: 'poisoned'};+ const bars = names.map(name => window[name]);+ delete Array.prototype[0];+ const result = [new Set(bars).size === 6,+ bars.every(bar => bar.visible && bar instanceof BarProp),+ bars.every(bar => Object.prototype.toString.call(bar) === '[object BarProp]')];+ const descriptor = Object.getOwnPropertyDescriptor(BarProp.prototype, 'visible');+ result.push(descriptor.enumerable && descriptor.configurable && descriptor.set === undefined,+ descriptor.get.name === 'get visible' && descriptor.get.length === 0);+ try { new BarProp(); result.push(false); } catch (e) { result.push(e instanceof TypeError); }+ const frame = document.createElement('iframe');+ (document.body || document.documentElement || document).appendChild(frame);+ const other = frame.contentWindow;+ const original = other.BarProp;+ other.BarProp = function Poisoned() { throw new Error('author constructor'); };+ const bar = other.locationbar;+ const getter = Object.getOwnPropertyDescriptor(original.prototype, 'visible').get;+ result.push(bar instanceof original, getter.call(locationbar) === true,+ descriptor.get.call(bar) === true,+ Object.getOwnPropertyDescriptor(window, 'locationbar').get.call(other) === bar);+ let traps = 0;+ const revoked = Proxy.revocable(bar, {}); revoked.revoke();+ for (const fake of [{}, Object.create(bar), new Proxy(bar, {get() {traps++;}}), revoked.proxy]) {+ try { getter.call(fake); result.push(false); }+ catch (e) { result.push(e instanceof other.TypeError && !(e instanceof TypeError)); }+ }+ result.push(traps === 0);+ const windowGetter = Object.getOwnPropertyDescriptor(other, 'menubar').get;+ try { windowGetter.call({}); result.push(false); }+ catch (e) { result.push(e instanceof other.TypeError); }+ for (const name of names) {+ const d = Object.getOwnPropertyDescriptor(window, name);+ const value = {toString() {throw new Error('unexpected conversion');}};+ d.set.call(window, value);+ const replaced = Object.getOwnPropertyDescriptor(window, name);+ result.push(replaced.value === value && replaced.writable && replaced.enumerable && replaced.configurable,+ d.get.call(window) === bars[names.indexOf(name)]);+ }+ frame.remove();+ result.push(getter.call(bar) === false);+ return result.every(Boolean) ? 'ok' : JSON.stringify(result);+})()+"#).unwrap();+ assert_eq!(result, "ok");+}++#[test]+fn bar_props_follow_child_window_lifetime() {+ let mut vm = new_storage_test_vm("https://barprop.test/child");+ let result = vm+ .eval(+ r#"+(() => {+ const names = ['locationbar', 'menubar', 'personalbar', 'scrollbars', 'statusbar', 'toolbar'];+ const frame = document.createElement('iframe');+ const parent = document.body || document.documentElement || document;+ parent.appendChild(frame);+ const window = frame.contentWindow;+ const bars = names.map(name => window[name]);+ bars[0].marker = 42;+ const prototype = Object.getPrototypeOf(bars[0]);+ window.document.open(); window.document.write('<p>stream'); window.document.close();+ const results = [names.every((name, index) => window[name] === bars[index]),+ bars[0].marker === 42, Object.getPrototypeOf(bars[0]) === prototype,+ bars.every(bar => bar.visible)];+ frame.remove();+ results.push(names.every((name, index) => window[name] === bars[index]),+ bars.every(bar => !bar.visible));+ parent.appendChild(frame);+ results.push(frame.contentWindow.locationbar !== bars[0],+ frame.contentWindow.locationbar.visible, bars.every(bar => !bar.visible));+ frame.remove();+ const untouched = document.createElement('iframe');+ parent.appendChild(untouched);+ const retired = untouched.contentWindow;+ untouched.remove();+ results.push(retired.locationbar.visible === false, retired.locationbar === retired.locationbar);+ return results.every(Boolean) ? 'ok' : JSON.stringify(results);+})()+"#,+ )+ .unwrap();+ assert_eq!(result, "ok");+}++#[test]+fn bar_props_follow_popup_features_and_close() {+ let mut vm = new_storage_page_task_executor_test_vm("https://barprop.test/popup");+ let result = vm.eval(r#"+(() => {+ const names = ['locationbar', 'menubar', 'personalbar', 'scrollbars', 'statusbar', 'toolbar'];+ const results = [];+ for (const [features, visible] of [['', true], ['popup', false], ['popup=0', true],+ ['width=300', false], ['location,menubar,scrollbars,status', true], ['popup=0,width=300', true]]) {+ const popup = window.open('about:blank', '', features);+ const bars = names.map(name => popup[name]);+ results.push(new Set(bars).size === 6, bars.every(bar => bar.visible === visible));+ const frame = popup.document.createElement('iframe'); popup.document.body.append(frame);+ const nested = frame.contentDocument.createElement('iframe'); frame.contentDocument.body.append(nested);+ results.push(names.every(name => frame.contentWindow[name].visible === visible),+ names.every(name => nested.contentWindow[name].visible === visible));+ popup.document.open(); popup.document.write('<p>stream'); popup.document.close();+ results.push(names.every((name, index) => popup[name] === bars[index]),+ bars.every(bar => bar.visible === visible));+ popup.close();+ results.push(popup.closed, bars.every(bar => bar.visible === false));+ }+ return results.every(Boolean) ? 'ok' : JSON.stringify(results);+})()+"#).unwrap();+ assert_eq!(result, "ok");+}diff --git a/moli-renderer-v8/src/script_vm/tests/browser_api/mod.rs b/moli-renderer-v8/src/script_vm/tests/browser_api/mod.rsindex 60f4a8a4e..92f3a3884 100644--- a/moli-renderer-v8/src/script_vm/tests/browser_api/mod.rs+++ b/moli-renderer-v8/src/script_vm/tests/browser_api/mod.rs@@ -2,6 +2,7 @@ use super::*;mod abort_signal_events;mod abort_signal_statics;+mod bar_prop;mod broadcast_channel;mod chrome;mod clipboard_storage;diff --git a/moli-renderer-v8/src/web_api_interfaces.rs b/moli-renderer-v8/src/web_api_interfaces.rsindex 79fc93865..d7bfbb6a6 100644--- a/moli-renderer-v8/src/web_api_interfaces.rs+++ b/moli-renderer-v8/src/web_api_interfaces.rs@@ -48,6 +48,7 @@ interfaces! {AudioWorklet: Worklet;AudioWorkletNode: AudioNode;BaseAudioContext: EventTarget;+ BarProp;BatteryManager;BeforeUnloadEvent: Event;BiquadFilterNode: AudioNode;