Skip to content

[V3]: fix partially occluded clicks - #3491

Merged
seanmcguire12 merged 5 commits into
v3from
v3-fix-occluded-clicks
Nov 18, 2026
Merged

seanmcguire12 merged 5 commits into
v3from
v3-fix-occluded-clicks

Conversation

@seanmcguire12

@seanmcguire12 seanmcguire12 commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

why

  • locator.click() clicks in the center of an element. if there is something covering the center of that element, then the click lands on the thing covering it

what changed

  • added a shared getClickPoint helper, which scrolls the element into view & decides which point to click
  • added a page side helper findClickablePoint (called by getClickPoint), which does hit testing. ie, it:
    • checks whether the element's center is actually reachable, or covered by something like a fixed footer or sticky header
    • if covered, it scrolls the element to the center, end & start of the viewport & checks the center again at each position
    • falls back to off-center points if the center is never reachable
    • counts hits on a child of the element, inside its shadow root, or on its <label> as reaching the element
    • scrolls instantly, so pages with smooth scrolling are measured after the scroll finishes
  • getClickPoint maps the chosen point onto the element's box model, so iframe offsets & transforms are handled as before
  • if every point is covered, it clicks the center like before & logs whatever is in the way

test plan

  • added locator-click-hit-target.spec.ts, which:
    • clicks & hovers a button partly under a fixed footer, & clicks a button partly under a sticky header. these fail without the fix
    • checks that a fully covered element still gets a center click instead of throwing
    • guards cases where the element on top is legitimately not the target: buttons in open & closed shadow roots, & two custom checkbox patterns where the native input is hidden under its label
    • clicks buttons inside same-origin & cross-origin iframes, & on a page with smooth scrolling
  • added find-clickable-point.spec.ts, which runs the page-side script directly & checks:
    • no scrolling when nothing covers the element
    • scrolling a button out from under a fixed footer, including with smooth scrolling
    • falling back to an off-center point when scrolling can't help
    • reporting what covers a fully covered element
    • shadow roots & labels count as reaching the element

Summary by cubic

Fixes clicks landing on elements overlapping the target. click(), hover(), and tap() now hit-test the chosen point and scroll the element (under fixed footers, sticky headers, banners) to find a reachable one before dispatching input. centroid() intentionally stays at the box center even when covered.

  • Adds getClickPoint, shared by click, hover, and tap (not centroid), which scrolls into view and runs a new findClickablePoint in-page script.
  • The script tries the element's center at several scroll positions, then falls back to off-center points; it treats hits on descendants, shadow root content, and associated <label>s as reaching the element.
  • If no point is reachable, it clicks the center as before and logs what is covering the element.
  • Adds integration tests for fixed footers, sticky headers, shadow roots, hidden checkboxes, same- and cross-origin iframes, smooth scrolling, fully covered elements, and centroid staying at a covered center.

Written for commit 202a1b4. Summary will update on new commits.

View guided diff Turn on auto-fix

@changeset-bot

changeset-bot Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 202a1b4

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 5 files

Architecture diagram
sequenceDiagram
    participant Client as Client Code
    participant Locator as Locator
    participant Session as CDP Session
    participant Page as Page (DOM)
    participant Browser as Browser Engine

    Note over Client,Browser: Click/Hover/Tap/Centroid Operation

    Client->>Locator: click() / hover() / tap() / centroid()
    Locator->>Locator: resolveNode()
    Locator->>Session: DOM.scrollIntoViewIfNeeded
    
    alt bestEffortScroll (hover, centroid)
        Session->>Browser: Scroll element into view
    else standard (click, tap)
        Session->>Browser: Scroll element into view
    end

    Locator->>Session: Runtime.callFunctionOn (findClickablePoint)
    Session->>Page: Execute findClickablePoint script

    Note over Page: Hit-testing algorithm
    Page->>Page: Check element center at current scroll position
    alt Center reachable
        Page-->>Locator: {status: "ok", fx: 0.5, fy: 0.5}
    else Center covered
        Page->>Page: Scroll to center/end/start of viewport
        Page->>Page: Re-check center after each scroll
        alt Center reachable after scroll
            Page-->>Locator: {status: "ok", fx: 0.5, fy: 0.5}
        else Still covered
            Page->>Page: Try off-center points
            alt Off-center point reachable
                Page-->>Locator: {status: "ok", fx: 0.25, fy: 0.5}
            else All points covered
                Page->>Page: Scroll to center, identify covering element
                Page-->>Locator: {status: "covered", coveredBy: "div#footer"}
            end
        end
    end

    alt Hit-test successful
        Locator->>Session: DOM.getBoxModel
        Session->>Browser: Get element box model
        Browser-->>Locator: Box model coordinates
        Locator->>Locator: Map point onto border box
        Locator->>Session: Input.dispatchMouseEvent (click/tap/hover)
        Session->>Browser: Dispatch input event
        Browser-->>Client: Click/hover completed
    else Element covered (fallback)
        Locator->>Locator: Log warning about covering element
        Locator->>Session: DOM.getBoxModel
        Session->>Browser: Get element box model
        Browser-->>Locator: Box model coordinates
        Locator->>Locator: Use center of content box
        Locator->>Session: Input.dispatchMouseEvent (click at center)
        Session->>Browser: Dispatch input event
        Browser-->>Client: Event dispatched to covering element
    end
Loading

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

View guided diff | Turn on auto-fix | Re-trigger cubic

@seanmcguire12
seanmcguire12 merged commit 57b905e into v3 Nov 18, 2026
255 checks passed
@seanmcguire12
seanmcguire12 deleted the v3-fix-occluded-clicks branch November 18, 2026 22:49
@github-actions github-actions Bot mentioned this pull request Nov 18, 2026
seanmcguire12 pushed a commit that referenced this pull request Nov 18, 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/[email protected]

### Patch Changes

- [#3150](#3150)
[`69c2440`](69c2440)
Thanks [@miguelg719](https://github.com/miguelg719)! - Fix OpenAI
strict-schema rejection of the nullable `act` action while still
stripping unknown keys when parsing.

- [#3114](#3114)
[`f6b3d85`](f6b3d85)
Thanks [@miguelg719](https://github.com/miguelg719)! - Fix CAPTCHA
awareness options for local Browserbase attachments and forward them
through the API.

- [#3491](#3491)
[`57b905e`](57b905e)
Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - Fix clicks
on partially occluded elements

- [#3132](#3132)
[`09063f6`](09063f6)
Thanks [@shubh24](https://github.com/shubh24)! - Use automatic tool
choice for the final agent `done` call with Claude Sonnet 5.5, Opus 5.5,
and Fable 5.1.

- [#3287](#3287)
[`27ee07c`](27ee07c)
Thanks [@akeimach](https://github.com/akeimach)! - Fix XPath resolution
for light DOM elements when the page has a shadow root and a host
element overrides `children`.

## @browserbasehq/[email protected]

### Patch Changes

- Updated dependencies
\[[`69c2440`](69c2440),
[`f6b3d85`](f6b3d85),
[`57b905e`](57b905e),
[`09063f6`](09063f6),
[`27ee07c`](27ee07c)]:
    -   @browserbasehq/[email protected]

## @browserbasehq/[email protected]

### Patch Changes

- [#3312](#3312)
[`e11bbe5`](e11bbe5)
Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - Rebuild the
standalone server binaries with Node.js 24.22.1 and Undici 7.30.1 to
include the October 2026 security fixes. Binary builds now reject
outdated Node versions and rebuild instead of reusing cached
executables.

- Updated dependencies
\[[`69c2440`](69c2440),
[`f6b3d85`](f6b3d85),
[`57b905e`](57b905e),
[`09063f6`](09063f6),
[`27ee07c`](27ee07c)]:
    -   @browserbasehq/[email protected]

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