A comprehensive collection of code examples for using Browserbase across different languages and automation frameworks.
Browserbase provides cloud browser infrastructure for reliable web automation. This playbook demonstrates how to use Browserbase with various languages and frameworks to:
- Run browser automation in the cloud
- Implement stealth and anti-bot features
- Manage browser sessions and contexts
- Handle downloads, uploads, and screenshots
- Configure proxies and captcha solving
- Node.js 18+ (for JavaScript/TypeScript examples)
- Python 3.8+ (for Python examples)
- A Browserbase account with API key and project ID (Sign up here)
-
Clone this repository:
git clone https://github.com/browserbase/playbook.git cd playbook
-
Install dependencies for your preferred language:
JavaScript/TypeScript:
npm install
Python:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate pip install -r requirements.txt
-
Set up your environment variables:
cp .env.example .env
Then edit the
.env
file with your credentials:BROWSERBASE_PROJECT_ID=your_project_id BROWSERBASE_API_KEY=your_api_key OPENAI_API_KEY=your_openai_key # Optional, used for Stagehand ANTHROPIC_API_KEY=your_anthropic_key # Optional, used for Stagehand
Find utility functions for managing Browserbase in:
node/functions.ts
(TypeScript)python/functions.py
(Python)
Node.js:
npx tsx path/to/example.ts
Python:
python path/to/example.py
- Connection Issues: Check your API key and network connection
- Session Timeouts: Configure longer timeouts or enable keep-alive
- Captcha Problems: Review captcha configuration in session settings
- Proxy Errors: Verify proxy settings and availability
For more help, visit the Browserbase Documentation or contact support at [email protected].