Initial import: opencode Chrome extension + native host (browser MCP bridge)

This commit is contained in:
ner committed 2026-11-25 18:46:48 +02:00
commit ee5b79570c
41 files changed
+6845

No files matched your search

+125
View File
@@ -0,0 +1,125 @@
# opencode (Chrome extension)
Gives [opencode](https://opencode.ai) the same browser tools as Anthropic's
Claude in Chrome: the same 22 MCP tools, with the same names, parameters and
behaviour, driving your real Chrome (logged-in profile, real tabs) through an
extension.
Fork of [noemica-io/open-claude-in-chrome](https://github.com/noemica-io/open-claude-in-chrome),
reworked for opencode. **License: PolyForm Noncommercial 1.0.0** (inherited
from upstream, see `LICENSE`): personal/non-commercial use only.
## How it works
```
opencode ──stdio MCP──▶ host/mcp-server.js ──unix socket──▶ native host ──native messaging──▶ extension ──CDP──▶ tabs
```
- Each browser with the extension runs its own native host, which opens a
socket and descriptor in `~/.config/opencode-browser/run/`. The MCP server
finds browsers there, which is what `list_connected_browsers`,
`select_browser` and `switch_browser` work on.
- Each opencode session (one MCP server process) gets its own tab group: a
background tab at the end of the window you are using, so your own tab stays
in front (focus emulation keeps the background tab rendering). A session's
calls run one at a time, in order, even when the model issues them in
parallel.
- While the agent works in a tab, the page shows the official extension's
overlay: a pulsing orange glow around the edges and an orange cursor that
glides to each click, hover, scroll or drag. Unlike the official extension,
which takes the glow out for every screenshot (so it blinks), the overlay is
left alone and shows in the agent's screenshots. It stays until the session
ends.
- Screenshots use the official frame: the viewport at device resolution,
shrunk to fit the image budget (1568 tiles of 28 px). Coordinates the agent
passes are in that frame. Tool output text (Tab Context blocks, batch labels,
`read_page` lines, console and network listings, errors) follows the official
extension's wording; it was compared side by side with it.
- `browser_batch`, `navigate` without a `tabId`, the browser-selection tools,
`file_upload` path checks and `save_to_disk` are handled in the MCP server;
everything else runs in the extension.
## Install
Requires Node.js 18+.
```sh
./install.sh --opencode
```
This registers the native host for Chrome, Chrome Beta/Canary, Chrome for
Testing, Chromium, Edge, Brave, Vivaldi and Arc (wherever installed), copies the
host to `~/Library/Application Support/opencode-browser/host` (macOS won't let a
browser run it from `~/Documents`), and adds this to
`~/.config/opencode/opencode.json` (after backing it up):
```json
"mcp": { "chrome": { "type": "local", "command": ["<node>", "<repo>/host/mcp-server.js"], "timeout": 150000 } },
"instructions": ["<repo>/host/instructions.md"]
```
Then, in each browser: `chrome://extensions` → Developer mode → **Load
unpacked** → select `extension/`. The ID is fixed by the manifest key:
`ilgnnaeidkbcbnklkmjllflfkmendiib`. The toolbar popup should say
"Connected"; you can rename the browser there.
`./install.sh --uninstall` removes the native host registrations.
### macOS installer (.pkg)
For another Mac, build a self-contained installer (no Node.js needed there):
```sh
packaging/build-pkg.sh # dist/opencode-browser-<version>.pkg (universal)
packaging/build-pkg.sh --arch arm64 # smaller, Apple silicon only
```
It installs a Node.js runtime, the MCP server and native host (bundled with
esbuild) and the extension into `/Library/Application Support/opencode-browser`.
It then registers the native host (system-wide for Chrome, and per user for the
other browsers) and adds the `chrome` MCP server to the logged-in user's
`~/.config/opencode/opencode.json`. An optional component, on by default,
adds the `llama.cpp` provider and makes it the default model when none is set.
The last installer page explains how to load the extension. The package is
unsigned: open it with right-click → Open, or System Settings → Privacy &
Security → Open Anyway.
On the installed Mac, `…/opencode-browser/setup [--llama]` repeats the per-user
setup for another account, and `sudo …/opencode-browser/uninstall` removes it.
## Tools
`tabs_context_mcp`, `tabs_create_mcp`, `tabs_close_mcp`, `navigate`,
`computer` (click/type/key/scroll/drag/hover/screenshot/zoom/scroll_to/wait),
`read_page`, `get_page_text`, `find`, `form_input`, `javascript_tool`,
`file_upload`, `upload_image`, `read_console_messages`,
`read_network_requests`, `resize_window`, `gif_creator`, `shortcuts_list`,
`shortcuts_execute`, `list_connected_browsers`, `select_browser`,
`switch_browser`, `browser_batch`. In opencode they appear as `chrome_<name>`.
Differences from the official extension:
- No per-site permission prompts and no site blocklist. Use opencode's own
`permission` config if you want approval before browser actions.
- `find` uses scored keyword/role matching in the page, not a language model,
so its one-line explanations are templated.
- Shortcuts are an official side-panel feature: `shortcuts_list` is always
empty.
- The GIF watermark says "opencode".
## Development
```sh
cd host && npm test # host + MCP server against a simulated extension
```
- After changing `extension/`, reload it in `chrome://extensions`. A browser
restart alone can keep running the cached service worker if the version is
unchanged.
- After changing `host/native-host.js` or `host/endpoint.js`, re-run
`./install.sh` (the browser runs the installed copy), then reload the
extension.
- Changes to `host/mcp-server.js` and friends take effect in the next opencode
session.
- Logs: `~/.config/opencode-browser/host.log` (native host exits),
`server-exits.log` (MCP server).