Skip to main content
  1. Backup your project. If you use a version control system, make sure all previous versions are committed.
  2. Upgrade to Stagehand v3.
  3. Follow the breaking changes guide below.
  4. Verify your project is working as expected.
  5. Commit your changes.

Stagehand v3 Package Version

Update your package.json to use Stagehand v3:
Bash

Overview of Major Changes

Stagehand v3 introduces significant improvements to the API design and functionality:
  • Removing Playwright Dependency: Stagehand v3 is now a standalone library that does not depend on Playwright. You can still use Stagehand with Playwright, check out our Playwright integration for more details.
  • Simplified Method Signatures: Cleaner, more intuitive parameter structures.
  • Unified Model Configuration: Model configuration is now consolidated into a single model parameter.
  • Automatic iframe & Shadow DOM Support: No more manual flags required.
  • Improved Type Safety: Better TypeScript inference and type checking.
  • Enhanced Multi-Page Support: New Context API for managing multiple pages.
  • Streamlined Timeouts: Consistent timeout naming across all methods.
  • Auto-caching: Stagehand v3 now automatically caches actions and agent steps using the file system cache.
  • Agent Improvements: Renamed parameters (instructionssystemPrompt), unified model configuration, and new executionModel option for cost optimization.

Breaking Changes

Stagehand Initialization

Model Configuration Consolidation

The modelName and modelClientOptions parameters have been unified into a single model parameter.
Stagehand v2
Stagehand v3

DOM Settle Timeout Rename

The domSettleTimeoutMs parameter has been renamed to domSettleTimeout for consistency.
Stagehand v2
Stagehand v3

Changes to return value of stagehand.init()

The init() used to return debugUrl, sessionUrl and sessionId
Stagehand v2
In v2, the returned object contains:
In v3 the return value is Promise<void>. The sessionId, sessionUrl, and debugUrl are now directly accessible via the stagehand object:
Stagehand v3
Example output:

Caching Changes

The enableCaching boolean has been replaced with a cacheDir string for more flexible cache management.
Stagehand v2
Stagehand v3

Page Access Changes

Direct page access has changed to use the Context API.
Stagehand v2
Stagehand v3

Context and Multi-Page Management

New Context API

v3 introduces a structured Context API for managing multiple pages.
Stagehand v2
Stagehand v3

act() Method Changes

Method Signature Simplification

The action parameter has been removed from ActOptions. Now you only pass the instruction as a string.
Stagehand v2
Stagehand v3
Method Location Change: In v3, act() is called on the stagehand instance, not the page object.

Model Configuration in act()

Model configuration follows the same pattern as initialization.
Stagehand v2
Stagehand v3

Timeout Parameter Rename

timeoutMs has been renamed to timeout.
Stagehand v2
Stagehand v3

Automatic iframe Support

The iframes flag has been removed. iframe support is now automatic.
Stagehand v2
Stagehand v3
Automatic Support: Stagehand v3 automatically handles iframe and Shadow DOM interactions without requiring explicit flags.

Result Structure Changes

The ActResult structure has been enhanced with more detailed information.
Stagehand v2
Stagehand v3

extract() Method Changes

Method Location and Signature

extract() has moved from the page object to the stagehand instance, with a cleaner parameter structure.
Stagehand v2
Stagehand v3
Parameter Order: In v3, instruction and schema are separate positional parameters, with options as an optional third parameter.

Extract Without Schema

Schema-less extraction also has a simpler interface.
Stagehand v2
Stagehand v3

Model Configuration in extract()

Stagehand v2
Stagehand v3

Automatic iframe Support

Stagehand v2
Stagehand v3

Array Schema Changes

Array extraction now has a more ergonomic syntax.
Stagehand v2
Stagehand v3

observe() Method Changes

Method Signature Updates

Stagehand v2
Stagehand v3
Method Location Change: Like act() and extract(), observe() is now called on the stagehand instance.

Draw Overlay Removed

The drawOverlay option has been removed in v3.
Stagehand v2
Stagehand v3

Automatic iframe Support

Stagehand v2
Stagehand v3

Observe with act() Integration

The observe → act workflow remains similar but with updated method signatures.
Stagehand v2
Stagehand v3

agent() Method Changes

Agent Configuration Updates

The agent configuration has been significantly restructured in v3 with renamed parameters and new capabilities.
Stagehand v2
Stagehand v3
Key Changes:
  • provider removed - now part of the model string (e.g., "anthropic/claude-sonnet-4-5")
  • instructions renamed to systemPrompt
  • options removed - use model object format for advanced configuration
  • executionModel added - specify a different model for tool execution
  • cua flag added - enable/disable Computer Use Agent mode

Model Configuration in agent()

Model configuration follows the same unified pattern as other methods.
Stagehand v2
Stagehand v3

Execute Method Changes

The execute() method has been simplified with some options removed and new ones added.
Stagehand v2
Stagehand v3
Removed Options:
  • autoScreenshot - no longer available
  • waitBetweenActions - no longer available
  • context - use the systemPrompt in agent config instead

Execution Model Configuration

v3 introduces a new executionModel option to use a different (often faster/cheaper) model for tool execution.
Stagehand v3

Agent with Multi-Page Support

v3 agents can now specify which page to operate on.
Stagehand v3

History and Metrics

History API

History is now async and returns a promise.
Stagehand v2
Stagehand v3

Metrics API

Metrics is now async and returns a promise.
Stagehand v2
Stagehand v3

Complete Migration Example

Here’s a complete example showing a full migration:

Quick Reference: Breaking Changes

Troubleshooting

Error: Cannot find property ‘page’ on Stagehand instance

Problem: Direct stagehand.page is not supported in Stagehand v3. Solution: Use the Context API or await the active page:

Error: act() method not found on page

Problem: v3 moved act(), extract(), and observe() to the stagehand instance. Solution: Call these methods on the stagehand instance:

TypeScript: Model configuration type errors

Problem: TypeScript errors with model configuration. Solution: Use the proper format:

Agent configuration errors

Problem: Using old provider and instructions parameters. Solution: Update to v3 format:

Agent execute options not recognized

Problem: Using removed options like autoScreenshot, waitBetweenActions, or context. Solution: Remove these options and use v3 alternatives:

Best Practices for v3

  1. Use the string model format for simplicity: model: "openai/gpt-5"
  2. Leverage automatic iframe support - remove all iframes flags
  3. Use the Context API for multi-page scenarios
  4. Monitor metrics to track token usage and optimize costs
  5. Use history for debugging and understanding automation flow
  6. Set appropriate timeouts based on your use case
  7. Specify cache directory to improve performance for repeated actions
  8. Use executionModel for agents - configure a faster/cheaper model for tool execution while keeping a powerful model for reasoning (e.g., model: "anthropic/claude-sonnet-4-5", executionModel: "google/gemini-2.0-flash")

Additional Resources

If you encounter any issues during migration, please open an issue on our GitHub repository.