@browserbasehq/orca 3.2.1-preview.2 → 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 +2 -9
  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 +1 -1
  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 +1 -1
  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 +1 -1
  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 +2 -9
  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 +1 -1
  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 +1 -1
  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 +1 -1
  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,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.reRenderScriptContent = void 0;
4
- exports.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";
4
+ exports.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();})();";
5
5
  //# sourceMappingURL=reRenderScriptContent.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"reRenderScriptContent.js","sourceRoot":"","sources":["../../../../../../lib/v3/dom/build/reRenderScriptContent.ts"],"names":[],"mappings":";;;AAAa,QAAA,qBAAqB,GAAG,goBAAgoB,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
+ {"version":3,"file":"reRenderScriptContent.js","sourceRoot":"","sources":["../../../../../../lib/v3/dom/build/reRenderScriptContent.ts"],"names":[],"mappings":";;;AAAa,QAAA,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"]}
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.screenshotScriptSources = void 0;
4
4
  /*
5
5
  * AUTO-GENERATED FILE. DO NOT EDIT.
6
- * Update sources in lib/v3/dom/screenshotScripts and run genScreenshotScripts.ts.
6
+ * Run `pnpm run build-dom-scripts` to regenerate.
7
7
  */
8
8
  exports.screenshotScriptSources = {
9
9
  "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}}"
@@ -1 +1 @@
1
- {"version":3,"file":"screenshotScripts.generated.js","sourceRoot":"","sources":["../../../../../../lib/v3/dom/build/screenshotScripts.generated.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACU,QAAA,uBAAuB,GAAG;IACrC,iBAAiB,EAAE,ilCAAilC;CAC5lC,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\": \"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;AACU,QAAA,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,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.v3ScriptContent = void 0;
4
- exports.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";
4
+ exports.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});})();";
5
5
  //# sourceMappingURL=scriptV3Content.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"scriptV3Content.js","sourceRoot":"","sources":["../../../../../../lib/v3/dom/build/scriptV3Content.ts"],"names":[],"mappings":";;;AAAa,QAAA,eAAe,GAAG,8pCAA8pC,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\";"]}
1
+ {"version":3,"file":"scriptV3Content.js","sourceRoot":"","sources":["../../../../../../lib/v3/dom/build/scriptV3Content.ts"],"names":[],"mappings":";;;AAAa,QAAA,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,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.selectorRuntimeGlobalRefs = exports.selectorRuntimeSources = exports.selectorRuntimeBootstrap = void 0;
4
+ /*
5
+ * AUTO-GENERATED FILE. DO NOT EDIT.
6
+ * Run `pnpm run build-dom-scripts` to regenerate.
7
+ */
8
+ exports.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}";
9
+ exports.selectorRuntimeSources = {
10
+ "countCssWithRoots": "function O(t,...e){return C.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}",
11
+ "countTextWithRoots": "function I(t,...e){return k.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}",
12
+ "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}}",
13
+ "countXPathWithRoots": "function F(t,...e){return W.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}",
14
+ "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}",
15
+ "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}",
16
+ "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}",
17
+ "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[]}}",
18
+ "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)}"
19
+ };
20
+ exports.selectorRuntimeGlobalRefs = {
21
+ "countCssWithRoots": "globalThis.__stagehandSelectorRuntime.countCssWithRoots",
22
+ "countTextWithRoots": "globalThis.__stagehandSelectorRuntime.countTextWithRoots",
23
+ "countXPathNative": "globalThis.__stagehandSelectorRuntime.countXPathNative",
24
+ "countXPathWithRoots": "globalThis.__stagehandSelectorRuntime.countXPathWithRoots",
25
+ "hasOpenShadowRoots": "globalThis.__stagehandSelectorRuntime.hasOpenShadowRoots",
26
+ "queryCssWithRoots": "globalThis.__stagehandSelectorRuntime.queryCssWithRoots",
27
+ "queryTextWithRoots": "globalThis.__stagehandSelectorRuntime.queryTextWithRoots",
28
+ "queryXPathNative": "globalThis.__stagehandSelectorRuntime.queryXPathNative",
29
+ "queryXPathWithRoots": "globalThis.__stagehandSelectorRuntime.queryXPathWithRoots"
30
+ };
31
+ //# 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;AACU,QAAA,wBAAwB,GAAG,0oRAA0oR,CAAC;AACtqR,QAAA,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;AACE,QAAA,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"]}
@@ -45,7 +45,7 @@ class ExtractHandler {
45
45
  this.onMetrics = onMetrics;
46
46
  }
47
47
  async extract(params) {
48
- const { instruction, schema, page, selector, timeout, model } = params;
48
+ const { instruction, schema, page, selector, ignoreSelectors, timeout, model, } = params;
49
49
  const llmClient = this.resolveLlmClient(model);
50
50
  const ensureTimeRemaining = (0, timeoutGuard_js_1.createTimeoutGuard)(timeout, (ms) => new sdkErrors_js_1.ExtractTimeoutError(ms));
51
51
  // No-args → page text (parity with v2)
@@ -56,6 +56,7 @@ class ExtractHandler {
56
56
  const snap = await (0, index_js_1.captureHybridSnapshot)(page, {
57
57
  experimental: this.experimental,
58
58
  focusSelector: focusSelector || undefined,
59
+ ignoreSelectors,
59
60
  });
60
61
  ensureTimeRemaining();
61
62
  const result = { pageText: snap.combinedTree };
@@ -71,6 +72,7 @@ class ExtractHandler {
71
72
  const { combinedTree, combinedUrlMap } = await (0, index_js_1.captureHybridSnapshot)(page, {
72
73
  experimental: this.experimental,
73
74
  focusSelector: focusSelector,
75
+ ignoreSelectors,
74
76
  });
75
77
  (0, logger_js_1.v3Logger)({
76
78
  category: "extraction",
@@ -1 +1 @@
1
- {"version":3,"file":"extractHandler.js","sourceRoot":"","sources":["../../../../../lib/v3/handlers/extractHandler.ts"],"names":[],"mappings":";;;AA6CA,0EAKC;AAlDD,oCAAoC;AACpC,qDAA2D;AAC3D,6CAKwB;AACxB,4CAAwC;AACxC,2DAA4D;AAC5D,mEAA6E;AAK7E,2DAGoC;AAMpC,+DAGsC;AACtC,oEAAoE;AAOpE;;;;;;;;;GASG;AACH,SAAgB,+BAA+B,CAC7C,MAAS;IAET,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,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\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":";;;AA6CA,0EAKC;AAlDD,oCAAoC;AACpC,qDAA2D;AAC3D,6CAKwB;AACxB,4CAAwC;AACxC,2DAA4D;AAC5D,mEAA6E;AAK7E,2DAGoC;AAMpC,+DAGsC;AACtC,oEAAoE;AAOpE;;;;;;;;;GASG;AACH,SAAgB,+BAA+B,CAC7C,MAAS;IAET,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,GAAG,IAAA,0BAAe,EAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAC5D,OAAO,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;AACjC,CAAC;AAcD,MAAa,cAAc;IACR,SAAS,CAAY;IACrB,gBAAgB,CAAiB;IACjC,oBAAoB,CAAgB;IACpC,gBAAgB,CAA4C;IAC5D,YAAY,CAAS;IACrB,kBAAkB,CAAU;IAC5B,YAAY,CAAU;IACtB,SAAS,CAOhB;IAEV,YACE,SAAoB,EACpB,gBAAgC,EAChC,oBAAmC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AAY,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,WAAW,CAAC;QAC3D,MAAM,aAAa,GACjB,YAAY,CAAC,MAAM,GAAG,mBAAmB;YACvC,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,mBAAmB,CAAC,GAAG,KAAK;YACpD,CAAC,CAAC,YAAY,CAAC;QAEnB,IAAA,oBAAQ,EAAC;YACP,QAAQ,EAAE,YAAY;YACtB,OAAO,EAAE,SAAS;gBAChB,CAAC,CAAC,mCAAmC;gBACrC,CAAC,CAAC,iDAAiD;YACrD,KAAK,EAAE,CAAC;YACR,SAAS,EAAE;gBACT,aAAa,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE;gBAC/D,iBAAiB,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,iBAAiB,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE;gBACvE,iBAAiB,EAAE;oBACjB,KAAK,EAAE,MAAM,CAAC,iBAAiB,CAAC;oBAChC,IAAI,EAAE,QAAQ;iBACf;gBACD,MAAM,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,QAAQ,EAAE;aACjD;SACF,CAAC,CAAC;QAEH,OAAO,MAAiC,CAAC;IAC3C,CAAC;CACF;AAtMD,wCAsMC","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"]}
@@ -30,7 +30,7 @@ class ObserveHandler {
30
30
  this.onMetrics = onMetrics;
31
31
  }
32
32
  async observe(params) {
33
- const { instruction, page, timeout, selector, model, variables } = params;
33
+ const { instruction, page, timeout, selector, ignoreSelectors, model, variables, } = params;
34
34
  const llmClient = this.resolveLlmClient(model);
35
35
  const ensureTimeRemaining = (0, timeoutGuard_js_1.createTimeoutGuard)(timeout, (ms) => new sdkErrors_js_1.ObserveTimeoutError(ms));
36
36
  const effectiveInstruction = instruction ??
@@ -52,6 +52,7 @@ class ObserveHandler {
52
52
  const snapshot = await (0, index_js_1.captureHybridSnapshot)(page, {
53
53
  experimental: this.experimental,
54
54
  focusSelector: focusSelector || undefined,
55
+ ignoreSelectors,
55
56
  });
56
57
  const combinedTree = snapshot.combinedTree;
57
58
  const combinedXpathMap = snapshot.combinedXpathMap ?? {};
@@ -1 +1 @@
1
- {"version":3,"file":"observeHandler.js","sourceRoot":"","sources":["../../../../../lib/v3/handlers/observeHandler.ts"],"names":[],"mappings":";;;AAAA,oCAAoC;AACpC,qDAA2D;AAC3D,6CAAsD;AACtD,4CAAwC;AACxC,2DAA4D;AAC5D,mEAA6E;AAE7E,8DAGsC;AAQtC,+DAAmE;AACnE,oEAAoE;AAEpE,MAAa,cAAc;IACR,SAAS,CAAY;IACrB,gBAAgB,CAAiB;IACjC,oBAAoB,CAAgB;IACpC,gBAAgB,CAA4C;IAC5D,YAAY,CAAS;IACrB,kBAAkB,CAAU;IAC5B,YAAY,CAAU;IACtB,SAAS,C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;QAEH,OAAO,qBAAqB,CAAC;IAC/B,CAAC;CACF;AApND,wCAoNC","sourcesContent":["// lib/v3/handlers/observeHandler.ts\nimport { observe as runObserve } from \"../../inference.js\";\nimport { trimTrailingTextNode } from \"../../utils.js\";\nimport { v3Logger } from \"../logger.js\";\nimport { V3FunctionName } from \"../types/public/methods.js\";\nimport { captureHybridSnapshot } from \"../understudy/a11y/snapshot/index.js\";\nimport { LLMClient } from \"../llm/LLMClient.js\";\nimport {\n ObserveHandlerParams,\n SupportedUnderstudyAction,\n} from \"../types/private/handlers.js\";\nimport { EncodedId } from \"../types/private/internal.js\";\nimport { Action } from \"../types/public/methods.js\";\nimport {\n AvailableModel,\n ClientOptions,\n ModelConfiguration,\n} from \"../types/public/model.js\";\nimport { ObserveTimeoutError } from \"../types/public/sdkErrors.js\";\nimport { createTimeoutGuard } from \"./handlerUtils/timeoutGuard.js\";\n\nexport class ObserveHandler {\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 observe(params: ObserveHandlerParams): Promise<Action[]> {\n const { instruction, page, timeout, selector, model, variables } = params;\n\n const llmClient = this.resolveLlmClient(model);\n\n const ensureTimeRemaining = createTimeoutGuard(\n timeout,\n (ms) => new ObserveTimeoutError(ms),\n );\n\n const effectiveInstruction =\n instruction ??\n \"Find elements that can be used for any future actions in the page. These may be navigation links, related pages, section/subsection links, buttons, or other interactive elements. Be comprehensive: if there are multiple elements that may be relevant for future actions, return all of them.\";\n\n v3Logger({\n category: \"observation\",\n message: \"starting observation\",\n level: 1,\n auxiliary: {\n instruction: {\n value: effectiveInstruction,\n type: \"string\",\n },\n },\n });\n\n // Build the hybrid snapshot (a11y-centric text tree + lookup maps)\n const focusSelector = selector?.replace(/^xpath=/i, \"\") ?? \"\";\n ensureTimeRemaining();\n const snapshot = await captureHybridSnapshot(page, {\n experimental: this.experimental,\n focusSelector: focusSelector || undefined,\n });\n\n const combinedTree = snapshot.combinedTree;\n const combinedXpathMap = snapshot.combinedXpathMap ?? {};\n\n v3Logger({\n category: \"observation\",\n message: \"Got accessibility tree data\",\n level: 1,\n });\n\n // Call the LLM to propose actionable elements\n ensureTimeRemaining();\n const observationResponse = await runObserve({\n instruction: effectiveInstruction,\n domElements: combinedTree,\n llmClient,\n userProvidedInstructions: this.systemPrompt,\n logger: v3Logger,\n logInferenceToFile: this.logInferenceToFile,\n supportedActions: Object.values(SupportedUnderstudyAction),\n variables,\n });\n\n const {\n prompt_tokens = 0,\n completion_tokens = 0,\n reasoning_tokens = 0,\n cached_input_tokens = 0,\n inference_time_ms = 0,\n } = observationResponse;\n\n // Update OBSERVE metrics from the LLM observation call\n this.onMetrics?.(\n V3FunctionName.OBSERVE,\n prompt_tokens,\n completion_tokens,\n reasoning_tokens,\n cached_input_tokens,\n inference_time_ms,\n );\n\n // Map elementIds -> selectors via combinedXpathMap\n const elementsWithSelectors = (\n await Promise.all(\n observationResponse.elements.map(async (element) => {\n const { elementId, ...rest } = element; // rest may or may not have method/arguments\n if (typeof elementId === \"string\" && elementId.includes(\"-\")) {\n const lookUpIndex = elementId as EncodedId;\n const xpath = combinedXpathMap[lookUpIndex];\n const trimmedXpath = trimTrailingTextNode(xpath);\n if (!trimmedXpath) return undefined;\n\n // For dragAndDrop, convert element ID in arguments to xpath (target element)\n let resolvedArgs = rest.arguments;\n if (\n rest.method === \"dragAndDrop\" &&\n Array.isArray(rest.arguments) &&\n rest.arguments.length > 0\n ) {\n const targetArg = rest.arguments[0];\n // Check if argument looks like an element ID (e.g., \"1-67\")\n if (\n typeof targetArg === \"string\" &&\n /^\\d+-\\d+$/.test(targetArg)\n ) {\n const argXpath = combinedXpathMap[targetArg as EncodedId];\n const trimmedArgXpath = trimTrailingTextNode(argXpath);\n if (trimmedArgXpath) {\n resolvedArgs = [\n `xpath=${trimmedArgXpath}`,\n ...rest.arguments.slice(1),\n ];\n } else {\n // Target element lookup failed, filter out this action\n v3Logger({\n category: \"observation\",\n message: \"dragAndDrop target element lookup failed\",\n level: 0,\n auxiliary: {\n targetElementId: { value: targetArg, type: \"string\" },\n sourceElementId: { value: elementId, type: \"string\" },\n },\n });\n return undefined;\n }\n } else {\n v3Logger({\n category: \"observation\",\n message: \"dragAndDrop target element invalid ID format\",\n level: 0,\n auxiliary: {\n targetElementId: { value: targetArg, type: \"string\" },\n sourceElementId: { value: elementId, type: \"string\" },\n },\n });\n return undefined;\n }\n }\n\n return {\n ...rest,\n arguments: resolvedArgs,\n selector: `xpath=${trimmedXpath}`,\n } as {\n description: string;\n method?: string;\n arguments?: string[];\n selector: string;\n };\n }\n // shadow-root fallback:\n return {\n description: \"an element inside a shadow DOM\",\n method: \"not-supported\",\n arguments: [],\n selector: \"not-supported\",\n };\n }),\n )\n ).filter(<T>(e: T | undefined): e is T => e !== undefined);\n\n v3Logger({\n category: \"observation\",\n message: \"found elements\",\n level: 1,\n auxiliary: {\n elements: {\n value: JSON.stringify(elementsWithSelectors),\n type: \"object\",\n },\n },\n });\n\n return elementsWithSelectors;\n }\n}\n"]}
1
+ {"version":3,"file":"observeHandler.js","sourceRoot":"","sources":["../../../../../lib/v3/handlers/observeHandler.ts"],"names":[],"mappings":";;;AAAA,oCAAoC;AACpC,qDAA2D;AAC3D,6CAAsD;AACtD,4CAAwC;AACxC,2DAA4D;AAC5D,mEAA6E;AAE7E,8DAGsC;AAQtC,+DAAmE;AACnE,oEAAoE;AAEpE,MAAa,cAAc;IACR,SAAS,CAAY;IACrB,gBAAgB,CAAiB;IACjC,oBAAoB,CAAgB;IACpC,gBAAgB,CAA4C;IAC5D,YAAY,CAAS;IACrB,kBAAkB,CAAU;IAC5B,YAAY,CAAU;IACtB,SAAS,CAOhB;IAEV,YACE,SAAoB,EACpB,gBAAgC,EAChC,oBAAmC,EACnC,gBAA2D,EAC3D,YAAqB,EACrB,kBAA4B,EAC5B,YAAsB,EACtB,SAOS;QAET,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QACzC,IAAI,CAAC,oBAAoB,GAAG,oBAAoB,CAAC;QACjD,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QACzC,IAAI,CAAC,YAAY,GAAG,YAAY,IAAI,EAAE,CAAC;QACvC,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,IAAI,KAAK,CAAC;QACtD,IAAI,CAAC,YAAY,GAAG,YAAY,IAAI,KAAK,CAAC;QAC1C,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,MAA4B;QACxC,MAAM,EACJ,WAAW,EACX,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,eAAe,EACf,KAAK,EACL,SAAS,GACV,GAAG,MAAM,CAAC;QAEX,MAAM,SAAS,GAAG,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;Q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ACD,wBAAwB;YACxB,OAAO;gBACL,WAAW,EAAE,gCAAgC;gBAC7C,MAAM,EAAE,eAAe;gBACvB,SAAS,EAAE,EAAE;gBACb,QAAQ,EAAE,eAAe;aAC1B,CAAC;QACJ,CAAC,CAAC,CACH,CACF,CAAC,MAAM,CAAC,CAAI,CAAgB,EAAU,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;QAE3D,IAAA,oBAAQ,EAAC;YACP,QAAQ,EAAE,aAAa;YACvB,OAAO,EAAE,gBAAgB;YACzB,KAAK,EAAE,CAAC;YACR,SAAS,EAAE;gBACT,QAAQ,EAAE;oBACR,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,qBAAqB,CAAC;oBAC5C,IAAI,EAAE,QAAQ;iBACf;aACF;SACF,CAAC,CAAC;QAEH,OAAO,qBAAqB,CAAC;IAC/B,CAAC;CACF;AA7ND,wCA6NC","sourcesContent":["// lib/v3/handlers/observeHandler.ts\nimport { observe as runObserve } from \"../../inference.js\";\nimport { trimTrailingTextNode } from \"../../utils.js\";\nimport { v3Logger } from \"../logger.js\";\nimport { V3FunctionName } from \"../types/public/methods.js\";\nimport { captureHybridSnapshot } from \"../understudy/a11y/snapshot/index.js\";\nimport { LLMClient } from \"../llm/LLMClient.js\";\nimport {\n ObserveHandlerParams,\n SupportedUnderstudyAction,\n} from \"../types/private/handlers.js\";\nimport { EncodedId } from \"../types/private/internal.js\";\nimport { Action } from \"../types/public/methods.js\";\nimport {\n AvailableModel,\n ClientOptions,\n ModelConfiguration,\n} from \"../types/public/model.js\";\nimport { ObserveTimeoutError } from \"../types/public/sdkErrors.js\";\nimport { createTimeoutGuard } from \"./handlerUtils/timeoutGuard.js\";\n\nexport class ObserveHandler {\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 observe(params: ObserveHandlerParams): Promise<Action[]> {\n const {\n instruction,\n page,\n timeout,\n selector,\n ignoreSelectors,\n model,\n variables,\n } = params;\n\n const llmClient = this.resolveLlmClient(model);\n\n const ensureTimeRemaining = createTimeoutGuard(\n timeout,\n (ms) => new ObserveTimeoutError(ms),\n );\n\n const effectiveInstruction =\n instruction ??\n \"Find elements that can be used for any future actions in the page. These may be navigation links, related pages, section/subsection links, buttons, or other interactive elements. Be comprehensive: if there are multiple elements that may be relevant for future actions, return all of them.\";\n\n v3Logger({\n category: \"observation\",\n message: \"starting observation\",\n level: 1,\n auxiliary: {\n instruction: {\n value: effectiveInstruction,\n type: \"string\",\n },\n },\n });\n\n // Build the hybrid snapshot (a11y-centric text tree + lookup maps)\n const focusSelector = selector?.replace(/^xpath=/i, \"\") ?? \"\";\n ensureTimeRemaining();\n const snapshot = await captureHybridSnapshot(page, {\n experimental: this.experimental,\n focusSelector: focusSelector || undefined,\n ignoreSelectors,\n });\n\n const combinedTree = snapshot.combinedTree;\n const combinedXpathMap = snapshot.combinedXpathMap ?? {};\n\n v3Logger({\n category: \"observation\",\n message: \"Got accessibility tree data\",\n level: 1,\n });\n\n // Call the LLM to propose actionable elements\n ensureTimeRemaining();\n const observationResponse = await runObserve({\n instruction: effectiveInstruction,\n domElements: combinedTree,\n llmClient,\n userProvidedInstructions: this.systemPrompt,\n logger: v3Logger,\n logInferenceToFile: this.logInferenceToFile,\n supportedActions: Object.values(SupportedUnderstudyAction),\n variables,\n });\n\n const {\n prompt_tokens = 0,\n completion_tokens = 0,\n reasoning_tokens = 0,\n cached_input_tokens = 0,\n inference_time_ms = 0,\n } = observationResponse;\n\n // Update OBSERVE metrics from the LLM observation call\n this.onMetrics?.(\n V3FunctionName.OBSERVE,\n prompt_tokens,\n completion_tokens,\n reasoning_tokens,\n cached_input_tokens,\n inference_time_ms,\n );\n\n // Map elementIds -> selectors via combinedXpathMap\n const elementsWithSelectors = (\n await Promise.all(\n observationResponse.elements.map(async (element) => {\n const { elementId, ...rest } = element; // rest may or may not have method/arguments\n if (typeof elementId === \"string\" && elementId.includes(\"-\")) {\n const lookUpIndex = elementId as EncodedId;\n const xpath = combinedXpathMap[lookUpIndex];\n const trimmedXpath = trimTrailingTextNode(xpath);\n if (!trimmedXpath) return undefined;\n\n // For dragAndDrop, convert element ID in arguments to xpath (target element)\n let resolvedArgs = rest.arguments;\n if (\n rest.method === \"dragAndDrop\" &&\n Array.isArray(rest.arguments) &&\n rest.arguments.length > 0\n ) {\n const targetArg = rest.arguments[0];\n // Check if argument looks like an element ID (e.g., \"1-67\")\n if (\n typeof targetArg === \"string\" &&\n /^\\d+-\\d+$/.test(targetArg)\n ) {\n const argXpath = combinedXpathMap[targetArg as EncodedId];\n const trimmedArgXpath = trimTrailingTextNode(argXpath);\n if (trimmedArgXpath) {\n resolvedArgs = [\n `xpath=${trimmedArgXpath}`,\n ...rest.arguments.slice(1),\n ];\n } else {\n // Target element lookup failed, filter out this action\n v3Logger({\n category: \"observation\",\n message: \"dragAndDrop target element lookup failed\",\n level: 0,\n auxiliary: {\n targetElementId: { value: targetArg, type: \"string\" },\n sourceElementId: { value: elementId, type: \"string\" },\n },\n });\n return undefined;\n }\n } else {\n v3Logger({\n category: \"observation\",\n message: \"dragAndDrop target element invalid ID format\",\n level: 0,\n auxiliary: {\n targetElementId: { value: targetArg, type: \"string\" },\n sourceElementId: { value: elementId, type: \"string\" },\n },\n });\n return undefined;\n }\n }\n\n return {\n ...rest,\n arguments: resolvedArgs,\n selector: `xpath=${trimmedXpath}`,\n } as {\n description: string;\n method?: string;\n arguments?: string[];\n selector: string;\n };\n }\n // shadow-root fallback:\n return {\n description: \"an element inside a shadow DOM\",\n method: \"not-supported\",\n arguments: [],\n selector: \"not-supported\",\n };\n }),\n )\n ).filter(<T>(e: T | undefined): e is T => e !== undefined);\n\n v3Logger({\n category: \"observation\",\n message: \"found elements\",\n level: 1,\n auxiliary: {\n elements: {\n value: JSON.stringify(elementsWithSelectors),\n type: \"object\",\n },\n },\n });\n\n return elementsWithSelectors;\n }\n}\n"]}
@@ -6,6 +6,7 @@ const agentSystemPrompt_js_1 = require("../agent/prompts/agentSystemPrompt.js");
6
6
  const ai_1 = require("ai");
7
7
  const messageProcessing_js_1 = require("../agent/utils/messageProcessing.js");
8
8
  const FlowLogger_js_1 = require("../flowlogger/FlowLogger.js");
9
+ const agent_js_1 = require("../types/private/agent.js");
9
10
  const methods_js_1 = require("../types/public/methods.js");
10
11
  const actionMapping_js_1 = require("../agent/utils/actionMapping.js");
11
12
  const sdkErrors_js_1 = require("../types/public/sdkErrors.js");
@@ -93,9 +94,8 @@ class V3AgentHandler {
93
94
  ...FlowLogger_js_1.FlowLogger.createLlmLoggingMiddleware(baseModel.modelId),
94
95
  },
95
96
  });
96
- if (this.mode === "hybrid" &&
97
- !baseModel.modelId.includes("gemini-3-flash") &&
98
- !baseModel.modelId.includes("claude")) {
97
+ const isHybridCapable = agent_js_1.HYBRID_CAPABLE_MODEL_PATTERNS.some((pattern) => baseModel.modelId.includes(pattern));
98
+ if (this.mode === "hybrid" && !isHybridCapable) {
99
99
  this.logger({
100
100
  category: "agent",
101
101
  message: `Warning: "${baseModel.modelId}" may not perform well in hybrid mode. See recommended models: https://docs.stagehand.dev/v3/basics/agent#hybrid-mode`,
@@ -259,7 +259,6 @@ class V3AgentHandler {
259
259
  messages: prependSystemMessage(systemPrompt, messages),
260
260
  tools: allTools,
261
261
  stopWhen: (result) => this.handleStop(result, maxSteps),
262
- temperature: 1,
263
262
  toolChoice: "auto",
264
263
  prepareStep: this.createPrepareStep(callbacks?.prepareStep, captchaSolver),
265
264
  onStepFinish: this.createStepHandler(state, callbacks?.onStepFinish),
@@ -351,7 +350,6 @@ class V3AgentHandler {
351
350
  messages: prependSystemMessage(systemPrompt, messages),
352
351
  tools: allTools,
353
352
  stopWhen: (result) => this.handleStop(result, maxSteps),
354
- temperature: 1,
355
353
  toolChoice: "auto",
356
354
  prepareStep: this.createPrepareStep(callbacks?.prepareStep, captchaSolver),
357
355
  onStepFinish: this.createStepHandler(state, callbacks?.onStepFinish),