Skip to content

armgit / moli

Public Imported from GitHub
0

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

fix(html): activate popovers from button inputs

ldm0140e2214453e
diff --git a/moli-renderer-v8/src/native_bridge/element/activation/default_action.rs b/moli-renderer-v8/src/native_bridge/element/activation/default_action.rs
index 6d47e6df1..cf3e0a54b 100644
--- a/moli-renderer-v8/src/native_bridge/element/activation/default_action.rs
+++ b/moli-renderer-v8/src/native_bridge/element/activation/default_action.rs
@@ -674,6 +674,14 @@ fn is_checkbox_input(runtime: &JsContextHost, handle: DomHandle) -> bool {
})
}
+fn is_button_input(runtime: &JsContextHost, handle: DomHandle) -> bool {
+ runtime
+ .dom_host()
+ .node(handle)
+ .and_then(Node::as_element)
+ .is_some_and(|element| element.is_html_input() && element.input_type() == InputType::Button)
+}
+
fn radio_group_members(runtime: &JsContextHost, handle: DomHandle) -> Vec<DomHandle> {
let Some(element) = runtime.dom_host().node(handle).and_then(Node::as_element) else {
return Vec::new();
@@ -1047,6 +1055,7 @@ fn element_has_click_activation_behavior(runtime: &JsContextHost, handle: DomHan
|| is_html_option_element(runtime, handle)
|| is_valid_submit_button(runtime, handle)
|| is_valid_reset_button(runtime, handle)
+ || is_button_input(runtime, handle)
|| runtime.dom_host().is_html_element_named(handle, "button")
|| runtime.dom_host().is_html_element_named(handle, "summary")
}
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 963963b24..5186b9a02 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
@@ -6214,6 +6214,61 @@ fn opening_auto_popovers_preserves_flat_tree_ancestors() {
);
}
+#[test]
+fn input_button_popover_invokers_run_across_form_ownership() {
+ let mut vm = new_storage_test_vm("https://input-button-popover.test/");
+
+ let result = vm
+ .eval(
+ r#"
+ (() => {
+ const html = document.appendChild(document.createElement("html"));
+ const body = html.appendChild(document.createElement("body"));
+ const form = document.createElement("form");
+ form.id = "owner";
+ const popover = document.createElement("div");
+ popover.id = "target";
+ popover.popover = "auto";
+ const makeInvoker = () => {
+ const input = document.createElement("input");
+ input.type = "button";
+ input.setAttribute("popovertarget", "target");
+ return input;
+ };
+ const ownedByAncestor = makeInvoker();
+ const ownedByAttribute = makeInvoker();
+ ownedByAttribute.setAttribute("form", "owner");
+ const outsideForm = makeInvoker();
+ const canceled = makeInvoker();
+ const disabled = makeInvoker();
+ disabled.disabled = true;
+ const text = makeInvoker();
+ text.type = "text";
+ canceled.addEventListener("click", event => event.preventDefault());
+ form.append(ownedByAncestor);
+ body.append(form, ownedByAttribute, outsideForm, canceled, disabled, text, popover);
+ const invoke = input => {
+ input.click();
+ const opened = popover.matches(":popover-open");
+ if (opened) popover.hidePopover();
+ return opened;
+ };
+ return [
+ invoke(ownedByAncestor),
+ invoke(ownedByAttribute),
+ invoke(outsideForm),
+ invoke(canceled),
+ invoke(disabled),
+ invoke(text)
+ ].join("|");
+ })()
+ "#,
+ )
+ .expect("input button popover invoker probe should evaluate");
+
+ assert_eq!(result, "true|true|true|false|false|false");
+}
+
#[test]
fn stale_popover_element_matches_false_after_document_open_replacement() {
let mut vm = new_storage_test_vm("https://popover-document-open.test/");