Ë
    H~éj©H  ã                  ó^  — U d Z ddlmZ ddlZddlZddlZddlZddlmZ dZ	ddddddœZ
d	ed
<   dgZded<   ddgZd<d„ZdddœZdddddddœZded<    ee
j%                  «       «      Zded<    ej(                  d«      Zd=d>d „Zd=d?d!„Zd@d"„Zd@d#„ZdAd$„ZdBdCd%„ZdBdCd&„ZdDd'„Z	 dE	 	 	 	 	 dFd(„ZdGd)„ZdHd*„Z ejB                  jE                  d+d,«      Z#d-Z$d.Z%d@d/„Z&d=dId0„Z'd=dJd1„Z(d=dJd2„Z)dKd3„Z*d4Z+ded5<   	 	 	 dL	 	 	 	 	 	 	 dMd6„Z,ddd7d7d7d8œZ-d	ed9<   	 	 	 dL	 	 	 	 	 	 	 dMd:„Z.	 	 	 dL	 	 	 	 	 	 	 dMd;„Z/y)Nz>Stealth configuration and platform detection for cloakbrowser.é    )ÚannotationsN)ÚPathz146.0.7680.177.5z146.0.7680.177.3z145.0.7632.109.2)ú	linux-x64úlinux-arm64údarwin-arm64ú
darwin-x64úwindows-x64zdict[str, str]ÚPLATFORM_CHROMIUM_VERSIONSz,MKFKwIhUcKWq5xTuNA0Ovg99njcDEcEJvmWYYhApvaU=ú	list[str]ÚBINARY_SIGNING_PUBKEYSz--enable-automationz--enable-unsafe-swiftshaderc                 ó†   — t        j                  dd«      } t        j                  «       }dd| › �g}|dk(  r|dgz   S |dgz   S )uÝ   Build stealth args with a random fingerprint seed per launch.

    On macOS, skips platform/GPU spoofing â€” runs as a native Mac browser.
    Spoofing Windows on Mac creates detectable mismatches (fonts, GPU, etc.).
    i'  iŸ† z--no-sandboxz--fingerprint=ÚDarwinz--fingerprint-platform=macosz--fingerprint-platform=windows)ÚrandomÚrandintÚplatformÚsystem)Úseedr   Úbases      úJ/home/boxd/.venv-cloak/lib/python3.12/site-packages/cloakbrowser/config.pyÚget_default_stealth_argsr   6   s`   € ô �>‰>˜% Ó'€DÜ�_‰_Ó€Fð 	Ø
˜˜Ðð€Dð
 �ÒàÐ5Ð6Ñ6Ð6ð Ð3Ð4Ñ4Ð4ó    i€  i³  )ÚwidthÚheightr   r   r   r   r	   ))ÚLinuxÚx86_64)r   Úaarch64)r   Úarm64)r   r   )ÚWindowsÚAMD64)r   r   zdict[tuple[str, str], str]ÚSUPPORTED_PLATFORMSzset[str]ÚAVAILABLE_PLATFORMSz^[0-9]+(?:\.[0-9]+){3,4}$ú
str | Nonec                ó”   — | �| nt         j                  j                  dd«      }|j                  «       j	                  «       dk(  rdS dS )z;Return the requested release channel, defaulting to Stable.ÚCLOAKBROWSER_RELEASE_CHANNELÚstableÚpreview)ÚosÚenvironÚgetÚstripÚlower)Úrelease_channelÚraws     r   Únormalize_release_channelr.   k   sJ   € ð Ð&ñ 	ä�Z‰Z�^‰^Ð:¸HÓEð ð
 Ÿ	™	›×)Ñ)Ó+¨yÒ8ˆ9ÐF¸hÐFr   c                ó¸   — | �| nt         j                  j                  d«      }|€y|j                  «       }|syt        j                  |«      st        d«      ‚|S )zöReturn an explicit Chromium version pin from arg/env, or None.

    The explicit argument wins over CLOAKBROWSER_VERSION. Only numeric dotted
    versions are accepted because the value is interpolated into cache paths and
    download URLs.
    NÚCLOAKBROWSER_VERSIONzZInvalid browser version pin. Use a full numeric Chromium version, e.g. '148.0.7778.215.2'.)r'   r(   r)   r*   Ú_VERSION_PIN_REÚ	fullmatchÚ
ValueError)Úversionr-   Ú
normalizeds      r   Únormalize_requested_versionr6   u   s_   € ð Ð(‰'¬b¯j©j¯n©nÐ=SÓ.T€CØ
€{ØØ—‘“€JÙØÜ×$Ñ$ ZÔ0Üð'ó
ð 	
ð Ðr   c                 óJ   — t        «       } t        j                  | t        «      S )z5Return the Chromium version for the current platform.)Úget_platform_tagr
   r)   ÚCHROMIUM_VERSION)Útags    r   Úget_chromium_versionr;   Š   s   € ä
Ó
€CÜ%×)Ñ)¨#Ô/?Ó@Ð@r   c                 óä   — t        j                  «       } t        j                  «       }t        j	                  | |f«      }|€.t        d| › d|› ddj                  d„ t        D «       «      › �«      ‚|S )zOReturn the platform tag for binary download (e.g. 'linux-x64', 'darwin-arm64').zUnsupported platform: ú z. Supported: ú, c              3  ó0   K  — | ]  \  }}|› d |› �–— Œ y­w)ú-N© )Ú.0ÚsÚms      r   ú	<genexpr>z#get_platform_tag.<locals>.<genexpr>˜   s   è ø€ Ò#Q±6°A°q q c¨¨1¨#¤JÑ#Qùs   ‚)r   r   Úmachiner    r)   ÚRuntimeErrorÚjoin)r   rF   r:   s      r   r8   r8   �   sx   € ä�_‰_Ó€FÜ×ÑÓ €GÜ
×
!Ñ
! 6¨7Ð"3Ó
4€CØ
€{ÜØ$ V H¨A¨g¨Yð 7ØŸ)™)Ñ#QÔ=PÔ#QÓQÐRðTó
ð 	
ð €Jr   c                 óˆ   — t         j                  j                  d«      } | rt        | «      S t        j                  «       dz  S )z‰Return the cache directory for downloaded binaries.

    Override with CLOAKBROWSER_CACHE_DIR env var.
    Default: ~/.cloakbrowser/
    ÚCLOAKBROWSER_CACHE_DIRz.cloakbrowser)r'   r(   r)   r   Úhome)Úcustoms    r   Úget_cache_dirrM       s5   € ô �Z‰Z�^‰^Ð4Ó5€FÙÜ�F‹|ÐÜ�9‰9‹;˜Ñ(Ð(r   c                óN   — | xs
 t        «       }|rdnd}t        «       d|› |› �z  S )z3Return the directory for a Chromium version binary.z-proÚ z	chromium-)r;   rM   )r4   ÚproÚvÚsuffixs       r   Úget_binary_dirrS   ¬   s1   € àÒ)Ô'Ó)€AÙ‰V €FÜ‹?˜y¨¨¨F¨8Ð4Ñ4Ð4r   c                ó¨   — t        | |¬«      }t        j                  «       dk(  r|dz  dz  dz  dz  S t        j                  «       dk(  r|dz  S |d	z  S )
z2Return the expected path to the chrome executable.©rP   r   zChromium.appÚContentsÚMacOSÚChromiumr   z
chrome.exeÚchrome)rS   r   r   )r4   rP   Ú
binary_dirs      r   Úget_binary_pathr[   ³   s^   € ä ¨SÔ1€Jä‡�Ó˜HÒ$à˜NÑ*¨ZÑ7¸'ÑAÀJÑNÐNÜ	�‰Ó	˜iÒ	'Ø˜LÑ(Ð(ð ˜HÑ$Ð$r   c                 ó®   — t        «       ryt        «       } | t        vr8dj                  t	        t        «      «      }ddl}|j                  d|› d�«       yy)z—Raise a clear error if no pre-built binary exists for this platform.

    Skipped when CLOAKBROWSER_BINARY_PATH is set (user has their own build).
    Nr>   r   uO   
[1mCloakBrowser[0m â€” Pre-built binaries are currently only available for: zT.

To use CloakBrowser now, set CLOAKBROWSER_BINARY_PATH to a local Chromium binary.)Úget_local_binary_overrider8   r!   rH   ÚsortedÚsysÚexit)r:   Ú	availabler_   s      r   Úcheck_platform_availablerb   Á   s\   € ô
 !Ô"Øä
Ó
€CØ
Ô%Ñ%Ø—I‘IœfÔ%8Ó9Ó:ˆ	Ûà�‰ØdÐenÐdoð p`ð aõ	
ð	 &r   c                óª  — t        «       }t        «       }| rœt        |«      }|dk(  rdnd}||› dt        «       › �z  }|j	                  «       re	 |j                  «       j                  «       }|rCt        |d¬«      }|j	                  «       r&t        j                  |t        j                  «      r|S yydt        «       › �d	fD ]d  }	||	z  }|j	                  «       sŒ	 |j                  «       j                  «       }|r+t        ||«      rt        |«      }|j	                  «       r|c S Œf |S # t        t        f$ r Y yw xY w# t        t        f$ r Y Œ�w xY w)
u9  Return the best available version: auto-updated if available, else platform default.

    Reads a platform-scoped marker file from the cache directory.
    Returns the platform's hardcoded version if no update has been downloaded.

    When ``pro=True``, reads from the Pro-specific marker and returns ``None`` when
    no cached Pro binary matches it. A valid Pro license must NEVER fall back to the
    free binary, so there is deliberately no free-version fallback here â€” callers
    treat ``None`` as "resolve the latest Pro version from the server" instead.
    r&   Úlatest_pro_version_previewÚlatest_pro_versionÚ_TrU   NÚlatest_version_Úlatest_version)r;   rM   r.   r8   ÚexistsÚ	read_textr*   r[   r'   ÚaccessÚX_OKr3   ÚOSErrorÚ_version_newer)
rP   r,   r   ÚcacheÚchannelÚmarker_prefixÚmarkerr4   ÚbinaryÚnames
             r   Úget_effective_versionru   Ô   s^  € ô  Ó!€DÜ‹O€Eá
Ü+¨OÓ<ˆð ˜)Ò#ñ )à%ð 	ð
 ˜M˜?¨!Ô,<Ó,>Ð+?Ð@Ñ@ˆØ�=‰=Œ?ð	Ø ×*Ñ*Ó,×2Ñ2Ó4�ÙÜ,¨W¸$Ô?�Fð —}‘}”¬2¯9©9°V¼R¿W¹WÔ+EØ&˜ñ ð #Ô#3Ó#5Ð"6Ð7Ð9IÐJò 
ˆØ˜‘ˆØ�=‰=�?ðØ ×*Ñ*Ó,×2Ñ2Ó4�Ùœ~¨g°tÔ<Ü,¨WÓ5�FØ—}‘}”Ø&šøð
ð €Køô! ¤Ð(ò ØØðûô ¤Ð(ò Ùðús&   ÁA"D+ ÃAE Ä+D=Ä<D=Å EÅEc                óD   — t        d„ | j                  d«      D «       «      S )z;Parse '145.0.7718.0' into (145, 0, 7718, 0) for comparison.c              3  ó2   K  — | ]  }t        |«      –— Œ y ­w©N)Úint)rB   Úxs     r   rE   z!_version_tuple.<locals>.<genexpr>
  s   è ø€ Ò.˜A”�Q—Ñ.ùs   ‚ú.)ÚtupleÚsplit)rQ   s    r   Ú_version_tupler~     s   € äÑ. §¡¨£Ô.Ó.Ð.r   c                ó0   — t        | «      t        |«      kD  S )z:Return True if version a is strictly newer than version b.)r~   )ÚaÚbs     r   rn   rn     s   € ä˜!Óœ~¨aÓ0Ñ0Ð0r   ÚCLOAKBROWSER_DOWNLOAD_URLzhttps://cloakbrowser.devz:https://api.github.com/repos/CloakHQ/cloakbrowser/releasesz9https://github.com/CloakHQ/cloakbrowser/releases/downloadc                 ó8   — t        j                  «       dk(  rdS dS )z\Return the archive extension for the current platform (.zip for Windows, .tar.gz otherwise).r   z.zipz.tar.gz)r   r   rA   r   r   Úget_archive_extr„     s   € ä—_‘_Ó&¨)Ò3ˆ6ÐB¸ÐBr   c                ó<   — | xs
 t        «       }d|› t        «       › �S )zVReturn the archive filename for a platform tag (e.g. 'cloakbrowser-linux-x64.tar.gz').zcloakbrowser-)r8   r„   )r:   Úts     r   Úget_archive_namer‡   $  s%   € àÒ!ÔÓ!€AØ˜1˜#œoÓ/Ð0Ð1Ð1r   c                óJ   — | xs
 t        «       }t        › d|› dt        «       › �S )zGReturn the full download URL for the current platform's binary archive.ú/chromium-vú/)r;   ÚDOWNLOAD_BASE_URLr‡   ©r4   rQ   s     r   Úget_download_urlr�   *  s-   € àÒ)Ô'Ó)€AÜÐ  ¨A¨3¨aÔ0@Ó0BÐ/CÐDÐDr   c                óJ   — | xs
 t        «       }t        › d|› dt        «       › �S )z?Return the GitHub Releases fallback URL for the binary archive.r‰   rŠ   )r;   ÚGITHUB_DOWNLOAD_BASE_URLr‡   rŒ   s     r   Úget_fallback_download_urlr�   0  s-   € àÒ)Ô'Ó)€AÜ&Ð' {°1°#°QÔ7GÓ7IÐ6JÐKÐKr   c                 ó@   — t         j                  j                  d«      S )z•Check if user has set a local binary path via env var.

    Set CLOAKBROWSER_BINARY_PATH to use a locally built Chromium instead of downloading.
    ÚCLOAKBROWSER_BINARY_PATH)r'   r(   r)   rA   r   r   r]   r]   9  s   € ô
 �:‰:�>‰>Ð4Ó5Ð5r   z148.0.7778.215.4Ú HEADLESS_NO_VIEWPORT_MIN_VERSIONc                ó  — t         €y	 t        |«      }|r|}n/t        «       ryddlm} t         || «      «      }t        ||¬«      }|€y	 t        t         |«       S # t        $ r d}Y ŒVw xY w# t        t        f$ r Y yw xY w)a-  Whether headless can launch with ``no_viewport`` on the resolved binary.

    Only binaries at or above ``HEADLESS_NO_VIEWPORT_MIN_VERSION`` qualify; older
    ones keep ``DEFAULT_VIEWPORT``. A local override binary
    (``CLOAKBROWSER_BINARY_PATH``) is unknown-version, so stay on the safe path.
    NFé   ©Úresolve_license_key©rP   r,   )
r“   r6   r3   r]   Úlicenser—   Úboolru   rn   ÚAttributeError)Úlicense_keyÚbrowser_versionr,   Údeclaredr4   r—   rP   s          r   Ú$binary_supports_headless_no_viewportrŸ   L  sš   € ô (Ð/ØðÜ.¨Ó?ˆñ Ø‰Ü	"Ô	$Øå0äÑ& {Ó3Ó4ˆÜ'¨CÀÔQˆØ€ØðÜ!Ô"BÀGÓLÐLÐLøô ò ØŠðûô œÐ'ò Ùðús#   ‰A ÁA. ÁA+Á*A+Á.B Á?B z148.0.7778.215.3)r   r	   r   r   r   Ú"HTTP_PROXY_INLINE_AUTH_MIN_VERSIONc                ó0  — t         j                  t        «       «      }|€y	 t        |«      }|r|}n/t        «       ryddlm} t         || «      «      }t        ||¬«      }|€y	 t        ||«       S # t        $ r d}Y ŒRw xY w# t        t        f$ r Y yw xY w)u­  Whether the resolved binary accepts inline HTTP proxy credentials.

    The capability is a function of the binary version; ``license_key`` only
    resolves *which* version launches (Pro build vs free default), exactly like
    ``binary_supports_headless_no_viewport``. A declared pin wins, else a valid
    Pro license resolves to the Pro build (which ships the patch), else the free
    per-platform default â€” then it compares to this platform's floor. Below the
    floor, credentialed HTTP proxies fall back to Playwright's proxy dict. A
    local override with no declared version is unknown-version, so stay on the
    safe fallback. Python, JS and .NET mirror this gate.
    NFr•   r–   r˜   T)r    r)   r8   r6   r3   r]   r™   r—   rš   ru   rn   r›   )rœ   r�   r,   Úfloorrž   r4   r—   rP   s           r   Ú&binary_supports_http_proxy_inline_authr£   ‰  s®   € ô  /×2Ñ2Ô3CÓ3EÓF€EØ€}ØðÜ.¨Ó?ˆñ Ø‰Ü	"Ô	$Øå0äÑ& {Ó3Ó4ˆÜ'¨CÀÔQˆØ€ð ðÜ! %¨Ó1Ð1Ð1øô! ò ØŠðûô" œÐ'ò Ùðús#   ¢A2 Á%B Á2B Á?B ÂBÂBc                ó   — t        | ||«      S )u:  Whether the wrapper may auto-add ``--start-maximized``.

    Gated on the same threshold as the no_viewport shim: only binaries whose
    headless surface-fix + headed screen-clamp make a maximized window coherent
    (``outer == screen``). Below it, maximizing headless while the CDP viewport
    stays at 1280x720 yields ``outerWidth < innerWidth`` â€” an impossible-window
    bot tell â€” so the flag must NOT be added. Shares
    ``HEADLESS_NO_VIEWPORT_MIN_VERSION``; kept as its own name so the two can
    diverge later. Python, JS and .NET mirror this gate.
    )rŸ   )rœ   r�   r,   s      r   Ú binary_supports_maximized_windowr¥   ³  s   € ô 0Ø�_ oóð r   )Úreturnr   rx   )r,   r"   r¦   Ústr)r4   r"   r¦   r"   )r¦   r§   )r¦   r   )NF)r4   r"   rP   rš   r¦   r   )r¦   ÚNone)FN)rP   rš   r,   r"   r¦   r"   )rQ   r§   r¦   ztuple[int, ...])r€   r§   r�   r§   r¦   rš   )r:   r"   r¦   r§   )r4   r"   r¦   r§   )r¦   r"   )NNN)rœ   r"   r�   r"   r,   r"   r¦   rš   )0Ú__doc__Ú
__future__r   r'   r   r   ÚreÚpathlibr   r9   r
   Ú__annotations__r   ÚIGNORE_DEFAULT_ARGSr   ÚDEFAULT_VIEWPORTr    ÚsetÚkeysr!   Úcompiler1   r.   r6   r;   r8   rM   rS   r[   rb   ru   r~   rn   r(   r)   r‹   ÚGITHUB_API_URLr�   r„   r‡   r�   r�   r]   r“   rŸ   r    r£   r¥   rA   r   r   ú<module>r´      s2  ðÚ Då "ã 	Û Û Û 	Ý ð &Ð ð $Ø%Ø&Ø$Ø%ñ.Ð ˜Nó ð$ 3ð%Ð ˜	ó ð -Ð.KÐLÐ ó5ð@ "¨SÑ1Ð ð %Ø'Ø'Ø&Ø'Ø(ñ3Ð Ð/ó ñ !$Ð$>×$CÑ$CÓ$EÓ FÐ �XÓ Fð �"—*‘*Ð9Ó:€ôGôó*Aó
ó 	)ô5ô%ó
ð( 6:ð1Ø	ð1Ø(2ð1àó1óh/ó
1ð —J‘J—N‘NØØóÐ ð
 N€àVÐ óCô
2ôEôLó6ð  0BÐ   *Ó Að #Ø"&Ø"&ð"Øð"àð"ð  ð"ð 
ó	"ðj $Ø%Ø%Ø&Ø$ñ6Ð " Nó ð #Ø"&Ø"&ð'Øð'àð'ð  ð'ð 
ó	'ðV #Ø"&Ø"&ðØðàðð  ðð 
ô	r   