Branchwell

Become a Pro / website · becomeapro.ai / content / lessons / knowledge-work / using-ai / playwright-mcp-claude-code.mdx

1---
2title: "Let Claude Code drive a browser with Playwright MCP"
3description: "Connect Microsoft's Playwright MCP server to Claude Code with one command, then have Claude open pages, fill in forms and test your web app in a real browser."
4level: Beginner
5minutes: 10
6updated: 2026-12-03
7order: 6
8sources:
9 - https://github.com/microsoft/playwright-mcp
10 - https://code.claude.com/docs/en/quickstart
11 - https://github.com/microsoft/playwright-cli
12 - https://code.claude.com/docs/en/mcp
13 - https://code.claude.com/docs/en/permissions
14 - https://code.claude.com/docs/en/permission-modes
15---
16
17Playwright MCP is a free MCP server from Microsoft that gives an AI agent a real browser. Once it's connected, Claude Code can open pages, click, type and take screenshots, which turns it into a computer-use agent for anything on the web.
18
19It doesn't work from screenshots. It hands Claude the page's accessibility tree, a text list of every button, link and field with its label, so Claude picks elements by name instead of guessing pixel positions. That makes it fast, and it works with any Claude model.
20
21<Diagram caption="Claude never sees pixels here. It reads a labeled list of the page and acts on items by reference.">
22 <svg viewBox="0 0 600 220" role="img" aria-label="Claude Code sends a request to Playwright MCP, which drives a browser and sends back the page's accessibility tree">
23 <rect x="20" y="70" width="150" height="70" rx="10" fill="none" stroke="currentColor" strokeWidth="2" />
24 <text x="95" y="111" fontSize="16" textAnchor="middle" fill="currentColor">Claude Code</text>
25 <rect x="225" y="70" width="150" height="70" rx="10" className="soft" stroke="currentColor" strokeWidth="2" />
26 <text x="300" y="111" fontSize="16" textAnchor="middle" fill="currentColor">Playwright MCP</text>
27 <rect x="430" y="70" width="150" height="70" rx="10" fill="none" stroke="currentColor" strokeWidth="2" />
28 <text x="505" y="111" fontSize="16" textAnchor="middle" fill="currentColor">Browser</text>
29 <line x1="170" y1="92" x2="223" y2="92" stroke="currentColor" strokeWidth="2" />
30 <line x1="375" y1="92" x2="428" y2="92" stroke="currentColor" strokeWidth="2" />
31 <line x1="225" y1="120" x2="172" y2="120" stroke="currentColor" strokeWidth="2" strokeDasharray="6 5" />
32 <line x1="428" y1="120" x2="377" y2="120" stroke="currentColor" strokeWidth="2" strokeDasharray="6 5" />
33 <text x="300" y="45" fontSize="15" textAnchor="middle" fill="currentColor">click "Sign up", type into "Email"</text>
34 <text x="300" y="180" fontSize="15" textAnchor="middle" fill="currentColor">back comes the page as a list of buttons, links and fields</text>
35 </svg>
36</Diagram>
37
38## What you need
39
40- Claude Code, installed and signed in
41- Node.js 20 or newer (check with `node --version`)
42- A project folder to run Claude Code in
43
44## Connect Playwright MCP
45
46<Steps>
47 <Step title="Add the server">
48 In a terminal, inside your project folder, run the command from Playwright MCP's README:
49
50 ```bash
51 claude mcp add playwright npx @playwright/mcp@latest
52 ```
53
54 This adds the server in local scope: it loads only in this project and isn't shared through git. Add `--scope user` after `add` to have it in every project.
55 </Step>
56 <Step title="Check that it's connected">
57 Run `claude mcp list` in the terminal, or type `/mcp` inside a Claude Code session. The `playwright` server should show as connected.
58 </Step>
59 <Step title="Give Claude a first task">
60 Start Claude Code with `claude` and try:
61
62 ```text
63 Use the Playwright browser to open https://example.com. Tell me the page title and list every link on the page.
64 ```
65
66 A browser window opens and Claude works through it. In Manual mode, Claude Code asks for your permission the first time it uses each browser tool. New terminal sessions start in auto mode, where a separate model reviews each action instead and blocks risky ones.
67 </Step>
68</Steps>
69
70## What Claude can do with it
71
72Playwright MCP exposes the browser as a set of tools. The ones you'll see most:
73
74| Tool | What it does |
75| --- | --- |
76| `browser_navigate` | Opens a URL |
77| `browser_snapshot` | Reads the page's accessibility tree, the structured view Claude acts on |
78| `browser_click` | Clicks an element |
79| `browser_type` | Types into a field |
80| `browser_fill_form` | Fills several fields at once |
81| `browser_take_screenshot` | Saves a screenshot of the page |
82| `browser_tabs` | Lists, opens and switches tabs |
83
84You don't call these yourself. Describe the task in plain words and Claude picks the tools.
85
86## Test your own web app
87
88This is where it earns its keep. Start your app's dev server, then ask Claude to use it like a new visitor would:
89
90```text
91My app is running at http://localhost:3000. Use the Playwright browser to sign up with
92test+1@example.com, create a first project, and log out. Take a screenshot after each step,
93and tell me anything that looks broken, slow or confusing.
94```
95
96Because Claude Code can also read and edit your code, it can follow up on what it finds: trace a broken button to the component, fix it, and run the same check in the browser again.
97
98## Change how the browser runs
99
100Options go after the package name. Put `--` before the server command so Claude Code passes the flags to Playwright MCP instead of reading them itself. To change an existing server, remove it and add it again:
101
102```bash
103claude mcp remove playwright
104claude mcp add playwright -- npx @playwright/mcp@latest --isolated --headless
105```
106
107Useful options from the README:
108
109| Option | Effect |
110| --- | --- |
111| `--isolated` | Keeps the browser profile in memory, so every session starts clean |
112| `--headless` | Runs without a visible window (the default is a visible browser) |
113| `--browser <name>` | Picks the browser: `chrome`, `firefox`, `webkit` or `msedge` |
114| `--device "iPhone 15"` | Emulates a phone, to check your mobile layout |
115| `--viewport-size 1280x720` | Sets the window size |
116| `--caps vision` | Adds tools that work from screenshots and coordinates |
117
118By default, Playwright MCP keeps a persistent browser profile for each project, so anything you sign in to stays signed in next time. On macOS it lives under `~/Library/Caches/ms-playwright/`. Use `--isolated` if you'd rather start fresh every time.
119
120## Skip the prompts for safe tools
121
122In Manual mode, Claude Code asks before each new browser tool. Once you're comfortable, allow the read-only ones in your project's `.claude/settings.json` and keep clicks and typing on ask:
123
124```json
125{
126 "permissions": {
127 "allow": [
128 "mcp__playwright__browser_navigate",
129 "mcp__playwright__browser_snapshot",
130 "mcp__playwright__browser_take_screenshot"
131 ]
132 }
133}
134```
135
136`mcp__playwright__*` (or just `mcp__playwright`) would allow every tool from the server at once. Only use that on a browser profile with nothing in it you care about.
137
138## Stay safe
139
140<Callout type="warning">
141Playwright MCP's own README says it is not a security boundary. The browser can do anything a person at the keyboard could, on any site you send it to.
142</Callout>
143
144- Use `--isolated` or a profile that isn't signed in to your email, bank or password manager.
145- Keep Claude asking before it clicks or types on sites where an action is hard to undo.
146- Pages can contain text written to steer AI agents. Send it only to sites you trust, and read what it plans to do before approving.
147
148[What computer-use agents can do, and how to run them safely](/knowledge-work/using-ai/what-is-computer-use) covers these guardrails in more depth.
149
150## A lighter option for coding work
151
152Microsoft also makes Playwright CLI, a command-line version meant for coding agents, installed with:
153
154```bash
155npm install -g @playwright/cli@latest
156```
157
158The Playwright MCP README now recommends the CLI for most coding agents. CLI commands use fewer tokens, because the agent doesn't load every tool and the full page tree into its context. MCP still fits long, exploratory sessions where the agent needs to keep the browser open and reason over the page structure step by step. If you mostly check your own app while coding, start with the CLI and keep MCP for deeper browser work.