
    >iD                        d dl mZ d dlmZmZ d dlmZ d dlmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZ er,d dlmZ d dlmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z% d dl&m'Z'  G d d	      Z(y
)    )annotations)TYPE_CHECKINGOptional)Command)ActivateTargetParamsAttachToBrowserTargetParamsAttachToTargetParamsCloseTargetParamsCreateBrowserContextParamsCreateTargetParamsDetachFromTargetParamsDisposeBrowserContextParamsGetTargetInfoParamsGetTargetsParamsSetAutoAttachParamsSetDiscoverTargetsParamsSetRemoteLocationsParamsTargetMethod)WindowState)ActivateTargetCommandAttachToBrowserTargetCommandAttachToTargetCommandCloseTargetCommandCreateBrowserContextCommandCreateTargetCommandDetachFromTargetCommandDisposeBrowserContextCommandGetBrowserContextsCommandGetTargetInfoCommandGetTargetsCommandSetAutoAttachCommandSetDiscoverTargetsCommandSetRemoteLocationsCommand)RemoteLocationc                     e Zd ZdZedd       Zeddd       Zedd       Ze	 	 	 	 d	 	 	 	 	 	 	 	 	 dd       Ze	 	 	 	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Z	eddd       Z
edd	       Zedd
       Zeddd       Ze	 	 	 d	 	 	 	 	 	 	 	 	 dd       Ze	 d	 	 	 	 	 dd       Zed d       Zed!d       Zed"d       Zy)#TargetCommandsa  
    A class for managing browser targets using Chrome DevTools Protocol.

    The Target domain of CDP supports additional targets discovery and allows to attach to them.
    Targets can represent browser tabs, windows, frames, web workers, service workers, etc.
    The domain provides methods to create, discover, and control these targets.

    This class provides methods to create commands for interacting with browser targets,
    including creating, activating, attaching to, and closing targets through CDP commands.
    c                P    t        |       }t        t        j                  |      S )z
        Generates a command to activate (focus) a target.

        Args:
            target_id: ID of the target to activate.

        Returns:
            Command: The CDP command to activate the target.
        targetIdmethodparams)r   r   r   ACTIVATE_TARGET	target_idr,   s     e/var/www/python/tenders/Scrapper/venv/lib/python3.12/site-packages/pydoll/commands/target_commands.pyactivate_targetzTargetCommands.activate_target8   s!     &y9l::6JJ    Nc                ^    t        |       }|||d<   t        t        j                  |      S )a  
        Generates a command to attach to a target with the given ID.

        When attached to a target, you can send commands to it and receive events from it.
        This is essential for controlling and automating targets like browser tabs.

        Args:
            target_id: ID of the target to attach to.
            flatten: If true, enables "flat" access to the session via specifying sessionId
                    attribute in the commands. This is recommended as the non-flattened
                    mode is being deprecated. See https://crbug.com/991325

        Returns:
            Command: The CDP command to attach to the target, which will return a sessionId.
        r(   flattenr*   )r	   r   r   ATTACH_TO_TARGET)r/   r4   r,   s      r0   attach_to_targetzTargetCommands.attach_to_targetF   s1    " &y9 'F9l;;FKKr2   c                P    t        |       }t        t        j                  |      S )ao  
        Generates a command to close a target.

        If the target is a page or a tab, it will be closed. This is equivalent to
        clicking the close button on a browser tab.

        Args:
            target_id: ID of the target to close.

        Returns:
            Command: The CDP command to close the target, which will return a success flag.
        r(   r*   )r
   r   r   CLOSE_TARGETr.   s     r0   close_targetzTargetCommands.close_target\   s!     #I6l77GGr2   c                    t               }| | |d<   |||d<   |||d<   |||d<   t        t        j                  |      S )aa  
        Generates a command to create a new empty browser context.

        A browser context is similar to an incognito profile but you can have more than one.
        Each context has its own set of cookies, local storage, and other browser data.
        This is useful for testing multiple users or isolating sessions.

        Args:
            dispose_on_detach: If specified, the context will be disposed when the
                              debugging session disconnects.
            proxy_server: Proxy server string, similar to the one passed to --proxy-server
                         command line argument (e.g., "socks5://192.168.1.100:1080").
            proxy_bypass_list: Proxy bypass list, similar to the one passed to
                               --proxy-bypass-list command line argument
                               (e.g., "*.example.com,localhost").
            origins_with_universal_network_access: An optional list of origins to grant
                                                  unlimited cross-origin access to.
                                                  Parts of the URL other than those
                                                  constituting origin are ignored.

        Returns:
            Command: The CDP command to create a browser context, which will return
                    the ID of the created context.
        disposeOnDetachproxyServerproxyBypassList!originsWithUniversalNetworkAccessr*   )r   r   r   CREATE_BROWSER_CONTEXT)dispose_on_detachproxy_serverproxy_bypass_list%origins_with_universal_network_accessr,   s        r0   create_browser_contextz%TargetCommands.create_browser_contextm   sb    > ,-((9F$%#$0F=!((9F$%0<:_F67lAA&QQr2   c                    t        |       }|||d<   |||d<   |||d<   |||d<   |||d<   |||d<   |||d<   |||d	<   |	|	|d
<   |
|
|d<   |||d<   t        t        j                  |      S )a  
        Generates a command to create a new page (target).

        This is one of the primary methods to open a new tab or window with specific
        properties such as position, size, and browser context.

        Args:
            url: The initial URL the page will navigate to. An empty string indicates about:blank.
            left: Frame left position in device-independent pixels (DIP).
                 Requires newWindow to be true or in headless mode.
            top: Frame top position in DIP. Requires newWindow to be true or in headless mode.
            width: Frame width in DIP.
            height: Frame height in DIP.
            window_state: Frame window state: normal, minimized, maximized, or fullscreen.
                         Default is normal.
            browser_context_id: The browser context to create the page in.
                               If not specified, the default browser context is used.
            enable_begin_frame_control: Whether BeginFrames for this target will be controlled
                                       via DevTools (headless shell only, not supported on
                                       MacOS yet, false by default).
            new_window: Whether to create a new window or tab (false by default,
                       not supported by headless shell).
            background: Whether to create the target in background or foreground
                       (false by default, not supported by headless shell).
            for_tab: Whether to create the target of type "tab".
            hidden: Whether to create a hidden target. The hidden target is observable via
                   protocol, but not present in the tab UI strip. Cannot be created with
                   forTab:true, newWindow:true or background:false. The life-time of the
                   tab is limited to the life-time of the session.

        Returns:
            Command: The CDP command to create a target, which will return the ID
                of the created target.
        )urllefttopwidthheightwindowStatebrowserContextIdenableBeginFrameControl	newWindow
backgroundforTabhiddenr*   )r   r   r   CREATE_TARGET)rF   rG   rH   rI   rJ   window_statebrowser_context_idenable_begin_frame_control
new_windowrO   for_tabrQ   r,   s                r0   create_targetzTargetCommands.create_target   s    b $,!F6N?F5M#F7O%F8#$0F=!));F%&%10JF,-!",F;!#-F< &F8%F8l88HHr2   c                Z    t               }| | |d<   t        t        j                  |      S )av  
        Generates a command to detach a session from its target.

        After detaching, you will no longer receive events from the target and
        cannot send commands to it.

        Args:
            session_id: Session ID to detach. If not specified, detaches all sessions.

        Returns:
            Command: The CDP command to detach from the target.
        	sessionIdr*   )r   r   r   DETACH_FROM_TARGET
session_idr,   s     r0   detach_from_targetz!TargetCommands.detach_from_target   s/     ()!",F;l==fMMr2   c                P    t        |       }t        t        j                  |      S )a  
        Generates a command to delete a browser context.

        All pages belonging to the browser context will be closed without calling
        their beforeunload hooks. This is similar to closing an incognito profile.

        Args:
            browser_context_id: The ID of the browser context to dispose.

        Returns:
            Command: The CDP command to dispose the browser context.
        )rL   r*   )r   r   r   DISPOSE_BROWSER_CONTEXT)rT   r,   s     r0   dispose_browser_contextz&TargetCommands.dispose_browser_context   s"     ->PQlBB6RRr2   c                 8    t        t        j                  i       S )a  
        Generates a command to get all browser contexts created with createBrowserContext.

        This is useful for obtaining a list of all available contexts for managing
        multiple isolated browser sessions.

        Returns:
            Command: The CDP command to get all browser contexts, which will return
                    an array of browser context IDs.
        r*   )r   r   GET_BROWSER_CONTEXTS r2   r0   get_browser_contextsz#TargetCommands.get_browser_contexts  s     l??KKr2   c                Z    t               }| | |d<   t        t        j                  |      S )a  
        Generates a command to retrieve a list of available targets.

        Targets include tabs, extensions, web workers, and other attachable entities
        in the browser. This is useful for discovering what targets exist before
        attaching to them.

        Args:
            filter: Only targets matching the filter will be reported. If filter is not
                   specified and target discovery is currently enabled, a filter used for
                   target discovery is used for consistency.

        Returns:
            Command: The CDP command to get targets, which will return a list of
                    TargetInfo objects with details about each target.
        filterr*   )r   r   r   GET_TARGETS)rg   r,   s     r0   get_targetszTargetCommands.get_targets  s/    $ "#%F8l66vFFr2   c                n    t        | |      }|||d<   |||d<   t        t        j                  |      S )aY  
        Generates a command to control whether to automatically attach to new targets.

        This method controls whether to automatically attach to new targets which are
        considered to be directly related to the current one (for example, iframes or workers).
        When turned on, it also attaches to all existing related targets. When turned off,
        it automatically detaches from all currently attached targets.

        Args:
            auto_attach: Whether to auto-attach to related targets.
            wait_for_debugger_on_start: Whether to pause new targets when attaching to them.
                                       Use Runtime.runIfWaitingForDebugger to run paused targets.
            flatten: Enables "flat" access to the session via specifying sessionId attribute
                    in the commands. This mode is being preferred, and non-flattened mode
                    is being deprecated (see crbug.com/991325).
            filter: Only targets matching filter will be attached.

        Returns:
            Command: The CDP command to set auto-attach behavior.
        )
autoAttachwaitForDebuggerOnStartr4   rg   r*   )r   r   r   SET_AUTO_ATTACH)auto_attachwait_for_debugger_on_startr4   rg   r,   s        r0   set_auto_attachzTargetCommands.set_auto_attach*  sI    6 %";U
  'F9%F8l::6JJr2   c                ^    t        |       }|||d<   t        t        j                  |      S )au  
        Generates a command to control target discovery.

        This method controls whether to discover available targets and notify via
        targetCreated/targetInfoChanged/targetDestroyed events. Target discovery is useful
        for monitoring when new tabs, workers, or other targets are created or destroyed.

        Args:
            discover: Whether to discover available targets.
            filter: Only targets matching filter will be discovered. If discover is false,
                   filter must be omitted or empty.

        Returns:
            Command: The CDP command to set target discovery.
        )discoverrg   r*   )r   r   r   SET_DISCOVER_TARGETS)rr   rg   r,   s      r0   set_discover_targetsz#TargetCommands.set_discover_targetsN  s1    & *8<%F8l??OOr2   c                P    t        |       }t        t        j                  |      S )a  
        Generates a command to attach to the browser target.

        This is an experimental method that attaches to the browser target,
        only using flat sessionId mode. The browser target is a special target that
        represents the browser itself rather than a page or other content.

        Args:
            session_id: ID of the session to attach to the browser target.

        Returns:
            Command: The CDP command to attach to the browser target,
                    which will return a new session ID.
        )rZ   r*   )r   r   r   ATTACH_TO_BROWSER_TARGETr\   s     r0   attach_to_browser_targetz'TargetCommands.attach_to_browser_targetf  s!      -zBlCCFSSr2   c                P    t        |       }t        t        j                  |      S )a  
        Generates a command to get information about a specific target.

        This experimental method returns detailed information about a target,
        such as its type, URL, title, and other properties.

        Args:
            target_id: ID of the target to get information about.

        Returns:
            Command: The CDP command to get target information, which will return
                    a TargetInfo object with details about the target.
        r(   r*   )r   r   r   GET_TARGET_INFOr.   s     r0   get_target_infozTargetCommands.get_target_infoy  s!     %i8l::6JJr2   c                P    t        |       }t        t        j                  |      S )a  
        Generates a command to enable target discovery for specified remote locations.

        This experimental method enables target discovery for remote locations when
        setDiscoverTargets was set to true. This is useful for discovering targets
        on remote devices or in different browser instances.

        Args:
            locations: list of remote locations, each containing a host and port.

        Returns:
            Command: The CDP command to set remote locations for target discovery.
        )	locationsr*   )r   r   r   SET_REMOTE_LOCATIONS)r|   r,   s     r0   set_remote_locationsz#TargetCommands.set_remote_locations  s!     *I>l??OOr2   )r/   strreturnr   )N)r/   r   r4   Optional[bool]r   r   )r/   r   r   r   )NNNN)
r@   r   rA   Optional[str]rB   r   rC   zOptional[list[str]]r   r   )zabout:blankNNNNNNNNNNN)rF   r   rG   Optional[int]rH   r   rI   r   rJ   r   rS   zOptional[WindowState]rT   r   rU   r   rV   r   rO   r   rW   r   rQ   r   r   r   )r]   r   r   r   )rT   r   r   r   )r   r   )rg   Optional[list]r   r    )FNN)
rn   boolro   r   r4   r   rg   r   r   r!   )rr   r   rg   r   r   r"   )r]   r   r   r   )r/   r   r   r   )r|   zlist[RemoteLocation]r   r#   )__name__
__module____qualname____doc__staticmethodr1   r6   r9   rD   rX   r^   ra   re   ri   rp   rt   rw   rz   r~   rd   r2   r0   r&   r&   ,   s   	 K K L L* H H  ,0&*+/EI	'R)'R#'R )'R 0C	'R
 
%'R 'RR  "!# $.2,059%)%)"&!%GIGIGI GI 	GI
 GI ,GI *GI %3GI #GI #GI  GI GI 
GI GIR N N$ S S  L L G G,  ,1"&!%	!K!K$(!K  !K 	!K
 
!K !KF 15PP .P	"P P. T T$ K K" P Pr2   r&   N))
__future__r   typingr   r   pydoll.protocol.baser   pydoll.protocol.target.methodsr   r   r	   r
   r   r   r   r   r   r   r   r   r   r   pydoll.protocol.browser.typesr   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   pydoll.protocol.target.typesr$   r&   rd   r2   r0   <module>r      sQ    " * (   " 9     <oP oPr2   