Prerequisites
You need:- A Browserbase account
- A Browserbase API key from Settings
- Node.js and pnpm
Create a Functions project
1
Initialize the project
Run the Functions initializer:The initializer creates
package.json, tsconfig.json, .env, and a starter index.ts.2
Add your Browserbase API key
Add your API key to Browserbase resolves the project from the API key. You don’t need a Project ID.
.env:3
Define the Function
Replace
index.ts with a Function that returns the title of a page:Node.js
Test the Function locally
1
Start the development server
Run:The server listens on
http://127.0.0.1:14113 and reloads when you change the Function files.2
Invoke the local Function
In another terminal, invoke the Function by the name passed to The local server runs the handler synchronously. The response contains:
defineFn:Publish the Function
Publish the entrypoint:index.ts and prints the Function IDs. Save the ID for page-title. See Deploy Functions for multi-file projects.
Invoke the deployed Function
Production invocations run asynchronously. Start an invocation with the Function ID:202 Accepted with an invocation object. Copy its id, then poll the invocation:
status is COMPLETED, results contains the value returned by the handler.
Next steps
Write a Function
Configure parameters, browser sessions, and multiple Functions.
Deploy Functions
Publish from the CLI or the Playground.
Invoke a Function
Override session settings and handle asynchronous results.