如何用 CDP 把 Cursor 连接到真实浏览器——Clawbrowser 文章封面插图

如何用 CDP 把 Cursor 连接到真实浏览器

Clawbrowser TeamAI-agentcdpcursor教程

Cursor 内置的 browser tool 用来调试本地应用很方便:打开页面、点击、输入、截图都可以。但它本质上是隔离 webview。到了真实网站,问题就来了:cookie 不够持久,fingerprint 不受管理,也没有和代理位置一致的 browser identity。

结论先行: 通过 CDP(Chrome DevTools Protocol)把 Cursor 连接到 Clawbrowser。agent 使用真实 Chromium、持久 profile、托管 fingerprint 和 proxy routing。安装 runtime,启动 profile,把本地 endpoint 交给 Cursor 即可。


为什么 Cursor 内置浏览器不够用

Cursor 的 browser tool 基于 sandboxed webview,并作为 MCP server extension 运行。对 localhost 来说够用:navigate、click、type、scroll、screenshot、console output、network traffic。

一旦碰到真实网站,限制很明显:

限制 会发生什么
Sandboxed webview 不是真正的 Chromium instance。网站能看到缺失 API 和非标准 window properties。
没有 session persistence Cookies 和 localStorage 绑定 workspace,跨运行不稳定。
没有 fingerprint management canvas hash、WebGL renderer、navigator properties 每次都很像。
没有 proxy support traffic 从机器默认 IP 出去。datacenter IP 很快被打标。
稳定性问题 Cursor 2.3.18+ 出现过 click、scroll、element 查找 regression。

如果 agent 需要登录、抓取 Cloudflare 后面的数据,或在 production site 上执行多步 workflow,内置 webview 不是合适的浏览器层。


CDP 能给你什么

CDP(Chrome DevTools Protocol)是用代码控制 Chromium browser 的标准接口。Playwright 使用 connectOverCDP,Puppeteer 使用 puppeteer.connect,原生 CDP client 通过 WebSocket 连接 debugging port。

把 Cursor 通过 CDP 连接到外部 browser 后,你得到:

  • 真实浏览器:完整 rendering engine、extension 和标准 API
  • 持久 session:cookies 和 login state 能跨 agent 运行保留
  • 完整页面控制:使用 Playwright 和 Puppeteer 内部同一套 protocol
  • Anti-detection:browser 把 fingerprint 和 proxy identity 保持一致

连接只是标准 WebSocket URL。任何会说 CDP 的工具,都可以连接到暴露 CDP endpoint 的 browser。Clawbrowser 为每个 profile 暴露 endpoint。


连接 Cursor 到 Clawbrowser:分步操作

前置条件

  • macOS(Apple Silicon)、Linux(x64 或 arm64)或 Windows
  • 已安装 Cursor
  • 来自 app.clawbrowser.ai 的 Clawbrowser API key

第 1 步:安装 Clawbrowser

下载并解压 clawctl bootstrapper:

# macOS (Apple Silicon)
archive="clawctl-macos-arm64.tar.gz"
curl -fL --retry 3 -o "$archive" \
  "https://github.com/clawbrowser/clawctl/releases/latest/download/${archive}"
tar -xzf "$archive"

Linux 使用 clawctl-linux-amd64.tar.gz 或 clawctl-linux-arm64.tar.gz。不需要 Docker 或 sudo。

设置 API key:

./clawctl config set api-key

第 2 步:启动浏览器 profile

用命名 profile 启动 Clawbrowser。每个 profile 都有自己的 fingerprint、cookie storage 和可选 proxy:

# Start a profile and open the verification page
clawctl start --profile cursor-dev --url clawbrowser://verify/ --json

# Get the CDP endpoint for this profile
clawctl endpoint --profile cursor-dev --json

endpoint 命令会返回类似 http://127.0.0.1:9222 的 URL。这就是 Cursor agent 要连接的 CDP endpoint。

第 3 步:从 Cursor 通过 MCP 连接

最简单的集成方式是 Clawbrowser 内置 MCP server。它把 navigation、screenshots、clicks、tab management、profile startup 暴露成 Cursor 可直接调用的 MCP tools。CDP 连接由 server 内部管理。

运行 installer 写入本地 MCP 配置:

clawctl install --agent all --json

Cursor 会从配置中加载这个 MCP server。

替代方案:Microsoft Playwright MCP

如果你更想用 Microsoft 官方 Playwright MCP server,在 Cursor Settings > MCP > Add Server 中指向 Clawbrowser CDP endpoint:

{
  "mcpServers": {
    "playwright": {
      "command": "npx",
      "args": [

两种方式都能给 Cursor 高层 browser 控制能力。Clawbrowser MCP server 额外提供 profile 和 fingerprint 管理。

第 4 步:验证连接

让 Cursor agent 打开测试页面:

Navigate to https://browserleaks.com/canvas and take a screenshot. Tell me what canvas fingerprint hash you see.

如果连接成功,你会看到 Clawbrowser profile 的真实 canvas fingerprint,而不是 sandboxed webview 的通用 hash。


从代码直接连接 CDP

如果 Cursor agent 写脚本并执行,而不是调用 MCP tools,可以直接用 Playwright 或 Puppeteer:

Playwright (Python)

from playwright.async_api import async_playwright

async def browse_with_clawbrowser():
    async with async_playwright() as p:
        # Connect to Clawbrowser's CDP endpoint

Playwright (Node.js)

const { chromium } = require('playwright');

const browser = await chromium.connectOverCDP('http://127.0.0.1:9222');
const page = browser.contexts()[0].pages()[0];

Puppeteer

const puppeteer = require('puppeteer');

const browser = await puppeteer.connect({
  browserURL: 'http://127.0.0.1:9222'
});

三个 framework 都连接同一个 CDP endpoint。Clawbrowser 在底层处理 identity layer:Canvas、WebGL、AudioContext、fonts、screen resolution、timezone、navigator properties、proxy routing 在 profile 内保持一致。


为什么 Cursor agent 需要 anti-detection

Cursor agent 用标准 browser 访问 web 时,anti-bot 系统会从多个 surface 检查 browser identity:

信号 检查内容 Standard Chrome Clawbrowser
Canvas hash GPU rendering fingerprint Static, matches known automation profiles Unique per profile, consistent with reported GPU
WebGL renderer Graphics card identifier Exposes real hardware Matches the profile's simulated hardware
Navigator properties Browser version, platform, language Generic Chromium values Consistent with profile's OS and locale
Timezone System timezone vs IP geo Mismatches with proxy location Auto-aligned with proxy geography
CDP detection Runtime.enable traces Detectable via leaked CDP artifacts Engine-level patches suppress CDP signals

普通 Chromium 通过 CDP 控制时,会留下 anti-bot script 很快能读到的痕迹。Clawbrowser 在 engine level 修补这些信号,而不是依赖容易被 descriptors 或 prototype chains 识破的 JavaScript overrides。

这就是连接 chrome --remote-debugging-port=9222 和连接 Clawbrowser 的区别:前者像自动化环境,后者保持一致的 browser identity。


管理多个 profile

每个 Clawbrowser profile 都是隔离的。你可以同时运行多个 profile,用于不同账号或项目:

# Create three profiles with different locations
clawctl create --profile account-a --location sweden --json
clawctl create --profile account-b --location germany --json
clawctl create --profile account-c --location japan --json

每个 profile 都有独立 fingerprint、自己的 proxy IP 和隔离 storage。平台看到的是来自不同国家、不同机器的独立用户。

Cursor agent 可以连接不同 CDP endpoint 来切换 profile,也可以从一个 script 并行管理多个 profile。


Cursor built-in browser vs CDP vs Clawbrowser

Cursor built-in Chrome via CDP Clawbrowser via CDP
Browser engine Sandboxed webview Real Chromium Real Chromium (patched)
Session persistence Workspace-scoped Manual profile dirs Named profiles with auto-persistence
Fingerprint management None None 20+ surfaces managed per profile
Proxy support None Manual flag Profile-bound, geo-aligned
Anti-bot survival Blocked instantly Blocked within minutes Passes Cloudflare, DataDome, PerimeterX
Multi-account Not possible Separate --user-data-dir Built-in profile isolation
Setup complexity Zero (built in) Moderate Three commands

内置 browser 适合检查 localhost。只要 agent 接触真实 web,就用 Clawbrowser via CDP。


FAQ

这能和 Cursor agent mode 一起用吗?

可以。Cursor agent mode 可以使用任何 MCP server,包括通过 CDP 连接外部 browser 的 server。action 会在 Clawbrowser 中执行,而不是 sandboxed webview。

需要安装 Playwright 或 Puppeteer 吗?

只有 agent 编写并运行 automation script 时才需要。MCP workflow 中,server 会在内部管理 CDP 连接。

Cursor 项目之间能复用 login session 吗?

可以。Clawbrowser profile 会保留 cookies、localStorage 和 IndexedDB。登录一次,之后在其他 workspace 复用同一个 profile。

Cursor browser tool 和外部 browser 混在一起怎么办?

可以在 Settings > Features > Browser 里关闭内置 browser。也可以让两者共存,因为它们互相独立。

Clawbrowser 免费吗?

是的。Clawbrowser 免费、open source、MIT-licensed。没有 seat fee、usage limit 或 browser runtime subscription。安装验证需要 app.clawbrowser.ai 的 API key。


开始使用

三条命令把 Cursor agent 连接到真实 browser:

# Install Clawbrowser
clawctl install --json

# Set your API key
clawctl config set api-key

把 MCP server 或 Playwright script 指向返回的 endpoint。Cursor agent 会通过带有 managed fingerprints、persistent sessions、proxy routing 的 browser 访问 web。

更多 CDP 背景见 AI Agents 开发者指南的 CDP 浏览器。fingerprinting 见 浏览器指纹:20 个自动化信号。

继续阅读

查看全部 →