Browser automation plugin for OpenCode using direct Chrome DevTools Protocol (CDP) connections.
This package now mirrors the browser tool example from OpenWork: no Chrome extension, no native messaging host, no local broker, and no hidden singleton browser state. Each tool call explicitly receives a browser_url, and tools can target a specific tab/window with target_id.
- Direct CDP keeps the package small and predictable.
browser_urlmakes the browser endpoint explicit and portable.target_idsupports multiple tabs/windows without per-session ownership state.- The same tools work with Chrome, Chromium, Electron, and remote/proxied CDP endpoints.
Install or link the package, then add it to opencode.json or opencode.jsonc:
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-chrome-devtools"]
}Start Chrome or Chromium with remote debugging enabled:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222Then use http://127.0.0.1:9222 as browser_url.
For Electron apps, pass the app's exposed CDP endpoint as browser_url.
The CLI can list tools and run a tool directly after bun run build:
npx opencode-chrome-devtools tools
npx opencode-chrome-devtools tool browser_list --args '{"browser_url":"http://127.0.0.1:9222"}'
npx opencode-chrome-devtools tool browser_snapshot --args '{"browser_url":"http://127.0.0.1:9222"}'If you omit browser_url in CLI calls, OPENCODE_BROWSER_URL is used, then http://127.0.0.1:9222.
browser_list: list page targets on a CDP endpoint.browser_navigate: navigate a target to a URL.browser_snapshot: get an accessibility tree snapshot with[uid]markers.browser_click: click an element by snapshot UID.browser_fill: fill an input by snapshot UID.browser_eval: evaluate JavaScript in the page.browser_screenshot: capture a PNG screenshot and return its saved path.
- Run
browser_listwith abrowser_url. - Choose a
target_id, or omit it to use the first page target. - Run
browser_navigateif needed. - Run
browser_snapshotto get UIDs. - Use
browser_clickorbrowser_fillwith a UID from the latest snapshot. - Confirm results with
browser_snapshotorbrowser_eval.
- If
browser_listfails, confirm the browser was started with--remote-debugging-portand that/json/listis reachable. - If
browser_clickorbrowser_fillsays no snapshot is cached, callbrowser_snapshotfirst with the samebrowser_urlandtarget_id. - If a proxied CDP endpoint returns localhost WebSocket URLs, the plugin rewrites them to the proxy host.