Skip to main content

Overview

By default, Browserbase sessions have a timeout period after which they automatically terminate — this prevents sessions from running forever unexpectedly. You can extend this duration either project-wide or per-session, allowing you to keep working without worrying about the session timing out.
The maximum session duration is 6 hours. When a session times out, you’ll see a TimeoutError: Timeout _____ms exceeded.

Project Wide Timeout

You can change the default session timeout for all sessions in your project through the dashboard settings.

Per Session Timeout

You can also set a custom timeout through code by specifying the timeout option in the API request body or with the SDK. This is useful when different sessions need different timeouts, or when you need more granular control than the dashboard toggle provides.
The examples below set timeout to 3600 seconds (1 hour), overriding the project default. Unless explicitly closed beforehand, the session will continue running for an hour before terminating. At disconnect, it will end.
import Browserbase from "browserbase";

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

// Creates a session with a timeout of 3600 seconds (1 hour)
const session = await bb.sessions.create({
  projectId: process.env.BROWSERBASE_PROJECT_ID!,
  timeout: 3600,
});

Timeouts and Keep Alive

Setting a custom timeout extends how long a session can run, but the session will still terminate when you disconnect. If you need to disconnect and reconnect to the same session, use Keep Alive instead. For sessions that need both extended duration and reconnection support, configure both options:
const session = await bb.sessions.create({
  projectId: process.env.BROWSERBASE_PROJECT_ID!,
  keepAlive: true,
  timeout: 3600, // 1 hour
});

Keep Alive

Learn how to keep sessions alive across disconnects.