Skip to content

feat(click): add --js-click flag for DOM-level element.click()#1072

Open
Hyeong-soo wants to merge 1 commit intovercel-labs:mainfrom
team-plask:feat/js-click
Open

feat(click): add --js-click flag for DOM-level element.click()#1072
Hyeong-soo wants to merge 1 commit intovercel-labs:mainfrom
team-plask:feat/js-click

Conversation

@Hyeong-soo
Copy link
Copy Markdown

@Hyeong-soo Hyeong-soo commented Mar 29, 2026

Problem

`click` uses CDP `Input.dispatchMouseEvent` which dispatches coordinate-based mouse events. This silently fails when:

  • `pointer-events: none` — coordinates pass through to underlying elements (e.g., vercel.com navigation links)
  • Viewport-obscured elements — `getBoundingClientRect()` returns incorrect coordinates for elements outside the visible area

The command reports success, but the intended element is not actually clicked. Related: #1011, #1044.

Note: SPA router click issues observed in v0.22.x appear to be resolved in v0.23.0. This PR addresses the remaining cases where coordinate-based clicking is fundamentally insufficient.

Root Cause

`Input.dispatchMouseEvent` operates at the browser input pipeline level (coordinates → hit-test → element). CSS properties like `pointer-events: none` cause the hit-test to resolve to a different element than intended, and viewport-obscured elements produce unreliable coordinates.

`element.click()` (DOM API) bypasses the coordinate system entirely and invokes the element's click handler directly, which is immune to CSS pointer restrictions and viewport position.

Changes

  • `cli/src/native/interaction.rs`: Added `pub async fn js_click()` — calls `element.scrollIntoView()` + `element.click()` via `Runtime.callFunctionOn`. Mirrors the existing `js_click_checkbox()` fallback (used by `check()`/`uncheck()`), generalized for any clickable element.
  • `cli/src/native/actions.rs`: `handle_click()` reads `jsClick` flag, dispatches to `js_click()` when set.
  • `cli/src/commands.rs`: Parses `--js-click` CLI flag into `{ "jsClick": true }` JSON field, following the `--new-tab` pattern.

Behavior

Site Issue `click @ref` `click @ref --js-click`
vercel.com `pointer-events: none` ❌ silent fail ✅ navigates
namu.wiki virtual rendering ❌ (element at wrong coords) ✅ navigates
example.com (none) ✅ works ✅ works

Testing

```bash
cargo test --manifest-path cli/Cargo.toml # 542 passed, 0 failed
cargo fmt --manifest-path cli/Cargo.toml -- --check

Manual verification (pointer-events: none):

agent-browser open https://vercel.com
agent-browser snapshot -i
agent-browser click @e91 # Docs link — URL unchanged
agent-browser click @e91 --js-click # URL → /docs ✅
```

CDP Input.dispatchMouseEvent (coordinate-based) silently fails on:
- SPA routers (React Router, Next.js, Vue Router)
- Elements with pointer-events: none
- Elements outside the viewport

The new --js-click flag uses Runtime.callFunctionOn to call
element.click() directly, bypassing the coordinate system.

This mirrors the existing js_click_checkbox() fallback used by
check()/uncheck() (interaction.rs L550), generalized for any
clickable element.

Fixes vercel-labs#1011
Addresses vercel-labs#1044
@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Mar 29, 2026

@Hyeong-soo is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant