Overview

A Session in web automation represents a single browser instance from connection to termination—closure, timeout, or disconnection, running in isolated environments to ensure resource exclusivity, thereby maintaining stability and performance.

These sessions are highly configurable through APIs, allowing for adjustments to settings such as viewport size and user agents via fingerprinting.

This customization is crucial for accurately simulating various user behaviors and conducting cross-platform testing.

Sessions also support on-the-fly file downloads and can be easily started with automation tools like Playwright, Puppeteer, or Selenium, or pre-configured using a Session API, offering flexibility and control for developers.

Browser configuration

Sessions run on fast instances with isolated resources (storage, network, memory, and vCPUs).

The viewport, user agents, and header configuration are handled by the fingerprint mechanism.

Downloads are enabled and stored by default, accessible via the API.

Sessions

Starting a Session

A Session is either created on the fly, upon connection (via connectOverCDP() or puppeteer.connect()), or via the Sessions API.

Once created, connect to a Session through a Driver (Playwright, Puppeteer, or Selenium) or via the Session Inspector.

import { chromium } from "playwright-core";

(async () => {
  const browser = await chromium.connectOverCDP(
    `wss://connect.browserbase.com?apiKey=${process.env.BROWSERBASE_API_KEY}`,
  );
  const defaultContext = browser.contexts()[0];
  const page = defaultContext.pages()[0];

  await page.goto("https://www.browserbase.com");

  await page.close();
  await browser.close();
})().catch((error) => console.error(error.message));

You must connect to a Session within the timeout supplied during creation or the default timeout of your project.

Session timeout

Sessions time out when running for longer than the timeout configured in your Project’s Settings:

To keep sessions alive upon disconnections, provide the keepAlive param when creating a new Session and stop the session manually:

import { Browserbase } from "@browserbasehq/sdk";

// Initialize the client
const browserbase = new Browserbase();

// Create a session with `keepAlive` set to `true`
const session = await browserbase.createSession({
keepAlive: true,
});

await browserbase.stopSession(session.id)

If you don’t stop sessions manually and just wait for them to time out, you’ll be charged for all the browser minutes used. Be efficient by stopping sessions when you’re done with them.

Inspecting a Session

You can inspect a completed Session using the Session API or the Session Inspector:

ActionSession InspectorSessions API
Access logsSessions API logs endpoint
Access ChromeDevTools data (ex: network, DOM events)Sessions API logs endpoint
Access recordingSessions API recording endpoint
Retrieve downloaded filesSessions API downloads endpoint
Session Live ViewSessions API Live URLs endpoint
Access memory and CPUs usage