# Stagehand v4 把狀態管理與 CDP dispatch 移入瀏覽器，遠端 browser agent 速度達 Playwright 1.59 倍

> 📖 本站完整內容索引（documentation index）：[llms.txt](/llms.txt)

> 原作者：Stagehand (@Stagehanddev) · 策展與摘要：EasyVibeCoding · 平台：X (Twitter) · 熱度：🔥🔥 · 日期：2026-08-12

> 原始來源：https://x.com/Stagehanddev/status/2086849338089857082

## 證據與延伸閱讀

- [Stagehand v4 把狀態管理與 CDP dispatch 移入瀏覽器，遠端 browser agent 速度達 Playwright 1.59 倍](https://browserbase.run/v4b) — 官方文件
- [Paul Klein IV 形容 v4 任務為 Destroy Playwright](https://x.com/pk_iv/status/2086867025050349839)
- [與 Vercel Mastra 等生態系合作](https://github.com/browserbase/stagehand/tree/main/packages/integrations/vercel-ai#readme)
- [Stagehand repository](https://github.com/browserbase/stagehand) — 官方 Repository

## 中文摘要

Stagehand v4 把狀態管理與 CDP dispatch 移入瀏覽器，遠端 browser agent 速度達 Playwright 1.59 倍。

<video src="https://pub-75d4fe1e4e80421b9ecb1245a7ae0d1a.r2.dev/curated/1786477082912-k1ixzf1f.mp4" poster="https://pub-75d4fe1e4e80421b9ecb1245a7ae0d1a.r2.dev/curated/c82f7bcdd54eafba.jpg" controls playsinline preload="metadata" style="max-width:100%;height:auto;display:block;margin:1rem 0"></video>
> Paul Klein介紹 Stagehand v4 的完整 SDK，展現將 browser agent 整合至雲端與擴充功能的架構。

**核心發布** Stagehand 團隊在 2026 年 8 月 11 日介紹 Stagehand v4，定位為專為 browser agent 打造的 SDK。團隊認為 Playwright 主要是為測試而設計，因此 Stagehand v4 改以 Agent 操作網頁的需求為中心，加入更完善的 context 管理、self-healing actions，以及 iframe 支援。Paul Klein IV 更以「Destroy Playwright」形容 v4 的任務；團隊也宣稱，若目前的 Agent 透過 Playwright MCP 操作瀏覽器，改用 Stagehand v4 可獲得成長為兩倍的效能。

![](https://pub-75d4fe1e4e80421b9ecb1245a7ae0d1a.r2.dev/curated/748734bc77c59372.jpg)
> Stagehand 的宣傳主視覺，背景為網格紋理，左上角印有綠色 S 方塊 logo 與 Stagehand 字樣，中央綠框內醒目標示「The SDK for browser agents」，下方左右並列兩個數值區塊，分別為左側強調比 playwright 快 2 倍的「2x」與右側強調節省 80% token 效率的「80%」。

**瀏覽器內執行** v4 的關鍵改動，是把 target management、狀態管理、frame 與 execution context 追蹤，以及 CDP dispatch 搬進瀏覽器內的 extension。Stagehand 會以 service worker 貼近頁面執行，讓遠端瀏覽器更接近使用者電腦上的本機 Chrome，而不是由遠端 SDK 維護一份可能過時的瀏覽器狀態。

- SDK 透過一條 CDP 連線與瀏覽器內的 service worker 溝通，service worker 再使用另一條連線操作瀏覽器。
- 原本需要跨網路傳送的多個 CDP 呼叫，v4 可在瀏覽器內完成，降低 round trip time，也減少 CDP race conditions。
- Stagehand 的生命週期與瀏覽器綁定；瀏覽器關閉時，Stagehand runtime 也會一併結束。
- Browserbase 的瀏覽器預先安裝 Stagehand；使用本機 Chromium 時，Stagehand 則透過 `Extensions.loadUnpacked` 載入 extension。

![](https://pub-75d4fe1e4e80421b9ecb1245a7ae0d1a.r2.dev/curated/2a1536fa24db8287.jpg)
> 示意圖說明 your code 透過綠色箭頭連線至顯示為「the page」標籤頁的瀏覽器視窗，右側標示為 browser extension 並帶有綠色圖示。

**速度與 token 效率** Stagehand 團隊貼文稱，v4 的執行速度成長為 Playwright 的兩倍，token 使用效率約高 80%。引用的發布文章則提供一組 50 個動作的 Wikipedia crawl 測量：Stagehand batch 花費 14,221.7ms，Playwright 花費 22,650.3ms，兩者都完成 50 個動作，速度分別為每秒 3.52 與 2.21 個動作，差距為 1.59 倍。團隊提醒，這只是單一路徑、單一客戶端的一次測量，不應視為完整 benchmark。

![](https://pub-75d4fe1e4e80421b9ecb1245a7ae0d1a.r2.dev/curated/e7e49340094d199c.jpg)
> Stagehand 執行速度比 Playwright 快上數倍，在各項操作的耗時（Wall-clock time）皆顯著更低。

較能反映各動作差異的數據包括：

- `waitForSelector`：493.2ms 降至 237.6ms。
- `click`：628.1ms 降至 323.1ms。
- `goBack`：139.5ms 降至 17.5ms。

在該次測量中，客戶端到遠端瀏覽器的 round trip 為 42.2ms，因此省下網路往返後，即使增加部分本機處理成本，整體仍可能更快；若瀏覽器就在使用者電腦上，改善幅度則會比較有限。

**功能與介面變化** v4 刻意讓介面接近 v3，降低既有專案的遷移成本，但仍調整了幾個核心行為：

- 先透過 `localBrowser` 或 `browserbase` 啟動或連線瀏覽器，再呼叫 `Stagehand.create({ browser })`。
- `Pages()`、`activePage()` 與 `url()` 改為非同步讀取，回傳 promise，因為資料直接來自瀏覽器。
- `serverCache` 改名為 `cache`，可設定 threshold，且 v4 不再使用客戶端快取。
- 每次呼叫都回傳詳細 metadata，包括 usage、快取狀態、未命中原因、產生決策的 threshold 與 count，以及節省的 token 數量。
- 自訂 model 只需實作 `model: { generate(params) }`。
- `agent()`、`deepLocator()`、`frameLocator()` 與原本的 selector 概念整合為單一 `Locator`。

v4 也改善跨來源 iframe、巢狀 iframe、Shadow DOM（包含 closed roots）與真實剪貼簿互動，並支援 WebMCP，讓提供工具給 Agent 的網頁能直接被操作。domain policy 則從 v3 的事後處理，改成在瀏覽器請求離開前執行；被封鎖的彈出視窗會直接顯示 blocked page，而不是先開啟再關閉。

![](https://pub-75d4fe1e4e80421b9ecb1245a7ae0d1a.r2.dev/curated/2f3b8ed5a3030da2.png)
> 白色圓角矩形框內放置了兩個圖示，左側為綠色正方形內含白色字母「S」，右側為黑色三角形，兩者之間以一個藍色細線構成的加號相連，整體背景帶有淡藍色的格線與十字標記，左下角與右上角各有一個微小的彩色方塊。

**安全性與限制** 把 raw CDP 命令放進瀏覽器是 v4 速度提升的來源，也帶來新的安全風險。若 Agent 讀取到攻擊者控制的文字，prompt injection 可能在指令觸及網路時轉化為資料外洩。因此 Stagehand 將 domain policy 放到請求層，在目的地尚未發出請求前就封鎖，而不是收到回應後才篩選。團隊也承認，v4 尚未消除所有 client-side state，只是集中處理大部分狀態；另外，兩個 CDP 客戶端同時操作同一瀏覽器時，仍可能互相影響導覽、分頁、cookie 或請求攔截。

![](https://pub-75d4fe1e4e80421b9ecb1245a7ae0d1a.r2.dev/curated/eba5be248e919254.png)
> 圓角矩形容器內並排顯示兩個圖示，左側為綠底白色 S 字母標誌，右側為黑底白色曲線連線圖示，兩者之間以一個加號相連，背景為帶有網格線的淺色畫面。

**生態系整合** Stagehand 團隊與 Vercel、Mastra、CrewAI、LangChain 合作，提供 browser agent 範本與指南：

- Vercel 的 Eve framework 可結合檔案系統、沙盒與完整 remote browser，快速部署能操作網路的 Agent。
- Mastra 整合 TypeScript browser agent、詳細 trace，以及 Mastra 與 Browserbase dashboard 的可觀測性。
- LangChain DeepAgents 可建立長時間執行、能使用網際網路的 Agent，並搭配 logs、traces 與 browser session replay 改善流程。
- CrewAI 可用 Python 建立 multi-agent crews，透過 StagehandTool 執行導覽、點擊、填寫表單與資料擷取。

![](https://pub-75d4fe1e4e80421b9ecb1245a7ae0d1a.r2.dev/curated/d43397b6fd3215cf.png)
> 圓角矩形框線內的簡約視覺圖，中央偏左為綠色背景的正方形內有白色英文字母 S，中間為一個藍色加號，右側為一個由淺藍色幾何扇形組成的鳥類剪影標誌。

CrewAI 整合文件列出的安裝指令是：

```bash
pip install stagehand-py crewai crewai-tools
```

![](https://pub-75d4fe1e4e80421b9ecb1245a7ae0d1a.r2.dev/curated/7c83c792f8f132cd.png)
> 呈橢圓形外框的白色背景版面上，左側為帶有白色大寫字母 S 的綠色正方形圖示，中央為一個藍色的加號，右側則是一個深褐色的大寫字母 C 的圓弧字體圖示。

整體而言，Stagehand v4 的核心主張不是單純增加瀏覽器自動化 API，而是把 Agent 需要的狀態與命令執行位置移到瀏覽器旁，藉此處理遠端執行常見的延遲、狀態不同步與彈出視窗政策漏洞；同時以共同核心支援 TypeScript、Python 與 Go SDK，並透過 Vercel、Mastra、LangChain DeepAgents 與 CrewAI 擴大 browser agent 的實作管道。

## 媒體內容

**Paul Klein介紹 Stagehand v4 的完整 SDK，展現將 browser agent 整合至雲端與擴充功能的架構。**

**逐字稿**

- `00:00` 嗨，我是 Paul Klein IV，今天我們要推出 Stagehand IV，（Hi, I'm Paul Klein IV, and today we're launching Stagehand IV,）
- `00:03` Stagehand 的第四個版本，（the fourth version of Stagehand,）
- `00:05` 這是一套完整的 SDK，能讓任何瀏覽器 Agent 將網路作業自動化。（the complete SDK to enable any browser agent to automate the web.）
- `00:08` 瀏覽器 Agent 一直以來在本機執行時，都比在遠端瀏覽器上有更好的效能。（Browser agents have always been more performing locally than on remote browsers.）
- `00:12` 如今，我們看到大多數開發工作都移到雲端，（Today, we're seeing most of the development move into the cloud,）
- `00:14` 所以我們重新打造 Stagehand，讓它以擴充功能的形式直接運作在瀏覽器裡。（so we rebuilt Stagehand to live in the browser as an extension.）
- `00:18` 當你在 Browserbase 上執行它時，它能匹敵本機開發的速度，（When you run it on Browserbase, it matches the speed of local development,）
- `00:21` 卻不必承擔所有的安全風險。（but without all of the security risks.）
- `00:23` 而且最棒的是，它可以無限擴展。（And the best part, it's infinitely scalable.）
- `00:26` 在 V4 中，Stagehand 的執行環境位於瀏覽器內部。（In V4, Stagehand's runtime lives inside the browser.）
- `00:29` 這代表用戶端與瀏覽器之間的往返次數更少、競態條件更少，（This means less client-to-browser round trips, fewer race conditions,）
- `00:32` 執行動作也更快。（and faster actions.）
- `00:34` 我們也補上了其他框架存在的功能缺口，（We've also closed feature gaps that exist in other frameworks,）
- `00:36` 例如複製貼上支援、網域政策設定，以及一流的 WebMCP 支援。（like copy-paste support, domain policy setting, and first-class WebMCP support.）
- `00:41` 數據不會說謊。（The numbers don't lie.）
- `00:42` 我們將 Stagehand 與 Playwright 進行基準測試，發現 V4 在準確度和速度上都勝出，（We benchmarked Stagehand against Playwright and found that V4 outperformed in both accuracy and speed,）
- `00:47` 整體而言也更有效率。（holistically being more efficient.）
- `00:49` 在動態網路上，Playwright 會失效，但 Stagehand 能自我修復。（On the dynamic web, Playwright breaks, but Stagehand self-heals.）
- `00:53` 所以即使網站有所變動，你的 Agent 仍然能持續勝出。（So even when websites change, your agent stays winning.）
- `00:58` 現在，Browserbase 上的 Stagehand 工作階段具備更完善的可觀測性，（Stagehand sessions on Browserbase now ship with better observability,）
- `01:00` 支援完整的 OTEL、token 指標和動作快取，（with full OTEL support, token metrics, and action caching,）
- `01:04` 另外還有模型路由器，能以最低成本提供最高準確度。（plus a model router that gives you the highest accuracy with the lowest cost.）
- `01:08` 我們聽取了大家的回饋，親手重新設計每個 SDK，（We've listened to your feedback and redesigned each SDK by hand,）
- `01:11` 更加專注於你們喜愛的程式語言。（doubling down on the languages you guys love.）
- `01:14` TypeScript、Python 和 Go。（TypeScript, Python, and Go.）
- `01:16` 現在每個 Browserbase 瀏覽器都會預先安裝 Stagehand v4。（Every Browserbase browser now ships with Stagehand v4 pre-installed.）
- `01:19` 而從今天開始，（And starting today,）
- `01:20` 你終於可以為你的 Agent 提供存取整個網路所需的工具。（you can finally give your agents the tools they need to access the whole web.）
- `01:23` 你會打造什麼？（What will you build?）

**Stagehand 執行速度比 Playwright 快上數倍，在各項操作的耗時（Wall-clock time）皆顯著更低。**

**數據表**

|   | stagehand | playwright |
| --- | --- | --- |
| batch | 4.7s | 9.0s |
| click | 97ms | 364ms |
| type | 291ms | 1.5s |

## 標籤

開源專案, 框架更新, Agent, Vercel, LangChain
