···11+---
22+name: browser-cli
33+description: Control Firefox browser from the command line. Use for web automation, scraping, testing, or any browser interaction tasks.
44+---
55+66+# Usage
77+88+```bash
99+# List managed tabs
1010+browser-cli --list
1111+1212+# Open a page and get snapshot
1313+browser-cli <<'EOF'
1414+await tab("https://example.com")
1515+snap()
1616+EOF
1717+1818+# Execute in a specific tab
1919+browser-cli abc123 <<'EOF'
2020+snap()
2121+EOF
2222+```
2323+2424+# JavaScript API
2525+2626+All functions are available in the execution context. Actions return simple
2727+confirmations; use `snap()` to get page state.
2828+2929+## Element Interaction (use refs from snap())
3030+3131+```bash
3232+browser-cli <<'EOF'
3333+await click(1) // Click element [1]
3434+await click(1, {double: true}) // Double click
3535+await type(2, "user@example.com") // Type into element [2]
3636+await type(2, "new", {clear: true}) // Clear first, then type
3737+await hover(3) // Hover over element [3]
3838+await drag(4, 5) // Drag from [4] to [5]
3939+await select(6, "option-value") // Select dropdown option
4040+key("Enter") // Press key
4141+key("Tab")
4242+EOF
4343+4444+# Can still use CSS selectors when needed
4545+browser-cli <<'EOF'
4646+await click("#submit-button")
4747+await click("Sign In", "text")
4848+EOF
4949+```
5050+5151+## Page Inspection
5252+5353+```bash
5454+browser-cli <<'EOF'
5555+snap() // Get page snapshot with refs
5656+snap({forms: true}) // Only form elements
5757+snap({links: true}) // Only links
5858+snap({buttons: true}) // Only buttons
5959+snap({text: "login"}) // Elements containing "login"
6060+diff() // Show changes since last snap
6161+logs() // Get console logs
6262+EOF
6363+```
6464+6565+## Waiting
6666+6767+```bash
6868+browser-cli <<'EOF'
6969+await wait(1000) // Wait 1 second
7070+await wait("idle") // Wait for DOM to stabilize
7171+await wait("text", "Success") // Wait for text to appear
7272+await wait("gone", "Loading") // Wait for text to disappear
7373+EOF
7474+```
7575+7676+## Downloads
7777+7878+```bash
7979+browser-cli TABID <<'EOF'
8080+const url = document.querySelector('a[href*="pdf"]').href
8181+await download(url, "invoice.pdf") // Downloads to ~/Downloads/invoice.pdf
8282+EOF
8383+```
8484+8585+## Screenshots & Tabs
8686+8787+```bash
8888+browser-cli <<'EOF'
8989+await shot() // Screenshot, returns data URL
9090+await shot("/tmp/page.png") // Screenshot to file
9191+await tab() // New tab
9292+await tab("https://example.com") // New tab with URL
9393+await tabs() // List all tabs
9494+EOF
9595+```
9696+9797+# Snapshot Output Format
9898+9999+```
100100+Page: Example Site
101101+URL: https://example.com
102102+103103+[1] heading "Welcome"
104104+[2] input[email] "Email" [required]
105105+[3] input[password] "Password" [required]
106106+[4] checkbox "Remember me"
107107+[5] button "Sign In"
108108+[6] link "Forgot password?"
109109+```
110110+111111+- `[N]` - Reference number for use with click(), type(), etc.
112112+- Role and accessible name shown
113113+- Attributes in brackets: `[disabled]`, `[checked]`, `[required]`, etc.
114114+115115+# Examples
116116+117117+```bash
118118+# Search on Google
119119+browser-cli <<'EOF'
120120+await tab("https://google.com")
121121+snap()
122122+EOF
123123+# Output shows [12] combobox "Suche"
124124+125125+browser-cli <<'EOF'
126126+await type(12, "hello world")
127127+diff()
128128+EOF
129129+# Shows: Added (autocomplete options), Changed (input value)
130130+131131+# Form filling
132132+browser-cli <<'EOF'
133133+await tab("https://example.com/login")
134134+snap()
135135+EOF
136136+# Output: [1] input "Email", [2] input "Password", [3] button "Sign In"
137137+138138+browser-cli <<'EOF'
139139+await type(1, "user@test.com")
140140+await type(2, "secret123")
141141+await click(3)
142142+diff()
143143+EOF
144144+145145+# Wait for dynamic content
146146+browser-cli <<'EOF'
147147+await click(5)
148148+await wait("text", "Success")
149149+snap()
150150+EOF
151151+```
152152+153153+See [README.md](README.md) for installation, architecture, and full API reference.
···11+"""Browser CLI - Control Firefox from the command line.
22+33+Provides a minimal CLI that executes JavaScript via stdin, with a rich
44+JS API for browser automation.
55+"""
66+77+from browser_cli.bridge import NativeMessagingBridge
88+from browser_cli.cli import main
99+from browser_cli.client import BrowserClient
1010+1111+__all__ = ["BrowserClient", "NativeMessagingBridge", "main"]
···11+"""Custom exceptions for browser-cli."""
22+33+44+class BrowserCLIError(Exception):
55+ """Base exception for browser-cli errors."""
66+77+88+class BrowserConnectionError(BrowserCLIError):
99+ """Raised when unable to connect to the browser extension or server."""
1010+1111+1212+class CommandError(BrowserCLIError):
1313+ """Raised when a command fails to execute."""