-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Restore active-page waiting in V4 #2430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |||||
| ContextActivePageResult, | ||||||
| ContextAddCookiesParams, | ||||||
| ContextAddInitScriptParams, | ||||||
| ContextAwaitActivePageParams, | ||||||
| ContextClearCookiesParams, | ||||||
| ContextCloseResult, | ||||||
| ContextCookiesParams, | ||||||
|
|
@@ -67,6 +68,15 @@ async def active_page(self) -> Page | None: | |||||
| ) | ||||||
| return None if result.root is None else Page(self._rpc_client, result.root) | ||||||
|
|
||||||
| async def await_active_page(self, timeout: int | None = None) -> Page: | ||||||
| params = ContextAwaitActivePageParams(timeout=timeout) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Calling Prompt for AI agents
Suggested change
|
||||||
| page_ref = await self._rpc_client.send( | ||||||
| "context.await_active_page", | ||||||
| params, | ||||||
| PageRef, | ||||||
| ) | ||||||
| return Page(self._rpc_client, page_ref) | ||||||
|
|
||||||
| async def set_active_page(self, page: Page) -> None: | ||||||
| await self._rpc_client.send( | ||||||
| "context.set_active_page", | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,12 +81,8 @@ def __init__(self, error: _JSONRPCError) -> None: | |
|
|
||
|
|
||
| class RPCClient: | ||
| def __init__(self, transport: _Transport, *, request_timeout_ms: int = 10_000) -> None: | ||
| if request_timeout_ms <= 0: | ||
| raise ValueError("request_timeout_ms must be positive") | ||
|
|
||
| def __init__(self, transport: _Transport) -> None: | ||
| self._transport = transport | ||
| self._request_timeout_seconds = request_timeout_ms / 1_000 | ||
| self._next_request_id = 1 | ||
| self._pending: dict[ | ||
| int, | ||
|
|
@@ -142,17 +138,14 @@ async def send( | |
| ) | ||
|
|
||
| try: | ||
| async with asyncio.timeout(self._request_timeout_seconds): | ||
| await self._transport.send( | ||
| cast( | ||
| dict[str, object], | ||
| request.model_dump(mode="json", exclude_none=True, exclude_unset=True), | ||
| ) | ||
| await self._transport.send( | ||
| cast( | ||
| dict[str, object], | ||
| request.model_dump(mode="json", exclude_none=True, exclude_unset=True), | ||
| ) | ||
| result = await response | ||
| return cast(ResultT, result) | ||
| except TimeoutError as error: | ||
| raise TimeoutError(f"RPC request timed out: {method}") from error | ||
| ) | ||
| result = await response | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: The removed RPC deadline has no regression coverage for its new indefinite-wait behavior. Add focused tests for a delayed response and cancellation so pending-request cleanup remains guaranteed. (Based on your team's feedback about unit tests for changed behavior.) Prompt for AI agents |
||
| return cast(ResultT, result) | ||
| finally: | ||
| self._pending.pop(request_id, None) | ||
| if not response.done(): | ||
|
|
@@ -477,7 +470,7 @@ async def connect_rpc_client( | |
| command_timeout_ms=command_timeout_ms, | ||
| cdp_connect_timeout_ms=cdp_connect_timeout_ms, | ||
| ) | ||
| client = RPCClient(cdp, request_timeout_ms=command_timeout_ms) | ||
| client = RPCClient(cdp) | ||
| configure = models.RuntimeConfigureParams( | ||
| cdp_url=cdp.web_socket_debugger_url, | ||
| **({"telemetry": telemetry} if telemetry is not None else {}), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3: New
context.await_active_pagewire validation has no regression coverage. Add focused parsing tests for omitted/valid timeout and rejected negative, fractional, or extra fields.Prompt for AI agents