Normally sessions being the shut down process on disconnect. But you can change this behavior so that sessions stay alive till they either timeout or you stop them manually.

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

To keep sessions alive on disconnect, during session creation, specify the keepAlive option as true. Here’s an example using our Node.js SDK:

import browserbase from "browserbase";

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

// Create a session with `keepAlive` set to `true`
const session = await bb.sessions.create({
  projectId: process.env.BROWSERBASE_PROJECT_ID!,
  keepAlive: true,
});

Now connect to the session and perform work as usual. When you disconnect, the session will stay alive. You can reconnect before the session times out and perform more work. When you’re done, make sure to stop the session:

await bb.sessions.update(session.id, {
  projectId: process.env.BROWSERBASE_PROJECT_ID!,
  status: "REQUEST_RELEASE",
});