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

> ## Agent Instructions
> The Zenrows HTTP API serves Fetch and Extract (extract=auto) at https://api.zenrows.com/v1/, Crawl at https://api.zenrows.com/v1/crawls, and Batch at https://async.api.zenrows.com/v1. Fetch, Extract, Crawl and Batch are described in OpenAPI 3.1 at https://www.zenrows.com/openapi.json and listed in the RFC 9727 API catalog at https://www.zenrows.com/.well-known/api-catalog. Every endpoint also has its own page under /api-reference with its schema. Use the spec for exact parameter names and types. Crawl's endpoints, parameters and errors are also at https://docs.zenrows.com/crawl/endpoints.md. To call Zenrows from an agent, connect the MCP server at https://mcp.zenrows.com/mcp. To search these docs from an agent, connect the docs MCP server at https://docs.zenrows.com/mcp. Agent skills for Zenrows are published at https://github.com/ZenRows/cli and install with `npx skills add ZenRows/cli`.

# Session TTL Configuration for the Zenrows Browser

> Set and customize Session TTL to manage how long your Zenrows Browser sessions stay active, from 1 to 15 minutes maximum.

The Zenrows Browser (formerly, Scraping Browser) lets you control the duration of your browser sessions with Session TTL (Time To Live) configuration. This is crucial for managing resource usage, maintaining session consistency, and optimizing scraping workflows.

## What is Session TTL?

Session TTL (Time To Live) controls how long a browser session stays active before terminating. Think of it as a timer for your scraping session after the time expires, the session closes automatically, freeing up resources and ensuring clean session management.

**Why Session TTL matters:**

* **Resource Management:** Prevents sessions from running indefinitely
* **Cost Control:** Helps manage usage costs by auto-terminating idle sessions
* **Session Consistency:** Maintains stable connections for multi-step workflows
* **Workflow Optimization:** Lets you match session duration to your scraping needs

> [!NOTE]
>
> The default Session TTL is 3 minutes (180 seconds), which works well for most tasks. You can customize this between 1 minute (60 seconds) and 15 minutes (900 seconds).

## How to Configure Session TTL

You can configure Session TTL in two ways:

* **Zenrows SDK:** Recommended for most users (simple, robust)
* **Direct WebSocket URL:** For advanced or custom integrations

> [tab] Puppeteer
>
> For advanced users or custom integrations, specify Session TTL in the WebSocket URL using the `session_ttl` parameter with duration strings.
>
> ```bash theme={"theme":"css-variables"}
> wss://browser.zenrows.com?apikey=YOUR_ZENROWS_API_KEY&session_ttl=2m
> ```
>
> **Duration String Examples:**
>
> * `1m` - 1 minute (60 seconds)
> * `2m` - 2 minutes (120 seconds)
> * `5m` - 5 minutes (300 seconds)
> * `10m` - 10 minutes (600 seconds)
> * `15m` - 15 minutes (900 seconds - max)
>
> ```javascript Node.js theme={"theme":"css-variables"}
> const puppeteer = require('puppeteer-core');
> const wsUrl = 'wss://browser.zenrows.com?apikey=YOUR_ZENROWS_API_KEY&session_ttl=5m';
> (async () => {
>     const browser = await puppeteer.connect({ browserWSEndpoint: wsUrl });
>     const page = await browser.newPage();
>     await page.goto('https://example.com');
>     await browser.close();
> })();
> ```
>
> ```python Python theme={"theme":"css-variables"}
> import asyncio
> from pyppeteer import connect
>
> async def main():
>     ws_url = 'wss://browser.zenrows.com?apikey=YOUR_ZENROWS_API_KEY&session_ttl=5m'
>     browser = await connect(browserWSEndpoint=ws_url)
>     page = await browser.newPage()
>     await page.goto('https://example.com')
>     await browser.close()
>
> asyncio.get_event_loop().run_until_complete(main())
>
> ```

> [tab] Playwright
>
> For advanced users or custom integrations, specify Session TTL in the WebSocket URL using the `session_ttl` parameter with duration strings.
>
> ```bash theme={"theme":"css-variables"}
> wss://browser.zenrows.com?apikey=YOUR_ZENROWS_API_KEY&session_ttl=2m
> ```
>
> **Duration String Examples:**
>
> * `1m` - 1 minute (60 seconds)
> * `2m` - 2 minutes (120 seconds)
> * `5m` - 5 minutes (300 seconds)
> * `10m` - 10 minutes (600 seconds)
> * `15m` - 15 minutes (900 seconds - max)
>
> ```javascript Node.js theme={"theme":"css-variables"}
> const { chromium } = require('playwright');
> const wsUrl = 'wss://browser.zenrows.com?apikey=YOUR_ZENROWS_API_KEY&session_ttl=5m';
> (async () => {
>     const browser = await chromium.connectOverCDP(wsUrl);
>     const page = await browser.newPage();
>     await page.goto('https://example.com');
>     await browser.close();
> })();
> ```
>
> ```python Python theme={"theme":"css-variables"}
> import asyncio
> from playwright.async_api import async_playwright
>
> async def main():
>     ws_url = 'wss://browser.zenrows.com?apikey=YOUR_ZENROWS_API_KEY&session_ttl=5m'
>     async with async_playwright() as p:
>         browser = await p.chromium.connect_over_cdp(ws_url)
>         page = await browser.new_page()
>         await page.goto('https://example.com')
>         await browser.close()
>
> asyncio.run(main())
> ```

> [tab] Zenrows SDK
>
> The Zenrows SDK offers the most user-friendly way to configure Session TTL, featuring automatic session management and error handling.
>
> ```javascript Node.js Puppeteer theme={"theme":"css-variables"}
> const { ScrapingBrowser } = require('@zenrows/scraping-browser');
> const puppeteer = require('puppeteer-core');
>
> (async () => {
>     const scrapingBrowser = new ScrapingBrowser({ apiKey: 'YOUR_ZENROWS_API_KEY' });
>     // 2-minute session
>     const connectionURL = scrapingBrowser.getConnectURL({ sessionTTL: 120 });
>     const browser = await puppeteer.connect({ browserWSEndpoint: connectionURL });
>     const page = await browser.newPage();
>     await page.goto('https://example.com');
>     await browser.close();
> })();
> ```
>
> ```javascript Node.js Playwright theme={"theme":"css-variables"}
> const { ScrapingBrowser } = require('@zenrows/scraping-browser');
> const { chromium } = require('playwright');
>
> (async () => {
>     const scrapingBrowser = new ScrapingBrowser({ apiKey: 'YOUR_ZENROWS_API_KEY' });
>     // 5-minute session
>     const connectionURL = scrapingBrowser.getConnectURL({ sessionTTL: 300 });
>     const browser = await chromium.connectOverCDP(connectionURL);
>     const page = await browser.newPage();
>     await page.goto('https://example.com');
>     await browser.close();
> })();
> ```
>
> **SDK Configuration Examples:**
>
> ```javascript theme={"theme":"css-variables"}
> // 1-minute session
> const quickSession = scrapingBrowser.getConnectURL({ sessionTTL: 60 });
> // 5-minute session
> const mediumSession = scrapingBrowser.getConnectURL({ sessionTTL: 300 });
> // 15-minute session (maximum)
> const longSession = scrapingBrowser.getConnectURL({ sessionTTL: 900 });
> ```

## Choosing the Right Session TTL

**Session Duration Guidelines:**

**1-2 Minutes (60-120 seconds):**

* Quick data extraction from single pages
* Simple form submissions
* Basic content scraping
* Testing and development

**3-5 Minutes (180-300 seconds):**

* Multi-page navigation
* Workflows with several steps
* Moderate data collection
* Most general scraping

**10-15 Minutes (600-900 seconds):**

* Complex multi-step workflows
* Large-scale extraction
* User interaction simulation
* Long-running automation

## Combining Session TTL with Other Features

Session TTL works seamlessly with other Zenrows features for advanced scraping setups.

### Session TTL + Country Targeting

```javascript Node.js theme={"theme":"css-variables"}
const connectionURL = scrapingBrowser.getConnectURL({
    sessionTTL: 300, // 5 minutes
    proxy: { location: ProxyCountry.ES },
});
```

### Session TTL + World Region Targeting

```javascript Node.js theme={"theme":"css-variables"}
const connectionURL = scrapingBrowser.getConnectURL({
    sessionTTL: 600, // 10 minutes
    proxy: { location: ProxyRegion.Europe },
});
```

### Direct WebSocket with Multiple Parameters

```bash theme={"theme":"css-variables"}
wss://browser.zenrows.com?apikey=YOUR_API_KEY&session_ttl=8m&proxy_country=us
```

## Best Practices

**Optimize for Your Workflow:**

* Match session duration to your scraping needs
* Add a small buffer (30-60 seconds) for delays
* Use shorter sessions for simple tasks

**SDK vs Direct Connection:**

* **SDK:** Use for most projects and handles sessions automatically
* **Direct WebSocket:** Use for custom frameworks or specific control

**Monitoring and Debugging:**

* Monitor session usage in the Zenrows dashboard
* Log session start/end times
* Use proper durations to avoid premature expiry

**Error Handling:**

```javascript Node.js theme={"theme":"css-variables"}
try {
    const browser = await puppeteer.connect({ browserWSEndpoint: connectionURL });
    // Your scraping code
} catch (error) {
    if (error.message.includes('session expired')) {
        console.log('Session TTL expired, consider increasing duration');
    }
    // Other errors
}
```

## Troubleshooting

**Common Issues and Solutions:**

**Session Expires Too Quickly:**

* Increase sessionTTL for more time
* Monitor execution time and add buffer
* Break long workflows into smaller sessions

**Invalid TTL Values:**

* TTL must be 60-900 seconds in SDK
* Use valid duration strings (1m, 2m, etc.) for WebSocket
* Match TTL to workflow

**Session Management Issues:**

* Always close browser connections properly
* Handle session expiration errors
* Monitor usage in the Analytics dashboard

  [Open Analytics](https://app.zenrows.com/overview?product=browser#performance)

> [!TIP]
>
> The sessionTTL parameter uses seconds with the SDK (e.g., 120 for 2 min) and duration strings for direct WebSocket (e.g., "2m").

## Next Steps

* Learn about [Country Targeting](https://docs.zenrows.com/browser-sessions/features/country.md)
* Explore [World Region Targeting](https://docs.zenrows.com/browser-sessions/features/world-region.md)
* See the [Zenrows SDK Repository](https://github.com/ZenRows/browser-js-sdk) for advanced features and examples
* Review the [Practical Use Cases](https://docs.zenrows.com/browser-sessions/help/practical-use-cases.md) for real world examples


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.