Puppeteer MCP
by greenfinity
README.md
# @greenfinity/puppeteer-mcp
MCP server for browser automation using Puppeteer - equivalent to Playwright MCP.
## Motivation
Playwright is an alternative to Puppeteer for browser testing, but at the end of the day it does not have significantly more to offer, apart from WebKit support and patched browser executables.
However, Puppeteer works with unpatched Chrome and Firefox browser executables which offer advantages, for example for in-browser debugging during automated tests.
Puppeteer is a well-established testing framework with significant experience and code accumulated during the years, so it's a more solid choice for features that it can do.
Since I use Puppeteer for testing, I would also like to use it with my agents for various automation and introspection tasks.
Puppeteer's existing MCP is deprecated, so it makes sense to build a new MCP from scratch.
## Installation
```bash
npm install @greenfinity/puppeteer-mcp
```
## Usage
### With Claude Desktop
Add to your Claude Desktop configuration:
```json
{
"mcpServers": {
"puppeteer": {
"command": "npx",
"args": ["@greenfinity/puppeteer-mcp"]
}
}
}
```
### CLI Options
```text
npx @greenfinity/puppeteer-mcp [options]
Options:
--headless Run browser in headless mode (default: true)
--no-headless Run browser in headed mode
--browser <type> Browser to use: chrome, firefox (default: chrome)
--viewport <size> Viewport size as WIDTHxHEIGHT (default: 1280x720)
--timeout <ms> Default timeout in milliseconds (default: 30000)
--user-data-dir Path to user data directory for browser profile
```
## Supported Tools
### Navigation & Page Control
- `browser_navigate` - Navigate to a URL
- `browser_navigate_back` - Go back in browser history
- `browser_close` - Close the browser
- `browser_tabs` - List, create, close, or select browser tabs
- `browser_resize` - Resize the browser viewport
- `browser_wait_for` - Wait for text, element, or time
### Interaction
- `browser_click` - Click on an element
- `browser_type` - Type text into an element
- `browser_hover` - Hover over an element
- `browser_drag` - Drag and drop between elements
- `browser_press_key` - Press a keyboard key
- `browser_select_option` - Select an option in a dropdown
- `browser_file_upload` - Upload files
- `browser_handle_dialog` - Handle browser dialogs (alert, confirm, prompt)
### Forms
- `browser_fill_form` - Fill multiple form fields at once
### Snapshots & Screenshots
- `browser_snapshot` - Capture accessibility tree snapshot (recommended for LLM interaction)
- `browser_take_screenshot` - Capture visual screenshot
### Diagnostics
- `browser_console_messages` - Get console log messages
- `browser_network_requests` - Get network request history
### Code Execution
- `browser_evaluate` - Execute JavaScript on the page
- `browser_run_code` - Run Puppeteer code snippets
### Setup
- `browser_launch` - Launch or relaunch browser with specific settings (headless mode, userDataDir for session persistence)
- `browser_install` - Install browser if not present
## Session Persistence
To preserve login sessions and cookies across browser relaunches (e.g., when switching between headless and visible mode), use the `userDataDir` parameter with `browser_launch`:
```text
browser_launch with userDataDir="/path/to/profile" and headless=false
# Login to your site in the visible browser
# Then switch to headless mode while keeping the session:
browser_launch with userDataDir="/path/to/profile" and headless=true
```
The browser profile directory stores cookies, localStorage, and other session data, allowing you to maintain authenticated sessions across mode switches.
## Accessibility Snapshots
The `browser_snapshot` tool uses Puppeteer's `page.accessibility.snapshot()` to capture a structured representation of the page. This is the recommended way for LLMs to understand page content as it provides:
- Semantic information (roles, names, states)
- Hierarchical structure
- Element references for interaction
- Fast and lightweight (no vision models required)
Each element in the snapshot has a `ref` attribute that can be used with interaction tools like `browser_click` and `browser_type`.
## Why ReScript?
This package is implemented in [ReScript](https://rescript-lang.org/), a functional language that compiles to JavaScript. ReScript is superior to TypeScript in every way - it offers a sound type system, excellent pattern matching, and produces clean, readable JavaScript output with no runtime overhead.
I use ReScript in my daily development for everything. There is no drawback to using ReScript, and TypeScript offers zero advantages over it.
The compiled JavaScript is included in the released npm package, so you can use this as a regular JavaScript module without any additional tooling.
### Local Development
For local development of this package, ReScript tooling is provided in the package.json scripts:
```bash
# Build the ReScript sources to JavaScript
yarn build
# Watch mode for development (rebuilds on file changes)
yarn rescript:dev
```
Note: These scripts are only needed if you're modifying the package source code locally. End users can simply install and use the package as-is.
## License
MIT
This server cannot be deployed
Maintenance
ActivityInactive
ResponsivenessNo recent community issues