OpenCode plugin for agent-browser - browser automation for AI agents with persistent sessions, dev tools, cross-platform installers (Windows / Linux desktop / Linux VPS-headless) and a rewritten, policy-first skill.
Maintained by Pouya Ghourchiani (BTF Kabir).
Note: This is an independent, third-party project. It is not built by the OpenCode team and is not affiliated with anomalyco/opencode in any way. "OpenCode" is used only to describe compatibility.
Project page: https://ghourchiani.ir/projects/opencode-browser-agent
- Uses your real browser, not a throwaway one. It attaches to your already-running Chrome with
--auto-connect— your logins and tabs stay, and the skill forbids killing or closing your browser. - Policy-first. A rewritten skill constrains how the agent drives the browser (no
pkill, no hijacking unrelated tabs, privacy-respecting defaults), rather than leaving the model to improvise. - One-command install everywhere. Windows PowerShell, Linux desktop, and headless VPS, with a matching one-command update path.
- Optional, opt-in Obscura engine. A lightweight local CDP backend you can switch on deliberately (Chrome stays the default); see
docs/obscura.md.
# Start from your already-running Chrome (your logins intact, no new profile)
agent-browser --auto-connect open https://example.com
agent-browser screenshot page.png
# Or let the opt-in Obscura backend manage a local CDP engine instead
# (tool: obscura_backend, actions: start / attach / status / doctor / stop)- Viewport guidance - open at a consistent 1920x1080 (
agent-browser set viewport) - Cookie Banner Handling - the skill tells the agent to dismiss cookie consent popups
- Cross-platform - Windows PowerShell, Linux terminal (headless) and Linux GUI desktops
- Never kills your browser - reuse your running Chrome via
--auto-connect; the skill forbidspkill/close - Persistent Sessions - Cookies saved across navigations, login once and stay authenticated
- Full Dev Tools - Console logs, network requests, cookies, localStorage, sessionStorage
- JavaScript Execution - Run arbitrary JS in page context
- Video Streaming - Real-time WebSocket streaming for visual monitoring
- Network Mocking - Intercept and mock API responses
- Optional Obscura backend - opt-in, never-automatic local CDP engine (Chrome stays default); see
docs/obscura.md - Zero Config - Works out of the box
Windows (PowerShell):
# install / first-time setup
powershell -ExecutionPolicy Bypass -File .\install.ps1
# update (git pull -> rebuild -> redeploy)
powershell -ExecutionPolicy Bypass -File .\update.ps1
# or: powershell -ExecutionPolicy Bypass -File .\install.ps1 -UpdateLinux / macOS (bash) — works in terminal-only (headless) and GUI desktops:
# install / first-time setup
bash install.sh
# update (git pull -> rebuild -> redeploy)
bash update.sh # or: bash install.sh --updateThen restart opencode — plugins load at startup.
What the scripts do (identical on both platforms):
git pull --ff-only(only with-Update/--update)npm installifnode_modulesis missing- builds
dist/index.js(esbuild via npx) +dist/index.d.ts(tsc) - sanity-checks the bundle (no
pkillguidance, has the new policy) - copies
distto all installed plugin locations (.config+.cache) - points the global
opencode.jsonat the local build via afile:///URL - strips the UTF-8 BOM from
~/.agent-browser/config.json
Rollback: set "plugins": ["opencode-browser-agent"] back in
~/.config/opencode/opencode.json — the deployed npm copies are updated too.
Everything works on a plain Linux VPS — opencode, the plugin, and agent-browser. Setup once:
npm i -g agent-browser
agent-browser install --with-deps # Chrome + system libraries (sudo may be needed)
agent-browser doctor # verify install before running tasks
bash install.sh # plugin: build + deploy + wire configNotes for a GUI-less box:
- Run headless (default). A desktop
~/.agent-browser/config.jsonthat sets"headed": true/"autoConnect": truewill fail here — override withagent-browser --headed false --auto-connect false open <url>, or set both tofalsein that config file. - There is no GUI Chrome to attach to, so
--auto-connectis pointless there; start a fresh browser instead. - Login without a desktop: ask the user to export their cookies from their own
browser and use
agent-browser cookies set --curl cookies.txt, or restore a savedagent-browser state load auth.json, or keep state withagent-browser --session-name app open <url>. - Screenshots, PDF and video recording all work headless.
- Root/container:
agent-browser open --args "--no-sandbox" <url>.
npm install -g agent-browser
agent-browser install # Download Chromium
# Tip: pin the agent-browser version you tested and re-audit the skill on upgrade.From npm (easiest) — add it by name; opencode fetches and loads it:
{
"plugins": ["opencode-browser-agent"]
}From a local build (for development) — either run install.ps1
(recommended), or point opencode.json at the built file:
{
"plugins": ["file:///abs/path/to/opencode-browser-agent/dist/index.js"]
}"Go to amazon.it and accept the cookies"
"Navigate to github.com and take a screenshot"
"Scrape product prices from this Amazon search page"
"Get all the links from the homepage"
"Extract the main article text from this news page"
"Fill the login form with username 'test' and password 'test123'"
"Submit the contact form with my details"
"Search for 'laptop' on Amazon"
"Check the browser console for JavaScript errors"
"Show me all network requests to the API"
"What cookies does this site set?"
"Get the localStorage data"
"Test if the checkout flow works correctly"
"Verify the login redirects to dashboard"
"Check if the form validation shows error messages"
OpenCode Plugin agent-browser
| | |
|-- loads plugin --------->| |
| |-- injects skill awareness -->|
| | |
|-- "go to amazon" ------->| |
| |-- load_agent_browser_skill ->|
| | |
| |<-- skill instructions -------|
| | |
| |-- bash: agent-browser ------>|
| | |
|<-- page opened ----------|<-- success -----------------|
-
Skill Injection - Adds
<available-skills>to system prompt so the AI knows when to use browser automation -
Tool Registration - Registers
load_agent_browser_skilltool that injects detailed instructions into the conversation -
Skill Template - Comprehensive documentation for agent-browser CLI including:
- Opening browser with correct viewport
- Cookie banner handling
- Element interaction via @refs
- Dev tools access
- Troubleshooting
-
Opt-in Obscura backend - Registers the experimental
obscura_backendtool (start/attach/status/doctor/stop). Chrome stays the default; nothing runs unless explicitly started. Seedocs/obscura.md.
agent-browser --auto-connect open <url> # reuse already-running Chrome (keeps logins)
agent-browser tab new --label work <url> # work in a NEW tab; leave user tabs alone
agent-browser set viewport 1920 1080
# NEVER pkill -f agent-browser, NEVER close a session you didn't create.agent-browser snapshot -i # Check for cookie banner
agent-browser click @eX # Click "Accept" buttonagent-browser snapshot -i # Get interactive elements with @refs
agent-browser click @e1 # Click element
agent-browser fill @e2 "text" # Fill input field
agent-browser press Enter # Press key
agent-browser select @e1 "value" # Select dropdown option
agent-browser scroll down 500 # Scroll pageagent-browser screenshot ./screenshot.png # Viewport
agent-browser screenshot ./screenshot.png --full # Full pageagent-browser console --json # Console logs
agent-browser errors --json # Page errors only
agent-browser cookies get --json # Get all cookies
agent-browser storage local --json # Get localStorage
agent-browser storage session --json # Get sessionStorage
agent-browser eval "document.title" # Execute JavaScriptagent-browser network requests --json # View requests
agent-browser network route "*/api/*" --abort # Block requests
agent-browser network route "*/api/*" --body '{}' # Mock responseAGENT_BROWSER_STREAM_PORT=9223 agent-browser open <url> --headed
# Connect via WebSocket at ws://localhost:9223Clone and customize:
git clone https://github.com/BTF-Kabir-2020/opencode-browser-agent.git
cd opencode-browser-agentEdit src/skill.ts (the skill template) or index.ts (the plugin entry/tools) to customize:
// Find this line in src/skill.ts:
agent-browser set viewport 1920 1080
// Change to your preferred size:
agent-browser set viewport 1440 900// Add to the open command:
agent-browser open <url> --headed --headers '{"Accept-Language": "en-US"}'// In the RULES section, change:
2. **Cookie banner**: ALWAYS dismiss cookie banners...
// To:
2. **Cookie banner**: ASK user before dismissing...npm install
npm run build
# In opencode.json, point at the built bundle (absolute file URL):
{
"plugins": ["file:///abs/path/to/opencode-browser-agent/dist/index.js"]
}The install.ps1 / install.sh scripts do exactly this for you and also
refresh the npm-installed copies.
agent-browser doctor # diagnose first (env, Chrome, daemons)
agent-browser --auto-connect open <url> # reuse the user's running Chrome
# Headless Linux / container / root shell:
agent-browser install --with-deps # Chrome + system libraries
agent-browser open --args "--no-sandbox" <url>
# NEVER pkill -f agent-browser; never close a session you didn't create.# GUI desktop (Windows/macOS/Linux X11 or Wayland):
agent-browser open <url> --headed # show the window
# Headless box (SSH, CI, container, Linux terminal): leave it headless -
# that is the default, screenshots still work. --headed fails with no
# $DISPLAY/Wayland session.# Always use --json flag for dev tools:
agent-browser console --json # Correct
agent-browser console # Wrong - may show empty# Run snapshot to see all interactive elements:
agent-browser snapshot -i
# Look for buttons with text like "Accept", "Accetta", "OK", "Agree"
# Then click the correct @ref# DON'T run 'agent-browser close' - it deletes all cookies!
# Instead, just navigate to new URLs (keeps cookies), or use:
agent-browser --auto-connect open <new-url> # reuse running Chrome# Always re-snapshot after navigation or page changes:
agent-browser open <url>
agent-browser snapshot -i # Get fresh @refs
agent-browser click @e1 # Use new refs--auto-connect only tells you that a Chrome answered, not which profile,
account, or tabs you now control. Before any login/account-dependent action:
agent-browser tab # list tab ids/labels
agent-browser get url
agent-browser get title
agent-browser get cdp-urlUse process/port evidence as read-only confirmation:
# Windows
Get-NetTCPConnection -LocalPort 9222 -State Listen |
Select-Object LocalAddress,LocalPort,OwningProcess
Get-CimInstance Win32_Process -Filter "Name='chrome.exe'" |
Where-Object { $_.CommandLine -match 'remote-debugging-port' } |
ForEach-Object { $_.ProcessId, $_.CommandLine }# Linux
ss -ltnp | grep 9222
ps -ww -o pid,args -C chrome | grep -- '--remote-debugging-port'Rules:
- Do not identify the browser from the profile label alone; compare tab URL, visible
account context, PID/port, and
--profile-directory/user-data-dir evidence. - State the identity evidence in your report (port, PID, tabs, visible account).
- If anything disagrees, stop and ask which Chrome/profile/account to use.
- Never read or report credentials, cookies, tokens, 2FA, or unrelated tabs.
- Never navigate/close/focus the user's existing tabs just to identify them.
Chrome only exposes CDP if it was launched with --remote-debugging-port=9222,
and that port belongs to one browser process - each Chrome profile is its
own process, so the port identifies the profile too.
# preferred: reuse the running Chrome
agent-browser --auto-connect open <url>
# fallback: attach by explicit port
agent-browser --auto-connect false --cdp 9222 open <url>
agent-browser --session work --auto-connect false --cdp 9222 get urlKnown gotchas:
- If
~/.agent-browser/config.jsonsets"autoConnect": true, every--cdpcall fails withCannot use --auto-connect and --cdp together. Pair it with--auto-connect false(or use--config <clean file>). - Recent Chrome can answer
GET /json/versionwith 404/empty while CDP works fine - never diagnose attachment with/json*, use--cdp <port>. chrome://inspect-> Target discovery settings / Enable port forwarding does not open a debugging port on the local Chrome.- A stale
DevToolsActivePortmakes--auto-connecthang, then fail withFailed to read: ... (os error 10060). Check the port is really listening. - A wedged session daemon (
~/.agent-browser/<session>.pid|.portexist and the port listens, yet every call hangs with10060): approve the pending confirmation (agent-browser confirm <id>), work in a fresh--session <name>, and neverpkillChrome or the daemon.
Read-only diagnostics:
# Windows
Get-NetTCPConnection -LocalPort 9222 -State Listen |
Select-Object LocalAddress,LocalPort,OwningProcess
Get-CimInstance Win32_Process -Filter "Name='chrome.exe'" |
Where-Object { $_.CommandLine -match 'remote-debugging-port' }
Get-Content "$env:USERPROFILE\.agent-browser\default.port"# Linux
ss -ltnp | grep 9222
ps aux | grep -- '--remote-debugging-port'
cat ~/.agent-browser/default.portIf no Chrome has the flag, ask the user to relaunch the profile they want:
# closes nothing by itself - the user quits Chrome first, logins are kept
chrome.exe --remote-debugging-port=9222 --profile-directory="Profile 3"Chrome is the default and is behaviourally unchanged. The plugin can optionally
launch a local Obscura CDP engine and
attach agent-browser to it via the generic --cdp <port> path. It is
opt-in, per-run, and never starts automatically.
# start a local engine on an explicit port (requires OBSCURA_BIN or obscura on PATH)
obscura_backend { "action": "start", "port": 9600 }
# then use the returned args:
agent-browser --session obscura-work --auto-connect false --cdp 9600 open https://example.com
# inspect / clean up owned runs only:
obscura_backend { "action": "status" }
obscura_backend { "action": "stop" }
Safety is enforced: binds 127.0.0.1 only, always an explicit port from
the pool 9600–9699 (reserved ports refused), never --allow-file-access,
and fixture mode (--allow-private-network) is off by default and only
allowed with explicit loopback-only targets. Cleanup terminates a process only
after positively verifying ownership.
It is not a Chrome replacement and makes no speed/parity claim; iframe srcdoc content is a confirmed limitation (Obscura 0.2.4). Full details, security
posture, the measured compatibility matrix, and rollback:
docs/obscura.md.
The plugin automatically suggests loading the skill when your prompt contains:
| Category | Trigger Words |
|---|---|
| Screenshots | screenshot, capture, snapshot |
| Scraping | scrape, extract, get data from |
| Navigation | go to, navigate, open website, browse |
| Forms | fill form, submit, login, signup |
| Testing | test website, verify, check page |
| Debugging | console log, network request, cookies |
- "Take a screenshot of google.com"
- "Scrape the prices from Amazon"
- "Fill the contact form on the website"
- "Check if there are any JavaScript errors"
- "Navigate to the login page and sign in"
- OpenCode >= 2.0.0
- agent-browser CLI installed globally (
npm i -g agent-browser, orbrew install agent-browser, orcargo install agent-browser) - Chromium (installed via
agent-browser install; on Linux addagent-browser install --with-depsfor system libraries) - Fully supported platforms: Windows (PowerShell 5.1+), Linux server / terminal (headless), Linux GUI desktop (X11 / Wayland), macOS
# Clone
git clone https://github.com/BTF-Kabir-2020/opencode-browser-agent.git
cd opencode-browser-agent
# Install dependencies (npm - works on Windows, Linux, macOS)
npm install
# Build (esbuild + tsc - identical on every platform)
npm run build
# equivalent one-shot: bash install.sh / powershell -File install.ps1
# The build creates:
# - dist/index.js (bundled plugin)
# - dist/index.d.ts (TypeScript types)opencode-browser-agent/
├── index.ts # Plugin entry: tools + skill loader (thin)
├── src/
│ ├── skill.ts # Skill template/description (single source)
│ └── obscura/ # Opt-in Obscura backend (launcher, manager, runtime)
├── test/
│ ├── obscura.test.ts # Unit tests (24)
│ └── obscura.e2e.ts # Real-binary E2E smoke test
├── docs/
│ └── obscura.md # Opt-in backend: usage, security, matrix, rollback
├── package.json # npm package config (build = esbuild + tsc)
├── tsconfig.json # TypeScript config
├── install.ps1 # Easy install/update - Windows
├── install.sh # Easy install/update - Linux/macOS
├── update.ps1 # Windows update wrapper
├── update.sh # Linux/macOS update wrapper
├── dist/ # Built output (gitignored; created by the scripts)
│ ├── index.js
│ └── index.d.ts
└── README.md
This is an independent project (not upstream's tracker):
- Clone
https://github.com/BTF-Kabir-2020/opencode-browser-agent.git - Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request on BTF-Kabir-2020/opencode-browser-agent
MIT - see LICENSE.
Copyright (c) 2026 Pouya Ghourchiani (BTF Kabir).
Derived from opencode-agent-browser (MIT, Copyright (c) Nicola Crotti); see NOTICE for the upstream license text.
- opencode-agent-browser by Nicola Crotti - the project this plugin is derived from (MIT)
- agent-browser by Vercel Labs
- OpenCode plugin system