-
Notifications
You must be signed in to change notification settings - Fork 979
Open
Description
Issue Description
When using --user-data-dir parameter with Browserless v2 in Docker, each new connection creates a new browser session instead of reusing the existing one with the same userDataDir. This prevents data persistence (localStorage, cookies, login sessions) between connections.
Environment
- Browserless Version: v2 (self-hosted Docker)
- Docker Setup: Standard containerized deployment
- Connection Method: WebSocket via puppeteer-extra
- Endpoint Format:
ws://host/?token=xxx&--user-data-dir=/tmp/session-name&launch={...}
Expected Behavior
- First connection creates session with userDataDir
/tmp/session-1 - Save data (localStorage, cookies) in the session
- Disconnect from session (session remains active)
- Second connection with same userDataDir should reuse existing session
- Data should persist and be accessible in the reconnected session
Actual Behavior
- First connection creates session
ID-Awith userDataDir/tmp/session-1✅ - Data is saved successfully ✅
- Disconnect from session ✅
- Second connection creates NEW session
ID-Bwith same userDataDir ❌ - All data is lost - localStorage and cookies are empty ❌
Test Results
API Response Analysis
// First connection
{
"id": "8056abdc-ffc2-4666-aafc-05ffabaae90f",
"userDataDir": "/tmp/session-test",
"isTempDataDir": false,
"numbConnected": 1
}
// Second connection (same userDataDir)
{
"id": "6da99604-27f1-4714-89d0-bdcd3143a9b1", // ← Different ID!
"userDataDir": "/tmp/session-test", // ← Same userDataDir
"isTempDataDir": false,
"numbConnected": 1
}Data Persistence Test
// First session - save data
localStorage.setItem('test-data', JSON.stringify({
timestamp: Date.now(),
message: 'Login session data'
}));
document.cookie = 'session-token=abc123; path=/; max-age=3600';
// Second session - check data
localStorage.getItem('test-data'); // → null ❌
document.cookie; // → "" ❌Tested Configurations
✅ Working (userDataDir accepted)
- Path format:
/tmp/custom-session - API shows:
"isTempDataDir": false - UserDataDir appears correctly in sessions API
❌ Not Working (session reuse)
- New session created each time
- Data doesn't persist between sessions
- No automatic session reuse
Code Example
const puppeteerExtra = require('puppeteer-extra');
const userDataDir = '/tmp/persistent-session';
const launchArgs = {
stealth: true,
args: ['--proxy-server=http://proxy:5432']
};
const queryParams = new URLSearchParams({
token: 'your-token',
timeout: '300000',
'--user-data-dir': userDataDir,
launch: JSON.stringify(launchArgs)
}).toString();
const endpoint = `ws://browserless-host/?${queryParams}`;
// First connection
const browser1 = await puppeteerExtra.connect({
browserWSEndpoint: endpoint
});
// ... save data ...
await browser1.disconnect();
// Second connection - should reuse session but creates new one
const browser2 = await puppeteerExtra.connect({
browserWSEndpoint: endpoint // Same endpoint, same userDataDir
});
// ... data is lost ...Related Issues
This issue is related to:
- --user-data-dir not working #3268 - userDataDir parameter not working correctly
- can't reconnect to existing session, docker #4149 - Session reconnection issues with Docker
Expected Solution
The system should:
- Check if an active session exists with the specified userDataDir
- If exists, reuse the existing session instead of creating new one
- Maintain data persistence (localStorage, cookies, session state)
- Allow reconnection to existing sessions via WebSocket
Use Case
This functionality is essential for:
- Maintaining login sessions across script executions
- Preserving user preferences and application state
- Reducing resource usage by reusing browser instances
- Supporting long-running automation workflows
Additional Information
- The userDataDir path is correctly recognized and appears in the API
- Sessions remain active after disconnection
- The issue seems specific to Docker deployments
- Manual reconnection via
/devtools/browser/{id}endpoints return 404
Would appreciate any guidance on configuration changes or workarounds to enable proper session reuse with userDataDir.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels