mokr.connection
Submodules
Classes
Create remote connection. |
|
Create new CDP (Chrome Devtools Protocol) session. |
Package Contents
- class mokr.connection.Connection(url: str, loop: asyncio.AbstractEventLoop, delay: int = 0)
Bases:
pyee.EventEmitter,mokr.connection.base.RemoteConnectionCreate remote connection.
- Parameters:
url (str) – Websocket URL for remote connection.
loop (asyncio.AbstractEventLoop) – Running asyncio loop.
delay (int, optional) – Time in milliseconds to wait before handling messages. Defaults to 0.
- connection: mokr.connection.devtools.DevtoolsConnection = None
- property url: str
Get remote websocket URL.
- send(method: str, params: dict = None) Awaitable[dict]
Send message to remote connection via websocket.
- Parameters:
method (str) – Method to run.
params (dict, optional) – Arguments for method, if any. Defaults to None.
- Raises:
ConnectionError – Raised if the connection is closed.
- Returns:
Remote response as dictionary.
- Return type:
Awaitable[dict]
- async dispose() None
Sever all connections.
- async create_session(target_info: dict) mokr.connection.devtools.DevtoolsConnection
Create a new
mokr.connection.DevtoolsConnection.- Parameters:
target_info (dict) – Target info from triggered event.
- Returns:
New
DevtoolsConnection.- Return type:
- class mokr.connection.DevtoolsConnection(connection: mokr.connection.connection.Connection | DevtoolsConnection, target_type: str, session_id: str, loop: asyncio.AbstractEventLoop)
Bases:
pyee.EventEmitter,mokr.connection.base.RemoteConnectionCreate new CDP (Chrome Devtools Protocol) session.
Most functionality is controlled by calling CDP methods or handling CDP events. Read more about these at: https://chromedevtools.github.io/devtools-protocol/
- Parameters:
connection (Connection | DevtoolsConnection) – Parent remote connection to use.
target_type (str) – Type of target this connection is for.
session_id (str) – Unique session identifier.
loop (asyncio.AbstractEventLoop) – Running asyncio loop.
- send(method: str, params: dict = None) Awaitable[dict]
Send a message to the remote connection.
- Parameters:
method (str) – Method to run.
params (dict, optional) – Arguments for method, if any. Defaults to None.
- Raises:
NetworkError – Raised if connection is closed.
- Returns:
Remote response as dictionary.
- Return type:
Awaitable[dict]
- async detach() None
Detach session from it’s target. Once detached, it is invalid and cannot receive or send messages.
- Raises:
NetworkError – Raised if remote connection is already closed.