Feature/cdp navigation timeout (#4527)

Resolves #4491

<!-- This is an auto-generated description by cubic. -->
## Summary by cubic
Make CDP navigation timeout configurable and apply it to
`Page.navigate`, fixing mismatched timeouts. This aligns
`NavigateToUrlEvent` (and `TIMEOUT_NavigateToUrlEvent`) with the actual
CDP call and prevents early failures on heavy pages.

- **Bug Fixes**
- Add `nav_timeout` to `_navigate_and_wait` and use it for
`Page.navigate(...)`.
- Pass `event.event_timeout`; default remains 20s when not provided.
Outer `timeout_ms` behavior is unchanged.

<sup>Written for commit 801b134f90.
Summary will update on new commits.</sup>

<!-- End of auto-generated description by cubic. -->
This commit is contained in:
laithrw
2026-03-25 17:33:12 -04:00
committed by GitHub

View File

@@ -909,6 +909,7 @@ class BrowserSession(BaseModel):
target_id,
timeout=event.timeout_ms / 1000 if event.timeout_ms is not None else None,
wait_until=event.wait_until,
nav_timeout=event.event_timeout,
)
# Close any extension options pages that might have opened
@@ -952,11 +953,13 @@ class BrowserSession(BaseModel):
target_id: str,
timeout: float | None = None,
wait_until: str = 'load',
nav_timeout: float | None = None,
) -> None:
"""Navigate to URL and wait for page readiness using CDP lifecycle events.
Polls stored lifecycle events (registered once per session in SessionManager).
wait_until controls the minimum acceptable signal: 'commit', 'domcontentloaded', 'load', 'networkidle'.
nav_timeout controls the timeout for the CDP Page.navigate() call itself (defaults to 20.0s).
"""
cdp_session = await self.get_or_create_cdp_session(target_id, focus=False)
@@ -973,7 +976,9 @@ class BrowserSession(BaseModel):
nav_start_time = asyncio.get_event_loop().time()
# Wrap Page.navigate() with timeout — heavy sites can block here for 10s+
nav_timeout = 20.0
# Use nav_timeout parameter if provided, otherwise default to 20.0
if nav_timeout is None:
nav_timeout = 20.0
try:
nav_result = await asyncio.wait_for(
cdp_session.cdp_client.send.Page.navigate(