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

# Browser Automation

> browser(action=...) — DOM-aware browser automation tool

# Browser Automation

`browser(action=...)` provides DOM-aware browser control via Chrome DevTools Protocol (CDP).

## Overview

The Browser tool is the middle-layer interaction tool — it understands web page DOM structure and can precisely operate elements via CSS selectors or Accessibility Tree refs. Suitable for all web interaction scenarios.

## Available Actions

| Action       | Description                 | Key Params                            |
| ------------ | --------------------------- | ------------------------------------- |
| `navigate`   | Go to URL                   | `url`, `new_tab`                      |
| `screenshot` | Page screenshot             | `url`/`html`/`file_path`, `full_page` |
| `snapshot`   | Get Accessibility Tree      | `selector`                            |
| `click`      | Click element               | `ref`, `button`                       |
| `type`       | Type keystroke-by-keystroke | `ref`, `text`, `clear`, `submit`      |
| `fill`       | Set value instantly         | `ref`, `text`                         |
| `scroll`     | Scroll                      | `direction`, `amount`, `ref`          |
| `press_key`  | Press key                   | `key`                                 |
| `tabs`       | Tab management              | `tab_action`, `tab_index`             |
| `set_html`   | Inject HTML via CDP         | `html`                                |
| `go_back`    | Navigate back               | —                                     |

## Screenshot: Three Modes

### 1. URL Mode (running page)

```python theme={null}
browser(action="screenshot", url="http://localhost:5173")
```

### 2. HTML Injection Mode (zero-server)

```python theme={null}
browser(action="screenshot", html="<html><body><h1>Hello</h1></body></html>")
```

Injects HTML via CDP `Page.setDocumentContent`. No server needed.

### 3. File Path Mode (local file)

```python theme={null}
browser(action="screenshot", file_path="/home/user/workspace/demo.html")
```

Auto-starts `bun serve` and captures the file.

## Accessibility Tree Workflow

```python theme={null}
# 1. Get page structure
browser(action="snapshot")
# → [0] button "Submit" [1] input "Email" [2] link "Home" ...

# 2. Operate by ref
browser(action="fill", ref="input[1]", text="user@example.com")
browser(action="click", ref="button[0]")
```

## Execution Backends

| Environment   | Backend                 | Notes              |
| ------------- | ----------------------- | ------------------ |
| Cloud Sandbox | CDP on sandbox Chromium | Direct CDP control |
| Desktop       | Electron in-app browser | WebSocket MCP      |

## Difference from `chrome`

| Aspect         | browser                    | chrome                    |
| -------------- | -------------------------- | ------------------------- |
| Environment    | Sandbox/controlled browser | User's real Chrome        |
| Auth state     | Clean (no logins)          | User's logged-in sessions |
| Confirmation   | Not required               | 4-level policy            |
| Tab management | AI creates freely          | Discover → Claim          |
| Risk           | None (isolated)            | Real-world actions        |
