Async context manager opens a connection to the browser then closes the connection when the block exits. The context manager also sets the connection as the default connection for the current task, so that commands like ``await target.get_targets()`` will run on this connection automati
(url, max_message_size=None)
| 493 | |
| 494 | @asynccontextmanager |
| 495 | async def open_cdp(url, max_message_size=None) -> AsyncIterator[CdpConnection]: |
| 496 | """Async context manager opens a connection to the browser then closes the connection when the block exits. |
| 497 | |
| 498 | The context manager also sets the connection as the default |
| 499 | connection for the current task, so that commands like ``await |
| 500 | target.get_targets()`` will run on this connection automatically. If |
| 501 | you want to use multiple connections concurrently, it is recommended |
| 502 | to open each on in a separate task. |
| 503 | |
| 504 | Args: |
| 505 | url: WebSocket URL of the browser's CDP endpoint. |
| 506 | max_message_size: Maximum WebSocket message size in bytes. Defaults to the |
| 507 | ``SE_CDP_MAX_WS_MESSAGE_SIZE`` environment variable, or 16 MiB if unset. |
| 508 | """ |
| 509 | async with trio.open_nursery() as nursery: |
| 510 | conn = await connect_cdp(nursery, url, max_message_size=max_message_size) |
| 511 | try: |
| 512 | with connection_context(conn): |
| 513 | yield conn |
| 514 | finally: |
| 515 | await conn.aclose() |
| 516 | |
| 517 | |
| 518 | async def connect_cdp(nursery, url, max_message_size=None) -> CdpConnection: |
nothing calls this directly
no test coverage detected