Skip to content

[CLI]: playwright-cli exits with status 0 when the tool result has isError: true #42028

Description

@rootTiket

What's going on?

Some playwright-cli commands report a semantic tool failure but still exit with status code 0.

For example, invoking an action with an invalid or stale element reference produces an error response:

playwright-cli open https://example.com
playwright-cli click e999999
echo $?

The command reports:

### Error
Error: Ref e999999 not found in the current page snapshot.

However, the reported exit status is:

0

The same behavior occurs in JSON mode:

playwright-cli --json click e999999
echo $?

The JSON response contains:

{
  "isError": true
}

but the process still exits with status code 0.

Impact

This makes shell-based automation interpret the command as successful unless it separately parses the text or JSON output.

For example, coding-agent shell tools and CI scripts commonly use the process exit status to determine whether an invocation succeeded. In this case, they may record the failed browser action as successful.

Expected behavior

I am not sure whether the current behavior is intentional.

Should a CLI command whose final tool response contains isError: true exit with a non-zero status in both text and JSON output modes?

If exit status 0 is intentional because the request to the daemon completed successfully, it would be helpful to document that contract so callers know that they must inspect isError.

Reproduction

  1. Install @playwright/cli.

  2. Open a page:

    playwright-cli open https://example.com
  3. Invoke an action using an invalid or stale element reference:

    playwright-cli click e999999
  4. Immediately inspect the exit status:

    echo $?
  5. Repeat using JSON output:

    playwright-cli --json click e999999
    echo $?

Versions tested

  • @playwright/cli: 0.1.17
  • OS: macOS 26.5.2
  • Node.js: v24.14.0

Additional context

A related but broader discussion about Playwright exit codes exists in #14109.

If non-zero exit status is considered the desired behavior, I would be interested in contributing a regression test and a fix.

Version

0.1.17

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions