Overview
Agent Browser uses a client-daemon architecture that combines the performance of native code with the power of browser automation:- Rust CLI - Fast native binary that parses commands and communicates with the daemon
- Node.js Daemon - Persistent background process that manages the Playwright browser instance
- Chromium Browser - Headless or headed browser controlled via Playwright
Why This Architecture?
The dual-process design solves several key problems:- Fast Command Execution: The Rust CLI handles argument parsing in native code (< 1ms overhead)
- Persistent Browser: The Node.js daemon keeps the browser alive between commands, avoiding slow startup
- Clean Separation: The CLI handles user interaction while the daemon focuses on browser control
- Fallback Support: If the native binary is unavailable, commands can fall back to Node.js
Communication Flow
IPC Transport
The CLI and daemon communicate via:- Unix Domain Sockets (macOS/Linux):
~/.agent-browser/{session}.sock - TCP Localhost (Windows): Port derived from session name (49152-65535 range)
\n).
Daemon Lifecycle
Automatic Start
The daemon starts automatically on the first command:~/.agent-browser/{session}.pid.
Session Persistence
The daemon persists between commands, keeping the browser session alive:Graceful Shutdown
The daemon shuts down on:- Explicit
closecommand:agent-browser close - Process signals:
SIGINT,SIGTERM,SIGHUP - Unexpected errors (cleanup before exit)
- Closes the browser
- Removes socket/PID files
- Auto-saves session state (if
--session-nameis set)
Session Isolation
Multiple isolated browser sessions can run concurrently using the--session flag:
- Daemon process
- Browser instance
- Socket file (
.sockor port) - PID file (
.pid)
Command Serialization
The daemon processes commands serially (one at a time) to prevent race conditions:- Concurrent writes to the same socket
- Buffer contention causing
EAGAINerrors on the CLI side - Playwright state corruption from parallel operations
Backpressure Handling
The daemon uses backpressure-aware socket writes to prevent buffer overflow:Security Model
Socket Permissions
Socket files are created with0o700 permissions (owner-only access):
HTTP Request Detection
The daemon rejects HTTP requests to prevent cross-origin attacks:{), while browsers send HTTP headers. This blocks malicious web pages from controlling your browser.
Browser Providers
The daemon supports multiple browser sources:Local Browser (Default)
Launches Playwright’s bundled Chromium:CDP Connection
Connects to an existing browser via Chrome DevTools Protocol:- Connecting to desktop Chrome/Chromium
- Controlling Electron apps
- Debugging mobile browsers via remote debugging
Cloud Providers
Connects to remote browser services (Browserbase, Browser Use, Kernel):Platform Support
| Platform | Architecture | Daemon IPC | Native Binary |
|---|---|---|---|
| macOS | ARM64 | Unix Socket | ✓ |
| macOS | x64 | Unix Socket | ✓ |
| Linux | ARM64 | Unix Socket | ✓ |
| Linux | x64 | Unix Socket | ✓ |
| Windows | x64 | TCP Localhost | ✓ |
Environment Configuration
The daemon reads configuration from environment variables:| Variable | Purpose |
|---|---|
AGENT_BROWSER_SESSION | Session name (default: default) |
AGENT_BROWSER_SOCKET_DIR | Socket directory override |
AGENT_BROWSER_DAEMON | Force daemon mode (1 to enable) |
AGENT_BROWSER_DEFAULT_TIMEOUT | Playwright timeout in ms (default: 25000) |
AGENT_BROWSER_DEBUG | Enable debug logging |
daemon.ts and browser.ts for the complete list.
Performance Characteristics
Command Overhead
- Native binary: < 1ms parsing + IPC round-trip
- npx fallback: 100-500ms Node.js startup overhead
- Daemon IPC: ~1-2ms round-trip (Unix socket) or ~2-5ms (TCP localhost)
Browser Startup
- First command: 2-3 seconds to launch Chromium
- Subsequent commands: 0ms (browser already running)
Memory Usage
- Rust CLI: ~1-2 MB
- Node.js daemon: ~50-100 MB
- Chromium browser: ~200-500 MB (depends on page complexity)
Error Handling
Stale Daemon Detection
The CLI checks if the PID in the PID file is still alive:Timeout Handling
Playwright operations timeout after 25 seconds by default:EAGAIN failures.
Next Steps
- Snapshot Refs - Learn how element references work
- Sessions - Understand session isolation and persistence
- Selectors - Master element selection strategies