mokr.execution.context

Attributes

LOGGER

EVALUATION_SCRIPT_URL

SOURCE_URL_REGEX

Classes

ExecutionContext

Class to handle execution of JavaScript functions, element manipulation,

Module Contents

mokr.execution.context.LOGGER
mokr.execution.context.EVALUATION_SCRIPT_URL = '__mokr_evaluation_script__'
mokr.execution.context.SOURCE_URL_REGEX
class mokr.execution.context.ExecutionContext(client: mokr.connection.DevtoolsConnection, context_payload: dict, object_handle_factory: Any, frame: mokr.frame.Frame = None)

Class to handle execution of JavaScript functions, element manipulation, and associated runtime error translation.

Parameters:
  • client (DevtoolsConnection) – Remote connection from parent.

  • context_payload (dict) – Context from triggering event.

  • object_handle_factory (Any) – Factory for handling remote objects. Should create mokr.execution.JavascriptHandle based objects.

  • frame (Frame, optional) – The mokr.frame.Frame that spawned this. Defaults to None.

property frame: mokr.frame.Frame | None

Parent mokr.frame.Frame that spawned this.

async evaluate(page_function: str, *args: Any, force_expr: bool = False) Any

Run ExecutionContext.evaluate_handle and try to run mokr.execution.JavascriptHandle.json on the result to return the object as a dictionary.

Parameters:
  • page_function (str) – JavaScript function to run.

  • force_expr (bool) – If True, treat page_function as an expression. Otherwise, automatically determine if it is a function or an expression. Defaults to False.

Raises:
Returns:

The decoded object (dict) via

mokr.execution.JavascriptHandle.json or None if a known error occurs decoding it.

Return type:

dict | None

async evaluate_handle(page_function: str, *args: Any, force_expr: bool = False, eval_script_url_suffix: str | None = None) mokr.execution.handle.javascript.JavascriptHandle

Execute a JavaScript function with given arguments.

Parameters:

page_function (str) – JavaScript function to run.

Raises:

ElementHandleError – Raised if execution fails.

Returns:

mokr.execution.JavascriptHandle.

Return type:

JavascriptHandle

async query_objects(javascript_handle: mokr.execution.handle.javascript.JavascriptHandle) mokr.execution.handle.javascript.JavascriptHandle

Query all objects with the given mokr.execution.JavascriptHandle’s get_property("objectId").

Parameters:

javascript_handle (JavascriptHandle) – A valid (not disposed) mokr.execution.JavascriptHandle object.

Raises:

ElementHandleError – Raised if the given handle is disposed, or does not have an “objectId” remote property (primitive type).

Returns:

A mokr.execution.JavascriptHandle initialised

from the remot response.

Return type:

JavascriptHandle