Recover from slow browser navigation

This commit is contained in:
2026-07-28 23:47:15 +03:30
parent 823acdd128
commit 601b8ec69e
3 changed files with 22 additions and 7 deletions
+20 -5
View File
@@ -2,9 +2,13 @@
from __future__ import annotations
import undetected_chromedriver as uc
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from crawler.driver import human_delay
from logger import get_logger
log = get_logger(__name__)
class FreshSessionScenario:
@@ -34,13 +38,24 @@ class FreshSessionScenario:
if not self.url:
return {"title": "", "url": "", "cookie_count": 0, "cookies": []}
self.driver.get(self.url)
try:
self.driver.get(self.url)
except TimeoutException:
log.warning(
"Page load exceeded the browser timeout; stopping navigation and continuing"
)
self.driver.execute_cdp_cmd("Page.stopLoading", {})
human_delay(2.0, 4.0)
# Wait for the page to reach a ready state
self.wait.until(
lambda d: d.execute_script("return document.readyState") == "complete"
)
# Interactive is sufficient for the dynamic flow and avoids waiting on
# analytics, ads, or other background resources indefinitely.
try:
self.wait.until(
lambda d: d.execute_script("return document.readyState")
in ("interactive", "complete")
)
except TimeoutException:
log.warning("Document did not report a ready state; continuing with the current DOM")
title = self.driver.title
current_url = self.driver.current_url