Skip to main content

Overview

The Browserbase Playground provides a visual interface for creating and deploying Functions without needing to set up a local development environment. Write your Stagehand automation script directly in the browser, test it with the Run button, and deploy as a function with a single click. Deploying functions from the Playground

Why Use the Playground?

  • No Local Setup - Start writing functions immediately without installing any tools
  • Instant Feedback - Test your automation and see results in real-time
  • Built-in Editor - Full-featured code editor with Stagehand support
  • Function Parameters - Define input parameters with optional default values
  • One-Click Deploy - Publish your function directly to Browserbase infrastructure
  • Live Session View - Watch your automation run in a live browser view

Creating and Deploying a Function

1

Open the Playground

Navigate to the Browserbase Dashboard and click on Playground in the navigation bar.
2

Write Your Script

The Playground editor comes pre-loaded with a Stagehand template. Write your automation logic using the Stagehand framework:
const stagehand = new Stagehand(config);
await stagehand.init();
const page = stagehand.context.pages()[0];

console.log('Initialized Stagehand');

await page.goto("https://news.ycombinator.com");
console.log('Navigated to page');

await stagehand.act(`Search for "${params.searchQuery}"`);
console.log('Searched');

const articles = await stagehand.extract({
  instruction: "Extract article titles and URLs",
  schema: z.object({
    articles: z.array(z.object({
      title: z.string(),
      url: z.string(),
    })),
  }),
});

return articles;
The Playground automatically provides Stagehand configuration and initialization. You can also use the Convert to Stagehand button to convert plain Playwright scripts.
3

Define Function Parameters

Use the Function Parameters panel on the right side to define inputs for your function. Click + Add to create parameters:Adding function parameters
  • Parameter name - The key used to access the value (e.g., searchQuery)
  • Default value - Optional fallback value if not provided at invocation
Access parameters in your script using the params object:
await stagehand.act(`Search for "${params.searchQuery}"`);
You can define up to 8 function parameters. Some parameters like modelApiKey are provided automatically in the Playground environment.
4

Test Your Script

Click the Run button to test your script. The Playground will:
  1. Create a new browser session
  2. Execute your automation code
  3. Display console output and results
  4. Show a live view of the browser session
Use the live view to debug and verify your automation is working correctly before deploying.
5

Deploy as Function

Once you’re satisfied with your script:
  1. Set the Function Name in the panel on the right (e.g., search-hacker-news)
  2. Click Deploy in the toolbar, then select Deploy as Function Deploying a function
After a successful deployment, a modal will appear with:
  • Confirmation that your function is live
  • A ready-to-use cURL command for invoking your function
  • A View Function button to see your function in the Functions dashboard

Managing Deployed Functions

Click View Function in the deployment modal or navigate to the Functions tab to see your deployed functions. From here you can:
  • View function details and invocation history
  • See previous versions of your function
  • Copy the invoke URL and cURL commands
  • Delete functions you no longer need
Redeploying from the Playground with the same function name will create a new version of the existing function.

Transitioning to Local Development

As your functions grow more complex, you may want to transition to local development for better tooling and version control. See the Functions Documentation for setup instructions.

Next Steps