+
    lHàj•Y  ã                  óh  a € 0 t $ R t^ RIHt ^ RIt^ RIt^ RIt^ RIHtH	t	H
t
 ^ RIHtHt ^ RIHt ]P                   ! ]4      tRt0 RQmtRRRR	RRR
RSRRTRRU/tR]R&   RRVRRVRRRRRW/tR]R&   RRXRRXR^ /R R llt ^ RIt^ RIHt RtR tR R lt R R  lt!R! R" lt"R# R$ lt#R]#R%3R&R' R(3/t$R) R* lt%R+ R, lt&R- R. lt'RYR/ R0 llt(R1R2R3R4] R52R6R7R8R9R:R7R;R3R</R=R7R8R9/ R>RR3R?/R@R7R;R3RA/RBR7R;R3RC/RDR7RERF^R3RG//RHR:.//t)RI]RJ&   RK RL lt*]PV                  ! R2RM])RN ]*RORP7       R#   ] d
    Rt]tRt L¬i ; i)ZuŽ  Raw Chrome DevTools Protocol (CDP) passthrough tool ``browser_cdp``.

Sends arbitrary CDP commands to the browser's DevTools WebSocket when a CDP URL is
configured (``/browser connect`` â†’ ``BROWSER_CDP_URL``, ``browser.cdp_url``, or a
CDP-backed cloud session). Escape hatch for operations the main browser tools don't
cover. Method reference: https://chromedevtools.github.io/devtools-protocol/
)ÚannotationsN)ÚAnyÚDictÚOptional)ÚregistryÚ
tool_error)Úrouted_browser_handlerz3https://chromedevtools.github.io/devtools-protocol/úPage.navigatezPage.captureScreenshotzPage.printToPDFzNetwork.streamResourceContentzHeadlessExperimental.beginFramez"CacheStorage.requestCachedResponsezdict[str, tuple]Ú_CDP_ALWAYS_BINARY_PATHSzNetwork.getResponseBodyzFetch.getResponseBodyzIO.readzNetwork.getRequestPostDataÚ_CDP_FLAGGED_BINARY_PATHSÚalways_pathsÚflagged_pathsÚ_depthc          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )	é   Úvaluer   r   Útupler   r   ÚintÚreturn© )Úformats   "Ú;/home/ubuntu/.hermes/hermes-agent/tools/browser_cdp_tool.pyÚ__annotate__r   0   s<   € ÷ 1ñ 1Øð1ð ð1ð ð	1ð
 ð1ð 	ñ1ó    c          	     ó�  a€ ^ RI HpHpHp SV8¼  d   V# \	        V \
        4      '       d   V! V RR7      # \	        V \        \        34      '       d   \        V 4      ! V3R lV  4       4      # \	        V \        4      '       g   V # V P                  R4      RJ pR R lpR R	 lp	/ p
V P                  4        F�  w  r¼V! W4      ;'       g    V! W+4      ;'       d    Tp\	        V\
        4      '       d   V! VRR7      MTp\	        V\
        4      '       d   V'       d   TM!\        VV	! W4      V	! W+4      S^,           R
7      W®&   K�  	  V
# )u  Redact browser-originated CDP result text; opaque bytes stay byte-identical.

Exemptions come ONLY from the calling method's spec as exact result paths. Path
suffixes propagate only into the matching subtree, so ``base64Encoded`` is honored
solely as a sibling on the trusted carrier object â€” never as ambient trust a
``Runtime.evaluate`` by-value object could spoof.

``_depth`` stops a page-controlled tree from raising RecursionError. The
unread remainder is replaced, not returned raw.

See #94138, #94142.
)ÚREDACT_WALK_DEPTH_MARKERÚREDACT_WALK_MAX_DEPTHÚredact_sensitive_textT)Úforcec              3  óL   <"  € T F  p\        VS^,           R7      x € K  	  R# 5i)é   )r   N)Ú_redact_cdp_output)Ú.0Úitemr   s   & €r   Ú	<genexpr>Ú%_redact_cdp_output.<locals>.<genexpr>M   s#   øé € ð 
ÙDI¸DÔ˜t¨F°Q­J×7Ñ7ÃEùs   ƒ!$Úbase64Encodedc               ó$   € V ^8„  d   QhRRRRRR/# )r   Úpathsr   ÚkeyÚstrr   Úboolr   )r   s   "r   r   Ú(_redact_cdp_output.<locals>.__annotate__S   s!   € ÷ ?ñ ?�Eð ? ð ?¨ñ ?r   c                óx   a€ \         ;QJ d    V3R  lV  4       F  '       g   K   R# 	  R# ! V3R  lV  4       4      # )c              3  óh   <"  € T F'  p\        V4      ^8H  ;'       d    V^ ,          S8H  x € K)  	  R# 5i)r    N©Úlen©r"   Úpr)   s   & €r   r$   Ú3_redact_cdp_output.<locals>.leaf.<locals>.<genexpr>T   s,   øé € Ð>¹°1”3�q“6˜Q‘;×.Ð. 1 Q¥4¨3¡;Ô.»ùs   ƒ2�2TF)Úany©r(   r)   s   &fr   ÚleafÚ _redact_cdp_output.<locals>.leafS   s,   ø€ ß‹sÔ>¹Ó>�sŒsÐ>ŠsÐ>ˆsÔ>¹Ó>Ó>Ð>r   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r(   r   r)   r*   r   r   )r   s   "r   r   r,   U   s&   € ÷ Iñ I�uð I 3ð I¨5ñ Ir   c                óh   a€ \         ;QJ d    . V3R  lV  4       F  NK  	  5# ! V3R  lV  4       4      # )c              3  óz   <"  € T F0  p\        V4      ^8”  g   K  V^ ,          S8X  g   K%  VR,          x € K2  	  R# 5i)r    :r    NNNr/   r1   s   & €r   r$   Ú6_redact_cdp_output.<locals>.descend.<locals>.<genexpr>V   s/   øé € ÐH¡E˜q¬S°«V°a©Z”U¸A¸a½DÀC¹K”U�Q�r—U’U£Eùs   ƒ;š;ª;)r   r5   s   &fr   ÚdescendÚ#_redact_cdp_output.<locals>.descendU   s%   ø€ ßŒuÔH¡EÓH�uÐHˆuÔH¡EÓHÓHÐHr   )r   r   r   )Úagent.redactr   r   r   Ú
isinstancer*   Úlistr   ÚtypeÚdictÚgetÚitemsr!   )r   r   r   r   r   r   r   Úbase64_flaggedr6   r<   Úredactedr)   r#   ÚopaqueÚout_keys   &$$d           r   r!   r!   0   s+  ø€ ÷&ñ ð
 Ð&Ô&Ø'Ð'Ü�%œ×ÒÙ$ U°$Ô7Ð7Ü�%œ$¤˜×'Ò'Ü�EŒ{ô 
ÙDIó
ó 
ð 	
ô �eœT×"Ò"ØˆØ—Y‘Y˜Ó/°4Ð7€Nõ?õIà!€HØ—[‘[–]‰	ˆÙ�lÓ(×YÐY©T°-Ó-E×-XÐ-XÈ.ˆÜ<FÀsÌC×<PÒ<PÑ'¨°4Õ8ÐVYˆÜ$.¨t´S×$9Ò$9¿f™DÔJ\ØÙ  Ó3Ù! -Ó5Ø˜A•:ô	K
ˆÓñ #ð €Or   )ÚWebSocketExceptionTFc                óÞ  €  \         P                  ! 4       pV'       d•   VP                  4       '       d   ^ RIp^ RIpVP                  P                  ^R7      ;_uu_ 4       pVP                  VP                  4       P                  \         P                  V 4      P                  4       uuRRR4       # \         P                  ! V 4      #   \         d    Rp LÁi ; i  + '       g   i     L9; i)zJRun an async coroutine from a sync handler, safe inside or outside a loop.N)Úmax_workers)ÚasyncioÚget_running_loopÚRuntimeErrorÚ
is_runningÚconcurrent.futuresÚcontextvarsÚfuturesÚThreadPoolExecutorÚsubmitÚcopy_contextÚrunÚresult)ÚcoroÚloopÚ
concurrentrQ   Úpools   &    r   Ú
_run_asyncr\   p   s¬   € ðÜ×'Ò'Ó)ˆ÷ �—‘×!Ò!Û!ÛØ×Ñ×2Ñ2¸qÐ2×AÔAÀTØ—;‘;˜{×7Ñ7Ó9×=Ñ=¼w¿{¹{ÈDÓQ×XÑXÓZ÷ BÒAä�;Š;�tÓÐøô ô ØŠðú÷
 B×Aús   ‚C	 Á!ACÃ	CÃCÃC,	c               ó   € V ^8„  d   QhRR/# )r   r   r*   r   )r   s   "r   r   r   ~   s   € ÷ ñ ˜sñ r   c                 ó¬   €  ^ RI Hp  V ! 4       ;'       g    RP                  4       #   \         d"   p\        P                  RT4        Rp?R# Rp?ii ; i)zONormalized CDP WebSocket URL via ``browser_tool_cdp._get_cdp_override``, or "".)Ú_get_cdp_overrideÚ z/browser_cdp: failed to resolve CDP endpoint: %sN)Útools.browser_tool_cdpr_   ÚstripÚ	ExceptionÚloggerÚdebug)r_   Úexcs     r   Ú_resolve_cdp_endpointrg   ~   sF   € ðÝ<Ù!Ó#×)Ð) r×0Ñ0Ó2Ð2øÜô Ü�‰ÐFÈÔLÝûðús   ‚' –' §A²AÁAc               ó$   € V ^8„  d   QhRRRRRR/# )r   Úmessager*   Úmethodr   r   )r   s   "r   r   r   ˆ   s&   € ÷ Eñ E�cð E 3ð E¨3ñ Er   c                ó$   € \        W\        R 7      # ))rj   Úcdp_docs)r   ÚCDP_DOCS_URL)ri   rj   s   &&r   Ú_blockedrn   ˆ   s   € Ü�g´|ÔDÐDr   c               ó    € V ^8„  d   QhRRRR/# )r   Ú
expressionr*   r   úOptional[str]r   )r   s   "r   r   r   Œ   s   € ÷ 7ñ 7¨3ð 7°=ñ 7r   c                ó   € ^ RI Hp V! V 4      # )é    )Ú_expression_targets_private_url)Útools.browser_tool_eval_policyrt   )rp   rt   s   & r   Ú_expression_private_targetrv   Œ   s   € ÝNÙ*¨:Ó6Ð6r   c               ó$   € V ^8„  d   QhRRRRRR/# )r   Úbtr   Úparamsúdict[str, Any]r   rq   r   )r   s   "r   r   r   ‘   s&   € ÷ Oñ O ð O¨nð OÀñ Or   c                ó¦   € ^ RI Hp \        VP                  R4      ;'       g    R4      P	                  4       pV'       d   V! W4      '       d   V# R# )z@Blocked URL literal for ``Page.navigate`` params, else ``None``.)Ú_url_blockedÚurlr`   N)ru   r|   r*   rC   rb   )rx   ry   r|   Ú
target_urls   &&  r   Ú_navigate_private_targetr   ‘   s@   € å;Ü�V—Z‘Z Ó&×,Ð,¨"Ó-×3Ñ3Ó5€Jß#©°R×(DÒ(Dˆ:ÐNÈ$ÐNr   zHBlocked: CDP Page.navigate target is a private or internal address ({}).zRuntime.evaluatec                ó\   € \        \        VP                  R 4      ;'       g    R4      4      # )rp   r`   )rv   r*   rC   )rx   ry   s   &&r   Ú<lambda>r�   œ   s"   € Ô,FÄsÈ6Ï:É:ÐVbÓKc×KiÐKiÐgiÓGjÔ,kr   zTBlocked: CDP Runtime.evaluate expression targets a private or internal address ({}).c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   Útask_idr*   rj   ry   rz   r   rq   r   )r   s   "r   r   r   ¡   s)   € ÷ ñ ¨3ð ¸ð À^ð ÐXeñ r   c                óÄ  €  ^ RI Hp ^ RI Hp VP                  V 4      '       g   R# \        P                  V4      pVe:   Vw  rgT! Y2;'       g    / 4      pV'       d   \        VP                  V4      V4      # V\        9  d.   VP                  V 4      p	V	'       d   \        RV	 RV: R2V4      # R#   \         d"   p
\        P                  RT
4        Rp
?
R# Rp
?
ii ; i)a#  Apply the browser SSRF/private-page guard to raw CDP calls.

Raw CDP shares the cloud/private-network boundary of ``browser_snapshot`` /
``browser_console`` / ``browser_eval`` and must not become their bypass. Probes are
best-effort; a probe failure never breaks local/custom CDP workflows.
)Úbrowser_tool)Úbrowser_tool_eval_policyNz9Blocked: page URL targets a private or internal address (z). Raw CDP method z, could expose private page content or state.z0browser_cdp: private-page guard probe failed: %s)Útoolsr…   r†   Ú_eval_ssrf_guard_activeÚ_METHOD_PARAM_GUARDSrC   rn   r   Ú!_CDP_PRIVATE_PAGE_ALLOWED_METHODSÚ_current_page_private_urlrc   rd   re   )rƒ   rj   ry   rx   ÚpolicyÚguardÚprobeÚtemplateÚliteralÚblocked_urlrf   s   $$$        r   Ú_browser_cdp_private_guardr’   ¡   sá   € ðNÝ,Ý<Ø×-Ñ-¨g×6Ò6ÙÜ$×(Ñ(¨Ó0ˆØÒØ#‰OˆEÙ˜B§ ¨"Ó-ˆGßÜ §¡°Ó 8¸&ÓAÐAØÔ:Ô:Ø ×:Ñ:¸7ÓCˆKßÜÐ"[Ð\gÐ[hð i2Ø28±Ð;gð!iØjpórð rñ øô ô NÜ�‰ÐGÈ×MÐMÙûðNús4   ‚"B3 §'B3 ÁB3 ÁB3 Á9#B3 ÂB3 Â3CÂ>CÃCc               ó0   € V ^8„  d   QhRRRRRRRRRR	R
R/# )r   Úws_urlr*   rj   ry   rz   Ú	target_idrq   ÚtimeoutÚfloatr   r   )r   s   "r   r   r   ½   s9   € ÷ '%ñ '%˜Cð '%¨ð '%°nð '%ÐQ^ð '%Ø"ð'%Ø'5ñ'%r   c              ƒ  ó¸  aa
a"  € \         f   Q h^ RIHp \         P                  ! V 3RRRSR^RR/V! V 4      B ;_uu_4       GRj  x€L
 o^o
R V
VV3R llpR	TR
T;'       g    / /pV'       dq   V! R	RR
RVRR//RV 24      G Rj  x€L
 pRV9   d   \	        RVR,           24      hVP                  R/ 4      P                  R4      p	V	'       g   \	        R4      hW—R&   V! VRV 24      G Rj  x€L
 pRV9   d   \	        RVR,           24      hVP                  R/ 4      uuRRR4      GRj  x€L
  #  Lí L® LH L  + GRj  x€L 
 '       g   i     R# ; i5i)zÃMake a single CDP call. With ``target_id``, ``Target.attachToTarget(flatten=True)`` multiplexes a
page-level session over the browser-level WebSocket; without it ``method`` runs at browser level.N)Úloopback_connect_kwargsÚmax_sizeÚopen_timeoutÚclose_timeoutÚping_intervalc               ó$   € V ^8„  d   QhRRRRRR/# )r   Úreqrz   Úwhatr*   r   r   )r   s   "r   r   Ú_cdp_call.<locals>.__annotate__É   s!   € ÷ 	ñ 	˜^ð 	°3ð 	¸>ñ 	r   c              “  ó  <"  € SS^,           upoSP                  \        P                  ! RV/V C4      4      G Rj  x€L
  \        P                  ! 4       P                  4       S,           p V\        P                  ! 4       P                  4       ,
          pV^ 8:  d   \        RV 24      h\        P                  ! \        P                  ! SP                  4       VR7      G Rj  x€L
 4      pVP                  R4      V8X  g   Kš  V#  LÊ L$5i)r    ÚidNz
Timed out ©r–   )ÚsendÚjsonÚdumpsrL   rM   ÚtimeÚTimeoutErrorÚloadsÚwait_forÚrecvrC   )	rŸ   r    Úcall_idÚdeadlineÚ	remainingÚmsgÚnext_idr–   Úwss	   &&    €€€r   Ú_sendÚ_cdp_call.<locals>._sendÉ   sÓ   øé € à&¨°!­ÐˆG�WØ—'‘'œ$Ÿ*š* d¨GÐ%;°sÐ%;Ó<Ó=×=Ð=Ü×/Ò/Ó1×6Ñ6Ó8¸7ÕBˆHØØ$¤w×'?Ò'?Ó'A×'FÑ'FÓ'HÕH�	Ø ”>Ü&¨°D°6Ð':Ó;Ð;Ü—j’j¤w×'7Ò'7¸¿¹»	È9Ô'U×!UÓV�Ø—7‘7˜4“= GÖ+Ø�Jñ >ñ "Vùs(   ƒ9D¼D½B'DÃ$D	Ã%DÄDÄ	Drj   ry   úTarget.attachToTargetÚtargetIdÚflattenTzattaching to target ÚerrorzTarget.attachToTarget failed: rW   Ú	sessionIdz0Target.attachToTarget did not return a sessionIdzwaiting for response to zCDP error: )Ú
websocketsÚagent.proxy_bypassr™   ÚconnectrN   rC   )r”   rj   ry   r•   r–   r™   r³   rŸ   r°   Ú
session_idr±   r²   s   &&&&f     @@r   Ú	_cdp_callr¾   ½   s�  úé € ô Ò!Ð!Ð!Ý:ô ×!Ò! &ñ Y°4ð YÀgð YÐ]^ð YØ04ðYÙ8OÐPVÓ8W÷Y÷ Yò YØ\^Øˆ÷	ò 	ð  (¨°¸6¿<¸<ÀRÐHˆßÙ˜xÐ)@À(ÈZÐYbÐdmÐosÐLtÐuØ 4°Y°KÐ@óB÷ BˆCà˜#Œ~Ü"Ð%CÀCÈÅLÀ>Ð#RÓSÐSØŸ™ ¨2Ó.×2Ñ2°;Ó?ˆJßÜ"Ð#UÓVÐVØ)�Ñá˜#Ð!9¸&¸ÐBÓC×CˆØ�cŒ>Ü ¨S°­\¨NÐ;Ó<Ð<Ø�w‰w�x Ó$÷?Y÷ Yô Yñ&Bñ D÷9Y÷ Y÷ Yó Yüs   …AEÁD5ÁEÁ%D=Á1D=ÂD7Â	AD=ÃD=Ã0D9Ã11D=Ä"EÄ/D;Ä0EÄ7D=Ä9D=Ä;EÄ=E	ÅEÅ
E	ÅE	Å	Ec               ó0   € V ^8„  d   QhRRRRRRRRRRR	R/# )
r   rƒ   r*   Úframe_idrj   ry   úOptional[dict[str, Any]]r–   r—   r   r   )r   s   "r   r   r   ç   sA   € ÷ /Tñ /T¨ð /T¸ð /TÀSð /TÐRjð /TØ).ð/TØ36ñ/Tr   c                ó¢  a€  ^ RI Hp TP	                  T 4      pTf   \        RT : R24      # TP                  4       P                  p\        T3R lTP	                  R4      .TP	                  R	4      ;'       g    . O 4       R4      p	T	fO   TP                  ;_uu_ 4        TP                  P	                  S4      p
RRR4       X
e   T
P                  4       MRp	T	f   \        R
S: R24      # T	P	                  R4      pT'       g   \        R
S: R24      # TP                  pTe   TP                  4       '       g   \        R4      #  ^ RIHp T! TP                  Y#;'       g    / Y´R7      T4      pTf   \        R\         R7      # TP#                  T^,           R7      p\(        P*                  ! RRRTRSRTRTP	                  R/ 4      /RR7      #   \         d   p\        RT R24      u Rp?# Rp?ii ; i  + '       g   i     ELG; i  \         d5   p\        R\%        T4      P&                   RT 2\         R7      u Rp?# Rp?ii ; i)zHRoute a CDP call through the live supervisor session for an OOPIF frame.)ÚSUPERVISOR_REGISTRYz!CDP supervisor is not available: zp. frame_id routing requires a running supervisor attached via /browser connect or an active Browserbase session.Nz'No CDP supervisor is attached for task=zª. Call browser_navigate or /browser connect first so the supervisor can attach. Once attached, browser_snapshot will populate frame_tree with frame_ids you can pass here.c              3  ój   <"  € T F(  q'       g   K  VP                  R 4      S8X  g   K$  Vx € K*  	  R# 5i)rÀ   N)rC   )r"   ÚfrÀ   s   & €r   r$   Ú._browser_cdp_via_supervisor.<locals>.<genexpr>ø   s+   øé € ÐlÑDˆqËŒÈaÏeÉeÐT^ÓN_ÐckÑNk�ŠÓDùs   ƒ	3‘3©
3ÚtopÚchildrenz	frame_id zP not found in supervisor state. Call browser_snapshot to see current frame_tree.r½   zò is not an out-of-process iframe (no dedicated CDP session). For same-origin iframes, use `browser_cdp(method='Runtime.evaluate', params={'expression': "document.querySelector('iframe').contentDocument.title"})` at the top-level page instead.zKCDP supervisor loop is not running. Try reconnecting with /browser connect.)Úsafe_schedule_threadsafe)r½   r–   z0CDP call via supervisor failed: loop unavailable©rl   r¤   z CDP call via supervisor failed: ú: ÚsuccessTrj   rÀ   rW   F©Úensure_ascii)Útools.browser_supervisorrÃ   rc   r   rC   ÚsnapshotÚ
frame_treeÚnextÚ_state_lockÚ_framesÚto_dictÚ_looprO   Úagent.async_utilsrÉ   Ú_cdprm   rW   rA   Ú__name__r¦   r§   )rƒ   rÀ   rj   ry   r–   rÃ   rf   Ú
supervisorÚtreeÚ
frame_infoÚrawÚ	child_sidrY   rÉ   ÚfutÚ
result_msgs   &f&&&           r   Ú_browser_cdp_via_supervisorrá   ç   sl  ø€ ðhÝ@ð
 %×(Ñ(¨Ó1€JØÒÜÐCÀGÁ;ð OWð Wó Xð 	Xð ×ÑÓ ×+Ñ+€DÜ+/Ül�T—X‘X˜e“_ÐD¨¯©°Ó(<×(BÐ(BÀÑDÓlÐnró,t€JàÒØ×#×#Ó#Ø×$Ñ$×(Ñ(¨Ó2ˆC÷ $à&)¢o�S—[‘[”]¸4ˆ
ØÒÜ˜I h¡\ð 2Mð Mó Nð 	Nð —‘˜|Ó,€IßÜ˜I h¡\ð 2yð yó zð 	zð ×Ñ€DØ‚|˜4Ÿ?™?×,Ò,ÜÐgÓhÐhðqÝ>Ù&Ø�O‰O˜F§L L¨b¸YˆOÓXÐZ^ó`ˆàŠ;ÜÐPÔ[gÔhÐhØ—Z‘Z¨°!­�ZÓ4ˆ
ô �:Š:�y $¨°&¸*ÀhÐP\Ð^gØ §¡°¸"Ó!=ð?ØMRôTð TøôS ô hÜÐ=¸c¸Uð Cgð gó hõ 	hûðhú÷ $×#Ð#ûô0 ô qÜÐ<¼TÀ#»Y×=OÑ=OÐ<PÐPRÐSVÐRWÐXÔcoÔpÕpûðqúsS   ƒG Â!G;Å
H Å&"H Æ	H ÇG8ÇG3Ç-G8Ç3G8Ç;H	ÈIÈ)I	ÉIÉ	Ic               ó4   € V ^8„  d   QhRRRRRRRRRR	R
RRR/# )r   rj   r*   ry   rÁ   r•   rq   rÀ   r–   r—   rƒ   r   r   )r   s   "r   r   r     sC   € ÷ =3ñ =3˜ð =3Ð%=ð =3ÐQ^ð =3Ø'ð=3Ø9>ð=3ØP]ð=3Øilñ=3r   c                óf  € T;'       g    RpV'       d0   \        Y`T;'       g    / R7      pV'       d   V# \        WcV WR7      # V '       d   \        V \        4      '       g   \	        R\
        R7      # \        '       g   \	        R4      # \        4       pV'       g   \	        R\
        R7      # VP                  R4      '       g   \	        RV: R	24      # T;'       g    / p	\        V	\        4      '       g"   \	        R
\        V	4      P                   24      # \        W`V	R7      pV'       d   V#  V'       d   \        V4      MRp
\        R\!        V
R4      4      p
 \#        \%        W€W’V
4      4      pRRRT R\3        T\4        P7                  T R 4      \8        P7                  T R 4      R7      /pT'       d   Y-R&   \:        P<                  ! TRR7      #   \        \        3 d    Rp
 L¢i ; i  \&         d   p\	        RT
 RT 2T R7      u Rp?# Rp?i\(         d!   p\	        \        T4      T R7      u Rp?# Rp?i\*         d   p\	        RT RT R2T R7      u Rp?# Rp?i\,         dF   p\.        P1                  R4       \	        R\        T4      P                   RT 2T R7      u Rp?# Rp?ii ; i)!uÛ  Send a raw CDP command (see ``CDP_DOCS_URL``). ``target_id`` attaches a fresh stateless connection
to a tab; ``frame_id`` (OOPIF from ``browser_snapshot.frame_tree``) routes through the supervisor's live
WebSocket instead â€” the only reliable way to evaluate inside an iframe where fresh per-call connections
hit signed-URL expiry (Browserbase). Both paths share the same private-page/SSRF guard. Returns JSON
``{"success": True, "method", "result"}`` or ``{"error": ...}``.Údefault)rƒ   rj   ry   )rƒ   rÀ   rj   ry   r–   z/'method' is required (e.g. 'Target.getTargets')rÊ   zTThe 'websockets' Python package is required but not installed. Run: hermes pm repairzØNo CDP endpoint is available. Run '/browser connect' to attach to a running Chrome, Brave, Chromium, or Edge browser, or set 'browser.cdp_url' in config.yaml. The Camofox backend is REST-only and does not expose CDP.z%CDP endpoint is not a WebSocket URL: u¬   . Expected ws://... or wss://... â€” the /browser connect resolver should have rewritten this. Check that a Chromium-family browser is actually listening on the debug port.z%'params' must be an object/dict, got ç      >@g      ð?g     Àr@zCDP call timed out after zs: )rj   Nz"WebSocket error talking to CDP at rË   uE   . The browser may have disconnected â€” try '/browser connect' again.zbrowser_cdp unexpected errorzUnexpected error: rÌ   Trj   rW   )r   r   r•   FrÍ   )zws://zwss://r   )r’   rá   r?   r*   r   rm   Ú_WS_AVAILABLErg   Ú
startswithrB   rA   rÙ   r—   Ú	TypeErrorÚ
ValueErrorÚmaxÚminr\   r¾   r©   rN   rI   rc   rd   Ú	exceptionr!   r
   rC   r   r¦   r§   )rj   ry   r•   rÀ   r–   rƒ   Úeffective_task_idÚblockedÚendpointÚcall_paramsÚsafe_timeoutrW   rf   Úpayloads   &&&&&&        r   Úbrowser_cdpró     s§  € ð  ×,Ð, 9ÐçÜ,Ð5FÐ^d×^jÐ^jÐhjÔkˆßØˆNÜ*Ð3DÐ`fØ28ôKð 	K÷ œ F¬C×0Ò0ÜÐKÔVbÔcÐcß‹=Üð 2ó 3ð 	3ä$Ó&€HßÜð JäT`ôbð 	bð ×ÑÐ2×3Ò3ÜÐAÀ(Áð NMð Mó Nð 	Nð #)§, ,¨B€KÜ�k¤4×(Ò(ÜÐAÄ$À{ÓBS×B\ÑB\ÐA]Ð^Ó_Ð_ä(Ð1BÐZeÔf€GßØˆðß)0”u˜W”~°dˆô �sœC ¨eÓ4Ó5€Lð[ÜœI h¸ÐP\Ó]Ó^ˆð  )¨$°¸&À(ÔL^ØÔ5×9Ñ9¸&À"ÓEÜ/×3Ñ3°F¸BÓ?ôMAð B€G÷ Ø(�ÑÜ�:Š:�g¨EÔ2Ð2øô+ ”zÐ"ô ØŠðûô
 ô ]ÜÐ5°l°^À3ÀsÀeÐLÐU[Ô\Õ\ûÜô 3Üœ#˜c›(¨6Ô2Õ2ûÜô [ÜÐ>¸x¸jÈÈ3È%ð PKð KØSYô[õ 	[ûäô [Ü×ÑÐ7Ô8ÜÐ.¬t°C«y×/AÑ/AÐ.BÀ"ÀSÀEÐJÐSYÔZÕZûð[ús~   Ä/G Ä7G ÅG* ÇG'Ç&G'Ç*J0Ç5HÈJ0ÈJ0ÈJ0ÈH6È0J0È6J0ÉJ0ÉIÉJ0ÉJ0É*J0É+:J+Ê%J0Ê+J0Únameró   Údescriptionuœ  Send a raw Chrome DevTools Protocol (CDP) command. Escape hatch for browser operations not covered by browser_navigate, browser_click, browser_console, etc.

**Requires a reachable CDP endpoint.** Available when the user has run '/browser connect' to attach to a running Chrome, Brave, Chromium, or Edge browser, or when 'browser.cdp_url' is set in config.yaml. Not currently wired up for cloud backends (Browserbase, Browser Use, Firecrawl) â€” those expose CDP per session but live-session routing is a follow-up. Camofox is REST-only and will never support CDP. If the tool is in your toolset at all, a CDP endpoint is already reachable.

**CDP method reference:** uÅ   â€” use an available documentation lookup or extraction tool on a method's URL (e.g. '/tot/Page/#method-handleJavaScriptDialog') to look up parameters and return shape.

**Common patterns:**
- List tabs: method='Target.getTargets', params={}
- Handle a native JS dialog: method='Page.handleJavaScriptDialog', params={'accept': true, 'promptText': ''}, target_id=<tabId>
- Get all cookies: method='Network.getAllCookies', params={}
- Eval in a specific tab: method='Runtime.evaluate', params={'expression': '...', 'returnByValue': true}, target_id=<tabId>
- Set viewport for a tab: method='Emulation.setDeviceMetricsOverride', params={'width': 1280, 'height': 720, 'deviceScaleFactor': 1, 'mobile': false}, target_id=<tabId>

**Usage rules:**
- Browser-level methods (Target.*, Browser.*, Storage.*): omit target_id and frame_id.
- Page-level methods (Page.*, Runtime.*, DOM.*, Emulation.*, Network.* scoped to a tab): pass target_id from Target.getTargets.
- **Cross-origin iframe scope** (Runtime.evaluate inside an OOPIF, Page.* targeting a frame target, etc.): pass frame_id from the browser_snapshot frame_tree output. This routes through the CDP supervisor's live connection â€” the only reliable way on Browserbase where stateless CDP calls hit signed-URL expiry.
- Each stateless call (without frame_id) is independent â€” sessions and event subscriptions do not persist between calls. For stateful workflows, prefer the dedicated browser tools or use frame_id routing.Ú
parametersrA   ÚobjectÚ
propertiesrj   Ústringz]CDP method name, e.g. 'Target.getTargets', 'Runtime.evaluate', 'Page.handleJavaScriptDialog'.ry   ÚadditionalPropertieszaMethod-specific parameters as a JSON object. Omit or pass {} for methods that take no parameters.r•   z©Optional. Target/tab ID from Target.getTargets result (each entry's 'targetId'). Use for page-level methods at the top-level tab scope. Mutually exclusive with frame_id.rÀ   aà  Optional. Out-of-process iframe (OOPIF) frame_id from browser_snapshot.frame_tree.children[] where is_oopif=true. When set, routes the call through the CDP supervisor's live session for that iframe. Essential for Runtime.evaluate inside cross-origin iframes, especially on Browserbase where fresh per-call CDP connections can't keep up with signed URL rotation. For same-origin iframes, use parent contentWindow/contentDocument from Runtime.evaluate at the top-level page instead.r–   Únumberrä   z)Timeout in seconds (default 30, max 300).Úrequiredrz   ÚBROWSER_CDP_SCHEMAc               ó   € V ^8„  d   QhRR/# )r   r   r+   r   )r   s   "r   r   r   “  s   € ÷ Jñ J˜Dñ Jr   c                 ó¸   €  ^ RI Hp  ^ RIHp \        T! 4       ;'       d    T ! 4       4      #   \         d"   p\
        P                  RT4        Rp?R# Rp?ii ; i)a<  Availability check: offered only when a static CDP URL is set (Camofox is REST-only;
the default local agent-browser hides its CDP port; cloud per-session ``cdp_url`` isn't
surfaced). Raw (no-I/O) gate: check_fns run at every startup, and resolving the endpoint
over HTTP here would block launch on a stale endpoint.)Ú_get_cdp_override_raw)Úcheck_browser_requirementsz1browser_cdp check: browser_tool import failed: %sNF)ra   r   Útools.browser_tool_installr  ÚImportErrorrd   re   r+   )r   r  rf   s      r   Ú_browser_cdp_checkr  “  sN   € ð
Ý@ÝIô Ñ*Ó,×HÐHÑ1FÓ1HÓIÐIøô ô Ü�‰ÐHÈ#ÔNÝûðús   ‚- ­A¸AÁAzbrowser-cdpc           	     ól   a a€ \        R S V V3R lSP                  R4      SP                  R4      R7      # )ró   c            
     óÞ   <€ \        S P                  R R4      S P                  R4      S P                  R4      S P                  R4      S P                  RR4      SP                  R4      R7      # )	rj   r`   ry   r•   rÀ   r–   rå   rƒ   )rj   ry   r•   rÀ   r–   rƒ   )ró   rC   ©ÚargsÚkws   €€r   r�   Ú<lambda>.<locals>.<lambda>§  sZ   ø€ œØ—8‘8˜H bÓ)°$·(±(¸8Ó2DÐPT×PXÑPXÐYdÓPeØ—X‘X˜jÓ)°4·8±8¸IÀtÓ3LÐVX×V\ÑV\Ð]fÓVgõ
r   rƒ   r½   )Úfallbackrƒ   r½   )r   rC   r  s   flr   r�   r�   ¥  s.   ù€ Ô5Ø�tõ
ð —‘�yÓ!¨b¯f©f°\Ó.Bõ r   u   ðŸ§ª)rô   ÚtoolsetÚschemaÚhandlerÚcheck_fnÚemoji>   úPage.reloadr	   úPage.stopLoadingúTarget.getTargetsúBrowser.getVersionrµ   úTarget.detachFromTarget))Údata))ÚbufferedData))ÚscreenshotData))ÚresponseÚbody))r  ))ÚpostDatar   )NNNrå   N),Ú__conditional_annotations__Ú__doc__Ú
__future__r   rL   r¦   ÚloggingÚtypingr   r   r   Útools.registryr   r   Útools.browser_extension_routerr   Ú	getLoggerrÙ   rd   rm   rŠ   r
   Ú__annotations__r   r!   rº   Úwebsockets.exceptionsrI   ræ   r  rc   r\   rg   rn   rv   r   r‰   r’   r¾   rá   ró   rý   r  Úregister)r  s   @r   Ú<module>r'     s3  øðôõ #ã Û Û ß &Ñ &ç /Ý Aà	×	Ò	˜8Ó	$€àD€ò%Ð !ð ˜lÐ,=¸|Ø#Ð%9Ð;\Ð^tØ(Ð*Að.Ð Ð*ó ð ˜|Ð-DÀlØˆ|Ð9Ð;Kð/Ð Ð+ó ð1ð ð1ð ð	1ð
 ÷1ðjÛÝ8à€MòõõEõ7õ
Oð Ð.Ø`ðbàÑkØoðqðÐ õõ8'%õT/T÷d=3ðB ˆMØð	%ð &2 Nð 3ð	ð> Ø�ØØ�v˜x¨Øoðrà�v˜x¨°rÐ;QÐSWÐYfØsðvà˜& (¨Mðcðeð ˜ ¨=ð*ð,ð ˜ ¨)°R¸ÐHsÐtð
ð" 	�X�Jð'ðE7&Ð �Nó 7õtJð 	× Ò Ø	ØØñð  Ø
÷øðo	 ô Ø€JØ"ÐØ‚Mðús   Á8D! Ä!D1Ä0D1