1

Get your API Key

Go over the Dashboard’s Settings tab:

Copy your API Key and Project ID from the input fields, then update your .env file by adding entries for BROWSERBASE_API_KEY and BROWSERBASE_PROJECT_ID.

Alternatively, you can temporarily set the environment variables for a single bash command by prefixing it with BROWSERBASE_API_KEY=<your_api_key> BROWSERBASE_PROJECT_ID=<your_project_id> in your terminal.

2

Install Selenium

npm i selenium-webdriver @browserbasehq/sdk
3

Update your code or clone a template

Running your existing code with Browserbase only requires a few line changes:

import http from "http";
import { Builder } from "selenium-webdriver";
import BrowserBase from "@browserbasehq/sdk";

const bb = new Browserbase({
  apiKey: process.env.BROWSERBASE_API_KEY as string,
});

(async () => {
  const session = await bb.sessions.create({
    projectId: process.env.BROWSERBASE_PROJECT_ID as string,
  });

  const customHttpAgent = new http.Agent({});
  (customHttpAgent as any).addRequest = (req: any, options: any) => {
    req.setHeader("x-bb-signing-key", session.signingKey);
    (http.Agent.prototype as any).addRequest.call(customHttpAgent, req, options);
  };

  const driver = new Builder()
    .forBrowser("chrome")
    .usingHttpAgent(customHttpAgent)
    .usingServer(
      session.seleniumRemoteUrl
    )
    .build();

  await driver.get("https://www.browserbase.com");

  // Make sure to quit the driver so your session is ended!
  await driver.quit();
})().catch((error) => console.error(error.message));
Be sure to set your BROWSERBASE_API_KEY and BROWSERBASE_PROJECT_ID environment variables to the values you copied from the Dashboard.

4

Inspect the completed Session

You can find all the recent sessions on the Dashboard’s Overview, along with essential metrics:

Select your Session to inspect it with the Session Inspector.

Start building