🔐 Implement robust session persistence to avoid 'are you human' captcha checks

- Add comprehensive session persistence with cookies, localStorage, and sessionStorage
- Implement stealth browser features to reduce bot detection
- Add smartLogin() method that prioritizes saved sessions over fresh logins
- Create session management utilities (refresh, clear, test validity)
- Update enhanced screenshot service to use session persistence
- Add comprehensive documentation and test script
- Support manual login fallback when captcha is encountered
- Sessions stored in .tradingview-session/ directory for Docker compatibility

This solves the captcha problem by avoiding repeated logins through persistent sessions.
This commit is contained in:
mindesbunister
2025-07-12 21:39:53 +02:00
parent 483d4c6576
commit cf58d41444
8 changed files with 976 additions and 26 deletions

View File

@@ -23,18 +23,30 @@ export class EnhancedScreenshotService {
// Initialize automation with Docker-optimized settings
await tradingViewAutomation.init()
// Check if already logged in
// Check if already logged in using session persistence
const alreadyLoggedIn = await tradingViewAutomation.isLoggedIn()
if (!alreadyLoggedIn) {
console.log('Attempting TradingView login...')
const loginSuccess = await tradingViewAutomation.login(config.credentials)
console.log('No active session found...')
if (!loginSuccess) {
throw new Error('Login failed')
// Try to use session persistence first to avoid captcha
const sessionTest = await tradingViewAutomation.testSessionPersistence()
if (sessionTest.isValid) {
console.log('✅ Valid session found - avoiding captcha!')
} else {
console.log('⚠️ No valid session - manual login may be required')
console.log('💡 Using smart login to handle captcha scenario...')
// Use smart login which prioritizes session persistence
const loginSuccess = await tradingViewAutomation.smartLogin(config.credentials)
if (!loginSuccess) {
throw new Error('Smart login failed - manual intervention may be required')
}
}
} else {
console.log('Already logged in to TradingView')
console.log('Already logged in using saved session')
}
// Navigate to chart