A powerful, production-ready browser automation toolkit built with Stagehand and Browserbase. Automate complex web interactions, scrape data, test responsive designs, and build intelligent web agents with AI-powered browser control.
Traditional browser automation is brittle and maintenance-heavy. Stagehand + Browserbase changes the game:
- π§ AI-Powered Actions - Natural language commands that adapt to UI changes
- βοΈ Cloud Browser Infrastructure - No local Chrome management, instant scalability
- π― Intelligent Element Detection - Robust selectors that survive DOM changes
- πΈ Built-in Debugging - Screenshots, session replays, detailed logging
- π Easy Scaling - Run hundreds of browsers in parallel
- π¨ Viewport Testing - Test across any device size or resolution
This toolkit enables countless automation scenarios:
- Extract structured data from dynamic websites
- Monitor competitor pricing and inventory
- Aggregate content from multiple sources
- Build custom APIs from websites without APIs
- Responsive design testing across devices
- Cross-browser compatibility checks
- E2E testing for complex user flows
- Visual regression testing
- Automated form filling and submissions
- Social media automation
- Lead generation and research
- Content posting and management
- SERP scraping and ranking analysis
- Competitor analysis automation
- Content audit and analysis
- Link checking and validation
- Market research automation
- Real-time data monitoring
- Automated reporting
- Trend analysis
- Node.js 18+
- pnpm (or npm/yarn)
- Browserbase account (free tier available)
- OpenAI API key (for AI-powered actions)
# Clone the repository
git clone https://github.com/laurentknauss/browser-automation.git
cd browser-automation
# Install dependencies
pnpm install
# Set up environment variables
cp .env.example .env
# Edit .env and add your API keys:
# - BROWSERBASE_API_KEY
# - BROWSERBASE_PROJECT_ID
# - OPENAI_API_KEYpnpm startimport { Stagehand } from "@browserbasehq/stagehand";
import { z } from "zod";
const stagehand = new Stagehand({ env: "BROWSERBASE" });
await stagehand.init();
// Navigate and extract data
await stagehand.page.goto("https://example.com");
const data = await stagehand.page.extract({
instruction: "Extract all product names and prices",
schema: z.object({
products: z.array(z.object({
name: z.string(),
price: z.string()
}))
})
});
console.log(data);
await stagehand.close();// Natural language browser control
await stagehand.page.act("Click the 'Sign Up' button");
await stagehand.page.act("Fill in the email field with test@example.com");
await stagehand.page.act("Submit the form");
// Check what happened
const result = await stagehand.page.extract({
instruction: "Did the signup succeed? What message is shown?",
schema: z.object({
success: z.boolean(),
message: z.string()
})
});const viewports = [
{ name: "Mobile", width: 393, height: 851 },
{ name: "Tablet", width: 768, height: 1024 },
{ name: "Desktop", width: 1920, height: 1080 }
];
for (const viewport of viewports) {
await stagehand.page.setViewportSize(viewport);
await stagehand.page.screenshot({
path: `${viewport.name.toLowerCase()}.png`
});
// Extract responsive design info
const layout = await stagehand.page.extract({
instruction: "Describe the layout and navigation structure",
schema: z.object({
navigation: z.string(),
layout: z.string()
})
});
console.log(`${viewport.name}:`, layout);
}browser-automation/
βββ index.ts # Main entry point (current example: mobile nav testing)
βββ package.json # Dependencies and scripts
βββ tsconfig.json # TypeScript configuration
βββ .cursorrules # AI coding assistant rules
βββ .env.example # Environment variables template
βββ README.md # This file
// Cloud execution (recommended for production)
const stagehand = new Stagehand({
env: "BROWSERBASE"
});
// Local execution (for development)
const stagehand = new Stagehand({
env: "LOCAL",
headless: false // See the browser in action
});const stagehand = new Stagehand({
env: "BROWSERBASE",
enableCaching: true,
debugDom: true,
// Add more options as needed
});Contributions are welcome! Whether it's:
- π Bug fixes
- β¨ New features
- π Documentation improvements
- π‘ Use case examples
Please feel free to open issues or submit pull requests.
MIT License - feel free to use this in your projects!
If this project helps you, please consider:
- β Starring the repository
- π Forking for your own use cases
- π’ Sharing with others who might benefit
- π Reporting issues or suggesting improvements
- Stagehand - The AI-powered browser SDK
- Browserbase - Cloud browser infrastructure
- Playwright - Browser automation library (Stagehand's foundation)
Built with β€οΈ using Stagehand and Browserbase
Need help? Open an issue or reach out!