Skip to main content
A Browserbase Function is TypeScript code that runs next to a Browserbase browser. You write the browser logic, publish it, and invoke it through an API. Functions run your code next to the browser and deploy instantly, with under 5ms latency to the browser. Browserbase creates a browser session for each invocation, gives your code the session’s connection URL, and closes the session when your code finishes. Your Function returns a JSON value that you retrieve through the Functions API.
Functions are currently only available in the us-west-2 region.

How a Function works

You define a Function with defineFn, then publish its entrypoint:
  1. The publish command builds your code and creates a Function version.
  2. An invoke request starts an asynchronous invocation.
  3. Browserbase creates a headless browser.
  4. Your handler connects to that browser through context.session.connectUrl.
  5. Browserbase stores the handler’s result, logs, and session ID.
Your code doesn’t send every browser action back to a separate service. Invocations and builds are asynchronous. Subscribe to Function webhook events instead of polling: Browserbase POSTs functions.invocations.* and functions.builds.* events to your endpoint when status changes. See the webhook example for a complete receiver.

Why use a Function?

A browser script that runs on your machine already contains the hard part: the logic that navigates pages and completes work. Production adds a process to run the script, an API to trigger it, and browser lifecycle management for every run. Functions provide that execution layer. Publish your existing Stagehand, Playwright, or Puppeteer code, then invoke it from a webhook, backend, queue worker, or scheduled job. Browserbase manages the browser session and records it for debugging. Use a Function when:
  • You need deterministic browser logic that you own.
  • You want to invoke that logic through an HTTP API.
  • Your code needs low-latency access to a Browserbase browser.
  • You want Browserbase to manage browser creation and cleanup for each run.

What runs inside a Function?

Functions support TypeScript code that uses the browser library you already know:
  • Stagehand adds natural language actions and structured extraction to browser code.
  • Playwright gives you deterministic browser control.
  • Puppeteer connects through the same browser session URL.
The handler receives the browser connection details and any parameters from the invoke request:
Node.js
You can run the Function with the local development server before you publish it. Production invocations use the same handler, but run asynchronously on Browserbase.

Functions quickstart

Build, test, publish, and invoke your first Function.

Write a Function

Define parameters, browser settings, and multiple Functions.

Invoke a Function

Pass parameters, override session settings, and get results.

Deploy Functions

Publish from the CLI or the Playground.

Functions limits

Check bundle, timeout, storage, and region constraints.

Functions API reference

Look up the invoke request, response, and session override schema.

Function webhooks

Get invocation and build events delivered to your endpoint.

Webhook example

Register an endpoint and handle Function invocation events.