@browserbasehq/orca 3.5.0-vertex-test → 3.6.0-gemini-cua

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (290) hide show
  1. package/README.md +7 -15
  2. package/dist/cjs/lib/utils.d.ts +8 -0
  3. package/dist/cjs/lib/utils.js +31 -0
  4. package/dist/cjs/lib/utils.js.map +1 -1
  5. package/dist/cjs/lib/v3/agent/AgentProvider.js +5 -3
  6. package/dist/cjs/lib/v3/agent/AgentProvider.js.map +1 -1
  7. package/dist/cjs/lib/v3/agent/AnthropicCUAClient.js +10 -8
  8. package/dist/cjs/lib/v3/agent/AnthropicCUAClient.js.map +1 -1
  9. package/dist/cjs/lib/v3/agent/GoogleCUAClient.js +124 -28
  10. package/dist/cjs/lib/v3/agent/GoogleCUAClient.js.map +1 -1
  11. package/dist/cjs/lib/v3/agent/utils/captureAriaTreeProbe.d.ts +35 -0
  12. package/dist/cjs/lib/v3/agent/utils/captureAriaTreeProbe.js +38 -0
  13. package/dist/cjs/lib/v3/agent/utils/captureAriaTreeProbe.js.map +1 -0
  14. package/dist/cjs/lib/v3/agent/utils/handleDoneToolCall.js +10 -1
  15. package/dist/cjs/lib/v3/agent/utils/handleDoneToolCall.js.map +1 -1
  16. package/dist/cjs/lib/v3/agent/utils/postStepProbeEvidence.d.ts +19 -0
  17. package/dist/cjs/lib/v3/agent/utils/postStepProbeEvidence.js +54 -0
  18. package/dist/cjs/lib/v3/agent/utils/postStepProbeEvidence.js.map +1 -0
  19. package/dist/cjs/lib/v3/agent/utils/toolOutputEvidence.d.ts +2 -0
  20. package/dist/cjs/lib/v3/agent/utils/toolOutputEvidence.js +62 -0
  21. package/dist/cjs/lib/v3/agent/utils/toolOutputEvidence.js.map +1 -0
  22. package/dist/cjs/lib/v3/agent/utils/wrapEvidenceCallback.d.ts +3 -0
  23. package/dist/cjs/lib/v3/agent/utils/wrapEvidenceCallback.js +25 -0
  24. package/dist/cjs/lib/v3/agent/utils/wrapEvidenceCallback.js.map +1 -0
  25. package/dist/cjs/lib/v3/api.d.ts +1 -0
  26. package/dist/cjs/lib/v3/api.js +37 -16
  27. package/dist/cjs/lib/v3/api.js.map +1 -1
  28. package/dist/cjs/lib/v3/cache/ActCache.js +1 -1
  29. package/dist/cjs/lib/v3/cache/ActCache.js.map +1 -1
  30. package/dist/cjs/lib/v3/cache/utils.d.ts +7 -0
  31. package/dist/cjs/lib/v3/cache/utils.js +19 -0
  32. package/dist/cjs/lib/v3/cache/utils.js.map +1 -1
  33. package/dist/cjs/lib/v3/dom/build/locatorScripts.generated.d.ts +24 -24
  34. package/dist/cjs/lib/v3/dom/build/locatorScripts.generated.js +24 -24
  35. package/dist/cjs/lib/v3/dom/build/locatorScripts.generated.js.map +1 -1
  36. package/dist/cjs/lib/v3/dom/locatorScripts/xpathResolver.js +79 -10
  37. package/dist/cjs/lib/v3/dom/locatorScripts/xpathResolver.js.map +1 -1
  38. package/dist/cjs/lib/v3/handlers/v3AgentHandler.d.ts +3 -1
  39. package/dist/cjs/lib/v3/handlers/v3AgentHandler.js +108 -16
  40. package/dist/cjs/lib/v3/handlers/v3AgentHandler.js.map +1 -1
  41. package/dist/cjs/lib/v3/handlers/v3CuaAgentHandler.d.ts +11 -0
  42. package/dist/cjs/lib/v3/handlers/v3CuaAgentHandler.js +119 -5
  43. package/dist/cjs/lib/v3/handlers/v3CuaAgentHandler.js.map +1 -1
  44. package/dist/cjs/lib/v3/index.d.ts +13 -1
  45. package/dist/cjs/lib/v3/index.js +19 -1
  46. package/dist/cjs/lib/v3/index.js.map +1 -1
  47. package/dist/cjs/lib/v3/launch/local.js +1 -0
  48. package/dist/cjs/lib/v3/launch/local.js.map +1 -1
  49. package/dist/cjs/lib/v3/llm/LLMProvider.d.ts +3 -0
  50. package/dist/cjs/lib/v3/llm/LLMProvider.js +45 -3
  51. package/dist/cjs/lib/v3/llm/LLMProvider.js.map +1 -1
  52. package/dist/cjs/lib/v3/llm/aisdk.js +4 -0
  53. package/dist/cjs/lib/v3/llm/aisdk.js.map +1 -1
  54. package/dist/cjs/lib/v3/llm/anthropicOptions.d.ts +57 -0
  55. package/dist/cjs/lib/v3/llm/anthropicOptions.js +115 -0
  56. package/dist/cjs/lib/v3/llm/anthropicOptions.js.map +1 -0
  57. package/dist/cjs/lib/v3/types/public/agent.d.ts +8 -2
  58. package/dist/cjs/lib/v3/types/public/agent.js +3 -0
  59. package/dist/cjs/lib/v3/types/public/agent.js.map +1 -1
  60. package/dist/cjs/lib/v3/types/public/agentEvidenceEvents.d.ts +85 -0
  61. package/dist/cjs/lib/v3/types/public/agentEvidenceEvents.js +15 -0
  62. package/dist/cjs/lib/v3/types/public/agentEvidenceEvents.js.map +1 -0
  63. package/dist/cjs/lib/v3/types/public/api.d.ts +925 -182
  64. package/dist/cjs/lib/v3/types/public/api.js +138 -20
  65. package/dist/cjs/lib/v3/types/public/api.js.map +1 -1
  66. package/dist/cjs/lib/v3/types/public/clipboard.d.ts +15 -0
  67. package/dist/cjs/lib/v3/types/public/clipboard.js +3 -0
  68. package/dist/cjs/lib/v3/types/public/clipboard.js.map +1 -0
  69. package/dist/cjs/lib/v3/types/public/index.d.ts +2 -0
  70. package/dist/cjs/lib/v3/types/public/index.js +2 -0
  71. package/dist/cjs/lib/v3/types/public/index.js.map +1 -1
  72. package/dist/cjs/lib/v3/types/public/model.d.ts +33 -8
  73. package/dist/cjs/lib/v3/types/public/model.js.map +1 -1
  74. package/dist/cjs/lib/v3/types/public/page.d.ts +29 -0
  75. package/dist/cjs/lib/v3/types/public/page.js.map +1 -1
  76. package/dist/cjs/lib/v3/types/public/sdkErrors.d.ts +3 -0
  77. package/dist/cjs/lib/v3/types/public/sdkErrors.js +8 -2
  78. package/dist/cjs/lib/v3/types/public/sdkErrors.js.map +1 -1
  79. package/dist/cjs/lib/v3/understudy/clipboard.d.ts +24 -0
  80. package/dist/cjs/lib/v3/understudy/clipboard.js +166 -0
  81. package/dist/cjs/lib/v3/understudy/clipboard.js.map +1 -0
  82. package/dist/cjs/lib/v3/understudy/context.d.ts +3 -0
  83. package/dist/cjs/lib/v3/understudy/context.js +15 -0
  84. package/dist/cjs/lib/v3/understudy/context.js.map +1 -1
  85. package/dist/cjs/lib/v3/understudy/page.d.ts +23 -1
  86. package/dist/cjs/lib/v3/understudy/page.js +283 -0
  87. package/dist/cjs/lib/v3/understudy/page.js.map +1 -1
  88. package/dist/cjs/lib/v3/v3.js +19 -7
  89. package/dist/cjs/lib/v3/v3.js.map +1 -1
  90. package/dist/cjs/lib/v3/verifier/errorTaxonomy.d.ts +35 -0
  91. package/dist/cjs/lib/v3/verifier/errorTaxonomy.js +291 -0
  92. package/dist/cjs/lib/v3/verifier/errorTaxonomy.js.map +1 -0
  93. package/dist/cjs/lib/v3/verifier/evidence.d.ts +44 -0
  94. package/dist/cjs/lib/v3/verifier/evidence.js +432 -0
  95. package/dist/cjs/lib/v3/verifier/evidence.js.map +1 -0
  96. package/dist/cjs/lib/v3/verifier/evidenceNormalization.d.ts +7 -0
  97. package/dist/cjs/lib/v3/verifier/evidenceNormalization.js +100 -0
  98. package/dist/cjs/lib/v3/verifier/evidenceNormalization.js.map +1 -0
  99. package/dist/cjs/lib/v3/verifier/index.d.ts +6 -0
  100. package/dist/cjs/lib/v3/verifier/index.js +16 -0
  101. package/dist/cjs/lib/v3/verifier/index.js.map +1 -0
  102. package/dist/cjs/lib/v3/verifier/prompts/batchedRelevance.d.ts +21 -0
  103. package/dist/cjs/lib/v3/verifier/prompts/batchedRelevance.js +71 -0
  104. package/dist/cjs/lib/v3/verifier/prompts/batchedRelevance.js.map +1 -0
  105. package/dist/cjs/lib/v3/verifier/prompts/firstPointOfFailure.d.ts +3 -0
  106. package/dist/cjs/lib/v3/verifier/prompts/firstPointOfFailure.js +166 -0
  107. package/dist/cjs/lib/v3/verifier/prompts/firstPointOfFailure.js.map +1 -0
  108. package/dist/cjs/lib/v3/verifier/prompts/fusedJudgment.d.ts +35 -0
  109. package/dist/cjs/lib/v3/verifier/prompts/fusedJudgment.js +158 -0
  110. package/dist/cjs/lib/v3/verifier/prompts/fusedJudgment.js.map +1 -0
  111. package/dist/cjs/lib/v3/verifier/prompts/fusedOutcome.d.ts +26 -0
  112. package/dist/cjs/lib/v3/verifier/prompts/fusedOutcome.js +137 -0
  113. package/dist/cjs/lib/v3/verifier/prompts/fusedOutcome.js.map +1 -0
  114. package/dist/cjs/lib/v3/verifier/prompts/index.d.ts +8 -0
  115. package/dist/cjs/lib/v3/verifier/prompts/index.js +22 -0
  116. package/dist/cjs/lib/v3/verifier/prompts/index.js.map +1 -0
  117. package/dist/cjs/lib/v3/verifier/prompts/perCriterionScore.d.ts +23 -0
  118. package/dist/cjs/lib/v3/verifier/prompts/perCriterionScore.js +77 -0
  119. package/dist/cjs/lib/v3/verifier/prompts/perCriterionScore.js.map +1 -0
  120. package/dist/cjs/lib/v3/verifier/prompts/render.d.ts +23 -0
  121. package/dist/cjs/lib/v3/verifier/prompts/render.js +45 -0
  122. package/dist/cjs/lib/v3/verifier/prompts/render.js.map +1 -0
  123. package/dist/cjs/lib/v3/verifier/prompts/rubricGeneration.d.ts +16 -0
  124. package/dist/cjs/lib/v3/verifier/prompts/rubricGeneration.js +321 -0
  125. package/dist/cjs/lib/v3/verifier/prompts/rubricGeneration.js.map +1 -0
  126. package/dist/cjs/lib/v3/verifier/prompts/taskValidity.d.ts +1 -0
  127. package/dist/cjs/lib/v3/verifier/prompts/taskValidity.js +116 -0
  128. package/dist/cjs/lib/v3/verifier/prompts/taskValidity.js.map +1 -0
  129. package/dist/cjs/lib/v3/verifier/rubricVerifier.d.ts +91 -0
  130. package/dist/cjs/lib/v3/verifier/rubricVerifier.js +1645 -0
  131. package/dist/cjs/lib/v3/verifier/rubricVerifier.js.map +1 -0
  132. package/dist/cjs/lib/v3/verifier/trajectory.d.ts +50 -0
  133. package/dist/cjs/lib/v3/verifier/trajectory.js +316 -0
  134. package/dist/cjs/lib/v3/verifier/trajectory.js.map +1 -0
  135. package/dist/cjs/lib/v3/verifier/types.d.ts +429 -0
  136. package/dist/cjs/lib/v3/verifier/types.js +3 -0
  137. package/dist/cjs/lib/v3/verifier/types.js.map +1 -0
  138. package/dist/cjs/lib/v3Evaluator.d.ts +14 -4
  139. package/dist/cjs/lib/v3Evaluator.js +189 -1
  140. package/dist/cjs/lib/v3Evaluator.js.map +1 -1
  141. package/dist/cjs/lib/v3LegacyEvaluator.js +5 -1
  142. package/dist/cjs/lib/v3LegacyEvaluator.js.map +1 -1
  143. package/dist/cjs/lib/version.d.ts +1 -1
  144. package/dist/cjs/lib/version.js +1 -1
  145. package/dist/cjs/lib/version.js.map +1 -1
  146. package/dist/esm/lib/utils.d.ts +8 -0
  147. package/dist/esm/lib/utils.js +28 -0
  148. package/dist/esm/lib/utils.js.map +1 -1
  149. package/dist/esm/lib/v3/agent/AgentProvider.js +5 -3
  150. package/dist/esm/lib/v3/agent/AgentProvider.js.map +1 -1
  151. package/dist/esm/lib/v3/agent/AnthropicCUAClient.js +10 -8
  152. package/dist/esm/lib/v3/agent/AnthropicCUAClient.js.map +1 -1
  153. package/dist/esm/lib/v3/agent/GoogleCUAClient.js +124 -28
  154. package/dist/esm/lib/v3/agent/GoogleCUAClient.js.map +1 -1
  155. package/dist/esm/lib/v3/agent/utils/captureAriaTreeProbe.d.ts +35 -0
  156. package/dist/esm/lib/v3/agent/utils/captureAriaTreeProbe.js +35 -0
  157. package/dist/esm/lib/v3/agent/utils/captureAriaTreeProbe.js.map +1 -0
  158. package/dist/esm/lib/v3/agent/utils/handleDoneToolCall.js +10 -1
  159. package/dist/esm/lib/v3/agent/utils/handleDoneToolCall.js.map +1 -1
  160. package/dist/esm/lib/v3/agent/utils/postStepProbeEvidence.d.ts +19 -0
  161. package/dist/esm/lib/v3/agent/utils/postStepProbeEvidence.js +50 -0
  162. package/dist/esm/lib/v3/agent/utils/postStepProbeEvidence.js.map +1 -0
  163. package/dist/esm/lib/v3/agent/utils/toolOutputEvidence.d.ts +2 -0
  164. package/dist/esm/lib/v3/agent/utils/toolOutputEvidence.js +59 -0
  165. package/dist/esm/lib/v3/agent/utils/toolOutputEvidence.js.map +1 -0
  166. package/dist/esm/lib/v3/agent/utils/wrapEvidenceCallback.d.ts +3 -0
  167. package/dist/esm/lib/v3/agent/utils/wrapEvidenceCallback.js +22 -0
  168. package/dist/esm/lib/v3/agent/utils/wrapEvidenceCallback.js.map +1 -0
  169. package/dist/esm/lib/v3/api.d.ts +1 -0
  170. package/dist/esm/lib/v3/api.js +38 -17
  171. package/dist/esm/lib/v3/api.js.map +1 -1
  172. package/dist/esm/lib/v3/cache/ActCache.js +2 -2
  173. package/dist/esm/lib/v3/cache/ActCache.js.map +1 -1
  174. package/dist/esm/lib/v3/cache/utils.d.ts +7 -0
  175. package/dist/esm/lib/v3/cache/utils.js +18 -0
  176. package/dist/esm/lib/v3/cache/utils.js.map +1 -1
  177. package/dist/esm/lib/v3/dom/build/locatorScripts.generated.d.ts +24 -24
  178. package/dist/esm/lib/v3/dom/build/locatorScripts.generated.js +24 -24
  179. package/dist/esm/lib/v3/dom/build/locatorScripts.generated.js.map +1 -1
  180. package/dist/esm/lib/v3/dom/locatorScripts/xpathResolver.js +79 -10
  181. package/dist/esm/lib/v3/dom/locatorScripts/xpathResolver.js.map +1 -1
  182. package/dist/esm/lib/v3/handlers/v3AgentHandler.d.ts +3 -1
  183. package/dist/esm/lib/v3/handlers/v3AgentHandler.js +108 -16
  184. package/dist/esm/lib/v3/handlers/v3AgentHandler.js.map +1 -1
  185. package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.d.ts +11 -0
  186. package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.js +119 -5
  187. package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.js.map +1 -1
  188. package/dist/esm/lib/v3/index.d.ts +13 -1
  189. package/dist/esm/lib/v3/index.js +10 -0
  190. package/dist/esm/lib/v3/index.js.map +1 -1
  191. package/dist/esm/lib/v3/launch/local.js +1 -0
  192. package/dist/esm/lib/v3/launch/local.js.map +1 -1
  193. package/dist/esm/lib/v3/llm/LLMProvider.d.ts +3 -0
  194. package/dist/esm/lib/v3/llm/LLMProvider.js +44 -3
  195. package/dist/esm/lib/v3/llm/LLMProvider.js.map +1 -1
  196. package/dist/esm/lib/v3/llm/aisdk.js +4 -0
  197. package/dist/esm/lib/v3/llm/aisdk.js.map +1 -1
  198. package/dist/esm/lib/v3/llm/anthropicOptions.d.ts +57 -0
  199. package/dist/esm/lib/v3/llm/anthropicOptions.js +106 -0
  200. package/dist/esm/lib/v3/llm/anthropicOptions.js.map +1 -0
  201. package/dist/esm/lib/v3/types/public/agent.d.ts +8 -2
  202. package/dist/esm/lib/v3/types/public/agent.js +3 -0
  203. package/dist/esm/lib/v3/types/public/agent.js.map +1 -1
  204. package/dist/esm/lib/v3/types/public/agentEvidenceEvents.d.ts +85 -0
  205. package/dist/esm/lib/v3/types/public/agentEvidenceEvents.js +14 -0
  206. package/dist/esm/lib/v3/types/public/agentEvidenceEvents.js.map +1 -0
  207. package/dist/esm/lib/v3/types/public/api.d.ts +925 -182
  208. package/dist/esm/lib/v3/types/public/api.js +136 -18
  209. package/dist/esm/lib/v3/types/public/api.js.map +1 -1
  210. package/dist/esm/lib/v3/types/public/clipboard.d.ts +15 -0
  211. package/dist/esm/lib/v3/types/public/clipboard.js +2 -0
  212. package/dist/esm/lib/v3/types/public/clipboard.js.map +1 -0
  213. package/dist/esm/lib/v3/types/public/index.d.ts +2 -0
  214. package/dist/esm/lib/v3/types/public/index.js +2 -0
  215. package/dist/esm/lib/v3/types/public/index.js.map +1 -1
  216. package/dist/esm/lib/v3/types/public/model.d.ts +33 -8
  217. package/dist/esm/lib/v3/types/public/model.js.map +1 -1
  218. package/dist/esm/lib/v3/types/public/page.d.ts +29 -0
  219. package/dist/esm/lib/v3/types/public/page.js.map +1 -1
  220. package/dist/esm/lib/v3/types/public/sdkErrors.d.ts +3 -0
  221. package/dist/esm/lib/v3/types/public/sdkErrors.js +5 -0
  222. package/dist/esm/lib/v3/types/public/sdkErrors.js.map +1 -1
  223. package/dist/esm/lib/v3/understudy/clipboard.d.ts +24 -0
  224. package/dist/esm/lib/v3/understudy/clipboard.js +163 -0
  225. package/dist/esm/lib/v3/understudy/clipboard.js.map +1 -0
  226. package/dist/esm/lib/v3/understudy/context.d.ts +3 -0
  227. package/dist/esm/lib/v3/understudy/context.js +15 -0
  228. package/dist/esm/lib/v3/understudy/context.js.map +1 -1
  229. package/dist/esm/lib/v3/understudy/page.d.ts +23 -1
  230. package/dist/esm/lib/v3/understudy/page.js +284 -1
  231. package/dist/esm/lib/v3/understudy/page.js.map +1 -1
  232. package/dist/esm/lib/v3/v3.js +20 -8
  233. package/dist/esm/lib/v3/v3.js.map +1 -1
  234. package/dist/esm/lib/v3/verifier/errorTaxonomy.d.ts +35 -0
  235. package/dist/esm/lib/v3/verifier/errorTaxonomy.js +285 -0
  236. package/dist/esm/lib/v3/verifier/errorTaxonomy.js.map +1 -0
  237. package/dist/esm/lib/v3/verifier/evidence.d.ts +44 -0
  238. package/dist/esm/lib/v3/verifier/evidence.js +393 -0
  239. package/dist/esm/lib/v3/verifier/evidence.js.map +1 -0
  240. package/dist/esm/lib/v3/verifier/evidenceNormalization.d.ts +7 -0
  241. package/dist/esm/lib/v3/verifier/evidenceNormalization.js +93 -0
  242. package/dist/esm/lib/v3/verifier/evidenceNormalization.js.map +1 -0
  243. package/dist/esm/lib/v3/verifier/index.d.ts +6 -0
  244. package/dist/esm/lib/v3/verifier/index.js +3 -0
  245. package/dist/esm/lib/v3/verifier/index.js.map +1 -0
  246. package/dist/esm/lib/v3/verifier/prompts/batchedRelevance.d.ts +21 -0
  247. package/dist/esm/lib/v3/verifier/prompts/batchedRelevance.js +68 -0
  248. package/dist/esm/lib/v3/verifier/prompts/batchedRelevance.js.map +1 -0
  249. package/dist/esm/lib/v3/verifier/prompts/firstPointOfFailure.d.ts +3 -0
  250. package/dist/esm/lib/v3/verifier/prompts/firstPointOfFailure.js +162 -0
  251. package/dist/esm/lib/v3/verifier/prompts/firstPointOfFailure.js.map +1 -0
  252. package/dist/esm/lib/v3/verifier/prompts/fusedJudgment.d.ts +35 -0
  253. package/dist/esm/lib/v3/verifier/prompts/fusedJudgment.js +155 -0
  254. package/dist/esm/lib/v3/verifier/prompts/fusedJudgment.js.map +1 -0
  255. package/dist/esm/lib/v3/verifier/prompts/fusedOutcome.d.ts +26 -0
  256. package/dist/esm/lib/v3/verifier/prompts/fusedOutcome.js +134 -0
  257. package/dist/esm/lib/v3/verifier/prompts/fusedOutcome.js.map +1 -0
  258. package/dist/esm/lib/v3/verifier/prompts/index.d.ts +8 -0
  259. package/dist/esm/lib/v3/verifier/prompts/index.js +9 -0
  260. package/dist/esm/lib/v3/verifier/prompts/index.js.map +1 -0
  261. package/dist/esm/lib/v3/verifier/prompts/perCriterionScore.d.ts +23 -0
  262. package/dist/esm/lib/v3/verifier/prompts/perCriterionScore.js +74 -0
  263. package/dist/esm/lib/v3/verifier/prompts/perCriterionScore.js.map +1 -0
  264. package/dist/esm/lib/v3/verifier/prompts/render.d.ts +23 -0
  265. package/dist/esm/lib/v3/verifier/prompts/render.js +41 -0
  266. package/dist/esm/lib/v3/verifier/prompts/render.js.map +1 -0
  267. package/dist/esm/lib/v3/verifier/prompts/rubricGeneration.d.ts +16 -0
  268. package/dist/esm/lib/v3/verifier/prompts/rubricGeneration.js +318 -0
  269. package/dist/esm/lib/v3/verifier/prompts/rubricGeneration.js.map +1 -0
  270. package/dist/esm/lib/v3/verifier/prompts/taskValidity.d.ts +1 -0
  271. package/dist/esm/lib/v3/verifier/prompts/taskValidity.js +113 -0
  272. package/dist/esm/lib/v3/verifier/prompts/taskValidity.js.map +1 -0
  273. package/dist/esm/lib/v3/verifier/rubricVerifier.d.ts +91 -0
  274. package/dist/esm/lib/v3/verifier/rubricVerifier.js +1640 -0
  275. package/dist/esm/lib/v3/verifier/rubricVerifier.js.map +1 -0
  276. package/dist/esm/lib/v3/verifier/trajectory.d.ts +50 -0
  277. package/dist/esm/lib/v3/verifier/trajectory.js +273 -0
  278. package/dist/esm/lib/v3/verifier/trajectory.js.map +1 -0
  279. package/dist/esm/lib/v3/verifier/types.d.ts +429 -0
  280. package/dist/esm/lib/v3/verifier/types.js +2 -0
  281. package/dist/esm/lib/v3/verifier/types.js.map +1 -0
  282. package/dist/esm/lib/v3Evaluator.d.ts +14 -4
  283. package/dist/esm/lib/v3Evaluator.js +189 -1
  284. package/dist/esm/lib/v3Evaluator.js.map +1 -1
  285. package/dist/esm/lib/v3LegacyEvaluator.js +5 -1
  286. package/dist/esm/lib/v3LegacyEvaluator.js.map +1 -1
  287. package/dist/esm/lib/version.d.ts +1 -1
  288. package/dist/esm/lib/version.js +1 -1
  289. package/dist/esm/lib/version.js.map +1 -1
  290. package/package.json +18 -12
@@ -1 +1 @@
1
- {"version":3,"file":"locatorScripts.generated.js","sourceRoot":"","sources":["../../../../../../lib/v3/dom/build/locatorScripts.generated.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,0rtBAA0rtB,CAAC;AACjutB,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,kCAAkC,EAAE,8tBAA8tB;IAClwB,uBAAuB,EAAE,ktBAAktB;IAC3uB,wBAAwB,EAAE,sgBAAsgB;IAChiB,kBAAkB,EAAE,ugDAAugD;IAC3hD,4BAA4B,EAAE,+CAA+C;IAC7E,kBAAkB,EAAE,yRAAyR;IAC7S,wBAAwB,EAAE,8IAA8I;IACxK,kBAAkB,EAAE,mlDAAmlD;IACvmD,cAAc,EAAE,0EAA0E;IAC1F,kBAAkB,EAAE,8PAA8P;IAClR,kBAAkB,EAAE,mZAAmZ;IACva,yBAAyB,EAAE,imBAAimB;IAC5nB,sBAAsB,EAAE,0EAA0E;IAClG,sBAAsB,EAAE,mKAAmK;IAC3L,uBAAuB,EAAE,qNAAqN;IAC9O,wBAAwB,EAAE,4EAA4E;IACtG,oBAAoB,EAAE,sGAAsG;IAC5H,0BAA0B,EAAE,8uBAA8uB;IAC1wB,qBAAqB,EAAE,o5CAAo5C;IAC36C,uBAAuB,EAAE,8DAA8D;IACvF,wBAAwB,EAAE,45BAA45B;IACt7B,sBAAsB,EAAE,snBAAsnB;IAC9oB,iBAAiB,EAAE,+lCAA+lC;CAC1mC,CAAC;AACX,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,kCAAkC,EAAE,uEAAuE;IAC3G,uBAAuB,EAAE,4DAA4D;IACrF,wBAAwB,EAAE,6DAA6D;IACvF,kBAAkB,EAAE,uDAAuD;IAC3E,4BAA4B,EAAE,iEAAiE;IAC/F,kBAAkB,EAAE,uDAAuD;IAC3E,wBAAwB,EAAE,6DAA6D;IACvF,kBAAkB,EAAE,uDAAuD;IAC3E,cAAc,EAAE,mDAAmD;IACnE,kBAAkB,EAAE,uDAAuD;IAC3E,kBAAkB,EAAE,uDAAuD;IAC3E,yBAAyB,EAAE,8DAA8D;IACzF,sBAAsB,EAAE,2DAA2D;IACnF,sBAAsB,EAAE,2DAA2D;IACnF,uBAAuB,EAAE,4DAA4D;IACrF,wBAAwB,EAAE,6DAA6D;IACvF,oBAAoB,EAAE,yDAAyD;IAC/E,0BAA0B,EAAE,+DAA+D;IAC3F,qBAAqB,EAAE,0DAA0D;IACjF,uBAAuB,EAAE,4DAA4D;IACrF,wBAAwB,EAAE,6DAA6D;IACvF,sBAAsB,EAAE,2DAA2D;IACnF,iBAAiB,EAAE,sDAAsD;CACjE,CAAC","sourcesContent":["/*\n * AUTO-GENERATED FILE. DO NOT EDIT.\n * Run `pnpm run build-dom-scripts` to regenerate.\n */\nexport const locatorScriptBootstrap = \"if (!globalThis.__stagehandLocatorScripts) { var __stagehandLocatorScriptsFactory=(()=>{var M=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var Q=Object.prototype.hasOwnProperty;var Z=(e,t)=>{for(var n in t)M(e,n,{get:t[n],enumerable:!0})},j=(e,t,n,o)=>{if(t&&typeof t==\\\"object\\\"||typeof t==\\\"function\\\")for(let r of U(t))!Q.call(e,r)&&r!==n&&M(e,r,{get:()=>t[r],enumerable:!(o=K(t,r))||o.enumerable});return e};var J=e=>j(M({},\\\"__esModule\\\",{value:!0}),e);var Oe={};Z(Oe,{assignFilePayloadsToInputElement:()=>te,countCssMatchesPierce:()=>Me,countCssMatchesPrimary:()=>Ce,countTextMatches:()=>Le,countXPathMatchesMainWorld:()=>Pe,dispatchDomClick:()=>ne,ensureFileInputElement:()=>ee,fillElementValue:()=>se,focusElement:()=>le,isElementChecked:()=>ce,isElementVisible:()=>ae,prepareElementForTyping:()=>v,readElementInnerHTML:()=>me,readElementInnerText:()=>fe,readElementInputValue:()=>ue,readElementTextContent:()=>de,resolveCssSelector:()=>ve,resolveCssSelectorPierce:()=>Te,resolveTextSelector:()=>Re,resolveXPathMainWorld:()=>Ne,scrollElementToPercent:()=>oe,selectElementOptions:()=>ie,waitForSelector:()=>_e});function ee(){try{return(this.tagName?.toLowerCase()??\\\"\\\")!==\\\"input\\\"?!1:String(this.type??\\\"\\\").toLowerCase()===\\\"file\\\"}catch{return!1}}function te(e){try{let t=this;if(!t||t.tagName?.toLowerCase()!==\\\"input\\\"||(t.type??\\\"\\\").toLowerCase()!==\\\"file\\\")return!1;let n=(()=>{try{return new DataTransfer}catch{return null}})();if(!n)return!1;let o=Array.isArray(e)?e:[];for(let r of o){if(!r)continue;let l=r.name||\\\"upload.bin\\\",s=r.mimeType||\\\"application/octet-stream\\\",i=typeof r.lastModified==\\\"number\\\"?r.lastModified:Date.now(),a=window.atob(r.base64??\\\"\\\"),d=new Uint8Array(a.length);for(let p=0;p<a.length;p+=1)d[p]=a.charCodeAt(p);let f=new Blob([d],{type:s}),c=new File([f],l,{type:s,lastModified:i});n.items.add(c)}return t.files=n.files,t.dispatchEvent(new Event(\\\"input\\\",{bubbles:!0})),t.dispatchEvent(new Event(\\\"change\\\",{bubbles:!0})),!0}catch{return!1}}function ne(e){let t=e??{};try{let n=new MouseEvent(\\\"click\\\",{bubbles:!!t.bubbles,cancelable:!!t.cancelable,composed:!!t.composed,detail:typeof t.detail==\\\"number\\\"?t.detail:1,view:this?.ownerDocument?.defaultView??window});this.dispatchEvent(n)}catch{try{this.click()}catch{}}}function oe(e){let t=n=>{if(typeof n==\\\"number\\\"&&Number.isFinite(n))return n;let o=String(n??\\\"\\\").trim();if(!o)return 0;let r=parseFloat(o.replace(\\\"%\\\",\\\"\\\"));return Number.isNaN(r)||!Number.isFinite(r)?0:r};try{let n=Math.max(0,Math.min(t(e),100)),o=this,r=o.tagName?.toLowerCase()??\\\"\\\";if(r===\\\"html\\\"||r===\\\"body\\\"){let c=(o.ownerDocument?.scrollingElement||o.ownerDocument?.documentElement||o.ownerDocument?.body||document.scrollingElement||document.documentElement||document.body)?.scrollHeight??document.body.scrollHeight??0,p=o.ownerDocument?.defaultView?.innerHeight??window.innerHeight,w=Math.max(0,c-p)*(n/100);return o.ownerDocument?.defaultView?.scrollTo({top:w,left:o.ownerDocument?.defaultView?.scrollX??window.scrollX??0,behavior:\\\"smooth\\\"}),!0}let s=o.scrollHeight??0,i=o.clientHeight??0,d=Math.max(0,s-i)*(n/100);return o.scrollTo({top:d,left:o.scrollLeft??0,behavior:\\\"smooth\\\"}),!0}catch{return!1}}var H=new Set([\\\"color\\\",\\\"date\\\",\\\"datetime-local\\\",\\\"month\\\",\\\"range\\\",\\\"time\\\",\\\"week\\\"]),re=new Set([\\\"\\\",\\\"email\\\",\\\"number\\\",\\\"password\\\",\\\"search\\\",\\\"tel\\\",\\\"text\\\",\\\"url\\\"]);function v(){try{let e=this;if(!e.isConnected)return!1;let t=e.ownerDocument||document,n=t.defaultView||window;try{typeof e.focus==\\\"function\\\"&&e.focus()}catch{}if(e instanceof n.HTMLInputElement||e instanceof n.HTMLTextAreaElement){try{if(typeof e.select==\\\"function\\\")return e.select(),!0}catch{}try{let o=(e.value??\\\"\\\").length;if(typeof e.setSelectionRange==\\\"function\\\")return e.setSelectionRange(0,o),!0}catch{}return!0}if(e.isContentEditable){let o=t.getSelection?.(),r=t.createRange?.();if(o&&r)try{r.selectNodeContents(e),o.removeAllRanges(),o.addRange(r)}catch{}return!0}return!1}catch{return!1}}function se(e){let t=this;if(!t.isConnected)return{status:\\\"error\\\",reason:\\\"notconnected\\\"};let o=(t.ownerDocument||document).defaultView||window,r=e??\\\"\\\";try{let l=s=>{let i;if(typeof o.InputEvent==\\\"function\\\")try{i=new o.InputEvent(\\\"input\\\",{bubbles:!0,composed:!0,data:s,inputType:\\\"insertText\\\"})}catch{i=new o.Event(\\\"input\\\",{bubbles:!0,composed:!0})}else i=new o.Event(\\\"input\\\",{bubbles:!0,composed:!0});t.dispatchEvent(i);let a=new o.Event(\\\"change\\\",{bubbles:!0});t.dispatchEvent(a)};if(t instanceof o.HTMLInputElement){let s=(t.type||\\\"\\\").toLowerCase();if(!re.has(s)&&!H.has(s))return{status:\\\"error\\\",reason:`unsupported-input-type:${s}`};let i=e;if(s===\\\"number\\\"){let a=e.trim();if(a!==\\\"\\\"&&Number.isNaN(Number(a)))return{status:\\\"error\\\",reason:\\\"invalid-number-value\\\"};i=a}if(r=i,H.has(s)){let a=e.trim();r=a,v.call(t);let d=o.HTMLInputElement.prototype,c=Object.getOwnPropertyDescriptor(d,\\\"value\\\")?.set;return typeof c==\\\"function\\\"?c.call(t,a):t.value=a,t._valueTracker?.setValue?.(a),t.value!==a?{status:\\\"error\\\",reason:\\\"malformed-value\\\"}:(l(a),{status:\\\"done\\\"})}return v.call(t),{status:\\\"needsinput\\\",value:i}}return t instanceof o.HTMLTextAreaElement?(v.call(t),r=e,{status:\\\"needsinput\\\",value:e}):t instanceof o.HTMLSelectElement?{status:\\\"error\\\",reason:\\\"unsupported-element\\\"}:t.isContentEditable?(v.call(t),r=e,{status:\\\"needsinput\\\",value:e}):{status:\\\"error\\\",reason:\\\"unsupported-element\\\"}}catch(l){let s=\\\"exception\\\";if(l&&typeof l==\\\"object\\\"){let i=l.message;typeof i==\\\"string\\\"&&i.trim().length>0&&(s=`exception:${i}`)}return{status:\\\"needsinput\\\",value:r,reason:s}}}function le(){try{typeof this.focus==\\\"function\\\"&&this.focus()}catch{}}function ie(e){try{if(!(this instanceof HTMLSelectElement))return[];let t=Array.isArray(e)?e:[e],n=new Set(t.map(s=>String(s??\\\"\\\").trim())),o=s=>{let i=(s.label||s.textContent||\\\"\\\").trim(),a=String(s.value??\\\"\\\").trim();return n.has(i)||n.has(a)};if(this.multiple)for(let s of Array.from(this.options))s.selected=o(s);else{let s=!1;for(let i of Array.from(this.options))!s&&o(i)?(i.selected=!0,this.value=i.value,s=!0):i.selected=!1}let r=new Event(\\\"input\\\",{bubbles:!0}),l=new Event(\\\"change\\\",{bubbles:!0});return this.dispatchEvent(r),this.dispatchEvent(l),Array.from(this.selectedOptions).map(s=>s.value)}catch{return[]}}function ae(){try{let e=this;if(!e.isConnected)return!1;let t=e.ownerDocument?.defaultView?.getComputedStyle(e)??window.getComputedStyle(e);if(!t||t.display===\\\"none\\\"||t.visibility===\\\"hidden\\\")return!1;let n=parseFloat(t.opacity??\\\"1\\\");if(!Number.isFinite(n)||n===0)return!1;let o=e.getBoundingClientRect();return!(!o||Math.max(o.width,o.height)===0||e.getClientRects().length===0)}catch{return!1}}function ce(){try{let e=this;if((e.tagName||\\\"\\\").toLowerCase()===\\\"input\\\"){let o=e.type?.toLowerCase()??\\\"\\\";if(o===\\\"checkbox\\\"||o===\\\"radio\\\")return!!e.checked}let n=e.getAttribute?.(\\\"aria-checked\\\");return n!=null?n===\\\"true\\\":!1}catch{return!1}}function ue(){try{let e=this,t=(e.tagName||\\\"\\\").toLowerCase();return t===\\\"input\\\"||t===\\\"textarea\\\"||t===\\\"select\\\"?String(e.value??\\\"\\\"):e.isContentEditable?String(e.textContent??\\\"\\\"):\\\"\\\"}catch{return\\\"\\\"}}function de(){try{return String(this.textContent??\\\"\\\")}catch{return\\\"\\\"}}function me(){try{return String(this.innerHTML??\\\"\\\")}catch{return\\\"\\\"}}function fe(){try{let e=this,t=e.innerText;if(typeof t==\\\"string\\\"&&t.length>0)return t;let n=e.textContent;return typeof n==\\\"string\\\"?n:\\\"\\\"}catch{return\\\"\\\"}}function O(e){let t=String(e||\\\"\\\").trim().replace(/^xpath=/i,\\\"\\\");if(!t)return[];let n=[],o=0;for(;o<t.length;){let r=\\\"child\\\";t.startsWith(\\\"//\\\",o)?(r=\\\"desc\\\",o+=2):t[o]===\\\"/\\\"&&(r=\\\"child\\\",o+=1);let l=o,s=0,i=null;for(;o<t.length;){let c=t[o];if(i)c===i&&(i=null);else if(c===\\\"'\\\"||c==='\\\"')i=c;else if(c===\\\"[\\\")s++;else if(c===\\\"]\\\")s--;else if(c===\\\"/\\\"&&s===0)break;o+=1}let a=t.slice(l,o).trim();if(!a)continue;let{tag:d,predicates:f}=pe(a);n.push({axis:r,tag:d,predicates:f})}return n}function he(e){let t=[],n=0;for(;n<e.length;){if(e[n]!==\\\"[\\\"){n++;continue}n++;let o=n,r=null;for(;n<e.length;){let l=e[n];if(r)l===r&&(r=null);else if(l===\\\"'\\\"||l==='\\\"')r=l;else if(l===\\\"]\\\")break;n++}t.push(e.slice(o,n).trim()),n++}return t}function pe(e){let t=e.indexOf(\\\"[\\\");if(t===-1)return{tag:e===\\\"\\\"?\\\"*\\\":e.toLowerCase(),predicates:[]};let n=e.slice(0,t).trim(),o=n===\\\"\\\"?\\\"*\\\":n.toLowerCase(),r=e.slice(t),l=[];for(let s of he(r)){let i=T(s);i&&l.push(i)}return{tag:o,predicates:l}}function T(e){let t=e.trim();if(!t)return null;let n=A(t,\\\"or\\\");if(n.length>1){let l=n.map(s=>T(s)).filter(Boolean);return l.length!==n.length?null:{type:\\\"or\\\",predicates:l}}let o=A(t,\\\"and\\\");if(o.length>1){let l=o.map(s=>T(s)).filter(Boolean);return l.length!==o.length?null:{type:\\\"and\\\",predicates:l}}let r=we(t,\\\"not\\\");if(r!=null){let l=T(r);return l?{type:\\\"not\\\",predicate:l}:null}return ge(t)}function ge(e){let t=/^(?:'([^']*)'|\\\"([^\\\"]*)\\\")$/,n=\\\"[a-zA-Z_][\\\\\\\\w.-]*\\\",o=`(?:'([^']*)'|\\\"([^\\\"]*)\\\")`;if(/^\\\\d+$/.test(e))return{type:\\\"index\\\",index:Math.max(1,Number(e))};let r=e.match(new RegExp(`^normalize-space\\\\\\\\(\\\\\\\\s*@(${n})\\\\\\\\s*\\\\\\\\)\\\\\\\\s*=\\\\\\\\s*${o}$`));if(r)return{type:\\\"attrEquals\\\",name:r[1],value:r[2]??r[3]??\\\"\\\",normalize:!0};let l=e.match(new RegExp(`^normalize-space\\\\\\\\(\\\\\\\\s*(?:text\\\\\\\\(\\\\\\\\)|\\\\\\\\.)\\\\\\\\s*\\\\\\\\)\\\\\\\\s*=\\\\\\\\s*${o}$`));if(l)return{type:\\\"textEquals\\\",value:l[1]??l[2]??\\\"\\\",normalize:!0};let s=e.match(new RegExp(`^@(${n})\\\\\\\\s*=\\\\\\\\s*${o}$`));if(s)return{type:\\\"attrEquals\\\",name:s[1],value:s[2]??s[3]??\\\"\\\"};let i=e.match(new RegExp(`^@(${n})$`));if(i)return{type:\\\"attrExists\\\",name:i[1]};let a=e.match(new RegExp(`^contains\\\\\\\\(\\\\\\\\s*@(${n})\\\\\\\\s*,\\\\\\\\s*${o}\\\\\\\\s*\\\\\\\\)$`));if(a)return{type:\\\"attrContains\\\",name:a[1],value:a[2]??a[3]??\\\"\\\"};let d=e.match(new RegExp(`^starts-with\\\\\\\\(\\\\\\\\s*@(${n})\\\\\\\\s*,\\\\\\\\s*${o}\\\\\\\\s*\\\\\\\\)$`));if(d)return{type:\\\"attrStartsWith\\\",name:d[1],value:d[2]??d[3]??\\\"\\\"};let f=e.match(new RegExp(`^(?:text\\\\\\\\(\\\\\\\\)|\\\\\\\\.)\\\\\\\\s*=\\\\\\\\s*${o}$`));if(f)return{type:\\\"textEquals\\\",value:f[1]??f[2]??\\\"\\\"};let c=e.match(new RegExp(`^contains\\\\\\\\(\\\\\\\\s*(?:text\\\\\\\\(\\\\\\\\)|\\\\\\\\.)\\\\\\\\s*,\\\\\\\\s*${o}\\\\\\\\s*\\\\\\\\)$`));return c?{type:\\\"textContains\\\",value:c[1]??c[2]??\\\"\\\"}:(t.test(e),null)}function A(e,t){let n=[],o=0,r=0,l=null,s=0;for(;s<e.length;){let i=e[s];if(l){i===l&&(l=null),s+=1;continue}if(i===\\\"'\\\"||i==='\\\"'){l=i,s+=1;continue}if(i===\\\"(\\\"){r+=1,s+=1;continue}if(i===\\\")\\\"){r=Math.max(0,r-1),s+=1;continue}if(r===0&&Ee(e,s,t)){n.push(e.slice(o,s).trim()),s+=t.length,o=s;continue}s+=1}return n.push(e.slice(o).trim()),n.filter(i=>i.length>0)}function Ee(e,t,n){if(!e.startsWith(n,t))return!1;let o=t>0?e[t-1]:\\\" \\\";if(o===\\\"@\\\")return!1;let r=t+n.length<e.length?e[t+n.length]:\\\" \\\";return W(o)&&W(r)}function W(e){return!/[a-zA-Z0-9_.-]/.test(e)}function we(e,t){let n=`${t}(`;if(!e.startsWith(n)||!e.endsWith(\\\")\\\"))return null;let o=e.slice(n.length,-1);return ye(o)?o:null}function ye(e){let t=0,n=null;for(let o=0;o<e.length;o+=1){let r=e[o];if(n){r===n&&(n=null);continue}if(r===\\\"'\\\"||r==='\\\"'){n=r;continue}if(r===\\\"(\\\"?t+=1:r===\\\")\\\"&&(t-=1),t<0)return!1}return t===0}var be=e=>e.replace(/\\\\s+/g,\\\" \\\").trim();function _(e){return String(e.textContent??\\\"\\\")}function S(e,t){return t?be(e):e}function R(e,t){switch(t.type){case\\\"and\\\":return t.predicates.every(n=>R(e,n));case\\\"or\\\":return t.predicates.some(n=>R(e,n));case\\\"not\\\":return!R(e,t.predicate);case\\\"attrExists\\\":return e.getAttribute(t.name)!==null;case\\\"attrEquals\\\":{let n=e.getAttribute(t.name);return n===null?!1:S(n,t.normalize)===S(t.value,t.normalize)}case\\\"attrContains\\\":{let n=e.getAttribute(t.name);return n===null?!1:S(n,t.normalize).includes(S(t.value,t.normalize))}case\\\"attrStartsWith\\\":{let n=e.getAttribute(t.name);return n===null?!1:S(n,t.normalize).startsWith(S(t.value,t.normalize))}case\\\"textEquals\\\":return S(_(e),t.normalize)===S(t.value,t.normalize);case\\\"textContains\\\":return S(_(e),t.normalize).includes(S(t.value,t.normalize));case\\\"index\\\":return!0;default:return!0}}function q(e,t){let n=e;for(let o of t){if(!n.length)return[];if(o.type===\\\"index\\\"){let r=o.index-1;n=r>=0&&r<n.length?[n[r]]:[];continue}n=n.filter(r=>R(r,o))}return n}var P=e=>{let t=String(e??\\\"\\\").trim();return t?t.replace(/^xpath=/i,\\\"\\\").trim():\\\"\\\"};function I(e,t){return k(e,0,t)}function k(e,t,n){if(!Number.isFinite(t)||t<0)return null;let o=P(e);if(!o)return null;let r=Math.floor(t),l=n?.pierceShadow!==!1,s=l?z():null;if(!l)return X(o,r).value;if(!s?.hasShadow){let a=X(o,r);return a.error?N(o,s?.getClosedRoot)[r]??null:a.value}return N(o,s.getClosedRoot)[r]??null}function $(e,t){let n=P(e);if(!n)return 0;let o=t?.pierceShadow!==!1,r=o?z():null;if(!o)return F(n).count;if(!r?.hasShadow){let l=F(n);return l.error?N(n,r?.getClosedRoot).length:l.count}return N(n,r.getClosedRoot).length}function N(e,t){let n=P(e);if(!n)return[];let o=O(n);if(!o.length)return[];let r=t??null,l=[document];for(let s of o){let i=[],a=new Set;for(let d of l){if(!d)continue;let f=s.axis===\\\"child\\\"?L(d,r):Se(d,r);if(!f.length)continue;let c=f.filter(g=>xe(g,s)),p=q(c,s.predicates);for(let g of p)a.has(g)||(a.add(g),i.push(g))}if(!i.length)return[];l=i}return l}function xe(e,t){return t.tag===\\\"*\\\"?!0:e.localName===t.tag}function z(){let e=window.__stagehandV3__,t=e&&typeof e.getClosedRoot==\\\"function\\\"?o=>{try{return e.getClosedRoot(o)??null}catch{return null}}:null,n=!1;try{if(e&&typeof e.stats==\\\"function\\\"){let o=e.stats();n=(o?.open??0)>0||(o?.closed??0)>0}}catch{}if(!n)try{let o=document.createTreeWalker(document,NodeFilter.SHOW_ELEMENT);for(;o.nextNode();)if(o.currentNode.shadowRoot){n=!0;break}}catch{}return{getClosedRoot:t,hasShadow:n}}function L(e,t){let n=[];if(!e)return n;if(e instanceof Document)return e.documentElement&&n.push(e.documentElement),n;if(e instanceof ShadowRoot||e instanceof DocumentFragment)return n.push(...Array.from(e.children??[])),n;if(e instanceof Element){n.push(...Array.from(e.children??[]));let o=e.shadowRoot;if(o&&n.push(...Array.from(o.children??[])),t){let r=t(e);r&&n.push(...Array.from(r.children??[]))}return n}return n}function Se(e,t){let n=[],o=new Set,r=[...L(e,t)].reverse();for(;r.length;){let l=r.pop();if(!l||o.has(l))continue;o.add(l),n.push(l);let s=L(l,t);for(let i=s.length-1;i>=0;i-=1)r.push(s[i])}return n}function X(e,t){try{return{value:document.evaluate(e,document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotItem(t),error:!1}}catch{return{value:null,error:!0}}}function F(e){try{return{count:document.evaluate(e,document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotLength,error:!1}}catch{return{count:0,error:!0}}}var C=e=>{let t=Number(e??0);return!Number.isFinite(t)||t<0?0:Math.floor(t)},V=(e,t)=>{if(!e)return[];let n=new WeakSet,o=new Set,r=[],l=[document],s=i=>{if(!(!i||n.has(i)||r.length>=t)){n.add(i);try{let a=i.querySelectorAll(e);for(let d of a)if(!o.has(d)&&(o.add(d),r.push(d),r.length>=t))return}catch{}try{let d=(i instanceof Document?i:i.host?.ownerDocument??document).createTreeWalker(i,NodeFilter.SHOW_ELEMENT),f;for(;f=d.nextNode();){if(!(f instanceof Element))continue;let c=f.shadowRoot;c&&l.push(c)}}catch{}}};for(;l.length&&r.length<t;){let i=l.shift();i&&s(i)}return r};function ve(e,t){let n=String(e??\\\"\\\").trim();if(!n)return null;let o=C(t);return V(n,o+1)[o]??null}function Te(e,t){let n=String(e??\\\"\\\").trim();if(!n)return null;let o=C(t),r=window.__stagehandV3__;if(!r||typeof r.getClosedRoot!=\\\"function\\\")return V(n,o+1)[o]??null;let l=c=>{try{return r.getClosedRoot(c)??null}catch{return null}},s=new WeakSet,i=new Set,a=[],d=[document],f=c=>{if(!(!c||s.has(c)||a.length>=o+1)){s.add(c);try{let p=c.querySelectorAll(n);for(let g of p)if(!i.has(g)&&(i.add(g),a.push(g),a.length>=o+1))return}catch{}try{let g=(c instanceof Document?c:c.host?.ownerDocument??document).createTreeWalker(c,NodeFilter.SHOW_ELEMENT),w;for(;w=g.nextNode();){if(!(w instanceof Element))continue;let x=w.shadowRoot;x&&d.push(x);let y=l(w);y&&d.push(y)}}catch{}}};for(;d.length&&a.length<o+1;){let c=d.shift();c&&f(c)}return a[o]??null}function Re(e,t){let n=String(e??\\\"\\\");if(!n)return null;let o=n.toLowerCase(),r=C(t),l=new Set([\\\"SCRIPT\\\",\\\"STYLE\\\",\\\"TEMPLATE\\\",\\\"NOSCRIPT\\\",\\\"HEAD\\\",\\\"TITLE\\\",\\\"LINK\\\",\\\"META\\\",\\\"HTML\\\",\\\"BODY\\\"]),s=u=>{if(!u)return!1;let h=u.tagName?.toUpperCase()??\\\"\\\";return l.has(h)},i=u=>{try{if(s(u))return\\\"\\\";let h=u.innerText;if(typeof h==\\\"string\\\"&&h.trim())return h.trim()}catch{}try{let h=u.textContent;if(typeof h==\\\"string\\\")return h.trim()}catch{}return\\\"\\\"},a=u=>{let h=i(u);return!!h&&h.toLowerCase().includes(o)},d=window.__stagehandV3__,f=d&&typeof d.getClosedRoot==\\\"function\\\"?u=>{try{return d.getClosedRoot(u)??null}catch{return null}}:u=>null,c=new WeakSet,p=[],g=[],w=u=>{!u||c.has(u)||(c.add(u),p.push(u))},x=u=>{try{return(u instanceof Document?u:u?.ownerDocument??document).createTreeWalker(u,NodeFilter.SHOW_ELEMENT)}catch{return null}};for(w(document);p.length;){let u=p.shift();if(!u)continue;u instanceof Element&&a(u)&&g.push({element:u,tag:u.tagName??\\\"\\\",id:u.id??\\\"\\\",className:u.className??\\\"\\\",text:i(u)});let h=x(u);if(!h)continue;let E;for(;E=h.nextNode();){if(!(E instanceof Element))continue;a(E)&&g.push({element:E,tag:E.tagName??\\\"\\\",id:E.id??\\\"\\\",className:E.className??\\\"\\\",text:i(E)});let b=E.shadowRoot;b&&w(b);let D=f(E);D&&w(D)}}let y=[];for(let u of g){let h=u.element,E=!1;for(let b of g)if(u!==b)try{if(h.contains(b.element)){E=!0;break}}catch{}E||y.push(u)}return y[r]?.element??null}function Ne(e,t){let n=C(t);return k(e,n,{pierceShadow:!0})}function Ce(e){let t=String(e??\\\"\\\").trim();if(!t)return 0;let n=new WeakSet,o=r=>{if(!r||n.has(r))return 0;n.add(r);let l=0;try{let s=r;typeof s.querySelectorAll==\\\"function\\\"&&(l+=s.querySelectorAll(t).length)}catch{}try{let i=(r instanceof Document?r:r?.ownerDocument??document).createTreeWalker(r,NodeFilter.SHOW_ELEMENT),a;for(;a=i.nextNode();)a instanceof Element&&a.shadowRoot&&(l+=o(a.shadowRoot))}catch{}return l};try{return o(document)}catch{try{return document.querySelectorAll(t).length}catch{return 0}}}function Me(e){let t=String(e??\\\"\\\").trim();if(!t)return 0;let n=window.__stagehandV3__;if(!n||typeof n.getClosedRoot!=\\\"function\\\")try{return document.querySelectorAll(t).length}catch{return 0}let o=new WeakSet,r=[],l=a=>{!a||o.has(a)||(o.add(a),r.push(a))};l(document);let s=0,i=a=>{let d=a.shadowRoot;d&&l(d);try{let f=n.getClosedRoot(a);f&&l(f)}catch{}};for(;r.length;){let a=r.shift();if(a){try{let d=a;typeof d.querySelectorAll==\\\"function\\\"&&(s+=d.querySelectorAll(t).length)}catch{}try{let f=(a instanceof Document?a:a instanceof ShadowRoot?a.host?.ownerDocument??document:a.ownerDocument??document).createTreeWalker(a,NodeFilter.SHOW_ELEMENT),c;for(;c=f.nextNode();)c instanceof Element&&i(c)}catch{}}}return s}function Le(e){let t=String(e??\\\"\\\");if(!t)return{count:0,sample:[],error:null};let n=t.toLowerCase(),o=new Set([\\\"SCRIPT\\\",\\\"STYLE\\\",\\\"TEMPLATE\\\",\\\"NOSCRIPT\\\",\\\"HEAD\\\",\\\"TITLE\\\",\\\"LINK\\\",\\\"META\\\",\\\"HTML\\\",\\\"BODY\\\"]),r=m=>{if(!m)return!1;let u=m.tagName?.toUpperCase()??\\\"\\\";return o.has(u)},l=m=>{try{if(r(m))return\\\"\\\";let u=m.innerText;if(typeof u==\\\"string\\\"&&u.trim())return u.trim()}catch{}try{let u=m.textContent;if(typeof u==\\\"string\\\")return u.trim()}catch{}return\\\"\\\"},s=m=>{let u=l(m);return!!u&&u.toLowerCase().includes(n)},i=window.__stagehandV3__,a=i&&typeof i.getClosedRoot==\\\"function\\\"?m=>{try{return i.getClosedRoot(m)??null}catch{return null}}:m=>null,d=new WeakSet,f=[],c=m=>{!m||d.has(m)||(d.add(m),f.push(m))},p=m=>{try{return(m instanceof Document?m:m?.ownerDocument??document).createTreeWalker(m,NodeFilter.SHOW_ELEMENT)}catch{return null}},g=[];for(c(document);f.length;){let m=f.shift();if(!m)continue;m instanceof Element&&s(m)&&g.push({element:m,tag:m.tagName??\\\"\\\",id:m.id??\\\"\\\",className:m.className??\\\"\\\",text:l(m)});let u=p(m);if(!u)continue;let h;for(;h=u.nextNode();){if(!(h instanceof Element))continue;s(h)&&g.push({element:h,tag:h.tagName??\\\"\\\",id:h.id??\\\"\\\",className:h.className??\\\"\\\",text:l(h)});let E=h.shadowRoot;E&&c(E);let b=a(h);b&&c(b)}}let w=[];for(let m of g){let u=m.element,h=!1;for(let E of g)if(m!==E)try{if(u.contains(E.element)){h=!0;break}}catch{}h||w.push(m)}let x=w.length,y=w.slice(0,5).map(m=>({tag:m.tag,id:m.id,class:m.className,text:m.text}));return{count:x,sample:y,error:null}}function Pe(e){return $(e,{pierceShadow:!0})}var ke=e=>e.startsWith(\\\"xpath=\\\")||e.startsWith(\\\"/\\\"),De=e=>{try{let t=window.__stagehandV3__;if(t&&typeof t.getClosedRoot==\\\"function\\\")return t.getClosedRoot(e)??null}catch{}return null},Y=e=>e.shadowRoot?e.shadowRoot:De(e),He=(e,t,n)=>{try{let l=e.querySelector(t);if(l)return l}catch{}if(!n)return null;let o=new WeakSet,r=[e];for(;r.length>0;){let l=r.shift();if(!(!l||o.has(l))){o.add(l);try{let s=l.querySelector(t);if(s)return s}catch{}try{let i=(l instanceof Document?l:l.host?.ownerDocument??document).createTreeWalker(l,NodeFilter.SHOW_ELEMENT),a;for(;a=i.nextNode();){if(!(a instanceof Element))continue;let d=Y(a);d&&!o.has(d)&&r.push(d)}}catch{}}}return null},Ae=(e,t)=>I(e,{pierceShadow:t}),B=(e,t)=>ke(e)?Ae(e,t):He(document,e,t),G=(e,t)=>{if(t===\\\"detached\\\")return e===null;if(t===\\\"attached\\\")return e!==null;if(e===null)return!1;if(t===\\\"hidden\\\")try{let n=window.getComputedStyle(e),o=e.getBoundingClientRect();return n.display===\\\"none\\\"||n.visibility===\\\"hidden\\\"||n.opacity===\\\"0\\\"||o.width===0||o.height===0}catch{return!1}try{let n=window.getComputedStyle(e),o=e.getBoundingClientRect();return n.display!==\\\"none\\\"&&n.visibility!==\\\"hidden\\\"&&n.opacity!==\\\"0\\\"&&o.width>0&&o.height>0}catch{return!1}},We=(e,t)=>{let n=new WeakSet,o=l=>{let s=Y(l);if(s&&!n.has(s)){n.add(s);let i=new MutationObserver(e);i.observe(s,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[\\\"style\\\",\\\"class\\\",\\\"hidden\\\",\\\"disabled\\\"]}),t.push(i);for(let a of Array.from(s.children))o(a)}for(let i of Array.from(l.children))o(i)},r=document.documentElement||document.body;r&&o(r)};function _e(e,t,n,o){let r=String(e??\\\"\\\").trim(),l=String(t??\\\"visible\\\")||\\\"visible\\\",s=typeof n==\\\"number\\\"&&n>0?n:3e4,i=o!==!1;return new Promise((a,d)=>{let f=null,c=null,p=!1,g=()=>{f!==null&&(clearTimeout(f),f=null)},w=B(r,i);if(G(w,l)){p=!0,a(!0);return}let x=[],y=()=>{for(let E of x)E.disconnect();c&&(document.removeEventListener(\\\"DOMContentLoaded\\\",c),c=null)},m=()=>{if(p)return;let E=B(r,i);G(E,l)&&(p=!0,g(),y(),a(!0))};if(!(document.body||document.documentElement)){c=()=>{document.removeEventListener(\\\"DOMContentLoaded\\\",c),c=null,m(),h()},document.addEventListener(\\\"DOMContentLoaded\\\",c),f=setTimeout(()=>{p||(p=!0,g(),y(),d(new Error(`waitForSelector: Timeout ${s}ms exceeded waiting for \\\"${r}\\\" to be ${l}`)))},s);return}let h=()=>{let E=document.body||document.documentElement;if(!E)return;let b=new MutationObserver(m);b.observe(E,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[\\\"style\\\",\\\"class\\\",\\\"hidden\\\",\\\"disabled\\\"]}),x.push(b),i&&We(m,x)};h(),f=setTimeout(()=>{p||(p=!0,g(),y(),d(new Error(`waitForSelector: Timeout ${s}ms exceeded waiting for \\\"${r}\\\" to be ${l}`)))},s)})}return J(Oe);})();\\n globalThis.__stagehandLocatorScripts = __stagehandLocatorScriptsFactory;\\n}\";\nexport const locatorScriptSources = {\n \"assignFilePayloadsToInputElement\": \"function ce(e){try{let t=this;if(!t||t.tagName?.toLowerCase()!==\\\"input\\\"||(t.type??\\\"\\\").toLowerCase()!==\\\"file\\\")return!1;let n=(()=>{try{return new DataTransfer}catch{return null}})();if(!n)return!1;let o=Array.isArray(e)?e:[];for(let r of o){if(!r)continue;let l=r.name||\\\"upload.bin\\\",s=r.mimeType||\\\"application/octet-stream\\\",i=typeof r.lastModified==\\\"number\\\"?r.lastModified:Date.now(),a=window.atob(r.base64??\\\"\\\"),d=new Uint8Array(a.length);for(let p=0;p<a.length;p+=1)d[p]=a.charCodeAt(p);let f=new Blob([d],{type:s}),c=new File([f],l,{type:s,lastModified:i});n.items.add(c)}return t.files=n.files,t.dispatchEvent(new Event(\\\"input\\\",{bubbles:!0})),t.dispatchEvent(new Event(\\\"change\\\",{bubbles:!0})),!0}catch{return!1}}\",\n \"countCssMatchesPierce\": \"function He(e){let t=String(e??\\\"\\\").trim();if(!t)return 0;let n=window.__stagehandV3__;if(!n||typeof n.getClosedRoot!=\\\"function\\\")try{return document.querySelectorAll(t).length}catch{return 0}let o=new WeakSet,r=[],l=a=>{!a||o.has(a)||(o.add(a),r.push(a))};l(document);let s=0,i=a=>{let d=a.shadowRoot;d&&l(d);try{let f=n.getClosedRoot(a);f&&l(f)}catch{}};for(;r.length;){let a=r.shift();if(a){try{let d=a;typeof d.querySelectorAll==\\\"function\\\"&&(s+=d.querySelectorAll(t).length)}catch{}try{let f=(a instanceof Document?a:a instanceof ShadowRoot?a.host?.ownerDocument??document:a.ownerDocument??document).createTreeWalker(a,NodeFilter.SHOW_ELEMENT),c;for(;c=f.nextNode();)c instanceof Element&&i(c)}catch{}}}return s}\",\n \"countCssMatchesPrimary\": \"function De(e){let t=String(e??\\\"\\\").trim();if(!t)return 0;let n=new WeakSet,o=r=>{if(!r||n.has(r))return 0;n.add(r);let l=0;try{let s=r;typeof s.querySelectorAll==\\\"function\\\"&&(l+=s.querySelectorAll(t).length)}catch{}try{let i=(r instanceof Document?r:r?.ownerDocument??document).createTreeWalker(r,NodeFilter.SHOW_ELEMENT),a;for(;a=i.nextNode();)a instanceof Element&&a.shadowRoot&&(l+=o(a.shadowRoot))}catch{}return l};try{return o(document)}catch{try{return document.querySelectorAll(t).length}catch{return 0}}}\",\n \"countTextMatches\": \"function Ae(e){let t=String(e??\\\"\\\");if(!t)return{count:0,sample:[],error:null};let n=t.toLowerCase(),o=new Set([\\\"SCRIPT\\\",\\\"STYLE\\\",\\\"TEMPLATE\\\",\\\"NOSCRIPT\\\",\\\"HEAD\\\",\\\"TITLE\\\",\\\"LINK\\\",\\\"META\\\",\\\"HTML\\\",\\\"BODY\\\"]),r=m=>{if(!m)return!1;let u=m.tagName?.toUpperCase()??\\\"\\\";return o.has(u)},l=m=>{try{if(r(m))return\\\"\\\";let u=m.innerText;if(typeof u==\\\"string\\\"&&u.trim())return u.trim()}catch{}try{let u=m.textContent;if(typeof u==\\\"string\\\")return u.trim()}catch{}return\\\"\\\"},s=m=>{let u=l(m);return!!u&&u.toLowerCase().includes(n)},i=window.__stagehandV3__,a=i&&typeof i.getClosedRoot==\\\"function\\\"?m=>{try{return i.getClosedRoot(m)??null}catch{return null}}:m=>null,d=new WeakSet,f=[],c=m=>{!m||d.has(m)||(d.add(m),f.push(m))},p=m=>{try{return(m instanceof Document?m:m?.ownerDocument??document).createTreeWalker(m,NodeFilter.SHOW_ELEMENT)}catch{return null}},g=[];for(c(document);f.length;){let m=f.shift();if(!m)continue;m instanceof Element&&s(m)&&g.push({element:m,tag:m.tagName??\\\"\\\",id:m.id??\\\"\\\",className:m.className??\\\"\\\",text:l(m)});let u=p(m);if(!u)continue;let h;for(;h=u.nextNode();){if(!(h instanceof Element))continue;s(h)&&g.push({element:h,tag:h.tagName??\\\"\\\",id:h.id??\\\"\\\",className:h.className??\\\"\\\",text:l(h)});let E=h.shadowRoot;E&&c(E);let b=a(h);b&&c(b)}}let w=[];for(let m of g){let u=m.element,h=!1;for(let E of g)if(m!==E)try{if(u.contains(E.element)){h=!0;break}}catch{}h||w.push(m)}let x=w.length,y=w.slice(0,5).map(m=>({tag:m.tag,id:m.id,class:m.className,text:m.text}));return{count:x,sample:y,error:null}}\",\n \"countXPathMatchesMainWorld\": \"function We(e){return I(e,{pierceShadow:!0})}\",\n \"dispatchDomClick\": \"function ue(e){let t=e??{};try{let n=new MouseEvent(\\\"click\\\",{bubbles:!!t.bubbles,cancelable:!!t.cancelable,composed:!!t.composed,detail:typeof t.detail==\\\"number\\\"?t.detail:1,view:this?.ownerDocument?.defaultView??window});this.dispatchEvent(n)}catch{try{this.click()}catch{}}}\",\n \"ensureFileInputElement\": \"function ae(){try{return(this.tagName?.toLowerCase()??\\\"\\\")!==\\\"input\\\"?!1:String(this.type??\\\"\\\").toLowerCase()===\\\"file\\\"}catch{return!1}}\",\n \"fillElementValue\": \"function me(e){let t=this;if(!t.isConnected)return{status:\\\"error\\\",reason:\\\"notconnected\\\"};let o=(t.ownerDocument||document).defaultView||window,r=e??\\\"\\\";try{let l=s=>{let i;if(typeof o.InputEvent==\\\"function\\\")try{i=new o.InputEvent(\\\"input\\\",{bubbles:!0,composed:!0,data:s,inputType:\\\"insertText\\\"})}catch{i=new o.Event(\\\"input\\\",{bubbles:!0,composed:!0})}else i=new o.Event(\\\"input\\\",{bubbles:!0,composed:!0});t.dispatchEvent(i);let a=new o.Event(\\\"change\\\",{bubbles:!0});t.dispatchEvent(a)};if(t instanceof o.HTMLInputElement){let s=(t.type||\\\"\\\").toLowerCase();if(!Y.has(s)&&!D.has(s))return{status:\\\"error\\\",reason:`unsupported-input-type:${s}`};let i=e;if(s===\\\"number\\\"){let a=e.trim();if(a!==\\\"\\\"&&Number.isNaN(Number(a)))return{status:\\\"error\\\",reason:\\\"invalid-number-value\\\"};i=a}if(r=i,D.has(s)){let a=e.trim();r=a,v.call(t);let d=o.HTMLInputElement.prototype,c=Object.getOwnPropertyDescriptor(d,\\\"value\\\")?.set;return typeof c==\\\"function\\\"?c.call(t,a):t.value=a,t._valueTracker?.setValue?.(a),t.value!==a?{status:\\\"error\\\",reason:\\\"malformed-value\\\"}:(l(a),{status:\\\"done\\\"})}return v.call(t),{status:\\\"needsinput\\\",value:i}}return t instanceof o.HTMLTextAreaElement?(v.call(t),r=e,{status:\\\"needsinput\\\",value:e}):t instanceof o.HTMLSelectElement?{status:\\\"error\\\",reason:\\\"unsupported-element\\\"}:t.isContentEditable?(v.call(t),r=e,{status:\\\"needsinput\\\",value:e}):{status:\\\"error\\\",reason:\\\"unsupported-element\\\"}}catch(l){let s=\\\"exception\\\";if(l&&typeof l==\\\"object\\\"){let i=l.message;typeof i==\\\"string\\\"&&i.trim().length>0&&(s=`exception:${i}`)}return{status:\\\"needsinput\\\",value:r,reason:s}}}\",\n \"focusElement\": \"function fe(){try{typeof this.focus==\\\"function\\\"&&this.focus()}catch{}}\",\n \"isElementChecked\": \"function ge(){try{let e=this;if((e.tagName||\\\"\\\").toLowerCase()===\\\"input\\\"){let o=e.type?.toLowerCase()??\\\"\\\";if(o===\\\"checkbox\\\"||o===\\\"radio\\\")return!!e.checked}let n=e.getAttribute?.(\\\"aria-checked\\\");return n!=null?n===\\\"true\\\":!1}catch{return!1}}\",\n \"isElementVisible\": \"function pe(){try{let e=this;if(!e.isConnected)return!1;let t=e.ownerDocument?.defaultView?.getComputedStyle(e)??window.getComputedStyle(e);if(!t||t.display===\\\"none\\\"||t.visibility===\\\"hidden\\\")return!1;let n=parseFloat(t.opacity??\\\"1\\\");if(!Number.isFinite(n)||n===0)return!1;let o=e.getBoundingClientRect();return!(!o||Math.max(o.width,o.height)===0||e.getClientRects().length===0)}catch{return!1}}\",\n \"prepareElementForTyping\": \"function v(){try{let e=this;if(!e.isConnected)return!1;let t=e.ownerDocument||document,n=t.defaultView||window;try{typeof e.focus==\\\"function\\\"&&e.focus()}catch{}if(e instanceof n.HTMLInputElement||e instanceof n.HTMLTextAreaElement){try{if(typeof e.select==\\\"function\\\")return e.select(),!0}catch{}try{let o=(e.value??\\\"\\\").length;if(typeof e.setSelectionRange==\\\"function\\\")return e.setSelectionRange(0,o),!0}catch{}return!0}if(e.isContentEditable){let o=t.getSelection?.(),r=t.createRange?.();if(o&&r)try{r.selectNodeContents(e),o.removeAllRanges(),o.addRange(r)}catch{}return!0}return!1}catch{return!1}}\",\n \"readElementInnerHTML\": \"function ye(){try{return String(this.innerHTML??\\\"\\\")}catch{return\\\"\\\"}}\",\n \"readElementInnerText\": \"function be(){try{let e=this,t=e.innerText;if(typeof t==\\\"string\\\"&&t.length>0)return t;let n=e.textContent;return typeof n==\\\"string\\\"?n:\\\"\\\"}catch{return\\\"\\\"}}\",\n \"readElementInputValue\": \"function Ee(){try{let e=this,t=(e.tagName||\\\"\\\").toLowerCase();return t===\\\"input\\\"||t===\\\"textarea\\\"||t===\\\"select\\\"?String(e.value??\\\"\\\"):e.isContentEditable?String(e.textContent??\\\"\\\"):\\\"\\\"}catch{return\\\"\\\"}}\",\n \"readElementTextContent\": \"function we(){try{return String(this.textContent??\\\"\\\")}catch{return\\\"\\\"}}\",\n \"resolveCssSelector\": \"function Ne(e,t){let n=String(e??\\\"\\\").trim();if(!n)return null;let o=C(t);return z(n,o+1)[o]??null}\",\n \"resolveCssSelectorPierce\": \"function Ce(e,t){let n=String(e??\\\"\\\").trim();if(!n)return null;let o=C(t),r=window.__stagehandV3__;if(!r||typeof r.getClosedRoot!=\\\"function\\\")return z(n,o+1)[o]??null;let l=c=>{try{return r.getClosedRoot(c)??null}catch{return null}},s=new WeakSet,i=new Set,a=[],d=[document],f=c=>{if(!(!c||s.has(c)||a.length>=o+1)){s.add(c);try{let p=c.querySelectorAll(n);for(let g of p)if(!i.has(g)&&(i.add(g),a.push(g),a.length>=o+1))return}catch{}try{let g=(c instanceof Document?c:c.host?.ownerDocument??document).createTreeWalker(c,NodeFilter.SHOW_ELEMENT),w;for(;w=g.nextNode();){if(!(w instanceof Element))continue;let x=w.shadowRoot;x&&d.push(x);let y=l(w);y&&d.push(y)}}catch{}}};for(;d.length&&a.length<o+1;){let c=d.shift();c&&f(c)}return a[o]??null}\",\n \"resolveTextSelector\": \"function Me(e,t){let n=String(e??\\\"\\\");if(!n)return null;let o=n.toLowerCase(),r=C(t),l=new Set([\\\"SCRIPT\\\",\\\"STYLE\\\",\\\"TEMPLATE\\\",\\\"NOSCRIPT\\\",\\\"HEAD\\\",\\\"TITLE\\\",\\\"LINK\\\",\\\"META\\\",\\\"HTML\\\",\\\"BODY\\\"]),s=u=>{if(!u)return!1;let h=u.tagName?.toUpperCase()??\\\"\\\";return l.has(h)},i=u=>{try{if(s(u))return\\\"\\\";let h=u.innerText;if(typeof h==\\\"string\\\"&&h.trim())return h.trim()}catch{}try{let h=u.textContent;if(typeof h==\\\"string\\\")return h.trim()}catch{}return\\\"\\\"},a=u=>{let h=i(u);return!!h&&h.toLowerCase().includes(o)},d=window.__stagehandV3__,f=d&&typeof d.getClosedRoot==\\\"function\\\"?u=>{try{return d.getClosedRoot(u)??null}catch{return null}}:u=>null,c=new WeakSet,p=[],g=[],w=u=>{!u||c.has(u)||(c.add(u),p.push(u))},x=u=>{try{return(u instanceof Document?u:u?.ownerDocument??document).createTreeWalker(u,NodeFilter.SHOW_ELEMENT)}catch{return null}};for(w(document);p.length;){let u=p.shift();if(!u)continue;u instanceof Element&&a(u)&&g.push({element:u,tag:u.tagName??\\\"\\\",id:u.id??\\\"\\\",className:u.className??\\\"\\\",text:i(u)});let h=x(u);if(!h)continue;let E;for(;E=h.nextNode();){if(!(E instanceof Element))continue;a(E)&&g.push({element:E,tag:E.tagName??\\\"\\\",id:E.id??\\\"\\\",className:E.className??\\\"\\\",text:i(E)});let b=E.shadowRoot;b&&w(b);let k=f(E);k&&w(k)}}let y=[];for(let u of g){let h=u.element,E=!1;for(let b of g)if(u!==b)try{if(h.contains(b.element)){E=!0;break}}catch{}E||y.push(u)}return y[r]?.element??null}\",\n \"resolveXPathMainWorld\": \"function Le(e,t){let n=C(t);return P(e,n,{pierceShadow:!0})}\",\n \"scrollElementToPercent\": \"function de(e){let t=n=>{if(typeof n==\\\"number\\\"&&Number.isFinite(n))return n;let o=String(n??\\\"\\\").trim();if(!o)return 0;let r=parseFloat(o.replace(\\\"%\\\",\\\"\\\"));return Number.isNaN(r)||!Number.isFinite(r)?0:r};try{let n=Math.max(0,Math.min(t(e),100)),o=this,r=o.tagName?.toLowerCase()??\\\"\\\";if(r===\\\"html\\\"||r===\\\"body\\\"){let c=(o.ownerDocument?.scrollingElement||o.ownerDocument?.documentElement||o.ownerDocument?.body||document.scrollingElement||document.documentElement||document.body)?.scrollHeight??document.body.scrollHeight??0,p=o.ownerDocument?.defaultView?.innerHeight??window.innerHeight,w=Math.max(0,c-p)*(n/100);return o.ownerDocument?.defaultView?.scrollTo({top:w,left:o.ownerDocument?.defaultView?.scrollX??window.scrollX??0,behavior:\\\"smooth\\\"}),!0}let s=o.scrollHeight??0,i=o.clientHeight??0,d=Math.max(0,s-i)*(n/100);return o.scrollTo({top:d,left:o.scrollLeft??0,behavior:\\\"smooth\\\"}),!0}catch{return!1}}\",\n \"selectElementOptions\": \"function he(e){try{if(!(this instanceof HTMLSelectElement))return[];let t=Array.isArray(e)?e:[e],n=new Set(t.map(s=>String(s??\\\"\\\").trim())),o=s=>{let i=(s.label||s.textContent||\\\"\\\").trim(),a=String(s.value??\\\"\\\").trim();return n.has(i)||n.has(a)};if(this.multiple)for(let s of Array.from(this.options))s.selected=o(s);else{let s=!1;for(let i of Array.from(this.options))!s&&o(i)?(i.selected=!0,this.value=i.value,s=!0):i.selected=!1}let r=new Event(\\\"input\\\",{bubbles:!0}),l=new Event(\\\"change\\\",{bubbles:!0});return this.dispatchEvent(r),this.dispatchEvent(l),Array.from(this.selectedOptions).map(s=>s.value)}catch{return[]}}\",\n \"waitForSelector\": \"function qe(e,t,n,o){let r=String(e??\\\"\\\").trim(),l=String(t??\\\"visible\\\")||\\\"visible\\\",s=typeof n==\\\"number\\\"&&n>0?n:3e4,i=o!==!1;return new Promise((a,d)=>{let f=null,c=null,p=!1,g=()=>{f!==null&&(clearTimeout(f),f=null)},w=V(r,i);if(B(w,l)){p=!0,a(!0);return}let x=[],y=()=>{for(let E of x)E.disconnect();c&&(document.removeEventListener(\\\"DOMContentLoaded\\\",c),c=null)},m=()=>{if(p)return;let E=V(r,i);B(E,l)&&(p=!0,g(),y(),a(!0))};if(!(document.body||document.documentElement)){c=()=>{document.removeEventListener(\\\"DOMContentLoaded\\\",c),c=null,m(),h()},document.addEventListener(\\\"DOMContentLoaded\\\",c),f=setTimeout(()=>{p||(p=!0,g(),y(),d(new Error(`waitForSelector: Timeout ${s}ms exceeded waiting for \\\"${r}\\\" to be ${l}`)))},s);return}let h=()=>{let E=document.body||document.documentElement;if(!E)return;let b=new MutationObserver(m);b.observe(E,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[\\\"style\\\",\\\"class\\\",\\\"hidden\\\",\\\"disabled\\\"]}),x.push(b),i&&ie(m,x)};h(),f=setTimeout(()=>{p||(p=!0,g(),y(),d(new Error(`waitForSelector: Timeout ${s}ms exceeded waiting for \\\"${r}\\\" to be ${l}`)))},s)})}\"\n} as const;\nexport const locatorScriptGlobalRefs = {\n \"assignFilePayloadsToInputElement\": \"globalThis.__stagehandLocatorScripts.assignFilePayloadsToInputElement\",\n \"countCssMatchesPierce\": \"globalThis.__stagehandLocatorScripts.countCssMatchesPierce\",\n \"countCssMatchesPrimary\": \"globalThis.__stagehandLocatorScripts.countCssMatchesPrimary\",\n \"countTextMatches\": \"globalThis.__stagehandLocatorScripts.countTextMatches\",\n \"countXPathMatchesMainWorld\": \"globalThis.__stagehandLocatorScripts.countXPathMatchesMainWorld\",\n \"dispatchDomClick\": \"globalThis.__stagehandLocatorScripts.dispatchDomClick\",\n \"ensureFileInputElement\": \"globalThis.__stagehandLocatorScripts.ensureFileInputElement\",\n \"fillElementValue\": \"globalThis.__stagehandLocatorScripts.fillElementValue\",\n \"focusElement\": \"globalThis.__stagehandLocatorScripts.focusElement\",\n \"isElementChecked\": \"globalThis.__stagehandLocatorScripts.isElementChecked\",\n \"isElementVisible\": \"globalThis.__stagehandLocatorScripts.isElementVisible\",\n \"prepareElementForTyping\": \"globalThis.__stagehandLocatorScripts.prepareElementForTyping\",\n \"readElementInnerHTML\": \"globalThis.__stagehandLocatorScripts.readElementInnerHTML\",\n \"readElementInnerText\": \"globalThis.__stagehandLocatorScripts.readElementInnerText\",\n \"readElementInputValue\": \"globalThis.__stagehandLocatorScripts.readElementInputValue\",\n \"readElementTextContent\": \"globalThis.__stagehandLocatorScripts.readElementTextContent\",\n \"resolveCssSelector\": \"globalThis.__stagehandLocatorScripts.resolveCssSelector\",\n \"resolveCssSelectorPierce\": \"globalThis.__stagehandLocatorScripts.resolveCssSelectorPierce\",\n \"resolveTextSelector\": \"globalThis.__stagehandLocatorScripts.resolveTextSelector\",\n \"resolveXPathMainWorld\": \"globalThis.__stagehandLocatorScripts.resolveXPathMainWorld\",\n \"scrollElementToPercent\": \"globalThis.__stagehandLocatorScripts.scrollElementToPercent\",\n \"selectElementOptions\": \"globalThis.__stagehandLocatorScripts.selectElementOptions\",\n \"waitForSelector\": \"globalThis.__stagehandLocatorScripts.waitForSelector\"\n} as const;\nexport type LocatorScriptName = keyof typeof locatorScriptSources;\n"]}
1
+ {"version":3,"file":"locatorScripts.generated.js","sourceRoot":"","sources":["../../../../../../lib/v3/dom/build/locatorScripts.generated.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,0kvBAA0kvB,CAAC;AACjnvB,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,kCAAkC,EAAE,8tBAA8tB;IAClwB,uBAAuB,EAAE,ktBAAktB;IAC3uB,wBAAwB,EAAE,sgBAAsgB;IAChiB,kBAAkB,EAAE,ugDAAugD;IAC3hD,4BAA4B,EAAE,+CAA+C;IAC7E,kBAAkB,EAAE,yRAAyR;IAC7S,wBAAwB,EAAE,8IAA8I;IACxK,kBAAkB,EAAE,mlDAAmlD;IACvmD,cAAc,EAAE,0EAA0E;IAC1F,kBAAkB,EAAE,8PAA8P;IAClR,kBAAkB,EAAE,mZAAmZ;IACva,yBAAyB,EAAE,imBAAimB;IAC5nB,sBAAsB,EAAE,0EAA0E;IAClG,sBAAsB,EAAE,mKAAmK;IAC3L,uBAAuB,EAAE,qNAAqN;IAC9O,wBAAwB,EAAE,4EAA4E;IACtG,oBAAoB,EAAE,sGAAsG;IAC5H,0BAA0B,EAAE,8uBAA8uB;IAC1wB,qBAAqB,EAAE,o5CAAo5C;IAC36C,uBAAuB,EAAE,8DAA8D;IACvF,wBAAwB,EAAE,45BAA45B;IACt7B,sBAAsB,EAAE,snBAAsnB;IAC9oB,iBAAiB,EAAE,+lCAA+lC;CAC1mC,CAAC;AACX,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,kCAAkC,EAAE,uEAAuE;IAC3G,uBAAuB,EAAE,4DAA4D;IACrF,wBAAwB,EAAE,6DAA6D;IACvF,kBAAkB,EAAE,uDAAuD;IAC3E,4BAA4B,EAAE,iEAAiE;IAC/F,kBAAkB,EAAE,uDAAuD;IAC3E,wBAAwB,EAAE,6DAA6D;IACvF,kBAAkB,EAAE,uDAAuD;IAC3E,cAAc,EAAE,mDAAmD;IACnE,kBAAkB,EAAE,uDAAuD;IAC3E,kBAAkB,EAAE,uDAAuD;IAC3E,yBAAyB,EAAE,8DAA8D;IACzF,sBAAsB,EAAE,2DAA2D;IACnF,sBAAsB,EAAE,2DAA2D;IACnF,uBAAuB,EAAE,4DAA4D;IACrF,wBAAwB,EAAE,6DAA6D;IACvF,oBAAoB,EAAE,yDAAyD;IAC/E,0BAA0B,EAAE,+DAA+D;IAC3F,qBAAqB,EAAE,0DAA0D;IACjF,uBAAuB,EAAE,4DAA4D;IACrF,wBAAwB,EAAE,6DAA6D;IACvF,sBAAsB,EAAE,2DAA2D;IACnF,iBAAiB,EAAE,sDAAsD;CACjE,CAAC","sourcesContent":["/*\n * AUTO-GENERATED FILE. DO NOT EDIT.\n * Run `pnpm run build-dom-scripts` to regenerate.\n */\nexport const locatorScriptBootstrap = \"if (!globalThis.__stagehandLocatorScripts) { var __stagehandLocatorScriptsFactory=(()=>{var L=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var J=Object.prototype.hasOwnProperty;var tt=(t,e)=>{for(var n in e)L(t,n,{get:e[n],enumerable:!0})},et=(t,e,n,o)=>{if(e&&typeof e==\\\"object\\\"||typeof e==\\\"function\\\")for(let r of j(e))!J.call(t,r)&&r!==n&&L(t,r,{get:()=>e[r],enumerable:!(o=Z(e,r))||o.enumerable});return t};var nt=t=>et(L({},\\\"__esModule\\\",{value:!0}),t);var Xt={};tt(Xt,{assignFilePayloadsToInputElement:()=>rt,countCssMatchesPierce:()=>kt,countCssMatchesPrimary:()=>Pt,countTextMatches:()=>Dt,countXPathMatchesMainWorld:()=>Ht,dispatchDomClick:()=>st,ensureFileInputElement:()=>ot,fillElementValue:()=>it,focusElement:()=>ct,isElementChecked:()=>ht,isElementVisible:()=>mt,prepareElementForTyping:()=>v,readElementInnerHTML:()=>pt,readElementInnerText:()=>gt,readElementInputValue:()=>ft,readElementTextContent:()=>dt,resolveCssSelector:()=>Ct,resolveCssSelectorPierce:()=>Mt,resolveTextSelector:()=>Nt,resolveXPathMainWorld:()=>Lt,scrollElementToPercent:()=>lt,selectElementOptions:()=>ut,waitForSelector:()=>Ft});function ot(){try{return(this.tagName?.toLowerCase()??\\\"\\\")!==\\\"input\\\"?!1:String(this.type??\\\"\\\").toLowerCase()===\\\"file\\\"}catch{return!1}}function rt(t){try{let e=this;if(!e||e.tagName?.toLowerCase()!==\\\"input\\\"||(e.type??\\\"\\\").toLowerCase()!==\\\"file\\\")return!1;let n=(()=>{try{return new DataTransfer}catch{return null}})();if(!n)return!1;let o=Array.isArray(t)?t:[];for(let r of o){if(!r)continue;let l=r.name||\\\"upload.bin\\\",s=r.mimeType||\\\"application/octet-stream\\\",a=typeof r.lastModified==\\\"number\\\"?r.lastModified:Date.now(),i=window.atob(r.base64??\\\"\\\"),m=new Uint8Array(i.length);for(let p=0;p<i.length;p+=1)m[p]=i.charCodeAt(p);let f=new Blob([m],{type:s}),c=new File([f],l,{type:s,lastModified:a});n.items.add(c)}return e.files=n.files,e.dispatchEvent(new Event(\\\"input\\\",{bubbles:!0})),e.dispatchEvent(new Event(\\\"change\\\",{bubbles:!0})),!0}catch{return!1}}function st(t){let e=t??{};try{let n=new MouseEvent(\\\"click\\\",{bubbles:!!e.bubbles,cancelable:!!e.cancelable,composed:!!e.composed,detail:typeof e.detail==\\\"number\\\"?e.detail:1,view:this?.ownerDocument?.defaultView??window});this.dispatchEvent(n)}catch{try{this.click()}catch{}}}function lt(t){let e=n=>{if(typeof n==\\\"number\\\"&&Number.isFinite(n))return n;let o=String(n??\\\"\\\").trim();if(!o)return 0;let r=parseFloat(o.replace(\\\"%\\\",\\\"\\\"));return Number.isNaN(r)||!Number.isFinite(r)?0:r};try{let n=Math.max(0,Math.min(e(t),100)),o=this,r=o.tagName?.toLowerCase()??\\\"\\\";if(r===\\\"html\\\"||r===\\\"body\\\"){let c=(o.ownerDocument?.scrollingElement||o.ownerDocument?.documentElement||o.ownerDocument?.body||document.scrollingElement||document.documentElement||document.body)?.scrollHeight??document.body.scrollHeight??0,p=o.ownerDocument?.defaultView?.innerHeight??window.innerHeight,w=Math.max(0,c-p)*(n/100);return o.ownerDocument?.defaultView?.scrollTo({top:w,left:o.ownerDocument?.defaultView?.scrollX??window.scrollX??0,behavior:\\\"smooth\\\"}),!0}let s=o.scrollHeight??0,a=o.clientHeight??0,m=Math.max(0,s-a)*(n/100);return o.scrollTo({top:m,left:o.scrollLeft??0,behavior:\\\"smooth\\\"}),!0}catch{return!1}}var W=new Set([\\\"color\\\",\\\"date\\\",\\\"datetime-local\\\",\\\"month\\\",\\\"range\\\",\\\"time\\\",\\\"week\\\"]),at=new Set([\\\"\\\",\\\"email\\\",\\\"number\\\",\\\"password\\\",\\\"search\\\",\\\"tel\\\",\\\"text\\\",\\\"url\\\"]);function v(){try{let t=this;if(!t.isConnected)return!1;let e=t.ownerDocument||document,n=e.defaultView||window;try{typeof t.focus==\\\"function\\\"&&t.focus()}catch{}if(t instanceof n.HTMLInputElement||t instanceof n.HTMLTextAreaElement){try{if(typeof t.select==\\\"function\\\")return t.select(),!0}catch{}try{let o=(t.value??\\\"\\\").length;if(typeof t.setSelectionRange==\\\"function\\\")return t.setSelectionRange(0,o),!0}catch{}return!0}if(t.isContentEditable){let o=e.getSelection?.(),r=e.createRange?.();if(o&&r)try{r.selectNodeContents(t),o.removeAllRanges(),o.addRange(r)}catch{}return!0}return!1}catch{return!1}}function it(t){let e=this;if(!e.isConnected)return{status:\\\"error\\\",reason:\\\"notconnected\\\"};let o=(e.ownerDocument||document).defaultView||window,r=t??\\\"\\\";try{let l=s=>{let a;if(typeof o.InputEvent==\\\"function\\\")try{a=new o.InputEvent(\\\"input\\\",{bubbles:!0,composed:!0,data:s,inputType:\\\"insertText\\\"})}catch{a=new o.Event(\\\"input\\\",{bubbles:!0,composed:!0})}else a=new o.Event(\\\"input\\\",{bubbles:!0,composed:!0});e.dispatchEvent(a);let i=new o.Event(\\\"change\\\",{bubbles:!0});e.dispatchEvent(i)};if(e instanceof o.HTMLInputElement){let s=(e.type||\\\"\\\").toLowerCase();if(!at.has(s)&&!W.has(s))return{status:\\\"error\\\",reason:`unsupported-input-type:${s}`};let a=t;if(s===\\\"number\\\"){let i=t.trim();if(i!==\\\"\\\"&&Number.isNaN(Number(i)))return{status:\\\"error\\\",reason:\\\"invalid-number-value\\\"};a=i}if(r=a,W.has(s)){let i=t.trim();r=i,v.call(e);let m=o.HTMLInputElement.prototype,c=Object.getOwnPropertyDescriptor(m,\\\"value\\\")?.set;return typeof c==\\\"function\\\"?c.call(e,i):e.value=i,e._valueTracker?.setValue?.(i),e.value!==i?{status:\\\"error\\\",reason:\\\"malformed-value\\\"}:(l(i),{status:\\\"done\\\"})}return v.call(e),{status:\\\"needsinput\\\",value:a}}return e instanceof o.HTMLTextAreaElement?(v.call(e),r=t,{status:\\\"needsinput\\\",value:t}):e instanceof o.HTMLSelectElement?{status:\\\"error\\\",reason:\\\"unsupported-element\\\"}:e.isContentEditable?(v.call(e),r=t,{status:\\\"needsinput\\\",value:t}):{status:\\\"error\\\",reason:\\\"unsupported-element\\\"}}catch(l){let s=\\\"exception\\\";if(l&&typeof l==\\\"object\\\"){let a=l.message;typeof a==\\\"string\\\"&&a.trim().length>0&&(s=`exception:${a}`)}return{status:\\\"needsinput\\\",value:r,reason:s}}}function ct(){try{typeof this.focus==\\\"function\\\"&&this.focus()}catch{}}function ut(t){try{if(!(this instanceof HTMLSelectElement))return[];let e=Array.isArray(t)?t:[t],n=new Set(e.map(s=>String(s??\\\"\\\").trim())),o=s=>{let a=(s.label||s.textContent||\\\"\\\").trim(),i=String(s.value??\\\"\\\").trim();return n.has(a)||n.has(i)};if(this.multiple)for(let s of Array.from(this.options))s.selected=o(s);else{let s=!1;for(let a of Array.from(this.options))!s&&o(a)?(a.selected=!0,this.value=a.value,s=!0):a.selected=!1}let r=new Event(\\\"input\\\",{bubbles:!0}),l=new Event(\\\"change\\\",{bubbles:!0});return this.dispatchEvent(r),this.dispatchEvent(l),Array.from(this.selectedOptions).map(s=>s.value)}catch{return[]}}function mt(){try{let t=this;if(!t.isConnected)return!1;let e=t.ownerDocument?.defaultView?.getComputedStyle(t)??window.getComputedStyle(t);if(!e||e.display===\\\"none\\\"||e.visibility===\\\"hidden\\\")return!1;let n=parseFloat(e.opacity??\\\"1\\\");if(!Number.isFinite(n)||n===0)return!1;let o=t.getBoundingClientRect();return!(!o||Math.max(o.width,o.height)===0||t.getClientRects().length===0)}catch{return!1}}function ht(){try{let t=this;if((t.tagName||\\\"\\\").toLowerCase()===\\\"input\\\"){let o=t.type?.toLowerCase()??\\\"\\\";if(o===\\\"checkbox\\\"||o===\\\"radio\\\")return!!t.checked}let n=t.getAttribute?.(\\\"aria-checked\\\");return n!=null?n===\\\"true\\\":!1}catch{return!1}}function ft(){try{let t=this,e=(t.tagName||\\\"\\\").toLowerCase();return e===\\\"input\\\"||e===\\\"textarea\\\"||e===\\\"select\\\"?String(t.value??\\\"\\\"):t.isContentEditable?String(t.textContent??\\\"\\\"):\\\"\\\"}catch{return\\\"\\\"}}function dt(){try{return String(this.textContent??\\\"\\\")}catch{return\\\"\\\"}}function pt(){try{return String(this.innerHTML??\\\"\\\")}catch{return\\\"\\\"}}function gt(){try{let t=this,e=t.innerText;if(typeof e==\\\"string\\\"&&e.length>0)return e;let n=t.textContent;return typeof n==\\\"string\\\"?n:\\\"\\\"}catch{return\\\"\\\"}}function P(t){let e=String(t||\\\"\\\").trim().replace(/^xpath=/i,\\\"\\\");if(!e)return[];let n=[],o=0;for(;o<e.length;){let r=\\\"child\\\";e.startsWith(\\\"//\\\",o)?(r=\\\"desc\\\",o+=2):e[o]===\\\"/\\\"&&(r=\\\"child\\\",o+=1);let l=o,s=0,a=null;for(;o<e.length;){let c=e[o];if(a)c===a&&(a=null);else if(c===\\\"'\\\"||c==='\\\"')a=c;else if(c===\\\"[\\\")s++;else if(c===\\\"]\\\")s--;else if(c===\\\"/\\\"&&s===0)break;o+=1}let i=e.slice(l,o).trim();if(!i)continue;let{tag:m,predicates:f}=wt(i);n.push({axis:r,tag:m,predicates:f})}return n}function Et(t){let e=[],n=0;for(;n<t.length;){if(t[n]!==\\\"[\\\"){n++;continue}n++;let o=n,r=null;for(;n<t.length;){let l=t[n];if(r)l===r&&(r=null);else if(l===\\\"'\\\"||l==='\\\"')r=l;else if(l===\\\"]\\\")break;n++}e.push(t.slice(o,n).trim()),n++}return e}function wt(t){let e=t.indexOf(\\\"[\\\");if(e===-1)return{tag:t===\\\"\\\"?\\\"*\\\":t.toLowerCase(),predicates:[]};let n=t.slice(0,e).trim(),o=n===\\\"\\\"?\\\"*\\\":n.toLowerCase(),r=t.slice(e),l=[];for(let s of Et(r)){let a=T(s);a&&l.push(a)}return{tag:o,predicates:l}}function T(t){let e=t.trim();if(!e)return null;let n=_(e,\\\"or\\\");if(n.length>1){let l=n.map(s=>T(s)).filter(Boolean);return l.length!==n.length?null:{type:\\\"or\\\",predicates:l}}let o=_(e,\\\"and\\\");if(o.length>1){let l=o.map(s=>T(s)).filter(Boolean);return l.length!==o.length?null:{type:\\\"and\\\",predicates:l}}let r=xt(e,\\\"not\\\");if(r!=null){let l=T(r);return l?{type:\\\"not\\\",predicate:l}:null}return yt(e)}function yt(t){let e=/^(?:'([^']*)'|\\\"([^\\\"]*)\\\")$/,n=\\\"[a-zA-Z_][\\\\\\\\w.-]*\\\",o=`(?:'([^']*)'|\\\"([^\\\"]*)\\\")`;if(/^\\\\d+$/.test(t))return{type:\\\"index\\\",index:Math.max(1,Number(t))};let r=t.match(new RegExp(`^normalize-space\\\\\\\\(\\\\\\\\s*@(${n})\\\\\\\\s*\\\\\\\\)\\\\\\\\s*=\\\\\\\\s*${o}$`));if(r)return{type:\\\"attrEquals\\\",name:r[1],value:r[2]??r[3]??\\\"\\\",normalize:!0};let l=t.match(new RegExp(`^normalize-space\\\\\\\\(\\\\\\\\s*(?:text\\\\\\\\(\\\\\\\\)|\\\\\\\\.)\\\\\\\\s*\\\\\\\\)\\\\\\\\s*=\\\\\\\\s*${o}$`));if(l)return{type:\\\"textEquals\\\",value:l[1]??l[2]??\\\"\\\",normalize:!0};let s=t.match(new RegExp(`^@(${n})\\\\\\\\s*=\\\\\\\\s*${o}$`));if(s)return{type:\\\"attrEquals\\\",name:s[1],value:s[2]??s[3]??\\\"\\\"};let a=t.match(new RegExp(`^@(${n})$`));if(a)return{type:\\\"attrExists\\\",name:a[1]};let i=t.match(new RegExp(`^contains\\\\\\\\(\\\\\\\\s*@(${n})\\\\\\\\s*,\\\\\\\\s*${o}\\\\\\\\s*\\\\\\\\)$`));if(i)return{type:\\\"attrContains\\\",name:i[1],value:i[2]??i[3]??\\\"\\\"};let m=t.match(new RegExp(`^starts-with\\\\\\\\(\\\\\\\\s*@(${n})\\\\\\\\s*,\\\\\\\\s*${o}\\\\\\\\s*\\\\\\\\)$`));if(m)return{type:\\\"attrStartsWith\\\",name:m[1],value:m[2]??m[3]??\\\"\\\"};let f=t.match(new RegExp(`^(?:text\\\\\\\\(\\\\\\\\)|\\\\\\\\.)\\\\\\\\s*=\\\\\\\\s*${o}$`));if(f)return{type:\\\"textEquals\\\",value:f[1]??f[2]??\\\"\\\"};let c=t.match(new RegExp(`^contains\\\\\\\\(\\\\\\\\s*(?:text\\\\\\\\(\\\\\\\\)|\\\\\\\\.)\\\\\\\\s*,\\\\\\\\s*${o}\\\\\\\\s*\\\\\\\\)$`));return c?{type:\\\"textContains\\\",value:c[1]??c[2]??\\\"\\\"}:(e.test(t),null)}function _(t,e){let n=[],o=0,r=0,l=null,s=0;for(;s<t.length;){let a=t[s];if(l){a===l&&(l=null),s+=1;continue}if(a===\\\"'\\\"||a==='\\\"'){l=a,s+=1;continue}if(a===\\\"(\\\"){r+=1,s+=1;continue}if(a===\\\")\\\"){r=Math.max(0,r-1),s+=1;continue}if(r===0&&bt(t,s,e)){n.push(t.slice(o,s).trim()),s+=e.length,o=s;continue}s+=1}return n.push(t.slice(o).trim()),n.filter(a=>a.length>0)}function bt(t,e,n){if(!t.startsWith(n,e))return!1;let o=e>0?t[e-1]:\\\" \\\";if(o===\\\"@\\\")return!1;let r=e+n.length<t.length?t[e+n.length]:\\\" \\\";return O(o)&&O(r)}function O(t){return!/[a-zA-Z0-9_.-]/.test(t)}function xt(t,e){let n=`${e}(`;if(!t.startsWith(n)||!t.endsWith(\\\")\\\"))return null;let o=t.slice(n.length,-1);return St(o)?o:null}function St(t){let e=0,n=null;for(let o=0;o<t.length;o+=1){let r=t[o];if(n){r===n&&(n=null);continue}if(r===\\\"'\\\"||r==='\\\"'){n=r;continue}if(r===\\\"(\\\"?e+=1:r===\\\")\\\"&&(e-=1),e<0)return!1}return e===0}var vt=t=>t.replace(/\\\\s+/g,\\\" \\\").trim();function q(t){return String(t.textContent??\\\"\\\")}function S(t,e){return e?vt(t):t}function R(t,e){switch(e.type){case\\\"and\\\":return e.predicates.every(n=>R(t,n));case\\\"or\\\":return e.predicates.some(n=>R(t,n));case\\\"not\\\":return!R(t,e.predicate);case\\\"attrExists\\\":return t.getAttribute(e.name)!==null;case\\\"attrEquals\\\":{let n=t.getAttribute(e.name);return n===null?!1:S(n,e.normalize)===S(e.value,e.normalize)}case\\\"attrContains\\\":{let n=t.getAttribute(e.name);return n===null?!1:S(n,e.normalize).includes(S(e.value,e.normalize))}case\\\"attrStartsWith\\\":{let n=t.getAttribute(e.name);return n===null?!1:S(n,e.normalize).startsWith(S(e.value,e.normalize))}case\\\"textEquals\\\":return S(q(t),e.normalize)===S(e.value,e.normalize);case\\\"textContains\\\":return S(q(t),e.normalize).includes(S(e.value,e.normalize));case\\\"index\\\":return!0;default:return!0}}function k(t,e){let n=t;for(let o of e){if(!n.length)return[];if(o.type===\\\"index\\\"){let r=o.index-1;n=r>=0&&r<n.length?[n[r]]:[];continue}n=n.filter(r=>R(r,o))}return n}var M=t=>{let e=String(t??\\\"\\\").trim();return e?e.replace(/^xpath=/i,\\\"\\\").trim():\\\"\\\"};function I(t,e){return H(t,0,e)}function H(t,e,n){if(!Number.isFinite(e)||e<0)return null;let o=M(t);if(!o)return null;let r=Math.floor(e),l=n?.pierceShadow!==!1,s=l?B():null;if(!l)return F(o,r).value;if(!s?.hasShadow){let m=F(o,r);return m.error?C(o,s?.getClosedRoot)[r]??null:m.value}let a=C(o,s.getClosedRoot);return a.length>0?a[r]??null:z(o,s.getClosedRoot)[r]??null}function $(t,e){let n=M(t);if(!n)return 0;let o=e?.pierceShadow!==!1,r=o?B():null;if(!o)return X(n).count;if(!r?.hasShadow){let s=X(n);return s.error?C(n,r?.getClosedRoot).length:s.count}let l=C(n,r.getClosedRoot).length;return l>0?l:z(n,r.getClosedRoot).length}function C(t,e){let n=M(t);if(!n)return[];let o=P(n);if(!o.length)return[];let r=e??null,l=[document];for(let s of o){let a=[],i=new Set;for(let m of l){let f=s.axis===\\\"child\\\"?D(m,r):G(m,r);if(!f.length)continue;let c=f.filter(g=>V(g,s)),p=k(c,s.predicates);for(let g of p)i.has(g)||(i.add(g),a.push(g))}if(!a.length)return[];l=a}return l}function z(t,e){let n=M(t);if(!n)return[];let o=P(n);if(!o.some((s,a)=>s.axis===\\\"desc\\\"&&a>0))return[];let r=e??null,l=[document];for(let s=0;s<o.length;s+=1){let a=o[s],i=[],m=new Set;for(let f of l){let c=a.axis===\\\"child\\\"?Tt(f):s===0?G(f,r):Rt(f,r);if(!c.length)continue;let p=c.filter(w=>V(w,a)),g=k(p,a.predicates);for(let w of g)m.has(w)||(m.add(w),i.push(w))}if(!i.length)return[];l=i}return l}function V(t,e){return e.tag===\\\"*\\\"?!0:t.localName===e.tag}function B(){let t=window.__stagehandV3__,e=t&&typeof t.getClosedRoot==\\\"function\\\"?o=>{try{return t.getClosedRoot(o)??null}catch{return null}}:null,n=!1;try{if(t&&typeof t.stats==\\\"function\\\"){let o=t.stats();n=(o?.open??0)>0||(o?.closed??0)>0}}catch{}if(!n)try{let o=document.createTreeWalker(document,NodeFilter.SHOW_ELEMENT);for(;o.nextNode();)if(o.currentNode.shadowRoot){n=!0;break}}catch{}return{getClosedRoot:e,hasShadow:n}}function D(t,e){let n=[];if(t instanceof Document)return t.documentElement&&n.push(t.documentElement),n;if(t instanceof ShadowRoot||t instanceof DocumentFragment)return n.push(...Array.from(t.children??[])),n;if(t instanceof Element){n.push(...Array.from(t.children??[]));let o=t.shadowRoot;if(o&&n.push(...Array.from(o.children??[])),e){let r=e(t);r&&n.push(...Array.from(r.children??[]))}return n}return n}function Tt(t){let e=[];return t instanceof Document?(t.documentElement&&e.push(t.documentElement),e):t instanceof ShadowRoot||t instanceof DocumentFragment?(e.push(...Array.from(t.children??[])),e):(t instanceof Element&&e.push(...Array.from(t.children??[])),e)}function Rt(t,e){let n=[];if(!(t instanceof Element))return n;let o=t.shadowRoot;if(o&&n.push(...Array.from(o.children??[])),e){let r=e(t);r&&n.push(...Array.from(r.children??[]))}return n}function G(t,e){let n=[],o=new Set,r=[...D(t,e)].reverse();for(;r.length;){let l=r.pop();if(o.has(l))continue;o.add(l),n.push(l);let s=D(l,e);for(let a=s.length-1;a>=0;a-=1)r.push(s[a])}return n}function F(t,e){try{return{value:document.evaluate(t,document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotItem(e),error:!1}}catch{return{value:null,error:!0}}}function X(t){try{return{count:document.evaluate(t,document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotLength,error:!1}}catch{return{count:0,error:!0}}}var N=t=>{let e=Number(t??0);return!Number.isFinite(e)||e<0?0:Math.floor(e)},Y=(t,e)=>{if(!t)return[];let n=new WeakSet,o=new Set,r=[],l=[document],s=a=>{if(!(!a||n.has(a)||r.length>=e)){n.add(a);try{let i=a.querySelectorAll(t);for(let m of i)if(!o.has(m)&&(o.add(m),r.push(m),r.length>=e))return}catch{}try{let m=(a instanceof Document?a:a.host?.ownerDocument??document).createTreeWalker(a,NodeFilter.SHOW_ELEMENT),f;for(;f=m.nextNode();){if(!(f instanceof Element))continue;let c=f.shadowRoot;c&&l.push(c)}}catch{}}};for(;l.length&&r.length<e;){let a=l.shift();a&&s(a)}return r};function Ct(t,e){let n=String(t??\\\"\\\").trim();if(!n)return null;let o=N(e);return Y(n,o+1)[o]??null}function Mt(t,e){let n=String(t??\\\"\\\").trim();if(!n)return null;let o=N(e),r=window.__stagehandV3__;if(!r||typeof r.getClosedRoot!=\\\"function\\\")return Y(n,o+1)[o]??null;let l=c=>{try{return r.getClosedRoot(c)??null}catch{return null}},s=new WeakSet,a=new Set,i=[],m=[document],f=c=>{if(!(!c||s.has(c)||i.length>=o+1)){s.add(c);try{let p=c.querySelectorAll(n);for(let g of p)if(!a.has(g)&&(a.add(g),i.push(g),i.length>=o+1))return}catch{}try{let g=(c instanceof Document?c:c.host?.ownerDocument??document).createTreeWalker(c,NodeFilter.SHOW_ELEMENT),w;for(;w=g.nextNode();){if(!(w instanceof Element))continue;let x=w.shadowRoot;x&&m.push(x);let y=l(w);y&&m.push(y)}}catch{}}};for(;m.length&&i.length<o+1;){let c=m.shift();c&&f(c)}return i[o]??null}function Nt(t,e){let n=String(t??\\\"\\\");if(!n)return null;let o=n.toLowerCase(),r=N(e),l=new Set([\\\"SCRIPT\\\",\\\"STYLE\\\",\\\"TEMPLATE\\\",\\\"NOSCRIPT\\\",\\\"HEAD\\\",\\\"TITLE\\\",\\\"LINK\\\",\\\"META\\\",\\\"HTML\\\",\\\"BODY\\\"]),s=u=>{if(!u)return!1;let d=u.tagName?.toUpperCase()??\\\"\\\";return l.has(d)},a=u=>{try{if(s(u))return\\\"\\\";let d=u.innerText;if(typeof d==\\\"string\\\"&&d.trim())return d.trim()}catch{}try{let d=u.textContent;if(typeof d==\\\"string\\\")return d.trim()}catch{}return\\\"\\\"},i=u=>{let d=a(u);return!!d&&d.toLowerCase().includes(o)},m=window.__stagehandV3__,f=m&&typeof m.getClosedRoot==\\\"function\\\"?u=>{try{return m.getClosedRoot(u)??null}catch{return null}}:u=>null,c=new WeakSet,p=[],g=[],w=u=>{!u||c.has(u)||(c.add(u),p.push(u))},x=u=>{try{return(u instanceof Document?u:u?.ownerDocument??document).createTreeWalker(u,NodeFilter.SHOW_ELEMENT)}catch{return null}};for(w(document);p.length;){let u=p.shift();if(!u)continue;u instanceof Element&&i(u)&&g.push({element:u,tag:u.tagName??\\\"\\\",id:u.id??\\\"\\\",className:u.className??\\\"\\\",text:a(u)});let d=x(u);if(!d)continue;let E;for(;E=d.nextNode();){if(!(E instanceof Element))continue;i(E)&&g.push({element:E,tag:E.tagName??\\\"\\\",id:E.id??\\\"\\\",className:E.className??\\\"\\\",text:a(E)});let b=E.shadowRoot;b&&w(b);let A=f(E);A&&w(A)}}let y=[];for(let u of g){let d=u.element,E=!1;for(let b of g)if(u!==b)try{if(d.contains(b.element)){E=!0;break}}catch{}E||y.push(u)}return y[r]?.element??null}function Lt(t,e){let n=N(e);return H(t,n,{pierceShadow:!0})}function Pt(t){let e=String(t??\\\"\\\").trim();if(!e)return 0;let n=new WeakSet,o=r=>{if(!r||n.has(r))return 0;n.add(r);let l=0;try{let s=r;typeof s.querySelectorAll==\\\"function\\\"&&(l+=s.querySelectorAll(e).length)}catch{}try{let a=(r instanceof Document?r:r?.ownerDocument??document).createTreeWalker(r,NodeFilter.SHOW_ELEMENT),i;for(;i=a.nextNode();)i instanceof Element&&i.shadowRoot&&(l+=o(i.shadowRoot))}catch{}return l};try{return o(document)}catch{try{return document.querySelectorAll(e).length}catch{return 0}}}function kt(t){let e=String(t??\\\"\\\").trim();if(!e)return 0;let n=window.__stagehandV3__;if(!n||typeof n.getClosedRoot!=\\\"function\\\")try{return document.querySelectorAll(e).length}catch{return 0}let o=new WeakSet,r=[],l=i=>{!i||o.has(i)||(o.add(i),r.push(i))};l(document);let s=0,a=i=>{let m=i.shadowRoot;m&&l(m);try{let f=n.getClosedRoot(i);f&&l(f)}catch{}};for(;r.length;){let i=r.shift();if(i){try{let m=i;typeof m.querySelectorAll==\\\"function\\\"&&(s+=m.querySelectorAll(e).length)}catch{}try{let f=(i instanceof Document?i:i instanceof ShadowRoot?i.host?.ownerDocument??document:i.ownerDocument??document).createTreeWalker(i,NodeFilter.SHOW_ELEMENT),c;for(;c=f.nextNode();)c instanceof Element&&a(c)}catch{}}}return s}function Dt(t){let e=String(t??\\\"\\\");if(!e)return{count:0,sample:[],error:null};let n=e.toLowerCase(),o=new Set([\\\"SCRIPT\\\",\\\"STYLE\\\",\\\"TEMPLATE\\\",\\\"NOSCRIPT\\\",\\\"HEAD\\\",\\\"TITLE\\\",\\\"LINK\\\",\\\"META\\\",\\\"HTML\\\",\\\"BODY\\\"]),r=h=>{if(!h)return!1;let u=h.tagName?.toUpperCase()??\\\"\\\";return o.has(u)},l=h=>{try{if(r(h))return\\\"\\\";let u=h.innerText;if(typeof u==\\\"string\\\"&&u.trim())return u.trim()}catch{}try{let u=h.textContent;if(typeof u==\\\"string\\\")return u.trim()}catch{}return\\\"\\\"},s=h=>{let u=l(h);return!!u&&u.toLowerCase().includes(n)},a=window.__stagehandV3__,i=a&&typeof a.getClosedRoot==\\\"function\\\"?h=>{try{return a.getClosedRoot(h)??null}catch{return null}}:h=>null,m=new WeakSet,f=[],c=h=>{!h||m.has(h)||(m.add(h),f.push(h))},p=h=>{try{return(h instanceof Document?h:h?.ownerDocument??document).createTreeWalker(h,NodeFilter.SHOW_ELEMENT)}catch{return null}},g=[];for(c(document);f.length;){let h=f.shift();if(!h)continue;h instanceof Element&&s(h)&&g.push({element:h,tag:h.tagName??\\\"\\\",id:h.id??\\\"\\\",className:h.className??\\\"\\\",text:l(h)});let u=p(h);if(!u)continue;let d;for(;d=u.nextNode();){if(!(d instanceof Element))continue;s(d)&&g.push({element:d,tag:d.tagName??\\\"\\\",id:d.id??\\\"\\\",className:d.className??\\\"\\\",text:l(d)});let E=d.shadowRoot;E&&c(E);let b=i(d);b&&c(b)}}let w=[];for(let h of g){let u=h.element,d=!1;for(let E of g)if(h!==E)try{if(u.contains(E.element)){d=!0;break}}catch{}d||w.push(h)}let x=w.length,y=w.slice(0,5).map(h=>({tag:h.tag,id:h.id,class:h.className,text:h.text}));return{count:x,sample:y,error:null}}function Ht(t){return $(t,{pierceShadow:!0})}var At=t=>t.startsWith(\\\"xpath=\\\")||t.startsWith(\\\"/\\\"),Wt=t=>{try{let e=window.__stagehandV3__;if(e&&typeof e.getClosedRoot==\\\"function\\\")return e.getClosedRoot(t)??null}catch{}return null},Q=t=>t.shadowRoot?t.shadowRoot:Wt(t),_t=(t,e,n)=>{try{let l=t.querySelector(e);if(l)return l}catch{}if(!n)return null;let o=new WeakSet,r=[t];for(;r.length>0;){let l=r.shift();if(!(!l||o.has(l))){o.add(l);try{let s=l.querySelector(e);if(s)return s}catch{}try{let a=(l instanceof Document?l:l.host?.ownerDocument??document).createTreeWalker(l,NodeFilter.SHOW_ELEMENT),i;for(;i=a.nextNode();){if(!(i instanceof Element))continue;let m=Q(i);m&&!o.has(m)&&r.push(m)}}catch{}}}return null},Ot=(t,e)=>I(t,{pierceShadow:e}),K=(t,e)=>At(t)?Ot(t,e):_t(document,t,e),U=(t,e)=>{if(e===\\\"detached\\\")return t===null;if(e===\\\"attached\\\")return t!==null;if(t===null)return!1;if(e===\\\"hidden\\\")try{let n=window.getComputedStyle(t),o=t.getBoundingClientRect();return n.display===\\\"none\\\"||n.visibility===\\\"hidden\\\"||n.opacity===\\\"0\\\"||o.width===0||o.height===0}catch{return!1}try{let n=window.getComputedStyle(t),o=t.getBoundingClientRect();return n.display!==\\\"none\\\"&&n.visibility!==\\\"hidden\\\"&&n.opacity!==\\\"0\\\"&&o.width>0&&o.height>0}catch{return!1}},qt=(t,e)=>{let n=new WeakSet,o=l=>{let s=Q(l);if(s&&!n.has(s)){n.add(s);let a=new MutationObserver(t);a.observe(s,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[\\\"style\\\",\\\"class\\\",\\\"hidden\\\",\\\"disabled\\\"]}),e.push(a);for(let i of Array.from(s.children))o(i)}for(let a of Array.from(l.children))o(a)},r=document.documentElement||document.body;r&&o(r)};function Ft(t,e,n,o){let r=String(t??\\\"\\\").trim(),l=String(e??\\\"visible\\\")||\\\"visible\\\",s=typeof n==\\\"number\\\"&&n>0?n:3e4,a=o!==!1;return new Promise((i,m)=>{let f=null,c=null,p=!1,g=()=>{f!==null&&(clearTimeout(f),f=null)},w=K(r,a);if(U(w,l)){p=!0,i(!0);return}let x=[],y=()=>{for(let E of x)E.disconnect();c&&(document.removeEventListener(\\\"DOMContentLoaded\\\",c),c=null)},h=()=>{if(p)return;let E=K(r,a);U(E,l)&&(p=!0,g(),y(),i(!0))};if(!(document.body||document.documentElement)){c=()=>{document.removeEventListener(\\\"DOMContentLoaded\\\",c),c=null,h(),d()},document.addEventListener(\\\"DOMContentLoaded\\\",c),f=setTimeout(()=>{p||(p=!0,g(),y(),m(new Error(`waitForSelector: Timeout ${s}ms exceeded waiting for \\\"${r}\\\" to be ${l}`)))},s);return}let d=()=>{let E=document.body||document.documentElement;if(!E)return;let b=new MutationObserver(h);b.observe(E,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[\\\"style\\\",\\\"class\\\",\\\"hidden\\\",\\\"disabled\\\"]}),x.push(b),a&&qt(h,x)};d(),f=setTimeout(()=>{p||(p=!0,g(),y(),m(new Error(`waitForSelector: Timeout ${s}ms exceeded waiting for \\\"${r}\\\" to be ${l}`)))},s)})}return nt(Xt);})();\\n globalThis.__stagehandLocatorScripts = __stagehandLocatorScriptsFactory;\\n}\";\nexport const locatorScriptSources = {\n \"assignFilePayloadsToInputElement\": \"function ht(t){try{let e=this;if(!e||e.tagName?.toLowerCase()!==\\\"input\\\"||(e.type??\\\"\\\").toLowerCase()!==\\\"file\\\")return!1;let n=(()=>{try{return new DataTransfer}catch{return null}})();if(!n)return!1;let o=Array.isArray(t)?t:[];for(let r of o){if(!r)continue;let l=r.name||\\\"upload.bin\\\",s=r.mimeType||\\\"application/octet-stream\\\",a=typeof r.lastModified==\\\"number\\\"?r.lastModified:Date.now(),i=window.atob(r.base64??\\\"\\\"),m=new Uint8Array(i.length);for(let p=0;p<i.length;p+=1)m[p]=i.charCodeAt(p);let f=new Blob([m],{type:s}),c=new File([f],l,{type:s,lastModified:a});n.items.add(c)}return e.files=n.files,e.dispatchEvent(new Event(\\\"input\\\",{bubbles:!0})),e.dispatchEvent(new Event(\\\"change\\\",{bubbles:!0})),!0}catch{return!1}}\",\n \"countCssMatchesPierce\": \"function _t(t){let e=String(t??\\\"\\\").trim();if(!e)return 0;let n=window.__stagehandV3__;if(!n||typeof n.getClosedRoot!=\\\"function\\\")try{return document.querySelectorAll(e).length}catch{return 0}let o=new WeakSet,r=[],l=i=>{!i||o.has(i)||(o.add(i),r.push(i))};l(document);let s=0,a=i=>{let m=i.shadowRoot;m&&l(m);try{let f=n.getClosedRoot(i);f&&l(f)}catch{}};for(;r.length;){let i=r.shift();if(i){try{let m=i;typeof m.querySelectorAll==\\\"function\\\"&&(s+=m.querySelectorAll(e).length)}catch{}try{let f=(i instanceof Document?i:i instanceof ShadowRoot?i.host?.ownerDocument??document:i.ownerDocument??document).createTreeWalker(i,NodeFilter.SHOW_ELEMENT),c;for(;c=f.nextNode();)c instanceof Element&&a(c)}catch{}}}return s}\",\n \"countCssMatchesPrimary\": \"function Wt(t){let e=String(t??\\\"\\\").trim();if(!e)return 0;let n=new WeakSet,o=r=>{if(!r||n.has(r))return 0;n.add(r);let l=0;try{let s=r;typeof s.querySelectorAll==\\\"function\\\"&&(l+=s.querySelectorAll(e).length)}catch{}try{let a=(r instanceof Document?r:r?.ownerDocument??document).createTreeWalker(r,NodeFilter.SHOW_ELEMENT),i;for(;i=a.nextNode();)i instanceof Element&&i.shadowRoot&&(l+=o(i.shadowRoot))}catch{}return l};try{return o(document)}catch{try{return document.querySelectorAll(e).length}catch{return 0}}}\",\n \"countTextMatches\": \"function Ot(t){let e=String(t??\\\"\\\");if(!e)return{count:0,sample:[],error:null};let n=e.toLowerCase(),o=new Set([\\\"SCRIPT\\\",\\\"STYLE\\\",\\\"TEMPLATE\\\",\\\"NOSCRIPT\\\",\\\"HEAD\\\",\\\"TITLE\\\",\\\"LINK\\\",\\\"META\\\",\\\"HTML\\\",\\\"BODY\\\"]),r=h=>{if(!h)return!1;let u=h.tagName?.toUpperCase()??\\\"\\\";return o.has(u)},l=h=>{try{if(r(h))return\\\"\\\";let u=h.innerText;if(typeof u==\\\"string\\\"&&u.trim())return u.trim()}catch{}try{let u=h.textContent;if(typeof u==\\\"string\\\")return u.trim()}catch{}return\\\"\\\"},s=h=>{let u=l(h);return!!u&&u.toLowerCase().includes(n)},a=window.__stagehandV3__,i=a&&typeof a.getClosedRoot==\\\"function\\\"?h=>{try{return a.getClosedRoot(h)??null}catch{return null}}:h=>null,m=new WeakSet,f=[],c=h=>{!h||m.has(h)||(m.add(h),f.push(h))},p=h=>{try{return(h instanceof Document?h:h?.ownerDocument??document).createTreeWalker(h,NodeFilter.SHOW_ELEMENT)}catch{return null}},g=[];for(c(document);f.length;){let h=f.shift();if(!h)continue;h instanceof Element&&s(h)&&g.push({element:h,tag:h.tagName??\\\"\\\",id:h.id??\\\"\\\",className:h.className??\\\"\\\",text:l(h)});let u=p(h);if(!u)continue;let d;for(;d=u.nextNode();){if(!(d instanceof Element))continue;s(d)&&g.push({element:d,tag:d.tagName??\\\"\\\",id:d.id??\\\"\\\",className:d.className??\\\"\\\",text:l(d)});let E=d.shadowRoot;E&&c(E);let b=i(d);b&&c(b)}}let w=[];for(let h of g){let u=h.element,d=!1;for(let E of g)if(h!==E)try{if(u.contains(E.element)){d=!0;break}}catch{}d||w.push(h)}let x=w.length,y=w.slice(0,5).map(h=>({tag:h.tag,id:h.id,class:h.className,text:h.text}));return{count:x,sample:y,error:null}}\",\n \"countXPathMatchesMainWorld\": \"function qt(t){return I(t,{pierceShadow:!0})}\",\n \"dispatchDomClick\": \"function ft(t){let e=t??{};try{let n=new MouseEvent(\\\"click\\\",{bubbles:!!e.bubbles,cancelable:!!e.cancelable,composed:!!e.composed,detail:typeof e.detail==\\\"number\\\"?e.detail:1,view:this?.ownerDocument?.defaultView??window});this.dispatchEvent(n)}catch{try{this.click()}catch{}}}\",\n \"ensureFileInputElement\": \"function mt(){try{return(this.tagName?.toLowerCase()??\\\"\\\")!==\\\"input\\\"?!1:String(this.type??\\\"\\\").toLowerCase()===\\\"file\\\"}catch{return!1}}\",\n \"fillElementValue\": \"function pt(t){let e=this;if(!e.isConnected)return{status:\\\"error\\\",reason:\\\"notconnected\\\"};let o=(e.ownerDocument||document).defaultView||window,r=t??\\\"\\\";try{let l=s=>{let a;if(typeof o.InputEvent==\\\"function\\\")try{a=new o.InputEvent(\\\"input\\\",{bubbles:!0,composed:!0,data:s,inputType:\\\"insertText\\\"})}catch{a=new o.Event(\\\"input\\\",{bubbles:!0,composed:!0})}else a=new o.Event(\\\"input\\\",{bubbles:!0,composed:!0});e.dispatchEvent(a);let i=new o.Event(\\\"change\\\",{bubbles:!0});e.dispatchEvent(i)};if(e instanceof o.HTMLInputElement){let s=(e.type||\\\"\\\").toLowerCase();if(!Q.has(s)&&!A.has(s))return{status:\\\"error\\\",reason:`unsupported-input-type:${s}`};let a=t;if(s===\\\"number\\\"){let i=t.trim();if(i!==\\\"\\\"&&Number.isNaN(Number(i)))return{status:\\\"error\\\",reason:\\\"invalid-number-value\\\"};a=i}if(r=a,A.has(s)){let i=t.trim();r=i,v.call(e);let m=o.HTMLInputElement.prototype,c=Object.getOwnPropertyDescriptor(m,\\\"value\\\")?.set;return typeof c==\\\"function\\\"?c.call(e,i):e.value=i,e._valueTracker?.setValue?.(i),e.value!==i?{status:\\\"error\\\",reason:\\\"malformed-value\\\"}:(l(i),{status:\\\"done\\\"})}return v.call(e),{status:\\\"needsinput\\\",value:a}}return e instanceof o.HTMLTextAreaElement?(v.call(e),r=t,{status:\\\"needsinput\\\",value:t}):e instanceof o.HTMLSelectElement?{status:\\\"error\\\",reason:\\\"unsupported-element\\\"}:e.isContentEditable?(v.call(e),r=t,{status:\\\"needsinput\\\",value:t}):{status:\\\"error\\\",reason:\\\"unsupported-element\\\"}}catch(l){let s=\\\"exception\\\";if(l&&typeof l==\\\"object\\\"){let a=l.message;typeof a==\\\"string\\\"&&a.trim().length>0&&(s=`exception:${a}`)}return{status:\\\"needsinput\\\",value:r,reason:s}}}\",\n \"focusElement\": \"function gt(){try{typeof this.focus==\\\"function\\\"&&this.focus()}catch{}}\",\n \"isElementChecked\": \"function yt(){try{let t=this;if((t.tagName||\\\"\\\").toLowerCase()===\\\"input\\\"){let o=t.type?.toLowerCase()??\\\"\\\";if(o===\\\"checkbox\\\"||o===\\\"radio\\\")return!!t.checked}let n=t.getAttribute?.(\\\"aria-checked\\\");return n!=null?n===\\\"true\\\":!1}catch{return!1}}\",\n \"isElementVisible\": \"function wt(){try{let t=this;if(!t.isConnected)return!1;let e=t.ownerDocument?.defaultView?.getComputedStyle(t)??window.getComputedStyle(t);if(!e||e.display===\\\"none\\\"||e.visibility===\\\"hidden\\\")return!1;let n=parseFloat(e.opacity??\\\"1\\\");if(!Number.isFinite(n)||n===0)return!1;let o=t.getBoundingClientRect();return!(!o||Math.max(o.width,o.height)===0||t.getClientRects().length===0)}catch{return!1}}\",\n \"prepareElementForTyping\": \"function v(){try{let t=this;if(!t.isConnected)return!1;let e=t.ownerDocument||document,n=e.defaultView||window;try{typeof t.focus==\\\"function\\\"&&t.focus()}catch{}if(t instanceof n.HTMLInputElement||t instanceof n.HTMLTextAreaElement){try{if(typeof t.select==\\\"function\\\")return t.select(),!0}catch{}try{let o=(t.value??\\\"\\\").length;if(typeof t.setSelectionRange==\\\"function\\\")return t.setSelectionRange(0,o),!0}catch{}return!0}if(t.isContentEditable){let o=e.getSelection?.(),r=e.createRange?.();if(o&&r)try{r.selectNodeContents(t),o.removeAllRanges(),o.addRange(r)}catch{}return!0}return!1}catch{return!1}}\",\n \"readElementInnerHTML\": \"function St(){try{return String(this.innerHTML??\\\"\\\")}catch{return\\\"\\\"}}\",\n \"readElementInnerText\": \"function vt(){try{let t=this,e=t.innerText;if(typeof e==\\\"string\\\"&&e.length>0)return e;let n=t.textContent;return typeof n==\\\"string\\\"?n:\\\"\\\"}catch{return\\\"\\\"}}\",\n \"readElementInputValue\": \"function bt(){try{let t=this,e=(t.tagName||\\\"\\\").toLowerCase();return e===\\\"input\\\"||e===\\\"textarea\\\"||e===\\\"select\\\"?String(t.value??\\\"\\\"):t.isContentEditable?String(t.textContent??\\\"\\\"):\\\"\\\"}catch{return\\\"\\\"}}\",\n \"readElementTextContent\": \"function xt(){try{return String(this.textContent??\\\"\\\")}catch{return\\\"\\\"}}\",\n \"resolveCssSelector\": \"function Lt(t,e){let n=String(t??\\\"\\\").trim();if(!n)return null;let o=N(e);return G(n,o+1)[o]??null}\",\n \"resolveCssSelectorPierce\": \"function Pt(t,e){let n=String(t??\\\"\\\").trim();if(!n)return null;let o=N(e),r=window.__stagehandV3__;if(!r||typeof r.getClosedRoot!=\\\"function\\\")return G(n,o+1)[o]??null;let l=c=>{try{return r.getClosedRoot(c)??null}catch{return null}},s=new WeakSet,a=new Set,i=[],m=[document],f=c=>{if(!(!c||s.has(c)||i.length>=o+1)){s.add(c);try{let p=c.querySelectorAll(n);for(let g of p)if(!a.has(g)&&(a.add(g),i.push(g),i.length>=o+1))return}catch{}try{let g=(c instanceof Document?c:c.host?.ownerDocument??document).createTreeWalker(c,NodeFilter.SHOW_ELEMENT),w;for(;w=g.nextNode();){if(!(w instanceof Element))continue;let x=w.shadowRoot;x&&m.push(x);let y=l(w);y&&m.push(y)}}catch{}}};for(;m.length&&i.length<o+1;){let c=m.shift();c&&f(c)}return i[o]??null}\",\n \"resolveTextSelector\": \"function kt(t,e){let n=String(t??\\\"\\\");if(!n)return null;let o=n.toLowerCase(),r=N(e),l=new Set([\\\"SCRIPT\\\",\\\"STYLE\\\",\\\"TEMPLATE\\\",\\\"NOSCRIPT\\\",\\\"HEAD\\\",\\\"TITLE\\\",\\\"LINK\\\",\\\"META\\\",\\\"HTML\\\",\\\"BODY\\\"]),s=u=>{if(!u)return!1;let d=u.tagName?.toUpperCase()??\\\"\\\";return l.has(d)},a=u=>{try{if(s(u))return\\\"\\\";let d=u.innerText;if(typeof d==\\\"string\\\"&&d.trim())return d.trim()}catch{}try{let d=u.textContent;if(typeof d==\\\"string\\\")return d.trim()}catch{}return\\\"\\\"},i=u=>{let d=a(u);return!!d&&d.toLowerCase().includes(o)},m=window.__stagehandV3__,f=m&&typeof m.getClosedRoot==\\\"function\\\"?u=>{try{return m.getClosedRoot(u)??null}catch{return null}}:u=>null,c=new WeakSet,p=[],g=[],w=u=>{!u||c.has(u)||(c.add(u),p.push(u))},x=u=>{try{return(u instanceof Document?u:u?.ownerDocument??document).createTreeWalker(u,NodeFilter.SHOW_ELEMENT)}catch{return null}};for(w(document);p.length;){let u=p.shift();if(!u)continue;u instanceof Element&&i(u)&&g.push({element:u,tag:u.tagName??\\\"\\\",id:u.id??\\\"\\\",className:u.className??\\\"\\\",text:a(u)});let d=x(u);if(!d)continue;let E;for(;E=d.nextNode();){if(!(E instanceof Element))continue;i(E)&&g.push({element:E,tag:E.tagName??\\\"\\\",id:E.id??\\\"\\\",className:E.className??\\\"\\\",text:a(E)});let b=E.shadowRoot;b&&w(b);let H=f(E);H&&w(H)}}let y=[];for(let u of g){let d=u.element,E=!1;for(let b of g)if(u!==b)try{if(d.contains(b.element)){E=!0;break}}catch{}E||y.push(u)}return y[r]?.element??null}\",\n \"resolveXPathMainWorld\": \"function Dt(t,e){let n=N(e);return D(t,n,{pierceShadow:!0})}\",\n \"scrollElementToPercent\": \"function dt(t){let e=n=>{if(typeof n==\\\"number\\\"&&Number.isFinite(n))return n;let o=String(n??\\\"\\\").trim();if(!o)return 0;let r=parseFloat(o.replace(\\\"%\\\",\\\"\\\"));return Number.isNaN(r)||!Number.isFinite(r)?0:r};try{let n=Math.max(0,Math.min(e(t),100)),o=this,r=o.tagName?.toLowerCase()??\\\"\\\";if(r===\\\"html\\\"||r===\\\"body\\\"){let c=(o.ownerDocument?.scrollingElement||o.ownerDocument?.documentElement||o.ownerDocument?.body||document.scrollingElement||document.documentElement||document.body)?.scrollHeight??document.body.scrollHeight??0,p=o.ownerDocument?.defaultView?.innerHeight??window.innerHeight,w=Math.max(0,c-p)*(n/100);return o.ownerDocument?.defaultView?.scrollTo({top:w,left:o.ownerDocument?.defaultView?.scrollX??window.scrollX??0,behavior:\\\"smooth\\\"}),!0}let s=o.scrollHeight??0,a=o.clientHeight??0,m=Math.max(0,s-a)*(n/100);return o.scrollTo({top:m,left:o.scrollLeft??0,behavior:\\\"smooth\\\"}),!0}catch{return!1}}\",\n \"selectElementOptions\": \"function Et(t){try{if(!(this instanceof HTMLSelectElement))return[];let e=Array.isArray(t)?t:[t],n=new Set(e.map(s=>String(s??\\\"\\\").trim())),o=s=>{let a=(s.label||s.textContent||\\\"\\\").trim(),i=String(s.value??\\\"\\\").trim();return n.has(a)||n.has(i)};if(this.multiple)for(let s of Array.from(this.options))s.selected=o(s);else{let s=!1;for(let a of Array.from(this.options))!s&&o(a)?(a.selected=!0,this.value=a.value,s=!0):a.selected=!1}let r=new Event(\\\"input\\\",{bubbles:!0}),l=new Event(\\\"change\\\",{bubbles:!0});return this.dispatchEvent(r),this.dispatchEvent(l),Array.from(this.selectedOptions).map(s=>s.value)}catch{return[]}}\",\n \"waitForSelector\": \"function It(t,e,n,o){let r=String(t??\\\"\\\").trim(),l=String(e??\\\"visible\\\")||\\\"visible\\\",s=typeof n==\\\"number\\\"&&n>0?n:3e4,a=o!==!1;return new Promise((i,m)=>{let f=null,c=null,p=!1,g=()=>{f!==null&&(clearTimeout(f),f=null)},w=Y(r,a);if(K(w,l)){p=!0,i(!0);return}let x=[],y=()=>{for(let E of x)E.disconnect();c&&(document.removeEventListener(\\\"DOMContentLoaded\\\",c),c=null)},h=()=>{if(p)return;let E=Y(r,a);K(E,l)&&(p=!0,g(),y(),i(!0))};if(!(document.body||document.documentElement)){c=()=>{document.removeEventListener(\\\"DOMContentLoaded\\\",c),c=null,h(),d()},document.addEventListener(\\\"DOMContentLoaded\\\",c),f=setTimeout(()=>{p||(p=!0,g(),y(),m(new Error(`waitForSelector: Timeout ${s}ms exceeded waiting for \\\"${r}\\\" to be ${l}`)))},s);return}let d=()=>{let E=document.body||document.documentElement;if(!E)return;let b=new MutationObserver(h);b.observe(E,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[\\\"style\\\",\\\"class\\\",\\\"hidden\\\",\\\"disabled\\\"]}),x.push(b),a&&ut(h,x)};d(),f=setTimeout(()=>{p||(p=!0,g(),y(),m(new Error(`waitForSelector: Timeout ${s}ms exceeded waiting for \\\"${r}\\\" to be ${l}`)))},s)})}\"\n} as const;\nexport const locatorScriptGlobalRefs = {\n \"assignFilePayloadsToInputElement\": \"globalThis.__stagehandLocatorScripts.assignFilePayloadsToInputElement\",\n \"countCssMatchesPierce\": \"globalThis.__stagehandLocatorScripts.countCssMatchesPierce\",\n \"countCssMatchesPrimary\": \"globalThis.__stagehandLocatorScripts.countCssMatchesPrimary\",\n \"countTextMatches\": \"globalThis.__stagehandLocatorScripts.countTextMatches\",\n \"countXPathMatchesMainWorld\": \"globalThis.__stagehandLocatorScripts.countXPathMatchesMainWorld\",\n \"dispatchDomClick\": \"globalThis.__stagehandLocatorScripts.dispatchDomClick\",\n \"ensureFileInputElement\": \"globalThis.__stagehandLocatorScripts.ensureFileInputElement\",\n \"fillElementValue\": \"globalThis.__stagehandLocatorScripts.fillElementValue\",\n \"focusElement\": \"globalThis.__stagehandLocatorScripts.focusElement\",\n \"isElementChecked\": \"globalThis.__stagehandLocatorScripts.isElementChecked\",\n \"isElementVisible\": \"globalThis.__stagehandLocatorScripts.isElementVisible\",\n \"prepareElementForTyping\": \"globalThis.__stagehandLocatorScripts.prepareElementForTyping\",\n \"readElementInnerHTML\": \"globalThis.__stagehandLocatorScripts.readElementInnerHTML\",\n \"readElementInnerText\": \"globalThis.__stagehandLocatorScripts.readElementInnerText\",\n \"readElementInputValue\": \"globalThis.__stagehandLocatorScripts.readElementInputValue\",\n \"readElementTextContent\": \"globalThis.__stagehandLocatorScripts.readElementTextContent\",\n \"resolveCssSelector\": \"globalThis.__stagehandLocatorScripts.resolveCssSelector\",\n \"resolveCssSelectorPierce\": \"globalThis.__stagehandLocatorScripts.resolveCssSelectorPierce\",\n \"resolveTextSelector\": \"globalThis.__stagehandLocatorScripts.resolveTextSelector\",\n \"resolveXPathMainWorld\": \"globalThis.__stagehandLocatorScripts.resolveXPathMainWorld\",\n \"scrollElementToPercent\": \"globalThis.__stagehandLocatorScripts.scrollElementToPercent\",\n \"selectElementOptions\": \"globalThis.__stagehandLocatorScripts.selectElementOptions\",\n \"waitForSelector\": \"globalThis.__stagehandLocatorScripts.waitForSelector\"\n} as const;\nexport type LocatorScriptName = keyof typeof locatorScriptSources;\n"]}
@@ -28,7 +28,11 @@ export function resolveXPathAtIndex(rawXp, index, options) {
28
28
  return composed[targetIndex] ?? null;
29
29
  }
30
30
  const composed = resolveXPathComposedMatches(xp, shadowCtx.getClosedRoot);
31
- return composed[targetIndex] ?? null;
31
+ if (composed.length > 0) {
32
+ return composed[targetIndex] ?? null;
33
+ }
34
+ const shadowHopMatches = resolveStagehandShadowHopMatches(xp, shadowCtx.getClosedRoot);
35
+ return shadowHopMatches[targetIndex] ?? null;
32
36
  }
33
37
  export function countXPathMatches(rawXp, options) {
34
38
  const xp = normalizeXPath(rawXp);
@@ -45,7 +49,10 @@ export function countXPathMatches(rawXp, options) {
45
49
  return count.count;
46
50
  return resolveXPathComposedMatches(xp, shadowCtx?.getClosedRoot).length;
47
51
  }
48
- return resolveXPathComposedMatches(xp, shadowCtx.getClosedRoot).length;
52
+ const composedCount = resolveXPathComposedMatches(xp, shadowCtx.getClosedRoot).length;
53
+ if (composedCount > 0)
54
+ return composedCount;
55
+ return resolveStagehandShadowHopMatches(xp, shadowCtx.getClosedRoot).length;
49
56
  }
50
57
  export function resolveXPathComposedMatches(rawXp, getClosedRoot) {
51
58
  const xp = normalizeXPath(rawXp);
@@ -55,15 +62,11 @@ export function resolveXPathComposedMatches(rawXp, getClosedRoot) {
55
62
  if (!steps.length)
56
63
  return [];
57
64
  const closedRoot = getClosedRoot ?? null;
58
- let current = [
59
- document,
60
- ];
65
+ let current = [document];
61
66
  for (const step of steps) {
62
67
  const next = [];
63
68
  const seen = new Set();
64
69
  for (const root of current) {
65
- if (!root)
66
- continue;
67
70
  const pool = step.axis === "child"
68
71
  ? composedChildren(root, closedRoot)
69
72
  : composedDescendants(root, closedRoot);
@@ -84,6 +87,43 @@ export function resolveXPathComposedMatches(rawXp, getClosedRoot) {
84
87
  }
85
88
  return current;
86
89
  }
90
+ function resolveStagehandShadowHopMatches(rawXp, getClosedRoot) {
91
+ const xp = normalizeXPath(rawXp);
92
+ if (!xp)
93
+ return [];
94
+ const steps = parseXPathSteps(xp);
95
+ if (!steps.some((step, index) => step.axis === "desc" && index > 0)) {
96
+ return [];
97
+ }
98
+ const closedRoot = getClosedRoot ?? null;
99
+ let current = [document];
100
+ for (let i = 0; i < steps.length; i += 1) {
101
+ const step = steps[i];
102
+ const next = [];
103
+ const seen = new Set();
104
+ for (const root of current) {
105
+ const pool = step.axis === "child"
106
+ ? domChildren(root)
107
+ : i === 0
108
+ ? composedDescendants(root, closedRoot)
109
+ : shadowRootChildren(root, closedRoot);
110
+ if (!pool.length)
111
+ continue;
112
+ const tagMatches = pool.filter((candidate) => matchesTag(candidate, step));
113
+ const matches = applyPredicates(tagMatches, step.predicates);
114
+ for (const candidate of matches) {
115
+ if (!seen.has(candidate)) {
116
+ seen.add(candidate);
117
+ next.push(candidate);
118
+ }
119
+ }
120
+ }
121
+ if (!next.length)
122
+ return [];
123
+ current = next;
124
+ }
125
+ return current;
126
+ }
87
127
  function matchesTag(element, step) {
88
128
  if (step.tag === "*")
89
129
  return true;
@@ -130,8 +170,6 @@ function getShadowContext() {
130
170
  }
131
171
  function composedChildren(node, getClosedRoot) {
132
172
  const out = [];
133
- if (!node)
134
- return out;
135
173
  if (node instanceof Document) {
136
174
  if (node.documentElement)
137
175
  out.push(node.documentElement);
@@ -155,13 +193,44 @@ function composedChildren(node, getClosedRoot) {
155
193
  }
156
194
  return out;
157
195
  }
196
+ function domChildren(node) {
197
+ const out = [];
198
+ if (node instanceof Document) {
199
+ if (node.documentElement)
200
+ out.push(node.documentElement);
201
+ return out;
202
+ }
203
+ if (node instanceof ShadowRoot || node instanceof DocumentFragment) {
204
+ out.push(...Array.from(node.children ?? []));
205
+ return out;
206
+ }
207
+ if (node instanceof Element) {
208
+ out.push(...Array.from(node.children ?? []));
209
+ return out;
210
+ }
211
+ return out;
212
+ }
213
+ function shadowRootChildren(node, getClosedRoot) {
214
+ const out = [];
215
+ if (!(node instanceof Element))
216
+ return out;
217
+ const open = node.shadowRoot;
218
+ if (open)
219
+ out.push(...Array.from(open.children ?? []));
220
+ if (getClosedRoot) {
221
+ const closed = getClosedRoot(node);
222
+ if (closed)
223
+ out.push(...Array.from(closed.children ?? []));
224
+ }
225
+ return out;
226
+ }
158
227
  function composedDescendants(node, getClosedRoot) {
159
228
  const out = [];
160
229
  const seen = new Set();
161
230
  const stack = [...composedChildren(node, getClosedRoot)].reverse();
162
231
  while (stack.length) {
163
232
  const next = stack.pop();
164
- if (!next || seen.has(next))
233
+ if (seen.has(next))
165
234
  continue;
166
235
  seen.add(next);
167
236
  out.push(next);
@@ -1 +1 @@
1
- {"version":3,"file":"xpathResolver.js","sourceRoot":"","sources":["../../../../../../lib/v3/dom/locatorScripts/xpathResolver.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,eAAe,GAEhB,MAAM,kBAAkB,CAAC;AAa1B,MAAM,cAAc,GAAG,CAAC,QAA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,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACtC,CAAC;AACH,CAAC;AAED,SAAS,2BAA2B,CAAC,EAAU;IAI7C,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAChC,EAAE,EACF,QAAQ,EACR,IAAI,EACJ,WAAW,CAAC,0BAA0B,EACtC,IAAI,CACL,CAAC;QACF,OAAO,EAAE,KAAK,EAAE,QAAQ,CAAC,cAAc,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;IAC1D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACnC,CAAC;AACH,CAAC","sourcesContent":["import {\n applyPredicates,\n parseXPathSteps,\n type XPathStep,\n} from \"./xpathParser.js\";\n\ntype ClosedRootGetter = (host: Element) => ShadowRoot | null;\n\nexport type XPathResolveOptions = {\n pierceShadow?: boolean;\n};\n\ntype ShadowContext = {\n getClosedRoot: ClosedRootGetter | null;\n hasShadow: boolean;\n};\n\nconst normalizeXPath = (selector: string): string => {\n const raw = String(selector ?? \"\").trim();\n if (!raw) return \"\";\n return raw.replace(/^xpath=/i, \"\").trim();\n};\n\nexport function resolveXPathFirst(\n rawXp: string,\n options?: XPathResolveOptions,\n): Element | null {\n return resolveXPathAtIndex(rawXp, 0, options);\n}\n\nexport function resolveXPathAtIndex(\n rawXp: string,\n index: number,\n options?: XPathResolveOptions,\n): Element | null {\n if (!Number.isFinite(index) || index < 0) return null;\n const xp = normalizeXPath(rawXp);\n if (!xp) return null;\n\n const targetIndex = Math.floor(index);\n const pierceShadow = options?.pierceShadow !== false;\n const shadowCtx = pierceShadow ? getShadowContext() : null;\n\n if (!pierceShadow) {\n return resolveNativeAtIndexWithError(xp, targetIndex).value;\n }\n\n if (!shadowCtx?.hasShadow) {\n const native = resolveNativeAtIndexWithError(xp, targetIndex);\n if (!native.error) return native.value;\n const composed = resolveXPathComposedMatches(xp, shadowCtx?.getClosedRoot);\n return composed[targetIndex] ?? null;\n }\n\n const composed = resolveXPathComposedMatches(xp, shadowCtx.getClosedRoot);\n return composed[targetIndex] ?? null;\n}\n\nexport function countXPathMatches(\n rawXp: string,\n options?: XPathResolveOptions,\n): number {\n const xp = normalizeXPath(rawXp);\n if (!xp) return 0;\n\n const pierceShadow = options?.pierceShadow !== false;\n const shadowCtx = pierceShadow ? getShadowContext() : null;\n\n if (!pierceShadow) {\n return resolveNativeCountWithError(xp).count;\n }\n\n if (!shadowCtx?.hasShadow) {\n const count = resolveNativeCountWithError(xp);\n if (!count.error) return count.count;\n return resolveXPathComposedMatches(xp, shadowCtx?.getClosedRoot).length;\n }\n\n return resolveXPathComposedMatches(xp, shadowCtx.getClosedRoot).length;\n}\n\nexport function resolveXPathComposedMatches(\n rawXp: string,\n getClosedRoot?: ClosedRootGetter | null,\n): Element[] {\n const xp = normalizeXPath(rawXp);\n if (!xp) return [];\n\n const steps = parseXPathSteps(xp);\n if (!steps.length) return [];\n\n const closedRoot = getClosedRoot ?? null;\n\n let current: Array<Document | Element | ShadowRoot | DocumentFragment> = [\n document,\n ];\n\n for (const step of steps) {\n const next: Element[] = [];\n const seen = new Set<Element>();\n\n for (const root of current) {\n if (!root) continue;\n const pool =\n step.axis === \"child\"\n ? composedChildren(root, closedRoot)\n : composedDescendants(root, closedRoot);\n if (!pool.length) continue;\n\n const tagMatches = pool.filter((candidate) =>\n matchesTag(candidate, step),\n );\n const matches = applyPredicates(tagMatches, step.predicates);\n\n for (const candidate of matches) {\n if (!seen.has(candidate)) {\n seen.add(candidate);\n next.push(candidate);\n }\n }\n }\n\n if (!next.length) return [];\n current = next;\n }\n\n return current as Element[];\n}\n\nfunction matchesTag(element: Element, step: XPathStep): boolean {\n if (step.tag === \"*\") return true;\n return element.localName === step.tag;\n}\n\nfunction getShadowContext(): ShadowContext {\n const backdoor = window.__stagehandV3__;\n const getClosedRoot: ClosedRootGetter | null =\n backdoor && typeof backdoor.getClosedRoot === \"function\"\n ? (host: Element): ShadowRoot | null => {\n try {\n return backdoor.getClosedRoot(host) ?? null;\n } catch {\n return null;\n }\n }\n : null;\n\n let hasShadow = false;\n try {\n if (backdoor && typeof backdoor.stats === \"function\") {\n const stats = backdoor.stats();\n hasShadow = (stats?.open ?? 0) > 0 || (stats?.closed ?? 0) > 0;\n }\n } catch {\n // ignore stats errors\n }\n\n if (!hasShadow) {\n try {\n const walker = document.createTreeWalker(\n document,\n NodeFilter.SHOW_ELEMENT,\n );\n while (walker.nextNode()) {\n const el = walker.currentNode as Element;\n if (el.shadowRoot) {\n hasShadow = true;\n break;\n }\n }\n } catch {\n // ignore scan errors\n }\n }\n\n return { getClosedRoot, hasShadow };\n}\n\nfunction composedChildren(\n node: Node | null | undefined,\n getClosedRoot: ClosedRootGetter | null,\n): Element[] {\n const out: Element[] = [];\n if (!node) return out;\n\n if (node instanceof Document) {\n if (node.documentElement) out.push(node.documentElement);\n return out;\n }\n\n if (node instanceof ShadowRoot || node instanceof DocumentFragment) {\n out.push(...Array.from(node.children ?? []));\n return out;\n }\n\n if (node instanceof Element) {\n out.push(...Array.from(node.children ?? []));\n const open = node.shadowRoot;\n if (open) out.push(...Array.from(open.children ?? []));\n if (getClosedRoot) {\n const closed = getClosedRoot(node);\n if (closed) out.push(...Array.from(closed.children ?? []));\n }\n return out;\n }\n\n return out;\n}\n\nfunction composedDescendants(\n node: Node | null | undefined,\n getClosedRoot: ClosedRootGetter | null,\n): Element[] {\n const out: Element[] = [];\n const seen = new Set<Element>();\n const stack = [...composedChildren(node, getClosedRoot)].reverse();\n\n while (stack.length) {\n const next = stack.pop();\n if (!next || seen.has(next)) continue;\n seen.add(next);\n out.push(next);\n\n const children = composedChildren(next, getClosedRoot);\n for (let i = children.length - 1; i >= 0; i -= 1) {\n stack.push(children[i]!);\n }\n }\n\n return out;\n}\n\nfunction resolveNativeAtIndexWithError(\n xp: string,\n index: number,\n): { value: Element | null; error: boolean } {\n try {\n const snapshot = document.evaluate(\n xp,\n document,\n null,\n XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,\n null,\n );\n return {\n value: snapshot.snapshotItem(index) as Element | null,\n error: false,\n };\n } catch {\n return { value: null, error: true };\n }\n}\n\nfunction resolveNativeCountWithError(xp: string): {\n count: number;\n error: boolean;\n} {\n try {\n const snapshot = document.evaluate(\n xp,\n document,\n null,\n XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,\n null,\n );\n return { count: snapshot.snapshotLength, error: false };\n } catch {\n return { count: 0, error: true };\n }\n}\n"]}
1
+ {"version":3,"file":"xpathResolver.js","sourceRoot":"","sources":["../../../../../../lib/v3/dom/locatorScripts/xpathResolver.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,eAAe,GAEhB,MAAM,kBAAkB,CAAC;AAc1B,MAAM,cAAc,GAAG,CAAC,QAAgB,EAAU,EAAE;IAClD,MAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAC1C,IAAI,CAAC,GAAG;QAAE,OAAO,EAAE,CAAC;IACpB,OAAO,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;AAC5C,CAAC,CAAC;AAEF,MAAM,UAAU,iBAAiB,CAC/B,KAAa,EACb,OAA6B;IAE7B,OAAO,mBAAmB,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;AAChD,CAAC;AAED,MAAM,UAAU,mBAAmB,CACjC,KAAa,EACb,KAAa,EACb,OAA6B;IAE7B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IACtD,MAAM,EAAE,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE;QAAE,OAAO,IAAI,CAAC;IAErB,MAAM,WAAW,GAAG,I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,EAAE,KAAK;SACb,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACtC,CAAC;AACH,CAAC;AAED,SAAS,2BAA2B,CAAC,EAAU;IAI7C,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAChC,EAAE,EACF,QAAQ,EACR,IAAI,EACJ,WAAW,CAAC,0BAA0B,EACtC,IAAI,CACL,CAAC;QACF,OAAO,EAAE,KAAK,EAAE,QAAQ,CAAC,cAAc,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;IAC1D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACnC,CAAC;AACH,CAAC","sourcesContent":["import {\n applyPredicates,\n parseXPathSteps,\n type XPathStep,\n} from \"./xpathParser.js\";\n\ntype ClosedRootGetter = (host: Element) => ShadowRoot | null;\ntype TraversalRoot = Document | Element | ShadowRoot | DocumentFragment;\n\nexport type XPathResolveOptions = {\n pierceShadow?: boolean;\n};\n\ntype ShadowContext = {\n getClosedRoot: ClosedRootGetter | null;\n hasShadow: boolean;\n};\n\nconst normalizeXPath = (selector: string): string => {\n const raw = String(selector ?? \"\").trim();\n if (!raw) return \"\";\n return raw.replace(/^xpath=/i, \"\").trim();\n};\n\nexport function resolveXPathFirst(\n rawXp: string,\n options?: XPathResolveOptions,\n): Element | null {\n return resolveXPathAtIndex(rawXp, 0, options);\n}\n\nexport function resolveXPathAtIndex(\n rawXp: string,\n index: number,\n options?: XPathResolveOptions,\n): Element | null {\n if (!Number.isFinite(index) || index < 0) return null;\n const xp = normalizeXPath(rawXp);\n if (!xp) return null;\n\n const targetIndex = Math.floor(index);\n const pierceShadow = options?.pierceShadow !== false;\n const shadowCtx = pierceShadow ? getShadowContext() : null;\n\n if (!pierceShadow) {\n return resolveNativeAtIndexWithError(xp, targetIndex).value;\n }\n\n if (!shadowCtx?.hasShadow) {\n const native = resolveNativeAtIndexWithError(xp, targetIndex);\n if (!native.error) return native.value;\n const composed = resolveXPathComposedMatches(xp, shadowCtx?.getClosedRoot);\n return composed[targetIndex] ?? null;\n }\n\n const composed = resolveXPathComposedMatches(xp, shadowCtx.getClosedRoot);\n if (composed.length > 0) {\n return composed[targetIndex] ?? null;\n }\n\n const shadowHopMatches = resolveStagehandShadowHopMatches(\n xp,\n shadowCtx.getClosedRoot,\n );\n return shadowHopMatches[targetIndex] ?? null;\n}\n\nexport function countXPathMatches(\n rawXp: string,\n options?: XPathResolveOptions,\n): number {\n const xp = normalizeXPath(rawXp);\n if (!xp) return 0;\n\n const pierceShadow = options?.pierceShadow !== false;\n const shadowCtx = pierceShadow ? getShadowContext() : null;\n\n if (!pierceShadow) {\n return resolveNativeCountWithError(xp).count;\n }\n\n if (!shadowCtx?.hasShadow) {\n const count = resolveNativeCountWithError(xp);\n if (!count.error) return count.count;\n return resolveXPathComposedMatches(xp, shadowCtx?.getClosedRoot).length;\n }\n\n const composedCount = resolveXPathComposedMatches(\n xp,\n shadowCtx.getClosedRoot,\n ).length;\n if (composedCount > 0) return composedCount;\n\n return resolveStagehandShadowHopMatches(xp, shadowCtx.getClosedRoot).length;\n}\n\nexport function resolveXPathComposedMatches(\n rawXp: string,\n getClosedRoot?: ClosedRootGetter | null,\n): Element[] {\n const xp = normalizeXPath(rawXp);\n if (!xp) return [];\n\n const steps = parseXPathSteps(xp);\n if (!steps.length) return [];\n\n const closedRoot = getClosedRoot ?? null;\n\n let current: TraversalRoot[] = [document];\n\n for (const step of steps) {\n const next: Element[] = [];\n const seen = new Set<Element>();\n\n for (const root of current) {\n const pool =\n step.axis === \"child\"\n ? composedChildren(root, closedRoot)\n : composedDescendants(root, closedRoot);\n if (!pool.length) continue;\n\n const tagMatches = pool.filter((candidate) =>\n matchesTag(candidate, step),\n );\n const matches = applyPredicates(tagMatches, step.predicates);\n\n for (const candidate of matches) {\n if (!seen.has(candidate)) {\n seen.add(candidate);\n next.push(candidate);\n }\n }\n }\n\n if (!next.length) return [];\n current = next;\n }\n\n return current as Element[];\n}\n\nfunction resolveStagehandShadowHopMatches(\n rawXp: string,\n getClosedRoot?: ClosedRootGetter | null,\n): Element[] {\n const xp = normalizeXPath(rawXp);\n if (!xp) return [];\n\n const steps = parseXPathSteps(xp);\n if (!steps.some((step, index) => step.axis === \"desc\" && index > 0)) {\n return [];\n }\n\n const closedRoot = getClosedRoot ?? null;\n let current: TraversalRoot[] = [document];\n\n for (let i = 0; i < steps.length; i += 1) {\n const step = steps[i]!;\n const next: Element[] = [];\n const seen = new Set<Element>();\n\n for (const root of current) {\n const pool =\n step.axis === \"child\"\n ? domChildren(root)\n : i === 0\n ? composedDescendants(root, closedRoot)\n : shadowRootChildren(root, closedRoot);\n if (!pool.length) continue;\n\n const tagMatches = pool.filter((candidate) =>\n matchesTag(candidate, step),\n );\n const matches = applyPredicates(tagMatches, step.predicates);\n\n for (const candidate of matches) {\n if (!seen.has(candidate)) {\n seen.add(candidate);\n next.push(candidate);\n }\n }\n }\n\n if (!next.length) return [];\n current = next;\n }\n\n return current as Element[];\n}\n\nfunction matchesTag(element: Element, step: XPathStep): boolean {\n if (step.tag === \"*\") return true;\n return element.localName === step.tag;\n}\n\nfunction getShadowContext(): ShadowContext {\n const backdoor = window.__stagehandV3__;\n const getClosedRoot: ClosedRootGetter | null =\n backdoor && typeof backdoor.getClosedRoot === \"function\"\n ? (host: Element): ShadowRoot | null => {\n try {\n return backdoor.getClosedRoot(host) ?? null;\n } catch {\n return null;\n }\n }\n : null;\n\n let hasShadow = false;\n try {\n if (backdoor && typeof backdoor.stats === \"function\") {\n const stats = backdoor.stats();\n hasShadow = (stats?.open ?? 0) > 0 || (stats?.closed ?? 0) > 0;\n }\n } catch {\n // ignore stats errors\n }\n\n if (!hasShadow) {\n try {\n const walker = document.createTreeWalker(\n document,\n NodeFilter.SHOW_ELEMENT,\n );\n while (walker.nextNode()) {\n const el = walker.currentNode as Element;\n if (el.shadowRoot) {\n hasShadow = true;\n break;\n }\n }\n } catch {\n // ignore scan errors\n }\n }\n\n return { getClosedRoot, hasShadow };\n}\n\nfunction composedChildren(\n node: TraversalRoot,\n getClosedRoot: ClosedRootGetter | null,\n): Element[] {\n const out: Element[] = [];\n\n if (node instanceof Document) {\n if (node.documentElement) out.push(node.documentElement);\n return out;\n }\n\n if (node instanceof ShadowRoot || node instanceof DocumentFragment) {\n out.push(...Array.from(node.children ?? []));\n return out;\n }\n\n if (node instanceof Element) {\n out.push(...Array.from(node.children ?? []));\n const open = node.shadowRoot;\n if (open) out.push(...Array.from(open.children ?? []));\n if (getClosedRoot) {\n const closed = getClosedRoot(node);\n if (closed) out.push(...Array.from(closed.children ?? []));\n }\n return out;\n }\n\n return out;\n}\n\nfunction domChildren(node: TraversalRoot): Element[] {\n const out: Element[] = [];\n\n if (node instanceof Document) {\n if (node.documentElement) out.push(node.documentElement);\n return out;\n }\n\n if (node instanceof ShadowRoot || node instanceof DocumentFragment) {\n out.push(...Array.from(node.children ?? []));\n return out;\n }\n\n if (node instanceof Element) {\n out.push(...Array.from(node.children ?? []));\n return out;\n }\n\n return out;\n}\n\nfunction shadowRootChildren(\n node: TraversalRoot,\n getClosedRoot: ClosedRootGetter | null,\n): Element[] {\n const out: Element[] = [];\n if (!(node instanceof Element)) return out;\n\n const open = node.shadowRoot;\n if (open) out.push(...Array.from(open.children ?? []));\n if (getClosedRoot) {\n const closed = getClosedRoot(node);\n if (closed) out.push(...Array.from(closed.children ?? []));\n }\n\n return out;\n}\n\nfunction composedDescendants(\n node: TraversalRoot,\n getClosedRoot: ClosedRootGetter | null,\n): Element[] {\n const out: Element[] = [];\n const seen = new Set<Element>();\n const stack = [...composedChildren(node, getClosedRoot)].reverse();\n\n while (stack.length) {\n const next = stack.pop()!;\n if (seen.has(next)) continue;\n seen.add(next);\n out.push(next);\n\n const children = composedChildren(next, getClosedRoot);\n for (let i = children.length - 1; i >= 0; i -= 1) {\n stack.push(children[i]!);\n }\n }\n\n return out;\n}\n\nfunction resolveNativeAtIndexWithError(\n xp: string,\n index: number,\n): { value: Element | null; error: boolean } {\n try {\n const snapshot = document.evaluate(\n xp,\n document,\n null,\n XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,\n null,\n );\n return {\n value: snapshot.snapshotItem(index) as Element | null,\n error: false,\n };\n } catch {\n return { value: null, error: true };\n }\n}\n\nfunction resolveNativeCountWithError(xp: string): {\n count: number;\n error: boolean;\n} {\n try {\n const snapshot = document.evaluate(\n xp,\n document,\n null,\n XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,\n null,\n );\n return { count: snapshot.snapshotLength, error: false };\n } catch {\n return { count: 0, error: true };\n }\n}\n"]}
@@ -12,12 +12,14 @@ export declare class V3AgentHandler {
12
12
  private mcpTools?;
13
13
  private mode;
14
14
  private captchaAutoSolveEnabled;
15
- constructor(v3: V3, logger: (message: LogLine) => void, llmClient: LLMClient, executionModel?: string | AgentModelConfig, systemInstructions?: string, mcpTools?: ToolSet, mode?: AgentToolMode, captchaAutoSolveEnabled?: boolean);
15
+ private thinkingEffort?;
16
+ constructor(v3: V3, logger: (message: LogLine) => void, llmClient: LLMClient, executionModel?: string | AgentModelConfig, systemInstructions?: string, mcpTools?: ToolSet, mode?: AgentToolMode, captchaAutoSolveEnabled?: boolean, thinkingEffort?: string);
16
17
  private prepareAgent;
17
18
  private createPrepareStep;
18
19
  private createStepHandler;
19
20
  execute(instructionOrOptions: string | AgentExecuteOptions): Promise<AgentResult>;
20
21
  stream(instructionOrOptions: string | AgentStreamExecuteOptions): Promise<AgentStreamResult>;
22
+ private emitFinalEvidence;
21
23
  private consolidateMetricsAndResult;
22
24
  private createTools;
23
25
  private handleStop;