Guide
Convert to Stagehand Script
Overview
Browserbase provides a cloud-based playground where you can write, convert, and test browser automation scripts. Stagehand is a newer framework for building browser agents that work with Browserbase, offering a more intuitive, prompt-driven approach to web automation compared to traditional Playwright scripts. This workflow guides you through converting an existing Playwright script to Stagehand format and running it immediately to verify the conversion works correctly. This is useful when you want to migrate legacy Playwright automation to Stagehand's agent-based capabilities, or when you prefer the cleaner syntax and AI-powered interaction model that Stagehand provides.
Before you begin
- Access to www.browserbase.com with an active Browserbase account (sign up at https://www.browserbase.com/sign-up if needed)
- A Playwright script ready to convert, copied to your clipboard
- Understanding of basic browser automation concepts (Playwright or similar)
- Basic familiarity with code editors and JavaScript/TypeScript syntax
Step by step
PlaygroundNavigate to the Browserbase Playground by clicking the 'Playground' link in the main navigation. This is where you can write, test, and convert browser automation scripts in a cloud-hosted environment.
console.info("Launching browser..."); /* To make things easier, we've setup Playwright using the window variables. You can access it and your API key using window.playwright or window.connectionString. */ console.info('Connected!'); /** * 👋 Welcome Click inside the code editor area to focus it. The editor contains a welcome template and placeholder code. You will replace this with your Playwright script.
console.info("Launching browser..."); /* To make things easier, we've setup Playwright using the window variables. You can access it and your API key using window.playwright or window.connectionString. */ console.info('Connected!'); /** * 👋 Welcome Click again to ensure the editor is fully focused and ready to receive input. This ensures that your subsequent paste operation will insert the script into the correct location.
Paste your Playwright script from the clipboard by pressing Cmd+V (or Ctrl+V on Windows/Linux). This inserts the script into the editor, replacing any template code.
Editor content;Press Alt+F1 for Accessibility Options.If needed, manually add or adjust any script content in the editor textbox. This step allows you to make quick edits to the Playwright code before conversion, such as fixing syntax errors or removing incompatible features.
Convert to StagehandClick the 'Convert to Stagehand' button to automatically transform your Playwright script into a Stagehand-compatible script. Browserbase will analyze your code and rewrite it using Stagehand's agent-based APIs.
Accept changesReview the converted script and click 'Accept changes' to confirm the conversion. This step commits the Stagehand script as your active code in the playground.
Run ⌘Click the 'Run' button (keyboard shortcut: Cmd+Enter) to execute the converted Stagehand script in a live browser session on Browserbase. The script will run in a real browser environment and output results to the console.
Confirm it worked
- 1The Browserbase Playground loads successfully with the code editor visible
- 2Your Playwright script appears in the editor after pasting
- 3A 'Convert to Stagehand' button is available in the playground interface
- 4The script executes without errors after clicking 'Run', with console output visible showing successful completion
Common issues
Keep reading
Migrate Python v2 to v3 - Stagehand
> ## Documentation Index > > Fetch the complete documentation index at: https://docs.stagehand.dev/llms.txt > Use this file to discover all available pages before exploring further. # Migrate Python
docs.stagehand.devMigrate TypeScript v2 to v3 - Stagehand
> ## Documentation Index > > Fetch the complete documentation index at: https://docs.stagehand.dev/llms.txt > Use this file to discover all available pages before exploring further. # Migrate TypeSc
docs.stagehand.devQuickstart - Stagehand
> ## Documentation Index > > Fetch the complete documentation index at: https://docs.stagehand.dev/llms.txt > Use this file to discover all available pages before exploring further. # Quickstart >
docs.stagehand.dev