Skip to content

Browser Automation: Puppeteer & Playwright

For web developers, the ability to test and interact with a live application is critical. The Puppeteer and Playwright MCP servers provide this capability directly to your AI assistant, effectively giving it a fully controllable web browser.

This integration unlocks powerful workflows for end-to-end (E2E) testing, visual verification, and interactive debugging, allowing you to build and validate web UIs at an incredible pace.

Puppeteer (Chromium-focused) and Playwright (cross-browser) are two leading browser automation libraries. Their respective MCP servers expose their core functionalities to your AI assistant.

Automated E2E Testing

The core use case. You can describe a user journey in plain English, and the AI will use the MCP server to execute it. It can navigate pages, fill in forms, click buttons, and assert that the application behaves as expected, all driven by your natural language prompts.

Visual Verification with Screenshots

“Does it look right?” One of the most powerful features is the ability to take screenshots. The AI can render a component or page and capture an image of it. This allows for automated visual regression testing and provides you with instant, visual confirmation that your UI is correct.


Scenario 1: Writing and Running an E2E Test

Section titled “Scenario 1: Writing and Running an E2E Test”

Let’s say you’ve just built a new contact form and you want to ensure it works.

  1. Describe the Test in Plain English. You give a high-level instruction to your AI assistant.

    Please write and run an end-to-end test for our new contact form.
    - Navigate to the `/contact` page.
    - Fill in the name and email fields with test data.
    - Click the "Submit" button.
    - Verify that a "Thank You" message appears on the screen.
  2. AI Executes the Test. The AI will translate your instructions into a series of tool calls to the Puppeteer or Playwright MCP server.

    • browser_navigate(url: '/contact')
    • browser_fill(selector: '#name', text: 'Test User')
    • browser_fill(selector: '#email', text: 'test@example.com')
    • browser_click(selector: '#submit')
  3. AI Verifies the Outcome. The AI will then check for the success condition. It might do this by scraping the page content or, even better, by taking a screenshot.

    • browser_screenshot()

    The resulting screenshot will appear directly in your chat, giving you immediate visual confirmation that the test passed and the UI looks correct.

A user reports that the “Login” button is not working on mobile screen sizes.

  1. Prompt the AI to Reproduce the Bug.

    Let's debug a UI issue. Using the Playwright server, open the `/login` page with a mobile viewport (375x667). Then, try to click the "Login" button and report what happens. Take a screenshot.
  2. AI Investigates. The AI will launch the browser with the specified viewport, attempt the action, and analyze the result. It might find that the button is being covered by another element or that a CSS rule is hiding it.

  3. AI Proposes a Fix. Based on its findings, the AI will propose a CSS or HTML change to fix the issue. Because it has the context from the live browser environment, its proposed fix is much more likely to be accurate.

By integrating browser automation into your workflow, you create a powerful feedback loop. Your AI assistant can not only write the code but also see, interact with, and verify the result, just as a human developer would—only much, much faster.

Beyond local browser automation, Cloudflare offers a powerful Browser Rendering MCP Server that runs in the cloud:

Cloudflare Browser Rendering

Server URL: https://browser.mcp.cloudflare.com/sse

Key Features:

  • Fetch and convert web pages to markdown
  • Take screenshots from any URL
  • No local browser installation required
  • Runs on Cloudflare’s edge network
  • Perfect for documentation and content extraction
// AI can extract structured content from any website
"Using Cloudflare browser MCP, fetch the pricing page from
competitor.com and convert it to markdown for analysis"
// The MCP server will:
// 1. Navigate to the URL
// 2. Render the page fully (including JS)
// 3. Convert to clean markdown
// 4. Return structured content
  1. Set up multi-browser testing

    "Test the checkout flow in Chrome, Firefox, and Safari:
    - Add item to cart
    - Proceed to checkout
    - Fill payment details
    - Verify order confirmation
    Take screenshots at each step for all browsers"
  2. AI generates comprehensive test suite

    • Creates browser-specific test cases
    • Handles browser quirks automatically
    • Captures visual differences
    • Reports compatibility issues
  3. Visual regression analysis

    "Compare screenshots from all browsers and highlight
    any visual differences in layout or rendering"

Performance Monitoring

Combine browser automation with performance analysis:

"Using Puppeteer, load the homepage and:
- Measure First Contentful Paint
- Track Largest Contentful Paint
- Monitor JavaScript execution time
- Identify render-blocking resources
- Generate a performance report"

Device Emulation

Test across common devices:

  • iPhone 14 Pro
  • Samsung Galaxy S23
  • iPad Pro
  • Various Android tablets

Touch Interactions

Simulate mobile gestures:

  • Swipe actions
  • Pinch to zoom
  • Long press
  • Device rotation
  1. Browser + GitHub MCP

    "Run visual regression tests, and if any fail,
    create a GitHub issue with the screenshots attached"
  2. Browser + Azure Monitor

    "Test the production site, and if errors occur,
    query Azure Monitor logs for related backend issues"
  3. Browser + Slack MCP

    "Run the E2E test suite and post results to
    #qa-team channel with pass/fail screenshots"
  1. Use headless mode for CI/CD - Faster and more reliable
  2. Set appropriate timeouts - Prevent hanging tests
  3. Clean up resources - Close browsers after use
  4. Parallelize when possible - Run tests concurrently
  5. Cache browser binaries - Avoid repeated downloads
Terminal window
# Puppeteer installation issues
npm install puppeteer --save-dev
# May need system dependencies on Linux:
sudo apt-get install chromium-browser
# Playwright installation
npx playwright install
# Installs all browser binaries