
    MiB                        % S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
r
SSKJr  SSKJr  SSKJrJrJrJrJr  SSKJr  SSKJr  SS	KJr  SS
KJrJrJr  SSKJ r    " S S\!\5      r"\"RF                  S1\"RH                  1 Sk\"RJ                  1 Sk\"RL                  1 Sk\"RN                  1 Sk0r(\\"\\!   4   \)S'   S\S\*4S jr+S\*S\!4S jr,\"RL                  S4S\!S\"S\-S\\!\4   4S jjr. " S S5      r/\0S :X  a  \/" 5       r1SSKrSSKJr  \Rd                  " 5       r3\Rh                  " \1Rk                  \!" \3S!-  5      5      5      r6\Rh                  " \1Ro                  5       5        \1Rq                  5       r9\9 H  r:\;" S"\:S#    S$\:S    35        M     \1Ry                  S%5      r=\=(       a	  \;" S&5        g\;" S'5        gg)(z
Browser Profiler Module

This module provides a dedicated class for managing browser profiles
that can be used for identity-based crawling with Crawl4AI.
    N)Enum)Path)ListDictOptionalAnySet)Console   BrowserConfig)ManagedBrowser)AsyncLoggerAsyncLoggerBaseLogColor)get_home_folderc                   ,    \ rS rSrSrSrSrSrSrSr	Sr
g	)
ShrinkLevel   z%Profile shrink aggressiveness levels.nonelightmedium
aggressiveminimal N)__name__
__module____qualname____firstlineno____doc__NONELIGHTMEDIUM
AGGRESSIVEMINIMAL__static_attributes__r       s/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/crawl4ai/browser_profiler.pyr   r      s    /DEFJGr'   r   *>   CookiesHistoryNetwork	Bookmarks	IndexedDBPreferencesTransportSecurityWeb Data
Login DataTrust TokensLocal StorageVisited LinksHistory-journalSession StorageSecure Preferencesstorage_state.jsonLogin Data For Account>   r*   r,   r.   r/   r0   r1   r2   r4   r7   r8   r9   r:   >   r*   r,   r.   r/   r4   r9   >   r*   r,   r4   r9   KEEP_PATTERNSpathreturnc                 .   U R                  5       (       a  U R                  5       R                  $ Sn U R                  S5       H6  nUR                  5       (       d  M  XR                  5       R                  -  nM8     U$ ! [        [
        4 a     U$ f = f)z9Get total size in bytes. Works for files and directories.r   r)   )is_filestatst_sizerglobPermissionErrorOSError)r<   totalfs      r(   	_get_sizerG   <   s    ||~~yy{"""ECAyy{{))) !
 L W% Ls   'B   B   BBnc                 J    S H  nU S:  a
  U S SU 3s  $ U S-  n M     U S S3$ )z&Format bytes as human-readable string.)BKBMBGBi   z.1f z TBr   )rH   us     r(   _format_sizerP   J   s>    $t8WAaS>!	T	 % WC=r'   Fprofile_pathleveldry_runc                   ^
 U[         R                  :X  a  / / S/ S.$ [        U 5      nUR                  5       (       a  UR	                  5       (       d  [        SU  35      eUS-  R	                  5       (       a  US-  OUn[        U   n/ / S/ [        U5      S.nUR                  5        H  nUR                  m
[        U
4S jU 5       5      (       a  US   R                  T
5        M?  [        U5      nU(       d_   UR	                  5       (       a  [        R                  " U5      OUR                  5         US   R                  T
5        US	==   U-  ss'   M  US   R                  T
5        US	==   U-  ss'   M     U(       d  [        U5      OSUS'   U$ ! [         a%  n	US
   R                  T
 SU	 35         Sn	A	GM  Sn	A	ff = f)aZ  
Shrink a Chrome profile to reduce storage while preserving auth data.

Args:
    profile_path: Path to profile directory
    level: How aggressively to shrink (LIGHT/MEDIUM/AGGRESSIVE/MINIMAL)
    dry_run: If True, only report what would be removed

Returns:
    Dict with 'removed', 'kept', 'bytes_freed', 'size_before', 'size_after', 'errors'
r   )removedkeptbytes_freederrorsProfile not found: Default)rU   rV   rW   rX   size_beforec              3   ^   >#    U  H"  nTU:H  =(       d    TR                  U5      v   M$     g 7fN)
startswith).0pnames     r(   	<genexpr>!shrink_profile.<locals>.<genexpr>s   s&     =1tqy.DOOA..s   *-rV   rU   rW   rX   z: N
size_after)r   r!   r   existsis_dir
ValueErrorr;   rG   iterdirra   anyappendshutilrmtreeunlink	Exception)rQ   rR   rS   profiletargetkeepresultitemsizeera   s             @r(   shrink_profilerv   S   s        r!rJJ< G>>7>>#3#3.|n=>> &-y%8$@$@$B$BWy FDRRXabiXjkF yy====6N!!$'T?D<+/;;==FMM$'dkkm9%,,T2=)T1) y!((.}%-%! !$ 6=9W-$F<M ! <8$++tfBqcN;;<s   ;AF
G!GGc                   d   \ rS rSrSrS*S\\   4S jjrS\4S jr	S\4S jr
S\4S	 jrS
\S\4S jrS
\4S jrS\R                   S
\4S jrS\R                   S
\4S jrSS\R(                  4S\\   S\\   S\S\\   4S jjrS\\\\4      4S jrS\S\\   4S jrS\S\4S jr\R:                  S4S\S\S\S\\\4   4S jjrS*S jr     S+S\S\\   S\ S \S!\S\\   4S" jjr!   S,S\S\ S \S\\   4S# jjr"S\\\\4      4S$ jr#S%\\    S\4S& jr$S\4S' jr%S\\\4   4S( jr&S)r'g)-BrowserProfiler   a3  
A dedicated class for managing browser profiles for Crawl4AI.

The BrowserProfiler allows you to:
- Create browser profiles interactively
- List available profiles
- Delete profiles when no longer needed
- Get profile paths for use in BrowserConfig

Profiles are stored by default in ~/.crawl4ai/profiles/
Nloggerc                 (   [        5       U l        Uc  [        SS9U l        O*[	        U[
        5      (       d  [        SS9U l        OXl        [        R                  R                  [        5       S5      U l
        [        R                  " U R                  SS9  [        R                  R                  [        5       S5      U l        [        R                  R                  U R                  S5      U l        [        R                  " U R                  SS9  g)z
Initialize the BrowserProfiler.

Args:
    logger (AsyncLoggerBase, optional): Logger for outputting messages.
        If None, a default AsyncLogger will be created.
NT)verboseprofilesexist_okzbuiltin-browserzbrowser_config.json)r
   consoler   rz   
isinstancer   osr<   joinr   profiles_dirmakedirsbuiltin_browser_dirbuiltin_config_file)selfrz   s     r(   __init__BrowserProfiler.__init__   s     y >%d3DKFO44%d3DK K GGLL):JG
D%%5 $&77<<0ACT#U #%77<<0H0HJ_#` 
D,,t<r'   r=   c                 t    [         R                  R                  S5      =(       d    [         R                  S:H  $ )z%Check if running on Windows platform.wincygwinsysplatformr^   r   s    r(   _is_windowsBrowserProfiler._is_windows   s%    ||&&u-I1IIr'   c                 (    [         R                  S:H  $ )z#Check if running on macOS platform.darwin)r   r   r   s    r(   	_is_macosBrowserProfiler._is_macos   s    ||x''r'   c                 @    [         R                  R                  S5      $ )z#Check if running on Linux platform.linuxr   r   s    r(   	_is_linuxBrowserProfiler._is_linux   s    ||&&w//r'   tagc                      US:X  a  gUS:X  a  gg)z.Get appropriate quit message based on context.PROFILEz%Closing browser and saving profile...CDPzClosing browser...r   )r   r   s     r(   _get_quit_message!BrowserProfiler._get_quit_message   s    ):E\''r'   c                 Z  #     SSK n  UR                  5       (       a  UR                  5       nSn UR	                  S5      nU(       a  [        U5      S:w  a  MS  UR                  5       (       d  Mj  UR                  5       S:X  aI  U R                  R                  U R                  U5      U[        R                  S9  UR                  5         gU" 5       I Sh  vN (       a  g[        R                   " S	5      I Sh  vN   M  ! [         a    [        S5      ef = f! [
         a(     UR	                  S5      n N! [
         a      GMB  f = ff = f Nx NV! ["         aH  nU R                  R%                  S
U 3US9  [        R                   " S	5      I Sh  vN     SnAGM  SnAff = f7f)z0Windows-specific keyboard listener using msvcrt.r   Nz,msvcrt module not available on this platformzutf-8latin1r   qr   
base_color皙?z$Error in Windows keyboard listener: r   )msvcrtImportErrorkbhitgetchdecodeUnicodeDecodeErrorlenisprintablelowerrz   infor   r   GREENsetasynciosleeprn   warning)r   user_done_eventcheck_browser_processr   r   rawkeyru   s           r(   _listen_windowsBrowserProfiler._listen_windows   s    	N .<<>> ,,.C C%!jj1 #c(a-  ??,,  yy{c)(( 2237 #'/~~ ) 
 (++- /000 mmC(((S   	NLMM	N . %%"%**X"6C1 %$%	%6 1 ) ##&J1#$NTW#XmmC(((	s   F+D F+'E D E F+E 0F+2AE F+
E E	E #F+$E =E>E F+DF+
E(D;9E ;
EEE F+
EEE E 
F( 6F#FF#F+#F((F+r   c                   #     SSK nSSKnSSKn [        R
                  R                  5       nSn UR                  U5      n UR                  U5          UR                  [        R
                  // / S5      u  n
  nU
(       a  [        R
                  R                  S5      nU(       a  UR                  5       S:X  ak  U R                  R                  U R!                  U5      U["        R$                  S	9  UR'                  5          Ub   UR)                  XtR*                  U5        ggU" 5       I Sh  vN (       a#   Ub   UR)                  XtR*                  U5        gg[.        R0                  " S5      I Sh  vN   GM,  ! [         a    [        S5      ef = f! [        [        4 a    [        S5      ef = f! UR                   a  n	[        SU	 35      eSn	A	ff = f! [,         a'  n	U R                  R                  S
U	 3US9   Sn	A	gSn	A	ff = f N! [,         a'  n	U R                  R                  S
U	 3US9   Sn	A	gSn	A	ff = f N! [2        [4        4 a    U R                  R                  SUS9  UR'                  5          UbR   UR)                  XtR*                  U5        g! [,         a'  n	U R                  R                  S
U	 3US9   Sn	A	gSn	A	ff = fg[,         aH  n	U R                  R7                  SU	 3US9  [.        R0                  " S5      I Sh  vN     Sn	A	GM  Sn	A	ff = f! UbR   UR)                  XtR*                  U5        f ! [,         a'  n	U R                  R                  S
U	 3US9   Sn	A	f Sn	A	ff = ff = f7f)z<Unix/Linux/macOS keyboard listener using termios and select.r   Nz9termios/tty/select modules not available on this platformzstdin is not a terminalz Cannot get terminal attributes:       ?r   r   r   z%Failed to restore terminal settings: r   r   zKeyboard interrupt receivedz!Error in Unix keyboard listener: )termiosttyselectr   r   stdinfilenoAttributeErrorrD   	tcgetattrerror	setcbreakreadr   rz   r   r   r   r   r   	tcsetattr	TCSADRAINrn   r   r   KeyboardInterruptEOFErrorr   )r   r   r   r   r   r   r   fdold_settingsru   readable_r   s                r(   _listen_unixBrowserProfiler._listen_unix   sr    	[
	9!!#B
 	F",,R0L.	\MM"! &,]]CII;B%LNHa!iinnQ/399;##5 KK,, $ 6 6s ;$'+3>> - 
 ,//1"* '\%%b*;*;\J (% 3444" '\%%b*;*;\J ( "--,,,1 )  	[YZZ	[ ( 	9788	9 }} 	F @DEE	F` ! \KK%%(MaS&QWZ%[\+ 5* ! \KK%%(MaS&QWZ%[\# -)84 KK$$%B$L#'') '\%%b*;*;\J  \KK%%(MaS&QWZ%[\ ( ! KK''*KA3(OUX'Y!--,,, '\%%b*;*;\J  \KK%%(MaS&QWZ%[\ (s  NF F NF: L1 B0I NG  (N*
I 4H5	I ?NH N!I :I
;I ?L1 FNF77N:G
GGN 
H*HNHNI 
I I=NIN
I :L.L1 NJ( 'N(
K2KNKN	L.&6L)LL)"L1 )L..L1 1N6MN
NM?:N?NNNc                 
  ^ ^^^
#    T R                   R                  STS9  SSKnSSKnUR	                  5       m
U
U UU4S jnUR                  USS9nUR                  5          TR                  5       (       d   T
R                  5       nUS:X  aI  T R                   R                  T R                  T5      T[        R                  S	9  TR                  5         g U" 5       I Sh  vN (       a  g[        R                  " S
5      I Sh  vN   TR                  5       (       d  M  gg! UR                   a     N^f = f NW N5! [          a7  n	T R                   R#                  SU	 3TS9  TR                  5          Sn	A	gSn	A	ff = f7f)z7Fallback keyboard listener using simple input() method.z<Using fallback input mode. Type 'q' and press Enter to quit.r   r   Nc                    >  TR                  5       (       dY   [        S5      R                  5       R                  5       n TR	                  U 5        U S:X  a  g TR                  5       (       d  MX  gg! [
        [        4 a    TR	                  S5         g[         a'  nTR                  R                  SU 3TS9   SnAgSnAff = f! [         a'  nTR                  R                  SU 3TS9   SnAgSnAff = f)z Thread function to handle input.zPress 'q' + Enter to quit: r   zError in input thread: r   NzInput thread failed: )is_setinputstripr   putr   r   rn   rz   r   r   )
user_inputru   input_queuer   r   r   s     r(   input_thread6BrowserProfiler._listen_fallback.<locals>.input_threadL  s    H)0022%*+H%I%O%O%Q%W%W%Y
#
3%,! - *0022 %&78 #,$ ++.EaS,Is+S  H!!$9!"=3!GHsL   C >A2 C 2!CC 	CC ;C  CC 
C9C44C9T)rp   daemonr   r   r   zFallback listener failed: )rz   r   	threadingqueueQueueThreadstartr   
get_nowaitr   r   r   r   Emptyr   r   rn   r   )r   r   r   r   r   r   r   threadr   ru   r   s   `` `      @r(   _listen_fallback BrowserProfiler._listen_fallbackB  sg    W]`a 	kkm	H 	H( !!d!C	"%,,..!,!7!7!9J!S((( 2237 #'/~~ ) 
 (++- ) /000 mmC((() &,,.. {{  1 ) 	"KK :1#>CH!!	"s   AF#D? 9AD% FD? #D;$	D? -F.D? D=D? #F%D85D? 7D88D? =D? ?
F 	-E;6F;F  Fprofile_namebrowser_configshrink_levelc                   ^ ^^^^^#    SS/nUc  SSK Jn  U" SSSUS	9nO:SUl        UR                  (       a  UR                  R	                  U5        OXBl        U(       dU  [
        R
                  R                  5       R                  S
5      nSU S[        R                  " 5       R                  SS  3nSR                  S U 5       5      n[        R                  R                  T R                  U5      n[        R                  " USS9  S nT R                   R#                  SSSSU 30S[$        R&                  0S9  T R                   R#                  SSSU0S[$        R(                  0S9  T R                   R#                  SSSU0S[$        R*                  0S9  T R                   R#                  SSS9  T R                   R#                  SSS9  T R                   R#                  SSSS 0S[$        R&                  0S9  T R                   R#                  S!SSS"0S[$        R*                  0S9  T R                   R#                  S#SS9  T R                   R#                  SSSU S30S[$        R&                  0S9  SUl        Xrl        [/        UT R                   S$9m[0        R2                  " [0        R4                  5      m[0        R2                  " [0        R6                  5      mUUUU 4S% jmU4S& jn	[0        R0                  " [0        R4                  U	5        [0        R0                  " [0        R6                  U	5        [8        R:                  " 5       mUU U4S' jn
 S(S)KJn  TRA                  5       I Sh  vN nU" 5       RA                  5       I Sh  vN nURB                  RE                  U5      I Sh  vN nURF                  S(   nTRH                  nU(       d~  T R                   RK                  S*SS9   [0        R0                  " [0        R4                  T5        [0        R0                  " [0        R6                  T5        TRM                  5       I Sh  vN   gT R                   R#                  S+SS9  [8        RN                  " U
" 5       5      nTRQ                  5       (       dW  URS                  5       cF  [8        RT                  " S,5      I Sh  vN   TRQ                  5       (       d  URS                  5       c  MF  URW                  5       (       d  URY                  5          UI Sh  vN   [        R                  R                  US-5      n UR]                  US.9I Sh  vN   T R                   R#                  S/U 3SS9  URc                  5       I Sh  vN   URe                  5       I Sh  vN   URS                  5       cG  TRQ                  5       (       a2  T R                   R#                  S1SS9  TRM                  5       I Sh  vN   T R                   Rg                  S2U 3SS9   [0        R0                  " [0        R4                  T5        [0        R0                  " [0        R6                  T5        TRM                  5       I Sh  vN   U[h        Rj                  :w  a?  U(       a8  T R                   R#                  S4URl                   3SS9  T Ro                  Xs5        U$  GNh GNN GN. GN GN GN! [8        RZ                   a     GNf = f GN! [^         a(  nT R                   Ra                  S0U 3SS9   SnAGNSnAff = f GN GN GNE! [^         a  nT R                   RK                  S3U< 3SS9  TRM                  5       I Sh  vN     SnA[0        R0                  " [0        R4                  T5        [0        R0                  " [0        R6                  T5        TRM                  5       I Sh  vN    gSnAff = f GNy! [0        R0                  " [0        R4                  T5        [0        R0                  " [0        R6                  T5        TRM                  5       I Sh  vN    f = f7f)5a  
Creates a browser profile by launching a browser for interactive user setup
and waits until the user closes it. The profile is stored in a directory that
can be used later with BrowserConfig.user_data_dir.

Args:
    profile_name (str, optional): Name for the profile directory.
        If None, a name is generated based on timestamp.
    browser_config (BrowserConfig, optional): Configuration for the browser.
        If None, a default configuration is used with headless=False.
    shrink_level (ShrinkLevel, optional): Optionally shrink profile after creation.
        Default is NONE (no shrinking).
        
Returns:
    str: Path to the created profile directory, or None if creation failed
    
Example:
    ```python
    profiler = BrowserProfiler()
    
    # Create a profile interactively
    profile_path = await profiler.create_profile(
        profile_name="my-login-profile"
    )
    
    # Use the profile in a crawler
    browser_config = BrowserConfig(
        headless=True,
        use_managed_browser=True,
        user_data_dir=profile_path
    )
    
    async with AsyncWebCrawler(config=browser_config) as crawler:
        # The crawler will now use your profile with all your cookies and login state
        result = await crawler.arun("https://example.com/dashboard")
    ```
z--password-store=basicz--use-mock-keychainNr   r   chromiumFT)browser_typeheadlessr|   
extra_args%Y%m%d_%H%M%Sprofile_r       c              3   ^   #    U  H#  oR                  5       (       d  US ;   a  UOSv   M%     g7f)z-_r   N)isalnum)r_   cs     r(   rb   1BrowserProfiler.create_profile.<locals>.<genexpr>  s#     \|!IIKK19q#E|s   +-r~   P================================================================================{border}r   border
r   paramscolorsz(Creating browser profile: {profile_name}r   z!Profile directory: {profile_path}rQ   z
Instructions:r   z=1. A browser window will open for you to set up your profile.z.{segment}, configure settings, etc. as needed.segmentz2. Log in to websitesz43. When you're done, {segment} to close the browser.zpress 'q' in this terminalz<4. The profile will be saved and ready to use with Crawl4AI.)r   rz   c                   >#    TR                   R                  SSS9  TR                  5       I S h  vN   [        R                  " [        R                  T5        [        R                  " [        R
                  T5        U [        R                  :X  a1  TR                   R                  SSS9  [        R                  " S5        g g  N7f)N
Cleaning up browser process...r   r   z8Profile creation interrupted. Profile may be incomplete.r   	rz   r   cleanupsignalSIGINTSIGTERMr   r   exitsigframemanaged_browseroriginal_sigintoriginal_sigtermr   s     r(   cleanup_handler7BrowserProfiler.create_profile.<locals>.cleanup_handler  s     KK B	R!))+++MM&--9MM&..*:;fmm#!!"\bk!l $	 ,   .CCBCc                 >   > [         R                  " T" X5      5        g r]   r   create_taskr
  r  r  s     r(   sigint_handler6BrowserProfiler.create_profile.<locals>.sigint_handler       ;<r'   c                    >#    TR                   R                  SSSS0S[        R                  0[        R                  S9  UUU4S jn  TR                  5       (       a  TR                  TU S5      I Sh  vN   gTR                  TU S5      I Sh  vN   g N! N! [         a]  nTR                   R                  SU 3SS	9  TR                   R                  S
SS	9  TR                  TU S5      I Sh  vN     SnAgSnAff = f7f)>Cross-platform keyboard listener that waits for 'q' key press.z9Press {segment} when you've finished using the browser...r   r   'q'r   r   r   r   c                     >#    T R                   (       aF  T R                   R                  5       b+  TR                  R                  SSS9  TR	                  5         gg7f)*Check if browser process is still running..Browser already closed. Ending input listener.r   r   TFbrowser_processpollrz   r   r   r  r   r   s   r(   r   ^BrowserProfiler.create_profile.<locals>.listen_for_quit_command.<locals>.check_browser_process  sV      $33'77<<>JKK$$Hi %  $'')   AAN,Platform-specific keyboard listener failed: r   $Falling back to simple input mode...rz   r   r   YELLOWCYANr   r   r   rn   r   r   r   ru   r  r   r   s     r(   listen_for_quit_command?BrowserProfiler.create_profile.<locals>.listen_for_quit_command  s      KKK!5)9hoo2N#==	  _##%%..@UW`aaa++O=RT]^^^ b^ _##&RSTRU$V\e#f  !GY W++O=RT]^^^_m   AD
+B 5B6B :D;B BB DB B 
D%AC=2C53C=8D=DDr   )async_playwright Failed to start browser process.z.Browser launched. Waiting for you to finish...r   r9   )r<   u%   [PROFILE].i  storage_state saved → z+[PROFILE].w  failed to save storage_state: Terminating browser process...z"Browser closed. Profile saved at: zError creating profile: zShrinking profile with level: )8async_configsr   r   r   extenddatetimenowstrftimeuuiduuid4hexr   r   r<   r   r   rz   r   r   r*  r   r)  user_data_dirr   r  	getsignalr  r  r   Eventplaywright.async_apir/  r   r   connect_over_cdpcontextsr!  r   r  r  r   r"  r   donecancelCancelledErrorstorage_statern   r   closestopsuccessr   r!   valueshrink)r   r   r   r   portable_profile_argsr   	timestamprQ   r   r  r,  r/  cdp_urlpwbrowsercontextr!  listener_task
state_fileru   r  r  r  r  r   s   `                   @@@@@r(   create_profileBrowserProfiler.create_profile~  s~    ` %!!

 !4*'0	N ',N#(())001FG,A)  ))--/88II%i[$**,2B2B2A2F1GHL ww\|\\ ww||D$5$5|D
L40 8H6(m;T^fhphuhu]vwC\jlx[y  DR  T\  Tb  Tb  Cc  	d<)UceqTr  }K  MU  M\  M\  |]  	^*	:X^ghIybk  nE  bF  PY  [c  [h  [h  Oi  	jOU^hq  tP  hQ  [d  fn  fu  fu  Zv  	wW]fgHPRm;T^fhphuhu]vw"''3$ )) ;;	
 !**6==9!++FNN;	 		= 	fmm^4fnnn5 "--/ 	_DB	,=
 ,1133G ./5577B[[99'BBG''*G .==O"!!"D)!TX MM&--9MM&..*:; "))+++] KKMS\] $//0G0IJM &,,..?3G3G3I3QmmC((( &,,..?3G3G3I3Q !%%''$$&'''
 l4HIJf+++<<<  #H!U[d e
 --/!!'')OO ##%-/2H2H2J2J  !Ay Q%--///KK"D\N SYbc MM&--9MM&..*:; "))+++ ;+++KK=l>P>P=QRXabKK3G 4 8Bp ,O ) (--  = f##&QRSQT$U[d#ef "
 0  	KK 8>IN!))+++ MM&--9MM&..*:; "))+++	 ,	 MM&--9MM&..*:; "))+++s  Ma#] 1[2] ["] 1[2A ] 3Aa#["a#A4] 
[%*] 7%] [+ "[(#[+ ' ] \	 \!\	 <] \>] '](A] ?] !] "Aa#?_8 Aa#] ] ] "a#%] ([+ +\?] \] \	 	
\;\60] 6\;;] ] ] 
_51_0^_0_; Aa#)_,*a#0_55_; 8a#;Aa aa  a#c                    [         R                  R                  U R                  5      (       d  / $ / n[         R                  " U R                  5       GH~  n[         R                  R                  U R                  U5      n[         R                  R                  U5      (       d  MT  Sn[         R                  R                  [         R                  R                  US5      5      (       dC  [         R                  R                  [         R                  R                  USS5      5      (       a  SnOD[         R                  R                  [         R                  R                  US5      5      (       a  SnU(       d  GM,  [        R                  R                  [         R                  R                  U5      5      nUR                  UUUUS.5        GM     UR                  S S	S
9  U$ )a  
Lists all available browser profiles in the Crawl4AI profiles directory.

Returns:
    list: A list of dictionaries containing profile information:
          [{"name": "profile_name", "path": "/path/to/profile", "created": datetime, "type": "chromium|firefox"}]
          
Example:
    ```python
    profiler = BrowserProfiler()
    
    # List all available profiles
    profiles = profiler.list_profiles()
    
    for profile in profiles:
        print(f"Profile: {profile['name']}")
        print(f"  Path: {profile['path']}")
        print(f"  Created: {profile['created']}")
        print(f"  Browser type: {profile['type']}")
    ```
Fr/   rZ   r   prefs.jsfirefox)ra   r<   createdtypec                     U S   $ )NrV  r   )xs    r(   <lambda>/BrowserProfiler.list_profiles.<locals>.<lambda>  s    AiLr'   T)r   reverse)r   r<   re   r   listdirr   isdirr4  fromtimestampgetctimerj   sort)r   r}   ra   rQ   is_validrV  s         r(   list_profilesBrowserProfiler.list_profilesp  sP   , ww~~d//00IJJt001D77<<(9(94@L 77==..
 Hww~~bggll<GHHww~~bggll<MRSS%\: FGG$x"++99GG$$\2  (&$	! 1 2@ 	0$?r'   c                    [         R                  R                  U R                  U5      n[         R                  R	                  U5      (       d(  [         R                  R                  U5      (       a  UnOg[         R                  R                  [         R                  R                  US5      5      =(       d    [         R                  R                  [         R                  R                  USS5      5      =(       d=    [         R                  R                  [         R                  R                  US5      5      nU(       d  gU$ )a  
Get the full path to a profile by name.

Args:
    profile_name (str): Name of the profile (not the full path)
    
Returns:
    str: Full path to the profile directory, or None if not found
    
Example:
    ```python
    profiler = BrowserProfiler()
    
    path = profiler.get_profile_path("my-profile")
    if path:
        print(f"Profile path: {path}")
    else:
        print("Profile not found")
    ```
Nr/   rZ   rT  )r   r<   r   r   r^  isabsre   )r   r   rQ   
is_profiles       r(   get_profile_path BrowserProfiler.get_profile_path  s    * ww||D$5$5|D ww}}\**ww}}\**+ GGNN277<<mDE CGGNN277<<iOPCGGNN277<<jAB 	 r'   profile_name_or_pathc                    [         R                  R                  U5      (       a  UnO*[         R                  R                  U R                  U5      n[         R                  R                  U5      (       d  g[         R                  R                  [         R                  R                  US5      5      =(       d    [         R                  R                  [         R                  R                  USS5      5      =(       d=    [         R                  R                  [         R                  R                  US5      5      nU(       d  g [        R                  " U5        g! [         a     gf = f)a  
Delete a browser profile by name or path.

Args:
    profile_name_or_path (str): Name of the profile or full path to profile directory
    
Returns:
    bool: True if the profile was deleted successfully, False otherwise
    
Example:
    ```python
    profiler = BrowserProfiler()
    
    # Delete by name
    success = profiler.delete_profile("my-profile")
    
    # Delete by path
    success = profiler.delete_profile("/path/to/.crawl4ai/profiles/my-profile")
    ```
Fr/   rZ   rT  T)
r   r<   rf  r   r   r^  re   rk   rl   rn   )r   rj  rQ   rg  s       r(   delete_profileBrowserProfiler.delete_profile  s    , 77==-../L 77<<(9(9;OPL ww}}\** GGNN277<<mDE CGGNN277<<iOPCGGNN277<<jAB 	 	MM,' 		s   E 
E*)E*FrR   rS   c                    [         R                  R                  U5      (       a  UnO*[         R                  R                  U R                  U5      n[         R                  R                  U5      (       d  [        SU 35      e[        XBU5      nU(       a  SOSnU R                  R                  U S[        US   5       S[        US   5       S[        US	   5       S
3SS9  U$ )aY  
Shrink a profile to reduce storage while preserving authentication data.

Args:
    profile_name_or_path: Profile name or full path
    level: LIGHT, MEDIUM, AGGRESSIVE (default), or MINIMAL
    dry_run: If True, only preview what would be removed

Returns:
    Dict with 'removed', 'kept', 'bytes_freed', 'size_before', 'size_after', 'errors'
rY   z
Would freeFreedrN   rW   z (rU   z items removed, rV   z kept)SHRINKr   )r   r<   rf  r   r   r^  rg   rv   rz   r   rP   r   )r   rj  rR   rS   rQ   rr   actions          r(   rH  BrowserProfiler.shrink  s    $ 77==-../L77<<(9(9;OPLww}}\**23G2HIJJW=!(ghaVM%:;< =F9%&''7F6N8K7LFT 	 	
 r'   c                 f  #     U R                   R                  SSS9  U R                   R                  SS[        R                  S9  U R                   R                  SS[        R                  S9  U R                   R                  SS[        R
                  S9  U(       aU  U R                   R                  SS[        R                  S9  U R                   R                  S	S[        R                  S9  S
nO+U R                   R                  SS[        R                  S9  SnU R                   R                  SU S3SS9  [        5       nUS:X  aH  U R                  R                  SSS9  [        5       nU R                  U=(       d    S5      I Sh  vN   GOUS:X  Ga"  U R                  5       nU(       d  U R                   R                  SSS9  GM  U R                   R                  SSS9  [        U5       H  u  pgU R                   R                  SUS-    SUS    3SS9  U R                   R                  SUS    3S[        R                  S9  U R                   R                  SUS   R                  S 5       3SS9  U R                   R                  S!US"    3SS9  U R                   R                  SSS9  M     GOUS#:X  Ga  U R                  5       nU(       d  U R                   R                  S$SS9  GM  U R                   R                  SS[        R                  S9  [        U5       H+  u  pgU R                   R                  SUS-    SUS    3SS9  M-     U R                  R                  S%SS9  [        5       nUR!                  5       S&:X  a  GM   [#        U5      S-
  n	S'U	s=::  a  [%        U5      :  a  O  OXY   S   n
U R                   R                  S(U
 S)3SS9  U R                  R                  S*SS9  [        5       nUR!                  5       S+:X  aZ  U R'                  XY   S   5      nU(       a   U R                   R)                  S,U
 S-3SS9  GOU R                   R+                  S.U
 3SS9  GOU R                   R+                  S/SS9  GOUS:X  Ga{  U(       Gas  U R                  5       nU(       d  U R                   R                  S1SS9  GM  U R                   R                  SS[        R                  S9  [        U5       H+  u  pgU R                   R                  SUS-    SUS    3SS9  M-     U R                  R                  S2SS9  [        5       nUR!                  5       S&:X  a  GMs   [#        U5      S-
  n	S'U	s=::  a  [%        U5      :  aa  O  O^XY   S   nU R                  R                  S3SS9  [        5       nU(       a  U" X5      I Sh  vN   OtU R                   R+                  S4S5S9  OYU R                   R+                  S/SS9  O>X2:X  a  U R                   R                  S6SS9  gU R                   R+                  S7U S83SS9  GMT   GN! [,         a    U R                   R+                  S0SS9   N,f = f N! [,         a    U R                   R+                  S0SS9   NXf = f7f)9aa  
Launch an interactive profile management console.

Args:
    crawl_callback (callable, optional): Function to call when selecting option to use 
        a profile for crawling. It will be called with (profile_path, url).
        
Example:
    ```python
    profiler = BrowserProfiler()
    
    # Define a custom crawl function
    async def my_crawl_function(profile_path, url):
        print(f"Crawling {url} with profile {profile_path}")
        # Implement your crawling logic here
        
    # Start interactive manager
    await profiler.interactive_manager(crawl_callback=my_crawl_function)
    ```
z
Profile Management Options:MENUr   z1. Create a new profiler   z2. List available profilesz3. Delete a profilez#4. Use a profile to crawl a websitez5. Exit5z4. Exit4z
[cyan]Enter your choice (1-z
): [/cyan]r   )end1zZ[green]Enter a name for the new profile (or press Enter for auto-generated name): [/green]N2z4  No profiles found. Create one first with option 1.PROFILESz
Available profiles:[r   z] ra   z
    Path: r<   z    Created: rV  z%Y-%m-%d %H:%M:%Sz    Browser type: rW  3zNo profiles found to deletezI[red]Enter the number of the profile to delete (or 'c' to cancel): [/red]r   r   zDeleting profile: [yellow]z	[/yellow]z@[red]Are you sure you want to delete this profile? (y/n): [/red]yzProfile z deleted successfullyzFailed to delete profile zInvalid profile numberzPlease enter a valid numberz$No profiles found. Create one first.zH[cyan]Enter the number of the profile to use (or 'c' to cancel): [/cyan]z%[cyan]Enter the URL to crawl: [/cyan]zNo URL providedCRAWLzExiting profile managementz4Invalid choice. Please enter a number between 1 and .)rz   r   r   r   r)  REDr*  MAGENTAr   r   printrQ  rc  r   	enumerater6  r   intr   rl  rF  r   rg   )r   crawl_callbackexit_optionchoicera   r}   iro   profile_idxidxr   confirmrF  rQ   urls                  r(   interactive_manager#BrowserProfiler.interactive_manager1  sZ    * KK<&IKK6Fx~~^KK9vRZRaRabKK28<<X   !FF_g_l_l m  8CSCS T!  8CSCS T!KK<[MTZ\]WF}""#  FH"  Iw))$,$7773--/KK''(^dn'o   !8j I"+H"5JAKK$$q1R/@%Az$RKK$$z'&/1B%C`h`o`o$pKK$$}WY5G5P5PQd5e4f%gmw$xKK$$'9'&/9J%KQ[$\KK$$RZ$8 #6 3--/KK''(E:'V   !8jU]UdUd e"+H"5JAKK$$q1R/@%Az$R #6 ""#ntv"w#g$$&#-Uk*Q.CC/#h-/'/}V'<((+El^S\)]cm(n **+msu*v"''"==?c1&*&9&9(-:O&PG& $ 3 3h|nLa4bhr 3 s $ 1 14Ml^2\bl 1 m))*B
)S 3>--/KK''(NT^'_   !8jU]UdUd e"+H"5JAKK$$q1R/@%Az$R #6 ""#msu"v#g$$&#-Uk*Q.CC/#h-/'/}V'<**+RXZ*[#g"0"CCC KK--.?W-M))*B
)S &  !=6 J !!$XYdXeef"gms!tq , 8n " UKK%%&C%TU: D
 " UKK%%&C%TUs   FZ1YHZ1B?Y Z1Y 7Z19Y C#Z17A$Z ZZ  Z1!Z ;Z1<Z AZ1$Z?Z1ZZ1Z $Z.+Z1-Z..Z1r   r:  debugging_portr   save_as_builtinc                   ^ ^^^^^#    U(       a  Un[         R                  " USS9  O[        R                  R                  5       R	                  S5      nSU S[
        R                  " 5       R                  SS  3n[         R                  R                  T R                  U5      n[         R                  " USS9  S n	T R                  R                  S	S
SU	0S[        R                  0S9  T R                  R                  SS
S9  T R                  R                  SS
SU0S[        R                  0S9  T R                  R                  SS
SU0S[        R                  0S9  T R                  R                  SU 3S
S9  T R                  R                  SU 3S
S9  [!        UUUUSS9n
[#        U
UUT R                  US9m[$        R&                  " [$        R(                  5      m[$        R&                  " [$        R*                  5      mUUUU 4S jmU4S jn[$        R$                  " [$        R(                  U5        [$        R$                  " [$        R*                  U5        [,        R.                  " 5       mUU U4S jnU 4S jnSnSn TR1                  5       I Sh  vN   TR2                  nU(       d~  T R                  R5                  SS
S9   [$        R$                  " [$        R(                  T5        [$        R$                  " [$        R*                  T5        TR7                  5       I Sh  vN   gT R                  R                  SS
S9  U" U5      I Sh  vN u  pU(       a  T R                  R9                  SU 3S
S9  U(       a  T R                  R                  SUR;                  SS 5       3S
S[        R                  0S!9  T R                  R                  S"UR;                  S#S 5       3S
S#[        R                  0S!9  S$U;   a1  T R                  R                  S%S
S$US$   0S$[        R<                  0S9  OT R                  R?                  S&S
S9  OT R                  R5                  S'U 3S
S9  TR7                  5       I Sh  vN    [$        R$                  " [$        R(                  T5        [$        R$                  " [$        R*                  T5        TR7                  5       I Sh  vN   g[,        R@                  " U" 5       5      nTRC                  5       (       dW  URE                  5       cF  [,        RF                  " S(5      I Sh  vN   TRC                  5       (       d  URE                  5       c  MF  URI                  5       (       d  URK                  5          UI Sh  vN   URE                  5       cG  TRC                  5       (       a2  T R                  R                  S)S
S9  TR7                  5       I Sh  vN   T R                  R9                  S*S
S9   [$        R$                  " [$        R(                  T5        [$        R$                  " [$        R*                  T5        TR7                  5       I Sh  vN   U$  GN GNV GN. GN  GN GNC N! [,        RL                   a     GNf = f N! [N         a  nT R                  R5                  S+[Q        U5       3S
S9  TR7                  5       I Sh  vN     SnA[$        R$                  " [$        R(                  T5        [$        R$                  " [$        R*                  T5        TR7                  5       I Sh  vN    gSnAff = f N! [$        R$                  " [$        R(                  T5        [$        R$                  " [$        R*                  T5        TR7                  5       I Sh  vN    f = f7f),a  
Launch a standalone browser with CDP debugging enabled and keep it running
until the user presses 'q'. Returns and displays the CDP URL.

Args:
    browser_type (str): Type of browser to launch ('chromium' or 'firefox')
    user_data_dir (str, optional): Path to user profile directory
    debugging_port (int): Port to use for CDP debugging
    headless (bool): Whether to run in headless mode
    
Returns:
    str: CDP URL for the browser, or None if launch failed
    
Example:
    ```python
    profiler = BrowserProfiler()
    cdp_url = await profiler.launch_standalone_browser(
        user_data_dir="/path/to/profile",
        debugging_port=9222
    )
    # Use cdp_url to connect to the browser
    ```
Tr~   r   temp_r   Nr   r   r   r   r   r   z/Launching standalone browser with CDP debuggingr   zBrowser type: {browser_type}r   zProfile path: {profile_path}rQ   zDebugging port: zHeadless mode: )r   r   r:  r  r|   )r   r:  r   rz   r  c                   >#    TR                   R                  SSS9  TR                  5       I S h  vN   [        R                  " [        R                  T5        [        R                  " [        R
                  T5        U [        R                  :X  a1  TR                   R                  SSS9  [        R                  " S5        g g  N7f)Nr  r   r   zBrowser terminated by user.r   r  r	  s     r(   r  BBrowserProfiler.launch_standalone_browser.<locals>.cleanup_handler	  s     KK BN!))+++MM&--9MM&..*:;fmm#!!"?U!K $	 ,r  c                 >   > [         R                  " T" X5      5        g r]   r  r  s     r(   r  ABrowserProfiler.launch_standalone_browser.<locals>.sigint_handler  r  r'   c                    >#    TR                   R                  SSSS0S[        R                  0[        R                  S9  UUU4S jn  TR                  5       (       a  TR                  TU S5      I Sh  vN   gTR                  TU S5      I Sh  vN   g N! N! [         a]  nTR                   R                  SU 3SS	9  TR                   R                  S
SS	9  TR                  TU S5      I Sh  vN     SnAgSnAff = f7f)r  z/Press {segment} to stop the browser and exit...r   r   r  r  c                     >#    T R                   (       aF  T R                   R                  5       b+  TR                  R                  SSS9  TR	                  5         gg7f)r  r  r   r   TFr   r#  s   r(   r   iBrowserProfiler.launch_standalone_browser.<locals>.listen_for_quit_command.<locals>.check_browser_process(  sN     "227V7V7[7[7]7iKK$$%U[`$a#'')r%  Nr&  r   r'  r(  r+  s     r(   r,  JBrowserProfiler.launch_standalone_browser.<locals>.listen_for_quit_command  s      KKA!5)9hoo2N#==	  [##%%..@UW\]]]++O=RTYZZZ ^Z [##&RSTRU$V\a#b  !GU S++O=RTYZZZ[r.  c           	        >#    SS K nSU  3nU S3n UR                  5        IS h  vN n[        S5       H  n UR                  U5       IS h  vN nUR                  S:X  a?  UR                  5       I S h  vN nX'4sS S S 5      IS h  vN   s  sS S S 5      IS h  vN   $ S S S 5      IS h  vN   [        R                  " S5      I S h  vN   M     US 4sS S S 5      IS h  vN   $  N N Nv Ne NT NE! , IS h  vN  (       d  f       NZ= f! [         a     Nif = f NS N=! , IS h  vN  (       d  f       g = f! [         a4  nT	R                  R                  S[        U5       3SS	9  US 4s S nA$ S nAff = f7f)
Nr   http://localhost:/json/version
      r   zError fetching CDP JSON: r   r   )aiohttpClientSessionrangegetstatusjsonrn   r   r   rz   r   str)
portr  rK  json_urlsessionr   responsedataru   r   s
            r(   get_cdp_json?BrowserProfiler.launch_standalone_browser.<locals>.get_cdp_json<  sE    )$0G!-0H%"0022g"2Y!'.{{8'<'<#+??c#919+@D+2= (='<'<	 322 (='< &mmC000 ' #D= 322 (=+@ (=	 3 (='<'<'<  ) ! ! 1 3222  %!!$=c!fX"FE!R}$%sV  F D? C+D? D%DC-
D$C78C/
9C7?DC1
DD%D? C3D? #F $D/C50D4D%D!D%D? %D#&D? *F +D? -D/C71D3D? 5D7D=D >D
DD%D
DD%DD%#D? %D<+D.,D<8D? ;F <D? ?
E=	)E82E=3F 8E==F r0  z<Browser launched successfully. Retrieving CDP information...z	CDP URL: z	Browser: BrowserUnknown)r   r   zProtocol Version: zProtocol-VersionwebSocketDebuggerUrlz%WebSocket URL: {webSocketDebuggerUrl}z)Could not retrieve CDP configuration JSONzFailed to get CDP URL on port r   r1  zBrowser closed.z$Error launching standalone browser: ))r   r   r4  r5  r6  r7  r8  r9  r<   r   r   rz   r   r   r*  r)  r   r   r  r;  r  r  r   r<  r   r!  r   r  rF  r  r   r   r  r   r"  r   r@  rA  rB  rn   r  )r   r   r:  r  r   r  rQ   rJ  r   r   r   r  r,  r  rK  config_jsonr!  rO  ru   r  r  r  r  r   s   `                  @@@@@r(   launch_standalone_browser)BrowserProfiler.launch_standalone_browser  s    < (LKKt4 !))--/88II"9+Qtzz|/?/?/C.DEL77<<(9(9<HLKKt4 8&7IS[]e]j]jRklJPUV7UN\hKi  tB  DL  DQ  DQ  sR  	S7UN\hKi  tB  DL  DS  DS  sT  	U+N+;<%H?8*55A '%&)
 ))&;;)
 !**6==9!++FNN;	 		= 	fmm^4fnnn5 "--/	[<	%0 ?	,!''))) .==O"!!"D%!Pf MM&--9MM&..*:; "))+++k KK[afg *6n)E#E G##iy$9u#EKK$$yI1V0W%X^cmv  yA  yF  yF  mG$  HKK$$'9+//J\^g:h9i%jpu  @R  T\  Ta  Ta  b$  c-<(()PV[e{  ~I  J`  ~a  eb  lB  DL  DR  DR  kS(  TKK''(SY^'_!!$B>BR"SY^!_%--///< MM&--9MM&..*:; "))+++? $//0G0IJM &,,..?3G3G3I3QmmC((( &,,..?3G3G3I3Q !%%''$$&'''
 ##%-/2H2H2J2J  !Au M%--///KK 1u= MM&--9MM&..*:; "))+++ A *z ,e $F 0F ,7 ) (--  0  	KK DSVHMSXY!))+++ MM&--9MM&..*:; "))+++	 ,	 MM&--9MM&..*:; "))+++sL  J_
Z1 Z 1Z1 A_-Z._3%Z1 ZD0Z1 	Z	
Z1 A_,Z-_2AZ1 Z*Z1 9%Z1 Z $Z%Z )AZ1 <Z/=Z1 A_9]*:_ Z1 _Z1 	Z1 _Z1 Z Z,(Z1 +Z,,Z1 1
]';9]"4[75]":], >A_]_"]''], *_,A_
___c           	        #    U R                  5       nU(       aP  U R                  UR                  S5      5      (       a+  U R                  R	                  SSS9  UR                  S5      $ [
        R                  R                  U R                  S5      n[
        R                  " USS9  [        UUUU R                  US	9n UR                  5       I S
h  vN   UR                  nU(       d  U R                  R                  SSS9  g
SU 3nSS
Kn	U S3n
S
n U	R                  5        IS
h  vN n[!        S5       H  n UR                  U
5       IS
h  vN nUR"                  S:X  a+  UR%                  5       I S
h  vN n S
S
S
5      IS
h  vN     O2S
S
S
5      IS
h  vN   [(        R*                  " S5      I S
h  vN   M     S
S
S
5      IS
h  vN   UR0                  UUUU[2        R2                  " 5       US.n[5        U R6                  S5       n[$        R8                  " UUSS9  S
S
S
5        S
Ul        U R                  R;                  SU 3SS9  U$  GN GN0 GN
 N N N! , IS
h  vN  (       d  f       N= f! [&         a     Nf = f N N! , IS
h  vN  (       d  f       N= f! [&         a1  nU R                  R-                  S[/        U5       3SS9   S
nAGNS
nAff = f! , (       d  f       N= f! [&         aP  nU R                  R                  S[/        U5       3SS9  U(       a  UR=                  5       I S
h  vN     S
nAg
S
nAff = f7f)aM  
Launch a browser in the background for use as the builtin browser.

Args:
    browser_type (str): Type of browser to launch ('chromium' or 'firefox')
    debugging_port (int): Port to use for CDP debugging
    headless (bool): Whether to run in headless mode
    
Returns:
    str: CDP URL for the browser, or None if launch failed
pidz"Builtin browser is already runningBUILTINr   rK  	user_dataTr~   )r   r:  r   rz   r  Nr0  r  r   r  r  r  r   zCould not verify browser: )r  rK  r:  r   r  
start_timeconfigw   )indentz%Builtin browser launched at CDP URL: z!Error launching builtin browser: )get_builtin_browser_info_is_browser_runningr  rz   r   r   r<   r   r   r   r   r   r!  r   r  r  r  r  r  rn   r   r   r   r  r  timeopenr   dumprF  r  )r   r   r  r   browser_infor:  r  r!  rK  r  r  r  r  r   r  ru   rF   s                    r(   launch_builtin_browser&BrowserProfiler.launch_builtin_browser  s      446D44\5E5Ee5LMMKKAyQ##I.. T%=%={K
MD1 )%';;)
:	!''))) .==O"!!"D)!T *.)9:G !-0HKZ"0022g"2Y!'.{{8'<'<#+??c#98@2GK$) (='<'<'<'< &mmC000 ' 32 '**"!. ,"0"iik%L d..4		,!4 5 /3O+KK"Gy QW`aNe *" 3 (=2G (='<'<'<  ) ! !0 3222  Z##&@Q$Iy#YZ 54  	KK A#a&JPYZ%--///		s  B>MK? I1K? MK? J0 ,I-J0 0J JI
J$I(=I"
>I(JI$JJJ I&!J%J>J?JJ0 JJ0 =K? K.+-K? MK? J0 J"I($J&J(I?.I1/I?;J>J?J
JJJJJ0 J-JJ-)J0 ,K? -J0 0
K+:&K& K? &K++K? .
K<8K? ?
M	A M	M
MMMMc                    [         R                  R                  U R                  5      (       d  g [	        U R                  S5       n[
        R                  " U5      nSSS5        U R                  WR                  S5      5      (       d  U R                  R                  SSS9  gU$ ! , (       d  f       NP= f! [         a0  nU R                  R                  S[        U5       3SS9   SnAgSnAff = f)z
Get information about the builtin browser.

Returns:
    dict: Browser information or None if no builtin browser is configured
Nrr  zBuiltin browser is not runningr  r   z&Error reading builtin browser config: )r   r<   re   r   r  r  loadr  r  rz   r   rn   r   r  )r   rF   r  ru   s       r(   r  (BrowserProfiler.get_builtin_browser_info  s     ww~~d6677	d..4#yy| 5 ++L,<,<U,CDD##$D)#T 54  	KK Fs1vhOU^_	s6   B9 B(AB9 &B9 (
B62B9 9
C3&C..C3r  c                 
   U(       d  g [         R                  S:X  a4  [        R                  " SSSU 3/SSS9n[	        U5      UR
                  ;   $ [        R                  " US5        g! [        [        [        4 a     gf = f)	z0Check if a process with the given PID is runningFwin32tasklistz/FIzPID eq T)capture_outputtextr   )r   r   
subprocessrunr  stdoutr   killProcessLookupErrorrC   rD   )r   r  processs      r(   r  #BrowserProfiler._is_browser_running  sz    	||w&$..*ewse_)M8<4I3x7>>11 Q"OW= 		s   AA* A* *BBc                   #    U R                  5       nU(       d  U R                  R                  SSS9  gUR                  S5      nU(       d  g [        R
                  S:X  a#  [        R                  " SSS	[        U5      /S
S9  O[        R                  " U[        R                  5        [        S5       H9  nU R                  U5      (       d    OG[        R                   " S5      I Sh  vN   M;     [        R                  " U[        R"                  5        [        R$                  R'                  U R(                  5      (       a   [        R*                  " U R(                  5        U R                  R-                  SSS9  g
 N! [.         a0  nU R                  R1                  S[        U5       3SS9   SnAgSnAff = f7f)zo
Kill the builtin browser if it's running.

Returns:
    bool: True if the browser was killed, False otherwise
zNo builtin browser foundr  r   Fr  r  taskkillz/Fz/PIDT)check   r   NzBuiltin browser terminatedzError killing builtin browser: )r  rz   r   r  r   r   r  r  r  r   r  r  r  r  r  r   r   SIGKILLr<   re   r   rm   rF  rn   r   )r   r  r  r   ru   s        r(   kill_builtin_browser$BrowserProfiler.kill_builtin_browser#  sS     446KK :	Ju%	||w&
D&#c(C4PV^^,qA33C88!--,,, " GGC0 ww~~d6677		$223KK <)L -  	KK ?AxHiX	sD   AG BF *F+BF  G F 
F=&F83G 8F==G c                 n   #    U R                  5       nU(       d  SSSS.$ SUR                  S5      US.$ 7f)z
Get status information about the builtin browser.

Returns:
    dict: Status information with running, cdp_url, and info fields
FN)runningrK  r   TrK  )r  r  )r   r  s     r(   get_builtin_browser_status*BrowserProfiler.get_builtin_browser_statusK  sK      446   #''	2 
 	
s   35)r   r   r   rz   r   r]   )r   N$  FF)r   r  T)(r   r   r   r   r    r   r   r   boolr   r   r   r  r   r   r   r<  r   r   r   r!   r   rQ  r   r   r   rc  rh  rl  r$   rH  r  r  r  r  r  r  r  r  r&   r   r'   r(   rx   rx      sh   
=x8 =8JT J(4 (04 0(S (S (6QT 6pD\'-- D\]` D\L:"gmm :"ad :"| '+26$/$4$4	psmp !/p "	p
 
#pd=tDcN3 =~)S )Xc] )V03 04 0j )33	#!# # 	#
 
c3h#JMu` 7AAE8<38:?Y03Y19#Y 36Y -1	Y
 48Y
 EMSMYx 6@7;26\/2\14\ ,0\ <DC=\|(4S>*B 0x}  $&D &P
$sCx. 
r'   rx   __main__z.crawl4ai/profiles/test-profilez	Profile: ra   z, Path: z
my-profilezProfile deleted successfullyzFailed to delete profile)>r    r   r   r  r   r4  r7  rk   r  r  r  enumr   pathlibr   typingr   r   r   r   r	   rich.consoler
   r2  r   browser_managerr   async_loggerr   r   r   utilsr   r  r   r!   r"   r#   r$   r%   r;   __annotations__r  rG   rP   r  rv   rx   r   profilerhomehome_dirr  rQ  rQ   r  rc  r}   ro   r  rl  rF  r   r'   r(   <module>r     s   
   
         1 1   ( + @ @ "#t  se   
 uV.tKS)* $D S C C  %//000 0 
#s(^	0fY
 Y
x& z H yy{H;;x66HGh<h8ijkL
 KK2245 %%'H	'&/*(76?2CDE  %%l3G,-()3 r'   