User Agents

Web browsers and everyday web tech, explained

Give Claude Code Real Browser Access: Setup Guide

· 5 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

This guide shows you how to give Claude Code (Anthropic's CLI coding agent) access to a real browser so it can navigate pages, click elements, fill forms, and read live web content. This is useful for testing your own web apps, scraping data you're allowed to access, or automating repetitive browser tasks. You'll need a working Claude Code installation and Node.js (version 18 or later) on your machine.

What You'll Need

  • Claude Code installed and authenticated (run claude in your terminal to verify).
  • Node.js version 18 or newer (check with node -v).
  • A Chromium-based browser (Chrome, Edge, or Chromium) or Firefox installed.
  • Basic familiarity with your terminal and command-line tools.

Step-by-Step

  1. Install Playwright MCP Server
    Open your terminal and run:
    npm install -g @playwright/mcp
    This installs the Playwright Model Context Protocol (MCP) server, which acts as a bridge between Claude Code and a real browser.
  2. Add the MCP Server to Claude Code
    In your project directory, run:
    claude mcp add playwright -- npx @playwright/mcp@latest
    This registers the server with Claude Code. If you want it available globally, add --scope user to the command.
  3. Verify the Server is Connected
    Start Claude Code with claude. Then type:
    mcp
    You should see playwright listed as a connected server. If not, check the Common Mistakes section below.
  4. Launch a Browser Session
    In Claude Code, ask: "Open a browser and go to example.com". Claude will use the Playwright MCP tools to launch a browser window. You can also specify a browser type by saying "use Firefox" or "use Chromium".
  5. Give Commands for Browser Actions
    Once the browser is open, you can instruct Claude to:
    • Click on a specific element (e.g., "Click the button with text 'Sign up'")
    • Fill in forms (e.g., "Type 'test@example.com' into the email field")
    • Navigate to different URLs (e.g., "Go to /pricing")
    • Extract text or take screenshots (e.g., "Take a screenshot of the current page")
    • Check console logs or network requests (e.g., "Show me any console errors")
    Claude will execute these actions and report back what it sees.
  6. Close the Browser When Done
    When finished, tell Claude to "close the browser" or "stop the browser session". This frees up system resources and prevents stray browser windows.
  7. Use Headless Mode (Optional)
    If you don't need to see the browser window, you can ask Claude to run in headless mode: "Use headless mode" or "Run without a visible window". This is faster and useful for automated testing.

Common Mistakes

  • Not installing the MCP server globally – If you get an error like "command not found: playwright-mcp", make sure you ran the npm install with -g flag.
  • Forgetting to restart Claude Code – After adding the MCP server, you must restart Claude Code for it to pick up the new configuration.
  • Using an outdated Node.js – Playwright MCP requires Node 18+. Check your version and upgrade if needed.
  • Asking for actions Claude can't do – Claude can only interact with the browser through the MCP tools. It can't, for example, read your local files or bypass authentication. Keep requests within browser actions.
  • Not specifying a browser – By default, Playwright uses Chromium. If you prefer Firefox or Edge, you must explicitly say so. Otherwise, it will launch the default.

Tips

  • Use explicit selectors – When asking Claude to click or fill, mention visible text or CSS selectors. For example, "Click the element with id='submit'" works better than "Click the button".
  • Combine with file operations – You can ask Claude to read a local HTML file and then open it in the browser to test it. This is great for front-end development.
  • Take screenshots for debugging – If something looks wrong, ask Claude to take a screenshot and describe what it sees. This helps catch visual issues.
  • Use headless mode for CI/CD – In automated pipelines, headless mode avoids pop-ups and is more reliable.
  • Keep browser sessions short – Long-running sessions can accumulate memory. Close the browser when you're done.

Troubleshooting

  • MCP server not connecting – Run claude mcp list to see if the server is registered. If not, re-run the add command. Also check that npx is available and that your npm global bin directory is in your PATH.
  • Browser doesn't launch – Ensure you have a compatible browser installed. Playwright can auto-download browsers, but you may need to run npx playwright install chromium to fetch the required binaries.
  • Permission errors – If Claude can't access certain pages (e.g., login-protected), it will report an error. You'll need to manually log in or provide credentials via environment variables, but never share passwords in the chat.
  • Slow performance – If the browser is sluggish, try closing other tabs or using headless mode. Also ensure your system meets minimum requirements.
  • Claude says "no browser tool found" – This usually means the MCP server isn't loaded. Restart Claude Code and check mcp command again.

Frequently Asked Questions

Can I use a browser I already have open?

No. Claude Code launches its own browser instance via Playwright. It cannot attach to an existing browser session.

Does this work with Safari?

No. Playwright supports Chromium, Firefox, and WebKit (Safari's engine), but the MCP server defaults to Chromium. You can specify WebKit, but it's less stable.

Can Claude Code click on elements inside iframes?

Yes, but you need to be specific. Ask Claude to "switch to the iframe with name 'foo'" first, then interact with elements inside.

Is there a way to record a session for later replay?

Yes. You can ask Claude to "record a video of the session" or "save a trace zip". Playwright supports tracing, and Claude can enable it via the MCP tools.

Can I use this to scrape data from any website?

You can scrape data from sites you have permission to access. Respect robots.txt, terms of service, and copyright laws. Avoid scraping personal or sensitive data.

How do I remove the MCP server later?

Run claude mcp remove playwright to unregister it. You can also uninstall the npm package globally with npm uninstall -g @playwright/mcp.