Overview

Stagehand is an AI-native framework for building browser agents in JavaScript.

Stagehand is designed to be a seamless extension of Playwright, and in particular, its Page API.

Thanks to Laminar’s native integration with Playwright, you can trace your Stagehand agents with ease.

Usage

1

Initialize Laminar

First, we need to initialize Laminar and pass the Stagehand module to instrumentModules.

import { Stagehand } from '@browserbase/stagehand';
import { Laminar } from '@lmnr-ai/lmnr';

Laminar.initialize({
  projectApiKey: process.env.LMNR_API_KEY,
  instrumentModules: {
    stagehand: Stagehand,
  },
});
2

Using Stagehand

You can now use the Stagehand API as usual.

const stagehand = new Stagehand();
await stagehand.init({
  modelName: 'gpt-4.1-mini',
  modelClientOptions: {
    apiKey: process.env.OPENAI_API_KEY,
  },
});

const page = stagehand.page;
await page.act("...");
3

Finalizing Stagehand traces

In order to finalize Stagehand traces, make sure to call stagehand.close() and Laminar.flush(), especially if you are using Laminar and Stagehand in standalone scripts or edge runtimes.

await stagehand.close(); // closes the browser and the parent span
await Laminar.flush(); // sends any remaining spans to Laminar

Example result

An example trace for page.act('go to Laminar blogs page')