Stagehand Integration

Stagehand is an AI-powered browser automation framework that combines natural language instructions with code-based precision. Connect it to Scrapfly Cloud Browser for intelligent, self-healing automation with built-in proxies and fingerprinting.

Beta Feature: Cloud Browser is currently in beta.

What is Stagehand?

Stagehand is a browser automation framework that uses AI to understand and interact with web pages using natural language. Built on Playwright, it offers:

  • Natural Language Control - Describe actions in plain English instead of writing complex selectors
  • Self-Healing Automation - AI adapts when website structures change
  • Smart Caching - Reduces AI costs by caching repeated actions
  • Hybrid Approach - Mix AI actions with traditional code for reliability

Installation

Install Stagehand via npm:

Stagehand requires an LLM API key (OpenAI, Anthropic, etc.) for AI-powered actions. Set OPENAI_API_KEY or configure your preferred provider.

Quick Start with AI Actions

Connect Stagehand to Cloud Browser and use AI to interact with pages:

AI-Powered Scraping

Use Stagehand's AI capabilities to scrape complex, dynamic websites without writing selectors:

Natural Language Interactions

Handle complex workflows like login flows using natural language instead of brittle selectors:

Multi-Step AI Agent

Use Stagehand's autonomous agent mode to complete complex, multi-step tasks:

Hybrid: AI + Traditional Code

Combine AI actions with traditional Playwright code for the best of both worlds:

Session Persistence

Maintain browser state across Stagehand connections using the session parameter:

Proxy Options

Proxy Pool Use Case Cost
datacenter General scraping, high speed, lower cost 1 credits/30s + 2 credits/MB
residential Protected sites, geo-targeting, AI-powered bypass 1 credits/30s + 10 credits/MB

Best Practices

  • Set LLM API key - Configure OPENAI_API_KEY or your preferred AI provider
  • Use caching - Stagehand automatically caches AI actions to reduce costs
  • Mix AI and code - Use AI for complex/changing UI, code for predictable steps
  • Close browsers - Always call stagehand.close() to stop billing
  • Preview actions - Use Stagehand's preview mode in development to verify AI actions
  • Handle errors - Wrap AI actions in try/catch for robust automation

Cost Optimization

Stagehand automation combines Cloud Browser costs with LLM API costs:

  • Cloud Browser - Billed per time + bandwidth (see table above)
  • LLM API - Billed by your AI provider (OpenAI, Anthropic, etc.)
  • Caching - Stagehand caches actions automatically to minimize LLM calls
  • Hybrid approach - Use traditional code where possible to reduce AI costs
Tip: Stagehand's smart caching can reduce LLM costs by up to 90% for repeated workflows.

Summary