agent-browser與playwright-mcp對比:AI瀏覽器自動化選型核心差異解析

為什么選 agent-browser 而不是 playwright-mcp
直接上手的差異
你寫一個 AI Agent,要操作瀏覽器——比如填表、點按鈕、抓數據。playwright-mcp 和 agent-browser 都能做,但體驗完全不同。
playwright-mcp 是把 Playwright 的能力“套殼”進 MCP 協議:它暴露的是底層瀏覽器操作(click, fill, wait_for_selector),返回的 JSON 帶大量元信息(如 DOM 樹快照、事件監聽器列表、樣式計算結果)。這些對調試瀏覽器本身有用,但對 AI Agent 來說,90% 是噪音。
agent-browser 反過來:它不暴露瀏覽器細節,只暴露語義動作和結構化結果。比如你讓 Agent “提交登錄表單”,它返回:
{
"success": true,
"redirect_url": "https://app.example.com/dashboard",
"extracted": {
"username": "alice",
"last_login": "2024-05-20T08:32:11Z"
}
}沒有 CSS 選擇器路徑,沒有 frame 層級,沒有未渲染的 shadow DOM 節點。只有你真正需要的數據。
關鍵維度對比
| 特性 | playwright-mcp | agent-browser |
|---|---|---|
| 輸出格式 | 龐大 JSON,含 DOM 快照、樣式、事件等 | 精簡語義化 JSON,只含動作結果與提取字段 |
| 元素定位 | 手寫 CSS/XPath,需反復 inspect 元素 | 自然語言描述 + 自動匹配(如 “右上角頭像圖標”) |
| 協議設計 | Playwright 命令直映射,MCP 封裝層薄 | 原生 MCP Action/Tool 定義,無冗余抽象 |
| 會話管理 | 每次調用新建 BrowserContext,狀態不保留 | 支持跨請求會話上下文(cookies、localStorage、history) |
| 性能 | 啟動 Chromium 實例約 1.2s,內存常駐 300MB+ | 復用進程,冷啟動 < 200ms,常駐內存 < 80MB |
| 移動端/云支持 | 需手動配置 viewport、userAgent、touch 事件 | 內置 mobile preset,自動適配 viewport 和手勢模擬 |
| 流式響應 | 僅支持 polling,延遲高且易丟幀 | WebSocket 原生流式輸出(如頁面加載中實時吐文本塊) |
具體場景怎么體現
1. 構建客服 Agent
用 playwright-mcp 實現“查看用戶訂單歷史”:
- 先
goto訂單頁 wait_for_selector等加載完成query_selector_all找所有.order-item- 對每個 item
inner_text()提取內容 - 手動解析日期、金額、狀態字段
- 最后拼成 JSON 返回
用 agent-browser:
{
"tool": "browser.extract",
"input": {
"url": "https://shop.example.com/orders",
"schema": {
"orders": [
{
"id": "text in .order-id",
"date": "text in .order-date",
"status": "text in .order-status"
}
]
}
}
}它自動處理等待、重試、字段提取、類型轉換(如把 "May 20, 2024" 轉成 ISO 時間)。
2. 電商比價工具
你需要在 5 個網站抓同款商品價格。playwright-mcp 要為每個站點寫獨立的 selector 邏輯,維護 5 套 XPath;agent-browser 只需統一 schema:
{
"price": "number in [data-testid='price'] or .price or .current-price"
}它內置 selector fallback 鏈和容錯重試,失敗時返回 {"price": null, "error": "timeout"},而不是拋出異常或卡死。
3. 調試真實發生什么
playwright-mcp 報錯常見于:
TimeoutError: waiting for get_by_test_id("submit-btn") failedError: Element is not attached to the DOM
你得開 DevTools,切到 Elements 面板,手動驗證 selector 是否還有效。
agent-browser 報錯帶上下文:
{
"error": "element_not_found",
"hint": "Button '提交' not visible; found 2 elements matching 'submit' but both are disabled",
"screenshot": "data:image/png;base64,..."
}截圖直接嵌在響應里,不用切窗口。
怎么開始
安裝:
pip install agent-browser啟動服務:
agent-browser --port 8000發送一個請求(curl 或 Python requests):
curl -X POST http://localhost:8000/v1/tools/browser.navigate \ -H "Content-Type: application/json" \ -d '{"url": "https://example.com", "wait_for": "text in h1"}'- 查看文檔:agent-browser.readthedocs.io —— 重點看
browser.extract和browser.interact的 schema 定義。
不需要改現有 MCP client,只要把 tool call 的 name 和 input 按 agent-browser 規范發過去就行。