@browserbasehq/orca 3.2.1-preview.3 → 3.4.0-preview-1

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 (223) hide show
  1. package/dist/cjs/lib/inference.js +1 -8
  2. package/dist/cjs/lib/inference.js.map +1 -1
  3. package/dist/cjs/lib/prompt.js +3 -1
  4. package/dist/cjs/lib/prompt.js.map +1 -1
  5. package/dist/cjs/lib/v3/agent/AgentProvider.js +3 -0
  6. package/dist/cjs/lib/v3/agent/AgentProvider.js.map +1 -1
  7. package/dist/cjs/lib/v3/agent/tools/fillFormVision.js +16 -12
  8. package/dist/cjs/lib/v3/agent/tools/fillFormVision.js.map +1 -1
  9. package/dist/cjs/lib/v3/agent/utils/validateExperimentalFeatures.js +0 -4
  10. package/dist/cjs/lib/v3/agent/utils/validateExperimentalFeatures.js.map +1 -1
  11. package/dist/cjs/lib/v3/api.d.ts +1 -0
  12. package/dist/cjs/lib/v3/api.js +15 -3
  13. package/dist/cjs/lib/v3/api.js.map +1 -1
  14. package/dist/cjs/lib/v3/dom/build/a11yScripts.generated.js +12 -12
  15. package/dist/cjs/lib/v3/dom/build/a11yScripts.generated.js.map +1 -1
  16. package/dist/cjs/lib/v3/dom/build/locatorScripts.generated.js +48 -48
  17. package/dist/cjs/lib/v3/dom/build/locatorScripts.generated.js.map +1 -1
  18. package/dist/cjs/lib/v3/dom/build/reRenderScriptContent.d.ts +1 -1
  19. package/dist/cjs/lib/v3/dom/build/reRenderScriptContent.js +1 -1
  20. package/dist/cjs/lib/v3/dom/build/reRenderScriptContent.js.map +1 -1
  21. package/dist/cjs/lib/v3/dom/build/screenshotScripts.generated.js +2 -2
  22. package/dist/cjs/lib/v3/dom/build/screenshotScripts.generated.js.map +1 -1
  23. package/dist/cjs/lib/v3/dom/build/scriptV3Content.d.ts +1 -1
  24. package/dist/cjs/lib/v3/dom/build/scriptV3Content.js +1 -1
  25. package/dist/cjs/lib/v3/dom/build/scriptV3Content.js.map +1 -1
  26. package/dist/cjs/lib/v3/dom/build/selectorRuntime.generated.d.ts +24 -0
  27. package/dist/cjs/lib/v3/dom/build/selectorRuntime.generated.js +31 -0
  28. package/dist/cjs/lib/v3/dom/build/selectorRuntime.generated.js.map +1 -0
  29. package/dist/cjs/lib/v3/handlers/extractHandler.js +3 -1
  30. package/dist/cjs/lib/v3/handlers/extractHandler.js.map +1 -1
  31. package/dist/cjs/lib/v3/handlers/observeHandler.js +2 -1
  32. package/dist/cjs/lib/v3/handlers/observeHandler.js.map +1 -1
  33. package/dist/cjs/lib/v3/handlers/v3AgentHandler.js +3 -5
  34. package/dist/cjs/lib/v3/handlers/v3AgentHandler.js.map +1 -1
  35. package/dist/cjs/lib/v3/index.d.ts +1 -1
  36. package/dist/cjs/lib/v3/llm/CerebrasClient.js +1 -1
  37. package/dist/cjs/lib/v3/llm/CerebrasClient.js.map +1 -1
  38. package/dist/cjs/lib/v3/llm/GroqClient.js +1 -1
  39. package/dist/cjs/lib/v3/llm/GroqClient.js.map +1 -1
  40. package/dist/cjs/lib/v3/types/private/agent.d.ts +5 -0
  41. package/dist/cjs/lib/v3/types/private/agent.js +11 -0
  42. package/dist/cjs/lib/v3/types/private/agent.js.map +1 -1
  43. package/dist/cjs/lib/v3/types/private/handlers.d.ts +2 -0
  44. package/dist/cjs/lib/v3/types/private/handlers.js.map +1 -1
  45. package/dist/cjs/lib/v3/types/private/snapshot.d.ts +8 -0
  46. package/dist/cjs/lib/v3/types/private/snapshot.js.map +1 -1
  47. package/dist/cjs/lib/v3/types/public/agent.d.ts +2 -3
  48. package/dist/cjs/lib/v3/types/public/agent.js +3 -0
  49. package/dist/cjs/lib/v3/types/public/agent.js.map +1 -1
  50. package/dist/cjs/lib/v3/types/public/api.d.ts +7 -1
  51. package/dist/cjs/lib/v3/types/public/api.js +22 -2
  52. package/dist/cjs/lib/v3/types/public/api.js.map +1 -1
  53. package/dist/cjs/lib/v3/types/public/methods.d.ts +2 -0
  54. package/dist/cjs/lib/v3/types/public/methods.js.map +1 -1
  55. package/dist/cjs/lib/v3/understudy/a11y/snapshot/a11yTree.js +21 -12
  56. package/dist/cjs/lib/v3/understudy/a11y/snapshot/a11yTree.js.map +1 -1
  57. package/dist/cjs/lib/v3/understudy/a11y/snapshot/capture.d.ts +11 -2
  58. package/dist/cjs/lib/v3/understudy/a11y/snapshot/capture.js +268 -21
  59. package/dist/cjs/lib/v3/understudy/a11y/snapshot/capture.js.map +1 -1
  60. package/dist/cjs/lib/v3/understudy/a11y/snapshot/domTree.js +60 -7
  61. package/dist/cjs/lib/v3/understudy/a11y/snapshot/domTree.js.map +1 -1
  62. package/dist/cjs/lib/v3/understudy/frameRegistry.js +16 -5
  63. package/dist/cjs/lib/v3/understudy/frameRegistry.js.map +1 -1
  64. package/dist/cjs/lib/v3/v3.d.ts +1 -0
  65. package/dist/cjs/lib/v3/v3.js +18 -14
  66. package/dist/cjs/lib/v3/v3.js.map +1 -1
  67. package/dist/cjs/lib/version.d.ts +1 -1
  68. package/dist/cjs/lib/version.js +1 -1
  69. package/dist/cjs/lib/version.js.map +1 -1
  70. package/dist/cjs/tests/integration/observe-element-id-format.spec.js +130 -0
  71. package/dist/cjs/tests/integration/observe-element-id-format.spec.js.map +1 -0
  72. package/dist/cjs/tests/unit/agent-mode-routing.test.js +88 -0
  73. package/dist/cjs/tests/unit/agent-mode-routing.test.js.map +1 -0
  74. package/dist/cjs/tests/unit/agent-temperature.test.d.ts +1 -0
  75. package/dist/cjs/tests/unit/agent-temperature.test.js +191 -0
  76. package/dist/cjs/tests/unit/agent-temperature.test.js.map +1 -0
  77. package/dist/cjs/tests/unit/agent-variables-validation.test.d.ts +1 -0
  78. package/dist/cjs/tests/unit/agent-variables-validation.test.js +43 -0
  79. package/dist/cjs/tests/unit/agent-variables-validation.test.js.map +1 -0
  80. package/dist/cjs/tests/unit/api-client-observe-variables.test.js +49 -0
  81. package/dist/cjs/tests/unit/api-client-observe-variables.test.js.map +1 -1
  82. package/dist/cjs/tests/unit/api-optional-model-api-key.test.js +60 -0
  83. package/dist/cjs/tests/unit/api-optional-model-api-key.test.js.map +1 -1
  84. package/dist/cjs/tests/unit/api-variables-schema.test.js +32 -0
  85. package/dist/cjs/tests/unit/api-variables-schema.test.js.map +1 -1
  86. package/dist/cjs/tests/unit/frame-registry-oopif-adoption.test.d.ts +1 -0
  87. package/dist/cjs/tests/unit/frame-registry-oopif-adoption.test.js +60 -0
  88. package/dist/cjs/tests/unit/frame-registry-oopif-adoption.test.js.map +1 -0
  89. package/dist/cjs/tests/unit/inference-temperature.test.d.ts +1 -0
  90. package/dist/cjs/tests/unit/inference-temperature.test.js +65 -0
  91. package/dist/cjs/tests/unit/inference-temperature.test.js.map +1 -0
  92. package/dist/cjs/tests/unit/openai-compatible-temperature.test.d.ts +1 -0
  93. package/dist/cjs/tests/unit/openai-compatible-temperature.test.js +84 -0
  94. package/dist/cjs/tests/unit/openai-compatible-temperature.test.js.map +1 -0
  95. package/dist/cjs/tests/unit/prompt-observe-variables.test.js +6 -0
  96. package/dist/cjs/tests/unit/prompt-observe-variables.test.js.map +1 -1
  97. package/dist/cjs/tests/unit/public-api/llm-and-agents.test.js +3 -0
  98. package/dist/cjs/tests/unit/public-api/llm-and-agents.test.js.map +1 -1
  99. package/dist/cjs/tests/unit/public-api/public-types.test.js.map +1 -1
  100. package/dist/cjs/tests/unit/snapshot-a11y-resolvers.test.js +106 -5
  101. package/dist/cjs/tests/unit/snapshot-a11y-resolvers.test.js.map +1 -1
  102. package/dist/cjs/tests/unit/snapshot-a11y-tree-utils.test.js +20 -0
  103. package/dist/cjs/tests/unit/snapshot-a11y-tree-utils.test.js.map +1 -1
  104. package/dist/cjs/tests/unit/snapshot-capture-orchestration.test.js +119 -9
  105. package/dist/cjs/tests/unit/snapshot-capture-orchestration.test.js.map +1 -1
  106. package/dist/cjs/tests/unit/timeout-handlers.test.js +36 -0
  107. package/dist/cjs/tests/unit/timeout-handlers.test.js.map +1 -1
  108. package/dist/esm/lib/inference.js +1 -8
  109. package/dist/esm/lib/inference.js.map +1 -1
  110. package/dist/esm/lib/prompt.js +3 -1
  111. package/dist/esm/lib/prompt.js.map +1 -1
  112. package/dist/esm/lib/v3/agent/AgentProvider.js +3 -0
  113. package/dist/esm/lib/v3/agent/AgentProvider.js.map +1 -1
  114. package/dist/esm/lib/v3/agent/tools/fillFormVision.js +16 -12
  115. package/dist/esm/lib/v3/agent/tools/fillFormVision.js.map +1 -1
  116. package/dist/esm/lib/v3/agent/utils/validateExperimentalFeatures.js +0 -4
  117. package/dist/esm/lib/v3/agent/utils/validateExperimentalFeatures.js.map +1 -1
  118. package/dist/esm/lib/v3/api.d.ts +1 -0
  119. package/dist/esm/lib/v3/api.js +15 -3
  120. package/dist/esm/lib/v3/api.js.map +1 -1
  121. package/dist/esm/lib/v3/dom/build/a11yScripts.generated.js +12 -12
  122. package/dist/esm/lib/v3/dom/build/a11yScripts.generated.js.map +1 -1
  123. package/dist/esm/lib/v3/dom/build/locatorScripts.generated.js +48 -48
  124. package/dist/esm/lib/v3/dom/build/locatorScripts.generated.js.map +1 -1
  125. package/dist/esm/lib/v3/dom/build/reRenderScriptContent.d.ts +1 -1
  126. package/dist/esm/lib/v3/dom/build/reRenderScriptContent.js +1 -1
  127. package/dist/esm/lib/v3/dom/build/reRenderScriptContent.js.map +1 -1
  128. package/dist/esm/lib/v3/dom/build/screenshotScripts.generated.js +2 -2
  129. package/dist/esm/lib/v3/dom/build/screenshotScripts.generated.js.map +1 -1
  130. package/dist/esm/lib/v3/dom/build/scriptV3Content.d.ts +1 -1
  131. package/dist/esm/lib/v3/dom/build/scriptV3Content.js +1 -1
  132. package/dist/esm/lib/v3/dom/build/scriptV3Content.js.map +1 -1
  133. package/dist/esm/lib/v3/dom/build/selectorRuntime.generated.d.ts +24 -0
  134. package/dist/esm/lib/v3/dom/build/selectorRuntime.generated.js +28 -0
  135. package/dist/esm/lib/v3/dom/build/selectorRuntime.generated.js.map +1 -0
  136. package/dist/esm/lib/v3/handlers/extractHandler.js +3 -1
  137. package/dist/esm/lib/v3/handlers/extractHandler.js.map +1 -1
  138. package/dist/esm/lib/v3/handlers/observeHandler.js +2 -1
  139. package/dist/esm/lib/v3/handlers/observeHandler.js.map +1 -1
  140. package/dist/esm/lib/v3/handlers/v3AgentHandler.js +3 -5
  141. package/dist/esm/lib/v3/handlers/v3AgentHandler.js.map +1 -1
  142. package/dist/esm/lib/v3/index.d.ts +1 -1
  143. package/dist/esm/lib/v3/llm/CerebrasClient.js +1 -1
  144. package/dist/esm/lib/v3/llm/CerebrasClient.js.map +1 -1
  145. package/dist/esm/lib/v3/llm/GroqClient.js +1 -1
  146. package/dist/esm/lib/v3/llm/GroqClient.js.map +1 -1
  147. package/dist/esm/lib/v3/types/private/agent.d.ts +5 -0
  148. package/dist/esm/lib/v3/types/private/agent.js +10 -1
  149. package/dist/esm/lib/v3/types/private/agent.js.map +1 -1
  150. package/dist/esm/lib/v3/types/private/handlers.d.ts +2 -0
  151. package/dist/esm/lib/v3/types/private/handlers.js.map +1 -1
  152. package/dist/esm/lib/v3/types/private/snapshot.d.ts +8 -0
  153. package/dist/esm/lib/v3/types/private/snapshot.js.map +1 -1
  154. package/dist/esm/lib/v3/types/public/agent.d.ts +2 -3
  155. package/dist/esm/lib/v3/types/public/agent.js +3 -0
  156. package/dist/esm/lib/v3/types/public/agent.js.map +1 -1
  157. package/dist/esm/lib/v3/types/public/api.d.ts +7 -1
  158. package/dist/esm/lib/v3/types/public/api.js +22 -2
  159. package/dist/esm/lib/v3/types/public/api.js.map +1 -1
  160. package/dist/esm/lib/v3/types/public/methods.d.ts +2 -0
  161. package/dist/esm/lib/v3/types/public/methods.js.map +1 -1
  162. package/dist/esm/lib/v3/understudy/a11y/snapshot/a11yTree.js +21 -12
  163. package/dist/esm/lib/v3/understudy/a11y/snapshot/a11yTree.js.map +1 -1
  164. package/dist/esm/lib/v3/understudy/a11y/snapshot/capture.d.ts +11 -2
  165. package/dist/esm/lib/v3/understudy/a11y/snapshot/capture.js +267 -22
  166. package/dist/esm/lib/v3/understudy/a11y/snapshot/capture.js.map +1 -1
  167. package/dist/esm/lib/v3/understudy/a11y/snapshot/domTree.js +60 -7
  168. package/dist/esm/lib/v3/understudy/a11y/snapshot/domTree.js.map +1 -1
  169. package/dist/esm/lib/v3/understudy/frameRegistry.js +16 -5
  170. package/dist/esm/lib/v3/understudy/frameRegistry.js.map +1 -1
  171. package/dist/esm/lib/v3/v3.d.ts +1 -0
  172. package/dist/esm/lib/v3/v3.js +18 -14
  173. package/dist/esm/lib/v3/v3.js.map +1 -1
  174. package/dist/esm/lib/version.d.ts +1 -1
  175. package/dist/esm/lib/version.js +1 -1
  176. package/dist/esm/lib/version.js.map +1 -1
  177. package/dist/esm/tests/integration/observe-element-id-format.spec.d.ts +1 -0
  178. package/dist/esm/tests/integration/observe-element-id-format.spec.js +128 -0
  179. package/dist/esm/tests/integration/observe-element-id-format.spec.js.map +1 -0
  180. package/dist/esm/tests/unit/agent-mode-routing.test.d.ts +1 -0
  181. package/dist/esm/tests/unit/agent-mode-routing.test.js +86 -0
  182. package/dist/esm/tests/unit/agent-mode-routing.test.js.map +1 -0
  183. package/dist/esm/tests/unit/agent-temperature.test.d.ts +1 -0
  184. package/dist/esm/tests/unit/agent-temperature.test.js +189 -0
  185. package/dist/esm/tests/unit/agent-temperature.test.js.map +1 -0
  186. package/dist/esm/tests/unit/agent-variables-validation.test.d.ts +1 -0
  187. package/dist/esm/tests/unit/agent-variables-validation.test.js +41 -0
  188. package/dist/esm/tests/unit/agent-variables-validation.test.js.map +1 -0
  189. package/dist/esm/tests/unit/api-client-observe-variables.test.js +49 -0
  190. package/dist/esm/tests/unit/api-client-observe-variables.test.js.map +1 -1
  191. package/dist/esm/tests/unit/api-optional-model-api-key.test.js +60 -0
  192. package/dist/esm/tests/unit/api-optional-model-api-key.test.js.map +1 -1
  193. package/dist/esm/tests/unit/api-variables-schema.test.js +32 -0
  194. package/dist/esm/tests/unit/api-variables-schema.test.js.map +1 -1
  195. package/dist/esm/tests/unit/frame-registry-oopif-adoption.test.d.ts +1 -0
  196. package/dist/esm/tests/unit/frame-registry-oopif-adoption.test.js +58 -0
  197. package/dist/esm/tests/unit/frame-registry-oopif-adoption.test.js.map +1 -0
  198. package/dist/esm/tests/unit/inference-temperature.test.d.ts +1 -0
  199. package/dist/esm/tests/unit/inference-temperature.test.js +63 -0
  200. package/dist/esm/tests/unit/inference-temperature.test.js.map +1 -0
  201. package/dist/esm/tests/unit/openai-compatible-temperature.test.d.ts +1 -0
  202. package/dist/esm/tests/unit/openai-compatible-temperature.test.js +82 -0
  203. package/dist/esm/tests/unit/openai-compatible-temperature.test.js.map +1 -0
  204. package/dist/esm/tests/unit/prompt-observe-variables.test.js +6 -0
  205. package/dist/esm/tests/unit/prompt-observe-variables.test.js.map +1 -1
  206. package/dist/esm/tests/unit/public-api/llm-and-agents.test.js +3 -0
  207. package/dist/esm/tests/unit/public-api/llm-and-agents.test.js.map +1 -1
  208. package/dist/esm/tests/unit/public-api/public-types.test.js.map +1 -1
  209. package/dist/esm/tests/unit/snapshot-a11y-resolvers.test.js +106 -5
  210. package/dist/esm/tests/unit/snapshot-a11y-resolvers.test.js.map +1 -1
  211. package/dist/esm/tests/unit/snapshot-a11y-tree-utils.test.js +20 -0
  212. package/dist/esm/tests/unit/snapshot-a11y-tree-utils.test.js.map +1 -1
  213. package/dist/esm/tests/unit/snapshot-capture-orchestration.test.js +119 -9
  214. package/dist/esm/tests/unit/snapshot-capture-orchestration.test.js.map +1 -1
  215. package/dist/esm/tests/unit/timeout-handlers.test.js +36 -0
  216. package/dist/esm/tests/unit/timeout-handlers.test.js.map +1 -1
  217. package/package.json +3 -3
  218. package/dist/cjs/tests/integration/agent-captcha-autosolve.spec.js +0 -56
  219. package/dist/cjs/tests/integration/agent-captcha-autosolve.spec.js.map +0 -1
  220. package/dist/esm/tests/integration/agent-captcha-autosolve.spec.js +0 -54
  221. package/dist/esm/tests/integration/agent-captcha-autosolve.spec.js.map +0 -1
  222. /package/dist/cjs/tests/integration/{agent-captcha-autosolve.spec.d.ts → observe-element-id-format.spec.d.ts} +0 -0
  223. /package/dist/{esm/tests/integration/agent-captcha-autosolve.spec.d.ts → cjs/tests/unit/agent-mode-routing.test.d.ts} +0 -0
@@ -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,GACjC,krsBAAkrsB,CAAC;AACrrsB,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,gCAAgC,EAC9B,4sBAA4sB;IAC9sB,qBAAqB,EACnB,4sBAA4sB;IAC9sB,sBAAsB,EACpB,kgBAAkgB;IACpgB,gBAAgB,EACd,y9CAAy9C;IAC39C,0BAA0B,EAAE,+CAA+C;IAC3E,gBAAgB,EACd,qRAAqR;IACvR,sBAAsB,EACpB,sIAAsI;IACxI,gBAAgB,EACd,qhDAAqhD;IACvhD,YAAY,EACV,wEAAwE;IAC1E,gBAAgB,EACd,gPAAgP;IAClP,gBAAgB,EACd,6YAA6Y;IAC/Y,uBAAuB,EACrB,ylBAAylB;IAC3lB,oBAAoB,EAClB,sEAAsE;IACxE,oBAAoB,EAClB,2JAA2J;IAC7J,qBAAqB,EACnB,qMAAqM;IACvM,sBAAsB,EACpB,wEAAwE;IAC1E,kBAAkB,EAChB,oGAAoG;IACtG,wBAAwB,EACtB,0uBAA0uB;IAC5uB,mBAAmB,EACjB,s2CAAs2C;IACx2C,qBAAqB,EACnB,8DAA8D;IAChE,sBAAsB,EACpB,04BAA04B;IAC54B,oBAAoB,EAClB,4mBAA4mB;IAC9mB,eAAe,EACb,qkCAAqkC;CAC/jC,CAAC;AACX,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,gCAAgC,EAC9B,uEAAuE;IACzE,qBAAqB,EACnB,4DAA4D;IAC9D,sBAAsB,EACpB,6DAA6D;IAC/D,gBAAgB,EAAE,uDAAuD;IACzE,0BAA0B,EACxB,iEAAiE;IACnE,gBAAgB,EAAE,uDAAuD;IACzE,sBAAsB,EACpB,6DAA6D;IAC/D,gBAAgB,EAAE,uDAAuD;IACzE,YAAY,EAAE,mDAAmD;IACjE,gBAAgB,EAAE,uDAAuD;IACzE,gBAAgB,EAAE,uDAAuD;IACzE,uBAAuB,EACrB,8DAA8D;IAChE,oBAAoB,EAClB,2DAA2D;IAC7D,oBAAoB,EAClB,2DAA2D;IAC7D,qBAAqB,EACnB,4DAA4D;IAC9D,sBAAsB,EACpB,6DAA6D;IAC/D,kBAAkB,EAAE,yDAAyD;IAC7E,wBAAwB,EACtB,+DAA+D;IACjE,mBAAmB,EACjB,0DAA0D;IAC5D,qBAAqB,EACnB,4DAA4D;IAC9D,sBAAsB,EACpB,6DAA6D;IAC/D,oBAAoB,EAClB,2DAA2D;IAC7D,eAAe,EAAE,sDAAsD;CAC/D,CAAC","sourcesContent":["/*\n * AUTO-GENERATED FILE. DO NOT EDIT.\n * Update sources in lib/v3/dom/locatorScripts and run genLocatorScripts.ts.\n */\nexport const locatorScriptBootstrap =\n '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:\n '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:\n '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:\n '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:\n '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:\n '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:\n 'function ae(){try{return(this.tagName?.toLowerCase()??\"\")!==\"input\"?!1:String(this.type??\"\").toLowerCase()===\"file\"}catch{return!1}}',\n fillElementValue:\n '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:\n 'function fe(){try{typeof this.focus==\"function\"&&this.focus()}catch{}}',\n isElementChecked:\n '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:\n '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:\n '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:\n 'function ye(){try{return String(this.innerHTML??\"\")}catch{return\"\"}}',\n readElementInnerText:\n '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:\n '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:\n 'function we(){try{return String(this.textContent??\"\")}catch{return\"\"}}',\n resolveCssSelector:\n '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:\n '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:\n '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:\n \"function Le(e,t){let n=C(t);return P(e,n,{pierceShadow:!0})}\",\n scrollElementToPercent:\n '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:\n '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:\n '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:\n \"globalThis.__stagehandLocatorScripts.assignFilePayloadsToInputElement\",\n countCssMatchesPierce:\n \"globalThis.__stagehandLocatorScripts.countCssMatchesPierce\",\n countCssMatchesPrimary:\n \"globalThis.__stagehandLocatorScripts.countCssMatchesPrimary\",\n countTextMatches: \"globalThis.__stagehandLocatorScripts.countTextMatches\",\n countXPathMatchesMainWorld:\n \"globalThis.__stagehandLocatorScripts.countXPathMatchesMainWorld\",\n dispatchDomClick: \"globalThis.__stagehandLocatorScripts.dispatchDomClick\",\n ensureFileInputElement:\n \"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:\n \"globalThis.__stagehandLocatorScripts.prepareElementForTyping\",\n readElementInnerHTML:\n \"globalThis.__stagehandLocatorScripts.readElementInnerHTML\",\n readElementInnerText:\n \"globalThis.__stagehandLocatorScripts.readElementInnerText\",\n readElementInputValue:\n \"globalThis.__stagehandLocatorScripts.readElementInputValue\",\n readElementTextContent:\n \"globalThis.__stagehandLocatorScripts.readElementTextContent\",\n resolveCssSelector: \"globalThis.__stagehandLocatorScripts.resolveCssSelector\",\n resolveCssSelectorPierce:\n \"globalThis.__stagehandLocatorScripts.resolveCssSelectorPierce\",\n resolveTextSelector:\n \"globalThis.__stagehandLocatorScripts.resolveTextSelector\",\n resolveXPathMainWorld:\n \"globalThis.__stagehandLocatorScripts.resolveXPathMainWorld\",\n scrollElementToPercent:\n \"globalThis.__stagehandLocatorScripts.scrollElementToPercent\",\n selectElementOptions:\n \"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,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 +1 @@
1
- export declare const reRenderScriptContent = "(()=>{function s(){try{let o=window.__stagehandV3__;if(!o||typeof o.getClosedRoot!=\"function\")return;let t=[],r=document.createTreeWalker(document,NodeFilter.SHOW_ELEMENT);for(;r.nextNode();){let e=r.currentNode,n=e.tagName?.toLowerCase()??\"\";if(!n.includes(\"-\")||typeof customElements?.get!=\"function\"||!customElements.get(n))continue;let c=!!e.shadowRoot,i=!!o.getClosedRoot(e);c||i||t.push(e)}for(let e of t)try{let n=e.cloneNode(!0);e.replaceWith(n)}catch{}o.stats&&t.length&&console.info(\"[v3-piercer] rerender\",{count:t.length})}catch(o){console.info(\"[v3-piercer] rerender error\",{message:String(o??\"\")})}}s();})();\n";
1
+ export declare const reRenderScriptContent = "(()=>{function s(){try{let o=window.__stagehandV3__;if(!o||typeof o.getClosedRoot!=\"function\")return;let t=[],r=document.createTreeWalker(document,NodeFilter.SHOW_ELEMENT);for(;r.nextNode();){let e=r.currentNode,n=e.tagName?.toLowerCase()??\"\";if(!n.includes(\"-\")||typeof customElements?.get!=\"function\"||!customElements.get(n))continue;let c=!!e.shadowRoot,i=!!o.getClosedRoot(e);c||i||t.push(e)}for(let e of t)try{let n=e.cloneNode(!0);e.replaceWith(n)}catch{}o.stats&&t.length&&console.info(\"[v3-piercer] rerender\",{count:t.length})}catch(o){console.info(\"[v3-piercer] rerender error\",{message:String(o??\"\")})}}s();})();";
@@ -1,2 +1,2 @@
1
- export const reRenderScriptContent = '(()=>{function s(){try{let o=window.__stagehandV3__;if(!o||typeof o.getClosedRoot!="function")return;let t=[],r=document.createTreeWalker(document,NodeFilter.SHOW_ELEMENT);for(;r.nextNode();){let e=r.currentNode,n=e.tagName?.toLowerCase()??"";if(!n.includes("-")||typeof customElements?.get!="function"||!customElements.get(n))continue;let c=!!e.shadowRoot,i=!!o.getClosedRoot(e);c||i||t.push(e)}for(let e of t)try{let n=e.cloneNode(!0);e.replaceWith(n)}catch{}o.stats&&t.length&&console.info("[v3-piercer] rerender",{count:t.length})}catch(o){console.info("[v3-piercer] rerender error",{message:String(o??"")})}}s();})();\n';
1
+ export const reRenderScriptContent = "(()=>{function s(){try{let o=window.__stagehandV3__;if(!o||typeof o.getClosedRoot!=\"function\")return;let t=[],r=document.createTreeWalker(document,NodeFilter.SHOW_ELEMENT);for(;r.nextNode();){let e=r.currentNode,n=e.tagName?.toLowerCase()??\"\";if(!n.includes(\"-\")||typeof customElements?.get!=\"function\"||!customElements.get(n))continue;let c=!!e.shadowRoot,i=!!o.getClosedRoot(e);c||i||t.push(e)}for(let e of t)try{let n=e.cloneNode(!0);e.replaceWith(n)}catch{}o.stats&&t.length&&console.info(\"[v3-piercer] rerender\",{count:t.length})}catch(o){console.info(\"[v3-piercer] rerender error\",{message:String(o??\"\")})}}s();})();";
2
2
  //# sourceMappingURL=reRenderScriptContent.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"reRenderScriptContent.js","sourceRoot":"","sources":["../../../../../../lib/v3/dom/build/reRenderScriptContent.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,qBAAqB,GAChC,knBAAknB,CAAC","sourcesContent":["export const reRenderScriptContent =\n '(()=>{function s(){try{let o=window.__stagehandV3__;if(!o||typeof o.getClosedRoot!=\"function\")return;let t=[],r=document.createTreeWalker(document,NodeFilter.SHOW_ELEMENT);for(;r.nextNode();){let e=r.currentNode,n=e.tagName?.toLowerCase()??\"\";if(!n.includes(\"-\")||typeof customElements?.get!=\"function\"||!customElements.get(n))continue;let c=!!e.shadowRoot,i=!!o.getClosedRoot(e);c||i||t.push(e)}for(let e of t)try{let n=e.cloneNode(!0);e.replaceWith(n)}catch{}o.stats&&t.length&&console.info(\"[v3-piercer] rerender\",{count:t.length})}catch(o){console.info(\"[v3-piercer] rerender error\",{message:String(o??\"\")})}}s();})();\\n';\n"]}
1
+ {"version":3,"file":"reRenderScriptContent.js","sourceRoot":"","sources":["../../../../../../lib/v3/dom/build/reRenderScriptContent.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,qBAAqB,GAAG,8nBAA8nB,CAAC","sourcesContent":["export const reRenderScriptContent = \"(()=>{function s(){try{let o=window.__stagehandV3__;if(!o||typeof o.getClosedRoot!=\\\"function\\\")return;let t=[],r=document.createTreeWalker(document,NodeFilter.SHOW_ELEMENT);for(;r.nextNode();){let e=r.currentNode,n=e.tagName?.toLowerCase()??\\\"\\\";if(!n.includes(\\\"-\\\")||typeof customElements?.get!=\\\"function\\\"||!customElements.get(n))continue;let c=!!e.shadowRoot,i=!!o.getClosedRoot(e);c||i||t.push(e)}for(let e of t)try{let n=e.cloneNode(!0);e.replaceWith(n)}catch{}o.stats&&t.length&&console.info(\\\"[v3-piercer] rerender\\\",{count:t.length})}catch(o){console.info(\\\"[v3-piercer] rerender error\\\",{message:String(o??\\\"\\\")})}}s();})();\";\n"]}
@@ -1,8 +1,8 @@
1
1
  /*
2
2
  * AUTO-GENERATED FILE. DO NOT EDIT.
3
- * Update sources in lib/v3/dom/screenshotScripts and run genScreenshotScripts.ts.
3
+ * Run `pnpm run build-dom-scripts` to regenerate.
4
4
  */
5
5
  export const screenshotScriptSources = {
6
- resolveMaskRect: 'function h(r){function u(t,e){try{return t&&typeof t.closest=="function"?t.closest(e):null}catch{return null}}function s(t,e){try{return!!t&&typeof t.matches=="function"&&t.matches(e)}catch{return!1}}function c(t){let e=u(t,"dialog[open]");if(e)return e;let l=u(t,"[popover]");return l&&s(l,":popover-open")?l:null}if(!this||typeof this.getBoundingClientRect!="function")return null;let n=this.getBoundingClientRect();if(!n)return null;let i=window.getComputedStyle(this);if(!i||i.visibility==="hidden"||i.display==="none"||n.width<=0||n.height<=0)return null;let o=c(this);if(o){let t=o.getBoundingClientRect();if(!t)return null;let e=null;if(r)try{let l=o.getAttribute("data-stagehand-mask-root");l&&l.startsWith(r)?e=l:(e=r+"_root_"+Math.random().toString(36).slice(2),o.setAttribute("data-stagehand-mask-root",e))}catch{e=null}return{x:n.left-t.left-(o.clientLeft||0)+(o.scrollLeft||0),y:n.top-t.top-(o.clientTop||0)+(o.scrollTop||0),width:n.width,height:n.height,rootToken:e}}return{x:n.left+window.scrollX,y:n.top+window.scrollY,width:n.width,height:n.height,rootToken:null}}',
6
+ "resolveMaskRect": "function h(r){function u(t,e){try{return t&&typeof t.closest==\"function\"?t.closest(e):null}catch{return null}}function s(t,e){try{return!!t&&typeof t.matches==\"function\"&&t.matches(e)}catch{return!1}}function c(t){let e=u(t,\"dialog[open]\");if(e)return e;let l=u(t,\"[popover]\");return l&&s(l,\":popover-open\")?l:null}if(!this||typeof this.getBoundingClientRect!=\"function\")return null;let n=this.getBoundingClientRect();if(!n)return null;let i=window.getComputedStyle(this);if(!i||i.visibility===\"hidden\"||i.display===\"none\"||n.width<=0||n.height<=0)return null;let o=c(this);if(o){let t=o.getBoundingClientRect();if(!t)return null;let e=null;if(r)try{let l=o.getAttribute(\"data-stagehand-mask-root\");l&&l.startsWith(r)?e=l:(e=r+\"_root_\"+Math.random().toString(36).slice(2),o.setAttribute(\"data-stagehand-mask-root\",e))}catch{e=null}return{x:n.left-t.left-(o.clientLeft||0)+(o.scrollLeft||0),y:n.top-t.top-(o.clientTop||0)+(o.scrollTop||0),width:n.width,height:n.height,rootToken:e}}return{x:n.left+window.scrollX,y:n.top+window.scrollY,width:n.width,height:n.height,rootToken:null}}"
7
7
  };
8
8
  //# sourceMappingURL=screenshotScripts.generated.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"screenshotScripts.generated.js","sourceRoot":"","sources":["../../../../../../lib/v3/dom/build/screenshotScripts.generated.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,eAAe,EACb,2jCAA2jC;CACrjC,CAAC","sourcesContent":["/*\n * AUTO-GENERATED FILE. DO NOT EDIT.\n * Update sources in lib/v3/dom/screenshotScripts and run genScreenshotScripts.ts.\n */\nexport const screenshotScriptSources = {\n resolveMaskRect:\n 'function h(r){function u(t,e){try{return t&&typeof t.closest==\"function\"?t.closest(e):null}catch{return null}}function s(t,e){try{return!!t&&typeof t.matches==\"function\"&&t.matches(e)}catch{return!1}}function c(t){let e=u(t,\"dialog[open]\");if(e)return e;let l=u(t,\"[popover]\");return l&&s(l,\":popover-open\")?l:null}if(!this||typeof this.getBoundingClientRect!=\"function\")return null;let n=this.getBoundingClientRect();if(!n)return null;let i=window.getComputedStyle(this);if(!i||i.visibility===\"hidden\"||i.display===\"none\"||n.width<=0||n.height<=0)return null;let o=c(this);if(o){let t=o.getBoundingClientRect();if(!t)return null;let e=null;if(r)try{let l=o.getAttribute(\"data-stagehand-mask-root\");l&&l.startsWith(r)?e=l:(e=r+\"_root_\"+Math.random().toString(36).slice(2),o.setAttribute(\"data-stagehand-mask-root\",e))}catch{e=null}return{x:n.left-t.left-(o.clientLeft||0)+(o.scrollLeft||0),y:n.top-t.top-(o.clientTop||0)+(o.scrollTop||0),width:n.width,height:n.height,rootToken:e}}return{x:n.left+window.scrollX,y:n.top+window.scrollY,width:n.width,height:n.height,rootToken:null}}',\n} as const;\nexport type ScreenshotScriptName = keyof typeof screenshotScriptSources;\n"]}
1
+ {"version":3,"file":"screenshotScripts.generated.js","sourceRoot":"","sources":["../../../../../../lib/v3/dom/build/screenshotScripts.generated.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,iBAAiB,EAAE,ilCAAilC;CAC5lC,CAAC","sourcesContent":["/*\n * AUTO-GENERATED FILE. DO NOT EDIT.\n * Run `pnpm run build-dom-scripts` to regenerate.\n */\nexport const screenshotScriptSources = {\n \"resolveMaskRect\": \"function h(r){function u(t,e){try{return t&&typeof t.closest==\\\"function\\\"?t.closest(e):null}catch{return null}}function s(t,e){try{return!!t&&typeof t.matches==\\\"function\\\"&&t.matches(e)}catch{return!1}}function c(t){let e=u(t,\\\"dialog[open]\\\");if(e)return e;let l=u(t,\\\"[popover]\\\");return l&&s(l,\\\":popover-open\\\")?l:null}if(!this||typeof this.getBoundingClientRect!=\\\"function\\\")return null;let n=this.getBoundingClientRect();if(!n)return null;let i=window.getComputedStyle(this);if(!i||i.visibility===\\\"hidden\\\"||i.display===\\\"none\\\"||n.width<=0||n.height<=0)return null;let o=c(this);if(o){let t=o.getBoundingClientRect();if(!t)return null;let e=null;if(r)try{let l=o.getAttribute(\\\"data-stagehand-mask-root\\\");l&&l.startsWith(r)?e=l:(e=r+\\\"_root_\\\"+Math.random().toString(36).slice(2),o.setAttribute(\\\"data-stagehand-mask-root\\\",e))}catch{e=null}return{x:n.left-t.left-(o.clientLeft||0)+(o.scrollLeft||0),y:n.top-t.top-(o.clientTop||0)+(o.scrollTop||0),width:n.width,height:n.height,rootToken:e}}return{x:n.left+window.scrollX,y:n.top+window.scrollY,width:n.width,height:n.height,rootToken:null}}\"\n} as const;\nexport type ScreenshotScriptName = keyof typeof screenshotScriptSources;\n"]}
@@ -1 +1 @@
1
- export declare const v3ScriptContent = "(()=>{function s(c={}){let r=e=>{let{hostToRoot:o}=e;window.__stagehandV3__={getClosedRoot:a=>o.get(a),stats:()=>({installed:!0,url:location.href,isTop:window.top===window,open:e.openCount,closed:e.closedCount})}},n=Element.prototype.attachShadow;if(n.__v3Patched&&n.__v3State){n.__v3State.debug=!0,r(n.__v3State);return}let t={hostToRoot:new WeakMap,openCount:0,closedCount:0,debug:!0},l=n,d=function(e){let o=e?.mode??\"open\",a=l.call(this,e);try{t.hostToRoot.set(this,a),o===\"closed\"?t.closedCount++:t.openCount++,t.debug&&console.info(\"[v3-piercer] attachShadow\",{tag:this.tagName?.toLowerCase()??\"\",mode:o,url:location.href})}catch{}return a};if(d.__v3Patched=!0,d.__v3State=t,Object.defineProperty(Element.prototype,\"attachShadow\",{configurable:!0,writable:!0,value:d}),c.tagExisting)try{let e=document.createTreeWalker(document,NodeFilter.SHOW_ELEMENT);for(;e.nextNode();){let o=e.currentNode;o.shadowRoot&&(t.hostToRoot.set(o,o.shadowRoot),t.openCount++)}}catch{}window.__stagehandV3Injected=!0,r(t),t.debug&&console.info(\"[v3-piercer] installed\",{url:location.href,isTop:window.top===window,readyState:document.readyState})}s({debug:!0,tagExisting:!1});})();\n";
1
+ export declare const v3ScriptContent = "(()=>{function s(c={}){let r=e=>{let{hostToRoot:o}=e;window.__stagehandV3__={getClosedRoot:a=>o.get(a),stats:()=>({installed:!0,url:location.href,isTop:window.top===window,open:e.openCount,closed:e.closedCount})}},n=Element.prototype.attachShadow;if(n.__v3Patched&&n.__v3State){n.__v3State.debug=!0,r(n.__v3State);return}let t={hostToRoot:new WeakMap,openCount:0,closedCount:0,debug:!0},l=n,d=function(e){let o=e?.mode??\"open\",a=l.call(this,e);try{t.hostToRoot.set(this,a),o===\"closed\"?t.closedCount++:t.openCount++,t.debug&&console.info(\"[v3-piercer] attachShadow\",{tag:this.tagName?.toLowerCase()??\"\",mode:o,url:location.href})}catch{}return a};if(d.__v3Patched=!0,d.__v3State=t,Object.defineProperty(Element.prototype,\"attachShadow\",{configurable:!0,writable:!0,value:d}),c.tagExisting)try{let e=document.createTreeWalker(document,NodeFilter.SHOW_ELEMENT);for(;e.nextNode();){let o=e.currentNode;o.shadowRoot&&(t.hostToRoot.set(o,o.shadowRoot),t.openCount++)}}catch{}window.__stagehandV3Injected=!0,r(t),t.debug&&console.info(\"[v3-piercer] installed\",{url:location.href,isTop:window.top===window,readyState:document.readyState})}s({debug:!0,tagExisting:!1});})();";
@@ -1,2 +1,2 @@
1
- export const v3ScriptContent = '(()=>{function s(c={}){let r=e=>{let{hostToRoot:o}=e;window.__stagehandV3__={getClosedRoot:a=>o.get(a),stats:()=>({installed:!0,url:location.href,isTop:window.top===window,open:e.openCount,closed:e.closedCount})}},n=Element.prototype.attachShadow;if(n.__v3Patched&&n.__v3State){n.__v3State.debug=!0,r(n.__v3State);return}let t={hostToRoot:new WeakMap,openCount:0,closedCount:0,debug:!0},l=n,d=function(e){let o=e?.mode??"open",a=l.call(this,e);try{t.hostToRoot.set(this,a),o==="closed"?t.closedCount++:t.openCount++,t.debug&&console.info("[v3-piercer] attachShadow",{tag:this.tagName?.toLowerCase()??"",mode:o,url:location.href})}catch{}return a};if(d.__v3Patched=!0,d.__v3State=t,Object.defineProperty(Element.prototype,"attachShadow",{configurable:!0,writable:!0,value:d}),c.tagExisting)try{let e=document.createTreeWalker(document,NodeFilter.SHOW_ELEMENT);for(;e.nextNode();){let o=e.currentNode;o.shadowRoot&&(t.hostToRoot.set(o,o.shadowRoot),t.openCount++)}}catch{}window.__stagehandV3Injected=!0,r(t),t.debug&&console.info("[v3-piercer] installed",{url:location.href,isTop:window.top===window,readyState:document.readyState})}s({debug:!0,tagExisting:!1});})();\n';
1
+ export const v3ScriptContent = "(()=>{function s(c={}){let r=e=>{let{hostToRoot:o}=e;window.__stagehandV3__={getClosedRoot:a=>o.get(a),stats:()=>({installed:!0,url:location.href,isTop:window.top===window,open:e.openCount,closed:e.closedCount})}},n=Element.prototype.attachShadow;if(n.__v3Patched&&n.__v3State){n.__v3State.debug=!0,r(n.__v3State);return}let t={hostToRoot:new WeakMap,openCount:0,closedCount:0,debug:!0},l=n,d=function(e){let o=e?.mode??\"open\",a=l.call(this,e);try{t.hostToRoot.set(this,a),o===\"closed\"?t.closedCount++:t.openCount++,t.debug&&console.info(\"[v3-piercer] attachShadow\",{tag:this.tagName?.toLowerCase()??\"\",mode:o,url:location.href})}catch{}return a};if(d.__v3Patched=!0,d.__v3State=t,Object.defineProperty(Element.prototype,\"attachShadow\",{configurable:!0,writable:!0,value:d}),c.tagExisting)try{let e=document.createTreeWalker(document,NodeFilter.SHOW_ELEMENT);for(;e.nextNode();){let o=e.currentNode;o.shadowRoot&&(t.hostToRoot.set(o,o.shadowRoot),t.openCount++)}}catch{}window.__stagehandV3Injected=!0,r(t),t.debug&&console.info(\"[v3-piercer] installed\",{url:location.href,isTop:window.top===window,readyState:document.readyState})}s({debug:!0,tagExisting:!1});})();";
2
2
  //# sourceMappingURL=scriptV3Content.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"scriptV3Content.js","sourceRoot":"","sources":["../../../../../../lib/v3/dom/build/scriptV3Content.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAC1B,kpCAAkpC,CAAC","sourcesContent":["export const v3ScriptContent =\n '(()=>{function s(c={}){let r=e=>{let{hostToRoot:o}=e;window.__stagehandV3__={getClosedRoot:a=>o.get(a),stats:()=>({installed:!0,url:location.href,isTop:window.top===window,open:e.openCount,closed:e.closedCount})}},n=Element.prototype.attachShadow;if(n.__v3Patched&&n.__v3State){n.__v3State.debug=!0,r(n.__v3State);return}let t={hostToRoot:new WeakMap,openCount:0,closedCount:0,debug:!0},l=n,d=function(e){let o=e?.mode??\"open\",a=l.call(this,e);try{t.hostToRoot.set(this,a),o===\"closed\"?t.closedCount++:t.openCount++,t.debug&&console.info(\"[v3-piercer] attachShadow\",{tag:this.tagName?.toLowerCase()??\"\",mode:o,url:location.href})}catch{}return a};if(d.__v3Patched=!0,d.__v3State=t,Object.defineProperty(Element.prototype,\"attachShadow\",{configurable:!0,writable:!0,value:d}),c.tagExisting)try{let e=document.createTreeWalker(document,NodeFilter.SHOW_ELEMENT);for(;e.nextNode();){let o=e.currentNode;o.shadowRoot&&(t.hostToRoot.set(o,o.shadowRoot),t.openCount++)}}catch{}window.__stagehandV3Injected=!0,r(t),t.debug&&console.info(\"[v3-piercer] installed\",{url:location.href,isTop:window.top===window,readyState:document.readyState})}s({debug:!0,tagExisting:!1});})();\\n';\n"]}
1
+ {"version":3,"file":"scriptV3Content.js","sourceRoot":"","sources":["../../../../../../lib/v3/dom/build/scriptV3Content.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG,4pCAA4pC,CAAC","sourcesContent":["export const v3ScriptContent = \"(()=>{function s(c={}){let r=e=>{let{hostToRoot:o}=e;window.__stagehandV3__={getClosedRoot:a=>o.get(a),stats:()=>({installed:!0,url:location.href,isTop:window.top===window,open:e.openCount,closed:e.closedCount})}},n=Element.prototype.attachShadow;if(n.__v3Patched&&n.__v3State){n.__v3State.debug=!0,r(n.__v3State);return}let t={hostToRoot:new WeakMap,openCount:0,closedCount:0,debug:!0},l=n,d=function(e){let o=e?.mode??\\\"open\\\",a=l.call(this,e);try{t.hostToRoot.set(this,a),o===\\\"closed\\\"?t.closedCount++:t.openCount++,t.debug&&console.info(\\\"[v3-piercer] attachShadow\\\",{tag:this.tagName?.toLowerCase()??\\\"\\\",mode:o,url:location.href})}catch{}return a};if(d.__v3Patched=!0,d.__v3State=t,Object.defineProperty(Element.prototype,\\\"attachShadow\\\",{configurable:!0,writable:!0,value:d}),c.tagExisting)try{let e=document.createTreeWalker(document,NodeFilter.SHOW_ELEMENT);for(;e.nextNode();){let o=e.currentNode;o.shadowRoot&&(t.hostToRoot.set(o,o.shadowRoot),t.openCount++)}}catch{}window.__stagehandV3Injected=!0,r(t),t.debug&&console.info(\\\"[v3-piercer] installed\\\",{url:location.href,isTop:window.top===window,readyState:document.readyState})}s({debug:!0,tagExisting:!1});})();\";\n"]}
@@ -0,0 +1,24 @@
1
+ export declare const selectorRuntimeBootstrap = "if (!globalThis.__stagehandSelectorRuntime) { var __stagehandSelectorRuntimeFactory=(()=>{var P=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var $=(t,e)=>{for(var n in e)P(t,n,{get:e[n],enumerable:!0})},C=(t,e,n,r)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let s of N(e))!D.call(t,s)&&s!==n&&P(t,s,{get:()=>e[s],enumerable:!(r=A(e,s))||r.enumerable});return t};var k=t=>C(P({},\"__esModule\",{value:!0}),t);var j={};$(j,{countCssWithRoots:()=>B,countTextWithRoots:()=>Y,countXPathNative:()=>U,countXPathWithRoots:()=>K,hasOpenShadowRoots:()=>V,queryCssWithRoots:()=>X,queryTextWithRoots:()=>M,queryXPathNative:()=>Z,queryXPathWithRoots:()=>z});function R(t){let e=String(t||\"\").trim().replace(/^xpath=/i,\"\");if(!e)return[];let n=[],r=0;for(;r<e.length;){let s=\"child\";e.startsWith(\"//\",r)?(s=\"desc\",r+=2):e[r]===\"/\"&&(s=\"child\",r+=1);let o=r,a=0,i=null;for(;r<e.length;){let l=e[r];if(i)l===i&&(i=null);else if(l===\"'\"||l==='\"')i=l;else if(l===\"[\")a++;else if(l===\"]\")a--;else if(l===\"/\"&&a===0)break;r+=1}let u=e.slice(o,r).trim();if(!u)continue;let{tag:c,predicates:f}=W(u);n.push({axis:s,tag:c,predicates:f})}return n}function q(t){let e=[],n=0;for(;n<t.length;){if(t[n]!==\"[\"){n++;continue}n++;let r=n,s=null;for(;n<t.length;){let o=t[n];if(s)o===s&&(s=null);else if(o===\"'\"||o==='\"')s=o;else if(o===\"]\")break;n++}e.push(t.slice(r,n).trim()),n++}return e}function W(t){let e=t.indexOf(\"[\");if(e===-1)return{tag:t===\"\"?\"*\":t.toLowerCase(),predicates:[]};let n=t.slice(0,e).trim(),r=n===\"\"?\"*\":n.toLowerCase(),s=t.slice(e),o=[];for(let a of q(s)){let i=d(a);i&&o.push(i)}return{tag:r,predicates:o}}function d(t){let e=t.trim();if(!e)return null;let n=y(e,\"or\");if(n.length>1){let o=n.map(a=>d(a)).filter(Boolean);return o.length!==n.length?null:{type:\"or\",predicates:o}}let r=y(e,\"and\");if(r.length>1){let o=r.map(a=>d(a)).filter(Boolean);return o.length!==r.length?null:{type:\"and\",predicates:o}}let s=O(e,\"not\");if(s!=null){let o=d(s);return o?{type:\"not\",predicate:o}:null}return _(e)}function _(t){let e=/^(?:'([^']*)'|\"([^\"]*)\")$/,n=\"[a-zA-Z_][\\\\w.-]*\",r=`(?:'([^']*)'|\"([^\"]*)\")`;if(/^\\d+$/.test(t))return{type:\"index\",index:Math.max(1,Number(t))};let s=t.match(new RegExp(`^normalize-space\\\\(\\\\s*@(${n})\\\\s*\\\\)\\\\s*=\\\\s*${r}$`));if(s)return{type:\"attrEquals\",name:s[1],value:s[2]??s[3]??\"\",normalize:!0};let o=t.match(new RegExp(`^normalize-space\\\\(\\\\s*(?:text\\\\(\\\\)|\\\\.)\\\\s*\\\\)\\\\s*=\\\\s*${r}$`));if(o)return{type:\"textEquals\",value:o[1]??o[2]??\"\",normalize:!0};let a=t.match(new RegExp(`^@(${n})\\\\s*=\\\\s*${r}$`));if(a)return{type:\"attrEquals\",name:a[1],value:a[2]??a[3]??\"\"};let i=t.match(new RegExp(`^@(${n})$`));if(i)return{type:\"attrExists\",name:i[1]};let u=t.match(new RegExp(`^contains\\\\(\\\\s*@(${n})\\\\s*,\\\\s*${r}\\\\s*\\\\)$`));if(u)return{type:\"attrContains\",name:u[1],value:u[2]??u[3]??\"\"};let c=t.match(new RegExp(`^starts-with\\\\(\\\\s*@(${n})\\\\s*,\\\\s*${r}\\\\s*\\\\)$`));if(c)return{type:\"attrStartsWith\",name:c[1],value:c[2]??c[3]??\"\"};let f=t.match(new RegExp(`^(?:text\\\\(\\\\)|\\\\.)\\\\s*=\\\\s*${r}$`));if(f)return{type:\"textEquals\",value:f[1]??f[2]??\"\"};let l=t.match(new RegExp(`^contains\\\\(\\\\s*(?:text\\\\(\\\\)|\\\\.)\\\\s*,\\\\s*${r}\\\\s*\\\\)$`));return l?{type:\"textContains\",value:l[1]??l[2]??\"\"}:(e.test(t),null)}function y(t,e){let n=[],r=0,s=0,o=null,a=0;for(;a<t.length;){let i=t[a];if(o){i===o&&(o=null),a+=1;continue}if(i===\"'\"||i==='\"'){o=i,a+=1;continue}if(i===\"(\"){s+=1,a+=1;continue}if(i===\")\"){s=Math.max(0,s-1),a+=1;continue}if(s===0&&L(t,a,e)){n.push(t.slice(r,a).trim()),a+=e.length,r=a;continue}a+=1}return n.push(t.slice(r).trim()),n.filter(i=>i.length>0)}function L(t,e,n){if(!t.startsWith(n,e))return!1;let r=e>0?t[e-1]:\" \";if(r===\"@\")return!1;let s=e+n.length<t.length?t[e+n.length]:\" \";return S(r)&&S(s)}function S(t){return!/[a-zA-Z0-9_.-]/.test(t)}function O(t,e){let n=`${e}(`;if(!t.startsWith(n)||!t.endsWith(\")\"))return null;let r=t.slice(n.length,-1);return I(r)?r:null}function I(t){let e=0,n=null;for(let r=0;r<t.length;r+=1){let s=t[r];if(n){s===n&&(n=null);continue}if(s===\"'\"||s==='\"'){n=s;continue}if(s===\"(\"?e+=1:s===\")\"&&(e-=1),e<0)return!1}return e===0}var F=t=>t.replace(/\\s+/g,\" \").trim();function b(t){return String(t.textContent??\"\")}function m(t,e){return e?F(t):t}function x(t,e){switch(e.type){case\"and\":return e.predicates.every(n=>x(t,n));case\"or\":return e.predicates.some(n=>x(t,n));case\"not\":return!x(t,e.predicate);case\"attrExists\":return t.getAttribute(e.name)!==null;case\"attrEquals\":{let n=t.getAttribute(e.name);return n===null?!1:m(n,e.normalize)===m(e.value,e.normalize)}case\"attrContains\":{let n=t.getAttribute(e.name);return n===null?!1:m(n,e.normalize).includes(m(e.value,e.normalize))}case\"attrStartsWith\":{let n=t.getAttribute(e.name);return n===null?!1:m(n,e.normalize).startsWith(m(e.value,e.normalize))}case\"textEquals\":return m(b(t),e.normalize)===m(e.value,e.normalize);case\"textContains\":return m(b(t),e.normalize).includes(m(e.value,e.normalize));case\"index\":return!0;default:return!0}}function v(t,e){let n=t;for(let r of e){if(!n.length)return[];if(r.type===\"index\"){let s=r.index-1;n=s>=0&&s<n.length?[n[s]]:[];continue}n=n.filter(s=>x(s,r))}return n}function w(t){let e=new Map;for(let n=0;n<t.length;n+=2){let r=t[n],s=t[n+1];r instanceof Element&&s instanceof ShadowRoot&&e.set(r,s)}return e}function E(t,e){if(!t)return[];if(t instanceof Document)return t.documentElement?[t.documentElement]:[];if(t instanceof ShadowRoot||t instanceof DocumentFragment)return Array.from(t.children||[]);if(!(t instanceof Element))return[];let n=Array.from(t.children||[]);t.shadowRoot&&n.push(...Array.from(t.shadowRoot.children||[]));let r=e.get(t);return r&&n.push(...Array.from(r.children||[])),n}function H(t,e){let n=[],r=new Set,s=[...E(t,e)].reverse();for(;s.length;){let o=s.pop();if(!(o instanceof Element)||r.has(o))continue;r.add(o),n.push(o);let a=E(o,e);for(let i=a.length-1;i>=0;i-=1)s.push(a[i])}return n}function X(t,e,...n){let r=w(n),s=[],o=new Set,a=[...E(this,r)].reverse();for(;a.length&&s.length<e;){let i=a.pop();if(!(i instanceof Element)||o.has(i))continue;o.add(i);try{if(i.matches(t)&&(s.push(i),s.length>=e))break}catch{return[]}let u=E(i,r);for(let c=u.length-1;c>=0;c-=1)a.push(u[c])}return s}function B(t,...e){return X.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}function M(t,e,...n){let r=w(n),s=new Set([\"SCRIPT\",\"STYLE\",\"TEMPLATE\",\"NOSCRIPT\",\"HEAD\",\"TITLE\",\"LINK\",\"META\",\"HTML\",\"BODY\"]),o=String(t||\"\").toLowerCase();if(!o)return[];let a=l=>{let g=l.tagName?l.tagName.toUpperCase():\"\";if(s.has(g))return\"\";try{let p=l.innerText;if(typeof p==\"string\"&&p.trim())return p.trim()}catch{}let h=l.textContent;return typeof h==\"string\"?h.trim():\"\"},i=[],u=new Set,c=[...E(this,r)].reverse();for(;c.length;){let l=c.pop();if(!(l instanceof Element)||u.has(l))continue;u.add(l);let g=a(l);g&&g.toLowerCase().includes(o)&&i.push(l);let h=E(l,r);for(let p=h.length-1;p>=0;p-=1)c.push(h[p])}let f=[];for(let l of i){let g=!1;for(let h of i)if(l!==h)try{if(l.contains(h)){g=!0;break}}catch{}if(!g&&(f.push(l),f.length>=e))break}return f}function Y(t,...e){return M.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}function T(t){let e=String(t||\"\").trim();return e?e.replace(/^xpath=/i,\"\").trim():\"\"}function G(t,e){return e.tag===\"*\"?!0:t.localName===e.tag}function z(t,e,...n){let r=w(n),s=R(t);if(!s.length)return[];let o=[this];for(let a of s){let i=[],u=new Set;for(let c of o){let l=(a.axis===\"child\"?E(c,r):H(c,r)).filter(h=>G(h,a)),g=v(l,a.predicates);for(let h of g)if(!u.has(h)&&(u.add(h),i.push(h),i.length>=e&&a===s[s.length-1]))break}if(!i.length)return[];o=i}return o.slice(0,e)}function K(t,...e){return z.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}function Z(t,e){let n=T(t);if(!n||!Number.isFinite(e)||e<=0)return[];try{let r=this.evaluate(n,this,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),s=[],o=Math.min(r.snapshotLength,Math.floor(e));for(let a=0;a<o;a+=1){let i=r.snapshotItem(a);i instanceof Element&&s.push(i)}return s}catch{return[]}}function U(t){let e=T(t);if(!e)return 0;try{let n=this.evaluate(e,this,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),r=0;for(let s=0;s<n.snapshotLength;s+=1)n.snapshotItem(s)instanceof Element&&(r+=1);return r}catch{return 0}}function V(){try{let t=this.createTreeWalker(this,NodeFilter.SHOW_ELEMENT);for(;t.nextNode();){let e=t.currentNode;if(e instanceof Element&&e.shadowRoot)return!0}}catch{return!1}return!1}return k(j);})();\n globalThis.__stagehandSelectorRuntime = __stagehandSelectorRuntimeFactory;\n}";
2
+ export declare const selectorRuntimeSources: {
3
+ readonly countCssWithRoots: "function O(t,...e){return C.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}";
4
+ readonly countTextWithRoots: "function I(t,...e){return k.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}";
5
+ readonly countXPathNative: "function B(t){let e=v(t);if(!e)return 0;try{let n=this.evaluate(e,this,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),r=0;for(let s=0;s<n.snapshotLength;s+=1)n.snapshotItem(s)instanceof Element&&(r+=1);return r}catch{return 0}}";
6
+ readonly countXPathWithRoots: "function F(t,...e){return W.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}";
7
+ readonly hasOpenShadowRoots: "function Y(){try{let t=this.createTreeWalker(this,NodeFilter.SHOW_ELEMENT);for(;t.nextNode();){let e=t.currentNode;if(e instanceof Element&&e.shadowRoot)return!0}}catch{return!1}return!1}";
8
+ readonly queryCssWithRoots: "function C(t,e,...n){let r=P(n),s=[],o=new Set,a=[...E(this,r)].reverse();for(;a.length&&s.length<e;){let i=a.pop();if(!(i instanceof Element)||o.has(i))continue;o.add(i);try{if(i.matches(t)&&(s.push(i),s.length>=e))break}catch{return[]}let u=E(i,r);for(let c=u.length-1;c>=0;c-=1)a.push(u[c])}return s}";
9
+ readonly queryTextWithRoots: "function k(t,e,...n){let r=P(n),s=new Set([\"SCRIPT\",\"STYLE\",\"TEMPLATE\",\"NOSCRIPT\",\"HEAD\",\"TITLE\",\"LINK\",\"META\",\"HTML\",\"BODY\"]),o=String(t||\"\").toLowerCase();if(!o)return[];let a=l=>{let g=l.tagName?l.tagName.toUpperCase():\"\";if(s.has(g))return\"\";try{let p=l.innerText;if(typeof p==\"string\"&&p.trim())return p.trim()}catch{}let h=l.textContent;return typeof h==\"string\"?h.trim():\"\"},i=[],u=new Set,c=[...E(this,r)].reverse();for(;c.length;){let l=c.pop();if(!(l instanceof Element)||u.has(l))continue;u.add(l);let g=a(l);g&&g.toLowerCase().includes(o)&&i.push(l);let h=E(l,r);for(let p=h.length-1;p>=0;p-=1)c.push(h[p])}let f=[];for(let l of i){let g=!1;for(let h of i)if(l!==h)try{if(l.contains(h)){g=!0;break}}catch{}if(!g&&(f.push(l),f.length>=e))break}return f}";
10
+ readonly queryXPathNative: "function H(t,e){let n=v(t);if(!n||!Number.isFinite(e)||e<=0)return[];try{let r=this.evaluate(n,this,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),s=[],o=Math.min(r.snapshotLength,Math.floor(e));for(let a=0;a<o;a+=1){let i=r.snapshotItem(a);i instanceof Element&&s.push(i)}return s}catch{return[]}}";
11
+ readonly queryXPathWithRoots: "function W(t,e,...n){let r=P(n),s=b(t);if(!s.length)return[];let o=[this];for(let a of s){let i=[],u=new Set;for(let c of o){let l=(a.axis===\"child\"?E(c,r):$(c,r)).filter(h=>q(h,a)),g=R(l,a.predicates);for(let h of g)if(!u.has(h)&&(u.add(h),i.push(h),i.length>=e&&a===s[s.length-1]))break}if(!i.length)return[];o=i}return o.slice(0,e)}";
12
+ };
13
+ export declare const selectorRuntimeGlobalRefs: {
14
+ readonly countCssWithRoots: "globalThis.__stagehandSelectorRuntime.countCssWithRoots";
15
+ readonly countTextWithRoots: "globalThis.__stagehandSelectorRuntime.countTextWithRoots";
16
+ readonly countXPathNative: "globalThis.__stagehandSelectorRuntime.countXPathNative";
17
+ readonly countXPathWithRoots: "globalThis.__stagehandSelectorRuntime.countXPathWithRoots";
18
+ readonly hasOpenShadowRoots: "globalThis.__stagehandSelectorRuntime.hasOpenShadowRoots";
19
+ readonly queryCssWithRoots: "globalThis.__stagehandSelectorRuntime.queryCssWithRoots";
20
+ readonly queryTextWithRoots: "globalThis.__stagehandSelectorRuntime.queryTextWithRoots";
21
+ readonly queryXPathNative: "globalThis.__stagehandSelectorRuntime.queryXPathNative";
22
+ readonly queryXPathWithRoots: "globalThis.__stagehandSelectorRuntime.queryXPathWithRoots";
23
+ };
24
+ export type SelectorRuntimeName = keyof typeof selectorRuntimeSources;
@@ -0,0 +1,28 @@
1
+ /*
2
+ * AUTO-GENERATED FILE. DO NOT EDIT.
3
+ * Run `pnpm run build-dom-scripts` to regenerate.
4
+ */
5
+ export const selectorRuntimeBootstrap = "if (!globalThis.__stagehandSelectorRuntime) { var __stagehandSelectorRuntimeFactory=(()=>{var P=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var $=(t,e)=>{for(var n in e)P(t,n,{get:e[n],enumerable:!0})},C=(t,e,n,r)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let s of N(e))!D.call(t,s)&&s!==n&&P(t,s,{get:()=>e[s],enumerable:!(r=A(e,s))||r.enumerable});return t};var k=t=>C(P({},\"__esModule\",{value:!0}),t);var j={};$(j,{countCssWithRoots:()=>B,countTextWithRoots:()=>Y,countXPathNative:()=>U,countXPathWithRoots:()=>K,hasOpenShadowRoots:()=>V,queryCssWithRoots:()=>X,queryTextWithRoots:()=>M,queryXPathNative:()=>Z,queryXPathWithRoots:()=>z});function R(t){let e=String(t||\"\").trim().replace(/^xpath=/i,\"\");if(!e)return[];let n=[],r=0;for(;r<e.length;){let s=\"child\";e.startsWith(\"//\",r)?(s=\"desc\",r+=2):e[r]===\"/\"&&(s=\"child\",r+=1);let o=r,a=0,i=null;for(;r<e.length;){let l=e[r];if(i)l===i&&(i=null);else if(l===\"'\"||l==='\"')i=l;else if(l===\"[\")a++;else if(l===\"]\")a--;else if(l===\"/\"&&a===0)break;r+=1}let u=e.slice(o,r).trim();if(!u)continue;let{tag:c,predicates:f}=W(u);n.push({axis:s,tag:c,predicates:f})}return n}function q(t){let e=[],n=0;for(;n<t.length;){if(t[n]!==\"[\"){n++;continue}n++;let r=n,s=null;for(;n<t.length;){let o=t[n];if(s)o===s&&(s=null);else if(o===\"'\"||o==='\"')s=o;else if(o===\"]\")break;n++}e.push(t.slice(r,n).trim()),n++}return e}function W(t){let e=t.indexOf(\"[\");if(e===-1)return{tag:t===\"\"?\"*\":t.toLowerCase(),predicates:[]};let n=t.slice(0,e).trim(),r=n===\"\"?\"*\":n.toLowerCase(),s=t.slice(e),o=[];for(let a of q(s)){let i=d(a);i&&o.push(i)}return{tag:r,predicates:o}}function d(t){let e=t.trim();if(!e)return null;let n=y(e,\"or\");if(n.length>1){let o=n.map(a=>d(a)).filter(Boolean);return o.length!==n.length?null:{type:\"or\",predicates:o}}let r=y(e,\"and\");if(r.length>1){let o=r.map(a=>d(a)).filter(Boolean);return o.length!==r.length?null:{type:\"and\",predicates:o}}let s=O(e,\"not\");if(s!=null){let o=d(s);return o?{type:\"not\",predicate:o}:null}return _(e)}function _(t){let e=/^(?:'([^']*)'|\"([^\"]*)\")$/,n=\"[a-zA-Z_][\\\\w.-]*\",r=`(?:'([^']*)'|\"([^\"]*)\")`;if(/^\\d+$/.test(t))return{type:\"index\",index:Math.max(1,Number(t))};let s=t.match(new RegExp(`^normalize-space\\\\(\\\\s*@(${n})\\\\s*\\\\)\\\\s*=\\\\s*${r}$`));if(s)return{type:\"attrEquals\",name:s[1],value:s[2]??s[3]??\"\",normalize:!0};let o=t.match(new RegExp(`^normalize-space\\\\(\\\\s*(?:text\\\\(\\\\)|\\\\.)\\\\s*\\\\)\\\\s*=\\\\s*${r}$`));if(o)return{type:\"textEquals\",value:o[1]??o[2]??\"\",normalize:!0};let a=t.match(new RegExp(`^@(${n})\\\\s*=\\\\s*${r}$`));if(a)return{type:\"attrEquals\",name:a[1],value:a[2]??a[3]??\"\"};let i=t.match(new RegExp(`^@(${n})$`));if(i)return{type:\"attrExists\",name:i[1]};let u=t.match(new RegExp(`^contains\\\\(\\\\s*@(${n})\\\\s*,\\\\s*${r}\\\\s*\\\\)$`));if(u)return{type:\"attrContains\",name:u[1],value:u[2]??u[3]??\"\"};let c=t.match(new RegExp(`^starts-with\\\\(\\\\s*@(${n})\\\\s*,\\\\s*${r}\\\\s*\\\\)$`));if(c)return{type:\"attrStartsWith\",name:c[1],value:c[2]??c[3]??\"\"};let f=t.match(new RegExp(`^(?:text\\\\(\\\\)|\\\\.)\\\\s*=\\\\s*${r}$`));if(f)return{type:\"textEquals\",value:f[1]??f[2]??\"\"};let l=t.match(new RegExp(`^contains\\\\(\\\\s*(?:text\\\\(\\\\)|\\\\.)\\\\s*,\\\\s*${r}\\\\s*\\\\)$`));return l?{type:\"textContains\",value:l[1]??l[2]??\"\"}:(e.test(t),null)}function y(t,e){let n=[],r=0,s=0,o=null,a=0;for(;a<t.length;){let i=t[a];if(o){i===o&&(o=null),a+=1;continue}if(i===\"'\"||i==='\"'){o=i,a+=1;continue}if(i===\"(\"){s+=1,a+=1;continue}if(i===\")\"){s=Math.max(0,s-1),a+=1;continue}if(s===0&&L(t,a,e)){n.push(t.slice(r,a).trim()),a+=e.length,r=a;continue}a+=1}return n.push(t.slice(r).trim()),n.filter(i=>i.length>0)}function L(t,e,n){if(!t.startsWith(n,e))return!1;let r=e>0?t[e-1]:\" \";if(r===\"@\")return!1;let s=e+n.length<t.length?t[e+n.length]:\" \";return S(r)&&S(s)}function S(t){return!/[a-zA-Z0-9_.-]/.test(t)}function O(t,e){let n=`${e}(`;if(!t.startsWith(n)||!t.endsWith(\")\"))return null;let r=t.slice(n.length,-1);return I(r)?r:null}function I(t){let e=0,n=null;for(let r=0;r<t.length;r+=1){let s=t[r];if(n){s===n&&(n=null);continue}if(s===\"'\"||s==='\"'){n=s;continue}if(s===\"(\"?e+=1:s===\")\"&&(e-=1),e<0)return!1}return e===0}var F=t=>t.replace(/\\s+/g,\" \").trim();function b(t){return String(t.textContent??\"\")}function m(t,e){return e?F(t):t}function x(t,e){switch(e.type){case\"and\":return e.predicates.every(n=>x(t,n));case\"or\":return e.predicates.some(n=>x(t,n));case\"not\":return!x(t,e.predicate);case\"attrExists\":return t.getAttribute(e.name)!==null;case\"attrEquals\":{let n=t.getAttribute(e.name);return n===null?!1:m(n,e.normalize)===m(e.value,e.normalize)}case\"attrContains\":{let n=t.getAttribute(e.name);return n===null?!1:m(n,e.normalize).includes(m(e.value,e.normalize))}case\"attrStartsWith\":{let n=t.getAttribute(e.name);return n===null?!1:m(n,e.normalize).startsWith(m(e.value,e.normalize))}case\"textEquals\":return m(b(t),e.normalize)===m(e.value,e.normalize);case\"textContains\":return m(b(t),e.normalize).includes(m(e.value,e.normalize));case\"index\":return!0;default:return!0}}function v(t,e){let n=t;for(let r of e){if(!n.length)return[];if(r.type===\"index\"){let s=r.index-1;n=s>=0&&s<n.length?[n[s]]:[];continue}n=n.filter(s=>x(s,r))}return n}function w(t){let e=new Map;for(let n=0;n<t.length;n+=2){let r=t[n],s=t[n+1];r instanceof Element&&s instanceof ShadowRoot&&e.set(r,s)}return e}function E(t,e){if(!t)return[];if(t instanceof Document)return t.documentElement?[t.documentElement]:[];if(t instanceof ShadowRoot||t instanceof DocumentFragment)return Array.from(t.children||[]);if(!(t instanceof Element))return[];let n=Array.from(t.children||[]);t.shadowRoot&&n.push(...Array.from(t.shadowRoot.children||[]));let r=e.get(t);return r&&n.push(...Array.from(r.children||[])),n}function H(t,e){let n=[],r=new Set,s=[...E(t,e)].reverse();for(;s.length;){let o=s.pop();if(!(o instanceof Element)||r.has(o))continue;r.add(o),n.push(o);let a=E(o,e);for(let i=a.length-1;i>=0;i-=1)s.push(a[i])}return n}function X(t,e,...n){let r=w(n),s=[],o=new Set,a=[...E(this,r)].reverse();for(;a.length&&s.length<e;){let i=a.pop();if(!(i instanceof Element)||o.has(i))continue;o.add(i);try{if(i.matches(t)&&(s.push(i),s.length>=e))break}catch{return[]}let u=E(i,r);for(let c=u.length-1;c>=0;c-=1)a.push(u[c])}return s}function B(t,...e){return X.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}function M(t,e,...n){let r=w(n),s=new Set([\"SCRIPT\",\"STYLE\",\"TEMPLATE\",\"NOSCRIPT\",\"HEAD\",\"TITLE\",\"LINK\",\"META\",\"HTML\",\"BODY\"]),o=String(t||\"\").toLowerCase();if(!o)return[];let a=l=>{let g=l.tagName?l.tagName.toUpperCase():\"\";if(s.has(g))return\"\";try{let p=l.innerText;if(typeof p==\"string\"&&p.trim())return p.trim()}catch{}let h=l.textContent;return typeof h==\"string\"?h.trim():\"\"},i=[],u=new Set,c=[...E(this,r)].reverse();for(;c.length;){let l=c.pop();if(!(l instanceof Element)||u.has(l))continue;u.add(l);let g=a(l);g&&g.toLowerCase().includes(o)&&i.push(l);let h=E(l,r);for(let p=h.length-1;p>=0;p-=1)c.push(h[p])}let f=[];for(let l of i){let g=!1;for(let h of i)if(l!==h)try{if(l.contains(h)){g=!0;break}}catch{}if(!g&&(f.push(l),f.length>=e))break}return f}function Y(t,...e){return M.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}function T(t){let e=String(t||\"\").trim();return e?e.replace(/^xpath=/i,\"\").trim():\"\"}function G(t,e){return e.tag===\"*\"?!0:t.localName===e.tag}function z(t,e,...n){let r=w(n),s=R(t);if(!s.length)return[];let o=[this];for(let a of s){let i=[],u=new Set;for(let c of o){let l=(a.axis===\"child\"?E(c,r):H(c,r)).filter(h=>G(h,a)),g=v(l,a.predicates);for(let h of g)if(!u.has(h)&&(u.add(h),i.push(h),i.length>=e&&a===s[s.length-1]))break}if(!i.length)return[];o=i}return o.slice(0,e)}function K(t,...e){return z.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}function Z(t,e){let n=T(t);if(!n||!Number.isFinite(e)||e<=0)return[];try{let r=this.evaluate(n,this,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),s=[],o=Math.min(r.snapshotLength,Math.floor(e));for(let a=0;a<o;a+=1){let i=r.snapshotItem(a);i instanceof Element&&s.push(i)}return s}catch{return[]}}function U(t){let e=T(t);if(!e)return 0;try{let n=this.evaluate(e,this,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),r=0;for(let s=0;s<n.snapshotLength;s+=1)n.snapshotItem(s)instanceof Element&&(r+=1);return r}catch{return 0}}function V(){try{let t=this.createTreeWalker(this,NodeFilter.SHOW_ELEMENT);for(;t.nextNode();){let e=t.currentNode;if(e instanceof Element&&e.shadowRoot)return!0}}catch{return!1}return!1}return k(j);})();\n globalThis.__stagehandSelectorRuntime = __stagehandSelectorRuntimeFactory;\n}";
6
+ export const selectorRuntimeSources = {
7
+ "countCssWithRoots": "function O(t,...e){return C.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}",
8
+ "countTextWithRoots": "function I(t,...e){return k.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}",
9
+ "countXPathNative": "function B(t){let e=v(t);if(!e)return 0;try{let n=this.evaluate(e,this,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),r=0;for(let s=0;s<n.snapshotLength;s+=1)n.snapshotItem(s)instanceof Element&&(r+=1);return r}catch{return 0}}",
10
+ "countXPathWithRoots": "function F(t,...e){return W.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}",
11
+ "hasOpenShadowRoots": "function Y(){try{let t=this.createTreeWalker(this,NodeFilter.SHOW_ELEMENT);for(;t.nextNode();){let e=t.currentNode;if(e instanceof Element&&e.shadowRoot)return!0}}catch{return!1}return!1}",
12
+ "queryCssWithRoots": "function C(t,e,...n){let r=P(n),s=[],o=new Set,a=[...E(this,r)].reverse();for(;a.length&&s.length<e;){let i=a.pop();if(!(i instanceof Element)||o.has(i))continue;o.add(i);try{if(i.matches(t)&&(s.push(i),s.length>=e))break}catch{return[]}let u=E(i,r);for(let c=u.length-1;c>=0;c-=1)a.push(u[c])}return s}",
13
+ "queryTextWithRoots": "function k(t,e,...n){let r=P(n),s=new Set([\"SCRIPT\",\"STYLE\",\"TEMPLATE\",\"NOSCRIPT\",\"HEAD\",\"TITLE\",\"LINK\",\"META\",\"HTML\",\"BODY\"]),o=String(t||\"\").toLowerCase();if(!o)return[];let a=l=>{let g=l.tagName?l.tagName.toUpperCase():\"\";if(s.has(g))return\"\";try{let p=l.innerText;if(typeof p==\"string\"&&p.trim())return p.trim()}catch{}let h=l.textContent;return typeof h==\"string\"?h.trim():\"\"},i=[],u=new Set,c=[...E(this,r)].reverse();for(;c.length;){let l=c.pop();if(!(l instanceof Element)||u.has(l))continue;u.add(l);let g=a(l);g&&g.toLowerCase().includes(o)&&i.push(l);let h=E(l,r);for(let p=h.length-1;p>=0;p-=1)c.push(h[p])}let f=[];for(let l of i){let g=!1;for(let h of i)if(l!==h)try{if(l.contains(h)){g=!0;break}}catch{}if(!g&&(f.push(l),f.length>=e))break}return f}",
14
+ "queryXPathNative": "function H(t,e){let n=v(t);if(!n||!Number.isFinite(e)||e<=0)return[];try{let r=this.evaluate(n,this,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),s=[],o=Math.min(r.snapshotLength,Math.floor(e));for(let a=0;a<o;a+=1){let i=r.snapshotItem(a);i instanceof Element&&s.push(i)}return s}catch{return[]}}",
15
+ "queryXPathWithRoots": "function W(t,e,...n){let r=P(n),s=b(t);if(!s.length)return[];let o=[this];for(let a of s){let i=[],u=new Set;for(let c of o){let l=(a.axis===\"child\"?E(c,r):$(c,r)).filter(h=>q(h,a)),g=R(l,a.predicates);for(let h of g)if(!u.has(h)&&(u.add(h),i.push(h),i.length>=e&&a===s[s.length-1]))break}if(!i.length)return[];o=i}return o.slice(0,e)}"
16
+ };
17
+ export const selectorRuntimeGlobalRefs = {
18
+ "countCssWithRoots": "globalThis.__stagehandSelectorRuntime.countCssWithRoots",
19
+ "countTextWithRoots": "globalThis.__stagehandSelectorRuntime.countTextWithRoots",
20
+ "countXPathNative": "globalThis.__stagehandSelectorRuntime.countXPathNative",
21
+ "countXPathWithRoots": "globalThis.__stagehandSelectorRuntime.countXPathWithRoots",
22
+ "hasOpenShadowRoots": "globalThis.__stagehandSelectorRuntime.hasOpenShadowRoots",
23
+ "queryCssWithRoots": "globalThis.__stagehandSelectorRuntime.queryCssWithRoots",
24
+ "queryTextWithRoots": "globalThis.__stagehandSelectorRuntime.queryTextWithRoots",
25
+ "queryXPathNative": "globalThis.__stagehandSelectorRuntime.queryXPathNative",
26
+ "queryXPathWithRoots": "globalThis.__stagehandSelectorRuntime.queryXPathWithRoots"
27
+ };
28
+ //# sourceMappingURL=selectorRuntime.generated.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectorRuntime.generated.js","sourceRoot":"","sources":["../../../../../../lib/v3/dom/build/selectorRuntime.generated.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,0oRAA0oR,CAAC;AACnrR,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,mBAAmB,EAAE,+EAA+E;IACpG,oBAAoB,EAAE,+EAA+E;IACrG,kBAAkB,EAAE,wOAAwO;IAC5P,qBAAqB,EAAE,+EAA+E;IACtG,oBAAoB,EAAE,6LAA6L;IACnN,mBAAmB,EAAE,iTAAiT;IACtU,oBAAoB,EAAE,8xBAA8xB;IACpzB,kBAAkB,EAAE,+SAA+S;IACnU,qBAAqB,EAAE,mVAAmV;CAClW,CAAC;AACX,MAAM,CAAC,MAAM,yBAAyB,GAAG;IACvC,mBAAmB,EAAE,yDAAyD;IAC9E,oBAAoB,EAAE,0DAA0D;IAChF,kBAAkB,EAAE,wDAAwD;IAC5E,qBAAqB,EAAE,2DAA2D;IAClF,oBAAoB,EAAE,0DAA0D;IAChF,mBAAmB,EAAE,yDAAyD;IAC9E,oBAAoB,EAAE,0DAA0D;IAChF,kBAAkB,EAAE,wDAAwD;IAC5E,qBAAqB,EAAE,2DAA2D;CAC1E,CAAC","sourcesContent":["/*\n * AUTO-GENERATED FILE. DO NOT EDIT.\n * Run `pnpm run build-dom-scripts` to regenerate.\n */\nexport const selectorRuntimeBootstrap = \"if (!globalThis.__stagehandSelectorRuntime) { var __stagehandSelectorRuntimeFactory=(()=>{var P=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var $=(t,e)=>{for(var n in e)P(t,n,{get:e[n],enumerable:!0})},C=(t,e,n,r)=>{if(e&&typeof e==\\\"object\\\"||typeof e==\\\"function\\\")for(let s of N(e))!D.call(t,s)&&s!==n&&P(t,s,{get:()=>e[s],enumerable:!(r=A(e,s))||r.enumerable});return t};var k=t=>C(P({},\\\"__esModule\\\",{value:!0}),t);var j={};$(j,{countCssWithRoots:()=>B,countTextWithRoots:()=>Y,countXPathNative:()=>U,countXPathWithRoots:()=>K,hasOpenShadowRoots:()=>V,queryCssWithRoots:()=>X,queryTextWithRoots:()=>M,queryXPathNative:()=>Z,queryXPathWithRoots:()=>z});function R(t){let e=String(t||\\\"\\\").trim().replace(/^xpath=/i,\\\"\\\");if(!e)return[];let n=[],r=0;for(;r<e.length;){let s=\\\"child\\\";e.startsWith(\\\"//\\\",r)?(s=\\\"desc\\\",r+=2):e[r]===\\\"/\\\"&&(s=\\\"child\\\",r+=1);let o=r,a=0,i=null;for(;r<e.length;){let l=e[r];if(i)l===i&&(i=null);else if(l===\\\"'\\\"||l==='\\\"')i=l;else if(l===\\\"[\\\")a++;else if(l===\\\"]\\\")a--;else if(l===\\\"/\\\"&&a===0)break;r+=1}let u=e.slice(o,r).trim();if(!u)continue;let{tag:c,predicates:f}=W(u);n.push({axis:s,tag:c,predicates:f})}return n}function q(t){let e=[],n=0;for(;n<t.length;){if(t[n]!==\\\"[\\\"){n++;continue}n++;let r=n,s=null;for(;n<t.length;){let o=t[n];if(s)o===s&&(s=null);else if(o===\\\"'\\\"||o==='\\\"')s=o;else if(o===\\\"]\\\")break;n++}e.push(t.slice(r,n).trim()),n++}return e}function W(t){let e=t.indexOf(\\\"[\\\");if(e===-1)return{tag:t===\\\"\\\"?\\\"*\\\":t.toLowerCase(),predicates:[]};let n=t.slice(0,e).trim(),r=n===\\\"\\\"?\\\"*\\\":n.toLowerCase(),s=t.slice(e),o=[];for(let a of q(s)){let i=d(a);i&&o.push(i)}return{tag:r,predicates:o}}function d(t){let e=t.trim();if(!e)return null;let n=y(e,\\\"or\\\");if(n.length>1){let o=n.map(a=>d(a)).filter(Boolean);return o.length!==n.length?null:{type:\\\"or\\\",predicates:o}}let r=y(e,\\\"and\\\");if(r.length>1){let o=r.map(a=>d(a)).filter(Boolean);return o.length!==r.length?null:{type:\\\"and\\\",predicates:o}}let s=O(e,\\\"not\\\");if(s!=null){let o=d(s);return o?{type:\\\"not\\\",predicate:o}:null}return _(e)}function _(t){let e=/^(?:'([^']*)'|\\\"([^\\\"]*)\\\")$/,n=\\\"[a-zA-Z_][\\\\\\\\w.-]*\\\",r=`(?:'([^']*)'|\\\"([^\\\"]*)\\\")`;if(/^\\\\d+$/.test(t))return{type:\\\"index\\\",index:Math.max(1,Number(t))};let s=t.match(new RegExp(`^normalize-space\\\\\\\\(\\\\\\\\s*@(${n})\\\\\\\\s*\\\\\\\\)\\\\\\\\s*=\\\\\\\\s*${r}$`));if(s)return{type:\\\"attrEquals\\\",name:s[1],value:s[2]??s[3]??\\\"\\\",normalize:!0};let o=t.match(new RegExp(`^normalize-space\\\\\\\\(\\\\\\\\s*(?:text\\\\\\\\(\\\\\\\\)|\\\\\\\\.)\\\\\\\\s*\\\\\\\\)\\\\\\\\s*=\\\\\\\\s*${r}$`));if(o)return{type:\\\"textEquals\\\",value:o[1]??o[2]??\\\"\\\",normalize:!0};let a=t.match(new RegExp(`^@(${n})\\\\\\\\s*=\\\\\\\\s*${r}$`));if(a)return{type:\\\"attrEquals\\\",name:a[1],value:a[2]??a[3]??\\\"\\\"};let i=t.match(new RegExp(`^@(${n})$`));if(i)return{type:\\\"attrExists\\\",name:i[1]};let u=t.match(new RegExp(`^contains\\\\\\\\(\\\\\\\\s*@(${n})\\\\\\\\s*,\\\\\\\\s*${r}\\\\\\\\s*\\\\\\\\)$`));if(u)return{type:\\\"attrContains\\\",name:u[1],value:u[2]??u[3]??\\\"\\\"};let c=t.match(new RegExp(`^starts-with\\\\\\\\(\\\\\\\\s*@(${n})\\\\\\\\s*,\\\\\\\\s*${r}\\\\\\\\s*\\\\\\\\)$`));if(c)return{type:\\\"attrStartsWith\\\",name:c[1],value:c[2]??c[3]??\\\"\\\"};let f=t.match(new RegExp(`^(?:text\\\\\\\\(\\\\\\\\)|\\\\\\\\.)\\\\\\\\s*=\\\\\\\\s*${r}$`));if(f)return{type:\\\"textEquals\\\",value:f[1]??f[2]??\\\"\\\"};let l=t.match(new RegExp(`^contains\\\\\\\\(\\\\\\\\s*(?:text\\\\\\\\(\\\\\\\\)|\\\\\\\\.)\\\\\\\\s*,\\\\\\\\s*${r}\\\\\\\\s*\\\\\\\\)$`));return l?{type:\\\"textContains\\\",value:l[1]??l[2]??\\\"\\\"}:(e.test(t),null)}function y(t,e){let n=[],r=0,s=0,o=null,a=0;for(;a<t.length;){let i=t[a];if(o){i===o&&(o=null),a+=1;continue}if(i===\\\"'\\\"||i==='\\\"'){o=i,a+=1;continue}if(i===\\\"(\\\"){s+=1,a+=1;continue}if(i===\\\")\\\"){s=Math.max(0,s-1),a+=1;continue}if(s===0&&L(t,a,e)){n.push(t.slice(r,a).trim()),a+=e.length,r=a;continue}a+=1}return n.push(t.slice(r).trim()),n.filter(i=>i.length>0)}function L(t,e,n){if(!t.startsWith(n,e))return!1;let r=e>0?t[e-1]:\\\" \\\";if(r===\\\"@\\\")return!1;let s=e+n.length<t.length?t[e+n.length]:\\\" \\\";return S(r)&&S(s)}function S(t){return!/[a-zA-Z0-9_.-]/.test(t)}function O(t,e){let n=`${e}(`;if(!t.startsWith(n)||!t.endsWith(\\\")\\\"))return null;let r=t.slice(n.length,-1);return I(r)?r:null}function I(t){let e=0,n=null;for(let r=0;r<t.length;r+=1){let s=t[r];if(n){s===n&&(n=null);continue}if(s===\\\"'\\\"||s==='\\\"'){n=s;continue}if(s===\\\"(\\\"?e+=1:s===\\\")\\\"&&(e-=1),e<0)return!1}return e===0}var F=t=>t.replace(/\\\\s+/g,\\\" \\\").trim();function b(t){return String(t.textContent??\\\"\\\")}function m(t,e){return e?F(t):t}function x(t,e){switch(e.type){case\\\"and\\\":return e.predicates.every(n=>x(t,n));case\\\"or\\\":return e.predicates.some(n=>x(t,n));case\\\"not\\\":return!x(t,e.predicate);case\\\"attrExists\\\":return t.getAttribute(e.name)!==null;case\\\"attrEquals\\\":{let n=t.getAttribute(e.name);return n===null?!1:m(n,e.normalize)===m(e.value,e.normalize)}case\\\"attrContains\\\":{let n=t.getAttribute(e.name);return n===null?!1:m(n,e.normalize).includes(m(e.value,e.normalize))}case\\\"attrStartsWith\\\":{let n=t.getAttribute(e.name);return n===null?!1:m(n,e.normalize).startsWith(m(e.value,e.normalize))}case\\\"textEquals\\\":return m(b(t),e.normalize)===m(e.value,e.normalize);case\\\"textContains\\\":return m(b(t),e.normalize).includes(m(e.value,e.normalize));case\\\"index\\\":return!0;default:return!0}}function v(t,e){let n=t;for(let r of e){if(!n.length)return[];if(r.type===\\\"index\\\"){let s=r.index-1;n=s>=0&&s<n.length?[n[s]]:[];continue}n=n.filter(s=>x(s,r))}return n}function w(t){let e=new Map;for(let n=0;n<t.length;n+=2){let r=t[n],s=t[n+1];r instanceof Element&&s instanceof ShadowRoot&&e.set(r,s)}return e}function E(t,e){if(!t)return[];if(t instanceof Document)return t.documentElement?[t.documentElement]:[];if(t instanceof ShadowRoot||t instanceof DocumentFragment)return Array.from(t.children||[]);if(!(t instanceof Element))return[];let n=Array.from(t.children||[]);t.shadowRoot&&n.push(...Array.from(t.shadowRoot.children||[]));let r=e.get(t);return r&&n.push(...Array.from(r.children||[])),n}function H(t,e){let n=[],r=new Set,s=[...E(t,e)].reverse();for(;s.length;){let o=s.pop();if(!(o instanceof Element)||r.has(o))continue;r.add(o),n.push(o);let a=E(o,e);for(let i=a.length-1;i>=0;i-=1)s.push(a[i])}return n}function X(t,e,...n){let r=w(n),s=[],o=new Set,a=[...E(this,r)].reverse();for(;a.length&&s.length<e;){let i=a.pop();if(!(i instanceof Element)||o.has(i))continue;o.add(i);try{if(i.matches(t)&&(s.push(i),s.length>=e))break}catch{return[]}let u=E(i,r);for(let c=u.length-1;c>=0;c-=1)a.push(u[c])}return s}function B(t,...e){return X.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}function M(t,e,...n){let r=w(n),s=new Set([\\\"SCRIPT\\\",\\\"STYLE\\\",\\\"TEMPLATE\\\",\\\"NOSCRIPT\\\",\\\"HEAD\\\",\\\"TITLE\\\",\\\"LINK\\\",\\\"META\\\",\\\"HTML\\\",\\\"BODY\\\"]),o=String(t||\\\"\\\").toLowerCase();if(!o)return[];let a=l=>{let g=l.tagName?l.tagName.toUpperCase():\\\"\\\";if(s.has(g))return\\\"\\\";try{let p=l.innerText;if(typeof p==\\\"string\\\"&&p.trim())return p.trim()}catch{}let h=l.textContent;return typeof h==\\\"string\\\"?h.trim():\\\"\\\"},i=[],u=new Set,c=[...E(this,r)].reverse();for(;c.length;){let l=c.pop();if(!(l instanceof Element)||u.has(l))continue;u.add(l);let g=a(l);g&&g.toLowerCase().includes(o)&&i.push(l);let h=E(l,r);for(let p=h.length-1;p>=0;p-=1)c.push(h[p])}let f=[];for(let l of i){let g=!1;for(let h of i)if(l!==h)try{if(l.contains(h)){g=!0;break}}catch{}if(!g&&(f.push(l),f.length>=e))break}return f}function Y(t,...e){return M.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}function T(t){let e=String(t||\\\"\\\").trim();return e?e.replace(/^xpath=/i,\\\"\\\").trim():\\\"\\\"}function G(t,e){return e.tag===\\\"*\\\"?!0:t.localName===e.tag}function z(t,e,...n){let r=w(n),s=R(t);if(!s.length)return[];let o=[this];for(let a of s){let i=[],u=new Set;for(let c of o){let l=(a.axis===\\\"child\\\"?E(c,r):H(c,r)).filter(h=>G(h,a)),g=v(l,a.predicates);for(let h of g)if(!u.has(h)&&(u.add(h),i.push(h),i.length>=e&&a===s[s.length-1]))break}if(!i.length)return[];o=i}return o.slice(0,e)}function K(t,...e){return z.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}function Z(t,e){let n=T(t);if(!n||!Number.isFinite(e)||e<=0)return[];try{let r=this.evaluate(n,this,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),s=[],o=Math.min(r.snapshotLength,Math.floor(e));for(let a=0;a<o;a+=1){let i=r.snapshotItem(a);i instanceof Element&&s.push(i)}return s}catch{return[]}}function U(t){let e=T(t);if(!e)return 0;try{let n=this.evaluate(e,this,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),r=0;for(let s=0;s<n.snapshotLength;s+=1)n.snapshotItem(s)instanceof Element&&(r+=1);return r}catch{return 0}}function V(){try{let t=this.createTreeWalker(this,NodeFilter.SHOW_ELEMENT);for(;t.nextNode();){let e=t.currentNode;if(e instanceof Element&&e.shadowRoot)return!0}}catch{return!1}return!1}return k(j);})();\\n globalThis.__stagehandSelectorRuntime = __stagehandSelectorRuntimeFactory;\\n}\";\nexport const selectorRuntimeSources = {\n \"countCssWithRoots\": \"function O(t,...e){return C.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}\",\n \"countTextWithRoots\": \"function I(t,...e){return k.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}\",\n \"countXPathNative\": \"function B(t){let e=v(t);if(!e)return 0;try{let n=this.evaluate(e,this,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),r=0;for(let s=0;s<n.snapshotLength;s+=1)n.snapshotItem(s)instanceof Element&&(r+=1);return r}catch{return 0}}\",\n \"countXPathWithRoots\": \"function F(t,...e){return W.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}\",\n \"hasOpenShadowRoots\": \"function Y(){try{let t=this.createTreeWalker(this,NodeFilter.SHOW_ELEMENT);for(;t.nextNode();){let e=t.currentNode;if(e instanceof Element&&e.shadowRoot)return!0}}catch{return!1}return!1}\",\n \"queryCssWithRoots\": \"function C(t,e,...n){let r=P(n),s=[],o=new Set,a=[...E(this,r)].reverse();for(;a.length&&s.length<e;){let i=a.pop();if(!(i instanceof Element)||o.has(i))continue;o.add(i);try{if(i.matches(t)&&(s.push(i),s.length>=e))break}catch{return[]}let u=E(i,r);for(let c=u.length-1;c>=0;c-=1)a.push(u[c])}return s}\",\n \"queryTextWithRoots\": \"function k(t,e,...n){let r=P(n),s=new Set([\\\"SCRIPT\\\",\\\"STYLE\\\",\\\"TEMPLATE\\\",\\\"NOSCRIPT\\\",\\\"HEAD\\\",\\\"TITLE\\\",\\\"LINK\\\",\\\"META\\\",\\\"HTML\\\",\\\"BODY\\\"]),o=String(t||\\\"\\\").toLowerCase();if(!o)return[];let a=l=>{let g=l.tagName?l.tagName.toUpperCase():\\\"\\\";if(s.has(g))return\\\"\\\";try{let p=l.innerText;if(typeof p==\\\"string\\\"&&p.trim())return p.trim()}catch{}let h=l.textContent;return typeof h==\\\"string\\\"?h.trim():\\\"\\\"},i=[],u=new Set,c=[...E(this,r)].reverse();for(;c.length;){let l=c.pop();if(!(l instanceof Element)||u.has(l))continue;u.add(l);let g=a(l);g&&g.toLowerCase().includes(o)&&i.push(l);let h=E(l,r);for(let p=h.length-1;p>=0;p-=1)c.push(h[p])}let f=[];for(let l of i){let g=!1;for(let h of i)if(l!==h)try{if(l.contains(h)){g=!0;break}}catch{}if(!g&&(f.push(l),f.length>=e))break}return f}\",\n \"queryXPathNative\": \"function H(t,e){let n=v(t);if(!n||!Number.isFinite(e)||e<=0)return[];try{let r=this.evaluate(n,this,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),s=[],o=Math.min(r.snapshotLength,Math.floor(e));for(let a=0;a<o;a+=1){let i=r.snapshotItem(a);i instanceof Element&&s.push(i)}return s}catch{return[]}}\",\n \"queryXPathWithRoots\": \"function W(t,e,...n){let r=P(n),s=b(t);if(!s.length)return[];let o=[this];for(let a of s){let i=[],u=new Set;for(let c of o){let l=(a.axis===\\\"child\\\"?E(c,r):$(c,r)).filter(h=>q(h,a)),g=R(l,a.predicates);for(let h of g)if(!u.has(h)&&(u.add(h),i.push(h),i.length>=e&&a===s[s.length-1]))break}if(!i.length)return[];o=i}return o.slice(0,e)}\"\n} as const;\nexport const selectorRuntimeGlobalRefs = {\n \"countCssWithRoots\": \"globalThis.__stagehandSelectorRuntime.countCssWithRoots\",\n \"countTextWithRoots\": \"globalThis.__stagehandSelectorRuntime.countTextWithRoots\",\n \"countXPathNative\": \"globalThis.__stagehandSelectorRuntime.countXPathNative\",\n \"countXPathWithRoots\": \"globalThis.__stagehandSelectorRuntime.countXPathWithRoots\",\n \"hasOpenShadowRoots\": \"globalThis.__stagehandSelectorRuntime.hasOpenShadowRoots\",\n \"queryCssWithRoots\": \"globalThis.__stagehandSelectorRuntime.queryCssWithRoots\",\n \"queryTextWithRoots\": \"globalThis.__stagehandSelectorRuntime.queryTextWithRoots\",\n \"queryXPathNative\": \"globalThis.__stagehandSelectorRuntime.queryXPathNative\",\n \"queryXPathWithRoots\": \"globalThis.__stagehandSelectorRuntime.queryXPathWithRoots\"\n} as const;\nexport type SelectorRuntimeName = keyof typeof selectorRuntimeSources;\n"]}
@@ -41,7 +41,7 @@ export class ExtractHandler {
41
41
  this.onMetrics = onMetrics;
42
42
  }
43
43
  async extract(params) {
44
- const { instruction, schema, page, selector, timeout, model } = params;
44
+ const { instruction, schema, page, selector, ignoreSelectors, timeout, model, } = params;
45
45
  const llmClient = this.resolveLlmClient(model);
46
46
  const ensureTimeRemaining = createTimeoutGuard(timeout, (ms) => new ExtractTimeoutError(ms));
47
47
  // No-args → page text (parity with v2)
@@ -52,6 +52,7 @@ export class ExtractHandler {
52
52
  const snap = await captureHybridSnapshot(page, {
53
53
  experimental: this.experimental,
54
54
  focusSelector: focusSelector || undefined,
55
+ ignoreSelectors,
55
56
  });
56
57
  ensureTimeRemaining();
57
58
  const result = { pageText: snap.combinedTree };
@@ -67,6 +68,7 @@ export class ExtractHandler {
67
68
  const { combinedTree, combinedUrlMap } = await captureHybridSnapshot(page, {
68
69
  experimental: this.experimental,
69
70
  focusSelector: focusSelector,
71
+ ignoreSelectors,
70
72
  });
71
73
  v3Logger({
72
74
  category: "extraction",
@@ -1 +1 @@
1
- {"version":3,"file":"extractHandler.js","sourceRoot":"","sources":["../../../../../lib/v3/handlers/extractHandler.ts"],"names":[],"mappings":"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","sourcesContent":["// lib/v3/handlers/extractHandler.ts\nimport { extract as runExtract } from \"../../inference.js\";\nimport {\n getZFactory,\n getZodType,\n injectUrls,\n transformSchema,\n} from \"../../utils.js\";\nimport { v3Logger } from \"../logger.js\";\nimport { V3FunctionName } from \"../types/public/methods.js\";\nimport { captureHybridSnapshot } from \"../understudy/a11y/snapshot/index.js\";\nimport type { ZodTypeAny } from \"zod\";\nimport { LLMClient } from \"../llm/LLMClient.js\";\nimport { ExtractHandlerParams } from \"../types/private/handlers.js\";\nimport { EncodedId, ZodPathSegments } from \"../types/private/internal.js\";\nimport {\n defaultExtractSchema,\n pageTextSchema,\n} from \"../types/public/methods.js\";\nimport {\n AvailableModel,\n ClientOptions,\n ModelConfiguration,\n} from \"../types/public/model.js\";\nimport {\n StagehandInvalidArgumentError,\n ExtractTimeoutError,\n} from \"../types/public/sdkErrors.js\";\nimport { createTimeoutGuard } from \"./handlerUtils/timeoutGuard.js\";\nimport type {\n InferStagehandSchema,\n StagehandZodObject,\n StagehandZodSchema,\n} from \"../zodCompat.js\";\n\n/**\n * Scans the provided Zod schema for any `z.string().url()` fields and\n * replaces them with `z.number()`.\n *\n * @param schema - The Zod object schema to transform.\n * @returns A tuple containing:\n * 1. The transformed schema (or the original schema if no changes were needed).\n * 2. An array of {@link ZodPathSegments} objects representing all the replaced URL fields,\n * with each path segment showing where in the schema the replacement occurred.\n */\nexport function transformUrlStringsToNumericIds<T extends StagehandZodSchema>(\n schema: T,\n): [StagehandZodSchema, ZodPathSegments[]] {\n const [finalSchema, urlPaths] = transformSchema(schema, []);\n return [finalSchema, urlPaths];\n}\n\ninterface ExtractionResponseBase {\n metadata: { completed: boolean };\n prompt_tokens: number;\n completion_tokens: number;\n reasoning_tokens: number;\n cached_input_tokens?: number;\n inference_time_ms: number;\n}\n\ntype ExtractionResponse<T extends StagehandZodObject> = ExtractionResponseBase &\n InferStagehandSchema<T>;\n\nexport class ExtractHandler {\n private readonly llmClient: LLMClient;\n private readonly defaultModelName: AvailableModel;\n private readonly defaultClientOptions: ClientOptions;\n private readonly resolveLlmClient: (model?: ModelConfiguration) => LLMClient;\n private readonly systemPrompt: string;\n private readonly logInferenceToFile: boolean;\n private readonly experimental: boolean;\n private readonly onMetrics?: (\n functionName: V3FunctionName,\n promptTokens: number,\n completionTokens: number,\n reasoningTokens: number,\n cachedInputTokens: number,\n inferenceTimeMs: number,\n ) => void;\n\n constructor(\n llmClient: LLMClient,\n defaultModelName: AvailableModel,\n defaultClientOptions: ClientOptions,\n resolveLlmClient: (model?: ModelConfiguration) => LLMClient,\n systemPrompt?: string,\n logInferenceToFile?: boolean,\n experimental?: boolean,\n onMetrics?: (\n functionName: V3FunctionName,\n promptTokens: number,\n completionTokens: number,\n reasoningTokens: number,\n cachedInputTokens: number,\n inferenceTimeMs: number,\n ) => void,\n ) {\n this.llmClient = llmClient;\n this.defaultModelName = defaultModelName;\n this.defaultClientOptions = defaultClientOptions;\n this.resolveLlmClient = resolveLlmClient;\n this.systemPrompt = systemPrompt ?? \"\";\n this.logInferenceToFile = logInferenceToFile ?? false;\n this.experimental = experimental ?? false;\n this.onMetrics = onMetrics;\n }\n\n async extract<T extends StagehandZodSchema>(\n params: ExtractHandlerParams<T>,\n ): Promise<InferStagehandSchema<T> | { pageText: string }> {\n const { instruction, schema, page, selector, timeout, model } = params;\n\n const llmClient = this.resolveLlmClient(model);\n\n const ensureTimeRemaining = createTimeoutGuard(\n timeout,\n (ms) => new ExtractTimeoutError(ms),\n );\n\n // No-args → page text (parity with v2)\n const noArgs = !instruction && !schema;\n if (noArgs) {\n const focusSelector = selector?.replace(/^xpath=/i, \"\") ?? \"\";\n ensureTimeRemaining();\n const snap = await captureHybridSnapshot(page, {\n experimental: this.experimental,\n focusSelector: focusSelector || undefined,\n });\n ensureTimeRemaining();\n\n const result = { pageText: snap.combinedTree };\n // Validate via the same schema used in v2\n return pageTextSchema.parse(result);\n }\n\n if (!instruction && schema) {\n throw new StagehandInvalidArgumentError(\n \"extract() requires an instruction when a schema is provided.\",\n );\n }\n\n const focusSelector = selector?.replace(/^xpath=/, \"\") ?? \"\";\n\n // Build the hybrid snapshot (includes combinedTree; combinedUrlMap optional)\n ensureTimeRemaining();\n const { combinedTree, combinedUrlMap } = await captureHybridSnapshot(page, {\n experimental: this.experimental,\n focusSelector: focusSelector,\n });\n\n v3Logger({\n category: \"extraction\",\n message: \"Starting extraction using a11y snapshot\",\n level: 1,\n auxiliary: instruction\n ? { instruction: { value: instruction, type: \"string\" } }\n : undefined,\n });\n\n // Normalize schema: if instruction provided without schema, use defaultExtractSchema\n const baseSchema: StagehandZodSchema = (schema ??\n defaultExtractSchema) as StagehandZodSchema;\n // Ensure we pass an object schema into inference; wrap non-object schemas\n const isObjectSchema = getZodType(baseSchema) === \"object\";\n const WRAP_KEY = \"value\" as const;\n const factory = getZFactory(baseSchema);\n const objectSchema: StagehandZodObject = isObjectSchema\n ? (baseSchema as StagehandZodObject)\n : (factory.object({\n [WRAP_KEY]: baseSchema as ZodTypeAny,\n }) as StagehandZodObject);\n\n const [transformedSchema, urlFieldPaths] =\n transformUrlStringsToNumericIds(objectSchema);\n\n ensureTimeRemaining();\n const extractionResponse: ExtractionResponse<StagehandZodObject> =\n await runExtract<StagehandZodObject>({\n instruction,\n domElements: combinedTree,\n schema: transformedSchema as StagehandZodObject,\n llmClient,\n userProvidedInstructions: this.systemPrompt,\n logger: v3Logger,\n logInferenceToFile: this.logInferenceToFile,\n });\n\n const {\n metadata: { completed },\n prompt_tokens,\n completion_tokens,\n reasoning_tokens = 0,\n cached_input_tokens = 0,\n inference_time_ms,\n ...rest\n } = extractionResponse;\n let output = rest as InferStagehandSchema<StagehandZodObject>;\n\n // Update EXTRACT metrics from the LLM calls\n this.onMetrics?.(\n V3FunctionName.EXTRACT,\n prompt_tokens,\n completion_tokens,\n reasoning_tokens,\n cached_input_tokens,\n inference_time_ms,\n );\n\n // Re-inject URLs for any url() fields we temporarily converted to number()\n const idToUrl: Record<EncodedId, string> = (combinedUrlMap ?? {}) as Record<\n EncodedId,\n string\n >;\n for (const { segments } of urlFieldPaths) {\n injectUrls(\n output as Record<string, unknown>,\n segments,\n idToUrl as unknown as Record<string, string>,\n );\n }\n // If we wrapped a non-object schema, unwrap the value\n if (!isObjectSchema && output && typeof output === \"object\") {\n output = (output as Record<string, unknown>)[WRAP_KEY];\n }\n\n const resultPreviewLength = 200;\n const resultString = JSON.stringify(output) ?? \"undefined\";\n const resultPreview =\n resultString.length > resultPreviewLength\n ? resultString.slice(0, resultPreviewLength) + \"...\"\n : resultString;\n\n v3Logger({\n category: \"extraction\",\n message: completed\n ? \"Extraction completed successfully\"\n : \"Extraction incomplete after processing all data\",\n level: 1,\n auxiliary: {\n prompt_tokens: { value: String(prompt_tokens), type: \"string\" },\n completion_tokens: { value: String(completion_tokens), type: \"string\" },\n inference_time_ms: {\n value: String(inference_time_ms),\n type: \"string\",\n },\n result: { value: resultPreview, type: \"string\" },\n },\n });\n\n return output as InferStagehandSchema<T>;\n }\n}\n"]}
1
+ {"version":3,"file":"extractHandler.js","sourceRoot":"","sources":["../../../../../lib/v3/handlers/extractHandler.ts"],"names":[],"mappings":"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","sourcesContent":["// lib/v3/handlers/extractHandler.ts\nimport { extract as runExtract } from \"../../inference.js\";\nimport {\n getZFactory,\n getZodType,\n injectUrls,\n transformSchema,\n} from \"../../utils.js\";\nimport { v3Logger } from \"../logger.js\";\nimport { V3FunctionName } from \"../types/public/methods.js\";\nimport { captureHybridSnapshot } from \"../understudy/a11y/snapshot/index.js\";\nimport type { ZodTypeAny } from \"zod\";\nimport { LLMClient } from \"../llm/LLMClient.js\";\nimport { ExtractHandlerParams } from \"../types/private/handlers.js\";\nimport { EncodedId, ZodPathSegments } from \"../types/private/internal.js\";\nimport {\n defaultExtractSchema,\n pageTextSchema,\n} from \"../types/public/methods.js\";\nimport {\n AvailableModel,\n ClientOptions,\n ModelConfiguration,\n} from \"../types/public/model.js\";\nimport {\n StagehandInvalidArgumentError,\n ExtractTimeoutError,\n} from \"../types/public/sdkErrors.js\";\nimport { createTimeoutGuard } from \"./handlerUtils/timeoutGuard.js\";\nimport type {\n InferStagehandSchema,\n StagehandZodObject,\n StagehandZodSchema,\n} from \"../zodCompat.js\";\n\n/**\n * Scans the provided Zod schema for any `z.string().url()` fields and\n * replaces them with `z.number()`.\n *\n * @param schema - The Zod object schema to transform.\n * @returns A tuple containing:\n * 1. The transformed schema (or the original schema if no changes were needed).\n * 2. An array of {@link ZodPathSegments} objects representing all the replaced URL fields,\n * with each path segment showing where in the schema the replacement occurred.\n */\nexport function transformUrlStringsToNumericIds<T extends StagehandZodSchema>(\n schema: T,\n): [StagehandZodSchema, ZodPathSegments[]] {\n const [finalSchema, urlPaths] = transformSchema(schema, []);\n return [finalSchema, urlPaths];\n}\n\ninterface ExtractionResponseBase {\n metadata: { completed: boolean };\n prompt_tokens: number;\n completion_tokens: number;\n reasoning_tokens: number;\n cached_input_tokens?: number;\n inference_time_ms: number;\n}\n\ntype ExtractionResponse<T extends StagehandZodObject> = ExtractionResponseBase &\n InferStagehandSchema<T>;\n\nexport class ExtractHandler {\n private readonly llmClient: LLMClient;\n private readonly defaultModelName: AvailableModel;\n private readonly defaultClientOptions: ClientOptions;\n private readonly resolveLlmClient: (model?: ModelConfiguration) => LLMClient;\n private readonly systemPrompt: string;\n private readonly logInferenceToFile: boolean;\n private readonly experimental: boolean;\n private readonly onMetrics?: (\n functionName: V3FunctionName,\n promptTokens: number,\n completionTokens: number,\n reasoningTokens: number,\n cachedInputTokens: number,\n inferenceTimeMs: number,\n ) => void;\n\n constructor(\n llmClient: LLMClient,\n defaultModelName: AvailableModel,\n defaultClientOptions: ClientOptions,\n resolveLlmClient: (model?: ModelConfiguration) => LLMClient,\n systemPrompt?: string,\n logInferenceToFile?: boolean,\n experimental?: boolean,\n onMetrics?: (\n functionName: V3FunctionName,\n promptTokens: number,\n completionTokens: number,\n reasoningTokens: number,\n cachedInputTokens: number,\n inferenceTimeMs: number,\n ) => void,\n ) {\n this.llmClient = llmClient;\n this.defaultModelName = defaultModelName;\n this.defaultClientOptions = defaultClientOptions;\n this.resolveLlmClient = resolveLlmClient;\n this.systemPrompt = systemPrompt ?? \"\";\n this.logInferenceToFile = logInferenceToFile ?? false;\n this.experimental = experimental ?? false;\n this.onMetrics = onMetrics;\n }\n\n async extract<T extends StagehandZodSchema>(\n params: ExtractHandlerParams<T>,\n ): Promise<InferStagehandSchema<T> | { pageText: string }> {\n const {\n instruction,\n schema,\n page,\n selector,\n ignoreSelectors,\n timeout,\n model,\n } = params;\n\n const llmClient = this.resolveLlmClient(model);\n\n const ensureTimeRemaining = createTimeoutGuard(\n timeout,\n (ms) => new ExtractTimeoutError(ms),\n );\n\n // No-args → page text (parity with v2)\n const noArgs = !instruction && !schema;\n if (noArgs) {\n const focusSelector = selector?.replace(/^xpath=/i, \"\") ?? \"\";\n ensureTimeRemaining();\n const snap = await captureHybridSnapshot(page, {\n experimental: this.experimental,\n focusSelector: focusSelector || undefined,\n ignoreSelectors,\n });\n ensureTimeRemaining();\n\n const result = { pageText: snap.combinedTree };\n // Validate via the same schema used in v2\n return pageTextSchema.parse(result);\n }\n\n if (!instruction && schema) {\n throw new StagehandInvalidArgumentError(\n \"extract() requires an instruction when a schema is provided.\",\n );\n }\n\n const focusSelector = selector?.replace(/^xpath=/, \"\") ?? \"\";\n\n // Build the hybrid snapshot (includes combinedTree; combinedUrlMap optional)\n ensureTimeRemaining();\n const { combinedTree, combinedUrlMap } = await captureHybridSnapshot(page, {\n experimental: this.experimental,\n focusSelector: focusSelector,\n ignoreSelectors,\n });\n\n v3Logger({\n category: \"extraction\",\n message: \"Starting extraction using a11y snapshot\",\n level: 1,\n auxiliary: instruction\n ? { instruction: { value: instruction, type: \"string\" } }\n : undefined,\n });\n\n // Normalize schema: if instruction provided without schema, use defaultExtractSchema\n const baseSchema: StagehandZodSchema = (schema ??\n defaultExtractSchema) as StagehandZodSchema;\n // Ensure we pass an object schema into inference; wrap non-object schemas\n const isObjectSchema = getZodType(baseSchema) === \"object\";\n const WRAP_KEY = \"value\" as const;\n const factory = getZFactory(baseSchema);\n const objectSchema: StagehandZodObject = isObjectSchema\n ? (baseSchema as StagehandZodObject)\n : (factory.object({\n [WRAP_KEY]: baseSchema as ZodTypeAny,\n }) as StagehandZodObject);\n\n const [transformedSchema, urlFieldPaths] =\n transformUrlStringsToNumericIds(objectSchema);\n\n ensureTimeRemaining();\n const extractionResponse: ExtractionResponse<StagehandZodObject> =\n await runExtract<StagehandZodObject>({\n instruction,\n domElements: combinedTree,\n schema: transformedSchema as StagehandZodObject,\n llmClient,\n userProvidedInstructions: this.systemPrompt,\n logger: v3Logger,\n logInferenceToFile: this.logInferenceToFile,\n });\n\n const {\n metadata: { completed },\n prompt_tokens,\n completion_tokens,\n reasoning_tokens = 0,\n cached_input_tokens = 0,\n inference_time_ms,\n ...rest\n } = extractionResponse;\n let output = rest as InferStagehandSchema<StagehandZodObject>;\n\n // Update EXTRACT metrics from the LLM calls\n this.onMetrics?.(\n V3FunctionName.EXTRACT,\n prompt_tokens,\n completion_tokens,\n reasoning_tokens,\n cached_input_tokens,\n inference_time_ms,\n );\n\n // Re-inject URLs for any url() fields we temporarily converted to number()\n const idToUrl: Record<EncodedId, string> = (combinedUrlMap ?? {}) as Record<\n EncodedId,\n string\n >;\n for (const { segments } of urlFieldPaths) {\n injectUrls(\n output as Record<string, unknown>,\n segments,\n idToUrl as unknown as Record<string, string>,\n );\n }\n // If we wrapped a non-object schema, unwrap the value\n if (!isObjectSchema && output && typeof output === \"object\") {\n output = (output as Record<string, unknown>)[WRAP_KEY];\n }\n\n const resultPreviewLength = 200;\n const resultString = JSON.stringify(output) ?? \"undefined\";\n const resultPreview =\n resultString.length > resultPreviewLength\n ? resultString.slice(0, resultPreviewLength) + \"...\"\n : resultString;\n\n v3Logger({\n category: \"extraction\",\n message: completed\n ? \"Extraction completed successfully\"\n : \"Extraction incomplete after processing all data\",\n level: 1,\n auxiliary: {\n prompt_tokens: { value: String(prompt_tokens), type: \"string\" },\n completion_tokens: { value: String(completion_tokens), type: \"string\" },\n inference_time_ms: {\n value: String(inference_time_ms),\n type: \"string\",\n },\n result: { value: resultPreview, type: \"string\" },\n },\n });\n\n return output as InferStagehandSchema<T>;\n }\n}\n"]}
@@ -27,7 +27,7 @@ export class ObserveHandler {
27
27
  this.onMetrics = onMetrics;
28
28
  }
29
29
  async observe(params) {
30
- const { instruction, page, timeout, selector, model, variables } = params;
30
+ const { instruction, page, timeout, selector, ignoreSelectors, model, variables, } = params;
31
31
  const llmClient = this.resolveLlmClient(model);
32
32
  const ensureTimeRemaining = createTimeoutGuard(timeout, (ms) => new ObserveTimeoutError(ms));
33
33
  const effectiveInstruction = instruction ??
@@ -49,6 +49,7 @@ export class ObserveHandler {
49
49
  const snapshot = await captureHybridSnapshot(page, {
50
50
  experimental: this.experimental,
51
51
  focusSelector: focusSelector || undefined,
52
+ ignoreSelectors,
52
53
  });
53
54
  const combinedTree = snapshot.combinedTree;
54
55
  const combinedXpathMap = snapshot.combinedXpathMap ?? {};