# AgentDock An original browser automation runtime for AI agents, built directly on the **Chrome DevTools Protocol** — no Playwright, no Puppeteer, zero runtime dependencies. Node.js 22+ and ESM all the way down. AgentDock gives an agent a small, self-describing facade set (`page`, `browser`, `taskSpaces`, `site`, `fetch`, `cdp`, `help`) and a CLI that executes JavaScript straight from stdin against a real Chrome window. It also ships an **MCP server** (`agentdock-mcp`) so Claude Desktop, Cursor, and any Model Context Protocol client can drive a browser with plain tools. ## Why - **Agents need primitives, not frameworks.** CDP is the native control surface of Chrome; AgentDock exposes it with thin, predictable facades. - **Zero runtime dependencies.** WebSocket, fetch, and the test runner all come from Node 22+ itself. Auditable, small, easy to vendor. - **LLM-friendly page model.** `page.snapshot()` returns a compact element list with refs (`e1`, `e2`, …) that locators can act on directly. - **Model Context Protocol built in.** One command (`agentdock-mcp`) serves browser tools to any MCP client — driving your real logged-in browser via the Bridge, or a fresh headless Chrome. Zero extra dependencies. - **Isolated task spaces.** Each agent task gets its own browser context — separate cookies and storage, disposable as a unit. - **Site learning packs.** Durable per-site knowledge (selectors, actions, workflows, pitfalls) as validated plain-JSON files. ## Requirements - **Node.js ≥ 22** (uses the built-in `WebSocket` client and `fetch`) - A Chrome-family browser: Chrome, Chromium, or Edge (auto-detected; or set `AGENTDOCK_CHROME_PATH` / pass `--chrome`) ## Install & build ```sh npm install npm run build # compiles src/ → dist/ (ESM + .d.ts) npm link # optional: puts `agentdock` on your PATH ``` During development you can skip the build and use `tsx`: ```sh npm run dev -- run --file examples/hello.js --headless ``` ## Quickstart Pipe JavaScript on stdin — the script runs as an async body with the agent context in scope: ```sh echo "await page.goto('https://example.com'); return await page.title();" | agentdock --headless # → Example Domain ``` or from a file: ```sh agentdock run --file examples/hello.js --headless ``` Attach to a Chrome you started yourself (`chrome --remote-debugging-port=9222`): ```sh agentdock --connect 9222 -f audit.js ``` First-run demo and a shareable run replay (both offline-capable): ```sh agentdock demo # guided run vs a local demo page → screenshot agentdock run -f task.js --replay run.html # record actions + frames → standalone HTML ``` ## The agent context Every script gets these globals (also exported as a typed API — see [Programmatic use](#programmatic-use)): | Global | Purpose | | ------------ | ------- | | `browser` | version, targets, `newPage()`, browser contexts, `close()` | | `page` | default tab: `goto`, `evaluate`, `click`, `fill`, `type`, `press`, `waitForSelector`, `snapshot`, `screenshot`, `title`, `url`, `content`, events, `close()` | | `taskSpaces` | `create(name)`, `get`, `list`, `dispose(name)`, `disposeAll()` — isolated browser contexts | | `site` | site learning packs: `list`, `get(name)`, `forUrl(url)`, `check(data)`, `validate(data)`, `load(path)`, `reload()` | | `fetch` | plain HTTP from Node: `await fetch(url, { method, headers, body, timeoutMs })` → `{ ok, status, headers, bodyText, json() }` | | `cdp` | raw CDP: `send(method, params)`, `forPage(method, params)`, `on(event, handler)` | | `help` | `help()` or `help('locator')` — full reference, in-script | | `console` | log to stdout | Scripts support top-level `await`; a returned value is printed on completion. ## Snapshots & locators `page.snapshot()` walks the live DOM and returns a compact node list: ```js const snap = await page.snapshot({ maxNodes: 200 }); // { url, title, capturedAt, // nodes: [ { ref: 'e1', role: 'textbox', name: 'Search', selector: 'input[name=q]' }, … ], // text: '…trimmed page text…' } ``` Refs are stored on the page and can be driven directly: ```js await page.locator('e7').click(); ``` Locator syntax: | Form | Meaning | | ----------------------------- | ------- | | `css=button.save` or bare CSS | `document.querySelector` | | `text=Sign in` | substring text match | | `text="Sign in"` | exact text match (quoted) | | `role=button` | ARIA role (inferred when not explicit) | | `role=button[name="Save"]` | role + accessible name | | `e7` / `@e7` | ref from the latest snapshot | Locator methods: `click()` (trusted CDP mouse events), `fill(text)` (native setter + `input`/`change`, framework-friendly), `type(text)` (CDP `Input.insertText`), `press('Enter' | 'Tab' | 'Escape' | 'Backspace')`, `count()`, `isVisible()`, `textContent()`. > Refs live on `window.__agentdock_refs` and are invalidated by navigation — > snapshot again after `goto()`. ## Task spaces ```js const research = await taskSpaces.create('research'); const shopping = await taskSpaces.create('shopping'); const a = await research.newPage('https://example.com'); const b = await shopping.newPage('https://shop.example.com'); // separate cookies await taskSpaces.dispose('research'); // closes pages + context await taskSpaces.disposeAll(); ``` ## Site learning packs Plain JSON files that accumulate durable, per-site knowledge: ```jsonc { "schemaVersion": 1, "name": "shop-example", "urlPatterns": ["https://shop.example.com/*"], "selectors": { "searchBox": "input[name=q]" }, "actions": { "search": { "steps": [ { "goto": "https://shop.example.com/" }, { "fill": { "selector": "input[name=q]", "value": "shoes" } }, { "press": "Enter" }, { "waitFor": "css=.results" }, { "snapshot": true } ] } }, "workflows": { "tour": { "use": ["search"] } }, "pitfalls": ["Results load lazily — wait for .results first."] } ``` Step keys: `goto`, `click`, `fill` (`{selector, value}`), `press`, `waitFor`, `snapshot`, `expectText`. Workflows compose actions by name. Validate packs without launching a browser: ```sh agentdock validate examples/site-packs/example.com.pack.json # OK examples/site-packs/example.com.pack.json — example-com@0.1.0 (1 url pattern(s)) ``` Load packs into the agent context: ```sh agentdock run --site-packs examples/site-packs -f task.js # in-script: site.list(), site.get('example-com'), site.forUrl(await page.url()) ``` ## Chrome Extension — drive YOUR logged-in browser (recommended for agents) Instead of launching a fresh Chrome, install the **AgentDock Bridge** extension once. Any agent (Claude, Hermes, Codex, curl, …) can then drive your real, already-logged-in browser over a tiny local HTTP API — no per-agent setup. ```mermaid flowchart LR A[Agent
Claude · Hermes · Codex] -->|HTTP POST localhost:7734/cmd| B[AgentDock Relay
node dist/relay.js] B <-->|WebSocket| C[AgentDock Bridge
Chrome extension] C -->|chrome.debugger · tabs| D[Your real logged-in tabs] ``` ### One-time setup 1. **Start the relay** — it's a single small Node process on `127.0.0.1:7734`. You never have to start it by hand: see [Who starts the relay?](#who-starts-the-relay--zero-manual-steps) below. 2. **Load the extension** in your everyday Chrome: - Open `chrome://extensions` - Enable **Developer mode** (top-right toggle) - **Load unpacked** → select the [`extension/`](extension/) folder - The AgentDock Bridge icon appears in your toolbar 3. **Connect:** click the AgentDock Bridge icon → **Connect**. The badge turns green (`ON`). That's it — your browser is now agent-drivable, with all your cookies and logins. ### How agents use it Agents send JSON HTTP POSTs to the relay: ``` POST http://127.0.0.1:7734/cmd Content-Type: application/json { "cmd": "goto", "params": { "url": "https://gpvacancy.com.au" } } ``` Available commands: `ping`, `tabs`, `newTab`, `goto`, `activate`, `closeTab`, `snapshot`, `click`, `fill`, `press`, `evaluate`, `screenshot`. Each takes an optional `tabId` in `params` (defaults to the active tab). Selectors use the same locator syntax as the rest of AgentDock (`css=`, `text=`, `role=`, `@e3`). Example: snapshot the active tab, then click a ref — ``` POST /cmd { "cmd": "snapshot" } → { ok: true, result: { nodes: [ { "ref": "e25", "role": "link", … } ] } } POST /cmd { "cmd": "click", "params": { "selector": "e25" } } ``` Check health any time: `GET http://127.0.0.1:7734/status` > Because commands run through `chrome.debugger`, Chrome shows a small > "AgentDock Bridge is debugging this browser" banner while connected — that's > normal and means it's working. Click the extension icon → Disconnect to stop. ### Who starts the relay? (zero manual steps) The relay is only needed in Bridge mode (driving your **own logged-in** browser). Direct mode — AgentDock launching its own Chrome — needs **no relay at all**: `agentdock run -f task.js` is fully self-contained. When you do use Bridge mode, nobody has to type `npm run relay`. Pick any: 1. **Your agent starts it (recommended — zero steps for you).** The whole point is an AI agent drives your browser, and the agent has a shell. [`AGENTS.md`](AGENTS.md) tells agents: *check `GET /status` first — if the relay isn't there, start it yourself and retry.* That single instruction makes the relay invisible. (Start is idempotent: the relay exits cleanly if port 7734 is already taken.) 2. **One-time OS auto-start** (install once, forget — starts at every logon): | OS | File in [`scripts/autostart/`](scripts/autostart/) | | --- | --- | | Windows | `windows/install-autostart.ps1` → registers an at-logon scheduled task running `start-relay-hidden.vbs` (hidden, no console) | | Linux | `linux/agentdock-relay.service` → `systemctl enable --now` | | macOS | `macos/com.agentdock.relay.plist` → `launchctl` (RunAtLoad + KeepAlive) | 3. **By hand** (for a quick try): `npm run relay` or `node dist/relay.js` — one foreground command, Ctrl-C to stop. ## MCP server — browser tools for any MCP client AgentDock doubles as a **Model Context Protocol** server, so Claude Desktop, Cursor, Claude Code, and any other MCP client can drive a browser with plain tools — no glue code, no SDKs (the server is ~700 lines of protocol core + two backends, zero dependencies). ```sh npm i -g agentdock # or: npm link in this repo agentdock-mcp # → MCP server over stdio ``` Register it in your MCP client (e.g. Claude Desktop → `claude_desktop_config.json`): ```json { "mcpServers": { "agentdock": { "command": "agentdock-mcp" } } } ``` **Tools:** `status`, `tabs`, `new_tab`, `goto`, `snapshot`, `click`, `fill`, `type`, `press`, `evaluate`, `screenshot`, `activate_tab`, `close_tab`. `snapshot` returns interactive nodes with refs (`e1`, `e2`, …) plus page text; `click`/`fill` accept `css=`, `text=`, `role=`, or snapshot refs. `screenshot` returns a real image block the client can display. **Two modes** (auto-selected, or force with `AGENTDOCK_MCP_MODE`): | Mode | Browser driven | | ---- | --------------- | | `relay` (default when a Bridge is connected) | **your real logged-in Chrome** — cookies, sessions, extensions, all tabs | | `embedded` (`launch`) | a fresh headless Chrome AgentDock launches and owns | Environment: `AGENTDOCK_MCP_RELAY_URL` (default `http://127.0.0.1:7734`), `AGENTDOCK_MCP_MODE` (`auto` | `relay` | `launch`), `AGENTDOCK_MCP_HEADED=1` for a visible embedded browser. The same server is available as a CLI subcommand (`agentdock mcp`) and programmatically (`McpServer` + `RelayBackend`/`EmbeddedBackend` from the `agentdock` API). ## See it live (observability) Three complementary ways to watch a run: ```sh # 1. Headed browser (the default) — a real Chrome window you can watch: agentdock run -f task.js # 2. Live dashboard — screencast stream + timestamped action feed: agentdock run -f task.js --observe # agentdock: live view → http://127.0.0.1:51723 (open this in any browser) # 3. Stderr trace — every action, timestamped (shows up in agent transcripts): agentdock run -f task.js --verbose --headless # [14:02:11] goto — https://example.com # [14:02:12] navigate — https://example.com/ # [14:02:12] snapshot — 1 interactive node(s) # [14:02:13] click — ref @e1 ``` The dashboard shows the live page as a streaming screenshot alongside the action feed (navigations, clicks, fills, snapshots, crashes). Agents can add their own annotations to the feed with `page.trace('checkpoint', 'logged in')`. Programmatically: ```ts import { Observer } from 'agentdock'; const observer = new Observer(); await observer.attachPage(ctx.page); const live = await observer.serve(0); // 0 = auto port console.log(live.url); ``` ## Raw CDP Anything not wrapped by a facade is one call away: ```js const version = await cdp.send('Browser.getVersion'); await cdp.forPage('Emulation.setDeviceMetricsOverride', { width: 390, height: 844, deviceScaleFactor: 3, mobile: true }); const off = cdp.on('Target.targetCreated', (t) => console.log(t.targetInfo.url)); ``` ## Programmatic use AgentDock is a library too: ```ts import { createAgentContext, Browser, runAgentScript } from 'agentdock'; const ctx = await createAgentContext({ launch: { headless: true } }); try { await ctx.page.goto('https://example.com'); console.log((await ctx.page.snapshot()).nodes); } finally { await ctx.browser.close(); } ``` ## CLI reference ``` agentdock [run] [options] [script.js] Run JS from --file / arg / stdin agentdock validate Validate site learning packs agentdock demo [--headed] [--out png] Offline guided demo + screenshot agentdock mcp MCP server over stdio agentdock help Usage agentdock --version Version --connect Attach: ws:// URL, port ("9222"), or host:port --headless Launch Chrome headless --chrome Chrome executable (or AGENTDOCK_CHROME_PATH) --port Remote debugging port for launched Chrome (default: auto) --site-packs Comma-separated site pack directories --timeout Chrome startup timeout (default 20000) -f, --file Script file (default: stdin) --observe Live dashboard: screencast + action feed (URL on stderr) --observe-port Dashboard port (default: auto) --verbose Timestamped action log on stderr --replay Record the run; write a standalone HTML replay when done --headed demo: visible Chrome window (demo defaults to headless) --out demo: screenshot destination (default ./agentdock-demo.png) --keep-open Leave the browser running after the script ``` ## Architecture ```mermaid flowchart LR A[Agent script
stdin / file] --> B[runtime
runAgentScript] B --> C[facades
page · browser · taskSpaces
site · fetch · cdp · help] C --> D[CDPConnection
sessions · events] D --> E[WebSocketTransport
Node 22 built-in WebSocket] E --> F[Chrome DevTools Protocol] C --> G[snapshot + locators
page-side DOM helpers] G --> D ``` ``` src/ ├── cli.ts CLI entry point (bin: agentdock) ├── index.ts public API barrel ├── demo/demo.ts offline guided demo (agentdock demo) ├── mcp/ MCP server: protocol core, relay + embedded │ backends, CLI (agentdock-mcp / agentdock mcp) ├── cdp/ │ ├── transport.ts WebSocket transport (zero-dep) │ ├── connection.ts session-aware command/event multiplexing │ └── discovery.ts Chrome detection, launching, endpoint polling ├── browser/browser.ts Browser facade: targets, pages, contexts ├── page/ │ ├── page.ts Page facade: navigation, eval, input, snapshot │ ├── locator.ts css/text/role/ref locators, trusted input │ └── domFunctions.ts self-contained page-side helpers (serialized) ├── snapshot/snapshot.ts snapshot collector + expression builder ├── taskspace/taskSpace.ts isolated per-task browser contexts ├── site/ learning pack schema, validation, loading, facade ├── fetch/fetch.ts structured HTTP facade ├── help/help.ts in-script + CLI help └── runtime/ ├── context.ts builds the agent context (all facades) └── runScript.ts executes JS with the context as globals test/ node:test unit tests (no Chrome required) examples/ hello.js + a sample site pack scripts/autostart/ one-time OS auto-start helpers (Windows/Linux/macOS) ``` Page-side helpers in `domFunctions.ts` are deliberately self-contained: they are serialized with `Function.prototype.toString()` and evaluated inside the inspected page. Keep them dependency-free. ## Development ```sh npm run typecheck # strict tsc over src/ and test/ npm run build # emit dist/ (tsconfig.build.json) npm test # node:test via tsx — no Chrome needed npm run dev -- … # run the CLI from source (tsx) ``` The test suite covers locator parsing, site-pack validation/loading, the fetch facade (against a local HTTP server), and the script runner. CDP paths that need a live browser are exercised manually via `examples/hello.js`. ## Publishing to GitHub / npm 1. `git init && git add -A && git commit -m "AgentDock 0.2.0"` 2. Create the repo on GitHub and add the remote. 3. Fill in `repository`, `bugs`, and `homepage` in `package.json`. 4. `npm publish --access public` (the `prepublishOnly` hook builds `dist/`; only `dist/`, `README.md`, and `LICENSE` ship). ## License MIT © 2026 Rakesh Patel. See [LICENSE](LICENSE). AgentDock is an original work and is not affiliated with or endorsed by Google, the Chrome team, Playwright, or Puppeteer. Automate responsibly: respect the terms of service of the sites you drive.