How a Function works
You define a Function withdefineFn, then publish its entrypoint:
- The publish command builds your code and creates a Function version.
- An invoke request starts an asynchronous invocation.
- Browserbase creates a headless browser.
- Your handler connects to that browser through
context.session.connectUrl. - Browserbase stores the handler’s result, logs, and session ID.
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.
Node.js
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.