feat(cli): coordinate click + command aliases + clearer find error (issue #8.4)
Field-report ergonomics fixes so agents stop wasting a round on a wrong guess: - Coordinate click is now first-class: `click <x> <y>`, `click <x>,<y>`, and `click --coords <x>,<y>` dispatch a raw viewport-point click (no element resolution), reusing the humanize trajectory + press dwell. Was previously only reachable via eval(elementFromPoint(...).click()). - Aliases: `tabs` (plural) → the `tab` subcommand tree; `get-text`/`get_text` → `get text <selector>`. - `find <value> <action>` with a bare value (no locator keyword), e.g. `find "I'm not a robot" click`, now errors with the corrected command (`find text "I'm not a robot" click`) plus concrete examples, instead of a bare "Valid options: role, text, ..." list. Adds parse-layer regression tests for every form.
This commit is contained in:
@@ -2986,6 +2986,20 @@ async fn handle_screenshot(cmd: &Value, state: &mut DaemonState) -> Result<Value
|
||||
}
|
||||
|
||||
async fn handle_click(cmd: &Value, state: &mut DaemonState) -> Result<Value, String> {
|
||||
// First-class coordinate click (issue #8.4): click a raw viewport point with
|
||||
// no element resolution. Parsed from `click <x> <y>` / `click --coords x,y`.
|
||||
if let (Some(x), Some(y)) = (
|
||||
cmd.get("x").and_then(|v| v.as_f64()),
|
||||
cmd.get("y").and_then(|v| v.as_f64()),
|
||||
) {
|
||||
let mgr = state.browser.as_ref().ok_or("Browser not launched")?;
|
||||
let session_id = mgr.active_session_id()?.to_string();
|
||||
let button = cmd.get("button").and_then(|v| v.as_str()).unwrap_or("left");
|
||||
let click_count = cmd.get("clickCount").and_then(|v| v.as_i64()).unwrap_or(1) as i32;
|
||||
interaction::click_at_point(&mgr.client, &session_id, x, y, button, click_count).await?;
|
||||
return Ok(json!({ "clicked": { "x": x, "y": y } }));
|
||||
}
|
||||
|
||||
let selector = cmd
|
||||
.get("selector")
|
||||
.and_then(|v| v.as_str())
|
||||
|
||||
@@ -1143,6 +1143,20 @@ async fn wait_for_paint_settled(client: &CdpClient, session_id: &str) {
|
||||
.await;
|
||||
}
|
||||
|
||||
/// Click at a raw viewport coordinate, bypassing element/selector resolution
|
||||
/// (issue #8.4 first-class coordinate click). Honors the humanize trajectory and
|
||||
/// press dwell exactly like a selector click — it shares `dispatch_click`.
|
||||
pub async fn click_at_point(
|
||||
client: &CdpClient,
|
||||
session_id: &str,
|
||||
x: f64,
|
||||
y: f64,
|
||||
button: &str,
|
||||
click_count: i32,
|
||||
) -> Result<(), String> {
|
||||
dispatch_click(client, session_id, x, y, button, click_count).await
|
||||
}
|
||||
|
||||
async fn dispatch_click(
|
||||
client: &CdpClient,
|
||||
session_id: &str,
|
||||
|
||||
Reference in New Issue
Block a user