# DO NOT EDIT THIS FILE!
#
# This code is generated off of PyCDP modules. If you need to make
# changes, edit the generator and regenerate all of the modules.

from __future__ import annotations
import typing

from ..context import get_connection_context, get_session_context

import cdp.debugger
from cdp.debugger import (
    BreakLocation,
    BreakpointId,
    BreakpointResolved,
    CallFrame,
    CallFrameId,
    Location,
    Paused,
    Resumed,
    Scope,
    ScriptFailedToParse,
    ScriptParsed,
    ScriptPosition,
    SearchMatch
)


async def continue_to_location(
        location: Location,
        target_call_frames: typing.Optional[str] = None
    ) -> None:
    '''
    Continues execution until specific location is reached.

    :param location: Location to continue to.
    :param target_call_frames: *(Optional)*
    '''
    session = get_session_context('debugger.continue_to_location')
    return await session.execute(cdp.debugger.continue_to_location(location, target_call_frames))


async def disable() -> None:
    '''
    Disables debugger for given page.
    '''
    session = get_session_context('debugger.disable')
    return await session.execute(cdp.debugger.disable())


async def enable(
        max_scripts_cache_size: typing.Optional[float] = None
    ) -> cdp.runtime.UniqueDebuggerId:
    '''
    Enables debugger for the given page. Clients should not assume that the debugging has been
    enabled until the result for this command is received.

    :param max_scripts_cache_size: **(EXPERIMENTAL)** *(Optional)* The maximum size in bytes of collected scripts (not referenced by other heap objects) the debugger can hold. Puts no limit if paramter is omitted.
    :returns: Unique identifier of the debugger.
    '''
    session = get_session_context('debugger.enable')
    return await session.execute(cdp.debugger.enable(max_scripts_cache_size))


async def evaluate_on_call_frame(
        call_frame_id: CallFrameId,
        expression: str,
        object_group: typing.Optional[str] = None,
        include_command_line_api: typing.Optional[bool] = None,
        silent: typing.Optional[bool] = None,
        return_by_value: typing.Optional[bool] = None,
        generate_preview: typing.Optional[bool] = None,
        throw_on_side_effect: typing.Optional[bool] = None,
        timeout: typing.Optional[cdp.runtime.TimeDelta] = None
    ) -> typing.Tuple[cdp.runtime.RemoteObject, typing.Optional[cdp.runtime.ExceptionDetails]]:
    '''
    Evaluates expression on a given call frame.

    :param call_frame_id: Call frame identifier to evaluate on.
    :param expression: Expression to evaluate.
    :param object_group: *(Optional)* String object group name to put result into (allows rapid releasing resulting object handles using ```releaseObjectGroup````).
    :param include_command_line_api: *(Optional)* Specifies whether command line API should be available to the evaluated expression, defaults to false.
    :param silent: *(Optional)* In silent mode exceptions thrown during evaluation are not reported and do not pause execution. Overrides ````setPauseOnException``` state.
    :param return_by_value: *(Optional)* Whether the result is expected to be a JSON object that should be sent by value.
    :param generate_preview: **(EXPERIMENTAL)** *(Optional)* Whether preview should be generated for the result.
    :param throw_on_side_effect: *(Optional)* Whether to throw an exception if side effect cannot be ruled out during evaluation.
    :param timeout: **(EXPERIMENTAL)** *(Optional)* Terminate execution after timing out (number of milliseconds).
    :returns: A tuple with the following items:

        0. **result** – Object wrapper for the evaluation result.
        1. **exceptionDetails** – *(Optional)* Exception details.
    '''
    session = get_session_context('debugger.evaluate_on_call_frame')
    return await session.execute(cdp.debugger.evaluate_on_call_frame(call_frame_id, expression, object_group, include_command_line_api, silent, return_by_value, generate_preview, throw_on_side_effect, timeout))


async def get_possible_breakpoints(
        start: Location,
        end: typing.Optional[Location] = None,
        restrict_to_function: typing.Optional[bool] = None
    ) -> typing.List[BreakLocation]:
    '''
    Returns possible locations for breakpoint. scriptId in start and end range locations should be
    the same.

    :param start: Start of range to search possible breakpoint locations in.
    :param end: *(Optional)* End of range to search possible breakpoint locations in (excluding). When not specified, end of scripts is used as end of range.
    :param restrict_to_function: *(Optional)* Only consider locations which are in the same (non-nested) function as start.
    :returns: List of the possible breakpoint locations.
    '''
    session = get_session_context('debugger.get_possible_breakpoints')
    return await session.execute(cdp.debugger.get_possible_breakpoints(start, end, restrict_to_function))


async def get_script_source(
        script_id: cdp.runtime.ScriptId
    ) -> str:
    '''
    Returns source for the script with given id.

    :param script_id: Id of the script to get source for.
    :returns: Script source.
    '''
    session = get_session_context('debugger.get_script_source')
    return await session.execute(cdp.debugger.get_script_source(script_id))


async def get_stack_trace(
        stack_trace_id: cdp.runtime.StackTraceId
    ) -> cdp.runtime.StackTrace:
    '''
    Returns stack trace with given ``stackTraceId``.

    **EXPERIMENTAL**

    :param stack_trace_id:
    :returns: 
    '''
    session = get_session_context('debugger.get_stack_trace')
    return await session.execute(cdp.debugger.get_stack_trace(stack_trace_id))


async def pause() -> None:
    '''
    Stops on the next JavaScript statement.
    '''
    session = get_session_context('debugger.pause')
    return await session.execute(cdp.debugger.pause())


async def pause_on_async_call(
        parent_stack_trace_id: cdp.runtime.StackTraceId
    ) -> None:
    '''


    **EXPERIMENTAL**

    :param parent_stack_trace_id: Debugger will pause when async call with given stack trace is started.
    '''
    session = get_session_context('debugger.pause_on_async_call')
    return await session.execute(cdp.debugger.pause_on_async_call(parent_stack_trace_id))


async def remove_breakpoint(
        breakpoint_id: BreakpointId
    ) -> None:
    '''
    Removes JavaScript breakpoint.

    :param breakpoint_id:
    '''
    session = get_session_context('debugger.remove_breakpoint')
    return await session.execute(cdp.debugger.remove_breakpoint(breakpoint_id))


async def restart_frame(
        call_frame_id: CallFrameId
    ) -> typing.Tuple[typing.List[CallFrame], typing.Optional[cdp.runtime.StackTrace], typing.Optional[cdp.runtime.StackTraceId]]:
    '''
    Restarts particular call frame from the beginning.

    :param call_frame_id: Call frame identifier to evaluate on.
    :returns: A tuple with the following items:

        0. **callFrames** – New stack trace.
        1. **asyncStackTrace** – *(Optional)* Async stack trace, if any.
        2. **asyncStackTraceId** – *(Optional)* Async stack trace, if any.
    '''
    session = get_session_context('debugger.restart_frame')
    return await session.execute(cdp.debugger.restart_frame(call_frame_id))


async def resume() -> None:
    '''
    Resumes JavaScript execution.
    '''
    session = get_session_context('debugger.resume')
    return await session.execute(cdp.debugger.resume())


async def search_in_content(
        script_id: cdp.runtime.ScriptId,
        query: str,
        case_sensitive: typing.Optional[bool] = None,
        is_regex: typing.Optional[bool] = None
    ) -> typing.List[SearchMatch]:
    '''
    Searches for given string in script content.

    :param script_id: Id of the script to search in.
    :param query: String to search for.
    :param case_sensitive: *(Optional)* If true, search is case sensitive.
    :param is_regex: *(Optional)* If true, treats string parameter as regex.
    :returns: List of search matches.
    '''
    session = get_session_context('debugger.search_in_content')
    return await session.execute(cdp.debugger.search_in_content(script_id, query, case_sensitive, is_regex))


async def set_async_call_stack_depth(
        max_depth: int
    ) -> None:
    '''
    Enables or disables async call stacks tracking.

    :param max_depth: Maximum depth of async call stacks. Setting to ```0``` will effectively disable collecting async call stacks (default).
    '''
    session = get_session_context('debugger.set_async_call_stack_depth')
    return await session.execute(cdp.debugger.set_async_call_stack_depth(max_depth))


async def set_blackbox_patterns(
        patterns: typing.List[str]
    ) -> None:
    '''
    Replace previous blackbox patterns with passed ones. Forces backend to skip stepping/pausing in
    scripts with url matching one of the patterns. VM will try to leave blackboxed script by
    performing 'step in' several times, finally resorting to 'step out' if unsuccessful.

    **EXPERIMENTAL**

    :param patterns: Array of regexps that will be used to check script url for blackbox state.
    '''
    session = get_session_context('debugger.set_blackbox_patterns')
    return await session.execute(cdp.debugger.set_blackbox_patterns(patterns))


async def set_blackboxed_ranges(
        script_id: cdp.runtime.ScriptId,
        positions: typing.List[ScriptPosition]
    ) -> None:
    '''
    Makes backend skip steps in the script in blackboxed ranges. VM will try leave blacklisted
    scripts by performing 'step in' several times, finally resorting to 'step out' if unsuccessful.
    Positions array contains positions where blackbox state is changed. First interval isn't
    blackboxed. Array should be sorted.

    **EXPERIMENTAL**

    :param script_id: Id of the script.
    :param positions:
    '''
    session = get_session_context('debugger.set_blackboxed_ranges')
    return await session.execute(cdp.debugger.set_blackboxed_ranges(script_id, positions))


async def set_breakpoint(
        location: Location,
        condition: typing.Optional[str] = None
    ) -> typing.Tuple[BreakpointId, Location]:
    '''
    Sets JavaScript breakpoint at a given location.

    :param location: Location to set breakpoint in.
    :param condition: *(Optional)* Expression to use as a breakpoint condition. When specified, debugger will only stop on the breakpoint if this expression evaluates to true.
    :returns: A tuple with the following items:

        0. **breakpointId** – Id of the created breakpoint for further reference.
        1. **actualLocation** – Location this breakpoint resolved into.
    '''
    session = get_session_context('debugger.set_breakpoint')
    return await session.execute(cdp.debugger.set_breakpoint(location, condition))


async def set_breakpoint_by_url(
        line_number: int,
        url: typing.Optional[str] = None,
        url_regex: typing.Optional[str] = None,
        script_hash: typing.Optional[str] = None,
        column_number: typing.Optional[int] = None,
        condition: typing.Optional[str] = None
    ) -> typing.Tuple[BreakpointId, typing.List[Location]]:
    '''
    Sets JavaScript breakpoint at given location specified either by URL or URL regex. Once this
    command is issued, all existing parsed scripts will have breakpoints resolved and returned in
    ``locations`` property. Further matching script parsing will result in subsequent
    ``breakpointResolved`` events issued. This logical breakpoint will survive page reloads.

    :param line_number: Line number to set breakpoint at.
    :param url: *(Optional)* URL of the resources to set breakpoint on.
    :param url_regex: *(Optional)* Regex pattern for the URLs of the resources to set breakpoints on. Either ```url```` or ````urlRegex``` must be specified.
    :param script_hash: *(Optional)* Script hash of the resources to set breakpoint on.
    :param column_number: *(Optional)* Offset in the line to set breakpoint at.
    :param condition: *(Optional)* Expression to use as a breakpoint condition. When specified, debugger will only stop on the breakpoint if this expression evaluates to true.
    :returns: A tuple with the following items:

        0. **breakpointId** – Id of the created breakpoint for further reference.
        1. **locations** – List of the locations this breakpoint resolved into upon addition.
    '''
    session = get_session_context('debugger.set_breakpoint_by_url')
    return await session.execute(cdp.debugger.set_breakpoint_by_url(line_number, url, url_regex, script_hash, column_number, condition))


async def set_breakpoint_on_function_call(
        object_id: cdp.runtime.RemoteObjectId,
        condition: typing.Optional[str] = None
    ) -> BreakpointId:
    '''
    Sets JavaScript breakpoint before each call to the given function.
    If another function was created from the same source as a given one,
    calling it will also trigger the breakpoint.

    **EXPERIMENTAL**

    :param object_id: Function object id.
    :param condition: *(Optional)* Expression to use as a breakpoint condition. When specified, debugger will stop on the breakpoint if this expression evaluates to true.
    :returns: Id of the created breakpoint for further reference.
    '''
    session = get_session_context('debugger.set_breakpoint_on_function_call')
    return await session.execute(cdp.debugger.set_breakpoint_on_function_call(object_id, condition))


async def set_breakpoints_active(
        active: bool
    ) -> None:
    '''
    Activates / deactivates all breakpoints on the page.

    :param active: New value for breakpoints active state.
    '''
    session = get_session_context('debugger.set_breakpoints_active')
    return await session.execute(cdp.debugger.set_breakpoints_active(active))


async def set_instrumentation_breakpoint(
        instrumentation: str
    ) -> BreakpointId:
    '''
    Sets instrumentation breakpoint.

    :param instrumentation: Instrumentation name.
    :returns: Id of the created breakpoint for further reference.
    '''
    session = get_session_context('debugger.set_instrumentation_breakpoint')
    return await session.execute(cdp.debugger.set_instrumentation_breakpoint(instrumentation))


async def set_pause_on_exceptions(
        state: str
    ) -> None:
    '''
    Defines pause on exceptions state. Can be set to stop on all exceptions, uncaught exceptions or
    no exceptions. Initial pause on exceptions state is ``none``.

    :param state: Pause on exceptions mode.
    '''
    session = get_session_context('debugger.set_pause_on_exceptions')
    return await session.execute(cdp.debugger.set_pause_on_exceptions(state))


async def set_return_value(
        new_value: cdp.runtime.CallArgument
    ) -> None:
    '''
    Changes return value in top frame. Available only at return break position.

    **EXPERIMENTAL**

    :param new_value: New return value.
    '''
    session = get_session_context('debugger.set_return_value')
    return await session.execute(cdp.debugger.set_return_value(new_value))


async def set_script_source(
        script_id: cdp.runtime.ScriptId,
        script_source: str,
        dry_run: typing.Optional[bool] = None
    ) -> typing.Tuple[typing.Optional[typing.List[CallFrame]], typing.Optional[bool], typing.Optional[cdp.runtime.StackTrace], typing.Optional[cdp.runtime.StackTraceId], typing.Optional[cdp.runtime.ExceptionDetails]]:
    '''
    Edits JavaScript source live.

    :param script_id: Id of the script to edit.
    :param script_source: New content of the script.
    :param dry_run: *(Optional)* If true the change will not actually be applied. Dry run may be used to get result description without actually modifying the code.
    :returns: A tuple with the following items:

        0. **callFrames** – *(Optional)* New stack trace in case editing has happened while VM was stopped.
        1. **stackChanged** – *(Optional)* Whether current call stack  was modified after applying the changes.
        2. **asyncStackTrace** – *(Optional)* Async stack trace, if any.
        3. **asyncStackTraceId** – *(Optional)* Async stack trace, if any.
        4. **exceptionDetails** – *(Optional)* Exception details if any.
    '''
    session = get_session_context('debugger.set_script_source')
    return await session.execute(cdp.debugger.set_script_source(script_id, script_source, dry_run))


async def set_skip_all_pauses(
        skip: bool
    ) -> None:
    '''
    Makes page not interrupt on any pauses (breakpoint, exception, dom exception etc).

    :param skip: New value for skip pauses state.
    '''
    session = get_session_context('debugger.set_skip_all_pauses')
    return await session.execute(cdp.debugger.set_skip_all_pauses(skip))


async def set_variable_value(
        scope_number: int,
        variable_name: str,
        new_value: cdp.runtime.CallArgument,
        call_frame_id: CallFrameId
    ) -> None:
    '''
    Changes value of variable in a callframe. Object-based scopes are not supported and must be
    mutated manually.

    :param scope_number: 0-based number of scope as was listed in scope chain. Only 'local', 'closure' and 'catch' scope types are allowed. Other scopes could be manipulated manually.
    :param variable_name: Variable name.
    :param new_value: New variable value.
    :param call_frame_id: Id of callframe that holds variable.
    '''
    session = get_session_context('debugger.set_variable_value')
    return await session.execute(cdp.debugger.set_variable_value(scope_number, variable_name, new_value, call_frame_id))


async def step_into(
        break_on_async_call: typing.Optional[bool] = None
    ) -> None:
    '''
    Steps into the function call.

    :param break_on_async_call: **(EXPERIMENTAL)** *(Optional)* Debugger will issue additional Debugger.paused notification if any async task is scheduled before next pause.
    '''
    session = get_session_context('debugger.step_into')
    return await session.execute(cdp.debugger.step_into(break_on_async_call))


async def step_out() -> None:
    '''
    Steps out of the function call.
    '''
    session = get_session_context('debugger.step_out')
    return await session.execute(cdp.debugger.step_out())


async def step_over() -> None:
    '''
    Steps over the statement.
    '''
    session = get_session_context('debugger.step_over')
    return await session.execute(cdp.debugger.step_over())
