Skip to main content
Glama

How to Use playwright-mcp?

npm version Docs

Introduction

Ever tried using Cursor or Claude to write Playwright tests? Yeah, it's kind of a mess.

Why? Because your AI assistant has no clue what's on your web page. It's like trying to describe a painting to someone who's blindfolded. The result?

  • Flaky tests → The AI is guessing selectors, and it gets them wrong.

  • Broken scripts → You spend more time fixing tests than writing them.

  • Debugging nightmares → The AI can't "see" what's happening, so you end up doing all the heavy lifting.

Wouldn't it be nice if your AI could actually understand your web page instead of just making educated guesses?

Enter playwright-mcp !

playwright-mcp gives your AI assistant superpowers by making the browser fully visible to it. Instead of working in the dark, your AI assistant now has real-time access to the page DOM, elements, and interactions.

How playwright-mcp Works (AKA How We Fix This Mess)

Once installed, playwright-mcp spins up a Playwright-controlled browser and gives your AI assistant full access to it. This unlocks:

  1. Recording interactions → Click, type, scroll—let playwright-mcp turn your actions into fully functional Playwright test cases.

  2. Taking screenshots → Capture elements or full pages so your AI gets actual visual context (no more guessing).

  3. Extracting the DOM → Grab the entire HTML structure so the AI can generate rock-solid selectors.

  4. Executing JavaScript → Run custom JS inside the browser for debugging, automation, or just for fun.

Why You'll Love playwright-mcp

🚀 AI-generated tests that actually work → No more flaky selectors, broken tests, or guesswork.

⏳ Massive time savings → Write and debug Playwright tests 5x faster.

🛠️ Fewer headaches → Your AI assistant gets live page context, so it can generate real test cases.

🔌 Works out of the box → Plug it into Cursor, Claude, WindSurf, or whatever you use—it just works.

Give Your AI the Context It Deserves

Tired of fixing AI-generated tests? Stop debugging AI's bad guesses—start writing flawless Playwright tests. Use the guide below to install playwright-mcp and let your AI assistant actually help you for once.


Installation: Get Up and Running in No Time

Prerequisites (a.k.a. What You Need Before You Start)

Before you install playwright-mcp, make sure you have:

✅ Node.js installed on your system (because, well… it's an npm package)

✅ Playwright and its Chromium browser installed

✅ An IDE that supports MCP, like Cursor

✅ A brain that's ready to automate Playwright tests like a pro

Setting Up playwright-mcp (It's Easy, I Promise)

Connect It to Your IDE (Cursor Setup)

If you're using Cursor, follow these steps to connect playwright-mcp like a boss:

  1. Open Cursor IDE

  2. Navigate to Settings (⚙️)

  3. Select Cursor Settings → Go to the MCP tab

  4. Click "Add new MCP server"

  5. Fill in the following details:

    Connect playwright-mcp to cursor

    • Name → playwright-mcp

    • Command → npx -y playwright-mcp

  6. Click "Add", and boom—you're connected! 🚀

Note: If clicking on "Add new MCP server", opens a file(.cursor/mcp.json), Paste the following code and save:

{
  "mcpServers": {
    "playwright-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "playwright-mcp"
      ]
    }
  }
}

Now Cursor actually understands your web pages. No more random test suggestions based on zero context! Head to the Claude tutorial or Cursor tutorial to understand it in details.


Connect It to Claude desktop

Wait… Does It Work with Other AI Assistants? Yes! While playwright-mcp is a match made in heaven for IDEs, you can use it with Claude desktop to write tests as well.

  1. Install playwright-mcp (The Easy Part)

    1. First things first, fire up your terminal and run:

    2. npm install -g playwright-mcp

  2. Hook It Up to Claude Desktop

    1. Find the Configuration File

    2. On windows

      1. %APPDATA%\Claude\claude_desktop_config.json

    3. On macOS:

      1. ~/Library/Application Support/Claude/claude_desktop_config.json

    4. Update the config file

    {
      "mcpServers": {
        "playwright": {
          "command": "npx",
          "args": ["-y", "playwright-mcp"]
        }
      }
    }
  3. Restart Claude Desktop (Because It's a New Day)

    1. Close and reopen Claude Desktop to apply the changes.

  4. Verify That It's Working

    1. Once everything is set up, let's test if Claude can actually talk to Playwright now.

    2. Open Claude and ask: "List all available MCP tools."

    3. If playwright-mcp is installed correctly, it should list tools like:

      1. init-browser → Initialize browser and navigate to a URL

      2. get-interactive-snapshot → Get focused snapshot of interactive elements (buttons, links, inputs) with annotated screenshot

      3. get-full-snapshot → Get complete page snapshot including all visible content for full context understanding

      4. get-text-snapshot → Extract all text content from the page for reading and content analysis

      5. get-screenshot → Take a simple screenshot of the current page

      6. get-full-dom → Get raw HTML DOM (deprecated - use snapshot tools instead)

      7. execute-code → Run custom Playwright JavaScript code against the page

    4. Ask Claude to init browser and a browser should open up after your approval!

Now that the Calude has access to the web pages. You can ask it write highly contextual tests! Head to the Claude tutorial or Cursor tutorial to understand it in details.

📖 View Documentation

Related MCP server: browser-devtools-mcp

Telemetry

Why we collect it: we are researching how AI browsing agents are used: which tools they call, on what kinds of pages, and from which MCP clients. The data also guides improvements to playwright-mcp. A one-line notice is printed to stderr the first time the server runs, and you can opt out at any time (see below).

What is sent: one event per tool call, named after the tool (init_browser, execute_code, get_screenshot, get_full_dom, get_interactive_snapshot, get_full_snapshot, get_text_snapshot), plus prompt_used (with the prompt's name) when you use one of the server's prompts, and server_start when an MCP client connects. Every event carries:

  • the server version, and the name and version of the MCP client (for example Claude Code or Cursor)

  • a random install ID, created on first run, that groups calls from one install

  • a random session ID, new each time the server starts, and the call's position in that session (seq)

Each tool event also carries:

  • ok: whether the call succeeded, and if not, error_kind: one of no_browser, timeout, navigation, selector, syntax, other. The error message itself is never sent.

  • duration_ms: how long the call took

  • result_chars and result_images: how much text and how many images the tool returned to the agent

  • a description of the page:

    • page_kind: one of public, local, private_ip, ip_literal, file, browser_internal, unparsed

    • page_domain: for public web pages only, the registrable domain (for example example.com or acme.vercel.app), never the full address, subdomain, path or query

    • page_is_dev_host: whether the host name contains a label such as dev, staging, qa or test

init_browser also sends reinit (whether a browser was already open). execute_code also sends the length of the code run (codeLength), how many times it calls each common Playwright method (for example { "click": 2, "fill": 1 }, from a fixed list of method names), and how many console logs and console errors it produced. The code itself is never sent. server_start sends the operating system type (darwin, linux or win32) and the Node.js major version.

Pages on localhost, private IPs, intranet host names or local files send only their type, not an address.

What is anonymised, and what is not: nothing sent identifies you by name, username, hostname, email or IP address. Two fields are not fully anonymous:

  • The install ID and session ID are random and not derived from you or your machine, but they link events from one install, and from one session, together.

  • page_domain names the public website your agent visited. For a company's own site (for example staging.acme.com becomes acme.com), that can show which organisation's site was being worked on.

How it is used: only for research and to improve playwright-mcp. As part of the research, we classify page domains by organisation size, sector and country to understand what kinds of organisations use browsing agents, and report only aggregate counts. It is not used for sales or marketing, and we never contact organisations based on it. Research results are published only in aggregate, with no organisation or install named.

What is never sent: page contents, screenshots, the code your agent runs, error messages, full URLs, your IP address (discarded on receipt, GeoIP disabled), or your username or hostname.

Retention: raw events are kept for 2 years, then deleted. Aggregate reports derived from them, which contain no install IDs or per-install records, may be kept indefinitely.

Deletion requests: email himanshusaleria [at] gmail [dot] com with your install ID, from ~/.config/playwright-mcp/install-id ($XDG_CONFIG_HOME/playwright-mcp/install-id if set, %APPDATA%\playwright-mcp\install-id on Windows).

Opt out: set DO_NOT_TRACK=1 or PLAYWRIGHT_MCP_TELEMETRY=0, or pass --no-telemetry (for example npx -y playwright-mcp --no-telemetry). When opted out, the server creates no telemetry client and sends nothing.

Available Tools

7 tools
execute-codeA

Execute custom Playwright JS code against the current page

Inputs: code (required).

get-full-domA

Get the full DOM of the current page. (Deprecated, use get-context instead)

Inputs: no named parameters.

get-full-snapshotB

Get a complete snapshot of the page including all visible content (text, images, forms, etc.) for understanding the full context

Inputs: no named parameters.

get-interactive-snapshotB

Get a snapshot focused on interactive elements (buttons, links, inputs) with annotated screenshot for UI automation

Inputs: no named parameters.

get-screenshotB

Get a screenshot of the current page

Inputs: no named parameters.

get-text-snapshotB

Get all text content from the page (headings, paragraphs, lists) for reading and content extraction

Inputs: no named parameters.

init-browserC

Initialize a browser with a URL

Inputs: url (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.4/5.0

    Scored across 7 tools

    Disambiguation3/5

    The three snapshot tools overlap somewhat in purpose, though their descriptions distinguish interactive, full, and text use cases. The deprecated get-full-dom tool references a missing get-context tool and also overlaps with the full snapshot, increasing misselection risk.

    Naming Consistency5/5

    All tool names use consistent kebab-case with clear verb-first patterns such as get-*, execute-code, and init-browser. There are no mixed casing or naming conventions.

    Tool Count5/5

    Seven tools is a well-scoped count for a Playwright browser automation server. Each tool broadly earns its place, with only the deprecated get-full-dom being questionable.

    Completeness3/5

    The server covers initialization, page inspection, screenshots, and arbitrary automation via execute-code, but lacks direct navigation, click, type, wait, and cleanup tools. The deprecated get-full-dom reference to a nonexistent get-context is a notable dead end.

    Maintenance

    ActivityNo data
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers