
    >i_H                       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mZmZ d dlmZmZ er@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(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/ d dlm0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6  G d d	      Z7y
)    )annotations)TYPE_CHECKINGOptional)Command)+AddPrivacySandboxCoordinatorKeyConfigParams)AddPrivacySandboxEnrollmentOverrideParamsBrowserMethodCancelDownloadParamsExecuteBrowserCommandParamsGetHistogramParamsGetHistogramsParamsGetWindowBoundsParamsGetWindowForTargetParamsGrantPermissionsParamsResetPermissionsParamsSetContentsSizeParamsSetDockTileParamsSetDownloadBehaviorParamsSetPermissionParamsSetWindowBoundsParams)BoundsWindowState),AddPrivacySandboxCoordinatorKeyConfigCommand*AddPrivacySandboxEnrollmentOverrideCommandCancelDownloadCommandCloseCommandCrashCommandCrashGpuProcessCommandDownloadBehaviorExecuteBrowserCommandCommandGetBrowserCommandLineCommandGetHistogramCommandGetHistogramsCommandGetVersionCommandGetWindowBoundsCommandGetWindowForTargetCommandGrantPermissionsCommandResetPermissionsCommandSetContentsSizeCommandSetDockTileCommandSetDownloadBehaviorCommandSetPermissionCommandSetWindowBoundsCommand)BrowserCommandIdBrowserContextIDPermissionDescriptorPermissionSettingPermissionTypePrivacySandboxAPIWindowIDc                     e Zd ZdZedd       Zedd       Ze	 	 d	 	 	 	 	 dd       Ze	 d	 	 	 	 	 d 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       Ze	 	 	 	 d)d       Ze	 d"	 	 	 	 	 	 	 	 	 d*d       Ze	 	 d%	 	 	 	 	 	 	 	 	 d+d       Ze	 	 d%	 	 	 	 	 	 	 d,d       Ze	 d"	 	 	 d-d       Ze	 	 	 d.	 	 	 	 	 	 	 	 	 d/d       Ze	 d"	 	 	 	 	 d0d       Zed1d       Zed2d       Zed3d       Zed4d       Zed4d       Zed4d       Zed4d       Zy)5BrowserCommandsa  
    BrowserCommands class provides a set of commands to interact with the
    browser's main functionality based on CDP. These commands allow for
    managing browser windows, such as closing windows, retrieving window IDs,
    and adjusting window bounds (size and state).

    The commands defined in this class provide functionality for:
    - Managing browser windows and targets.
    - Setting permissions and download behavior.
    - Controlling browser windows (size, state).
    - Retrieving browser information and versioning.
    c                 6    t        t        j                        S )a  
        Generates a command to get browser version information.

        Returns:
            GetVersionCommand: The CDP command that returns browser version details
                including protocol version, product name, revision, and user agent.
        method)r   r	   GET_VERSION     f/var/www/python/tenders/Scrapper/venv/lib/python3.12/site-packages/pydoll/commands/browser_commands.pyget_versionzBrowserCommands.get_versionN   s     m7788r<   c                 6    t        t        j                        S )a  
        Returns the command line switches for the browser process.

        Returns:
            GetBrowserCommandLineCommand: The CDP command that returns command line arguments.

        Note: Only works if --enable-automation is on the command line.
        r8   )r   r	   GET_BROWSER_COMMAND_LINEr;   r<   r=   get_browser_command_linez(BrowserCommands.get_browser_command_lineY   s     mDDEEr<   Nc                h    t               }| | |d<   |r||d<   t        t        j                  |      S )a  
        Get Chrome histograms.

        Args:
            query: Requested substring in name. Only histograms which have query as a
                   substring in their name are extracted. An empty or absent query returns
                   all histograms.
            delta: If true, retrieve delta since last delta call.

        Returns:
            GetHistogramsCommand: The CDP command that returns histogram data.
        querydeltar9   params)r   r   r	   GET_HISTOGRAMS)rC   rD   rF   s      r=   get_histogramszBrowserCommands.get_histogramse   s:    " %&#F7O#F7Om::6JJr<   c                ^    t        |       }|r||d<   t        t        j                  |      S )a  
        Get a Chrome histogram by name.

        Args:
            name: Requested histogram name.
            delta: If true, retrieve delta since last delta call.

        Returns:
            GetHistogramCommand: The CDP command that returns histogram data.
        )namerD   rE   )r   r   r	   GET_HISTOGRAM)rJ   rD   rF   s      r=   get_histogramzBrowserCommands.get_histogram}   s-     $.#F7Om99&IIr<   c                P    t        |       }t        t        j                  |      S )z
        Get position and size of the browser window.

        Args:
            window_id: Browser window id.

        Returns:
            GetWindowBoundsCommand: The CDP command that returns window bounds information.
        windowIdrE   )r   r   r	   GET_WINDOW_BOUNDS)	window_idrF   s     r=   get_window_boundsz!BrowserCommands.get_window_bounds   s!     '	:m==fMMr<   c                Z    t               }| | |d<   t        t        j                  |      S )ax  
        Get the browser window that contains the devtools target.

        Args:
            target_id: Devtools agent host id. If called as a part of the session,
                      associated targetId is used.

        Returns:
            GetWindowForTargetCommand: The CDP command that returns window information
                including windowId and bounds.
        targetIdrE   )r   r   r	   GET_WINDOW_FOR_TARGET)	target_idrF   s     r=   get_window_for_targetz%BrowserCommands.get_window_for_target   s/     *+ !*F:mAA&QQr<   c                R    t        | |      }t        t        j                  |      S )a  
        Set position and/or size of the browser window.

        Args:
            window_id: Browser window id.
            bounds: New window bounds. The 'minimized', 'maximized' and 'fullscreen' states
                   cannot be combined with 'left', 'top', 'width' or 'height'. Leaves
                   unspecified fields unchanged.

        Returns:
            SetWindowBoundsCommand: The CDP command that sets window bounds.
        )rO   boundsrE   )r   r   r	   SET_WINDOW_BOUNDS)rQ   rY   rF   s      r=   set_window_boundsz!BrowserCommands.set_window_bounds   s#     '	&Im==fMMr<   c                l    t        |       }|||d<   |||d<   t        t        j                  |      S )a   
        Set size of the browser contents resizing browser window as necessary.

        Args:
            window_id: Browser window id.
            width: The window contents width in DIP. Assumes current width if omitted.
                  Must be specified if 'height' is omitted.
            height: The window contents height in DIP. Assumes current height if omitted.
                   Must be specified if 'width' is omitted.

        Returns:
            SetContentsSizeCommand: The CDP command that sets window contents size.
        rN   widthheightrE   )r   r   r	   SET_CONTENTS_SIZE)rQ   r]   r^   rF   s       r=   set_contents_sizez!BrowserCommands.set_contents_size   s@    & '	:#F7O%F8m==fMMr<   c                h    t               }| | |d<   |||d<   t        t        j                  |      S )a$  
        Set dock tile details, platform-specific.

        Args:
            badge_label: Optional badge label.
            image: Png encoded image (base64 string when passed over JSON).

        Returns:
            SetDockTileCommand: The CDP command that sets dock tile details.
        
badgeLabelimagerE   )r   r   r	   SET_DOCK_TILE)badge_labelrc   rF   s      r=   set_dock_tilezBrowserCommands.set_dock_tile   s>     #$"#.F< #F7Om99&IIr<   c                P    t        |       }t        t        j                  |      S )z
        Invoke custom browser commands used by telemetry.

        Args:
            command_id: Browser command identifier.

        Returns:
            ExecuteBrowserCommandCommand: The CDP command that executes browser command.
        )	commandIdrE   )r   r   r	   EXECUTE_BROWSER_COMMAND)
command_idrF   s     r=   execute_browser_commandz'BrowserCommands.execute_browser_command   s!     -zBmCCFSSr<   c                P    t        |       }t        t        j                  |      S )aX  
        Allows a site to use privacy sandbox features that require enrollment
        without the site actually being enrolled. Only supported on page targets.

        Args:
            url: Site URL.

        Returns:
            AddPrivacySandboxEnrollmentOverrideCommand: The CDP command that adds enrollment
            override.
        )urlrE   )r   r   r	   'ADD_PRIVACY_SANDBOX_ENROLLMENT_OVERRIDE)rm   rF   s     r=   'add_privacy_sandbox_enrollment_overridez7BrowserCommands.add_privacy_sandbox_enrollment_override  s"     ;sCmSS\bccr<   c                b    t        | ||      }|||d<   t        t        j                  |      S )a  
        Configures encryption keys used with a given privacy sandbox API to talk
        to a trusted coordinator. Since this is intended for test automation only,
        coordinatorOrigin must be a .test domain. No existing coordinator
        configuration for the origin may exist.

        Args:
            api: Privacy Sandbox API type.
            coordinator_origin: Coordinator origin (must be .test domain).
            key_config: Key configuration string.
            browser_context_id: BrowserContext to perform the action in. When omitted,
                               default browser context is used.

        Returns:
            AddPrivacySandboxCoordinatorKeyConfigCommand: The CDP command that adds key config.
        )apicoordinatorOrigin	keyConfigbrowserContextIdrE   )r   r   r	   *ADD_PRIVACY_SANDBOX_COORDINATOR_KEY_CONFIG)rq   coordinator_origin
key_configbrowser_context_idrF   s        r=   *add_privacy_sandbox_coordinator_key_configz:BrowserCommands.add_privacy_sandbox_coordinator_key_config  sC    . =0 

 ));F%& KKTZ
 	
r<   c                n    t        | |      }|||d<   |||d<   t        t        j                  |      S )a  
        Set permission settings for given origin.

        Args:
            permission: Descriptor of permission to override.
            setting: Setting of the permission.
            origin: Origin the permission applies to, all origins if not specified.
            browser_context_id: Context to override. When omitted, default browser context is used.

        Returns:
            SetPermissionCommand: The CDP command that sets permission.
        )
permissionsettingoriginrt   rE   )r   r   r	   SET_PERMISSION)r{   r|   r}   rx   rF   s        r=   set_permissionzBrowserCommands.set_permission6  sD    & %
GL%F8));F%&m::6JJr<   c                l    t        |       }|||d<   |||d<   t        t        j                  |      S )a  
        Grant specific permissions to the given origin and reject all others.

        Args:
            permissions: List of permissions to grant.
            origin: Origin the permission applies to, all origins if not specified.
            browser_context_id: BrowserContext to override permissions. When omitted,
                               default browser context is used.

        Returns:
            GrantPermissionsCommand: The CDP command that grants permissions.
        )permissionsr}   rt   rE   )r   r   r	   GRANT_PERMISSIONS)r   r}   rx   rF   s       r=   grant_permissionsz!BrowserCommands.grant_permissionsP  sB    $ (K@%F8));F%&m==fMMr<   c                Z    t               }| | |d<   t        t        j                  |      S )aD  
        Reset all permission management for all origins.

        Args:
            browser_context_id: BrowserContext to reset permissions. When omitted,
                               default browser context is used.

        Returns:
            ResetPermissionsCommand: The CDP command that resets permissions.
        rt   rE   )r   r   r	   RESET_PERMISSIONS)rx   rF   s     r=   reset_permissionsz!BrowserCommands.reset_permissionsi  s0     ()));F%&m==fMMr<   c                z    t        |       }|||d<   |||d<   |||d<   t        t        j                  |      S )a@  
        Set the behavior when downloading a file.

        Args:
            behavior: Whether to allow all or deny all download requests, or use default
                     Chrome behavior if available (otherwise deny). allowAndName allows
                     download and names files according to their download guids.
            browser_context_id: BrowserContext to set download behavior. When omitted,
                               default browser context is used.
            download_path: The default path to save downloaded files to. This is required
                          if behavior is set to 'allow' or 'allowAndName'.
            events_enabled: Whether to emit download events (defaults to false).

        Returns:
            SetDownloadBehaviorCommand: The CDP command that sets download behavior.
        )behaviorrt   downloadPatheventsEnabledrE   )r   r   r	   SET_DOWNLOAD_BEHAVIOR)r   rx   download_pathevents_enabledrF   s        r=   set_download_behaviorz%BrowserCommands.set_download_behavior|  sR    . +H=));F%&$%2F>"%&4F?#mAA&QQr<   c                ^    t        |       }|||d<   t        t        j                  |      S )aq  
        Cancel a download if in progress.

        Args:
            guid: Global unique identifier of the download.
            browser_context_id: BrowserContext to perform the action in. When omitted,
                               default browser context is used.

        Returns:
            CancelDownloadCommand: The CDP command that cancels download.
        )guidrt   rE   )r
   r   r	   CANCEL_DOWNLOAD)r   rx   rF   s      r=   cancel_downloadzBrowserCommands.cancel_download  s2      &40));F%&m;;FKKr<   c                 6    t        t        j                        S )z
        Close browser gracefully.

        Returns:
            CloseCommand: The CDP command that closes the browser.
        r8   )r   r	   CLOSEr;   r<   r=   closezBrowserCommands.close       m1122r<   c                 6    t        t        j                        S )z
        Crashes browser on the main thread.

        Returns:
            CrashCommand: The CDP command that crashes the browser.
        r8   )r   r	   CRASHr;   r<   r=   crashzBrowserCommands.crash  r   r<   c                 6    t        t        j                        S )z
        Crashes GPU process.

        Returns:
            CrashGpuProcessCommand: The CDP command that crashes the GPU process.
        r8   )r   r	   CRASH_GPU_PROCESSr;   r<   r=   crash_gpu_processz!BrowserCommands.crash_gpu_process  s     m==>>r<   c                b    t        t        j                        }t        j	                  | |      S )z
        Maximize a browser window.

        Args:
            window_id: Browser window id.

        Returns:
            SetWindowBoundsCommand: The CDP command that maximizes the window.
        windowState)r   r   	MAXIMIZEDr6   r[   rQ   rY   s     r=   set_window_maximizedz$BrowserCommands.set_window_maximized  '     K$9$9:00FCCr<   c                b    t        t        j                        }t        j	                  | |      S )z
        Minimize a browser window.

        Args:
            window_id: Browser window id.

        Returns:
            SetWindowBoundsCommand: The CDP command that minimizes the window.
        r   )r   r   	MINIMIZEDr6   r[   r   s     r=   set_window_minimizedz$BrowserCommands.set_window_minimized  r   r<   c                b    t        t        j                        }t        j	                  | |      S )z
        Set a browser window to fullscreen.

        Args:
            window_id: Browser window id.

        Returns:
            SetWindowBoundsCommand: The CDP command that sets window to fullscreen.
        r   )r   r   
FULLSCREENr6   r[   r   s     r=   set_window_fullscreenz%BrowserCommands.set_window_fullscreen  s'     K$:$:;00FCCr<   c                b    t        t        j                        }t        j	                  | |      S )z
        Set a browser window to normal state.

        Args:
            window_id: Browser window id.

        Returns:
            SetWindowBoundsCommand: The CDP command that sets window to normal state.
        r   )r   r   NORMALr6   r[   r   s     r=   set_window_normalz!BrowserCommands.set_window_normal  s'     K$6$6700FCCr<   )returnr$   )r   r!   )NF)rC   Optional[str]rD   boolr   r#   )F)rJ   strrD   r   r   r"   )rQ   r4   r   r%   )N)rV   r   r   r&   )rQ   r4   rY   r   r   r-   )NN)rQ   r4   r]   Optional[int]r^   r   r   r)   )re   r   rc   r   r   r*   )rj   r.   r   r    )rm   r   r   r   )
rq   r3   rv   r   rw   r   rx   Optional[BrowserContextID]r   r   )
r{   r0   r|   r1   r}   r   rx   r   r   r,   )r   zlist['PermissionType']r}   r   rx   Optional['BrowserContextID']r   r'   )rx   r   r   r(   )NNF)
r   r   rx   r   r   r   r   r   r   r+   )r   r   rx   r   r   r   )r   r   )r   r   )r   r   )rQ   r4   r   r-   )__name__
__module____qualname____doc__staticmethodr>   rA   rH   rL   rR   rW   r[   r`   rf   rk   ro   ry   r   r   r   r   r   r   r   r   r   r   r   r   r;   r<   r=   r6   r6   @   s    9 9 	F 	F #KKK 
K K.  JJJ 
J J& N N #'R R	"R R& N N    $ $NNN N 
 	N N2 %)#J"JJ 
J J* T T dd	3d d" 
 :>	


 
 7	

 
6
 
B  !%9=	K(K"K K 7	K
 
K K2  !%;?N+NN 9N 
!	N N0 ;?N8N	 N N$  <@'+$	R"R8R %R 	R
 
$R R>  <@LL8L 
L L( 3 3 3 3 ? ? D D D D D D D Dr<   r6   N)8
__future__r   typingr   r   pydoll.protocol.baser   pydoll.protocol.browser.methodsr   r   r	   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%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r6   r;   r<   r=   <module>r      sl    " * (    $
      .  FD FDr<   