🐍 Looking for Stagehand in Python?Switch to v2 →
Overview
Stagehand v3 can work seamlessly with Playwright, allowing you to use Playwright’sPage objects directly with Stagehand’s AI-powered methods like act(), extract(), and observe().
Installation
First, install both Stagehand and Playwright:Quickstart
Basic Setup
Connect Playwright to Stagehand’s browser instance using Chrome DevTools Protocol (CDP):Using Playwright Pages with Stagehand
Once connected, you can use Playwright’sPage objects with Stagehand’s AI-powered methods:
Multi-Page Example
Stagehand works great with multiple Playwright pages:Complete Example
Here’s a full working example:Key Points
- Connect via CDP: Use
chromium.connectOverCDP()withstagehand.connectURL()as the WebSocket endpoint - Pass the page: Always pass the Playwright
pageobject to Stagehand methods using the{ page }option - Multi-page support: Create multiple pages with
pwContext.newPage()and pass them to Stagehand methods - Concurrent operations: Use
Promise.all()to run multiple Stagehand operations in parallel across different pages

