
    ]jߥ              
      >
   d dl mZ d dlmZ d dlmZmZ d dlmZ d dl	m
Z
 d dlmZmZmZ  G d d      Z G d	 d
      Z G d d      Ze G d d             Ze G d d             Ze G d d             Ze G d d             Ze G d d             Ze G d d             Ze G d d             Ze G d d             Ze G d d             Ze G d d              Ze G d! d"             Ze G d# d$             Ze G d% d&             Ze G d' d(             Ze G d) d*             Z e G d+ d,             Z!e G d- d.             Z"e G d/ d0             Z#e G d1 d2             Z$e G d3 d4             Z%e G d5 d6             Z&e G d7 d8             Z'e G d9 d:             Z(e G d; d<             Z)e G d= d>             Z*e G d? d@             Z+e G dA dB             Z,e G dC dD             Z-e G dE dF             Z.e G dG dH             Z/e G dI dJ             Z0e G dK dL             Z1e G dM dN             Z2e G dO dP             Z3e G dQ dR             Z4e G dS dT             Z5e G dU dV             Z6e G dW dX             Z7e G dY dZ             Z8e G d[ d\             Z9e G d] d^             Z:e G d_ d`             Z;e G da db             Z<e G dc dd             Z=e G de df             Z>e G dg dh             Z?e G di dj             Z@e G dk dl             ZAe G dm dn             ZBe G do dp             ZCe G dq dr             ZDe G ds dt             ZEe G du dv             ZFe G dw dx             ZGe G dy dz             ZHe G d{ d|             ZIe G d} d~             ZJe G d d             ZKe G d d             ZLe G d d             ZMe G d d             ZNe G d d             ZOe G d d             ZPe G d d             ZQe G d d             ZRe G d d             ZSe G d d             ZTddddZU G d d      ZV eW       j                  deY      ZZ eW       j                  deY      Z[ eW       j                  deY      Z\ eW       Z] edde]j                  d      re]j                  deY      neY       edde]j                  d      re]j                  deY      neY       edde]j                  d      re]j                  deY      neY      deV_^        y)    )annotations)Callable)	dataclassfield)Any)command_builder)EventConfig_EventWrapper_EventManagerc                       e Zd ZdZdZdZdZdZy)SpecialNumberzSpecialNumber.NaNz-0Infinity	-InfinityN)__name__
__module____qualname____doc__NAN_0INFINITY	_INFINITY     Y/home/ubuntu/.local/lib/python3.12/site-packages/selenium/webdriver/common/bidi/script.pyr   r      s    
C	BHIr   r   c                  0    e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zy
)	RealmTypez
RealmType.windowdedicated-workershared-workerservice-workerworkerpaint-workletaudio-workletworkletN)r   r   r   r   WINDOWDEDICATED_WORKERSHARED_WORKERSERVICE_WORKERWORKERPAINT_WORKLETAUDIO_WORKLETWORKLETr   r   r   r   r      s.    F)#M%NF#M#MGr   r   c                      e Zd ZdZdZdZy)ResultOwnershipzResultOwnership.rootnoneN)r   r   r   r   ROOTNONEr   r   r   r/   r/   &   s    DDr   r/   c                  >    e Zd ZU dZ edd      Zded<   dZded	<   y)
ChannelValuezChannelValue.channelFdefaultinitstrtypeN
Any | Nonevaluer   r   r   r   r   r;   __annotations__r=   r   r   r   r5   r5   -   s     ie4D#4E:r   r5   c                  <    e Zd ZU dZdZded<   dZded<   dZded<   y)ChannelPropertieszChannelProperties.Nr<   r6   serialization_options	ownership)r   r   r   r   r6   r?   rB   rC   r   r   r   rA   rA   5   s$    GZ(,:, Iz r   rA   c                  L    e Zd ZU dZ edd      Zded<   dZded	<   dZded
<   y)EvaluateResultSuccesszEvaluateResultSuccess.successFr7   r:   r;   Nr<   resultrealm)	r   r   r   r   r   r;   r?   rG   rH   r   r   r   rE   rE   >   s*     ie4D#4FJE:r   rE   c                  L    e Zd ZU dZ edd      Zded<   dZded	<   dZded
<   y)EvaluateResultExceptionzEvaluateResultException.	exceptionFr7   r:   r;   Nr<   exception_detailsrH   )	r   r   r   r   r   r;   r?   rL   rH   r   r   r   rJ   rJ   G   s+    "k6D#6$(z(E:r   rJ   c                  X    e Zd ZU dZdZded<   dZded<   dZded<   dZded<   dZ	ded	<   y)
ExceptionDetailszExceptionDetails.Nr<   column_numberrK   line_numberstack_trace
str | Nonetext)
r   r   r   r   rO   r?   rK   rP   rQ   rS   r   r   r   rN   rN   P   s7     $M:$ Iz "K""K"D*r   rN   c                  >    e Zd ZU dZ edd      Zded<   dZded	<   y)
ArrayLocalValuezArrayLocalValue.arrayFr7   r:   r;   Nr<   r=   r>   r   r   r   rU   rU   [   s     gE2D#2E:r   rU   c                  >    e Zd ZU dZ edd      Zded<   dZded	<   y)
DateLocalValuezDateLocalValue.dateFr7   r:   r;   NrR   r=   r>   r   r   r   rX   rX   c   s     f51D#1E:r   rX   c                  >    e Zd ZU dZ edd      Zded<   dZded	<   y)
MapLocalValuezMapLocalValue.mapFr7   r:   r;   Nr<   r=   r>   r   r   r   r[   r[   k        e%0D#0E:r   r[   c                  >    e Zd ZU dZ edd      Zded<   dZded	<   y)
ObjectLocalValuezObjectLocalValue.objectFr7   r:   r;   Nr<   r=   r>   r   r   r   r_   r_   s        hU3D#3E:r   r_   c                  .    e Zd ZU dZdZded<   dZded<   y)RegExpValuezRegExpValue.NrR   patternflags)r   r   r   r   rd   r?   re   r   r   r   rc   rc   {   s    GZE:r   rc   c                  >    e Zd ZU dZ edd      Zded<   dZded	<   y)
RegExpLocalValuezRegExpLocalValue.regexpFr7   r:   r;   Nr<   r=   r>   r   r   r   rg   rg      ra   r   rg   c                  >    e Zd ZU dZ edd      Zded<   dZded	<   y)
SetLocalValuezSetLocalValue.setFr7   r:   r;   Nr<   r=   r>   r   r   r   rj   rj      r]   r   rj   c                  0    e Zd ZU dZ edd      Zded<   y)UndefinedValuezUndefinedValue.	undefinedFr7   r:   r;   Nr   r   r   r   r   r;   r?   r   r   r   rm   rm      s    k6D#6r   rm   c                  0    e Zd ZU dZ edd      Zded<   y)	NullValuez
NullValue.nullFr7   r:   r;   Nro   r   r   r   rq   rq      s    f51D#1r   rq   c                  >    e Zd ZU dZ edd      Zded<   dZded	<   y)
StringValuezStringValue.stringFr7   r:   r;   NrR   r=   r>   r   r   r   rt   rt           hU3D#3E:r   rt   c                  >    e Zd ZU dZ edd      Zded<   dZded	<   y)
NumberValuezNumberValue.numberFr7   r:   r;   Nr<   r=   r>   r   r   r   rx   rx      rv   r   rx   c                  >    e Zd ZU dZ edd      Zded<   dZded	<   y)
BooleanValuezBooleanValue.booleanFr7   r:   r;   Nbool | Noner=   r>   r   r   r   r{   r{      s     ie4D#4E;r   r{   c                  >    e Zd ZU dZ edd      Zded<   dZded	<   y)
BigIntValuezBigIntValue.bigintFr7   r:   r;   NrR   r=   r>   r   r   r   r   r      rv   r   r   c                  .    e Zd ZU dZdZded<   dZded<   y)BaseRealmInfozBaseRealmInfo.Nr<   rH   rR   origin)r   r   r   r   rH   r?   r   r   r   r   r   r      s    E:FJr   r   c                  Z    e Zd ZU dZ edd      Zded<   dZded	<   dZded
<   dZ	ded<   y)WindowRealmInfozWindowRealmInfo.r   Fr7   r:   r;   Nr<   contextuser_contextrR   sandbox)
r   r   r   r   r   r;   r?   r   r   r   r   r   r   r   r      s4    hU3D#3GZ#L*#GZr   r   c                  L    e Zd ZU dZ edd      Zded<    ee      Zded	<   y
)DedicatedWorkerRealmInfozDedicatedWorkerRealmInfo.r   Fr7   r:   r;   default_factory	list[Any]ownersN)	r   r   r   r   r   r;   r?   listr   r   r   r   r   r      s&    #0u=D#=d3FI3r   r   c                  0    e Zd ZU dZ edd      Zded<   y)SharedWorkerRealmInfozSharedWorkerRealmInfo.r    Fr7   r:   r;   Nro   r   r   r   r   r           oE:D#:r   r   c                  0    e Zd ZU dZ edd      Zded<   y)ServiceWorkerRealmInfozServiceWorkerRealmInfo.r!   Fr7   r:   r;   Nro   r   r   r   r   r      s    !.U;D#;r   r   c                  0    e Zd ZU dZ edd      Zded<   y)WorkerRealmInfozWorkerRealmInfo.r"   Fr7   r:   r;   Nro   r   r   r   r   r      s    hU3D#3r   r   c                  0    e Zd ZU dZ edd      Zded<   y)PaintWorkletRealmInfozPaintWorkletRealmInfo.r#   Fr7   r:   r;   Nro   r   r   r   r   r      r   r   r   c                  0    e Zd ZU dZ edd      Zded<   y)AudioWorkletRealmInfozAudioWorkletRealmInfo.r$   Fr7   r:   r;   Nro   r   r   r   r   r      r   r   r   c                  0    e Zd ZU dZ edd      Zded<   y)WorkletRealmInfozWorkletRealmInfo.r%   Fr7   r:   r;   Nro   r   r   r   r   r      s    ie4D#4r   r   c                  .    e Zd ZU dZdZded<   dZded<   y)SharedReferencezSharedReference.Nr<   	shared_idhandle)r   r   r   r   r   r?   r   r   r   r   r   r     s     Iz FJr   r   c                  .    e Zd ZU dZdZded<   dZded<   y)RemoteObjectReferencezRemoteObjectReference.Nr<   r   r   )r   r   r   r   r   r?   r   r   r   r   r   r     s     FJ Iz r   r   c                  L    e Zd ZU dZ edd      Zded<   dZded	<   dZded
<   y)SymbolRemoteValuezSymbolRemoteValue.symbolFr7   r:   r;   Nr<   r   internal_id	r   r   r   r   r   r;   r?   r   r   r   r   r   r   r     s*    hU3D#3FJ"K"r   r   c                  Z    e Zd ZU dZ edd      Zded<   dZded	<   dZded
<   dZ	ded<   y)ArrayRemoteValuezArrayRemoteValue.rV   Fr7   r:   r;   Nr<   r   r   r=   
r   r   r   r   r   r;   r?   r   r   r=   r   r   r   r   r     s4    gE2D#2FJ"K"E:r   r   c                  Z    e Zd ZU dZ edd      Zded<   dZded	<   dZded
<   dZ	ded<   y)ObjectRemoteValuezObjectRemoteValue.r`   Fr7   r:   r;   Nr<   r   r   r=   r   r   r   r   r   r   (  s4    hU3D#3FJ"K"E:r   r   c                  L    e Zd ZU dZ edd      Zded<   dZded	<   dZded
<   y)FunctionRemoteValuezFunctionRemoteValue.functionFr7   r:   r;   Nr<   r   r   r   r   r   r   r   r   2  s*    ju5D#5FJ"K"r   r   c                  .    e Zd ZU dZdZded<   dZded<   y)RegExpRemoteValuezRegExpRemoteValue.Nr<   r   r   r   r   r   r   r   r?   r   r   r   r   r   r   ;  s    FJ"K"r   r   c                  .    e Zd ZU dZdZded<   dZded<   y)DateRemoteValuezDateRemoteValue.Nr<   r   r   r   r   r   r   r   r   C  s    FJ"K"r   r   c                  Z    e Zd ZU dZ edd      Zded<   dZded	<   dZded
<   dZ	ded<   y)MapRemoteValuezMapRemoteValue.r\   Fr7   r:   r;   Nr<   r   r   r=   r   r   r   r   r   r   K  4    e%0D#0FJ"K"E:r   r   c                  Z    e Zd ZU dZ edd      Zded<   dZded	<   dZded
<   dZ	ded<   y)SetRemoteValuezSetRemoteValue.rk   Fr7   r:   r;   Nr<   r   r   r=   r   r   r   r   r   r   U  r   r   r   c                  L    e Zd ZU dZ edd      Zded<   dZded	<   dZded
<   y)WeakMapRemoteValuezWeakMapRemoteValue.weakmapFr7   r:   r;   Nr<   r   r   r   r   r   r   r   r   _  *    ie4D#4FJ"K"r   r   c                  L    e Zd ZU dZ edd      Zded<   dZded	<   dZded
<   y)WeakSetRemoteValuezWeakSetRemoteValue.weaksetFr7   r:   r;   Nr<   r   r   r   r   r   r   r   r   h  r   r   r   c                  L    e Zd ZU dZ edd      Zded<   dZded	<   dZded
<   y)GeneratorRemoteValuezGeneratorRemoteValue.	generatorFr7   r:   r;   Nr<   r   r   r   r   r   r   r   r   q  s*    k6D#6FJ"K"r   r   c                  L    e Zd ZU dZ edd      Zded<   dZded	<   dZded
<   y)ErrorRemoteValuezErrorRemoteValue.errorFr7   r:   r;   Nr<   r   r   r   r   r   r   r   r   z  *    gE2D#2FJ"K"r   r   c                  L    e Zd ZU dZ edd      Zded<   dZded	<   dZded
<   y)ProxyRemoteValuezProxyRemoteValue.proxyFr7   r:   r;   Nr<   r   r   r   r   r   r   r   r     r   r   r   c                  L    e Zd ZU dZ edd      Zded<   dZded	<   dZded
<   y)PromiseRemoteValuezPromiseRemoteValue.promiseFr7   r:   r;   Nr<   r   r   r   r   r   r   r   r     r   r   r   c                  L    e Zd ZU dZ edd      Zded<   dZded	<   dZded
<   y)TypedArrayRemoteValuezTypedArrayRemoteValue.
typedarrayFr7   r:   r;   Nr<   r   r   r   r   r   r   r   r     s*     l7D#7FJ"K"r   r   c                  L    e Zd ZU dZ edd      Zded<   dZded	<   dZded
<   y)ArrayBufferRemoteValuezArrayBufferRemoteValue.arraybufferFr7   r:   r;   Nr<   r   r   r   r   r   r   r   r     s*    !m%8D#8FJ"K"r   r   c                  Z    e Zd ZU dZ edd      Zded<   dZded	<   dZded
<   dZ	ded<   y)NodeListRemoteValuezNodeListRemoteValue.nodelistFr7   r:   r;   Nr<   r   r   r=   r   r   r   r   r   r     s4    ju5D#5FJ"K"E:r   r   c                  Z    e Zd ZU dZ edd      Zded<   dZded	<   dZded
<   dZ	ded<   y)HTMLCollectionRemoteValuezHTMLCollectionRemoteValue.htmlcollectionFr7   r:   r;   Nr<   r   r   r=   r   r   r   r   r   r     s5    $.U;D#;FJ"K"E:r   r   c                  h    e Zd ZU dZ edd      Zded<   dZded	<   dZded
<   dZ	ded<   dZ
ded<   y)NodeRemoteValuezNodeRemoteValue.nodeFr7   r:   r;   Nr<   r   r   r   r=   )r   r   r   r   r   r;   r?   r   r   r   r=   r   r   r   r   r     s>    f51D#1 Iz FJ"K"E:r   r   c                      e Zd ZU dZdZded<   dZded<    ee      Z	ded<   dZ
d	ed
<   dZded<   dZd	ed<   dZd	ed<   dZded<   y)NodePropertieszNodeProperties.Nr<   	node_typechild_node_countr   r   childrenrR   
local_namemodenamespace_uri
node_valueshadow_root)r   r   r   r   r   r?   r   r   r   r   r   r   r   r   r   r   r   r   r   r     s[     Iz #'j'5Hi5!J
!D* $M:$!J
!"K"r   r   c                  Z    e Zd ZU dZ edd      Zded<   dZded	<   dZded
<   dZ	ded<   y)WindowProxyRemoteValuezWindowProxyRemoteValue.r   Fr7   r:   r;   Nr<   r=   r   r   )
r   r   r   r   r   r;   r?   r=   r   r   r   r   r   r   r     s4    !hU3D#3E:FJ"K"r   r   c                       e Zd ZU dZdZded<   y)WindowProxyPropertieszWindowProxyProperties.Nr<   r   )r   r   r   r   r   r?   r   r   r   r   r     s     GZr   r   c                  J    e Zd ZU dZdZded<   dZded<   dZded<   dZded<   y)	
StackFramezStackFrame.Nr<   rO   rR   function_namerP   url)	r   r   r   r   rO   r?   r   rP   r   r   r   r   r   r     s-     $M:$ $M:$"K"Cr   r   c                  .    e Zd ZU dZ ee      Zded<   y)
StackTracezStackTrace.r   r   call_framesN)r   r   r   r   r   r   r   r?   r   r   r   r   r     s    "48K8r   r   c                  <    e Zd ZU dZdZded<   dZded<   dZded<   y)SourcezSource.Nr<   rH   r   r   )r   r   r   r   rH   r?   r   r   r   r   r   r   r     s#    E:GZ#L*#r   r   c                       e Zd ZU dZdZded<   y)RealmTargetzRealmTarget.Nr<   rH   r   r   r   r   rH   r?   r   r   r   r   r     s    E:r   r   c                  .    e Zd ZU dZdZded<   dZded<   y)ContextTargetzContextTarget.Nr<   r   rR   r   )r   r   r   r   r   r?   r   r   r   r   r   r     s    GZGZr   r   c                      e Zd ZU dZdZded<    ee      Zded<    ee      Z	ded<    ee      Z
ded	<   dZded
<   y)AddPreloadScriptParameterszAddPreloadScriptParameters.NrR   function_declarationr   r   	argumentscontextsuser_contextsr   )r   r   r   r   r   r?   r   r   r   r   r   r   r   r   r   r   r     sG    %'+*+ 6Iy65Hi5$T:M9:GZr   r   c                       e Zd ZU dZdZded<   y)AddPreloadScriptResultzAddPreloadScriptResult.Nr<   scriptr   r   r   r   r  r?   r   r   r   r   r     s    !FJr   r   c                  <    e Zd ZU dZ ee      Zded<   dZded<   y)DisownParameterszDisownParameters.r   r   handlesNr<   target)	r   r   r   r   r   r   r  r?   r  r   r   r   r  r     s    t4GY4FJr   r  c                      e Zd ZU dZdZded<   dZded<   dZded<    ee		      Z
d
ed<   dZded<   dZded<   dZded<   dZded<   y)CallFunctionParameterszCallFunctionParameters.NrR   r   r}   await_promiser<   r  r   r   r   result_ownershiprB   thisuser_activation)r   r   r   r   r   r?   r	  r  r   r   r   r
  rB   r  r  r   r   r   r  r  (  s]    !'+*+!%M;%FJ 6Iy6#'j'(,:,D*#'O['r   r  c                  f    e Zd ZU dZdZded<   dZded<   dZded<   dZded	<   dZ	ded
<   dZ
ded<   y)EvaluateParameterszEvaluateParameters.NrR   
expressionr<   r  r}   r	  r
  rB   r  )r   r   r   r   r  r?   r  r	  r
  rB   r  r   r   r   r  r  6  sC    !J
!FJ!%M;%#'j'(,:,#'O['r   r  c                  .    e Zd ZU dZdZded<   dZded<   y)GetRealmsParameterszGetRealmsParameters.Nr<   r   r;   )r   r   r   r   r   r?   r;   r   r   r   r  r  B  s    GZD*r   r  c                  .    e Zd ZU dZ ee      Zded<   y)GetRealmsResultzGetRealmsResult.r   r   realmsN)r   r   r   r   r   r   r  r?   r   r   r   r  r  J  s    d3FI3r   r  c                       e Zd ZU dZdZded<   y)RemovePreloadScriptParameterszRemovePreloadScriptParameters.Nr<   r  r  r   r   r   r  r  Q  s    (FJr   r  c                  <    e Zd ZU dZdZded<   dZded<   dZded<   y)MessageParameterszMessageParameters.Nr<   r6   datasource)r   r   r   r   r6   r?   r  r  r   r   r   r  r  X  s#    GZD*FJr   r  c                       e Zd ZU dZdZded<   y)RealmDestroyedParameterszRealmDestroyedParameters.Nr<   rH   r   r   r   r   r  r  a  s    #E:r   r  c                  J    e Zd ZU dZdZded<   dZded<   dZded<   dZded<   y)DomMutationa  Represents a DOM attribute mutation event from add_dom_mutation_handler.

    Attributes:
        element_id: The ``data-__webdriver_id`` attribute value set on the
            mutated element by the MutationObserver. Use this to locate the
            element from the main thread if needed.
        attribute_name: The name of the changed attribute.
        current_value: The attribute value after the mutation (may be ``None``
            if the attribute was removed).
        old_value: The attribute value before the mutation.
    NrR   
element_idattribute_namecurrent_value	old_value)	r   r   r   r   r  r?   r   r!  r"  r   r   r   r  r  h  s1    
 "J
!!%NJ% $M:$ Iz r   r  script.messagezscript.realmCreatedzscript.realmDestroyed)messagerealm_createdrealm_destroyedc                     e Zd ZU dZi Zded<   d#d$dZ	 	 	 	 	 d%	 	 	 	 	 	 	 	 	 d&dZd'd(dZ	 	 	 	 	 	 	 	 d)	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d*dZ		 	 	 	 	 	 d+	 	 	 	 	 	 	 	 	 	 	 d,d	Z
d'd-d
Zd#d.dZddd/dZ	 	 	 	 d0dZd Zd Zd Z	 	 	 d1dZ	 	 	 	 	 d%dZd'dZd Zd#dZd Zd2dZd3dZd2dZd3dZd Zd Zd2dZd3dZd#d4d Z d5d!Z!d$d"Z"y)6ScriptzWebDriver BiDi script module.zdict[str, EventConfig]EVENT_CONFIGSNc                V    || _         || _        t        || j                        | _        y N)_conn_driverr   r)  _event_manager)selfconndrivers      r   __init__zScript.__init__  s%    
+D$2D2DEr   c                    |t        d      |||||d}|j                         D ci c]  \  }}|	|| }}}t        d|      }	| j                  j	                  |	      }
|
S c c}}w )zExecute script.addPreloadScriptzFadd_preload_script() missing required argument: 'function_declaration')functionDeclarationr   r   userContextsr   zscript.addPreloadScript	TypeErroritemsr   r,  execute)r/  r   r   r   r   r   paramskvcmdrG   s              r   add_preload_scriptzScript.add_preload_script  s      'dee $8" )
 $*<<>C41aQ]!Q$CC7@##C( Ds
   
A%A%c                    |t        d      |t        d      ||d}|j                         D ci c]  \  }}|	|| }}}t        d|      }| j                  j	                  |      }|S c c}}w )zExecute script.disownz-disown() missing required argument: 'handles'z,disown() missing required argument: 'target'r  r  zscript.disownr6  )r/  r  r  r:  r;  r<  r=  rG   s           r   disownzScript.disown  s    ?KLL>JKK 
 $*<<>C41aQ]!Q$CCov6##C( Ds
   
A/A/c	           	        |t        d      |t        d      |t        d      ||||||||d}	|	j                         D 
ci c]  \  }
}|	|
| }	}
}t        d|	      }| j                  j	                  |      }|S c c}}
w )zExecute script.callFunctionzAcall_function() missing required argument: 'function_declaration'z:call_function() missing required argument: 'await_promise'z3call_function() missing required argument: 'target')r4  awaitPromiser  r   resultOwnershipserializationOptionsr  userActivationzscript.callFunctionr6  )r/  r   r	  r  r   r
  rB   r  r  r:  r;  r<  r=  rG   s                 r   call_functionzScript.call_function  s      '_`` XYY>QRR $8)"/$9-	
 $*<<>C41aQ]!Q$CC3V<##C( Ds   
BBc                   |t        d      |t        d      |t        d      ||||||d}|j                         D 	ci c]  \  }}	|		||	 }}}	t        d|      }
| j                  j	                  |
      }|S c c}	}w )zExecute script.evaluatez2evaluate() missing required argument: 'expression'z.evaluate() missing required argument: 'target'z5evaluate() missing required argument: 'await_promise')r  r  rC  rD  rE  rF  zscript.evaluater6  )r/  r  r  r	  r
  rB   r  r:  r;  r<  r=  rG   s               r   evaluatezScript.evaluate  s     PQQ>LMM STT %)/$9-
 $*<<>C41aQ]!Q$CC/8##C( Ds   
B B c                    ||d}|j                         D ci c]  \  }}|	|| }}}t        d|      }| j                  j                  |      }|S c c}}w )zExecute script.getRealmsr   r;   zscript.getRealms)r8  r   r,  r9  )r/  r   r;   r:  r;  r<  r=  rG   s           r   
get_realmszScript.get_realms  sd     
 $*<<>C41aQ]!Q$CC0&9##C( Ds
   
AAc                    |t        d      d|i}|j                         D ci c]  \  }}|	|| }}}t        d|      }| j                  j	                  |      }|S c c}}w )z"Execute script.removePreloadScriptz;remove_preload_script() missing required argument: 'script'r  zscript.removePreloadScriptr6  )r/  r  r:  r;  r<  r=  rG   s          r   remove_preload_scriptzScript.remove_preload_script  st    >YZZ f
 $*<<>C41aQ]!Q$CC:FC##C( Ds
   
A!A!)
context_idc               H   ddl ddlddlm} fd|#| j                  	 | j                  j
                  }|rd|ini }|r|D cg c]
  } |       c}nd}| j                  |d||      }t        |t              r|j                  d      d	k(  rP|j                  d
i       }	t        |	t              r|	j                  dt        |	            n
t        |	      }
 ||
      |j                  d      dk(  r|j                  d      S |S # t        $ r Y w xY wc c}w )a  Execute a function declaration in the browser context.

        Args:
            function_declaration: The function as a string, e.g. ``"() => document.title"``.
            *args: Optional Python values to pass as arguments to the function.
                Each value is serialised to a BiDi ``LocalValue`` automatically.
                Supported types: ``None``, ``bool``, ``int``, ``float``
                (including ``NaN`` and ``Infinity``), ``str``, ``list``,
                ``dict``, and ``datetime.datetime``.
            context_id: The browsing context ID to run in. Defaults to the
                driver's current window handle when a driver was provided.

        Returns:
            The inner RemoteValue result dict, or raises WebDriverException on exception.
        r   N)WebDriverExceptionc           	        | ddiS t        | t              rd| dS t        | j                        rd| j                         dS t        | t              r:j                  |       rdddS j                  |       rd| dkD  rd	dS d
dS d| dS t        | t              r#d}t        |       |kD  rdt        |       dS d| dS t        | t              rd| dS t        | t              rd| D cg c]
  } |       c}dS t        | t              r7d| j                         D cg c]  \  }}t        |       |      g c}}dS | S c c}w c c}}w )z3Serialise a Python value to a BiDi LocalValue dict.r;   rr   r|   r;   r=   rY   ry   r   r   r   r   l    r   ru   rV   r`   )
isinstancebooldatetime	isoformatfloatisnanisinfintabsr:   r   dictr8  )r=   _MAX_SAFE_INTr<  r;  	_datetime_math_serialize_args       r   ra  z&Script.execute.<locals>._serialize_arg   sX   }''%& )E::%!3!34 &1BCC%';;u%$,u==;;u%$,UQYz``T_`` (599%% 0u:-$,s5zBB (599%% (599%& 'e2T>!3D2TUU%& (\a\g\g\i3jTXTUWXSV^A=N4O3jkkL 3U3js   -E
%Er   T)r   r	  r  r   r;   rK   exceptionDetailsrS   rF   rG   )mathrV  selenium.common.exceptionsrQ  r-  current_window_handle	ExceptionrG  rT  r]  getr:   )r/  r   rO  args_WebDriverExceptionr  aserialized_argsrawexcmsgr_  r`  ra  s              @@@r   r9  zScript.execute  s     	$X	6 $,,":!\\??
 -7)Z(B?Cd;>!,;  !5%	 ! 
 c4 wwv+-gg0"53=c43Hcggfc#h/cRUh)#..wwv)+wwx((
#   <s   D D	DDc                    ||t        d      | j                  |||||      }t        |t              r|j	                  d      S |S )a  Add a preload script with validation.

        Args:
            function_declaration: The JS function to run on page load.
            arguments: Optional list of BiDi arguments.
            contexts: Optional list of browsing context IDs.
            user_contexts: Optional list of user context IDs.
            sandbox: Optional sandbox name.

        Returns:
            script_id: The ID of the added preload script (str).

        Raises:
            ValueError: If both contexts and user_contexts are specified.
        z.Cannot specify both contexts and user_contexts)r   r   r   r   r   r  )
ValueErrorr>  rT  r]  rg  )r/  r   r   r   r   r   rG   s          r   _add_preload_scriptzScript._add_preload_scriptP  s_    . M$=MNN((!5' ) 
 fd#::h''r   c                &    | j                  |      S )zuRemove a preload script by ID.

        Args:
            script_id: The ID of the preload script to remove.
        )r  )rN  r/  	script_ids     r   _remove_preload_scriptzScript._remove_preload_scripts  s     )));;r   c                $    | j                  |      S )zPin (add) a preload script that runs on every page load.

        Args:
            function_declaration: The JS function to execute on page load.

        Returns:
            script_id: The ID of the pinned script (str).
        )rq  )r/  r   s     r   pinz
Script.pinz  s     ''(<==r   c                &    | j                  |      S )z{Unpin (remove) a previously pinned preload script.

        Args:
            script_id: The ID returned by pin().
        )rt  )ru  rs  s     r   unpinzScript.unpin  s     **Y*??r   c                0    G d d      }| j                  ||||||      }t        |t              r[|j                  d      }	|j                  d      dk(  r|j                  d      }
 ||	d|
	      S  ||	|j                  d
      d	      S  |d|d	      S )aM  Evaluate a script expression and return a structured result.

        Args:
            expression: The JavaScript expression to evaluate.
            target: A dict like {"context": <id>} or {"realm": <id>}.
            await_promise: Whether to await a returned promise.
            result_ownership: Optional result ownership setting.
            serialization_options: Optional serialization options dict.
            user_activation: Optional user activation flag.

        Returns:
            An object with .realm, .result (dict or None), and .exception_details (or None).
        c                      e Zd Zd Zy)%Script._evaluate.<locals>._EvalResultc                .    || _         || _        || _        y r+  rH   rG   rL   )self2rH   rG   rL   s       r   r2  z.Script._evaluate.<locals>._EvalResult.__init__  s    #%*;'r   Nr   r   r   r2  r   r   r   _EvalResultr|    s    <r   r  )r  r  r	  r
  rB   r  rH   r;   rK   rb  Nr~  rG   )rI  rT  r]  rg  )r/  r  r  r	  r
  rB   r  r  rl  rH   rm  s              r   	_evaluatezScript._evaluate  s    ,	< 	< mm!'-"7+  
 c4 GGG$Ewwv+-gg01"tsSSU37783DX\]]cTJJr   c	           
     4    G d d      }	| j                  ||||||||      }
t        |
t              r\|
j                  d      dk(  r|
j                  d      } |	d|      S |
j                  d      d	k(  r |	|
j                  d
      d      S  |	|
d      S )ax  Call a function and return a structured result.

        Args:
            function_declaration: The JS function string.
            await_promise: Whether to await the return value.
            target: A dict like {"context": <id>}.
            arguments: Optional list of BiDi arguments.
            result_ownership: Optional result ownership.
            this: Optional 'this' binding.
            user_activation: Optional user activation flag.
            serialization_options: Optional serialization options dict.

        Returns:
            An object with .result (dict or None) and .exception_details (or None).
        c                      e Zd Zd Zy)*Script._call_function.<locals>._CallResultc                     || _         || _        y r+  rG   rL   )r  rG   rL   s      r   r2  z3Script._call_function.<locals>._CallResult.__init__  s    %*;'r   Nr  r   r   r   _CallResultr    s    <r   r  )r   r	  r  r   r
  r  r  rB   r;   rK   rb  Nr  rF   rG   )rG  rT  r]  rg  )r/  r   r	  r  r   r
  r  r  rB   r  rl  rm  s               r   _call_functionzScript._call_function  s    4	< 	<
   !5'-+"7 ! 	
 c4 wwv+-gg01"$#FFwwv)+"#''(*;tTT#>>r   c                j    G d d      }| j                  ||      }t        |t              r|j                  dg       ng }g }|D ]j  }t        |t              s|j	                   ||j                  d      |j                  d      |j                  d      |j                  d      	             l |S )
aN  Get all realms, optionally filtered by context and type.

        Args:
            context: Optional browsing context ID to filter by.
            type: Optional realm type string to filter by (e.g. RealmType.WINDOW).

        Returns:
            List of realm info objects with .realm, .origin, .type, .context attributes.
        c                      e Zd Zd Zy)&Script._get_realms.<locals>._RealmInfoc                <    || _         || _        || _        || _        y r+  )rH   r   r;   r   )r  rH   r   type_r   s        r   r2  z/Script._get_realms.<locals>._RealmInfo.__init__  s    #%"
 'r   Nr  r   r   r   
_RealmInfor    s    (r   r  rK  r  rH   r   r;   r   )rH   r   r  r   )rL  rT  r]  rg  append)r/  r   r;   r  rl  realms_listrG   rs           r   _get_realmszScript._get_realms  s    	( 	( oogDo9/9#t/Dcggh+" 	A!T"j%%.55?%%-EE),	 	 r   c                (    | j                  ||      S )zDisown handles in a browsing context.

        Args:
            handles: List of handle strings to disown.
            target: A dict like {"context": <id>}.
        r@  )rA  )r/  r  r  s      r   _disownzScript._disown  s     {{76{::r   c                N   ddl }ddlm} ddlm dt        | d      si | _        |j                         | _        fdfd} G fd	d
      } |       }| j                  j                  ||      }| j                  5  | j                  vrY || j                        }	|	j                  g      }
t        |
t              r|
j                  d      nd}g |d| j                  <   | j                     d   j                  |       ddd       |S # 1 sw Y   |S xY w)zESubscribe to log.entryAdded BiDi events with optional type filtering.r   NSession)loglog.entryAdded_log_subscriptionsc                Z   t        | t              r| j                  d      nd }|dk(  r/t        dd       }|t	        |d      r	 |j                  |       S | S |dk(  r-t        dd       }|t	        |d      r	 |j                  |       S | S # t        $ r Y | S w xY w# t        $ r Y | S w xY w)Nr;   consoleConsoleLogEntry	from_json
javascriptJavascriptLogEntry)rT  r]  rg  getattrhasattrr  rf  )r:  tcls_log_mods      r   _deserializez1Script._subscribe_log_entry.<locals>._deserialize  s    &0&>

6"DAI~h(94@?wsK'@"}}V44 M l"h(<dC?wsK'@"}}V44 M %  M % Ms$   B :B 	BB	B*)B*c                     |       }	 |       y t        |dd       xs# t        |t              r|j                  d      nd }|k(  r	 |       y y )Nr  r;   )r  rT  r]  rg  )rl  entryr  r  callbackentry_type_filters      r   _wrappedz-Script._subscribe_log_entry.<locals>._wrapped)  s^     %E (E7D1 )3E4)@EIIf%d  ))UO *r   c                      e Zd ZW  Zd Zy)-Script._subscribe_log_entry.<locals>._BidiRefc                    |S r+  r   r  ps     r   r  z7Script._subscribe_log_entry.<locals>._BidiRef.from_json7      r   Nr   r   r   event_classr  
bidi_events   r   _BidiRefr  4      $Kr   r  subscription	callbackssubscription_idr  )	threading&selenium.webdriver.common.bidi.sessionr  selenium.webdriver.common.bidir  r  r  Lock	_log_lockr,  add_callback	subscriberT  r]  rg  r  )r/  r  r  
_threading_Sessionr  r  _wrappercallback_idsessionrG   sub_idr  r  r  s    ``         @@@r   _subscribe_log_entryzScript._subscribe_log_entry  s   &NB%
t12&(D#'__.DN	$		$	 	 :jj--hA^^ 	Q!8!88"4::. **J<82<VT2JFJJ~.PT  "$'-7''
3 ##J/<CCKP	Q 	Q s   B	DD$c                    ddl m} dt        | d      sy G fdd      } |       }| j                  j	                  ||       | j
                  5  | j                  j                        }|r||d   v r|d   j                  |       |^|d   sY || j                        }|j                  d	      }|r|j                  |g
       n|j                  g       | j                  = ddd       y# 1 sw Y   yxY w)z'Unsubscribe a log entry callback by ID.r   r  r  r  Nc                      e Zd ZW  Zd Zy)/Script._unsubscribe_log_entry.<locals>._BidiRefc                    |S r+  r   r  s     r   r  z9Script._unsubscribe_log_entry.<locals>._BidiRef.from_jsonT  r  r   Nr  r  s   r   r  r  Q  r  r   r  r  r  subscriptionsevents)
r  r  r  r,  remove_callbackr  r  rg  removeunsubscribe)	r/  r  r  r  r  r  r  r  r  s	           @r   _unsubscribe_log_entryzScript._unsubscribe_log_entryI  s    N%
t12	 	 :

""8[9^^ 	8++//
;Ek(::k"))+6 {);"4::.#45''vh'?''
|'<++J7	8 	8 	8s   BC44C=c                (    | j                  |d      S )a
  Add a handler for console log messages (log.entryAdded type=console).

        Args:
            callback: Function called with a ConsoleLogEntry on each console message.

        Returns:
            callback_id for use with remove_console_message_handler.
        r  r  r  r/  r  s     r   add_console_message_handlerz"Script.add_console_message_handlere  s     ((Y(OOr   c                &    | j                  |       y)z0Remove a console message handler by callback ID.Nr  r/  r  s     r   remove_console_message_handlerz%Script.remove_console_message_handlero      ##K0r   c                (    | j                  |d      S )a  Add a handler for JavaScript error log messages (log.entryAdded type=javascript).

        Args:
            callback: Function called with a JavascriptLogEntry on each JS error.

        Returns:
            callback_id for use with remove_javascript_error_handler.
        r  r  r  r  s     r   add_javascript_error_handlerz#Script.add_javascript_error_handlerr  s     ((\(RRr   c                &    | j                  |       y)z1Remove a JavaScript error handler by callback ID.Nr  r  s     r   remove_javascript_error_handlerz&Script.remove_javascript_error_handler|  r  r   c                   ddl ddl}ddl}ddlm} dt        | d      si | _        |j                         | _        t        | d      sEd}|j                  |d      }|t        d	      |j                  d
      j                         | _        t        | d      s&ddl}d|j                         j                    | _        | j"                  ddid}fd}	 G fdd      }
| j                  5  t        | d      sl| j%                  | j                  |g      | _        | j(                  =d}	 | j(                  j*                  }|"| j/                  | j                  d|id|g       | j                  vrY || j0                        }|j3                  g      }t5        |t6              r|j9                  d      nd}g |d| j                  <    |
       }| j0                  j;                  ||	      }| j                     d   j=                  |       ddd       |S # t,        $ r Y w xY w# 1 sw Y   S xY w)a%  Subscribe to DOM mutation events using a BiDi preload script and script.message channel.

        Loads bidi-mutation-listener.js as a preload script with a channel argument,
        then subscribes to script.message events from that channel to detect
        DOM attribute mutations.
        r   Nr  r#  _mutation_subscriptions_bidi_mutation_listener_jszselenium.webdriver.commonzbidi-mutation-listener.jsz(Failed to load bidi-mutation-listener.jsutf8_mutation_channel_namezselenium.domMutation.r6   rS  c                   t        | t              r| j                  d      nd }|k7  ry t        | t              r| j                  di       ni }t        |t              r|j                  d      nd }|y 	 	j                  |      }|j                  d      }|s|dk7  ry ddlm}  |t        |      |j                  d      |j                  d      |j                  d      	      } 
|       y # t        t
        f$ r Y y w xY w)
Nr6   r  r=   r  r   )r  nameoldValue)r  r   r!  r"  )	rT  r]  rg  loadsrp  r7  %selenium.webdriver.common.bidi.scriptr  r:   )r$  r6   r  r=   payload	target_id_DomMutationevent_channel_name_jsonr  s           r   _on_messagez7Script._subscribe_mutation_handler.<locals>._on_message  s    0:7D0Igkk),tG-'.8$.G7;;vr*RD)3D$)?DHHW%TE}++e,  H-IaY y>&{{62%kk'2!++j1	E UO 	* s   6C1 1DDc                      e Zd ZW  Zd Zy)4Script._subscribe_mutation_handler.<locals>._BidiRefc                    |S r+  r   r  s     r   r  z>Script._subscribe_mutation_handler.<locals>._BidiRef.from_json  r  r   Nr  r  s   r   r  r    r  r   r  _mutation_preload_script_id)r   r   F)r   r  r	  r   r  r  r  )jsonpkgutilr  r  r  r  r  r  _mutation_lockget_datarp  decodestripr  uuiduuid4hexr  rq  r  r-  re  rf  rG  r,  r  rT  r]  rg  r  r  )r/  r  _pkgutilr  r  _pkg	_js_bytes_uuid_channel_argr  r  _contextr  rG   r  r  r  r  r  r  s    `               @@@r   _subscribe_mutation_handlerz"Script._subscribe_mutation_handler  sU    	"&N%
t67+-D(",//"3D t9:.D ))$0KLI  !KLL.7.>.>v.F.L.L.ND+ t56 ,A%++-BSBSAT*UD'33 )Y4NO	2	 	    #	V 4!>?373K3K33~ 4L 40
 <<+#H#'<<#E#E  +**151P1P$-x#8*/'3n	 +  !=!=="4::. **J<82<VT2JFJJ~.PT  "$'-<,,Z8
  zH**11(KHK((4[AHHUG#	VH / % #	VH s1   6>H35H$CH3$	H0-H3/H00H33H=c                f  	 ddl m} d	t        | d      sy G 	fdd      } |       }| j                  j	                  ||       | j
                  5  | j                  j                  	      }|r||d   v r|d   j                  |       ||d   s || j                        }|j                  d	      }|r|j                  |g
       n|j                  	g       | j                  	= t        | d      r | j                  }	 | j                  |       | `
ddd       y# | `
w xY w# 1 sw Y   yxY w)z2Unsubscribe a DOM mutation handler by callback ID.r   r  r#  r  Nc                      e Zd ZW  Zd Zy)6Script._unsubscribe_mutation_handler.<locals>._BidiRefc                    |S r+  r   r  s     r   r  z@Script._unsubscribe_mutation_handler.<locals>._BidiRef.from_json  r  r   Nr  r  s   r   r  r    r  r   r  r  r  r  r  r  )r  r  r  r,  r  r  r  rg  r  r  r  ru  )
r/  r  r  r  r  r  r  r  preload_script_idr  s
            @r   _unsubscribe_mutation_handlerz$Script._unsubscribe_mutation_handler  s7   N%
t67	 	 :

""8[9   	=0044Z@Ek(::k"))+6 {);"4::.#45''vh'?''
|'<00<4!>?(,(H(H%=334EF <#	= 	=" !<#	= 	=s%   B1D'D D' D$$D''D0c                $    | j                  |      S )a  Add a handler for DOM attribute mutation events.

        Uses a BiDi preload script and channel to observe DOM attribute mutations
        on the page. When an attribute changes, the callback is invoked with a
        ``DomMutation`` object describing the element and attribute change.

        Args:
            callback: Function called with a ``DomMutation`` on each attribute mutation.

        Returns:
            callback_id for use with remove_dom_mutation_handler.
        )r	  r  s     r   add_dom_mutation_handlerzScript.add_dom_mutation_handler  s     //99r   c                &    | j                  |       y)z-Remove a DOM mutation handler by callback ID.N)r  r  s     r   remove_dom_mutation_handlerz"Script.remove_dom_mutation_handler  s    **;7r   c                <    | j                   j                  |||      S )a  Add an event handler.

        Args:
            event: The event to subscribe to.
            callback: The callback function to execute on event.
            contexts: The context IDs to subscribe to (optional).

        Returns:
            The callback ID.
        )r.  add_event_handler)r/  r  r  r   s       r   r  zScript.add_event_handler  s     ""44UHhOOr   c                :    | j                   j                  ||      S )zRemove an event handler.

        Args:
            event: The event to unsubscribe from.
            callback_id: The callback ID.
        )r.  remove_event_handler)r/  r  r  s      r   r  zScript.remove_event_handler%  s     ""77{KKr   c                6    | j                   j                         S )zClear all event handlers.)r.  clear_event_handlers)r/  s    r   r  zScript.clear_event_handlers.  s    ""7799r   r+  )returnNone)NNNNN)
r   r<   r   list[Any] | Noner   r  r   r  r   r<   )NN)r  r  r  r<   )NNNNNNNN)r   r<   r	  r}   r  r<   r   r  r
  r<   rB   r<   r  r<   r  r}   )NNNNNN)r  r<   r  r<   r	  r}   r
  r<   rB   r<   r  r}   )r   r<   r;   r<   )r  r<   )r   r:   rO  rR   r  r   )NNNN)NNN)r  r   r  r[  )r  r[  r  r  )r  r:   r  r   r   zlist[str] | Noner  r[  )r  r:   r  r[  r  r  )#r   r   r   r   r)  r?   r2  r>  rA  rG  rI  rL  rN  r9  rq  ru  rw  ry  r  r  r  r  r  r  r  r  r  r  r	  r  r  r  r  r  r  r   r   r   r(  r(    s   ',.M).F ,0&*%)*."( $ #	
 ( 0$ ,0%)!&*'+,0'+ (  #  	 
 $  %   *    % H "&!%)'+,0'+  #	
 %  * %<	 RV CN "F<	>@ "*K` "/?`:;=|88	P1	S1dJ!=D:8PL:r   r(  	RealmInfor$  Messager%  RealmCreatedr&  RealmDestroyedN)_
__future__r   collections.abcr   dataclassesr   r   typingr   %selenium.webdriver.common.bidi.commonr   -selenium.webdriver.common.bidi._event_managerr	   r
   r   r   r   r/   r5   rA   rE   rJ   rN   rU   rX   r[   r_   rc   rg   rj   rm   rq   rt   rx   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r  r  EVENT_NAME_MAPPINGr(  globalsrg  r]  r  r  r   _globalsr)  r   r   r   <module>r*     s   # $ (  A c c 
 
     ! ! !                               7 7 7 2 2 2                   4 4 4 ; ; ; < < < 4 4 4 ; ; ; ; ; ; 5 5 5    ! ! ! # # #       # # # # # # # # #       # # # # # # # # # # # # # # # # # # # # # # # #          
# 
# 
# # # #       9 9 9 $ $ $                
( 
( 
( ( ( (    4 4 4          ! ! !*  *. m
: m
:b )--+T
2 y}}[$/ 94@ 9)1i)@Y%d
 !.6ll>.J^T*PT
 #08=M0N%t,TX r   