🤖

如何设置 Puppeteer MCP

让 openclaw 获得浏览器自动化能力:点击按钮、填写表单、截图,以及从网站抓取数据。

分类: 自动化
难度: 高级

Overview

The Puppeteer MCP enables:

  • Navigate to any URL
  • Click elements, fill forms, submit
  • Take screenshots (full page or element)
  • Extract text and data from pages
  • Handle JavaScript-heavy SPAs

Prerequisites

  • openclaw installed and running
  • Option A: Node.js 18+ with Chrome/Chromium installed
  • Option B: Docker (recommended for avoiding dependency issues)

Method 1: NPX (Local Node.js)

Simplest if you have Chrome installed locally.

Puppeteer NPX Config json
{
  "Puppeteer": {
    "command": "npx",
    "args": ["-y", "@anthropics/mcp-server-puppeteer"]
  }
}

Dependency Check

Run this to verify Chrome is findable:

npx puppeteer browsers install chrome

Method 2: Docker (Recommended)

Avoids all local dependency issues. Chrome runs inside the container.

Puppeteer Docker Config json
{
  "Puppeteer": {
    "command": "docker",
    "args": [
      "run", "-i", "--rm",
      "--cap-add=SYS_ADMIN",
      "ghcr.io/anthropics/mcp-server-puppeteer"
    ]
  }
}
Note: --cap-add=SYS_ADMIN is required for Chrome sandbox.

Verify Setup

  1. Run openclaw status — Puppeteer MCP should show as "running"
  2. Test: "Go to https://example.com and take a screenshot"
  3. Test: "Navigate to https://news.ycombinator.com and list the top 5 headlines"

Common Errors

ErrorCauseFix
Failed to launch browser Chrome not installed or not found Run npx puppeteer browsers install chrome or use Docker
No usable sandbox Linux sandbox issue Add --no-sandbox flag or use Docker with SYS_ADMIN
Navigation timeout Page too slow or blocked Increase timeout or check network/firewall
Element not found Selector invalid or page not loaded Wait for element, verify selector in DevTools

Windows / WSL2 Notes

  • On Windows, run openclaw in WSL2 for best compatibility
  • Docker Desktop with WSL2 backend works well
  • Native Windows may require additional Chrome path config

Security Considerations

  • Puppeteer can access any website—use responsibly
  • Don't automate login to sensitive accounts without understanding risks
  • Docker isolates the browser from your host system
  • Consider running in a separate network namespace for production

Example Prompts

  • "Go to https://github.com/trending and list the top 3 repos"
  • "Screenshot the homepage of https://example.com"
  • "Fill out the contact form on https://example.com/contact with name 'Test' and email '[email protected]'"
  • "Extract all product prices from https://example-store.com/products"

When to Use Puppeteer vs Fetch

Use CasePuppeteerFetch
Static HTML page ❌ Overkill ✅ Fast & simple
JavaScript-rendered content ✅ Required ❌ Won't work
Form submission ✅ Full control ❌ Limited
Screenshots ✅ Yes ❌ No
Resource usage ⚠️ High (runs browser) ✅ Low

相关 MCP