opencode/packages/browser-extension/vite.config.ts
Ryan Vogel 0f0fd4243d feat(browser-extension): add OpenCode Browser, an extension agents control over MCP
OpenCode Browser lets AI agents use the user's real Chromium browser
(Chrome, Edge, Brave, Opera, Vivaldi, Chromium, Helium, Arc). It has no chat
UI: agents drive it through the `browse` MCP server (added in the next
commit), which talks to it through a local relay:

  agent - browse MCP (stdio) - relay 127.0.0.1:19988 - WebSocket - extension

The extension (src/):
- background/agent-relay.ts: the WebSocket link to the relay. Runs its
  commands (CDP through chrome.debugger, tabs, groups, badges, tab-capture
  recordings) and reports tab events; reconnects with backoff; survives an
  extension reload or worker restart by re-attaching its tabs
  (debugger-hub.ts). Commands it doesn't know get an error reply instead of
  leaving the relay waiting.
- agent-groups.ts, tab-cleanup.ts: agent tabs are grouped under the session's
  name at the start of the tab strip, collapsed unless the user is looking at
  one; agent tabs nobody uses for 10 minutes close.
- background/index.ts: the toolbar button lets agents use the current tab, or
  stops them (badge ON / RUN / WAIT).
- content/page-status.ts: the in-page banner while an agent works or waits
  for a handoff (login, 2FA, payment), with Continue.
- status/ (welcome.html, also the options page): install command, relay
  connection, reconnect, close agent tabs, copy diagnostics.

Permissions: debugger, tabs, tabGroups, storage, alarms, offscreen and
tabCapture (recordings), <all_urls> (agents work on any site the user asks;
the banner content script). The manifest key pins the unpacked ID
(afeafocngkodbmaipcngoamamfmekgfo); the store build is
mfnicocicmmlkpjnaffgihfjhdgjkdjg. store/ holds the Web Store listing and
privacy policy; scripts/package.ts builds the store zip.

Verified: typecheck, lint, build; loaded in a clean headless Chrome (status
page connects, no worker errors) and in Helium, driven through the browse
MCP tools.
2026-10-18 18:16:01 -04:00

31 lines
1.3 KiB
TypeScript

import { defineConfig } from "vite"
import { fileURLToPath } from "node:url"
// The extension is loaded unpacked from dist/. The service worker must keep a stable name for the
// manifest; everything else is content-hashed.
export default defineConfig(({ mode }) => ({
// Identifies this build in the relay's log and status, so install can tell whether a reload took effect. The CLI's
// build passes its own stamp so it can record it next to the copied extension.
define: { __OPENCODE_BROWSER_BUILD__: JSON.stringify(process.env.OPENCODE_BROWSER_BUILD ?? new Date().toISOString()) },
root: fileURLToPath(new URL(".", import.meta.url)),
publicDir: "public",
base: "./",
build: {
outDir: "dist",
emptyOutDir: true,
target: "chrome130",
minify: mode !== "development",
sourcemap: mode === "development" ? "inline" : false,
modulePreload: false,
rolldownOptions: {
input: {
welcome: fileURLToPath(new URL("./welcome.html", import.meta.url)),
offscreen: fileURLToPath(new URL("./offscreen.html", import.meta.url)),
background: fileURLToPath(new URL("./src/background/index.ts", import.meta.url)),
},
output: {
entryFileNames: (chunk) => (chunk.name === "background" ? "background.js" : "assets/[name]-[hash].js"),
},
},
},
}))