An OpenCode plugin that exposes Playwright browser-control tools. Single source file: index.ts.
- Bun (not Node). Lockfile is
bun.lock. - ESM only (
"type": "module"). - No build step — the plugin entry is raw TypeScript via package.json
exports["./server"].
@opencode-ai/plugin— plugin API (tool(),tool.schema,PluginInput,PluginOptions).playwright— browser automation (onlychromiumis used).
- No tests, no CI, no build script. Changes are verified by running an OpenCode session that loads the plugin.
- Playwright browsers must be installed separately:
bunx playwright install chromium. The error message inensureBrowser()also reminds of this.
- Persistent profile: Browser data lives at
~/.opencode/browser-profile. Created on first launch. - Idle timeout: Browser auto-closes after 30 min of inactivity (
IDLE_TIMEOUT). A watchdog polls every 60 s. - Tool multiplexing: One
browsertool accepts anactionparam to dispatch (start/stop/open/navigate/snapshot/screenshot/click/type/evaluate/wait/close/back). Four convenience shortcuts (browser_start,browser_snapshot,browser_click,browser_type) wrap the most common actions. - Ref-based targeting:
buildSnapshot()runs ARIA snapshot on<body>, assignse1,e2, … refs to interactive elements, and stores them instate.refs. Click/type look up refs by role + name + nth index. - Multi-tab: Pages tracked in
state.pagesMap keyed bypage_id.state.currentPageIdtracks the active tab.
- All browser state is in a module-level
stateobject — no classes, no external state store. - Errors are returned as strings (not thrown) from tool execute handlers.