| name | browser |
| description | Use when building browser automation scripts that need to control Chrome via the AgentInBrowser REST API. Covers how to start/stop the server, send commands, and handle responses. |
AgentInBrowser Skill
Overview
AgentInBrowser is a REST API service that provides remote control of a Chrome browser. It wraps Selenium WebDriver and exposes HTTP endpoints for browser operations (find elements, click, type, screenshot, execute JS, etc.).
Project Location: D:\Develop\AgentInBrowser
When to Use
- Building browser automation scripts (auto-login, course watching, form filling, etc.)
- Need to control browser via HTTP interface instead of using Selenium directly
- Need to run browser tasks in background without detection
Quick Reference
Start Server
cd D:\Develop\AgentInBrowser
source .venv/bin/activate
aib
aib
Server listens on: http://127.0.0.1:5000
Check Server Status
import requests
resp = requests.get("http://127.0.0.1:5000/status")
Stop Server
requests.post("http://127.0.0.1:5000/shutdown")
requests.post("http://127.0.0.1:5000/quit")
API Endpoints
| Endpoint | Method | Description |
|---|
/status | GET | Get server status |
/env | GET | Get server environment info (project dir, venv path, etc.) |
/init | POST | Initialize browser and navigate to URL |
/execute | POST | Execute a Selenium command |
/quit | POST | Close browser (server continues) |
/shutdown | POST | Close browser and stop server |
Agent Usage Workflow (Important!)
Since the server uses uv for dependency management, the virtual environment .venv is inside the project directory. Agent's bash tool runs in a local directory, so you need to get server environment info first before activating venv.
Step 1: Query Server Environment
import requests
env = requests.get("http://127.0.0.1:5000/env").json()
print(env)
Step 2: Activate venv (Execute Before Using CLI)
In Agent's bash command, activate venv first before using aib-client:
Windows PowerShell:
& "D:\Develop\AgentInBrowser\.venv\Scripts\Activate.ps1"
aib-client init https://example.com
Windows cmd:
D:\Develop\AgentInBrowser\.venv\Scripts\activate.bat && aib-client init https://example.com
Linux/macOS:
source /path/to/AgentInBrowser/.venv/bin/activate
aib-client init https://example.com
Step 3: Use CLI Client
aib-client init https://example.com
aib-client find button
aib-client click 0
aib-client quit
Response Format
All endpoints return JSON with unified format:
{"success": true, "data": {...}}
{"success": false, "error": "error message"}
Commands via /execute
Request body format:
{"cmd": "command_name", "params": {"key": "value"}}
Finding Elements
find — Find elements by CSS selector
requests.post("http://127.0.0.1:5000/execute", json={
"cmd": "find",
"params": {"selector": "button.btn-primary"}
})
Note: find results are cached, subsequent click/send_keys/get_html reference by index.
inputs — Get all input elements
requests.post("http://127.0.0.1:5000/execute", json={"cmd": "inputs"})
buttons — Get all button elements
requests.post("http://127.0.0.1:5000/execute", json={"cmd": "buttons"})
Element Interaction
click — Click element (by index from find/inputs/buttons)
requests.post("http://127.0.0.1:5000/execute", json={
"cmd": "click",
"params": {"index": 0}
})
Auto-scrolls to element visible area, falls back to JS click on normal click failure. Built-in random delays mimic human behavior.
send_keys — Type text into element
requests.post("http://127.0.0.1:5000/execute", json={
"cmd": "send_keys",
"params": {"index": 0, "text": "hello"}
})
Calls clear() first before typing, built-in random delays.
Page Information
page_info — Get current page information
requests.post("http://127.0.0.1:5000/execute", json={"cmd": "page_info"})
get_text — Get page text
requests.post("http://127.0.0.1:5000/execute", json={"cmd": "get_text"})
get_html — Get element innerHTML
requests.post("http://127.0.0.1:5000/execute", json={
"cmd": "get_html",
"params": {"index": 0}
})
Utility Commands
screenshot — Take screenshot
requests.post("http://127.0.0.1:5000/execute", json={
"cmd": "screenshot",
"params": {"filename": "my_screenshot.png"}
})
execute_script — Execute JavaScript
requests.post("http://127.0.0.1:5000/execute", json={
"cmd": "execute_script",
"params": {"script": "return document.title"}
})
sleep — Wait (also saves page HTML)
requests.post("http://127.0.0.1:5000/execute", json={
"cmd": "sleep",
"params": {"seconds": 5}
})
Window Management
switch_window — Switch window
requests.post("http://127.0.0.1:5000/execute", json={
"cmd": "switch_window",
"params": {"index": -1}
})
close_window — Close current window (auto-switch back to main window)
requests.post("http://127.0.0.1:5000/execute", json={"cmd": "close_window"})
Typical Workflow
1. Initialize browser and open page
import requests
SERVER = "http://127.0.0.1:5000"
resp = requests.post(f"{SERVER}/init", json={"url": "https://example.com"})
print(resp.json())
2. Find and interact
resp = requests.post(f"{SERVER}/execute", json={
"cmd": "find", "params": {"selector": "a"}
})
elements = resp.json()["data"]["elements"]
requests.post(f"{SERVER}/execute", json={
"cmd": "click", "params": {"index": 0}
})
requests.post(f"{SERVER}/execute", json={
"cmd": "sleep", "params": {"seconds": 3}
})
3. Fill form
requests.post(f"{SERVER}/execute", json={"cmd": "inputs"})
requests.post(f"{SERVER}/execute", json={
"cmd": "send_keys", "params": {"index": 0, "text": "username"}
})
requests.post(f"{SERVER}/execute", json={
"cmd": "send_keys", "params": {"index": 1, "text": "password"}
})
requests.post(f"{SERVER}/execute", json={"cmd": "buttons"})
requests.post(f"{SERVER}/execute", json={
"cmd": "click", "params": {"index": 0}
})
4. Handle new window (e.g., popup login)
requests.post(f"{SERVER}/execute", json={
"cmd": "switch_window", "params": {"index": -1}
})
requests.post(f"{SERVER}/execute", json={"cmd": "close_window"})
5. Cleanup
requests.post(f"{SERVER}/quit")
requests.post(f"{SERVER}/shutdown")
Important Notes
- Element indices are ephemeral — Each
find/inputs/buttons call resets internal cache, subsequent click/send_keys/get_html reference the most recent find result
- Server must be started first — Client scripts should check
/status before sending commands
- Anti-detection is built-in — Server automatically injects anti-suspend scripts and anti-automation detection, no client-side work needed
- Random delays included —
click and send_keys include random delays to mimic human behavior
- Auto-logging — All operations logged to
server_log.txt in working directory
- Click auto-fallback — Falls back to JavaScript click when normal click fails