mokr.utils.remote
Attributes
Functions
|
Get and format a JavaScript exception message. |
|
Add an event |
|
Remove all event listeners given from their emitters. |
|
Transform a remote JavaScript object's "value" to a Python equivalent. |
|
Release a given |
|
Casually check if string is a JavaScript method. |
Module Contents
- mokr.utils.remote.LOGGER
- mokr.utils.remote.format_javascript_exception(exception_details: dict) str
Get and format a JavaScript exception message.
- Parameters:
exception_details (dict) – An “exceptionDetails” object loaded as a dictionary.
- Returns:
Formatted exception as string.
- Return type:
str
- mokr.utils.remote.add_event_listener(emitter: pyee.EventEmitter, event_name: str, handler: Callable) dict[str, Any]
Add an event
handlerto anemitterfor a givenevent_name.- Parameters:
emitter (EventEmitter) – Emitter to listen on.
event_name (str) – Event name to listen for.
handler (Callable) – Handler callback to run when event is emitted.
- Returns:
A dictionary representation of the listener.
- Return type:
dict[str, Any]
- mokr.utils.remote.remove_event_listeners(listeners: list[dict]) None
Remove all event listeners given from their emitters.
- Parameters:
listeners (list[dict]) – A list of listeners in dictionary form, as returned by
mokr.utils.remote.add_event_listener.
- mokr.utils.remote.serialize_remote_object(remote_object: dict) Any
Transform a remote JavaScript object’s “value” to a Python equivalent.
- Parameters:
remote_object (dict) – The remote JavaScript object to serialise.
- Raises:
ElementHandleError – Raised if the
remote_objecthas an “objectId”(is not a primitive object) or if an unhandled case is encountered –
when checking remote_object["unserializableValue"]. –
- Returns:
- Python representation of remote object. May be str, int, dict,
list, etc. Some
remote_object["unserializableValue"]`s will be transformed into equivalents including "Nan" to None, "-0" to 0, "Infinity" to `math.inf, and “-Infinity” to-math.inf.
- Return type:
Any
- mokr.utils.remote.release_remote_object(client: mokr.connection.DevtoolsConnection, remote_object: dict) Awaitable
Release a given
remote_objectso that it is no longer referenced by the browser and can be garbage collected.Ignores all exceptions raised when sending request to devtools session.
- Parameters:
client (DevtoolsConnection) – A
mokr.connection.DevtoolsConnection.remote_object (dict) – A remote object as dictionary.
- Returns:
Awaitable that yields None.
- Return type:
Awaitable
- mokr.utils.remote.is_javascript_method(method: str) bool
Casually check if string is a JavaScript method.
- Parameters:
method (str) – String to check.
- Returns:
True if deemed to be a method, else False.
- Return type:
bool