ai-agent-browser 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Agent Browser Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,360 @@
1
+ Metadata-Version: 2.4
2
+ Name: ai-agent-browser
3
+ Version: 0.1.0
4
+ Summary: A robust browser automation tool for AI agents - control browsers via CLI or IPC
5
+ Author: Agent Browser Contributors
6
+ License-Expression: GPL-3.0-only
7
+ Project-URL: Homepage, https://github.com/abhinav-nigam/agent-browser
8
+ Project-URL: Documentation, https://github.com/abhinav-nigam/agent-browser#readme
9
+ Project-URL: Repository, https://github.com/abhinav-nigam/agent-browser
10
+ Project-URL: Issues, https://github.com/abhinav-nigam/agent-browser/issues
11
+ Keywords: browser,automation,playwright,testing,ai,agent
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Topic :: Software Development :: Testing
22
+ Classifier: Topic :: Internet :: WWW/HTTP :: Browsers
23
+ Requires-Python: >=3.9
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: playwright>=1.40.0
27
+ Requires-Dist: pillow>=10.0.0
28
+ Provides-Extra: dev
29
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
30
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
31
+ Dynamic: license-file
32
+
33
+ # agent-browser
34
+
35
+ A robust browser automation tool designed for AI agents to control browsers via CLI commands.
36
+
37
+ [![PyPI version](https://badge.fury.io/py/agent-browser.svg)](https://badge.fury.io/py/agent-browser)
38
+ [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
39
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
40
+
41
+ ## Why This Exists
42
+
43
+ AI agents (like Claude Code, Codex, GPT-based tools) need to interact with web applications for testing and automation. However, most browser automation tools require:
44
+ - Programmatic API access within a running process
45
+ - Complex async/await patterns
46
+ - Persistent connections
47
+
48
+ **agent-browser** solves this by providing:
49
+ - **Simple CLI commands** - Any process that can run shell commands can control a browser
50
+ - **File-based IPC** - Stateless CLI commands control a stateful browser session
51
+ - **Multi-session support** - Run multiple browser sessions concurrently
52
+ - **Built for AI** - Screenshots auto-resize for vision models, assertions return clear PASS/FAIL
53
+
54
+ ## Installation
55
+
56
+ ```bash
57
+ pip install agent-browser
58
+ playwright install chromium
59
+ ```
60
+
61
+ ## Quick Start
62
+
63
+ ```bash
64
+ # Terminal 1: Start browser (blocks while running)
65
+ agent-browser start http://localhost:8080
66
+
67
+ # Terminal 2: Send commands
68
+ agent-browser cmd screenshot home
69
+ agent-browser cmd click "button[type='submit']"
70
+ agent-browser cmd fill "#email" "test@example.com"
71
+ agent-browser cmd assert_visible ".success-message"
72
+
73
+ # When done
74
+ agent-browser stop
75
+ ```
76
+
77
+ ## Architecture
78
+
79
+ ```
80
+ ┌─────────────────┐ ┌──────────────┐ ┌─────────────────┐
81
+ │ AI Agent │ │ IPC Files │ │ Browser │
82
+ │ (Claude Code, │────▶│ (temp dir) │────▶│ (Playwright) │
83
+ │ Codex, etc) │ │ │ │ │
84
+ │ │◀────│ cmd.json │◀────│ Chromium │
85
+ │ CLI commands │ │ result.json │ │ │
86
+ └─────────────────┘ └──────────────┘ └─────────────────┘
87
+ ```
88
+
89
+ The browser runs in one process, listening for commands via JSON files. CLI commands write to `cmd.json`, the browser processes them and writes results to `result.json`. This decoupled architecture allows any process to control the browser.
90
+
91
+ ## Command Reference
92
+
93
+ ### Browser Control
94
+
95
+ | Command | Description | Example |
96
+ |---------|-------------|---------|
97
+ | `start <url>` | Start browser session (blocks) | `agent-browser start http://localhost:8080` |
98
+ | `start <url> --visible` | Start in headed mode | `agent-browser start http://localhost:8080 --visible` |
99
+ | `stop` | Close browser | `agent-browser stop` |
100
+ | `status` | Check if browser is running | `agent-browser status` |
101
+ | `cmd reload` | Reload current page | `agent-browser cmd reload` |
102
+ | `cmd goto <url>` | Navigate to URL | `agent-browser cmd goto http://example.com` |
103
+ | `cmd back` | Navigate back | `agent-browser cmd back` |
104
+ | `cmd forward` | Navigate forward | `agent-browser cmd forward` |
105
+ | `cmd url` | Print current URL | `agent-browser cmd url` |
106
+ | `cmd viewport <w> <h>` | Set viewport size | `agent-browser cmd viewport 1920 1080` |
107
+
108
+ ### Screenshots
109
+
110
+ | Command | Description | Example |
111
+ |---------|-------------|---------|
112
+ | `cmd screenshot [name]` | Full-page screenshot | `agent-browser cmd screenshot checkout_page` |
113
+ | `cmd screenshot viewport [name]` | Viewport only (faster) | `agent-browser cmd screenshot viewport header` |
114
+ | `cmd ss [name]` | Alias for screenshot | `agent-browser cmd ss step1` |
115
+
116
+ Screenshots are automatically resized to max 1500x1500 for AI vision model compatibility.
117
+
118
+ ### Interactions
119
+
120
+ | Command | Description | Example |
121
+ |---------|-------------|---------|
122
+ | `cmd click <selector>` | Click element | `agent-browser cmd click "#submit-btn"` |
123
+ | `cmd click_nth <selector> <n>` | Click nth element (0-indexed) | `agent-browser cmd click_nth ".item" 2` |
124
+ | `cmd fill <selector> <text>` | Fill input field | `agent-browser cmd fill "#email" "test@example.com"` |
125
+ | `cmd type <selector> <text>` | Type with key events | `agent-browser cmd type "#search" "query"` |
126
+ | `cmd select <selector> <value>` | Select dropdown option | `agent-browser cmd select "#country" "US"` |
127
+ | `cmd press <key>` | Press keyboard key | `agent-browser cmd press Enter` |
128
+ | `cmd scroll <direction>` | Scroll page | `agent-browser cmd scroll down` |
129
+ | `cmd hover <selector>` | Hover over element | `agent-browser cmd hover ".tooltip-trigger"` |
130
+ | `cmd focus <selector>` | Focus element | `agent-browser cmd focus "#input"` |
131
+ | `cmd upload <selector> <path>` | Upload file | `agent-browser cmd upload "#file" ./doc.pdf` |
132
+ | `cmd dialog <action> [text]` | Handle dialog | `agent-browser cmd dialog accept` |
133
+ | `cmd clear` | Clear localStorage/sessionStorage | `agent-browser cmd clear` |
134
+
135
+ **Scroll directions:** `up`, `down`, `top`, `bottom`, `left`, `right`
136
+
137
+ **Dialog actions:** `accept`, `dismiss`, `accept <prompt_text>`
138
+
139
+ ### Assertions
140
+
141
+ All assertions return `[PASS]` or `[FAIL]` prefix for easy parsing.
142
+
143
+ | Command | Description | Example |
144
+ |---------|-------------|---------|
145
+ | `cmd assert_visible <selector>` | Element is visible | `agent-browser cmd assert_visible ".modal"` |
146
+ | `cmd assert_hidden <selector>` | Element is hidden | `agent-browser cmd assert_hidden ".loading"` |
147
+ | `cmd assert_text <selector> <text>` | Element contains text | `agent-browser cmd assert_text ".msg" "Success"` |
148
+ | `cmd assert_text_exact <sel> <text>` | Text matches exactly | `agent-browser cmd assert_text_exact ".count" "42"` |
149
+ | `cmd assert_value <selector> <value>` | Input has value | `agent-browser cmd assert_value "#email" "test@example.com"` |
150
+ | `cmd assert_checked <selector>` | Checkbox is checked | `agent-browser cmd assert_checked "#agree"` |
151
+ | `cmd assert_url <pattern>` | URL contains pattern | `agent-browser cmd assert_url "/dashboard"` |
152
+
153
+ ### Data Extraction
154
+
155
+ | Command | Description | Example |
156
+ |---------|-------------|---------|
157
+ | `cmd text <selector>` | Get text content | `agent-browser cmd text ".title"` |
158
+ | `cmd value <selector>` | Get input value | `agent-browser cmd value "#email"` |
159
+ | `cmd attr <selector> <attr>` | Get attribute | `agent-browser cmd attr "a" "href"` |
160
+ | `cmd count <selector>` | Count matching elements | `agent-browser cmd count ".item"` |
161
+ | `cmd eval <javascript>` | Execute JavaScript | `agent-browser cmd eval "document.title"` |
162
+ | `cmd cookies` | Get all cookies (JSON) | `agent-browser cmd cookies` |
163
+ | `cmd storage` | Get localStorage (JSON) | `agent-browser cmd storage` |
164
+
165
+ ### Debugging
166
+
167
+ | Command | Description | Example |
168
+ |---------|-------------|---------|
169
+ | `cmd console` | View JS console logs | `agent-browser cmd console` |
170
+ | `cmd network` | View network requests | `agent-browser cmd network` |
171
+ | `cmd network_failed` | View failed requests | `agent-browser cmd network_failed` |
172
+ | `cmd clear_logs` | Clear console/network logs | `agent-browser cmd clear_logs` |
173
+ | `cmd wait <ms>` | Wait milliseconds | `agent-browser cmd wait 2000` |
174
+ | `cmd wait_for <selector> [ms]` | Wait for element | `agent-browser cmd wait_for ".loaded" 15000` |
175
+ | `cmd wait_for_text <text>` | Wait for text | `agent-browser cmd wait_for_text "Complete"` |
176
+ | `cmd help` | Show help | `agent-browser cmd help` |
177
+
178
+ ## Session Management
179
+
180
+ Run multiple browser sessions concurrently using session IDs:
181
+
182
+ ```bash
183
+ # Start two sessions
184
+ agent-browser start http://localhost:8080 --session app1
185
+ agent-browser start http://localhost:9090 --session app2
186
+
187
+ # Send commands to specific sessions
188
+ agent-browser cmd screenshot home --session app1
189
+ agent-browser cmd click "#login" --session app2
190
+
191
+ # Check status
192
+ agent-browser status --session app1
193
+
194
+ # Stop specific session
195
+ agent-browser stop --session app1
196
+ ```
197
+
198
+ ## Configuration
199
+
200
+ ### Screenshot Output Directory
201
+
202
+ ```bash
203
+ agent-browser start http://localhost:8080 --output-dir ./my-screenshots
204
+ ```
205
+
206
+ ### Timeouts
207
+
208
+ Default timeouts:
209
+ - **Command timeout:** 5 seconds (click, fill, etc.)
210
+ - **wait_for timeout:** 10 seconds (can override: `wait_for .element 15000`)
211
+ - **IPC timeout:** 10 seconds (waiting for browser response)
212
+
213
+ ## Selectors
214
+
215
+ Use standard Playwright/CSS selectors:
216
+
217
+ ```bash
218
+ # CSS selectors
219
+ agent-browser cmd click ".btn-primary"
220
+ agent-browser cmd click "#submit"
221
+ agent-browser cmd click "button[type='submit']"
222
+ agent-browser cmd click "[data-testid='login-btn']"
223
+
224
+ # Text selectors
225
+ agent-browser cmd click "text='Sign In'"
226
+ agent-browser cmd click "text=Submit"
227
+
228
+ # Chained selectors
229
+ agent-browser cmd click ".card >> text='Edit'"
230
+ ```
231
+
232
+ ## Interactive Mode
233
+
234
+ For manual testing with AI assistance:
235
+
236
+ ```bash
237
+ agent-browser interact http://localhost:8080
238
+ ```
239
+
240
+ This starts a REPL where you can type commands directly:
241
+
242
+ ```
243
+ > ss initial
244
+ Screenshot saved: ./screenshots/interactive/step_01_initial.png
245
+ > click #login
246
+ Clicked: #login
247
+ > ss after_login
248
+ Screenshot saved: ./screenshots/interactive/step_02_after_login.png
249
+ > quit
250
+ ```
251
+
252
+ ## Integration with AI Agents
253
+
254
+ ### Claude Code Example
255
+
256
+ ```bash
257
+ # In Claude Code conversation:
258
+ # "Test the login flow on localhost:8080"
259
+
260
+ # Claude runs:
261
+ agent-browser start http://localhost:8080 --session test1 &
262
+ sleep 2
263
+ agent-browser cmd screenshot login_page --session test1
264
+ # Claude analyzes screenshot...
265
+ agent-browser cmd fill "#username" "testuser" --session test1
266
+ agent-browser cmd fill "#password" "testpass" --session test1
267
+ agent-browser cmd click "button[type='submit']" --session test1
268
+ agent-browser cmd wait_for ".dashboard" --session test1
269
+ agent-browser cmd assert_url "/dashboard" --session test1
270
+ agent-browser cmd screenshot success --session test1
271
+ agent-browser stop --session test1
272
+ ```
273
+
274
+ ### Generic LLM Integration
275
+
276
+ ```python
277
+ import subprocess
278
+
279
+ def browser_cmd(cmd: str, session: str = "default") -> str:
280
+ result = subprocess.run(
281
+ ["agent-browser", "cmd", *cmd.split(), "--session", session],
282
+ capture_output=True, text=True
283
+ )
284
+ return result.stdout.strip()
285
+
286
+ # Start browser (in separate process)
287
+ subprocess.Popen(["agent-browser", "start", "http://localhost:8080", "--session", "test"])
288
+
289
+ # Send commands
290
+ browser_cmd("screenshot initial", "test")
291
+ browser_cmd("click #login", "test")
292
+ browser_cmd("assert_visible .dashboard", "test")
293
+ ```
294
+
295
+ ## File Locations
296
+
297
+ | File | Location | Purpose |
298
+ |------|----------|---------|
299
+ | State | `%TEMP%/agent_browser_{session}_state.json` | Browser running state |
300
+ | Commands | `%TEMP%/agent_browser_{session}_cmd.json` | Pending command |
301
+ | Results | `%TEMP%/agent_browser_{session}_result.json` | Command result |
302
+ | Console logs | `%TEMP%/agent_browser_{session}_console.json` | JS console output |
303
+ | Network logs | `%TEMP%/agent_browser_{session}_network.json` | Network requests |
304
+ | Screenshots | `./screenshots/` (configurable) | Captured screenshots |
305
+
306
+ ## Troubleshooting
307
+
308
+ | Problem | Solution |
309
+ |---------|----------|
310
+ | `Timeout waiting for result` | Browser may have crashed - run `status` to check |
311
+ | `Element not found` | Use `count` to verify selector matches elements |
312
+ | `Browser not responding` | Run `status` to ping the browser |
313
+ | `Browser process has died` | State was stale - run `start <url>` to restart |
314
+ | `Complex selector failing` | Use `eval` with JavaScript as fallback |
315
+
316
+ ### Debug Workflow
317
+
318
+ ```bash
319
+ # 1. Check browser status
320
+ agent-browser status
321
+
322
+ # 2. Check for JS errors
323
+ agent-browser cmd console
324
+
325
+ # 3. Check for failed requests
326
+ agent-browser cmd network_failed
327
+
328
+ # 4. Take screenshot to see current state
329
+ agent-browser cmd screenshot debug
330
+
331
+ # 5. Count elements to verify selector
332
+ agent-browser cmd count ".my-selector"
333
+ ```
334
+
335
+ ## Python API
336
+
337
+ You can also use agent-browser as a Python library:
338
+
339
+ ```python
340
+ from agent_browser import BrowserDriver
341
+
342
+ driver = BrowserDriver(session_id="test", output_dir="./screenshots")
343
+
344
+ # Start browser (blocking - run in thread/process)
345
+ # driver.start("http://localhost:8080")
346
+
347
+ # Or send commands to running browser
348
+ result = driver.send_command("screenshot home")
349
+ print(result)
350
+
351
+ status = driver.status() # Returns True if running
352
+ ```
353
+
354
+ ## Contributing
355
+
356
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
357
+
358
+ ## License
359
+
360
+ GNU General Public License v3.0 - see [LICENSE](LICENSE) for details.