MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / open_cdp

Function open_cdp

py/private/cdp.py:495–515  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

493
494@asynccontextmanager
495async 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
518async def connect_cdp(nursery, url, max_message_size=None) -> CdpConnection:

Callers

nothing calls this directly

Calls 3

connect_cdpFunction · 0.85
connection_contextFunction · 0.85
acloseMethod · 0.80

Tested by

no test coverage detected