2026 年瀏覽器自動化 AI 倉庫比較:Playwright MCP、Browser Use 與 agent-browser
Best AI repos for browser automation in 2026: Playwright MCP vs Browser Use vs agent-browser
這份指南比較 Playwright MCP、Browser Use 和 agent-browser 三個瀏覽器自動化開源工具,分別適用於由編碼代理操控瀏覽器、以 Python 建立自主瀏覽流程,以及透過短 CLI 命令控制上下文成本。
Letting an AI agent use a browser used to mean screenshots, a vision model and a lot of misclicks. That changed. The open-source tools that lead this space in 2026 read the page as structured data (an accessibility tree with element references), so the model clicks "@e3" instead of guessing pixel coordinates.
There are three repos most people end up choosing between, and they solve different problems:
- Playwright MCP: Microsoft's MCP server, for when your coding agent (Claude Code, Cursor, VS Code, Codex) should drive a real browser.
- Browser Use: a Python library for building an agent that browses on its own, with any LLM.
- agent-browser: a fast Rust CLI from Vercel Labs, for agents that work best through short shell commands.
Below is how to set up each one with real commands from their READMEs, and when to pick which. If you want the full ranked list with more options, including computer-use sandboxes, it lives on our best AI repos for browser automation page.
Quick answer
| You want to... | Use |
|---|---|
| Let Claude Code or Cursor test and click through your web app | Playwright MCP |
| Write a Python script where an agent completes a web task by itself | Browser Use |
| Give a coding agent a browser with the smallest context cost | agent-browser |
1. Playwright MCP: the default for coding agents
Playwright MCP exposes Playwright as MCP tools. The README sums up why it works well with LLMs: it "operates purely on structured data" and needs no vision model, because the agent reads accessibility snapshots instead of screenshots.
Add it to Claude Code with one command:
claude mcp add playwright npx @playwright/mcp@latest
For Codex:
codex mcp add playwright npx "@playwright/mcp@latest"
For VS Code:
code --add-mcp '{"name":"playwright","command":"npx","args":["@playwright/mcp@latest"]}'
Cursor, Windsurf, Claude Desktop and most other clients take the standard JSON block:
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": ["@playwright/mcp@latest"]
}
}
}
Then ask your agent something concrete, like "open localhost:3000, sign up with a test email and tell me which step fails." It will call tools such as browser_snapshot (the README describes it as "better than screenshot") and click by element reference.
A few flags worth knowing, all from the README's options table:
-
--headlessruns without a visible window (it is headed by default). -
--browserpickschrome,firefox,webkitormsedge. -
--caps vision,pdf,devtoolsturns on extra capabilities such as coordinate-based clicks and PDF generation. -
--mobileemulates a phone. The README notes mobile pages are usually lighter, which saves tokens. -
--isolated --storage-state=path/to/storage.jsonstarts each session clean but logged in from a saved state file.
One honest note from Microsoft itself: the README says coding agents may get better token efficiency from Playwright CLI with skills, because a CLI avoids loading large tool schemas and full accessibility trees into context. MCP still wins for long, stateful loops such as exploratory testing or self-healing tests.
2. Browser Use: an agent that browses by itself
Browser Use is different in kind. Instead of your coding agent driving a browser step by step, you write a short Python program, give it a task in plain English, and the library's agent loop does the rest with whatever model you choose.
Install it with uv (the README asks for Python 3.11 or newer; run uv init --python 3.12 first in a new project):
uv add browser-use
Put your model key in .env:
OPENAI_API_KEY=your-key
Then the core of the README's quickstart is this:
import asyncio
from browser_use import Agent, ChatOpenAI
from dotenv import load_dotenv
load_dotenv()
async def main():
agent = Agent(
task="Find the number of stars of the browser-use repo",
llm=ChatOpenAI(model="gpt-5.6-luna"),
)
history = await agent.run()
print(history.final_result())
asyncio.run(main())
Run it:
uv run agent.py
What makes it worth choosing over a hand-written Playwright script:
-
Any model.
ChatOpenAI,ChatBrowserUseand other providers plug in the same way. -
Custom tools. Decorate a Python function with
@tools.action(...)and the agent can call it mid-task. -
Replays. Save a run with
agent.save_history('invoice_run.json'), andagent.detect_variables()finds the form values so you can repeat the same clicks with new inputs later. -
Local or cloud browser. Pass
browser=Browser(use_cloud=True)when you need a hosted browser; the local browser is the default.
There is also a path for coding agents: the README gives a prompt you paste into Claude Code or Codex that installs Browser Use with uv and runs browser-use skill install to register it as a skill.
We keep a step-by-step card for this on our automate a web task with a Python agent page.
3. agent-browser: the lightweight CLI
agent-browser is a native Rust CLI built for agents. Every action is a short shell command, which keeps the model's context small. Install it globally and download Chrome for Testing once:
npm install -g agent-browser
agent-browser install
Homebrew (brew install agent-browser) and Cargo (cargo install agent-browser) work too.
The core loop from the README:
agent-browser open example.com
agent-browser snapshot # accessibility tree with refs
agent-browser click @e2 # click by ref
agent-browser fill @e3 "test@example.com" # fill by ref
agent-browser get text @e1
agent-browser screenshot page.png
agent-browser close
You can also find elements semantically, which is handy when refs change between pages:
agent-browser find role button click --name "Submit"
agent-browser find label "Email" fill "test@test.com"
To make Claude Code use it, install the skill:
npx skills add vercel-labs/agent-browser
The README explains this adds a small stub at .claude/skills/agent-browser/SKILL.md that tells the agent to load current instructions with agent-browser skills get core, so the instructions never go stale between releases. The same command works for Codex, Cursor, Gemini CLI, GitHub Copilot, Goose, OpenCode and Windsurf. If your setup needs MCP instead, agent-browser mcp exposes it as a server.
There is a walkthrough on our let your agent browse with short CLI commands page.
How to choose
- You are building or testing a web app and already live in Claude Code or Cursor: start with Playwright MCP. One command, no code, and Microsoft maintains it.
- Your context window is tight or your agent juggles a big codebase: try agent-browser (or Playwright CLI). Short commands cost far fewer tokens than full MCP tool schemas.
- You want a product feature, not a dev tool, such as an agent that fills forms or pulls data on a schedule: Browser Use, because it is a library you call from your own code.
They also combine. A common setup is Playwright MCP for interactive debugging and Browser Use in production scripts.
Safety notes before you let an agent loose
- Use a separate browser profile or
--isolatedsessions so the agent never touches your personal logins. - Keep saved storage-state files out of git; they hold session cookies.
- Prefer headed mode while you build trust, so you can watch what the agent clicks.
Get one email every Monday with the week's hottest AI repos and exactly how to use them: subscribe free at dedupedai.com
來源:DEV Community · dev.to