Skip to content

Conversation

@miguelg719
Copy link
Collaborator

@miguelg719 miguelg719 commented Dec 9, 2025

why

Click count in CDP's Input.dispatchMouseEvent does not issue multiple click events, is mainly kept for tracking. Individual mousePressed/mouseReleased events must be sent

what changed

Added a for loop for the clickCount number provided in both locator.click() and page.click(). Also built redundancy around AnthropicCUAClient double_click coordinate parsing.

test plan


Summary by cubic

Fixes multiple-click behavior by dispatching individual mousePressed/mouseReleased events per click and normalizes Anthropic CUA doubleClick coordinates. Double-clicks and multi-clicks now work reliably via CDP and CUA.

  • Bug Fixes
    • locator.click and page.click now loop over clickCount, sending pressed/released pairs for each click.
    • AnthropicCUAClient parses doubleClick consistently and falls back to coordinate arrays when x/y are missing.
    • Added tests for single, double, and triple clicks for locator.click and page.click.

Written for commit 26b784d. Summary will update automatically on new commits.

@changeset-bot
Copy link

changeset-bot bot commented Dec 9, 2025

🦋 Changeset detected

Latest commit: e6d079c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@browserbasehq/stagehand Patch
@browserbasehq/stagehand-evals Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@miguelg719 miguelg719 marked this pull request as ready for review December 9, 2025 00:03
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 9, 2025

Greptile Overview

Greptile Summary

Fixes multiple-click behavior by correctly dispatching individual mousePressed/mouseReleased event pairs for each click. The CDP clickCount parameter tracks click state rather than issuing multiple clicks, so the fix loops from 1 to clickCount, sending sequential press/release pairs with incrementing counts. Also normalizes Anthropic CUA doubleClick coordinate parsing to handle both x/y properties and coordinate array format.

  • Fixed locator.click() to loop and dispatch individual mouse events for each click
  • Fixed page.click() to loop and dispatch individual mouse events for each click
  • Added fallback coordinate parsing in AnthropicCUAClient for doubleClick actions
  • Tested on doubleclicktest.com to verify multi-click behavior

Confidence Score: 5/5

  • This PR is safe to merge with no identified issues
  • The implementation correctly addresses the CDP click dispatch bug with a straightforward loop solution that matches CDP protocol semantics. Previous logic issues flagged in review were fixed. The Anthropic CUA coordinate fallback follows existing patterns in the codebase. Changes are well-tested and focused.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
packages/core/lib/v3/understudy/locator.ts 5/5 Correctly loops to dispatch individual mouse press/release pairs for each click, incrementing clickCount from 1 to target count
packages/core/lib/v3/understudy/page.ts 5/5 Correctly loops to dispatch individual mouse press/release pairs for each click, incrementing clickCount from 1 to target count
packages/core/lib/v3/agent/AnthropicCUAClient.ts 5/5 Normalizes doubleClick action to handle both x/y properties and coordinate array format with fallback to 0

Sequence Diagram

sequenceDiagram
    participant Client as Client Code
    participant Locator as Locator/Page
    participant CDP as Chrome DevTools Protocol
    participant Browser as Browser Engine
    
    Client->>Locator: click(clickCount=2)
    Locator->>CDP: dispatchMouseEvent(type="mouseMoved")
    CDP->>Browser: Move cursor to position
    
    loop For each click (i=1 to clickCount)
        Locator->>CDP: dispatchMouseEvent(type="mousePressed", clickCount=i)
        CDP->>Browser: Press mouse button (click count: i)
        Locator->>CDP: dispatchMouseEvent(type="mouseReleased", clickCount=i)
        CDP->>Browser: Release mouse button (click count: i)
    end
    
    Browser->>Browser: Trigger click/dblclick events
    Locator-->>Client: Click complete
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

x,
y,
button,
clickCount,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: should be i not clickCount - the loop increments i to send individual events

Suggested change
clickCount,
clickCount: i,
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/core/lib/v3/understudy/page.ts
Line: 1360:1360

Comment:
**logic:** should be `i` not `clickCount` - the loop increments `i` to send individual events

```suggestion
        clickCount: i,
```

How can I resolve this? If you propose a fix, please make it concise.

x,
y,
button,
clickCount,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: should be i not clickCount - matches the pattern in locator.ts:417,425

Suggested change
clickCount,
clickCount: i,
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/core/lib/v3/understudy/page.ts
Line: 1368:1368

Comment:
**logic:** should be `i` not `clickCount` - matches the pattern in locator.ts:417,425

```suggestion
        clickCount: i,
```

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 4 files

Prompt for AI agents (all 1 issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="packages/core/lib/v3/understudy/page.ts">

<violation number="1" location="packages/core/lib/v3/understudy/page.ts:1360">
P2: The `clickCount` parameter in each iteration should be `i` (the iteration index), not the total `clickCount`. For proper double-click/triple-click simulation, browsers expect clickCount to increment with each successive click in the sequence (1 for first click, 2 for second click, etc.). This is how `event.detail` is set and how JavaScript double-click detection works.</violation>
</file>

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR

x,
y,
button,
clickCount,
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The clickCount parameter in each iteration should be i (the iteration index), not the total clickCount. For proper double-click/triple-click simulation, browsers expect clickCount to increment with each successive click in the sequence (1 for first click, 2 for second click, etc.). This is how event.detail is set and how JavaScript double-click detection works.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/core/lib/v3/understudy/page.ts, line 1360:

<comment>The `clickCount` parameter in each iteration should be `i` (the iteration index), not the total `clickCount`. For proper double-click/triple-click simulation, browsers expect clickCount to increment with each successive click in the sequence (1 for first click, 2 for second click, etc.). This is how `event.detail` is set and how JavaScript double-click detection works.</comment>

<file context>
@@ -1350,22 +1350,24 @@ export class Page {
+        x,
+        y,
+        button,
+        clickCount,
+      } as Protocol.Input.DispatchMouseEventRequest);
 
</file context>
Fix with Cubic

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too slow, Greptile beat you mate

@miguelg719
Copy link
Collaborator Author

@greptileai

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@miguelg719 miguelg719 merged commit 605ed6b into main Dec 10, 2025
40 of 42 checks passed
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.

3 participants