Skip to main content

Overview

The keepAlive feature allows you to keep sessions alive across disconnects, permitting you to reconnect and continue using the same session. By default, Browserbase sessions terminate when a developer disconnects. With Keep Alive enabled, the session remains available for reconnection using the same connection URL.
Session keep alive is only available on paid plans.

Why use Keep Alive?

  • Survive disconnects: Network issues or client restarts won’t terminate your session
  • Reconnect to existing sessions: Continue where you left off without starting fresh
  • Reuse sessions for performance: Reconnecting is faster than creating a new session

Creating a Keep Alive Session

Setting keepAlive to true will keep the session available for later use. You can reconnect to the session using the same connection URL.
import Browserbase from "browserbase";

const bb = new Browserbase({ apiKey: process.env.BROWSERBASE_API_KEY! });
const session = await bb.sessions.create({
  projectId: process.env.BROWSERBASE_PROJECT_ID!,
  keepAlive: true,
});

console.log("Session ID:", session.id);
// Reconnect later using the same session ID

Stopping a Keep Alive Session

Keep alive sessions must be explicitly stopped when you’re done with them. Use the API or SDK to release the session.
import Browserbase from "browserbase";

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

// Stop the session by setting status to REQUEST_RELEASE
await bb.sessions.update(session.id, {
  status: "REQUEST_RELEASE",
  projectId: process.env.BROWSERBASE_PROJECT_ID!,
});
We recommend stopping keep alive sessions explicitly when no longer needed. They will eventually time out, but you will be charged for all browser minutes used.

Keep Alive and Timeouts

Keep alive sessions still respect session timeouts. If you need a session that both survives disconnects and runs for an extended period, configure both options:
const session = await bb.sessions.create({
  projectId: process.env.BROWSERBASE_PROJECT_ID!,
  keepAlive: true,
  timeout: 3600, // 1 hour
});

Session Timeouts

Learn how to extend session duration beyond the default timeout.