MCP Playwright Browser

MCP Playwright Browser

Exposes Playwright-powered automation tools to AI assistants for navigating web pages, interacting with elements, and extracting structured data. It features specialized scrapers for Indeed and Google Search, along with stealth mode to bypass bot detection.

Category
访问服务器

README

MCP Playwright Browser Server

A powerful Model Context Protocol (MCP) server that exposes Playwright-powered browser automation tools to AI assistants. Enable your AI to navigate web pages, extract structured data, scrape job listings, and interact with web content programmatically - using both traditional DOM methods and visual screenshot-based navigation.

Features

  • Visual Navigation: Screenshot-based page analysis with element mapping and coordinate-based clicking
  • Browser Automation: Full browser control via Playwright (Chromium)
  • MCP Integration: Expose 23+ tools via Model Context Protocol
  • Anti-Detection: Stealth mode to bypass bot detection
  • Job Scraping: Specialized extractors for Indeed job postings
  • Search Extraction: Google search results extraction
  • CDP Support: Connect to existing Chrome instances via Chrome DevTools Protocol
  • Flexible Modes: Headless or headful browser operation
  • Dual Navigation: Traditional DOM-based OR visual screenshot-based interaction
  • File Management: Save extracted data to structured text files

How This Differs from Microsoft's Official playwright-mcp

Microsoft's playwright-mcp focuses on accessibility-tree based automation for test development and structured page interaction.

This server adds:

  • Visual/screenshot-based navigation - For sites where accessibility trees are insufficient (Shadow DOM, obfuscated forms, visual layouts)
  • Production-ready extractors - Pre-built Indeed and Google scrapers with anti-detection
  • Stealth capabilities - User profile persistence, anti-bot headers, CDP connection to real Chrome instances
  • Hybrid approach - Combines DOM and visual methods, letting AI choose based on task requirements

Use Microsoft's tool for: Test automation, structured accessibility-driven workflows Use this tool for: Web scraping, complex agent-driven automation, anti-detection scenarios

Visual Navigation: A Unique Advantage

This server provides two ways for AI assistants to interact with web pages:

  1. Traditional DOM-based (default, faster): AI reads the HTML code structure
  2. Visual screenshot-based (optional, more human-like): AI analyzes a screenshot of the page

The visual navigation feature (browser.visual_snapshot + browser.click_at) allows AI to "see" pages like a human, which is invaluable for:

  • Complex layouts where HTML structure doesn't match visual appearance
  • Obfuscated forms with dynamically generated or meaningless element IDs
  • Shadow DOM or heavily nested iframe structures
  • When you need the AI to understand the visual layout, not just the code

Performance & Cost Considerations

When to use DOM methods (default):

  • ~10x faster execution
  • Minimal token usage (structured text vs. image encoding)
  • Lower latency for multi-step workflows
  • Works reliably on well-structured sites

When to use Visual methods:

  • Complex Shadow DOM or iframes where DOM traversal fails
  • Sites with obfuscated or dynamically-generated element IDs
  • Anti-bot measures that detect programmatic element selection
  • When human-like interaction patterns are required

The AI automatically defaults to DOM-based methods for efficiency, switching to visual only when explicitly requested or when DOM methods fail. This optimizes for speed and cost while maintaining robustness.

⚠️ Ethical Use & Legal Compliance

This tool is provided for:

  • Educational purposes and learning browser automation
  • Testing your own web applications
  • Legitimate research with appropriate authorization
  • Automation of tasks you have permission to perform

You are responsible for:

  • Respecting robots.txt and website Terms of Service
  • Obtaining permission before scraping third-party sites
  • Complying with data protection regulations (GDPR, CCPA, etc.)
  • Rate-limiting requests to avoid service disruption
  • Using the tool in accordance with applicable laws

Not intended for:

  • Violating website terms of service
  • Bypassing paywalls or access controls without authorization
  • Automated data collection without permission
  • Any illegal activity

The authors assume no liability for misuse of this software. Users are solely responsible for ensuring their use complies with all applicable laws and regulations.

Installation

npm install

Install Playwright Chromium browser:

npx playwright install chromium

Quick Start

Running the MCP Server

npm start

Running Standalone Tests

Test Indeed job extraction:

npm run test:indeed

Test Google search extraction:

npm run test:google

MCP Configuration

Configure your MCP client to use this server. For Gemini CLI, add to your settings.json:

{
  "mcpServers": {
    "playwrightBrowser": {
      "command": "node",
      "args": ["src/mcp-browser-server.js"],
      "cwd": "/path/to/this/repo"
    }
  }
}

Or use the CLI:

gemini mcp add playwrightBrowser node src/mcp-browser-server.js

Available Tools

Browser Control

  • browser.launch - Launch Chromium with optional stealth mode
  • browser.connect_cdp - Connect to existing Chrome instance
  • browser.goto - Navigate to URL
  • browser.back / browser.forward - Navigate history
  • browser.new_page - Open new tab
  • browser.close - Close browser session

Element Interaction

  • browser.list - List interactive elements
  • browser.click - Click elements by ID, selector, or text
  • browser.type - Type into input fields
  • browser.press - Press keyboard keys

Data Extraction

  • browser.snapshot - Get page summary with text and links
  • browser.extract_text - Extract text from selectors
  • browser.extract_html - Extract HTML from selectors
  • browser.screenshot - Capture screenshots

Visual Navigation

  • browser.visual_snapshot - Take screenshot + generate element map with bounding boxes and IDs
  • browser.click_at - Click at specific X/Y coordinates for visual workflows

Specialized Extractors (Production Examples)

Pre-built extractors for common automation targets - demonstrating robust, production-grade scraping patterns:

Job Scraping:

  • jobs.extract_indeed - Extract Indeed job listings with multi-selector fallbacks, duplicate detection, and anti-bot awareness
  • jobs.indeed_next_page - Navigate to next Indeed results page with multiple pagination strategies

Search:

  • search.google - Search Google and extract results with consent handling and result deobfuscation
  • search.extract_google - Extract results from current Google page with multiple container format support

These extractors showcase best practices for building reliable scrapers: fallback selector chains, access issue detection, URL normalization, and filesystem-safe sanitization. Use them as templates for building your own specialized extractors.

File Operations

  • files.write_text - Save arbitrary text to files

Usage Examples

Example 1: Scrape Indeed Jobs

// Launch browser
browser.launch({ headless: false })

// Navigate to Indeed search
browser.goto({ url: "https://ae.indeed.com/q-ai-engineer-l-dubai-jobs.html" })

// Extract and save jobs
jobs.extract_indeed({ limit: 20, saveDir: "output/indeed/page-1" })

// Go to next page
jobs.indeed_next_page()

// Extract more jobs
jobs.extract_indeed({ limit: 20, saveDir: "output/indeed/page-2" })

Example 2: Google Search

// Launch browser
browser.launch({ headless: true })

// Search and extract results
search.google({
  query: "remote ai jobs in usa",
  limit: 10,
  saveDir: "output/google"
})

Example 3: Visual Navigation (Screenshot-Based)

// Launch browser
browser.launch({ headless: false })

// Navigate to a page
browser.goto({ url: "https://example.com" })

// Take visual snapshot - AI can "see" the page layout
browser.visual_snapshot({
  path: "output/screenshot.png",
  saveMapPath: "output/element-map.json"
})

// Click element by ID from the visual map
browser.click({ elementId: 42 })

// Or click at specific coordinates
browser.click_at({ x: 350, y: 450 })

When to use visual navigation:

  • Complex layouts where DOM structure is hard to parse
  • Obfuscated forms or dynamically generated IDs
  • When you need the AI to "see" the page like a human
  • Shadow DOM or iframe-heavy pages

Example 4: Stealth Mode with User Profile

// Launch with persistent profile to bypass captchas
browser.launch({
  headless: false,
  userDataDir: "C:/Users/User/AppData/Local/Google/Chrome/User Data",
  args: ["--disable-blink-features=AutomationControlled"],
  stealth: true
})

Example 5: Connect to Existing Chrome

Start Chrome with remote debugging:

chrome.exe --remote-debugging-port=9222

Then connect:

browser.connect_cdp({ endpoint: "http://127.0.0.1:9222" })

Handling Captchas and Blocks

Indeed and Google may show captchas or block automation. Solutions:

  1. Use headful mode: browser.launch({ headless: false }) allows you to solve captchas manually
  2. Use persistent profiles: Launch with userDataDir to reuse cookies and sessions
  3. Enable stealth mode: browser.launch({ stealth: true })
  4. Use existing Chrome: Connect via CDP to a logged-in Chrome instance
  5. Change network/IP: Some blocks are IP-based

Output Structure

Extracted data is saved as text files:

output/
├── indeed/
│   ├── page-1/
│   │   ├── AI Engineer.txt
│   │   ├── Machine Learning Engineer.txt
│   │   └── ...
│   └── page-2/
│       └── ...
└── google/
    ├── Result Title.txt
    └── ...

Each file contains structured data:

Title: AI Engineer
Company: Tech Company
Location: Dubai, UAE
Salary: AED 15,000 - 25,000
URL: https://ae.indeed.com/viewjob?jk=...
Summary:
Job description text here...

Architecture

  • src/mcp-browser-server.js - Main MCP server with tool definitions
  • src/extractors.js - Extraction logic for Indeed and Google
  • src/tests/ - Standalone test scripts

Dependencies

  • @modelcontextprotocol/sdk - MCP server implementation
  • playwright - Browser automation framework
  • zod - Schema validation for MCP tools

License

ISC

Contributing

Contributions welcome! Please feel free to submit issues and pull requests.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选