Browser session recovery, price tracking, and dashboard improvements
- Add browser session validation and auto-restart for BestBuy/GameStop scrapers - Add price change detection and notifications - Remove PokemonCenter scraper (now uses Chrome Extension) - Dashboard UI improvements Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -193,6 +193,47 @@ class StealthBrowser:
|
||||
self.driver = None
|
||||
self._setup_complete = False
|
||||
|
||||
def is_session_valid(self) -> bool:
|
||||
"""
|
||||
Check if the browser session is still valid.
|
||||
Returns False if the session has crashed or been closed.
|
||||
"""
|
||||
if not self.driver:
|
||||
return False
|
||||
|
||||
try:
|
||||
# Try to get current URL - this will fail if session is invalid
|
||||
_ = self.driver.current_url
|
||||
return True
|
||||
except Exception as e:
|
||||
error_msg = str(e).lower()
|
||||
if "invalid session id" in error_msg or "session deleted" in error_msg or "no such session" in error_msg:
|
||||
logger.warning(f"Browser session invalid: {e}")
|
||||
return False
|
||||
# Other errors might be temporary
|
||||
return True
|
||||
|
||||
def restart(self):
|
||||
"""
|
||||
Restart the browser, cleaning up the old session.
|
||||
Useful when the session has become invalid.
|
||||
"""
|
||||
logger.info("Restarting stealth browser...")
|
||||
|
||||
# Force cleanup of old driver without trying to save cookies (session is dead)
|
||||
if self.driver:
|
||||
try:
|
||||
self.driver.quit()
|
||||
except Exception:
|
||||
pass # Ignore errors - session is already dead
|
||||
finally:
|
||||
self.driver = None
|
||||
self._setup_complete = False
|
||||
|
||||
# Start fresh
|
||||
self.start()
|
||||
logger.info("Stealth browser restarted successfully")
|
||||
|
||||
def _get_cookie_file(self) -> Path:
|
||||
"""Get path to cookie file for this session"""
|
||||
return SESSION_DIR / f"{self.session_name}_cookies.pkl"
|
||||
|
||||
Reference in New Issue
Block a user