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
Function Name - Unique identifier for your function (used in the “invoke function” HTTP request)
Handler - Async function that receives:
ctx - Context object with session information
params - Parameters passed when invoking the function
Options - Optional configuration object for session settings
Make sure that you give each function in your codebase a unique name! Function names are unique per project.
The name parameter serves as a function’s “Logical ID” (a unique, human-friendly identifier), meaning
reusing a name string could lead to overwriting an existing built function with the same name.
Most session creation options are supported in sessionConfig. See the Create Session API Reference for the full list of available options including proxies, stealth mode, viewports, contexts, and extensions.
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.
Access these parameters in your function handler via the params argument:
Copy
Ask AI
defineFn("my-function", async (ctx, params) => { const { url, selector } = params; // Use parameters in your automation});
Pipe the curl output to jq for human-readable JSON formatting:
Copy
Ask AI
curl -X POST http://127.0.0.1:14113/v1/functions/my-function/invoke \ -H "Content-Type: application/json" | jq
The local development server runs your function synchronously and returns the result directly in the HTTP response. This differs from production, where invocations are asynchronous and require polling for results.
Both functions will be deployed when you run pnpm bb publish index.ts.
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.
Unhandled errors will be caught by our runners and reported as an error. If you want to gracefully
handle your errors (for example, return information on the failure), wrap your automation code in try-catch blocks:
Secrets management for Functions environments is coming soon! This will allow you to securely store and
access sensitive values like API keys, tokens, and credentials within your deployed functions without
passing them as parameters.
Availability: Support for Secrets is a top priority on our current roadmap.
This feature is not yet available in beta; contact us at support@browserbase.com to get
on the waitlist and stay tuned for the latest updates.