This repository has no description
3.5 kB
153 lines
1---
2name: browser-cli
3description: Control Firefox browser from the command line. Use for web automation, scraping, testing, or any browser interaction tasks.
4---
5
6# Usage
7
8```bash
9# List managed tabs
10browser-cli --list
11
12# Open a page and get snapshot
13browser-cli <<'EOF'
14await tab("https://example.com")
15snap()
16EOF
17
18# Execute in a specific tab
19browser-cli abc123 <<'EOF'
20snap()
21EOF
22```
23
24# JavaScript API
25
26All functions are available in the execution context. Actions return simple
27confirmations; use `snap()` to get page state.
28
29## Element Interaction (use refs from snap())
30
31```bash
32browser-cli <<'EOF'
33await click(1) // Click element [1]
34await click(1, {double: true}) // Double click
35await type(2, "user@example.com") // Type into element [2]
36await type(2, "new", {clear: true}) // Clear first, then type
37await hover(3) // Hover over element [3]
38await drag(4, 5) // Drag from [4] to [5]
39await select(6, "option-value") // Select dropdown option
40key("Enter") // Press key
41key("Tab")
42EOF
43
44# Can still use CSS selectors when needed
45browser-cli <<'EOF'
46await click("#submit-button")
47await click("Sign In", "text")
48EOF
49```
50
51## Page Inspection
52
53```bash
54browser-cli <<'EOF'
55snap() // Get page snapshot with refs
56snap({forms: true}) // Only form elements
57snap({links: true}) // Only links
58snap({buttons: true}) // Only buttons
59snap({text: "login"}) // Elements containing "login"
60diff() // Show changes since last snap
61logs() // Get console logs
62EOF
63```
64
65## Waiting
66
67```bash
68browser-cli <<'EOF'
69await wait(1000) // Wait 1 second
70await wait("idle") // Wait for DOM to stabilize
71await wait("text", "Success") // Wait for text to appear
72await wait("gone", "Loading") // Wait for text to disappear
73EOF
74```
75
76## Downloads
77
78```bash
79browser-cli TABID <<'EOF'
80const url = document.querySelector('a[href*="pdf"]').href
81await download(url, "invoice.pdf") // Downloads to ~/Downloads/invoice.pdf
82EOF
83```
84
85## Screenshots & Tabs
86
87```bash
88browser-cli <<'EOF'
89await shot() // Screenshot, returns data URL
90await shot("/tmp/page.png") // Screenshot to file
91await tab() // New tab
92await tab("https://example.com") // New tab with URL
93await tabs() // List all tabs
94EOF
95```
96
97# Snapshot Output Format
98
99```
100Page: Example Site
101URL: https://example.com
102
103[1] heading "Welcome"
104[2] input[email] "Email" [required]
105[3] input[password] "Password" [required]
106[4] checkbox "Remember me"
107[5] button "Sign In"
108[6] link "Forgot password?"
109```
110
111- `[N]` - Reference number for use with click(), type(), etc.
112- Role and accessible name shown
113- Attributes in brackets: `[disabled]`, `[checked]`, `[required]`, etc.
114
115# Examples
116
117```bash
118# Search on Google
119browser-cli <<'EOF'
120await tab("https://google.com")
121snap()
122EOF
123# Output shows [12] combobox "Suche"
124
125browser-cli <<'EOF'
126await type(12, "hello world")
127diff()
128EOF
129# Shows: Added (autocomplete options), Changed (input value)
130
131# Form filling
132browser-cli <<'EOF'
133await tab("https://example.com/login")
134snap()
135EOF
136# Output: [1] input "Email", [2] input "Password", [3] button "Sign In"
137
138browser-cli <<'EOF'
139await type(1, "user@test.com")
140await type(2, "secret123")
141await click(3)
142diff()
143EOF
144
145# Wait for dynamic content
146browser-cli <<'EOF'
147await click(5)
148await wait("text", "Success")
149snap()
150EOF
151```
152
153See [README.md](README.md) for installation, architecture, and full API reference.