mokr.execution.context ====================== .. py:module:: mokr.execution.context Attributes ---------- .. autoapisummary:: mokr.execution.context.LOGGER mokr.execution.context.EVALUATION_SCRIPT_URL mokr.execution.context.SOURCE_URL_REGEX Classes ------- .. autoapisummary:: mokr.execution.context.ExecutionContext Module Contents --------------- .. py:data:: LOGGER .. py:data:: EVALUATION_SCRIPT_URL :value: '__mokr_evaluation_script__' .. py:data:: SOURCE_URL_REGEX .. py:class:: 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. :param client: Remote connection from parent. :type client: DevtoolsConnection :param context_payload: Context from triggering event. :type context_payload: dict :param object_handle_factory: Factory for handling remote objects. Should create `mokr.execution.JavascriptHandle` based objects. :type object_handle_factory: Any :param frame: The `mokr.frame.Frame` that spawned this. Defaults to None. :type frame: Frame, optional .. py:property:: frame :type: mokr.frame.Frame | None Parent `mokr.frame.Frame` that spawned this. .. py:method:: evaluate(page_function: str, *args: Any, force_expr: bool = False) -> Any :async: Run `ExecutionContext.evaluate_handle` and try to run `mokr.execution.JavascriptHandle.json` on the result to return the object as a dictionary. :param page_function: JavaScript function to run. :type page_function: str :param force_expr: If True, treat `page_function` as an expression. Otherwise, automatically determine if it is a function or an expression. Defaults to False. :type force_expr: bool :raises mokr.exceptions.NetworkError: :raises either evaluating the function or requesting the resulting object.: :returns: The decoded object (dict) via `mokr.execution.JavascriptHandle.json` or None if a known error occurs decoding it. :rtype: dict | None .. py:method:: evaluate_handle(page_function: str, *args: Any, force_expr: bool = False, eval_script_url_suffix: str | None = None) -> mokr.execution.handle.javascript.JavascriptHandle :async: Execute a JavaScript function with given arguments. :param page_function: JavaScript function to run. :type page_function: str :raises ElementHandleError: Raised if execution fails. :returns: `mokr.execution.JavascriptHandle`. :rtype: JavascriptHandle .. py:method:: query_objects(javascript_handle: mokr.execution.handle.javascript.JavascriptHandle) -> mokr.execution.handle.javascript.JavascriptHandle :async: Query all objects with the given `mokr.execution.JavascriptHandle`'s `get_property("objectId")`. :param javascript_handle: A valid (not disposed) `mokr.execution.JavascriptHandle` object. :type javascript_handle: JavascriptHandle :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. :rtype: JavascriptHandle