@liang-hz/agent-in-chrome 0.55.0

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.
Files changed (112) hide show
  1. package/.ext-id.txt +4 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +5 -0
  4. package/PRIVACY.md +86 -0
  5. package/README.en.md +419 -0
  6. package/README.md +406 -0
  7. package/bin/agent-in-chrome.mjs +97 -0
  8. package/commands/agent-in-chrome.md +18 -0
  9. package/commands/install-agent-in-chrome.md +22 -0
  10. package/docs/AGENTS.md +94 -0
  11. package/docs/CLI.md +297 -0
  12. package/docs/client-compat.json +23 -0
  13. package/extension/about-toc.js +25 -0
  14. package/extension/about.html +240 -0
  15. package/extension/about.js +44 -0
  16. package/extension/agent-window.html +100 -0
  17. package/extension/icons/icon-128.png +0 -0
  18. package/extension/icons/icon-16.png +0 -0
  19. package/extension/icons/icon-24.png +0 -0
  20. package/extension/icons/icon-32.png +0 -0
  21. package/extension/icons/icon-48.png +0 -0
  22. package/extension/icons/icon-64.png +0 -0
  23. package/extension/icons/icon-attention-128.png +0 -0
  24. package/extension/icons/icon-attention-16.png +0 -0
  25. package/extension/icons/icon-attention-24.png +0 -0
  26. package/extension/icons/icon-attention-32.png +0 -0
  27. package/extension/icons/icon-attention-48.png +0 -0
  28. package/extension/icons/icon-attention-64.png +0 -0
  29. package/extension/icons/icon-attention.svg +18 -0
  30. package/extension/icons/icon-failed-128.png +0 -0
  31. package/extension/icons/icon-failed-16.png +0 -0
  32. package/extension/icons/icon-failed-24.png +0 -0
  33. package/extension/icons/icon-failed-32.png +0 -0
  34. package/extension/icons/icon-failed-48.png +0 -0
  35. package/extension/icons/icon-failed-64.png +0 -0
  36. package/extension/icons/icon-failed.svg +18 -0
  37. package/extension/icons/icon-idle-128.png +0 -0
  38. package/extension/icons/icon-idle-16.png +0 -0
  39. package/extension/icons/icon-idle-24.png +0 -0
  40. package/extension/icons/icon-idle-32.png +0 -0
  41. package/extension/icons/icon-idle-48.png +0 -0
  42. package/extension/icons/icon-idle-64.png +0 -0
  43. package/extension/icons/icon-idle.svg +18 -0
  44. package/extension/icons/icon-mark.svg +10 -0
  45. package/extension/icons/icon-running-128.png +0 -0
  46. package/extension/icons/icon-running-16.png +0 -0
  47. package/extension/icons/icon-running-24.png +0 -0
  48. package/extension/icons/icon-running-32.png +0 -0
  49. package/extension/icons/icon-running-48.png +0 -0
  50. package/extension/icons/icon-running-64.png +0 -0
  51. package/extension/icons/icon-running.svg +18 -0
  52. package/extension/icons/icon.svg +18 -0
  53. package/extension/manifest.json +44 -0
  54. package/extension/popup-ui.js +38 -0
  55. package/extension/popup.html +350 -0
  56. package/extension/popup.js +741 -0
  57. package/extension/sw.js +11127 -0
  58. package/extension/update-check.js +66 -0
  59. package/extension/welcome.html +110 -0
  60. package/extension/welcome.js +18 -0
  61. package/mcp/agent-identity.mjs +1007 -0
  62. package/mcp/cdp/bridge.mjs +239 -0
  63. package/mcp/cdp/browser-launch.mjs +1127 -0
  64. package/mcp/cdp/chrome-shim.mjs +1124 -0
  65. package/mcp/cdp/client.mjs +443 -0
  66. package/mcp/cli-invocation.mjs +67 -0
  67. package/mcp/config.mjs +191 -0
  68. package/mcp/foreground-guard.mjs +295 -0
  69. package/mcp/proc-win.mjs +112 -0
  70. package/mcp/secret-shape.mjs +155 -0
  71. package/mcp/server.mjs +3437 -0
  72. package/mcp/session-id.mjs +281 -0
  73. package/mcp/token.mjs +260 -0
  74. package/mcp/tool-tiers.mjs +84 -0
  75. package/mcp/trace.mjs +528 -0
  76. package/mcp/update-cli.mjs +163 -0
  77. package/mcp/update-notice.mjs +194 -0
  78. package/native-host/host.mjs +356 -0
  79. package/native-host/mac-foreground/aic-fg.swift +114 -0
  80. package/native-host/mac-foreground/build.mjs +43 -0
  81. package/package.json +46 -0
  82. package/scripts/agents.mjs +921 -0
  83. package/scripts/borrow-login.mjs +935 -0
  84. package/scripts/cli-browser.mjs +148 -0
  85. package/scripts/e2e-sweep.mjs +192 -0
  86. package/scripts/e2e.mjs +3911 -0
  87. package/scripts/fixture-server.mjs +1419 -0
  88. package/scripts/guard-publish.mjs +175 -0
  89. package/scripts/install.mjs +1383 -0
  90. package/scripts/launcher-provenance.mjs +74 -0
  91. package/scripts/pack-crx.mjs +82 -0
  92. package/scripts/pick.mjs +114 -0
  93. package/scripts/test-agents.mjs +968 -0
  94. package/scripts/test-borrow.mjs +289 -0
  95. package/scripts/test-config.mjs +618 -0
  96. package/scripts/test-e2e-sweep.mjs +251 -0
  97. package/scripts/test-foreground-guard.mjs +383 -0
  98. package/scripts/test-identity.mjs +1141 -0
  99. package/scripts/test-install-skill.mjs +378 -0
  100. package/scripts/test-protocol.mjs +712 -0
  101. package/scripts/test-security.mjs +1360 -0
  102. package/scripts/test-sw.mjs +14526 -0
  103. package/scripts/test-update.mjs +301 -0
  104. package/skills/agent-in-chrome/SKILL.md +60 -0
  105. package/skills/agent-in-chrome/references/actions-and-waits.md +136 -0
  106. package/skills/agent-in-chrome/references/amap-dir-dropdown.md +66 -0
  107. package/skills/agent-in-chrome/references/geetest-click-captcha.md +55 -0
  108. package/skills/agent-in-chrome/references/network-debugging.md +20 -0
  109. package/skills/agent-in-chrome/references/reading-pages.md +30 -0
  110. package/skills/agent-in-chrome/references/recovery.md +25 -0
  111. package/skills/agent-in-chrome/references/tabs-and-sessions.md +34 -0
  112. package/skills/install-agent-in-chrome/SKILL.md +252 -0
package/README.en.md ADDED
@@ -0,0 +1,419 @@
1
+ <div align="center">
2
+
3
+ # Agent in Chrome
4
+
5
+ **Let your AI agent drive the Chrome you're already using — not a blank browser it spawns for itself.**
6
+
7
+ by Liang · [liangai.org](https://liangai.org)
8
+
9
+ It inherits the sessions you're already logged into: intranet tools, Gmail, admin dashboards, staging environments. No re-authentication, no profile migration.
10
+
11
+ [中文](./README.md) · [Quick start](#quick-start) · [Extension vs CLI mode](#two-modes) · [Tools](#tool-reference) · [Security](#security-and-transparency)
12
+
13
+ [![npm](https://img.shields.io/npm/v/@liang-hz/agent-in-chrome?color=cb3837&label=npm)](https://www.npmjs.com/package/@liang-hz/agent-in-chrome)
14
+ [![License](https://img.shields.io/badge/license-Apache--2.0-blue)](./LICENSE)
15
+ [![Chrome](https://img.shields.io/badge/Chrome-125%2B-4285F4?logo=googlechrome&logoColor=white)](#quick-start)
16
+ [![tests](https://img.shields.io/github/actions/workflow/status/Liang-HZ/agent-in-chrome/test.yml?branch=main&label=tests)](https://github.com/Liang-HZ/agent-in-chrome/actions/workflows/test.yml)
17
+
18
+ </div>
19
+
20
+ ---
21
+
22
+ ## What this is
23
+
24
+ Agent in Chrome connects an AI agent (Claude Code, Claude Desktop, Trae, Codex, and others) to **the Chrome sitting in front of you**. It exposes a browser toolset over [MCP](https://modelcontextprotocol.io) so the agent can read pages, click, fill forms, and capture network traffic — all carrying your existing login state, all in background tabs that never steal your foreground.
25
+
26
+ **How does it compare?** The table below scores only **native, out-of-the-box capability**: ✅ = works without writing code, ❌ = not available. (Most of these tools ship an arbitrary-code-execution escape hatch, so in principle anything can be rebuilt by hand — count that and every cell turns ✅ and the table stops meaning anything.) Based on a source-code read and hands-on measurement on 2026-08-18, against @playwright/mcp 0.0.79 · chrome-devtools-mcp 1.7.0 · browser-use 0.13.8 · ego lite 0.4.6.14. No recommendation implied — pick by your situation.
27
+
28
+ | | Agent in Chrome | Playwright MCP | Chrome DevTools MCP | browser-use | ego lite |
29
+ |---|:---:|:---:|:---:|:---:|:---:|
30
+ | Drives the browser you're using (inherits login state) | ✅ | ✅¹ | ✅² | ✅³ | ❌⁴ |
31
+ | No browser restart with a debug port | ✅ | ✅ | ❌ | ❌ | ✅ |
32
+ | Concurrent sessions with non-overlapping tab ownership | ✅ | ✅¹ | ❌ | ❌ | ✅ |
33
+ | Speaks MCP | ✅ | ✅ | ✅ | ✅ | ❌ |
34
+ | Windows / Linux | ✅⁵ | ✅ | ✅ | ✅ | ❌ |
35
+ | Firefox / WebKit | ❌ | ✅ | ❌ | ❌ | ❌ |
36
+ | Raw network headers + request/response bodies | ✅ | ✅ | ✅ | ❌ | ❌ |
37
+ | WebSocket frames / initiator stack / export as curl | ✅ | ❌ | ❌ | ❌ | ❌ |
38
+ | Request mocking / throttling / performance traces | ❌ | ✅ | ✅ | ❌ | ❌ |
39
+ | Credentials redacted by default (cookies and passwords never enter model context) | ✅ | ❌⁶ | ❌⁶ | ✅⁷ | ❌ |
40
+ | No server-side arbitrary code execution enabled by default | ✅ | ❌⁸ | ✅ | ❌ | ❌ |
41
+ | Zero runtime third-party dependencies | ✅ | ❌ | ❌ | ❌ | ❌ |
42
+ | Modal overlay detection (including login walls with no ARIA role) | ✅ | ❌ | ❌ | ❌ | ❌ |
43
+ | Element pixel coordinates + top-level coordinates across frames | ✅ | ❌ | ❌ | ❌ | ❌ |
44
+
45
+ <sup>1</sup> `--extension` mode only (Chrome/Edge, requires installing their extension); the default mode is an isolated profile. <sup>2</sup> `--autoConnect` only (Chrome 144+, requires manually opening the gate in `chrome://inspect`, which exposes every window in that profile). <sup>3</sup> Either connect to a Chrome already started with a debug port, or close Chrome and let it copy the entire profile. <sup>4</sup> A separate Chromium fork; migrates your Chrome data once on first launch. <sup>5</sup> Windows supports extension mode (CLI/headless mode planned); the Linux path is written but unverified. <sup>6</sup> Playwright's `--secrets` and DevTools MCP's `--redactNetworkHeaders` are both opt-in and off by default, and the latter doesn't cover bodies. <sup>7</sup> Solid placeholder mechanism on the input side; no redaction on network responses. <sup>8</sup> `browser_run_code_unsafe` describes itself as RCE-equivalent and is on by default.
46
+
47
+ **Speed** (same test page containing a cross-origin iframe, equivalent fresh profiles, medians; browser-use is omitted because it requires manual per-run authorization in `chrome://inspect` and can't complete the same flow unattended):
48
+
49
+ | | Cold start → first result | Warm navigation | Warm page read | Page-read response bytes |
50
+ |---|---|---|---|---|
51
+ | Agent in Chrome | **1247ms** | 250ms | 27ms¹ | **4146** |
52
+ | Playwright MCP | 1819ms | 225ms | 10ms | 8235 |
53
+ | Chrome DevTools MCP | 1252ms | 288ms | 13ms | 6954 |
54
+
55
+ <sup>1</sup> Our page read returns an interactive-element table + pixel coordinates + cross-origin frame geometry + isolated body text + credential redaction + overlay adjudication; the others return an accessibility tree with no coordinates. Strictly more content, in fewer bytes.
56
+
57
+ ---
58
+
59
+ ## Core features
60
+
61
+ - **Attaches to the Chrome you already use.** No new browser, no data migration. Wherever you're logged in is where the agent works.
62
+ - **Runs in the background.** Page reads and input happen in background tabs; you keep using the foreground for something else. Pages that pop their own new tab (`target=_blank`, `window.open`, middle-click) get raised by Chrome itself — that line is hard-coded in the browser process and nothing can intercept it — so on macOS a local causal guard hands the foreground back to the app you were in, within tens of milliseconds (measured: 11–100ms).
63
+ - **Visible, and revocable.** Tabs the agent opens land in a per-session colored, named tab group; the extension popup lists in real time which tabs each session holds, with one click to 「解除全部托管」(drop every session's hold) or to close everything the agent opened. To step in on a single page, hit 「手动接管」(take over) on its card: the debug banner disappears and the agent is told you have it; 「交给AI接管」(hand back to the AI) returns it. Tabs *you* dragged into the group are **handed back** at the end, never closed.
64
+ - **Page understanding that pierces Shadow DOM and cross-origin iframes.** Interactive elements carry stable `ref`s, and modal overlays inside out-of-process iframes are still detected.
65
+ - **A genuinely complete network layer**: request lists, raw headers (including `Set-Cookie` and rejection reasons), request/response bodies, initiator stacks, WebSocket messages sent and received, and export-as-curl for replay. **Captured credentials are redacted by default** — you get "Cookie, 1258 chars, starts with `_octo=…`", and the plaintext only if you ask for it explicitly. For a tool whose output flows straight into a model's context, this is a requirement, not fastidiousness. Comparable tools either can't see raw headers at all, or hand the model plaintext cookies.
66
+ - **Two modes, one toolset.** If there's a Chrome on your desktop, use extension mode. For terminal agents, cron, CI, and remote machines with no desktop Chrome, CLI mode launches a real Chrome and drives it over CDP directly — identical tool behavior.
67
+ - **An audit trail** (`browser_trace`). Every step records a sequence number, the tool, redacted arguments, success or failure, and which page it happened on. Survives context compaction and session restarts. Credential fields are always redacted.
68
+ - **Safe defaults**: never takes over a tab on its own; irreversible actions (sending messages, placing orders, deleting, changing settings) require your confirmation first; page content is always treated as data, never as instructions (prompt-injection defense); the values of passwords, CVVs, and one-time codes never appear in any result.
69
+ - **Zero runtime dependencies.** The MCP server, native host, and CDP client are all hand-written dependency-free Node. `npm install` pulls in nothing.
70
+
71
+ ---
72
+
73
+ ## Quick start
74
+
75
+ > Requires Node.js 18+ and Chrome 125+ (or Edge / Brave / Vivaldi / any Chromium-based browser). macOS is fully tested; Windows extension mode is supported (named pipes + registry + `.bat` launcher, with CLI/headless mode planned); the Linux path is written but unverified — see [Known limitations](#known-limitations).
76
+ >
77
+ > 18 really is enough, and that's measured: on Node 18.20.8 `check` passes end to end, the MCP server
78
+ > boots and lists all 37 tools. The one exception is CLI mode's `AGENT_IN_CHROME_KEEP=1`, which needs
79
+ > Node's global `WebSocket` — **Node 22+ only**; the default pipe transport works fine on older Node.
80
+ > See [docs/CLI.md](docs/CLI.md).
81
+
82
+ ### Step one: run the installer
83
+
84
+ The fastest route is to **paste this at your agent and let it install for you**:
85
+
86
+ ```
87
+ Install agent-in-chrome for me: npx @liang-hz/agent-in-chrome@latest install
88
+ Then tell me which steps I still have to do by hand.
89
+ ```
90
+
91
+ Or run it yourself:
92
+
93
+ ```bash
94
+ npx @liang-hz/agent-in-chrome@latest install # install (from a git clone: node scripts/install.mjs, equivalent)
95
+ npx @liang-hz/agent-in-chrome check # self-check, changes nothing (non-zero exit if anything failed)
96
+ npx @liang-hz/agent-in-chrome uninstall # uninstall, fully reversible
97
+ ```
98
+
99
+ All three subcommands exit on whether anything failed: 0 when everything passed, non-zero when any
100
+ check did not; a mistyped flag prints the help and also exits non-zero. So
101
+ `npx @liang-hz/agent-in-chrome check && your-command` works.
102
+
103
+ **Installing into a client the installer doesn't cover yet, or it installed but nothing connects?**
104
+ Have your agent run `/install-agent-in-chrome` (or just say "install agent-in-chrome for me"). It
105
+ starts from `npx @liang-hz/agent-in-chrome check --print-config`, which prints this machine's exact
106
+ configuration — runtime absolute paths, native host name, extension ID, launcher command — and only
107
+ then goes looking for where that client keeps its MCP config, writing the entry in that client's own
108
+ schema. Guessing the paths is how this usually fails: a wrong path gets you a bare
109
+ `Connection closed` and nothing else.
110
+
111
+ The installer will (every step reversible, and every file it's about to touch is listed before it touches it):
112
+
113
+ 1. Sync the runtime into `~/.agent-in-chrome/agent-in-chrome/` and write the native host manifest into each Chromium browser's `NativeMessagingHosts/` directory.
114
+ 2. Detect the agents on your machine (Claude Code, Claude Desktop, WorkBuddy, ZCode, opencode, Kimi CLI, Gemini CLI, Antigravity, Qoder CLI, Qoder IDE, Trae, Codex CLI, DeepSeek Harness, plus the China builds Qoder CN CLI / Qoder CN IDE / Trae CN — 16 in total), show you the exact file and content it would write for each, and register the MCP server after you confirm (originals backed up automatically; `--yes` skips the per-agent prompts, `--agents=claude-code,trae` narrows the set, `--no-agents` skips this entirely).
115
+ 3. Generate a **connection token unique to this machine** (mode `0600`, never committed, never uploaded) — see [Security and transparency](#security-and-transparency).
116
+ 4. Install **two skills and two commands**: `skills/agent-in-chrome/` (including the reference handbooks under `references/`, which teach the agent how to use the browser tools) and `skills/install-agent-in-chrome/` (which teaches it how to install this into another client) are copied to `~/.agent-in-chrome/skills/`, and the `/agent-in-chrome` and `/install-agent-in-chrome` commands to `~/.agent-in-chrome/commands/`.
117
+
118
+ ### Step two: install the Chrome extension (the only manual step)
119
+
120
+ > **Load unpacked is currently the only route.** The Chrome Web Store listing is still going through
121
+ > review, so you won't find it by searching the store. Browsers don't allow silent extension installs
122
+ > from the command line either — so these few clicks can't be automated away. You only do them once.
123
+ > The cost is that **an unpacked extension does not auto-update** (see [Updates and versioning](#updates-and-versioning)
124
+ > for how to upgrade it); the store build, once live, updates itself and becomes the recommended entry point.
125
+
126
+ 1. Type `chrome://extensions` in the address bar and hit Enter.
127
+ 2. Turn on **Developer mode** (top right) — **without it, the button in step 3 does not appear**.
128
+ 3. Click **Load unpacked** (top left) and pick **the extension directory the installer printed at the end**:
129
+ - npx / npm install: `~/.agent-in-chrome/extension`
130
+ (macOS file pickers hide dot-directories by default: press `⇧⌘.` to show hidden files, or `⇧⌘G` to paste the path)
131
+ - git clone: `extension/` in the repo
132
+ 4. An "Agent in Chrome" card appears — that's it installed. The ID on that card must read
133
+ `eknmigackgheebnojadpjepdoebpfnil`; **if it doesn't, you picked the wrong directory** (the native
134
+ host only accepts that ID).
135
+ 5. **Pin it to the toolbar**: click the puzzle-piece icon 🧩 next to the address bar, find Agent in
136
+ Chrome, click the pin. Every "click the extension icon" below means that one.
137
+
138
+ **The two steps work in either order.** The native host manifest names a fixed extension ID and doesn't care whether the extension exists yet; once installed, the extension dials in on its own (every 30 seconds, backing off to 60s and at most 2 minutes while no agent is connected, and resetting the moment a call arrives — the popup's 「立即重连」(reconnect now) button is the instant fallback). **You don't need to restart Chrome or your agent**: Chrome re-reads the host config on every `connectNative`, and on the agent side `/mcp` reconnects (supported by Claude Code and WorkBuddy).
139
+
140
+ ### Step three: check that it connected
141
+
142
+ Click the extension icon and read the status line at the top of the popup: **connected** means you're
143
+ done. If it says not connected, the popup translates Chrome's disconnect reason into one concrete next
144
+ action — do that first (most often: the native half isn't installed yet, so go back to step one).
145
+
146
+ Then ask your agent to "list my open tabs" or run `/agent-in-chrome`. If it comes back with your real
147
+ tabs, the whole chain works. If the `browser_*` tools aren't in the agent's tool list at all, that
148
+ client simply hasn't reconnected its MCP servers — it isn't an install failure.
149
+
150
+ Still stuck? Run the per-item self check (**quit your agent first**: the bridge socket is
151
+ single-owner, so the check can't get in while an agent holds it):
152
+
153
+ ```bash
154
+ npx @liang-hz/agent-in-chrome check
155
+ ```
156
+
157
+ Every ✗ line tells you the exact command to run next. The full troubleshooting tree lives in the
158
+ `/install-agent-in-chrome` skill.
159
+
160
+ <details>
161
+ <summary>Per-agent MCP configuration details live in <a href="docs/AGENTS.md">docs/AGENTS.md</a> (the installer writes these for you; you rarely need them)</summary>
162
+ </details>
163
+
164
+ ---
165
+
166
+ ## Two modes
167
+
168
+ One toolset, two transports. You almost never have to care which one is running — tool behavior is identical.
169
+
170
+ ### Extension mode (default; you have Chrome in front of you)
171
+
172
+ agent → MCP server → local socket → native host (spawned by Chrome) → extension → your open tabs.
173
+
174
+ This is the Chrome on your screen. It's the day-to-day mode: you're logged into everything, and the agent works inside that.
175
+
176
+ ### CLI / headless mode (no desktop Chrome)
177
+
178
+ Terminal agents, cron jobs, CI, and remote SSH boxes don't have "an open Chrome with an extension installed" available. Set `AGENT_IN_CHROME_LAUNCH=1` on the MCP server and it **launches a real Chrome itself** and drives it over a direct CDP connection — no extension, no native host, running the same tool code.
179
+
180
+ - Uses the **stable Chrome** already on the machine (not Chrome for Testing), so the fingerprint is what it always was.
181
+ - The profile is dedicated and starts fresh (log into whatever sites you need once; it persists from then on). You can also **borrow login state from your own Chrome, per domain**, and hand it back precisely when you're done: `npx @liang-hz/agent-in-chrome borrow-login --domains github.com` (from a git checkout: `node scripts/borrow-login.mjs --domains github.com` — same flags; boundaries are documented in [docs/CLI.md](docs/CLI.md): session cookies don't survive a restart, and localStorage-based sites can't be moved).
182
+ - Common switches: `AGENT_IN_CHROME_HEADLESS=0` to watch it work; `AGENT_IN_CHROME_KEEP=1` to leave the browser running between sessions and skip the cold start. Full environment variable reference in [docs/CLI.md](docs/CLI.md).
183
+
184
+ | Situation | Mode |
185
+ |---|---|
186
+ | Chrome is open locally, logged into everything, and I want the agent to work in it | **Extension** |
187
+ | Terminal agent / cron / CI / remote machine with no desktop | **CLI** |
188
+ | I want the agent in a clean environment isolated from my daily browser | **CLI** |
189
+ | I need to get past bot detection with a real Chrome fingerprint | Either (both are real Chrome) |
190
+
191
+ ---
192
+
193
+ ## Tool reference
194
+
195
+ <details>
196
+ <summary>Expand 30+ browser tools</summary>
197
+
198
+ **Tabs and sessions**
199
+
200
+ | Tool | What it does |
201
+ |---|---|
202
+ | `browser_status` | Bridge status, which tabs this session holds, `sessionOrigin` |
203
+ | `browser_tabs_list` | List every tab the user has open |
204
+ | `browser_new_tab` | Open a new tab and take it over, filed into the tab group (the default choice) |
205
+ | `browser_tab_use` | Take over a tab the user already had open |
206
+ | `browser_set_label` | Name this session's tab group after the current task |
207
+ | `browser_tab_group` | File held tabs into the tab group |
208
+ | `browser_close_tab` / `browser_close_all` | Close one tab / clean up the tabs this task opened (`scope:"session"` clears the whole session ledger, `scope:"all"` is a cross-session sweep) |
209
+ | `browser_tab_release` | Let go: detach the debugger and hand the tab back to the user (without closing it) |
210
+ | `browser_set_task_state` | Set the task state shown on the tab group (running / attention / failed) — the agent's only non-interrupting channel to the user |
211
+ | `browser_cookies_export` / `_import` | Move login state to another instance; by default no plaintext is returned — it writes a `0600` file and returns only the path, and the importing side reads it via `inFile`, so plaintext enters neither context. Exporting real values is gated **per domain**: ungranted domains are refused on the spot, and you allow them in the extension popup under Preferences → credential loans, after which the agent simply retries (a standing grant expires after 30 days) |
212
+
213
+ **Page understanding**
214
+
215
+ | Tool | What it does |
216
+ |---|---|
217
+ | `browser_navigate` | Navigate / back / forward / reload, waiting for load |
218
+ | `browser_read_page` | Interactive element table (with `ref_N`) + body text, through Shadow DOM and iframes; `activeDialog` reports any modal overlay in the way |
219
+ | `browser_refresh_refs` | Refresh just the element table and ref mapping, without body text (much cheaper) |
220
+ | `browser_find` | Find elements via Chrome's whole-page search (text / CSS / XPath, through iframes and shadow DOM, no element-count ceiling) |
221
+ | `browser_screenshot` | Viewport / full page / single element; writes to disk and returns metadata by default |
222
+
223
+ **Actions**
224
+
225
+ | Tool | What it does |
226
+ |---|---|
227
+ | `browser_click` / `browser_hover` | Click / hover; verifies the target is hittable before, and that it was hit after |
228
+ | `browser_set` | Set a form control's value (select / checkbox / radio / date / range) and read it back to confirm. It only takes the `ref_b…` handles from `browser_find`; `read_page`'s `ref_N` goes to `browser_click` / `browser_type` |
229
+ | `browser_type` / `browser_press_key` | Type text / press keys |
230
+ | `browser_scroll` | Scroll |
231
+ | `browser_emulate` | Viewport / dark mode / throttling / geolocation emulation: reads back whether the viewport really took (mobile on a page without a viewport meta falls back to 980), geolocation also grants the origin's permission, `reset:true` undoes it all |
232
+ | `browser_batch` | Run a sequence of actions, stopping at the first failure and reporting which step broke |
233
+ | `browser_upload_file` | Put a local file into an `<input type=file>` (hidden, shadow, and in-iframe inputs all work) |
234
+
235
+ **Data and network**
236
+
237
+ | Tool | What it does |
238
+ |---|---|
239
+ | `browser_eval` | Evaluate in-page to extract data; results aren't truncated and can go to `outFile` |
240
+ | `browser_cdp` | Raw CDP passthrough (escape hatch) |
241
+ | `browser_console` | Console output and page exceptions |
242
+ | `browser_network` | Request list (`type:"api"` filter, `bodyContains` searches response bodies directly) |
243
+ | `browser_request_detail` | Raw headers (including `Set-Cookie` and rejection reasons) / request body / response body / timing / initiator stack |
244
+ | `browser_network_wait` | Wait for this particular call to a given endpoint and return its result |
245
+ | `browser_websocket` | WebSocket connections and the messages over them |
246
+ | `browser_as_curl` | Export as curl for replay (using the raw request headers from the network layer, including the cookies actually sent) |
247
+ | `browser_wait_for` / `browser_handle_dialog` / `browser_trace` | Wait for a condition / pre-decide how to handle the next dialog / review the audit trail |
248
+
249
+ </details>
250
+
251
+ ---
252
+
253
+ ## Configuration: trimming tools you don't need
254
+
255
+ **Switch profiles straight from the extension popup** (click the extension icon → tool profile). Finer control lives in `~/.agent-in-chrome/config.json` (create it if it doesn't exist):
256
+
257
+ ```json
258
+ {
259
+ "tools": {
260
+ "profile": "observe",
261
+ "disable": ["browser_batch"]
262
+ }
263
+ }
264
+ ```
265
+
266
+ - **`profile` has two settings**, controlling which tools appear in the agent's tool list at all. A tool that's off isn't "disabled" — it **doesn't exist**, so the model never sees it and never reaches for it:
267
+ - `observe` — read pages, screenshot, inspect network, open its own tabs and navigate them. No clicking, no typing, no credential access — any **parameter** that crosses into the credential or execution surface is refused outright at this level: `revealSecrets`, and `browser_wait_for`'s `js` (which is arbitrary evaluation in the page's main world). **An honest caveat**: navigation itself issues GET requests as you, and on some sites unsubscribe or deactivate links *are* GETs. The whole `tools/list` is about 20 KB at this level (about 36 KB at `full`), which saves tokens on every single request.
268
+ - `full` (default) — everything: click/type, `eval` / `cdp` (arbitrary code), cookie import/export (your entire login state), `websocket`, `upload_file`.
269
+ - Older configs using `readonly` / `standard` still work, mapping to `observe` / `full` respectively (`standard` migrates toward the permissive side, so we never silently take away capability you already had).
270
+ - **`disable` / `enable`** turn individual tools off or on on top of the profile (full names, `browser_` prefix). If a tool appears in both, `disable` wins.
271
+ - A broken config is safe: if the JSON is invalid, the last known-good config stays in effect — it **never silently falls back to everything-on**.
272
+
273
+ **When changes take effect**: saving the file is enough; nothing on our side needs restarting. On the agent client side, Claude Code picks up the new tool list on the next turn; **for other clients, if a change doesn't take, restart that client** (reopening a session isn't always enough — some GUI clients reuse one MCP connection across sessions, and restarting the client is the action that always works).
274
+
275
+ ---
276
+
277
+ ## Updates and versioning
278
+
279
+ Nothing updates automatically, and nothing updates silently — **when to upgrade is your call**.
280
+ There are four ways to find out a new version exists, and two ways to install it.
281
+
282
+ ### Finding out there's a new version
283
+
284
+ | Channel | When it shows up | What you see |
285
+ |---|---|---|
286
+ | **Tail of a tool result** | While the agent is working; once per MCP process | A one-line notice appended to some tool result; the agent reads it and passes it along |
287
+ | **Extension popup** | When you click the toolbar icon (result cached 6 hours) | An extra line in the popup with a link |
288
+ | **`check` subcommand** | When you run it | A line at the end of the self-check: local vX, npm latest vY, update available or not |
289
+ | **`browser_status` tool** | When the agent asks | `update: { current, latest, hasUpdate }` in the result |
290
+
291
+ The first two are **passive** — they come to you, but each is a one-shot (the tool-result line is
292
+ consumed once it's read; the popup needs a click). The last two are **the ways to ask**: to confirm
293
+ whether you're current, run `check`, or have the agent look at `browser_status`.
294
+
295
+ In `browser_status`, `latest: null` means **not known** (offline, checking disabled, or the query
296
+ hasn't returned yet), and `hasUpdate` is then always `false` — "don't know" and "confirmed current"
297
+ are told apart by whether `latest` is `null`.
298
+
299
+ The check itself is **lightweight, disableable, and non-blocking**: it asks the npm registry for one
300
+ number and sends nothing about your machine, and it never makes a tool call wait. It's skipped
301
+ entirely with `AGENT_IN_CHROME_NO_UPDATE_NOTIFIER=1` or in any CI environment.
302
+
303
+ ### Upgrading
304
+
305
+ **Local components (MCP server + native host):**
306
+
307
+ ```bash
308
+ npx @liang-hz/agent-in-chrome@latest update
309
+ ```
310
+
311
+ It queries npm for the latest version; if you're already current it does nothing. Otherwise it
312
+ fetches and runs that version's installer **pinned to the exact version number**, then verifies what
313
+ actually landed. It passes through `--yes`, `--agents=claude-code,codex`, and `--no-agents`, same as
314
+ `install`. Offline, it just says it couldn't check — it does not fail.
315
+
316
+ **The Chrome extension** ships through a separate channel and `update` does not touch it:
317
+
318
+ - **Loaded unpacked (everyone, today)**: after upgrading the local components, go to
319
+ `chrome://extensions` and hit the reload button on the card — `install` / `update` has already
320
+ replaced the copy in `~/.agent-in-chrome/extension`, and reload is what makes Chrome re-read it.
321
+ No Chrome restart, and no need to "Load unpacked" a second time.
322
+ - **Installed from the Web Store** (once the listing is live): the store updates it for you; nothing
323
+ to do. (npm running one or two minors ahead of the store is normal review lag and the extension
324
+ won't nag about it; it only speaks up when the gap is large enough that the update has probably stalled.)
325
+
326
+ When the two sides disagree, `browser_status`'s `versions` field reports it honestly and the agent
327
+ gets a one-time version-mismatch notice — that's not a fault; npm and the store release
328
+ independently.
329
+
330
+ Releases are cut as git tags (`vX.Y.Z`) plus GitHub Releases, which serve as the changelog. To hear
331
+ about updates first, [watch this repo](https://github.com/Liang-HZ/agent-in-chrome)'s releases, or
332
+ follow the npm package.
333
+
334
+ ---
335
+
336
+ ## Known limitations
337
+
338
+ - **`chrome://` URLs, extension pages, and the Web Store can't be touched** — Chrome forbids attaching a debugger to them.
339
+ - **A debug notification bar sits at the top of a held page** and can't be hidden (Chrome's security design). It disappears after `browser_tab_release`.
340
+ - **Cross-origin iframes under a CSS transform** (rotate/scale/skew) can't have their coordinates computed, so elements inside them can't be clicked; `read_page` marks them `coords: "未知"` ("unknown" — the field is emitted in Chinese). Work around it by opening that URL directly with `browser_new_tab`.
341
+ - **No performance / a11y / SEO audit scores** — `npx lighthouse <url> --view` is one command away and carries Chrome's own scoring; in extension mode we drive your everyday Chrome, which has no debugging port, so building our own would only produce a worse Lighthouse. **Division of labour**: scores come from `npx lighthouse`; we cover what it can't reach — pages behind a login, the screen that only appears after you open some panel, and the headers and bodies of one specific request.
342
+ - **There is no dedicated drag tool** — drag sliders, drag-and-drop reordering, and canvas gestures are done with `browser_batch` chaining a series of `browser_cdp` `Input.dispatchMouseEvent` calls (recipe in [skills/agent-in-chrome/references/actions-and-waits.md](skills/agent-in-chrome/references/actions-and-waits.md#拖拽--滑块没有-drag-工具), under "拖拽 / 滑块"). Synthesizing events via `eval` dispatches `isTrusted: false`, which real captchas reject.
343
+ - **Platforms**: macOS is fully tested. **Windows extension mode is supported** (registry + named pipes + a `.bat` launcher; the bridge's first line of defense becomes the token rather than directory permissions — see the `bridgeEndpoint` comment in `mcp/token.mjs`). Windows CLI/headless mode (`AGENT_IN_CHROME_LAUNCH=1`) is not yet supported. The Linux path is written but unverified. PRs welcome.
344
+
345
+ ---
346
+
347
+ ## Security and transparency
348
+
349
+ This tool holds **complete control of your logged-in browser**, so transparency is a design goal, not an afterthought.
350
+
351
+ **What it does to protect you:**
352
+
353
+ - **It takes over no tab by default** — that requires an explicit `browser_tab_use`, which itself refuses to commandeer tabs you already had open.
354
+ - **Connection token**: install generates a random token on your machine (`~/.agent-in-chrome/`, mode `0600`), and the control socket verifies it. Together with directory permissions (`0700`) it keeps out **other users** and **stray connections**; the token is never committed, never uploaded, and unique per machine. **An honest caveat**: any process running as you — a malicious npm package you installed, say — can read that token file, and no token stops it. Nothing running locally can; that's the operating system's user-isolation boundary, not ours.
355
+ - **Irreversible actions ask first**: sending a message, placing an order, deleting something, changing account settings — the skill requires the agent to spell out what it's about to do and wait for your consent.
356
+ - **Page content is data, never instructions** (prompt-injection defense). If a page says "ignore your previous instructions", the agent quotes it back to you instead of complying.
357
+ - **Credentials never leak**: the values in password fields, credit card numbers, CVVs, and SMS codes never appear in `browser_read_page` or `browser_find` results — only "filled (N chars)". The audit trail records only the length of typed text. `Cookie`, `Authorization`, and token headers are always redacted.
358
+ - **You can see it happening**: Chrome's own "is being debugged" banner can't be suppressed (that's Chrome's design, and we like it); agent tabs sit in a colored, named tab group; the extension popup refreshes every 1.5 s with every tab every session holds.
359
+
360
+ **Where it reads and writes on your machine** (the installer and the extension's "properties" page both print exact paths):
361
+
362
+ - The install directory `~/.agent-in-chrome/`: a copy of the runtime, the connection token, logs, audit traces (`traces/`), screenshots (`screenshots/`, most recent 100 kept), exported cookies (`cookies/`, mode `0700`), both skill directories (`skills/`; the `agent-in-chrome` one includes `references/`) and both commands (`commands/`).
363
+ - One host manifest in each browser's `NativeMessagingHosts/` directory.
364
+ - Read-only access to each Chrome profile's `Preferences`, to detect whether the extension is installed.
365
+ - A dedicated Chrome profile in CLI mode.
366
+ - **Outbound network: none.** Apart from localhost, the product itself sends data to no server. What the agent visits is entirely determined by your instructions.
367
+
368
+ **On bot detection**: CLI mode uses your real Chrome, clears headless markers, and doesn't set `navigator.webdriver` — the goal is **fidelity** (it *is* your browser, acting for you), not impersonating someone else. Please stay within the terms of service of the sites you visit.
369
+
370
+ Full privacy details in [PRIVACY.md](PRIVACY.md).
371
+
372
+ ---
373
+
374
+ ## About this repository
375
+
376
+ This is the **release mirror**. Day-to-day development happens in a private repository; the public
377
+ tree carries the product, the docs, and the tests. The website (`site/` and its Cloudflare
378
+ Functions) is not here — it deploys from the private repository.
379
+
380
+ - **Comments**: the code keeps its explanatory comments — what a piece does, what the parameters
381
+ mean, where the boundaries are. What is not published is the other half: why this choice over
382
+ that one, how a particular trap was discovered, what the measurements were.
383
+ - **Tests**: two layers. **The layer that needs no browser ships with the repository** — `npm test`
384
+ runs on a clean clone, and that is what CI runs (the badge above). The layer that drives a real
385
+ Chrome stays on the maintainer's side: end-to-end runs against the real extension, the concurrency
386
+ suites, and the interop checks against the various MCP SDKs all depend on a locally installed
387
+ extension and a signed-in browser, so they would not reproduce the same conclusions elsewhere.
388
+
389
+ So every commit you see here is a complete, working product you can verify yourself — you just
390
+ don't see how it was arrived at.
391
+
392
+ The dead ends and the trade-offs get written up as articles on
393
+ [liangai.org](https://liangai.org) instead. Turning the process into something readable is worth
394
+ more than checking half-finished notes into a repo.
395
+
396
+ ---
397
+
398
+ ## Contributing
399
+
400
+ Architecture, engineering conventions, and the test layering are documented in [CONTRIBUTING.md](CONTRIBUTING.md). The core invariant: **one tool layer (`extension/sw.js`), two transports (native messaging / direct CDP), and exactly one place in the whole project that branches on which.**
401
+
402
+ ```bash
403
+ npm test # every unit and integration test that doesn't need a browser; runs on a clean clone
404
+ ```
405
+
406
+ Issues are welcome any time: bugs, platform differences, a client it won't install into — those are
407
+ exactly what I want to hear about. For a PR, please open an issue first and say what you intend to
408
+ change. The public and private trees have to be kept in sync, and a large unannounced PR is one I
409
+ probably can't merge.
410
+
411
+ ---
412
+
413
+ ## License
414
+
415
+ [Apache License 2.0](./LICENSE) © 2026 Liang · [liangai.org](https://liangai.org)
416
+
417
+ ---
418
+
419
+ **中文:** 完整文档见 **[README.md](./README.md)**。