geckordp.rdp_client module

class geckordp.rdp_client.RDPClient(timeout_sec=3.0, max_buffer_size=33554432, executor_workers=3, executor=None)

Bases: object

add_actor_listener(actor_id: str, handler: Callable[[dict], None] | Any) bool

Appends a listener for a specific actor. Multiple handlers can be added for each event type.

Warning

Called functions within manually registered async handlers on RDPClient can not call functions which emits send_receive() later in its execution path (instead use non-async handlers in this case)

Parameters:
  • actor_id (str) – The actor ID.

  • handler (Callable[[dict], None]) – The handler to call on match. Can be either async (executed with coroutine) or a common function (queued to executor).

Returns:

True: Handler registered; False: Handler already registered

Return type:

bool

add_event_listener(actor_id: str, event: str | Events, handler: Callable[[dict], None] | Any) bool

Appends a listener for a specific actor and event. Multiple handlers can be added for each event type.

Warning

Called functions within manually registered async handlers on RDPClient can not call functions which emits send_receive() later in its execution path (instead use non-async handlers in this case)

Parameters:
  • actor_id (str) – The actor ID.

  • event_type (Enum/str) – The event type. See /actors/events.py

  • handler (Callable[[dict], None]) – The handler to call on match. Can be either async (executed with coroutine) or a common function (queued to executor).

Returns:

True: Handler registered; False: Handler already registered

Return type:

bool

add_universal_listener(handler: Callable[[dict], None] | Any) bool

Appends a universal listener.

Warning

Called functions within manually registered async handlers on RDPClient can not call functions which emits send_receive() later in its execution path (instead use non-async handlers in this case)

Parameters:

handler (Callable[[dict], None]) – The handler to call on match. Can be either async (executed with coroutine) or a common function (queued to executor).

Returns:

True: Handler registered; False: Handler already registered

Return type:

bool

connect(host: str, port: int) dict | None

Connects to the firefox debug server.

Parameters:
  • host (str) – The host to connect to, usually ‘localhost’

  • port (int) – The port to use, default ‘6000’

Returns:

The server response on successful established connection.

Return type:

dict | None

connected() bool

Check whether the client is currently connected to the server.

Returns:

True: Connected; False: Disconnected

Return type:

bool

disconnect()

Disconnects from the debug server.

remove_actor_listener(actor_id: str, handler: Callable[[dict], None] | Any)

Removes a listener with the specified actor ID.

Parameters:
  • actor_id (str) – The ID to find.

  • handler (Callable[[dict], None]) – The handler to remove.

remove_event_listener(actor_id: str, event, handler: Callable[[dict], None] | Any)

Removes a listener with the specified actor ID and event.

Parameters:
  • actor_id (str) – The actor ID.

  • event_type (Enum/str) – The event type. See /actors/events.py

  • handler (Callable[[dict], None]) – The handler to remove.

remove_event_listeners_by_id(actor_id: str)

Removes all callback handlers by actor ID.

Parameters:

actor_id (str) – The actor ID.

remove_universal_listener(handler: Callable[[dict], None] | Any)

Removes a universal listener.

Parameters:
  • actor_id (str) – The ID to find.

  • handler (Callable[[dict], None]) – The handler to remove.

send(msg: dict) Coroutine | bool
Starts sending a request without waiting for a response.

The dict message will be transformed to a utf-8 json string.

Parameters:

msg (dict) – The message to send.

Raises:

ValueError – If parameter ‘msg’ doesn’t contain key ‘to’.

Returns:

Return type depends on handler type (asnyc).

Return type:

Coroutine | bool

send_receive(msg: dict, extract_expression='') dict
Starts sending a request and waiting for a response.

The dictionary message will be transformed to a utf-8 json string. The timeout can be specified in the class its constructor.

Note

Receiving messages asynchronously is not possible since the remote debug protocol is sequential itself and doesn’t have a way to identify individual received packets by an ID (which the sender would transmit).

Parameters:
  • msg (dict) – The message to send.

  • extract_expression (str, optional) – A jmespath expression to extract data from the response. Defaults to “”.

Raises:

ValueError – If ‘msg’ parameter doesn’t contain field ‘to’

Returns:

The response from the server.

Return type:

Coroutine | dict | None

property timeout_sec: float

Returns the timeout in seconds.

Returns:

The timeout.

Return type:

float