Guidelines for AI agents working on this codebase.
OpenCode Browser provides browser automation tools to OpenCode via an OpenCode plugin backed by direct Chrome DevTools Protocol (CDP) connections.
Architecture:
OpenCode Plugin <-> CDP HTTP endpoint <-> Browser target WebSocket
Components:
- Plugin (
src/plugin.ts) - OpenCode plugin that exposesbrowser_*tools. - CDP client (
src/lib/cdp.ts) - minimal raw WebSocket client and target discovery. - Snapshot helpers (
src/lib/snapshot.ts) - accessibility tree rendering and UID resolution.
# Install dependencies
bun install
# CLI status/tools
node bin/cli.js status
node bin/cli.js tools
# Validate scripts
node --check bin/cli.js
bun run buildTo test end-to-end you need a Chrome, Chromium, or Electron instance exposing CDP.
Example Chrome launch:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222Then run in a fresh OpenCode process:
opencode run "use browser_list with browser_url http://127.0.0.1:9222"
opencode run "use browser_snapshot with browser_url http://127.0.0.1:9222"- 2-space indentation
- Double quotes
- Semicolons required
- 2-space indentation
- Double quotes
- No semicolons
- Every tool requires an explicit
browser_url. - Use
browser_listto discovertarget_idvalues for multi-target sessions. browser_clickandbrowser_fillrequire a priorbrowser_snapshotwith the samebrowser_urlandtarget_id.