INNER CODE UNIT · Rust

element_center

keon/browser-control · src/actions.rs:49

pub async fn element_center(c: &mut Cdp, target: &str) -> Result<(i64, i64)> {
    let v = c
        .eval(&format!(
            "({ACTION_JS}).point({})",
            serde_json::to_string(target)?
        ))
        .await?;
    let x = v["x"].as_i64().context("element x")?;
    let y = v["y"].as_i64().context("element y")?;
    Ok((x, y))
}

pub async fn drag(c: &mut Cdp, x1: i64, y1: i64, x2: i64, y2: i64) -> Result<()> {
    c.call(
        "Input.dispatchMouseEvent",
        json!({"type":"mousePressed","x":x1,"y":y1,"button":"left","clickCount":1}),
        true,
    )

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…