Skip to main content

Overview

Stagehand v3 can work seamlessly with Puppeteer, allowing you to use Puppeteer’s Page 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’s Page 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:
This pattern helps avoid DOM changes between observation and action execution.

Key Points

  • Connect via WebSocket: Use puppeteer.connect() with stagehand.connectURL() as the browserWSEndpoint
  • Pass the page: Always pass the Puppeteer page object to Stagehand methods using the { page } option
  • Disable viewport: Set defaultViewport: null to 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:
For OpenAI (or other providers):

Comparison: Stagehand Native vs Puppeteer

Next Steps

Agent

Automate entire workflows

Act

Execute actions on web pages

Extract

Extract structured data from pages

Observe

Observe and find elements on pages