Skip to content

fix(v3): normalize CUA coordinates to actual viewport - #2767

Merged
miguelg719 merged 2 commits into
v3from
fix/v3-mobile-cua-viewport
Aug 18, 2026
Merged

miguelg719 merged 2 commits into
v3from
fix/v3-mobile-cua-viewport

Conversation

@miguelg719

@miguelg719 miguelg719 commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

why

Verified Browserbase mobile sessions can expose a CSS viewport such as 384x696 even when the requested viewport differs. Google CUA was instead normalizing model coordinates against a hard-coded 1288x711 viewport, which converted valid taps into off-screen mouse coordinates and prevented touch-only controls from working.

what changed

  • Add a shared V3 viewport resolver: use an explicitly configured viewport without probing, otherwise probe the active page, then fall back to the default.
  • Use the shared resolver in both direct CUA and hybrid Google coordinate normalization, removing both Verified-mode 1288x711 special cases.
  • Resolve the viewport once per fillFormVision execution and reuse it across all fields.
  • Deduplicate configured viewport lookup behind rawConfiguredViewport.
  • Cover configured, probed, default, direct CUA, and hybrid coordinate paths without constructing the Google SDK client.

test plan

  • pnpm --filter @browserbasehq/stagehand build:esm
  • pnpm --filter @browserbasehq/stagehand exec vitest run dist/esm/tests/unit/touch-cua-routing.test.js dist/esm/tests/unit/coordinate-normalization.test.js dist/esm/tests/unit/touch-tool-routing.test.js
  • pnpm --filter @browserbasehq/stagehand typecheck
  • pnpm exec eslint on all changed production and test files
  • Full unit suite: 909 passed; the four FlowLogger failures reproduce unchanged on origin/v3
  • Verified through the Browserbase path with disableAPI=true: https://www.browserbase.com/sessions/164a55eb-1cf6-4267-86b2-90e821a7c119

@changeset-bot

changeset-bot Bot commented Aug 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 80ea5e2

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

This PR includes changesets to release 3 packages
Name Type
@browserbasehq/stagehand Patch
@browserbasehq/stagehand-evals Patch
@browserbasehq/stagehand-server-v3 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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 2 files

Architecture diagram
sequenceDiagram
    participant V3 as V3CuaAgentHandler
    participant Page as Active Page (Browser)
    participant Google as GoogleCUAClient
    participant Test as Regression Test

    Note over V3,Google: CUA Coordinate Normalization Flow

    alt Normalization for all CUA clients (NEW unified path)
        V3->>Page: awaitActivePage()
        Page-->>V3: page reference
        V3->>Page: page.mainFrame().evaluate() for window.innerWidth/innerHeight
        Page-->>V3: { w: 384, h: 696 } (actual CSS viewport)
        alt Valid dimensions returned
            V3->>Google: setViewport(384, 696)
            Google-->>V3: viewport updated
        else w or h is 0/undefined
            V3->>V3: skip update (empty catch block)
        end
    end

    Note over V3,Test: Key behavior: coordinates now match actual rendered viewport instead of hard-coded 1288x711 (old Verified mode)

    alt Regression test: Google CUA with mobile viewport mismatch
        Test->>V3: create handler with isVerified=true, configuredViewport=430x932
        Test->>Test: spy on GoogleCUAClient.setViewport()
        V3->>Page: awaitActivePage()
        Page-->>V3: page with 384x696 CSS viewport
        V3->>Google: setViewport(384, 696)
        Google-->>V3: viewport set
        Test->>Test: expect(setViewport).toHaveBeenCalledWith(384, 696)
        Note over Test: Verifies actual mobile viewport (384x696) overrides<br/>configured (430x932) and old 1288x711 fallback
    end
Loading

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/core/tests/unit/touch-cua-routing.test.ts
@miguelg719
miguelg719 force-pushed the fix/v3-mobile-cua-viewport branch 3 times, most recently from 41b0675 to 5f78422 Compare August 17, 2026 22:04
@miguelg719
miguelg719 force-pushed the fix/v3-mobile-cua-viewport branch from 5f78422 to 70359ca Compare August 17, 2026 22:19
@miguelg719
miguelg719 merged commit 98fa7a4 into v3 Aug 18, 2026
478 of 483 checks passed
@github-actions github-actions Bot mentioned this pull request Aug 18, 2026
miguelg719 pushed a commit that referenced this pull request Aug 20, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to v3, this PR will
be updated.


# Releases
## @browserbasehq/stagehand@3.7.2

### Patch Changes

- [#2775](#2775)
[`b954a46`](b954a46)
Thanks [@miguelg719](https://github.com/miguelg719)! - Fix Anthropic
structured output options for provider-prefixed models

- [#2767](#2767)
[`98fa7a4`](98fa7a4)
Thanks [@miguelg719](https://github.com/miguelg719)! - Fix: Normalize
CUA coordinates to actual viewport

- [#2385](#2385)
[`7566804`](7566804)
Thanks [@miguelg719](https://github.com/miguelg719)! - Add `useTouch`
option to actuate agent clicks as trusted touch

## @browserbasehq/stagehand-evals@2.1.1

### Patch Changes

- Updated dependencies
\[[`b954a46`](b954a46),
[`98fa7a4`](98fa7a4),
[`7566804`](7566804)]:
    -   @browserbasehq/stagehand@3.7.2

## @browserbasehq/stagehand-server-v3@3.7.4

### Patch Changes

- Updated dependencies
\[[`b954a46`](b954a46),
[`98fa7a4`](98fa7a4),
[`7566804`](7566804)]:
    -   @browserbasehq/stagehand@3.7.2

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

2 participants