🐍 Looking for Stagehand in Python?Switch to v2 →
Overview
Stagehand v3 can work seamlessly with Puppeteer, allowing you to use Puppeteer’sPage objects directly with Stagehand’s AI-powered methods like act(), extract(), and observe().
Installation
First, install both Stagehand and Puppeteer:Quickstart
Basic Setup
Connect Puppeteer to Stagehand’s browser instance:Using Puppeteer Pages with Stagehand
Once connected, you can use Puppeteer’sPage objects with Stagehand’s AI-powered methods:
Advanced: Multi-Page Usage
Create and manage multiple Puppeteer pages with Stagehand:Observe + Act Pattern
The recommended pattern for reliable automation:Key Points
- Connect via WebSocket: Use
puppeteer.connect()withstagehand.connectURL()as thebrowserWSEndpoint - Pass the page: Always pass the Puppeteer
pageobject to Stagehand methods using the{ page }option - Disable viewport: Set
defaultViewport: nullto use Stagehand’s viewport settings - Multi-page support: Create multiple pages with
browser.newPage()and pass them to Stagehand methods
Environment Variables
When using Browserbase, set your credentials:Comparison: Stagehand Native vs Puppeteer
| Feature | Stagehand Native | With Puppeteer |
|---|---|---|
| Setup | Simple - use stagehand.context.pages() | Requires puppeteer.connect() |
| Page Access | stagehand.context.pages()[0] | await browser.pages() |
| AI Methods | stagehand.act("click") | stagehand.act("click", { page: ppPage }) |
| Best For | Pure Stagehand workflows | Existing Puppeteer codebases |

