Overview
Browser Functions let you deploy serverless browser automation workflows directly to Browserbase’s infrastructure. Write your automation code locally, test it instantly, and deploy it as a cloud function that can be invoked via API. There are four steps to creating and using Browser Functions:- Set up a functions project in your local environment
- Locally develop and verify your functions defined in TypeScript
- Publish your functions to Browserbase infrastructure
- Invoke your functions via API! 🎉
Why Browser Functions?
Key Benefits:- Zero Infrastructure - No servers to manage or containers to configure
- Instant Testing - Local development server for rapid iteration
- Playwright Native - Use familiar Playwright APIs for browser automation
- Built-in Session Management - Sessions are automatically created and configured
- API-First - Invoke functions via simple HTTP requests
Getting Started
Environment Setup
Browser Functions are defined via Infrastructure as Code (IaC)! This means that your functions are defined alongside your automations in TypeScript. This step will walk you through how to set up a functions development environment.1
Initialize Your Project
Initialize your functions project with the Enter the
@browserbasehq/sdk-functions NPM package CLI. This will initialize a my-functions-project
directory, configure a TypeScript pNPM project, install required packages, create a template .env file, and initialize a starter function
in index.ts.my-functions-project directory created by the CLI:2
Configure Environment Variables
Populate the
.env file with your Browserbase credentials:Get your API key and Project ID from the Browserbase Dashboard Settings.
3
Create your Function
Now you can create a new Function! The CLI creates a template function
"my-function" in index.ts. This function does the following:- Connects to the browser session associated with the function
- Navigates to Hacker News
- Extracts the top 3 results from the page and returns them
index.ts
Start the Development Server
http://127.0.0.1:14113 and watch for file changes.
Invoke Your Function Locally
Use curl to test your function:The local development server automatically reloads when you modify your function files.
Publishing a Function
To publish all of the functions in your local project to Browserbase’s cloud infrastructure, run the following command. This command does the following:- Bundles your local project while respecting
.gitignore. Project root is the directory containingpackage.json - Uploads this bundle to Browserbase, which builds all functions in the project so that they can be invoked.
- Return a build ID and function IDs for each discovered function
The
publish command requires an “entrypoint” parameter. An “entrypoint” file indicates that “all functions in this
project are either defined in this file or defined in files directly or indirectly imported into this file”. Multi-file
projects in TypeScript use import "other-file.ts" to ensure that defineFn is called in the imported file
when the entrpoint file is run.Keep track of your function ID - you’ll need it to invoke your deployed function.
Invoking Functions
Call your deployed function via HTTP POST. Parameters are optional:Get your API key and Project ID from the Browserbase Dashboard Settings.
For the time being, you will always be invoking the latest version of each function (uniquely identified by
name). New versions
are created each time you publish a function.Use Cases
Browser Functions are perfect for:- Webhooks - Trigger browser automation from external services
- Scheduled Tasks - Run periodic scraping or monitoring jobs
- API Endpoints - Expose browser automation via REST APIs
- CI/CD Pipelines - Automate testing and validation workflows
- Data Collection - Extract structured data from websites
- Form Submissions - Automate repetitive form-filling tasks
Notes
- Functions have a maximum execution time of 15 minutes
- Invocations automatically create a Browserbase session each time they’re invoked
- Functions don’t support persistent storage across invocations
- Custom NPM packages must be bundled with your functions code. We don’t support accessing private NPM packages
For long-running or interactive sessions, consider using standard Browserbase sessions instead of functions.
Next Steps
Functions Reference
Learn more about Functions configuration and best practices