Prerequisites
Vercel: A developer infrastructure platform that lets you build, deploy, and scale. Vercel owns & maintains Next.js, one of the most popular frontend frameworks, allowing you to build applications completely out-of-box without additional configuration. Browserbase: A headless browser infrastructure platform that provides ready-to-use browsers out of the box. This includes observability, proxies, Verified, and additional debugging tools for your automation scripts. Browsers are essential for interacting with the web, and Browserbase simplifies this process by managing multiple browser sessions and providing debugging capabilities from the start. Puppeteer: A Node library that provides a high-level API to control Chrome or Chromium over the DevTools Protocol. Puppeteer runs headless by default but can be configured to run a full version of Chrome or Chromium.Step 1: Setting up your project
First, you’ll need to create a Browserbase account. You can sign up for a free account here. You’ll also need a Vercel account, of which you can sign up for a free account here. Now, create a Next.js app through the CLI. This project is calledvercel-automation.
Install packages
Install Browserbase’s Node.js SDK, Stagehand AI SDK, Zod for data validation, and Prettier for formatting.Managing API keys
Be sure to add environment variables for this project. You’ll need a Browserbase API key. You can get it from the Browserbase Settings.Step 2: Using Next.js route handlers
Next.js Route Handlers let you create custom API endpoints that process HTTP requests and return web content through APIs, directly within your application.- Next.js provides helper classes
NextRequestandNextResponseto simplify working with native Request/Response APIs. - Route Handlers are exclusively available within the
appdirectory.
HTML
Create the first route handler for retrieving HTML. Create anhtml directory in the app/api folder. To create an endpoint, add a route.ts file that handles the API requests. Use the GET method to retrieve HTML content from a specified URL.
Here’s the code for the first route handler:
Screenshots
For the second route handler, create a new browser session with a specified viewport, navigate to the URL, and screenshot the screen. Createscreenshot/route.ts and use the following code to enable screenshot abilities.
Form inputs
Puppeteer can be a bit cumbersome for form interactions. For the Form API route handler, the example uses Stagehand, an AI SDK. Stagehand simplifies complex browser interactions by letting you use plain English. Stagehand consists of three main functions:Act, Extract, and Observe.
In this example, Stagehand is initialized with Browserbase credentials and an LLM model to efficiently fill out a sample form, rather than writing a more complex Puppeteer script.
Below is the same web automation task, comparing the Puppeteer and Stagehand implementations.
If you’re using Stagehand, you’ll need to set up an LLM provider. Be sure to include the environment variable for your LLM provider in your
.env file.Testing the API endpoints
Now that the three route handlers are implemented in the Next.js app, test the API endpoints.-
Start the development server:
-
Access the API at the base URL:
http://localhost:3000/api -
Test each endpoint by navigating to:
http://localhost:3000/api/htmlhttp://localhost:3000/api/screenshothttp://localhost:3000/api/form
200 status code when working correctly.
Step 3: Deploying to Vercel
Finally, after testing the API endpoints locally, deploy to Vercel:- Sign in to Vercel
- Click “Add New…” → “Project”
- Connect and select your repository
- Add any environment variables
- Click “Deploy”
- Once complete, you’ll get a deployment URL
Deploying with fluid compute

Why Fluid Compute for browser automations
For your route handlers connecting to Browserbase’s headless browser infrastructure, Fluid Compute offers key benefits:- Performance optimization - Route handlers that orchestrate complex browser automations remain responsive under load, with warm mini-servers eliminating cold start delays when initiating browser sessions
- Optimized concurrency - Multiple function invocations share a single instance, allowing concurrent processing while some requests wait for Browserbase responses, eliminating idle resource waste
- Extended, efficient runtimes - Complex automation workflows that would timeout in standard serverless functions complete successfully, while you only pay when your route handlers are processing requests
How to enable Fluid Compute
- Go to your project settings in Vercel
- Select Functions from the left navigation menu
- Toggle the Fluid compute button to enable it
- Click Save
- Redeploy your project
