Skip to main content
Glama
ma-browser
by zzhan111
README.md
<div align="center">

# MultiAgentsBrowser

### `ma-browser` — your browser as the API, shared safely by many AI agents

**Your browser is the API. No keys. No bots. No scrapers.**

[![Node.js](https://img.shields.io/badge/Node.js-18+-339933?logo=node.js&logoColor=white)](https://nodejs.org)
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)

[English](README.md) · [中文](README.zh-CN.md)

</div>

---

You're already logged into Twitter, Reddit, YouTube, Zhihu, Bilibili, LinkedIn, GitHub — ma-browser lets AI agents **use that directly**.

```bash
ma-browser site twitter/search "AI agent"       # search tweets
ma-browser site zhihu/hot                        # trending on Zhihu
ma-browser site arxiv/search "transformer"       # search papers
ma-browser site eastmoney/stock "茅台"            # real-time stock quote
ma-browser site boss/search "AI engineer"        # search jobs
ma-browser site wikipedia/summary "Python"       # Wikipedia summary
ma-browser site youtube/transcript VIDEO_ID      # full transcript
ma-browser site stackoverflow/search "async"     # search SO questions
```

**103 commands across 36 platforms.** All using your real browser's login state. [Full list →](https://github.com/epiral/bb-sites)

## The idea

The internet was built for browsers. AI agents have been trying to access it through APIs — but 99% of websites don't offer one.

ma-browser flips this: **instead of forcing websites to provide machine interfaces, let machines use the human interface directly.** The adapter runs `eval` inside your browser tab, calls `fetch()` with your cookies, or invokes the page's own webpack modules. The website thinks it's you. Because it **is** you.

| | Playwright / Selenium | Scraping libs | ma-browser |
|---|---|---|---|
| Browser | Headless, isolated | No browser | Your real Chrome |
| Login state | None, must re-login | Cookie extraction | Already there |
| Anti-bot | Detected easily | Cat-and-mouse | Invisible — it IS the user |
| Complex auth | Can't replicate | Reverse engineer | Page handles it itself |

## Quick Start

### Install

```bash
npm install -g ma-browser
```

### Use

```bash
ma-browser site update        # pull community adapters
ma-browser site recommend     # see which adapters match your browsing habits
ma-browser site zhihu/hot     # go
```

### Windows headless tray

After building from source, run this from the repository directory:

```powershell
Start-Process powershell.exe -WindowStyle Hidden -ArgumentList @('-NoProfile', '-STA', '-ExecutionPolicy', 'Bypass', '-File', "`"$PWD\scripts\windows-tray.ps1`"")
```

The tray starts and monitors the daemon, launching new managed browsers in headless mode (zero-restart background stealth on Windows) with the dedicated profile. Left-click the tray icon for one-click instant pop-up: it immediately switches from headless to headed if needed and brings the managed browser window to the foreground without any confirmation dialog or browser restart; failures appear as balloon tips. Right-click the tray icon to switch between headed (show window) and headless (hide window) modes; the selected mode persists across sign-ins, and switching preserves all open tabs, in-page state, and short tab IDs. Use headed mode to sign in or pass interactive verification, then switch back to headless seamlessly. The menu also opens logs or exits the tray while leaving the daemon running. Outside the tray, set `MA_BROWSER_HEADLESS=1` to launch a managed browser headlessly.

Right-click → **发现并接管已有 Chrome** lists every debuggable browser on the machine (checked = already attached); click one to attach it, or **全部接管** to attach them all. Failures show as a balloon with the reason.

Agents can call `ma-browser mode status|headed|headless [--focus] --json` or the MCP `browser_mode` tool with the same `mode` values. Status is read-only; switching is handled directly inside the live daemon without restarting it, so open tabs, leases, and existing short tab IDs remain valid.

To verify the left-click flow by hand: with the tray in headless mode, start `.\scripts\check-windows-tray.ps1 -Mode headed -ExpectForeground -DelaySeconds 10`, then left-click the tray icon once; the window pops up immediately and the check passes once it is in the foreground. Cover the window with another app and repeat with `-DelaySeconds 10`.

To start the tray at Windows sign-in, run this from the repository directory:

```powershell
$trayScript = (Resolve-Path .\scripts\windows-tray.ps1).Path
$command = "powershell.exe -NoProfile -STA -ExecutionPolicy Bypass -WindowStyle Hidden -File `"$trayScript`""
Set-ItemProperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Run' -Name 'ma-browser-tray' -Value $command
```

### MCP (Claude Code / Cursor)

```json
{
  "mcpServers": {
    "ma-browser": {
      "command": "npx",
      "args": ["-y", "ma-browser", "--mcp"]
    }
  }
}
```

## 36 platforms, 103 commands

Community-driven via [bb-sites](https://github.com/epiral/bb-sites). One JS file per command.

| Category | Platforms | Commands |
|----------|-----------|----------|
| **Search** | Google, Baidu, Bing, DuckDuckGo, Sogou WeChat | search |
| **Social** | Twitter/X, Reddit, Weibo, Xiaohongshu, Jike, LinkedIn, Hupu | search, feed, thread, user, notifications, hot |
| **News** | BBC, Reuters, 36kr, Toutiao, Eastmoney | headlines, search, newsflash, hot |
| **Dev** | GitHub, StackOverflow, HackerNews, CSDN, cnblogs, V2EX, Dev.to, npm, PyPI, arXiv | search, issues, repo, top, thread, package |
| **Video** | YouTube, Bilibili | search, video, transcript, popular, comments, feed |
| **Entertainment** | Douban, IMDb, Genius, Qidian | movie, search, top250 |
| **Finance** | Xueqiu, Eastmoney, Yahoo Finance | stock, hot stocks, feed, watchlist, search |
| **Jobs** | BOSS Zhipin, LinkedIn | search, detail, profile |
| **Knowledge** | Wikipedia, Zhihu, Open Library | search, summary, hot, question |
| **Shopping** | SMZDM | search deals |
| **Tools** | Youdao, GSMArena, Product Hunt, Ctrip | translate, phone specs, trending products |

## 10 minutes to add any website

```bash
ma-browser guide    # full tutorial
```

Tell your AI agent: *"turn XX website into a CLI"*. It reads the guide, reverse-engineers the API with `network --with-body`, writes the adapter, tests it, and submits a PR. All autonomously.

Three tiers of adapter complexity:

| Tier | Auth method | Example | Time |
|------|-------------|---------|------|
| **1** | Cookie (fetch directly) | Reddit, GitHub, V2EX | ~1 min |
| **2** | Bearer + CSRF token | Twitter, Zhihu | ~3 min |
| **3** | Webpack injection / Pinia store | Twitter search, Xiaohongshu | ~10 min |

We tested this: **20 AI agents ran in parallel, each independently reverse-engineered a website and produced a working adapter.** The marginal cost of adding a new website to the agent-accessible internet is approaching zero.

## What this means for AI agents

Without ma-browser, an AI agent's world is: **files + terminal + a few APIs with keys.**

With ma-browser: **files + terminal + the entire internet.**

An agent can now, in under a minute:

```bash
# Cross-platform research on any topic
ma-browser site arxiv/search "retrieval augmented generation"
ma-browser site twitter/search "RAG"
ma-browser site github search rag-framework
ma-browser site stackoverflow/search "RAG implementation"
ma-browser site zhihu/search "RAG"
ma-browser site 36kr/newsflash
```

Six platforms, six dimensions, structured JSON. Faster and broader than any human researcher.

## Also a full browser automation tool

```bash
ma-browser open https://example.com
ma-browser snapshot -i                # accessibility tree
ma-browser click @3                   # click element
ma-browser fill @5 "hello"            # fill input
ma-browser upload @6 "C:\Users\me\a.pdf" # set files on <input type=file> (ref or CSS selector)
ma-browser eval "document.title"      # run JS
ma-browser fetch URL --json           # authenticated fetch
ma-browser network requests --with-body --json  # capture traffic
ma-browser screenshot                 # take screenshot
```

`upload` uses CDP `DOM.setFileInputFiles` and fires input/change; target the file input's ref, its label/wrapper, or a selector such as `"input[type=file]"` for hidden inputs. Paths may be relative or absolute (including Windows `C:\...`); multiple files need a `multiple` input, and an `accept` mismatch is rejected unless `--force`. Custom upload widgets often read the file on change and clear the input, so `uploadedFiles` can be empty while the page UI shows the file — check with `snapshot`.

All commands support `--json` output, `--jq <expr>` for inline filtering, and `--tab <id>` for concurrent multi-tab operations.

```bash
ma-browser site xueqiu/hot-stock 5 --jq '.items[] | {name, changePercent}'
# {"name":"云天化","changePercent":"2.08%"}
# {"name":"东芯股份","changePercent":"-7.60%"}

ma-browser site info xueqiu/stock   # view adapter args, example, domain
```

## Use your own Chrome, or several at once

ma-browser drives browsers that expose a remote-debugging port. Start your everyday Chrome (or a sandbox one) with a port and its own profile directory — Chrome 136+ refuses remote debugging on the default profile:

```bash
google-chrome --remote-debugging-port=9222 --user-data-dir="$HOME/.chrome-debug"
```

```bash
ma-browser cdp list                    # every debuggable browser here: id, browser, profile, tabs, managed, attached
ma-browser cdp attach 9222             # take it over — never relaunched, never closed
ma-browser cdp attach --all            # attach everything found, driven in parallel
ma-browser tab list                    # each tab shows its browser (@9222)
ma-browser tab list --browser 9222     # just that browser's tabs
ma-browser open https://x.com --browser 9222   # new tab in that browser
ma-browser status                      # connection + health per browser
ma-browser cdp detach 9222             # stop driving it (the browser keeps running)
```

Tab IDs are unique across browsers, so `--tab <id>` always reaches the right one. Without `--tab`, `--browser` picks the browser; otherwise a command goes to your current tab's browser, then the default. MCP has the same as `browser_cdp_list` / `browser_cdp_attach` / `browser_cdp_detach` and a `browser` argument on `browser_open`, `browser_tab_new`, `browser_tab_list` and `site_run`.

**Which browser a cold start uses** (CLI and daemon share one policy): `BB_BROWSER_CDP_URL[S]` / `--port` → the running managed browser → any other debuggable browser found on this machine → launch the managed browser. ma-browser launches its own browser only when nothing debuggable is running. Scanning only covers loopback: ports 9222, 9229 and 19825–19865 (odd), plus `--remote-debugging-port` in running browser command lines and `DevToolsActivePort` files. If an attached browser drops, its tabs fail with a readable error and it reconnects in the background.

| Variable | Effect |
|---|---|
| `BB_BROWSER_CDP_URLS=http://127.0.0.1:9222,http://127.0.0.1:9333` | Explicit endpoints: the first reachable one is the default, the rest are attached at startup |
| `BB_CDP_DISCOVERY=0` / `all` | Turn off scanning / also attach every browser found at startup (default `1`: scan, attach one) |
| `BB_CDP_SCAN_PORTS=9300,9400-9410` | Extra ports to scan |
| `BB_CDP_ALLOW_REMOTE=1` | Allow `cdp attach` to a non-loopback host (or pass `--allow-remote`). Anyone who can reach that port controls that browser |

## Daemon configuration

The daemon binds to `127.0.0.1:19824` by default. You can customize the host with `--host`:

```bash
ma-browser daemon --host 127.0.0.1    # IPv4 only (fix macOS IPv6 issues)
ma-browser daemon --host 0.0.0.0      # listen on all interfaces (for Tailscale / ZeroTier remote access)
```

### Command timeouts and health

Each action has its own budget: 30 s by default, 60 s for `screenshot` / `eval` / `snapshot` / `open` / `refresh` / `back` / `forward` / `site update`, 120 s for `site run`, and `wait <ms>` + 5 s. The caller's environment wins (the CLI/MCP sends its budget with each command):

```bash
BB_COMMAND_TIMEOUT_SCREENSHOT_MS=120000 ma-browser screenshot   # one action
BB_COMMAND_TIMEOUT_MS=90000 ma-browser eval "..."                # floor for every action
```

A timed-out command returns an error tagged with where it stalled: `[cdp]` (the browser never answered a CDP call, with the method), `[dispatch]` (daemon-side work, e.g. queued behind an earlier stuck command on the same tab), `[queue]` (no free command slot) or `[cdp_connect]` (the browser never connected). If the daemon sends no response at all, the client probes `/status` to tell a stuck command from an unresponsive daemon.

`ma-browser status` (and `/status` → `health`) reports `ok` / `degraded` / `stalled` / `disconnected`, with the last command/success time, consecutive timeouts, timed-out commands still running, in-flight commands, pending CDP calls, event-loop lag and a recovery hint. A daemon that "can list tabs but can't screenshot" shows up as `degraded`/`stalled` instead of looking healthy.

## Architecture

```
AI Agent (Claude Code, Codex, Cursor, etc.)
       │ CLI or MCP (stdio)
       ▼
ma-browser CLI ──HTTP──▶ Daemon ──CDP WebSocket──▶ Your Real Browser
                           │
                    ┌──────┴──────┐
                    │ Per-tab     │
                    │ event cache │
                    │ (network,   │
                    │  console,   │
                    │  errors)    │
                    └─────────────┘
```

## Credits

MultiAgentsBrowser evolved from [bb-browser](https://github.com/epiral/bb-browser)
by **epiral** (MIT). The full upstream commit history is preserved in this
repository. Community site adapters still live at
[epiral/bb-sites](https://github.com/epiral/bb-sites).

## License

[MIT](LICENSE)