opchrm 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +70 -2
- package/apps/daemon/bin/openchrome.mjs +75 -0
- package/apps/daemon/dist/index.js +3912 -0
- package/apps/daemon/dist/package.json +3 -0
- package/apps/mcp-server/dist/index.js +40394 -0
- package/apps/mcp-server/dist/package.json +3 -0
- package/bin/opchrm-daemon.js +2 -0
- package/bin/opchrm-mcp.js +2 -0
- package/package.json +49 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 OpenChrome contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,71 @@
|
|
|
1
|
-
#
|
|
1
|
+
# OpenChrome
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Let your coding agent use the Chrome browser you're already using. OpenChrome connects MCP-compatible agents (OpenCode, Claude Code, Codex, Cursor) to your existing Chrome session — tabs, navigation, snapshots, clicks, typing, console, network, screenshots — so the agent can test and verify its own work.
|
|
4
|
+
|
|
5
|
+
```text
|
|
6
|
+
Agent --MCP(stdio)--> openchrome-mcp --WS(127.0.0.1:18721)--> daemon <--WS--> Chrome extension --> your tabs
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
Requires Node.js 22+ and Chrome.
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install -g opchrm
|
|
15
|
+
opchrm daemon # start the local bridge (leave running)
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Load the extension once: `chrome://extensions` → Developer mode → Load unpacked → select the `extension/` folder from this repo (or unzip `dist/openchrome-extension.zip`).
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
opchrm init # prints a pairing token
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Paste the token into the extension popup → Pair. Verify:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
opchrm status # extensionConnected: true
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Use with OpenCode
|
|
31
|
+
|
|
32
|
+
```json
|
|
33
|
+
{
|
|
34
|
+
"mcp": {
|
|
35
|
+
"openchrome": {
|
|
36
|
+
"type": "local",
|
|
37
|
+
"command": ["openchrome-mcp"],
|
|
38
|
+
"enabled": true
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Then prompt: `Open localhost:3000/signup, fill the form, submit, and tell me whether it works.`
|
|
45
|
+
|
|
46
|
+
## Tools
|
|
47
|
+
|
|
48
|
+
14 MCP tools: `browser_status`, `browser_tabs`, `browser_select_tab`, `browser_open`, `browser_snapshot`, `browser_screenshot` (image), `browser_click`, `browser_type`, `browser_press`, `browser_back`, `browser_forward`, `browser_reload`, `browser_console`, `browser_network`.
|
|
49
|
+
|
|
50
|
+
Snapshots return `[eN]` refs; refs go stale on navigation (`STALE_ELEMENT_REFERENCE` → snapshot again). Sensitive actions (password fields, non-allowlisted sites) return `NEEDS_APPROVAL` — approve in the popup, retry.
|
|
51
|
+
|
|
52
|
+
## Permissions
|
|
53
|
+
|
|
54
|
+
Default: `localhost` allowed, unknown sites ask, explicit rules in the popup (Allow/Ask/Deny per pattern). Denied tabs are hidden from the agent. Secrets (cookies, passwords, tokens) are never exposed; URLs are redacted in logs.
|
|
55
|
+
|
|
56
|
+
## Develop
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
npm install
|
|
60
|
+
npm run build # typecheck + dist bundles for daemon, MCP server, extension
|
|
61
|
+
npm run daemon # run daemon from dist
|
|
62
|
+
npm run mcp # run MCP server from dist (stdio)
|
|
63
|
+
npm run test-app # deterministic test app on :3000 (/signup, /login, /js-error, /api-error…)
|
|
64
|
+
npm run pack:extension # zip the extension for sideload/store
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
CLI manual mode (no MCP client needed): `node apps/mcp-server/dist/index.cjs browser_tabs`.
|
|
68
|
+
|
|
69
|
+
## License
|
|
70
|
+
|
|
71
|
+
MIT — see LICENSE.
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// opc CLI: daemon | init | reset-token | status. Self-contained (no TS imports).
|
|
3
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { dirname, join } from "node:path";
|
|
6
|
+
import { homedir } from "node:os";
|
|
7
|
+
import { mkdirSync, readFileSync, writeFileSync, existsSync } from "node:fs";
|
|
8
|
+
import { randomBytes } from "node:crypto";
|
|
9
|
+
|
|
10
|
+
const cmd = process.argv[2] ?? "help";
|
|
11
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
12
|
+
const port = Number(process.env.OPENCHROME_PORT ?? 18721);
|
|
13
|
+
|
|
14
|
+
function tokenPath() {
|
|
15
|
+
const dir = process.env.OPENCHROME_CONFIG_DIR ?? join(homedir(), ".openchrome");
|
|
16
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
17
|
+
return join(dir, "token");
|
|
18
|
+
}
|
|
19
|
+
function loadOrCreateToken() {
|
|
20
|
+
if (process.env.OPENCHROME_TOKEN) return process.env.OPENCHROME_TOKEN;
|
|
21
|
+
const p = tokenPath();
|
|
22
|
+
if (existsSync(p)) {
|
|
23
|
+
const t = readFileSync(p, "utf8").trim();
|
|
24
|
+
if (t.startsWith("oc_")) return t;
|
|
25
|
+
}
|
|
26
|
+
const t = "oc_" + randomBytes(16).toString("hex");
|
|
27
|
+
writeFileSync(p, t + "\n", { mode: 0o600 });
|
|
28
|
+
return t;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (cmd === "daemon") {
|
|
32
|
+
const dist = join(here, "../dist/index.cjs");
|
|
33
|
+
const args = process.argv.slice(3);
|
|
34
|
+
if (existsSync(dist)) {
|
|
35
|
+
const child = spawn(process.execPath, [dist, ...args], { stdio: "inherit" });
|
|
36
|
+
child.on("exit", (c) => process.exit(c ?? 0));
|
|
37
|
+
} else {
|
|
38
|
+
console.error("dist missing; run `npm run build` first (or use tsx dev: node ./node_modules/tsx/dist/cli.mjs apps/daemon/src/index.ts)");
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
} else if (cmd === "init") {
|
|
42
|
+
const token = loadOrCreateToken();
|
|
43
|
+
console.log(`OpenChrome\n\nDaemon token (paste into extension popup Pairing field):\n ${token}\n\nDaemon endpoint: ws://127.0.0.1:${port}\n\nNext:\n 1. run: opchrm daemon (or npm run daemon)\n 2. load apps/extension in chrome://extensions (Developer mode)\n 3. paste token into popup -> Pair\n 4. run: opchrm status`);
|
|
44
|
+
} else if (cmd === "reset-token") {
|
|
45
|
+
const t = "oc_" + randomBytes(16).toString("hex");
|
|
46
|
+
writeFileSync(tokenPath(), t + "\n", { mode: 0o600 });
|
|
47
|
+
console.log(t);
|
|
48
|
+
} else if (cmd === "status") {
|
|
49
|
+
const token = loadOrCreateToken();
|
|
50
|
+
const { default: WebSocket } = await import("ws").catch(() => ({ default: null }));
|
|
51
|
+
if (!WebSocket) {
|
|
52
|
+
// fallback: raw TCP probe won't speak WS; just report daemon port state
|
|
53
|
+
const net = await import("node:net");
|
|
54
|
+
const s = net.connect(port, "127.0.0.1");
|
|
55
|
+
s.on("connect", () => { console.log(JSON.stringify({ daemonPort: port, reachable: true }, null, 2)); process.exit(0); });
|
|
56
|
+
s.on("error", () => { console.error("daemon not reachable on " + port); process.exit(1); });
|
|
57
|
+
} else {
|
|
58
|
+
const ws = new WebSocket(`ws://127.0.0.1:${port}`);
|
|
59
|
+
const id = Math.random().toString(36).slice(2);
|
|
60
|
+
const timer = setTimeout(() => { console.error("COMMAND_TIMEOUT"); process.exit(1); }, 8000);
|
|
61
|
+
ws.on("open", () => ws.send(JSON.stringify({ id: "reg1", type: "register", token, role: "mcp-shim" })));
|
|
62
|
+
ws.on("message", (raw) => {
|
|
63
|
+
const msg = JSON.parse(String(raw));
|
|
64
|
+
if (msg.id === "reg1" && msg.success) { ws.send(JSON.stringify({ id, type: "command", method: "status.get", params: {} })); return; }
|
|
65
|
+
if (msg.id === id) {
|
|
66
|
+
clearTimeout(timer);
|
|
67
|
+
console.log(JSON.stringify(msg.success ? msg.result : msg.error, null, 2));
|
|
68
|
+
ws.close();
|
|
69
|
+
process.exit(msg.success ? 0 : 1);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
console.log(`usage: opchrm <daemon|init|reset-token|status> [--port N]`);
|
|
75
|
+
}
|