> ## Documentation Index
> Fetch the complete documentation index at: https://docs.browserbase.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Manage a browser session

> Learn how to manage session termination and inspect completed sessions

While Browserbase automatically handles session termination when you disconnect, understanding how sessions end helps you debug failed runs, manage long-running sessions, optimize resource usage, and investigate timeouts or errors.

## Session termination

Browser sessions can end in these ways:

1. **Automatic timeout**
   Sessions have a default timeout configured at the project level, which can be customized when creating a session. For longer-running tasks, enable [keep alive](/platform/browser/long-sessions/overview).

2. **Manual termination**
   You can end sessions explicitly by closing the browser programmatically (`browser.close()` or `driver.quit()`), using the Sessions API, or releasing keep-alive sessions when no longer needed.

3. **Unhandled errors**
   Unhandled errors in your automation code can cause your script to disconnect from the browser, ending the session prematurely. Common scenarios include network interruptions, uncaught exceptions, or exceeded resource limits.

   To prevent premature termination, make sure to implement proper error handling and cleanup in your code.

4. **CDP inactivity timeout**
   CDP (Chrome DevTools Protocol) connections are closed after 10 minutes without any CDP commands. If your script holds a session open without sending CDP commands for this period, the connection will be terminated.

   To keep the connection alive, send a periodic heartbeat — a lightweight CDP command at a regular interval:

   <CodeGroup>
     ```javascript Node.js theme={null}
     // Send a heartbeat every 5 minutes to prevent CDP inactivity timeout
     setInterval(async () => {
       await page.evaluate(() => undefined);
     }, 5 * 60 * 1000);
     ```

     ```python Python theme={null}
     import asyncio

     # Send a heartbeat every 5 minutes to prevent CDP inactivity timeout
     async def heartbeat(page):
         while True:
             try:
                 await asyncio.sleep(5 * 60)
                 await page.evaluate("undefined")
             except Exception:
                 break

     asyncio.create_task(heartbeat(page))
     ```
   </CodeGroup>

## Session timeout settings

Configure timeouts at two levels:

**Project level**
Set the default timeout for all sessions in your [project settings](https://browserbase.com/settings). This acts as the fallback when no session-specific timeout is set.

**Session level**
Override the project timeout for specific sessions when [creating them](/platform/browser/getting-started/create-browser-session#configuration-options). This gives you fine-grained control over individual session durations.

## Debugging completed sessions

The [Session Inspector](/platform/browser/observability/observability) is your primary tool for analyzing completed sessions:

<CardGroup>
  <Card title="Session Recordings" icon="play" href="/platform/browser/observability/session-recording">
    Record and replay browser activity to understand what happened
  </Card>

  <Card title="Network Monitor" icon="wifi" href="/platform/browser/observability/observability#network">
    Inspect HTTP traffic, responses, and timing
  </Card>

  <Card title="Console & Logs" icon="terminal" href="/platform/browser/observability/observability#console">
    Review JavaScript output and debug messages
  </Card>

  <Card title="Performance" icon="gauge-high" href="/platform/browser/observability/observability#performance">
    Track CPU, memory usage, and other metrics
  </Card>
</CardGroup>

## Measuring usage

Track and analyze your browser session usage through multiple interfaces:

**Dashboard**
Your central hub at [browserbase.com/overview](https://browserbase.com/overview) shows total browser minutes, active sessions, usage trends, and billing information.

**Sessions list**
Browse your session history at [browserbase.com/sessions](https://browserbase.com/sessions) to view duration, status, and resource consumption for individual sessions.

For programmatic access to these metrics, see the [Measuring Usage Guide](/optimizations/cost/measuring-usage).
