Skip to content

Latest commit

 

History

History
34 lines (22 loc) · 1.84 KB

File metadata and controls

34 lines (22 loc) · 1.84 KB

AGENTS.md

What this is

An OpenCode plugin that exposes Playwright browser-control tools. Single source file: index.ts.

Runtime & package manager

  • 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"].

Key dependencies

  • @opencode-ai/plugin — plugin API (tool(), tool.schema, PluginInput, PluginOptions).
  • playwright — browser automation (only chromium is used).

Running / testing

  • 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 in ensureBrowser() also reminds of this.

Architecture notes

  • 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 browser tool accepts an action param 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>, assigns e1, e2, … refs to interactive elements, and stores them in state.refs. Click/type look up refs by role + name + nth index.
  • Multi-tab: Pages tracked in state.pages Map keyed by page_id. state.currentPageId tracks the active tab.

Conventions

  • All browser state is in a module-level state object — no classes, no external state store.
  • Errors are returned as strings (not thrown) from tool execute handlers.