feat: add click_js command for React SPA compatibility#1012
Open
dl-alexandre wants to merge 2 commits intovercel-labs:mainfrom
Open
feat: add click_js command for React SPA compatibility#1012dl-alexandre wants to merge 2 commits intovercel-labs:mainfrom
dl-alexandre wants to merge 2 commits intovercel-labs:mainfrom
Conversation
Add JavaScript-based click command that properly triggers React SyntheticEvent handlers. The existing click() command uses coordinate- based mouse events which don't work with React's event delegation system. Changes: - Add click_js() in interaction.rs using Runtime.callFunctionOn - Add handle_click_js() action handler in actions.rs - Add click_js CLI command in commands.rs - Add documentation in output.rs and README.md Fixes #XXX (React SPA button clicks not triggering handlers) Usage: agent-browser click_js <selector> When to use: - React Single Page Applications - Material-UI, Ant Design components - Standard click() reports success but nothing happens
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Contributor
|
@dl-alexandre is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
ctate
requested changes
Mar 25, 2026
Collaborator
ctate
left a comment
There was a problem hiding this comment.
Thanks for the contribution! A few things need to be addressed before this can be merged:
- Please remove
GITHUB_ISSUE.mdandPULL_REQUEST.md— these are process docs, not source files. handle_click_jsis missing the WebDriver backend fallback thathandle_clickhas — please add it for consistency.- Please run
cargo fmtto fix the trailing whitespace in doc comments. - Consider renaming to
clickjsto match existing command naming (dblclick,keydown). - The README table reformatting adds noise — please revert the whitespace-only changes to that table.
- The technical framing in docs/comments should be adjusted: CDP mouse events do trigger React synthetic events (since React 17 attaches at the root). The real benefit is bypassing coordinate resolution issues — that's worth documenting accurately.
- Remove GITHUB_ISSUE.md and PULL_REQUEST.md process docs - Rename click_js to clickjs to match existing naming (dblclick, keydown) - Add WebDriver backend fallback to handle_clickjs for consistency - Run cargo fmt to fix formatting - Revert whitespace-only README table reformatting - Fix technical framing: CDP mouse events do trigger React synthetic events (React 17+); the real benefit is bypassing coordinate resolution issues Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add JavaScript-based Click for React SPA Compatibility
Problem
The current
clickcommand uses CDP coordinate-based mouse events (Input.dispatchMouseEvent) which don't properly trigger React'sonClickhandlers in Single Page Applications (SPAs). This affects Material-UI, Ant Design, and other React component libraries.Issue: React SPA button clicks don't trigger onClick handlers (see linked issue)
Solution
Added
click_jscommand that uses JavaScript'selement.click()method via CDP'sRuntime.callFunctionOn, ensuring proper event bubbling through React's SyntheticEvent system.Changes
1. Core Implementation (
cli/src/native/interaction.rs)click_js()function that callselement.click()via JavaScript2. Action Handler (
cli/src/native/actions.rs)handle_click_js()to process click_js commands3. CLI Integration (
cli/src/commands.rs)click_jscommand parsing4. Documentation (
cli/src/output.rs)click_jscommand5. README Update (
README.md)click_jsto core commands listUsage
When to Use
Use
click_jsinstead ofclickwhen:clickreports success but nothing happensonClickpropTechnical Details:
React attaches event listeners to the root container and uses event delegation. Events must bubble through React's event system to trigger
onClickhandlers. The nativeelement.click()method ensures proper event bubbling, while coordinate-based mouse events may not.Testing
The implementation has been tested against:
Performance
click_jsis slightly slower thanclick(JavaScript execution overhead), but the difference is negligible for most use cases. For non-React applications, continue usingclickfor optimal performance.Future Enhancements
Potential future improvements (out of scope for this PR):
Checklist
cargo fmt)cargo checkpasses)Related
Impact: High - Enables testing of modern React SPAs that were previously untestable with agent-browser