How are sessions terminated?
By default, Browserbase sessions automatically terminate in two scenarios:- When a developer disconnects from the session
- When the session reaches its default timeout period
| Property | Description |
|---|---|
| Keep Alive | Allowing you to reconnect to the same session after a disconnect |
| Custom Timeout | Extending the lifetime of a session beyond its default timeout period |
Session keep alive is only available on paid plans.
Why keep sessions alive?
Custom timeouts and session keep alive supports a broad spectrum of use cases. Key benefits include:- Avoid interrupting long-running tasks and workflows.
- Connect, disconnect, and reconnect to the same session.
- Keep working with a session without worrying about it timing out.
- Reusing existing sessions is more performant than creating new ones.
Keep Alive Sessions
ThekeepAlive feature allows you to keep sessions alive across disconnects, permitting you to continue using it as long as needed.
Create a Keep Alive Session
SettingkeepAlive to true will keep the session available for later use. You can reconnect to the keep alive session using the same connection URL as the original session.
Let’s walk through an example of how to keep a session alive:
- Node.js
- Python
SDK
Stop a Keep Alive Session
In order to stop the session, use the Browserbase API or the SDK as shown here:- Node.js
- Python
We recommend that you stop your keep alive sessions explicitly when no longer
needed. They will time out eventually, but you may be charged for the unneeded
browser minutes used.
Session Timeouts
After the script is past the default timeout, we’ll see aTimeoutError: Timeout _____ms exceeded
Browserbase has a project wide settings for session timeout. We can change to session timeout project wide to a different value in the toggle.


Custom session timeout
We can also set a custom timeout for a created session through code. If you’d like to set a custom timeout that isn’t shown in the toggle, you can set a custom timeout in thecreateSession function.
To set a custom timeout for your session, specify the timeout option in the API request body or
with the SDK.
- Node.js
- Python
The maximum duration of a session is 6 hours. Once a session times out, it can
no longer be used.