> ## Documentation Index
> Fetch the complete documentation index at: https://piyushvyas.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# CLI Overview

> CLI-first browser automation for AI coding agents. Like playwright-cli but with composite actions, semantic selectors, and structured extraction.

# BAP CLI

CLI-first browser automation from the command line. BAP defaults to installed Chrome, an auto-detected profile when available, and a persistent daemon so agents can work against a real browser instead of starting fresh every time.

## Install

<CodeGroup>
  ```bash npm theme={null}
  npm i -g @browseragentprotocol/cli
  ```

  ```bash npx (no install) theme={null}
  npx @browseragentprotocol/cli goto https://example.com
  ```

  ```bash pnpm theme={null}
  pnpm add -g @browseragentprotocol/cli
  ```
</CodeGroup>

<Note>
  Requires Node.js 20+ and Playwright browsers. Install browsers with `npx playwright install
      chromium`.
</Note>

## 30-Second Demo

<Steps>
  <Step title="Navigate to a page">
    ```bash theme={null}
    bap goto https://example.com --observe
    ```

    The `--observe` flag fuses navigation and observation into a single server call, returning interactive elements with stable refs.
  </Step>

  <Step title="Click an element">
    `bash bap click role:button:"Get Started" ` Semantic selectors target elements by purpose, not
    DOM position. They survive redesigns.
  </Step>

  <Step title="Fill a form with composite actions">
    ````bash bap act fill:label:"Email"="user@example.com" \ fill:label:"Password"="secret" \ theme={null}
    click:role:button:"Sign in" ``` Three steps, one command, one server call. Fewer tokens, fewer
    roundtrips.
    </Step>

    <Step title="Extract structured data">
      ```bash
      bap extract --fields="title,price,rating"
    ````

    Returns validated JSON output.
  </Step>
</Steps>

## Architecture

```
bap <command>
    | WebSocket (JSON-RPC 2.0)
BAP Playwright Server (auto-started as background daemon)
    | Playwright
Browser (Chromium / Firefox / WebKit)
```

The server starts automatically on first use and persists across commands. No manual setup needed.

<Tip>Use `bap close-all` to stop the daemon and shut down all browser sessions.</Tip>

## Why BAP CLI?

<CardGroup cols={3}>
  <Card title="Composite Actions" icon="layer-group">
    Execute multi-step flows in one command instead of one-at-a-time. A login flow is 1 `bap act`,
    not 3 separate fill/click calls.
  </Card>

  <Card title="Semantic Selectors" icon="crosshairs">
    Target elements by ARIA role, visible text, label, or placeholder. Selectors survive DOM changes
    and redesigns.
  </Card>

  <Card title="Structured Extraction" icon="database">
    Extract validated JSON from pages using field names, JSON Schema, or list mode. No HTML parsing
    needed.
  </Card>
</CardGroup>

### Composite Actions vs playwright-cli

```bash theme={null}
# playwright-cli: 3 commands, 3 snapshots, 3 LLM reasoning cycles
playwright-cli fill e5 "user@example.com"
playwright-cli fill e8 "password123"
playwright-cli click e12

# bap: 1 command, 1 snapshot, 1 LLM reasoning cycle
bap act fill:e5="user@example.com" fill:e8="password123" click:e12
```

## Migrating from playwright-cli

BAP is a drop-in replacement. All `e<N>` refs from snapshots work identically:

| playwright-cli                  | bap                  |
| ------------------------------- | -------------------- |
| `playwright-cli open [url]`     | `bap open [url]`     |
| `playwright-cli click e15`      | `bap click e15`      |
| `playwright-cli fill e5 "text"` | `bap fill e5 "text"` |
| `playwright-cli snapshot`       | `bap snapshot`       |
| `playwright-cli screenshot`     | `bap screenshot`     |

BAP adds composite actions, semantic selectors, smart observation, and structured extraction on top.

## Output

Commands produce concise, AI-agent-friendly output. Files are saved to `.bap/` in the current directory:

* Snapshots: `.bap/snapshot-<timestamp>.yml`
* Screenshots: `.bap/screenshot-<timestamp>.png`
* Extractions: `.bap/extraction-<timestamp>.json`

## Command Overview

| Category            | Commands                                                                       |
| ------------------- | ------------------------------------------------------------------------------ |
| **Essentials**      | `goto`, `observe`, `act`, `extract`, `screenshot`                              |
| **Actions**         | `click`, `fill`, `type`, `press`, `select`, `check/uncheck`, `hover`, `scroll` |
| **Navigation**      | `open`, `back`, `forward`, `reload`, `close`, `close-all`                      |
| **Observation**     | `observe`, `snapshot`                                                          |
| **Sessions & Tabs** | `sessions`, `tabs`, `tab-new`, `tab-select`, `frames`, `frame-switch`          |
| **Workflows**       | `workflow record/stop/run/list`, `run`                                         |
| **Debugging**       | `watch`, `trace`, `demo`, `plan`                                               |
| **Configuration**   | `config`, `install-skill`, `skill`                                             |
