Overview
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. 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
Quick start
Ready to deploy? Follow the step-by-step guide to deploy your first Function.
Getting started
The easiest way to get started is using the CLI to scaffold a new project:- A configured
package.jsonwith required dependencies - A
tsconfig.jsonfor TypeScript support - A template
.envfile for your credentials - A starter
index.tsfile with an example function
.env file:
Get your API key and Project ID from the Browserbase Dashboard Settings.
Defining Functions
Basic Function
Function parameters
- Function Name - Unique identifier for your function (used in the “invoke function” HTTP request)
- Handler - Async function that receives:
ctx- Context object with session informationparams- Parameters passed when invoking the function
- Options - Optional configuration object for session settings
Context object
Thectx parameter provides access to the browser session:
Function response
Return any JSON-serializable data from your function:Session configuration
Configure browser session settings using the third parameter:Most session creation options are supported in
sessionConfig. See the Create Session API Reference for the full list of available options including proxies, Verified, viewports, contexts, and extensions.Complete example
Here’s a full example that fills out a contact form:Local development
Before publishing, you can test your functions locally using the development server. This creates real Browserbase sessions using your credentials, ensuring your function behaves the same locally and in production.Start the development server
http://127.0.0.1:14113 and watches for file changes, automatically reloading when you modify your function files.
Invoke Functions locally
Pass parameters locally
The local development server runs functions synchronously and returns results directly. Production invocations are async and require polling.
Publishing Functions
Single file
Multiple files
Import other function files into your entrypoint:index.ts
The
publish command requires an entrypoint file. All functions must be defined in or imported by that file.Invoking Functions
Get build result
Invoke with parameters
Poll for results
Function invocations are async. Poll the invocation endpoint untilstatus is COMPLETED:
Best practices
- Wrap automation code in
try/catchand return error shapes rather than letting errors propagate unhandled - Use
console.log/console.errorfor debugging — logs are captured in invocation logs - Sessions close automatically when your function completes; no manual cleanup needed
Monitoring and debugging
Every invocation creates a browser session you can inspect in the Session Inspector:- Session replays
- Console logs
- Network activity
- Performance metrics
Limitations
- Maximum execution time: 15 minutes
- No persistent storage between invocations
- TypeScript only (no Python support)
- Private NPM packages are not supported