
    dh                        S r SSKJr  SSKrSSKJrJrJrJrJ	r	J
r
  \(       a  SSKJr  SSKJr  SSKJr  SSKJr  SS jrSS jr S     SS	 jjr S     SS
 jjr\
" S5      rSS jrg)z+Utilities for the Playwright browser tools.    )annotationsN)TYPE_CHECKINGAny	CoroutineListOptionalTypeVar)Browser)Pagec                &  #    U R                   (       d0  U R                  5       I Sh  vN nUR                  5       I Sh  vN $ U R                   S   nUR                  (       d  UR                  5       I Sh  vN $ UR                  S   $  Nc NM N7f)z
Asynchronously get the current page of the browser.

Args:
    browser: The browser (AsyncBrowser) to get the current page from.

Returns:
    AsyncPage: The current page.
Nr   contextsnew_contextnew_pagepagesbrowsercontexts     b/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/tools/playwright/utils.pyaget_current_pager      sx      ++--%%'''q!G==%%'''== .' (s2   %BBBB 7B7B8BBBc                    U R                   (       d   U R                  5       nUR                  5       $ U R                   S   nUR                  (       d  UR                  5       $ UR                  S   $ )z
Get the current page of the browser.
Args:
    browser: The browser to get the current page from.

Returns:
    SyncPage: The current page.
r   r   r   r   s     r   get_current_pager   #   s_     %%'!!q!G==!!==    c                    SSK Jn  [        U" 5       R                  5       5      n[        UR                  R                  XS95      $ )z
Create an async playwright browser.

Args:
    headless: Whether to run the browser in headless mode. Defaults to True.
    args: arguments to pass to browser.chromium.launch

Returns:
    AsyncBrowser: The playwright browser.
r   )async_playwrightheadlessargs)playwright.async_apir   	run_asyncstartchromiumlaunch)r   r   r   r   s       r   create_async_playwright_browserr%   6   s=     6(*0023GW%%,,h,JKKr   c                j    SSK Jn  U" 5       R                  5       nUR                  R	                  XS9$ )z
Create a playwright browser.

Args:
    headless: Whether to run the browser in headless mode. Defaults to True.
    args: arguments to pass to browser.chromium.launch

Returns:
    SyncBrowser: The playwright browser.
r   )sync_playwrightr   )playwright.sync_apir'   r"   r#   r$   )r   r   r'   r   s       r   create_sync_playwright_browserr)   I   s2     4%%'G""H"@@r   Tc                N    [         R                  " 5       nUR                  U 5      $ )zRun an async coroutine.

Args:
    coro: The coroutine to run. Coroutine[Any, Any, T]

Returns:
    T: The result of the coroutine.
)asyncioget_event_looprun_until_complete)coro
event_loops     r   r!   r!   _   s#     '')J((..r   )r   AsyncBrowserreturn	AsyncPage)r   SyncBrowserr2   SyncPage)TN)r   boolr   Optional[List[str]]r2   r1   )r   r6   r   r7   r2   r4   )r/   zCoroutine[Any, Any, T]r2   r*   )__doc__
__future__r   r,   typingr   r   r   r   r   r	   r    r
   r1   r   r3   r(   r4   r5   r   r   r%   r)   r*   r!    r   r   <module>r<      s    1 "  I I<6:4(( 8<LL!4LL( 8<AA!4AA& CL
/r   