Environment Configuration
Set the environment type using theenv option:
Local Browser Configuration
Run Stagehand with a local Chrome/Chromium browser on your machine.Basic Local Setup
Local Browser Launch Options
ThelocalBrowserLaunchOptions object supports the following configuration:
Additional command-line arguments to pass to Chrome
Path to a Chrome/Chromium executable
Port for the Chrome DevTools Protocol (CDP) server
Path to a user data directory for storing browser profiles, cookies, and cache
Keep the user data directory after browser closes
Run browser in headless mode (no UI)
Auto-open Chrome DevTools
Enable Chromium sandbox (disable for Docker)
Ignore default Chrome arguments or filter specific ones
Proxy server configuration
Browser locale
Browser viewport size
Device pixel ratio
Enable touch events
Ignore HTTPS certificate errors
Connect to an existing Chrome DevTools Protocol URL
Timeout for connecting to the browser (default: 15000ms)
Directory for downloads
Allow file downloads
Complete Local Example
Browserbase Configuration
Use Browserbase for cloud-based, scalable browser automation with built-in anti-detection, session recording, and debugging.Basic Browserbase Setup
Get your Browserbase API credentials at browserbase.com
Browserbase Session Options
Customize Browserbase sessions withbrowserbaseSessionCreateParams:
Keep session alive after Stagehand closes (for debugging)
Browserbase region:
us-west-2, us-east-1, eu-central-1, ap-southeast-1Session timeout in seconds
Browser configuration options
Proxy configuration
Persist browser context across sessions
Advanced Browserbase Example
Resume Existing Session
Resume a previously created Browserbase session:Access Session Information
Get session URLs for debugging and viewing recordings:Choosing Between Local and Browserbase
Local Browser
Best for:
- Local development and testing
- Applications requiring local files
- Custom browser configurations
- Cost-sensitive workloads
Browserbase
Best for:
- Production deployments
- Scalable automation
- Anti-detection requirements
- Session recording and debugging
- Multi-region support
Tip: Start development locally and switch to Browserbase for production by changing the
env parameter.