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 (instructions → systemPrompt), unified model configuration, and new executionModel option for cost optimization.
Direct page access has changed to use the Context API.
Stagehand v2
Copy
Ask AI
const stagehand = new Stagehand({ env: "LOCAL" });await stagehand.init();// Direct page accessconst page = stagehand.page;await page.goto("https://example.com");
Stagehand v3
Copy
Ask AI
const stagehand = new Stagehand({ env: "LOCAL" });await stagehand.init();// Access via contextconst page = stagehand.context.pages()[0];await page.goto("https://example.com");// Or use the convenience getterconst page = stagehand.page;await page.goto("https://example.com");
import { z } from 'zod/v3';// Had to wrap array in objectconst ApartmentListingsSchema = z.object({ apartments: z.array(z.object({ address: z.string(), price: z.string(), bedrooms: z.number() }))});const result = await page.extract({ instruction: "extract all apartment listings", schema: ApartmentListingsSchema});// Access via: result.apartments
Stagehand v3
Copy
Ask AI
import { z } from 'zod/v3';// Can use array schema directlyconst ApartmentListingsSchema = z.array( z.object({ address: z.string(), price: z.string(), bedrooms: z.number() }));const result = await stagehand.extract( "extract all apartment listings", ApartmentListingsSchema);// Result is directly the arrayconsole.log(result[0].address);
The agent configuration has been significantly restructured in v3 with renamed parameters and new capabilities.
Stagehand v2
Copy
Ask AI
const agent = stagehand.agent({ provider: "google", model: "gemini-2.5-computer-use-preview-10-2025", instructions: "You are a helpful assistant that can navigate websites.", options: { apiKey: process.env.GEMINI_API_KEY }, integrations: ["https://mcp-server.example.com"], tools: customTools});
Stagehand v3
Copy
Ask AI
const agent = stagehand.agent({ model: "google/gemini-2.5-computer-use-preview-10-2025", // Provider now in model string systemPrompt: "You are a helpful assistant that can navigate websites.", // Renamed from 'instructions' cua: true, // NEW: Computer Use Agent mode integrations: ["https://mcp-server.example.com"], tools: customTools});
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
The execute() method has been simplified with some options removed and new ones added.
Stagehand v2
Copy
Ask AI
const result = await agent.execute({ instruction: "Search for products", maxSteps: 20, autoScreenshot: true, waitBetweenActions: 1000, context: "Focus on electronics category"});
Stagehand v3
Copy
Ask AI
const result = await agent.execute({ instruction: "Search for products", maxSteps: 20, page: page, // NEW: specify which page to operate on highlightCursor: true // NEW: visual cursor for debugging});
Removed Options:
autoScreenshot - no longer available
waitBetweenActions - no longer available
context - use the systemPrompt in agent config instead
v3 introduces a new executionModel option to use a different (often faster/cheaper) model for tool execution.
Stagehand v3
Copy
Ask AI
const agent = stagehand.agent({ model: "anthropic/claude-sonnet-4-5", // Main reasoning model executionModel: "anthropic/claude-haiku-4-5" // Faster model for tool execution (act, extract, observe)});// The agent will use claude-sonnet-4-5 for high-level reasoning// but claude-haiku-4-5 for executing individual actionsconst result = await agent.execute("Complete the checkout process");
Use the string model format for simplicity: model: "openai/gpt-5"
Leverage automatic iframe support - remove all iframes flags
Use the Context API for multi-page scenarios
Monitor metrics to track token usage and optimize costs
Use history for debugging and understanding automation flow
Set appropriate timeouts based on your use case
Specify cache directory to improve performance for repeated actions
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")