Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,22 @@ pub fn parse_command(args: &[String], flags: &Flags) -> Result<Value, ParseError
// === Core Actions ===
"click" => {
let new_tab = rest.contains(&"--new-tab");
let js_click = rest.contains(&"--js-click");
let sel = rest
.iter()
.find(|arg| **arg != "--new-tab")
.find(|arg| **arg != "--new-tab" && **arg != "--js-click")
.ok_or_else(|| ParseError::MissingArguments {
context: "click".to_string(),
usage: "click <selector> [--new-tab]",
usage: "click <selector> [--new-tab] [--js-click]",
})?;
let mut cmd = json!({ "id": id, "action": "click", "selector": sel });
if new_tab {
Ok(json!({ "id": id, "action": "click", "selector": sel, "newTab": true }))
} else {
Ok(json!({ "id": id, "action": "click", "selector": sel }))
cmd["newTab"] = json!(true);
}
if js_click {
cmd["jsClick"] = json!(true);
}
Ok(cmd)
}
"dblclick" => {
let sel = rest.first().ok_or_else(|| ParseError::MissingArguments {
Expand Down
13 changes: 13 additions & 0 deletions cli/src/native/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2186,6 +2186,19 @@ async fn handle_click(cmd: &Value, state: &mut DaemonState) -> Result<Value, Str
let session_id = mgr.active_session_id()?.to_string();

let new_tab = cmd.get("newTab").and_then(|v| v.as_bool()).unwrap_or(false);
let js_click = cmd.get("jsClick").and_then(|v| v.as_bool()).unwrap_or(false);

if js_click {
interaction::js_click(
&mgr.client,
&session_id,
&state.ref_map,
selector,
&state.iframe_sessions,
)
.await?;
return Ok(json!({ "clicked": selector, "method": "js" }));
}

if new_tab {
use super::element::resolve_element_object_id;
Expand Down
44 changes: 44 additions & 0 deletions cli/src/native/interaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,50 @@ pub async fn uncheck(
Ok(())
}

/// DOM-level click via `element.click()`. Bypasses CDP coordinate-based
/// input, working around pointer-events:none, viewport issues, and SPA
/// routers that don't respond to Input.dispatchMouseEvent.
///
/// This mirrors the fallback path used by `check()`/`uncheck()` via
/// `js_click_checkbox()`, generalized for any clickable element.
pub async fn js_click(
client: &CdpClient,
session_id: &str,
ref_map: &RefMap,
selector_or_ref: &str,
iframe_sessions: &HashMap<String, String>,
) -> Result<(), String> {
let (object_id, effective_session_id) = resolve_element_object_id(
client,
session_id,
ref_map,
selector_or_ref,
iframe_sessions,
)
.await?;

let js = r#"function() {
this.scrollIntoView({ block: 'center', behavior: 'instant' });
this.click();
}"#;

client
.send_command_typed::<_, Value>(
"Runtime.callFunctionOn",
&CallFunctionOnParams {
function_declaration: js.to_string(),
object_id: Some(object_id),
arguments: None,
return_by_value: Some(true),
await_promise: Some(false),
},
Some(&effective_session_id),
)
.await?;

Ok(())
}

/// Fallback for when the coordinate-based CDP click did not toggle the
/// checkbox/radio state. This mirrors how Playwright dispatches clicks
/// through the DOM rather than via raw Input.dispatchMouseEvent coordinates.
Expand Down