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
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
For advanced users or custom integrations, specify Session TTL in the WebSocket URL using the Duration String Examples:
session_ttl
parameter with duration strings.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)
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
- Multi-page navigation
- Workflows with several steps
- Moderate data collection
- Most general scraping
- 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
Node.js
Session TTL + World Region Targeting
Node.js
Direct WebSocket with Multiple Parameters
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: Use for most projects and handles sessions automatically
- Direct WebSocket: Use for custom frameworks or specific control
- Monitor session usage in the ZenRows dashboard
- Log session start/end times
- Use proper durations to avoid premature expiry
Node.js
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
- TTL must be 60-900 seconds in SDK
- Use valid duration strings (1m, 2m, etc.) for WebSocket
- Match TTL to workflow
- Always close browser connections properly
- Handle session expiration errors
- Monitor usage in the Analytics dashboard
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
- Explore World Region Targeting
- See the ZenRows SDK Repository for advanced features and examples
- Review the Practical Use Cases for real world examples