What You'll Build
A production-ready browser automation system that can handle failures gracefully using Temporal’s workflow orchestration and Browserbase’s cloud browsers.
Before You Start
Ensure you have these requirements ready:Node.js 18+
Required runtime environment
Temporal CLI
Install:
brew install temporal
API Access
Browserbase API key and project ID
Required: The Temporal CLI must be installed and available in your PATH before proceeding.
Step 1: Project Setup
Clone and Install
What gets installed?
What gets installed?
Core Temporal packages:
@temporalio/worker
- Workflow execution engine@temporalio/workflow
- Workflow definitions@temporalio/activity
- Activity implementations
@browserbasehq/stagehand
- AI-powered browser controlplaywright
- Browser automation engine
@anthropic-ai/sdk
- Claude API clientzod
- Schema validation
Step 2: Configuration
Environment Variables
Create your.env
file with the required API keys:
Step 3: Start Temporal Server
Launch Development Server
Keep this terminal open - The Temporal server must run continuously during development.
Step 4: Run Your First Workflow
Start the Worker Process
In a new terminal (keep Temporal server running):Execute a Search Workflow
In a third terminal, run the demo:- Creates a new workflow execution
- Provides monitoring URL for real-time tracking
- Executes browser automation with automatic retries
- Returns structured search results
Monitoring and Debugging
Using Temporal Web UI
1
Access Workflow Details
Click the monitoring URL provided when starting a workflow:
2
Inspect Execution Timeline
The Web UI shows:
- Visual timeline of activity execution
- Event history with detailed logs
- Input/output data for each activity
- Retry attempts and failure reasons
Testing Resilience
The integration includes built-in failure simulation for testing:Troubleshooting Guide
Temporal Server Connection Failed
Temporal Server Connection Failed
Error:
Error: 14 UNAVAILABLE: failed to connect to all addresses
Root Cause: Temporal server not running or port conflictsSolutions:- Start Temporal server:
temporal server start-dev
- Check port 7233 is available:
lsof -i :7233
- Kill conflicting processes if needed
- Restart the server completely
Worker Failed to Start
Worker Failed to Start
Error:
Worker failed to start
or connection timeoutsRoot Cause: Worker cannot connect to Temporal serverSolutions:- Ensure Temporal server started successfully first
- Verify task queue name:
browser-automation
- Check network connectivity to localhost:7233
- Restart worker after server is stable
Browser Session Creation Failed
Browser Session Creation Failed
Error:
Failed to initialize browser
or Browserbase errorsRoot Cause: Invalid API credentials or quota limitsSolutions:- Verify API key and project ID in
.env
- Check Browserbase account credits/quota
- Test API credentials with
curl
request - Try a different Browserbase project
AI Extraction Returns Null
AI Extraction Returns Null
Error:
Extraction returned null values
or validation failuresRoot Cause: AI API issues or rate limitingSolutions:- Verify Anthropic API key validity
- Check API rate limits and credits
- Simplify extraction instructions
- Consider switching to OpenAI as fallback
Workflow Appears Stuck
Workflow Appears Stuck
Error: Workflows hang or don’t progressRoot Cause: Worker issues or activity timeoutsSolutions:
- Check worker is processing tasks (
npm run worker
) - Inspect workflow state in Web UI
- Look for timeout errors in activity logs
- Increase timeout values if needed
- Restart worker if necessary
What’s Next?
Now that you have a working Temporal + Browserbase integration:Build Custom Workflows
Create your own workflows for specific automation tasks
Production Deployment
Deploy to Temporal Cloud for production workloads
Advanced Patterns
Explore child workflows, signals, and queries
Monitoring & Alerting
Set up production monitoring and alerting
Need help? Join the Temporal Community and Stagehand Slack for support and discussions.