Open target URL during Chrome startup

This commit is contained in:
2026-08-03 00:42:09 +03:30
parent 9f986255b3
commit 71790cf0ad
5 changed files with 71 additions and 13 deletions
+15 -5
View File
@@ -13,9 +13,6 @@ from logger import get_logger
log = get_logger(__name__)
_BLANK_URLS = {"", "about:blank", "data:,"}
class FreshSessionError(RuntimeError):
"""The browser could not leave its initial blank page."""
@@ -32,6 +29,11 @@ def _normalise_url(url: str) -> str:
return value
def _is_web_url(url: str) -> bool:
parsed = urlsplit(url)
return parsed.scheme in {"http", "https"} and bool(parsed.netloc)
class FreshSessionScenario:
"""
Opens the target URL in a brand-new browser profile (no stored cookies,
@@ -76,10 +78,18 @@ class FreshSessionScenario:
)
try:
self.wait.until(lambda d: d.current_url not in _BLANK_URLS)
# Chrome's internal New Tab URLs (chrome://newtab and
# chrome://new-tab-page) are not successful navigation. Wait until
# the address bar actually contains an HTTP(S) page or redirect.
self.wait.until(lambda d: _is_web_url(d.current_url))
except TimeoutException as exc:
try:
current_url = self.driver.current_url
except WebDriverException:
current_url = "<unavailable>"
raise FreshSessionError(
f"navigation to {self.url} never left Chrome's blank page"
f"navigation to {self.url} never reached a web page "
f"(Chrome remained at {current_url})"
) from exc
human_delay(1.0, 2.0)