Skip to content

fix(cli): surface no-match failures in browse click/fill#2309

Open
yawbtng wants to merge 1 commit into
browserbase:mainfrom
yawbtng:fix-cli-click-fill-nomatch
Open

fix(cli): surface no-match failures in browse click/fill#2309
yawbtng wants to merge 1 commit into
browserbase:mainfrom
yawbtng:fix-cli-click-fill-nomatch

Conversation

@yawbtng

@yawbtng yawbtng commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

why

browse click and browse fill report success on a selector that matches nothing. Reproduced on browse@0.9.1 against a real page:

$ browse click "#this-element-does-not-exist-xyz"
{ "clicked": true }
$ echo $?
0

$ browse fill "#this-element-does-not-exist-xyz" "hello"
{ "filled": true, "pressedEnter": false }
$ echo $?
0

Every other element command errors correctly on the same no-match selector:

$ browse is visible "#missing"   →  exit 1  "Could not find an element for the given xPath(s): #missing"
$ browse get text "#missing"     →  exit 1  "Could not find an element ..."
$ browse select "#missing" ...   →  exit 1  (throws via deepLocator)
$ browse upload "#missing" ...    →  exit 1  (throws via deepLocator)

click/fill are the only outliers. They run through stagehand.act(), which reports a missing element via success:false rather than throwing (actHandler.ts), and the handlers discard that result — so a script or agent driving the CLI proceeds on a false premise.

what changed

packages/cli/src/lib/driver/commands/elements.tsclick and fill now check the act() result and throw new Error(result.message) when success is false, so they exit non-zero and print the same "Could not find an element" error as their siblings. A failed fill no longer presses Enter afterward.

test plan

Adds tests/element-command-failures.test.ts (5 cases, mock manager per the existing driver-commands.test.ts pattern): click/fill throw on success:false, resolve on success, and a failed fill never presses Enter. Adjacent suites (driver-commands, driver-foundation) still green; tsc -p tsconfig.json clean.

The pre-fix behavior above was reproduced live; the fix is covered by the unit tests (a full end-to-end run needs a driver session).


Summary by cubic

Fixes the browse CLI so browse click and browse fill fail with a clear error and non-zero exit when the selector matches no element, aligning with other element commands.

  • Bug Fixes
    • Throw the act() error message when success:false instead of reporting success.
    • fill no longer presses Enter after a failed action.

Written for commit aee59f5. Summary will update on new commits.

Review in cubic

browse click and browse fill returned { clicked: true } / { filled: true }
and exited 0 even when the selector matched no element, because they run
through act() — which reports a missing element via success:false rather
than throwing. The sibling commands select/upload already error via
deepLocator, so click/fill were inconsistent outliers that silently
reported success on a no-op.

Check the act() result and throw its message when success is false, so a
no-match click/fill exits non-zero like the rest of the element commands.
Adds unit coverage for both the failure (throws) and success paths, and
that a failed fill never presses Enter.
@changeset-bot

changeset-bot Bot commented Jul 2, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: aee59f5

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

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

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

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

This PR is from an external contributor and must be approved by a stagehand team member with write access before CI can run.
Approving the latest commit mirrors it into an internal PR owned by the approver.
If new commits are pushed later, the internal PR stays open but is marked stale until someone approves the latest external commit and refreshes it.

@github-actions github-actions Bot added external-contributor Tracks PRs mirrored from external contributor forks. external-contributor:awaiting-approval Waiting for a stagehand team member to approve the latest external commit. labels Jul 2, 2026

@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.

No issues found across 3 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.
Architecture diagram
sequenceDiagram
    participant Client as CLI User
    participant Handler as Elements Handler (elements.ts)
    participant Manager as Driver Manager
    participant Stagehand as Stagehand (act)
    participant Page as Active Page

    Client->>Handler: click(selector) or fill(selector, value, pressEnter?)
    Handler->>Manager: stagehandInstance()
    Manager-->>Handler: stagehand
    Handler->>Stagehand: act({action: "click"|"fill", selector, ...})
    Stagehand-->>Handler: { success: false, message: "Could not find..." }
    alt success == false (NEW)
        Handler->>Handler: throw new Error(result.message)
        Handler-->>Client: Non-zero exit + error message
    else success == true
        opt fill with pressEnter
            Handler->>Page: keyPress("Enter")
        end
        Handler-->>Client: { clicked: true } / { filled: true, pressedEnter }
    end
Loading

Re-trigger cubic

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

Labels

external-contributor:awaiting-approval Waiting for a stagehand team member to approve the latest external commit. external-contributor Tracks PRs mirrored from external contributor forks.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant