User Agents

Web browsers and everyday web tech, explained

Playwright MCP Setup and Browser Automation Guide

· 4 min read · Browsers

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

The Playwright Model Context Protocol (MCP) server allows an LLM-powered client to interact directly with a web browser. By integrating Playwright via MCP, you enable a system to navigate websites, click elements, extract data, and take screenshots in real-time, effectively giving the agent a functional web browser to perform complex automation tasks that go beyond simple API calls.

What You'll Need

  • Node.js (v18 or higher) installed on your system.
  • npm (comes bundled with Node.js).
  • An MCP-compatible client (such as Claude Desktop or other IDEs supporting the Model Context Protocol).
  • Administrative privileges to modify configuration files on your machine.

Step-by-Step

  1. Install Node.js and npm: Ensure you have the latest LTS version of Node.js installed. Open your terminal or command prompt and run node -v to verify the installation. If not installed, download it from the official Node.js website.
  2. Locate your MCP Configuration File: Depending on your client, the configuration file is usually a JSON file. For Claude Desktop on macOS, it is typically located at ~/Library/Application Support/Claude/claude_desktop_config.json. On Windows, it is usually found at %APPDATA%\Claude\claude_desktop_config.json.
  3. Configure the Playwright MCP Server: Open the configuration file in a text editor. You need to add the Playwright server to the mcpServers object. Add the following configuration block:
    {
      "mcpServers": {
        "playwright": {
          "command": "npx",
          "args": ["-y", "@modelcontextprotocol/server-playwright"]
        }
      }
    }
  4. Install Playwright Browsers: The MCP server uses npx to run, but the underlying Playwright library requires browser binaries (Chromium, Firefox, WebKit) to function. Open your terminal and run npx playwright install to download the necessary browser engines.
  5. Restart the MCP Client: Fully quit your MCP-compatible application (e.g., Claude Desktop) and restart it. This forces the client to read the updated claude_desktop_config.json file and initialize the Playwright server.
  6. Verify the Connection: Once the client restarts, look for the tools icon or check the logs to ensure the Playwright tools (such as playwright_navigate, playwright_click, and playwright_screenshot) are available.
  7. Execute Browser Automation: You can now give the agent natural language commands to automate the browser. For example: "Go to example.com, find the login button, and take a screenshot of the page." The agent will translate this into a sequence of Playwright tool calls.

Common Mistakes

  • Skipping Browser Installation: A common error is configuring the JSON file but forgetting to run npx playwright install. Without the binaries, the server will start, but any attempt to navigate to a URL will result in a "browser not found" error.
  • Incorrect JSON Syntax: Missing commas or mismatched brackets in the claude_desktop_config.json file will prevent the client from loading any MCP servers. Always validate your JSON.
  • Permissions Issues: On some systems, npx may fail due to restricted execution policies. Ensure your terminal has the necessary permissions to execute scripts.
  • Overloading the Agent: Asking the agent to perform 20 steps in one prompt can lead to timeouts or logic errors. Break complex automation workflows into smaller, sequential requests.

Tips

  • Use Screenshots for Debugging: If the agent claims it cannot find an element, ask it to take a screenshot. This allows you to see exactly what the browser sees and identify if a popup or cookie banner is blocking the view.
  • Target Specific Selectors: If you know the CSS selector or ID of an element, provide it to the agent. This reduces the trial-and-error process of the agent searching for the correct button or field.
  • Wait for Load: For heavy websites, explicitly tell the agent to wait a few seconds for the page to fully render before attempting to click a button.
  • Headless vs Headful: By default, MCP servers often run in headless mode (no visible window). If you are developing a complex script, check if your specific MCP implementation allows for headful mode to watch the automation happen in real-time.

Troubleshooting

If the Playwright tools do not appear in your client, first check the client logs. Most MCP clients provide a log file that will specify if the server failed to start due to a path error or a missing dependency. If the log indicates a command not found: npx error, ensure Node.js is added to your system's PATH environment variable.

If the browser opens but fails to interact with elements, check for iframes or shadow DOMs. Playwright can handle these, but the agent may need a specific hint to "look inside the iframe" to find the target element. If the browser crashes, try updating Playwright by running npm install -g playwright and then running the install command again.

Frequently Asked Questions

Does Playwright MCP require a paid subscription?

The Playwright library and the Model Context Protocol are open source. However, the client you use to run the MCP server (like a specific LLM provider) may have its own subscription costs.

Can I use this to bypass CAPTCHAs?

No. Playwright is an automation tool and does not inherently bypass CAPTCHAs or security challenges designed to prevent automated access.

Which browsers are supported?

Playwright supports Chromium (Chrome, Edge), Firefox, and WebKit (Safari). The MCP server typically defaults to Chromium for most automation tasks.

Is it safe to give the agent access to my browser?

The MCP server typically launches a clean, isolated browser instance rather than using your personal browser profile. However, always be cautious about providing the agent with access to sites where you are already logged in with sensitive credentials.

Can I run this on a remote server?

Yes, as long as the remote server has Node.js installed and the necessary system dependencies for the browsers (such as Xvfb for Linux environments to simulate a display).