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

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 (33) hide show
  1. package/dist/cjs/lib/inference.js +1 -1
  2. package/dist/cjs/lib/inference.js.map +1 -1
  3. package/dist/cjs/lib/v3/dom/build/a11yScripts.generated.js +11 -11
  4. package/dist/cjs/lib/v3/dom/build/a11yScripts.generated.js.map +1 -1
  5. package/dist/cjs/lib/v3/dom/build/locatorScripts.generated.js +47 -47
  6. package/dist/cjs/lib/v3/dom/build/locatorScripts.generated.js.map +1 -1
  7. package/dist/cjs/lib/v3/dom/build/reRenderScriptContent.js +1 -1
  8. package/dist/cjs/lib/v3/dom/build/reRenderScriptContent.js.map +1 -1
  9. package/dist/cjs/lib/v3/dom/build/screenshotScripts.generated.js +1 -1
  10. package/dist/cjs/lib/v3/dom/build/screenshotScripts.generated.js.map +1 -1
  11. package/dist/cjs/lib/v3/dom/build/scriptV3Content.js +1 -1
  12. package/dist/cjs/lib/v3/dom/build/scriptV3Content.js.map +1 -1
  13. package/dist/cjs/lib/v3/llm/aisdk.js +0 -5
  14. package/dist/cjs/lib/v3/llm/aisdk.js.map +1 -1
  15. package/dist/cjs/tests/unit/aisdk-clients.test.js +0 -4
  16. package/dist/cjs/tests/unit/aisdk-clients.test.js.map +1 -1
  17. package/dist/esm/lib/inference.js +1 -1
  18. package/dist/esm/lib/inference.js.map +1 -1
  19. package/dist/esm/lib/v3/dom/build/a11yScripts.generated.js +11 -11
  20. package/dist/esm/lib/v3/dom/build/a11yScripts.generated.js.map +1 -1
  21. package/dist/esm/lib/v3/dom/build/locatorScripts.generated.js +47 -47
  22. package/dist/esm/lib/v3/dom/build/locatorScripts.generated.js.map +1 -1
  23. package/dist/esm/lib/v3/dom/build/reRenderScriptContent.js +1 -1
  24. package/dist/esm/lib/v3/dom/build/reRenderScriptContent.js.map +1 -1
  25. package/dist/esm/lib/v3/dom/build/screenshotScripts.generated.js +1 -1
  26. package/dist/esm/lib/v3/dom/build/screenshotScripts.generated.js.map +1 -1
  27. package/dist/esm/lib/v3/dom/build/scriptV3Content.js +1 -1
  28. package/dist/esm/lib/v3/dom/build/scriptV3Content.js.map +1 -1
  29. package/dist/esm/lib/v3/llm/aisdk.js +0 -5
  30. package/dist/esm/lib/v3/llm/aisdk.js.map +1 -1
  31. package/dist/esm/tests/unit/aisdk-clients.test.js +0 -4
  32. package/dist/esm/tests/unit/aisdk-clients.test.js.map +1 -1
  33. package/package.json +1 -1
@@ -264,7 +264,7 @@ async function act({ instruction, domElements, llmClient, userProvidedInstructio
264
264
  })
265
265
  .nullable()
266
266
  .describe("The element to act on. Return null if no element on the page matches the instruction — do NOT fabricate or guess an element, and never emit empty strings or placeholder values."),
267
- twoStep: zod_1.z.boolean().default(false),
267
+ twoStep: zod_1.z.boolean(),
268
268
  });
269
269
  const messages = [
270
270
  (0, prompt_js_1.buildActSystemPrompt)(userProvidedInstructions),
@@ -1 +1 @@
1
- {"version":3,"file":"inference.js","sourceRoot":"","sources":["../../../lib/inference.ts"],"names":[],"mappings":";;AAgCA,0BA8MC;AAED,0BAyJC;AAED,kBAgJC;AA3hBD,6BAAwB;AAGxB,4DAAqE;AACrE,2CAQqB;AACrB,iEAAgF;AAKhF,gEAA2E;AAM3E,SAAS,cAAc,CAAI,OAAmB,EAAE,SAAiB;IAC/D,OAAO,IAAA,8BAAW,EAChB,OAAO,EACP,IAAA,kCAAe,EAAC,YAAY,CAAC,EAC7B,OAAO,SAAS,EAAE,CACnB,CAAC;AACJ,CAAC;AAEM,KAAK,UAAU,OAAO,CAA+B,EAC1D,WAAW,EACX,WAAW,EACX,MAAM,EACN,SAAS,EACT,MAAM,EACN,wBAAwB,EACxB,kBAAkB,GAAG,KAAK,GAS3B;IACC,MAAM,cAAc,GAAG,OAAC,CAAC,MAAM,CAAC;QAC9B,QAAQ,EAAE,OAAC;aACR,MAAM,EAAE;aACR,QAAQ,CACP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AO,EAAE,aAAa;QACtB,aAAa,EAAE,YAAY;QAC3B,iBAAiB,EAAE,gBAAgB;QACnC,gBAAgB,EAAE,eAAe;QACjC,mBAAmB,EAAE,iBAAiB;QACtC,iBAAiB,EAAE,WAAW;QAC9B,OAAO,EAAE,OAAO,CAAC,OAAO;KACzB,CAAC;AACJ,CAAC","sourcesContent":["import { z } from \"zod\";\nimport { LogLine } from \"./v3/types/public/logs.js\";\nimport { ChatMessage, LLMClient } from \"./v3/llm/LLMClient.js\";\nimport { getEnvTimeoutMs, withTimeout } from \"./v3/timeoutConfig.js\";\nimport {\n buildActSystemPrompt,\n buildExtractSystemPrompt,\n buildExtractUserPrompt,\n buildMetadataPrompt,\n buildMetadataSystemPrompt,\n buildObserveSystemPrompt,\n buildObserveUserMessage,\n} from \"./prompt.js\";\nimport { appendSummary, writeTimestampedTxtFile } from \"./inferenceLogUtils.js\";\nimport type {\n InferStagehandSchema,\n StagehandZodObject,\n} from \"./v3/zodCompat.js\";\nimport { SupportedUnderstudyAction } from \"./v3/types/private/handlers.js\";\nimport type { Variables } from \"./v3/types/public/agent.js\";\n\n// Re-export for backward compatibility\nexport type { LLMParsedResponse, LLMUsage } from \"./v3/llm/LLMClient.js\";\n\nfunction withLlmTimeout<T>(promise: Promise<T>, operation: string): Promise<T> {\n return withTimeout(\n promise,\n getEnvTimeoutMs(\"LLM_MAX_MS\"),\n `LLM ${operation}`,\n );\n}\n\nexport async function extract<T extends StagehandZodObject>({\n instruction,\n domElements,\n schema,\n llmClient,\n logger,\n userProvidedInstructions,\n logInferenceToFile = false,\n}: {\n instruction: string;\n domElements: string;\n schema: T;\n llmClient: LLMClient;\n userProvidedInstructions?: string;\n logger: (message: LogLine) => void;\n logInferenceToFile?: boolean;\n}) {\n const metadataSchema = z.object({\n progress: z\n .string()\n .describe(\n \"progress of what has been extracted so far, as concise as possible\",\n ),\n completed: z\n .boolean()\n .describe(\n \"true if the goal is now accomplished. Use this conservatively, only when sure that the goal has been completed.\",\n ),\n });\n\n type ExtractionResponse = InferStagehandSchema<T>;\n type MetadataResponse = z.infer<typeof metadataSchema>;\n\n const isUsingAnthropic = llmClient.type === \"anthropic\";\n const isGPT5 = llmClient.modelName.includes(\"gpt-5\"); // TODO: remove this as we update support for gpt-5 configuration options\n\n const extractCallMessages: ChatMessage[] = [\n buildExtractSystemPrompt(isUsingAnthropic, userProvidedInstructions),\n buildExtractUserPrompt(instruction, domElements, isUsingAnthropic),\n ];\n\n let extractCallFile = \"\";\n let extractCallTimestamp = \"\";\n if (logInferenceToFile) {\n const { fileName, timestamp } = writeTimestampedTxtFile(\n \"extract_summary\",\n \"extract_call\",\n {\n modelCall: \"extract\",\n messages: extractCallMessages,\n },\n );\n extractCallFile = fileName;\n extractCallTimestamp = timestamp;\n }\n\n const extractStartTime = Date.now();\n const extractionResponse = await withLlmTimeout(\n llmClient.createChatCompletion<ExtractionResponse>({\n options: {\n messages: extractCallMessages,\n response_model: {\n schema,\n name: \"Extraction\",\n },\n temperature: isGPT5 ? 1 : 0.1,\n top_p: 1,\n frequency_penalty: 0,\n presence_penalty: 0,\n },\n logger,\n }),\n \"extract\",\n );\n const extractEndTime = Date.now();\n\n const { data: extractedData, usage: extractUsage } = extractionResponse;\n\n let extractResponseFile: string;\n if (logInferenceToFile) {\n const { fileName } = writeTimestampedTxtFile(\n \"extract_summary\",\n \"extract_response\",\n {\n modelResponse: \"extract\",\n rawResponse: extractedData,\n },\n );\n extractResponseFile = fileName;\n\n appendSummary(\"extract\", {\n extract_inference_type: \"extract\",\n timestamp: extractCallTimestamp,\n LLM_input_file: extractCallFile,\n LLM_output_file: extractResponseFile,\n prompt_tokens: extractUsage?.prompt_tokens ?? 0,\n completion_tokens: extractUsage?.completion_tokens ?? 0,\n reasoning_tokens: extractUsage?.reasoning_tokens ?? 0,\n cached_input_tokens: extractUsage?.cached_input_tokens ?? 0,\n inference_time_ms: extractEndTime - extractStartTime,\n });\n }\n\n const metadataCallMessages: ChatMessage[] = [\n buildMetadataSystemPrompt(),\n buildMetadataPrompt(instruction, extractedData),\n ];\n\n let metadataCallFile = \"\";\n let metadataCallTimestamp = \"\";\n if (logInferenceToFile) {\n const { fileName, timestamp } = writeTimestampedTxtFile(\n \"extract_summary\",\n \"metadata_call\",\n {\n modelCall: \"metadata\",\n messages: metadataCallMessages,\n },\n );\n metadataCallFile = fileName;\n metadataCallTimestamp = timestamp;\n }\n\n const metadataStartTime = Date.now();\n const metadataResponse = await withLlmTimeout(\n llmClient.createChatCompletion<MetadataResponse>({\n options: {\n messages: metadataCallMessages,\n response_model: {\n name: \"Metadata\",\n schema: metadataSchema,\n },\n temperature: isGPT5 ? 1 : 0.1,\n top_p: 1,\n frequency_penalty: 0,\n presence_penalty: 0,\n },\n logger,\n }),\n \"extract metadata\",\n );\n const metadataEndTime = Date.now();\n\n const {\n data: {\n completed: metadataResponseCompleted,\n progress: metadataResponseProgress,\n },\n usage: metadataResponseUsage,\n } = metadataResponse;\n\n let metadataResponseFile: string;\n if (logInferenceToFile) {\n const { fileName } = writeTimestampedTxtFile(\n \"extract_summary\",\n \"metadata_response\",\n {\n modelResponse: \"metadata\",\n completed: metadataResponseCompleted,\n progress: metadataResponseProgress,\n },\n );\n metadataResponseFile = fileName;\n\n appendSummary(\"extract\", {\n extract_inference_type: \"metadata\",\n timestamp: metadataCallTimestamp,\n LLM_input_file: metadataCallFile,\n LLM_output_file: metadataResponseFile,\n prompt_tokens: metadataResponseUsage?.prompt_tokens ?? 0,\n completion_tokens: metadataResponseUsage?.completion_tokens ?? 0,\n reasoning_tokens: metadataResponseUsage?.reasoning_tokens ?? 0,\n cached_input_tokens: metadataResponseUsage?.cached_input_tokens ?? 0,\n inference_time_ms: metadataEndTime - metadataStartTime,\n });\n }\n\n const totalPromptTokens =\n (extractUsage?.prompt_tokens ?? 0) +\n (metadataResponseUsage?.prompt_tokens ?? 0);\n\n const totalCompletionTokens =\n (extractUsage?.completion_tokens ?? 0) +\n (metadataResponseUsage?.completion_tokens ?? 0);\n\n const totalInferenceTimeMs =\n extractEndTime - extractStartTime + (metadataEndTime - metadataStartTime);\n const totalReasoningTokens =\n (extractUsage?.reasoning_tokens ?? 0) +\n (metadataResponseUsage?.reasoning_tokens ?? 0);\n const totalCachedInputTokens =\n (extractUsage?.cached_input_tokens ?? 0) +\n (metadataResponseUsage?.cached_input_tokens ?? 0);\n\n return {\n ...extractedData,\n metadata: {\n completed: metadataResponseCompleted,\n progress: metadataResponseProgress,\n },\n prompt_tokens: totalPromptTokens,\n completion_tokens: totalCompletionTokens,\n reasoning_tokens: totalReasoningTokens,\n cached_input_tokens: totalCachedInputTokens,\n inference_time_ms: totalInferenceTimeMs,\n };\n}\n\nexport async function observe({\n instruction,\n domElements,\n llmClient,\n userProvidedInstructions,\n logger,\n logInferenceToFile = false,\n supportedActions,\n variables,\n}: {\n instruction: string;\n domElements: string;\n llmClient: LLMClient;\n userProvidedInstructions?: string;\n logger: (message: LogLine) => void;\n logInferenceToFile?: boolean;\n supportedActions?: string[];\n variables?: Variables;\n}) {\n const isGPT5 = llmClient.modelName.includes(\"gpt-5\"); // TODO: remove this as we update support for gpt-5 configuration options\n\n const observeSchema = z.object({\n elements: z\n .array(\n z.object({\n elementId: z\n .string()\n .regex(/^\\d+-\\d+$/)\n .describe(\n \"the ID string associated with the element. Never include surrounding square brackets. This field must follow the format of 'number-number'.\",\n ),\n description: z\n .string()\n .describe(\n \"a description of the accessible element and its purpose\",\n ),\n method: z\n .enum(\n // Use Object.values() for Zod v3 compatibility - z.enum() in v3 doesn't accept TypeScript enums directly\n Object.values(SupportedUnderstudyAction) as unknown as readonly [\n string,\n ...string[],\n ],\n )\n .describe(\n `the candidate method/action to interact with the element. Select one of the available Understudy interaction methods.`,\n ),\n arguments: z.array(\n z\n .string()\n .describe(\n \"the arguments to pass to the method. For example, for a click, the arguments are empty, but for a fill, the arguments are the value to fill in.\",\n ),\n ),\n }),\n )\n .describe(\"an array of accessible elements that match the instruction\"),\n });\n\n type ObserveResponse = z.infer<typeof observeSchema>;\n\n const messages: ChatMessage[] = [\n buildObserveSystemPrompt(\n userProvidedInstructions,\n supportedActions,\n variables,\n ),\n buildObserveUserMessage(instruction, domElements),\n ];\n\n let callTimestamp = \"\";\n let callFile = \"\";\n if (logInferenceToFile) {\n const { fileName, timestamp } = writeTimestampedTxtFile(\n `observe_summary`,\n `observe_call`,\n {\n modelCall: \"observe\",\n messages,\n },\n );\n callFile = fileName;\n callTimestamp = timestamp;\n }\n\n const start = Date.now();\n const rawResponse = await llmClient.createChatCompletion<ObserveResponse>({\n options: {\n messages,\n response_model: {\n schema: observeSchema,\n name: \"Observation\",\n },\n temperature: isGPT5 ? 1 : 0.1,\n top_p: 1,\n frequency_penalty: 0,\n presence_penalty: 0,\n },\n logger,\n });\n const end = Date.now();\n const usageTimeMs = end - start;\n\n const { data: observeData, usage: observeUsage } = rawResponse;\n const promptTokens = observeUsage?.prompt_tokens ?? 0;\n const completionTokens = observeUsage?.completion_tokens ?? 0;\n const reasoningTokens = observeUsage?.reasoning_tokens ?? 0;\n const cachedInputTokens = observeUsage?.cached_input_tokens ?? 0;\n\n let responseFile: string;\n if (logInferenceToFile) {\n const { fileName: responseFileName } = writeTimestampedTxtFile(\n `observe_summary`,\n `observe_response`,\n {\n modelResponse: \"observe\",\n rawResponse: observeData,\n },\n );\n responseFile = responseFileName;\n\n appendSummary(\"observe\", {\n [`observe_inference_type`]: \"observe\",\n timestamp: callTimestamp,\n LLM_input_file: callFile,\n LLM_output_file: responseFile,\n prompt_tokens: promptTokens,\n completion_tokens: completionTokens,\n reasoning_tokens: reasoningTokens,\n cached_input_tokens: cachedInputTokens,\n inference_time_ms: usageTimeMs,\n });\n }\n\n const parsedElements =\n observeData.elements?.map((el) => {\n const base = {\n elementId: el.elementId,\n description: String(el.description),\n method: String(el.method),\n arguments: el.arguments,\n };\n return base;\n }) ?? [];\n\n return {\n elements: parsedElements,\n prompt_tokens: promptTokens,\n completion_tokens: completionTokens,\n reasoning_tokens: reasoningTokens,\n cached_input_tokens: cachedInputTokens,\n inference_time_ms: usageTimeMs,\n };\n}\n\nexport async function act({\n instruction,\n domElements,\n llmClient,\n userProvidedInstructions,\n logger,\n logInferenceToFile = false,\n}: {\n instruction: string;\n domElements: string;\n llmClient: LLMClient;\n userProvidedInstructions?: string;\n logger: (message: LogLine) => void;\n logInferenceToFile?: boolean;\n}) {\n const isGPT5 = llmClient.modelName.includes(\"gpt-5\"); // TODO: remove this as we update support for gpt-5 configuration options\n\n const actSchema = z.object({\n action: z\n .object({\n elementId: z\n .string()\n .regex(/^\\d+-\\d+$/)\n .describe(\n \"the ID string associated with the element. Never include surrounding square brackets. This field must follow the format of 'number-number'. for example, '0-76' or '16-21'\",\n ),\n description: z\n .string()\n .describe(\"a description of the accessible element and its purpose\"),\n method: z\n .enum(\n // Use Object.values() for Zod v3 compatibility - z.enum() in v3 doesn't accept TypeScript enums directly\n Object.values(SupportedUnderstudyAction) as unknown as readonly [\n string,\n ...string[],\n ],\n )\n .describe(\n \"the candidate method/action to interact with the element. Select one of the available Understudy interaction methods.\",\n ),\n arguments: z.array(\n z\n .string()\n .describe(\n \"the arguments to pass to the method. For example, for a click, the arguments are empty, but for a fill, the arguments are the value to fill in.\",\n ),\n ),\n })\n .nullable()\n .describe(\n \"The element to act on. Return null if no element on the page matches the instruction — do NOT fabricate or guess an element, and never emit empty strings or placeholder values.\",\n ),\n twoStep: z.boolean().default(false),\n });\n\n type ActResponse = z.infer<typeof actSchema>;\n\n const messages: ChatMessage[] = [\n buildActSystemPrompt(userProvidedInstructions),\n buildObserveUserMessage(instruction, domElements),\n ];\n\n let callTimestamp = \"\";\n let callFile = \"\";\n if (logInferenceToFile) {\n const { fileName, timestamp } = writeTimestampedTxtFile(\n `act_summary`,\n `act_call`,\n {\n modelCall: \"act\",\n messages,\n },\n );\n callFile = fileName;\n callTimestamp = timestamp;\n }\n\n const start = Date.now();\n const rawResponse = await llmClient.createChatCompletion<ActResponse>({\n options: {\n messages,\n response_model: {\n schema: actSchema,\n name: \"act\",\n },\n temperature: isGPT5 ? 1 : 0.1,\n top_p: 1,\n frequency_penalty: 0,\n presence_penalty: 0,\n },\n logger,\n });\n const end = Date.now();\n const usageTimeMs = end - start;\n\n const { data: actData, usage: actUsage } = rawResponse;\n const promptTokens = actUsage?.prompt_tokens ?? 0;\n const completionTokens = actUsage?.completion_tokens ?? 0;\n const reasoningTokens = actUsage?.reasoning_tokens ?? 0;\n const cachedInputTokens = actUsage?.cached_input_tokens ?? 0;\n\n let responseFile: string;\n if (logInferenceToFile) {\n const { fileName: responseFileName } = writeTimestampedTxtFile(\n `act_summary`,\n `act_response`,\n {\n modelResponse: \"act\",\n rawResponse: actData,\n },\n );\n responseFile = responseFileName;\n\n appendSummary(\"act\", {\n [`act_inference_type`]: \"act\",\n timestamp: callTimestamp,\n LLM_input_file: callFile,\n LLM_output_file: responseFile,\n prompt_tokens: promptTokens,\n completion_tokens: completionTokens,\n reasoning_tokens: reasoningTokens,\n cached_input_tokens: cachedInputTokens,\n inference_time_ms: usageTimeMs,\n });\n }\n\n const parsedElement = actData.action\n ? {\n elementId: actData.action.elementId,\n description: String(actData.action.description),\n method: String(actData.action.method),\n arguments: actData.action.arguments,\n }\n : undefined;\n\n return {\n element: parsedElement,\n prompt_tokens: promptTokens,\n completion_tokens: completionTokens,\n reasoning_tokens: reasoningTokens,\n cached_input_tokens: cachedInputTokens,\n inference_time_ms: usageTimeMs,\n twoStep: actData.twoStep,\n };\n}\n"]}
1
+ {"version":3,"file":"inference.js","sourceRoot":"","sources":["../../../lib/inference.ts"],"names":[],"mappings":";;AAgCA,0BA8MC;AAED,0BAyJC;AAED,kBAgJC;AA3hBD,6BAAwB;AAGxB,4DAAqE;AACrE,2CAQqB;AACrB,iEAAgF;AAKhF,gEAA2E;AAM3E,SAAS,cAAc,CAAI,OAAmB,EAAE,SAAiB;IAC/D,OAAO,IAAA,8BAAW,EAChB,OAAO,EACP,IAAA,kCAAe,EAAC,YAAY,CAAC,EAC7B,OAAO,SAAS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SAAS;YACnC,WAAW,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC;YAC/C,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC;YACrC,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,SAAS;SACpC;QACH,CAAC,CAAC,SAAS,CAAC;IAEd,OAAO;QACL,OAAO,EAAE,aAAa;QACtB,aAAa,EAAE,YAAY;QAC3B,iBAAiB,EAAE,gBAAgB;QACnC,gBAAgB,EAAE,eAAe;QACjC,mBAAmB,EAAE,iBAAiB;QACtC,iBAAiB,EAAE,WAAW;QAC9B,OAAO,EAAE,OAAO,CAAC,OAAO;KACzB,CAAC;AACJ,CAAC","sourcesContent":["import { z } from \"zod\";\nimport { LogLine } from \"./v3/types/public/logs.js\";\nimport { ChatMessage, LLMClient } from \"./v3/llm/LLMClient.js\";\nimport { getEnvTimeoutMs, withTimeout } from \"./v3/timeoutConfig.js\";\nimport {\n buildActSystemPrompt,\n buildExtractSystemPrompt,\n buildExtractUserPrompt,\n buildMetadataPrompt,\n buildMetadataSystemPrompt,\n buildObserveSystemPrompt,\n buildObserveUserMessage,\n} from \"./prompt.js\";\nimport { appendSummary, writeTimestampedTxtFile } from \"./inferenceLogUtils.js\";\nimport type {\n InferStagehandSchema,\n StagehandZodObject,\n} from \"./v3/zodCompat.js\";\nimport { SupportedUnderstudyAction } from \"./v3/types/private/handlers.js\";\nimport type { Variables } from \"./v3/types/public/agent.js\";\n\n// Re-export for backward compatibility\nexport type { LLMParsedResponse, LLMUsage } from \"./v3/llm/LLMClient.js\";\n\nfunction withLlmTimeout<T>(promise: Promise<T>, operation: string): Promise<T> {\n return withTimeout(\n promise,\n getEnvTimeoutMs(\"LLM_MAX_MS\"),\n `LLM ${operation}`,\n );\n}\n\nexport async function extract<T extends StagehandZodObject>({\n instruction,\n domElements,\n schema,\n llmClient,\n logger,\n userProvidedInstructions,\n logInferenceToFile = false,\n}: {\n instruction: string;\n domElements: string;\n schema: T;\n llmClient: LLMClient;\n userProvidedInstructions?: string;\n logger: (message: LogLine) => void;\n logInferenceToFile?: boolean;\n}) {\n const metadataSchema = z.object({\n progress: z\n .string()\n .describe(\n \"progress of what has been extracted so far, as concise as possible\",\n ),\n completed: z\n .boolean()\n .describe(\n \"true if the goal is now accomplished. Use this conservatively, only when sure that the goal has been completed.\",\n ),\n });\n\n type ExtractionResponse = InferStagehandSchema<T>;\n type MetadataResponse = z.infer<typeof metadataSchema>;\n\n const isUsingAnthropic = llmClient.type === \"anthropic\";\n const isGPT5 = llmClient.modelName.includes(\"gpt-5\"); // TODO: remove this as we update support for gpt-5 configuration options\n\n const extractCallMessages: ChatMessage[] = [\n buildExtractSystemPrompt(isUsingAnthropic, userProvidedInstructions),\n buildExtractUserPrompt(instruction, domElements, isUsingAnthropic),\n ];\n\n let extractCallFile = \"\";\n let extractCallTimestamp = \"\";\n if (logInferenceToFile) {\n const { fileName, timestamp } = writeTimestampedTxtFile(\n \"extract_summary\",\n \"extract_call\",\n {\n modelCall: \"extract\",\n messages: extractCallMessages,\n },\n );\n extractCallFile = fileName;\n extractCallTimestamp = timestamp;\n }\n\n const extractStartTime = Date.now();\n const extractionResponse = await withLlmTimeout(\n llmClient.createChatCompletion<ExtractionResponse>({\n options: {\n messages: extractCallMessages,\n response_model: {\n schema,\n name: \"Extraction\",\n },\n temperature: isGPT5 ? 1 : 0.1,\n top_p: 1,\n frequency_penalty: 0,\n presence_penalty: 0,\n },\n logger,\n }),\n \"extract\",\n );\n const extractEndTime = Date.now();\n\n const { data: extractedData, usage: extractUsage } = extractionResponse;\n\n let extractResponseFile: string;\n if (logInferenceToFile) {\n const { fileName } = writeTimestampedTxtFile(\n \"extract_summary\",\n \"extract_response\",\n {\n modelResponse: \"extract\",\n rawResponse: extractedData,\n },\n );\n extractResponseFile = fileName;\n\n appendSummary(\"extract\", {\n extract_inference_type: \"extract\",\n timestamp: extractCallTimestamp,\n LLM_input_file: extractCallFile,\n LLM_output_file: extractResponseFile,\n prompt_tokens: extractUsage?.prompt_tokens ?? 0,\n completion_tokens: extractUsage?.completion_tokens ?? 0,\n reasoning_tokens: extractUsage?.reasoning_tokens ?? 0,\n cached_input_tokens: extractUsage?.cached_input_tokens ?? 0,\n inference_time_ms: extractEndTime - extractStartTime,\n });\n }\n\n const metadataCallMessages: ChatMessage[] = [\n buildMetadataSystemPrompt(),\n buildMetadataPrompt(instruction, extractedData),\n ];\n\n let metadataCallFile = \"\";\n let metadataCallTimestamp = \"\";\n if (logInferenceToFile) {\n const { fileName, timestamp } = writeTimestampedTxtFile(\n \"extract_summary\",\n \"metadata_call\",\n {\n modelCall: \"metadata\",\n messages: metadataCallMessages,\n },\n );\n metadataCallFile = fileName;\n metadataCallTimestamp = timestamp;\n }\n\n const metadataStartTime = Date.now();\n const metadataResponse = await withLlmTimeout(\n llmClient.createChatCompletion<MetadataResponse>({\n options: {\n messages: metadataCallMessages,\n response_model: {\n name: \"Metadata\",\n schema: metadataSchema,\n },\n temperature: isGPT5 ? 1 : 0.1,\n top_p: 1,\n frequency_penalty: 0,\n presence_penalty: 0,\n },\n logger,\n }),\n \"extract metadata\",\n );\n const metadataEndTime = Date.now();\n\n const {\n data: {\n completed: metadataResponseCompleted,\n progress: metadataResponseProgress,\n },\n usage: metadataResponseUsage,\n } = metadataResponse;\n\n let metadataResponseFile: string;\n if (logInferenceToFile) {\n const { fileName } = writeTimestampedTxtFile(\n \"extract_summary\",\n \"metadata_response\",\n {\n modelResponse: \"metadata\",\n completed: metadataResponseCompleted,\n progress: metadataResponseProgress,\n },\n );\n metadataResponseFile = fileName;\n\n appendSummary(\"extract\", {\n extract_inference_type: \"metadata\",\n timestamp: metadataCallTimestamp,\n LLM_input_file: metadataCallFile,\n LLM_output_file: metadataResponseFile,\n prompt_tokens: metadataResponseUsage?.prompt_tokens ?? 0,\n completion_tokens: metadataResponseUsage?.completion_tokens ?? 0,\n reasoning_tokens: metadataResponseUsage?.reasoning_tokens ?? 0,\n cached_input_tokens: metadataResponseUsage?.cached_input_tokens ?? 0,\n inference_time_ms: metadataEndTime - metadataStartTime,\n });\n }\n\n const totalPromptTokens =\n (extractUsage?.prompt_tokens ?? 0) +\n (metadataResponseUsage?.prompt_tokens ?? 0);\n\n const totalCompletionTokens =\n (extractUsage?.completion_tokens ?? 0) +\n (metadataResponseUsage?.completion_tokens ?? 0);\n\n const totalInferenceTimeMs =\n extractEndTime - extractStartTime + (metadataEndTime - metadataStartTime);\n const totalReasoningTokens =\n (extractUsage?.reasoning_tokens ?? 0) +\n (metadataResponseUsage?.reasoning_tokens ?? 0);\n const totalCachedInputTokens =\n (extractUsage?.cached_input_tokens ?? 0) +\n (metadataResponseUsage?.cached_input_tokens ?? 0);\n\n return {\n ...extractedData,\n metadata: {\n completed: metadataResponseCompleted,\n progress: metadataResponseProgress,\n },\n prompt_tokens: totalPromptTokens,\n completion_tokens: totalCompletionTokens,\n reasoning_tokens: totalReasoningTokens,\n cached_input_tokens: totalCachedInputTokens,\n inference_time_ms: totalInferenceTimeMs,\n };\n}\n\nexport async function observe({\n instruction,\n domElements,\n llmClient,\n userProvidedInstructions,\n logger,\n logInferenceToFile = false,\n supportedActions,\n variables,\n}: {\n instruction: string;\n domElements: string;\n llmClient: LLMClient;\n userProvidedInstructions?: string;\n logger: (message: LogLine) => void;\n logInferenceToFile?: boolean;\n supportedActions?: string[];\n variables?: Variables;\n}) {\n const isGPT5 = llmClient.modelName.includes(\"gpt-5\"); // TODO: remove this as we update support for gpt-5 configuration options\n\n const observeSchema = z.object({\n elements: z\n .array(\n z.object({\n elementId: z\n .string()\n .regex(/^\\d+-\\d+$/)\n .describe(\n \"the ID string associated with the element. Never include surrounding square brackets. This field must follow the format of 'number-number'.\",\n ),\n description: z\n .string()\n .describe(\n \"a description of the accessible element and its purpose\",\n ),\n method: z\n .enum(\n // Use Object.values() for Zod v3 compatibility - z.enum() in v3 doesn't accept TypeScript enums directly\n Object.values(SupportedUnderstudyAction) as unknown as readonly [\n string,\n ...string[],\n ],\n )\n .describe(\n `the candidate method/action to interact with the element. Select one of the available Understudy interaction methods.`,\n ),\n arguments: z.array(\n z\n .string()\n .describe(\n \"the arguments to pass to the method. For example, for a click, the arguments are empty, but for a fill, the arguments are the value to fill in.\",\n ),\n ),\n }),\n )\n .describe(\"an array of accessible elements that match the instruction\"),\n });\n\n type ObserveResponse = z.infer<typeof observeSchema>;\n\n const messages: ChatMessage[] = [\n buildObserveSystemPrompt(\n userProvidedInstructions,\n supportedActions,\n variables,\n ),\n buildObserveUserMessage(instruction, domElements),\n ];\n\n let callTimestamp = \"\";\n let callFile = \"\";\n if (logInferenceToFile) {\n const { fileName, timestamp } = writeTimestampedTxtFile(\n `observe_summary`,\n `observe_call`,\n {\n modelCall: \"observe\",\n messages,\n },\n );\n callFile = fileName;\n callTimestamp = timestamp;\n }\n\n const start = Date.now();\n const rawResponse = await llmClient.createChatCompletion<ObserveResponse>({\n options: {\n messages,\n response_model: {\n schema: observeSchema,\n name: \"Observation\",\n },\n temperature: isGPT5 ? 1 : 0.1,\n top_p: 1,\n frequency_penalty: 0,\n presence_penalty: 0,\n },\n logger,\n });\n const end = Date.now();\n const usageTimeMs = end - start;\n\n const { data: observeData, usage: observeUsage } = rawResponse;\n const promptTokens = observeUsage?.prompt_tokens ?? 0;\n const completionTokens = observeUsage?.completion_tokens ?? 0;\n const reasoningTokens = observeUsage?.reasoning_tokens ?? 0;\n const cachedInputTokens = observeUsage?.cached_input_tokens ?? 0;\n\n let responseFile: string;\n if (logInferenceToFile) {\n const { fileName: responseFileName } = writeTimestampedTxtFile(\n `observe_summary`,\n `observe_response`,\n {\n modelResponse: \"observe\",\n rawResponse: observeData,\n },\n );\n responseFile = responseFileName;\n\n appendSummary(\"observe\", {\n [`observe_inference_type`]: \"observe\",\n timestamp: callTimestamp,\n LLM_input_file: callFile,\n LLM_output_file: responseFile,\n prompt_tokens: promptTokens,\n completion_tokens: completionTokens,\n reasoning_tokens: reasoningTokens,\n cached_input_tokens: cachedInputTokens,\n inference_time_ms: usageTimeMs,\n });\n }\n\n const parsedElements =\n observeData.elements?.map((el) => {\n const base = {\n elementId: el.elementId,\n description: String(el.description),\n method: String(el.method),\n arguments: el.arguments,\n };\n return base;\n }) ?? [];\n\n return {\n elements: parsedElements,\n prompt_tokens: promptTokens,\n completion_tokens: completionTokens,\n reasoning_tokens: reasoningTokens,\n cached_input_tokens: cachedInputTokens,\n inference_time_ms: usageTimeMs,\n };\n}\n\nexport async function act({\n instruction,\n domElements,\n llmClient,\n userProvidedInstructions,\n logger,\n logInferenceToFile = false,\n}: {\n instruction: string;\n domElements: string;\n llmClient: LLMClient;\n userProvidedInstructions?: string;\n logger: (message: LogLine) => void;\n logInferenceToFile?: boolean;\n}) {\n const isGPT5 = llmClient.modelName.includes(\"gpt-5\"); // TODO: remove this as we update support for gpt-5 configuration options\n\n const actSchema = z.object({\n action: z\n .object({\n elementId: z\n .string()\n .regex(/^\\d+-\\d+$/)\n .describe(\n \"the ID string associated with the element. Never include surrounding square brackets. This field must follow the format of 'number-number'. for example, '0-76' or '16-21'\",\n ),\n description: z\n .string()\n .describe(\"a description of the accessible element and its purpose\"),\n method: z\n .enum(\n // Use Object.values() for Zod v3 compatibility - z.enum() in v3 doesn't accept TypeScript enums directly\n Object.values(SupportedUnderstudyAction) as unknown as readonly [\n string,\n ...string[],\n ],\n )\n .describe(\n \"the candidate method/action to interact with the element. Select one of the available Understudy interaction methods.\",\n ),\n arguments: z.array(\n z\n .string()\n .describe(\n \"the arguments to pass to the method. For example, for a click, the arguments are empty, but for a fill, the arguments are the value to fill in.\",\n ),\n ),\n })\n .nullable()\n .describe(\n \"The element to act on. Return null if no element on the page matches the instruction — do NOT fabricate or guess an element, and never emit empty strings or placeholder values.\",\n ),\n twoStep: z.boolean(),\n });\n\n type ActResponse = z.infer<typeof actSchema>;\n\n const messages: ChatMessage[] = [\n buildActSystemPrompt(userProvidedInstructions),\n buildObserveUserMessage(instruction, domElements),\n ];\n\n let callTimestamp = \"\";\n let callFile = \"\";\n if (logInferenceToFile) {\n const { fileName, timestamp } = writeTimestampedTxtFile(\n `act_summary`,\n `act_call`,\n {\n modelCall: \"act\",\n messages,\n },\n );\n callFile = fileName;\n callTimestamp = timestamp;\n }\n\n const start = Date.now();\n const rawResponse = await llmClient.createChatCompletion<ActResponse>({\n options: {\n messages,\n response_model: {\n schema: actSchema,\n name: \"act\",\n },\n temperature: isGPT5 ? 1 : 0.1,\n top_p: 1,\n frequency_penalty: 0,\n presence_penalty: 0,\n },\n logger,\n });\n const end = Date.now();\n const usageTimeMs = end - start;\n\n const { data: actData, usage: actUsage } = rawResponse;\n const promptTokens = actUsage?.prompt_tokens ?? 0;\n const completionTokens = actUsage?.completion_tokens ?? 0;\n const reasoningTokens = actUsage?.reasoning_tokens ?? 0;\n const cachedInputTokens = actUsage?.cached_input_tokens ?? 0;\n\n let responseFile: string;\n if (logInferenceToFile) {\n const { fileName: responseFileName } = writeTimestampedTxtFile(\n `act_summary`,\n `act_response`,\n {\n modelResponse: \"act\",\n rawResponse: actData,\n },\n );\n responseFile = responseFileName;\n\n appendSummary(\"act\", {\n [`act_inference_type`]: \"act\",\n timestamp: callTimestamp,\n LLM_input_file: callFile,\n LLM_output_file: responseFile,\n prompt_tokens: promptTokens,\n completion_tokens: completionTokens,\n reasoning_tokens: reasoningTokens,\n cached_input_tokens: cachedInputTokens,\n inference_time_ms: usageTimeMs,\n });\n }\n\n const parsedElement = actData.action\n ? {\n elementId: actData.action.elementId,\n description: String(actData.action.description),\n method: String(actData.action.method),\n arguments: actData.action.arguments,\n }\n : undefined;\n\n return {\n element: parsedElement,\n prompt_tokens: promptTokens,\n completion_tokens: completionTokens,\n reasoning_tokens: reasoningTokens,\n cached_input_tokens: cachedInputTokens,\n inference_time_ms: usageTimeMs,\n twoStep: actData.twoStep,\n };\n}\n"]}
@@ -5,19 +5,19 @@ exports.a11yScriptGlobalRefs = exports.a11yScriptSources = exports.a11yScriptBoo
5
5
  * AUTO-GENERATED FILE. DO NOT EDIT.
6
6
  * Update sources in lib/v3/dom/a11yScripts and run genA11yScripts.ts.
7
7
  */
8
- exports.a11yScriptBootstrap = "if (!globalThis.__stagehandA11yScripts) { var __stagehandA11yScriptsFactory=(()=>{var i=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var N=(o,t)=>{for(var n in t)i(o,n,{get:t[n],enumerable:!0})},h=(o,t,n,d)=>{if(t&&typeof t==\"object\"||typeof t==\"function\")for(let u of f(t))!p.call(o,u)&&u!==n&&i(o,u,{get:()=>t[u],enumerable:!(d=a(t,u))||d.enumerable});return o};var E=o=>h(i({},\"__esModule\",{value:!0}),o);var b={};N(b,{documentHasFocusStrict:()=>g,getBoundingRectLite:()=>w,getScrollOffsets:()=>y,nodeToAbsoluteXPath:()=>$,resolveDeepActiveElement:()=>T});function y(){try{let o=window.scrollX??window.pageXOffset??document.documentElement?.scrollLeft??0,t=window.scrollY??window.pageYOffset??document.documentElement?.scrollTop??0;return{sx:Number(o)||0,sy:Number(t)||0}}catch{return{sx:0,sy:0}}}function w(){try{let o=this.getBoundingClientRect();return{left:Number(o?.left??0)||0,top:Number(o?.top??0)||0}}catch{return{left:0,top:0}}}function T(){try{return(t=>{let n=t.activeElement??null;for(;n&&n.shadowRoot&&n.shadowRoot.activeElement;)n=n.shadowRoot.activeElement;return n??null})(document)}catch{return null}}function $(){return(t=>{try{let n=e=>{if(!e||!e.parentNode)return 1;let l=1,m=`${e.nodeType}:${(e.nodeName||\"\").toLowerCase()}`;for(let c=e.previousSibling;c;c=c.previousSibling)`${c.nodeType}:${(c.nodeName||\"\").toLowerCase()}`===m&&(l+=1);return l},d=e=>{if(!e||e.nodeType===Node.DOCUMENT_NODE)return\"\";if(e.nodeType===Node.DOCUMENT_FRAGMENT_NODE)return\"//\";if(e.nodeType===Node.TEXT_NODE)return`text()[${n(e)}]`;if(e.nodeType===Node.COMMENT_NODE)return`comment()[${n(e)}]`;let l=(e.nodeName||\"\").toLowerCase();return`${l.includes(\":\")?`*[name()='${l}']`:l}[${n(e)}]`},u=[],s=t;for(;s;){if(s.nodeType===Node.DOCUMENT_FRAGMENT_NODE){u.push(\"//\"),s=s.host??null;continue}let e=d(s);e&&u.push(e),s=s.parentNode}u.reverse();let r=\"\";for(let e of u)e===\"//\"?r=r?r.endsWith(\"/\")?`${r}/`:`${r}//`:\"//\":r=r?r.endsWith(\"/\")?`${r}${e}`:`${r}/${e}`:`/${e}`;return r||\"/\"}catch{return\"/\"}})(this)}function g(){try{return document.hasFocus()===!0}catch{return!1}}return E(b);})();\n globalThis.__stagehandA11yScripts = __stagehandA11yScriptsFactory;\n}";
8
+ exports.a11yScriptBootstrap = 'if (!globalThis.__stagehandA11yScripts) { var __stagehandA11yScriptsFactory=(()=>{var i=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var N=(o,t)=>{for(var n in t)i(o,n,{get:t[n],enumerable:!0})},h=(o,t,n,d)=>{if(t&&typeof t=="object"||typeof t=="function")for(let u of f(t))!p.call(o,u)&&u!==n&&i(o,u,{get:()=>t[u],enumerable:!(d=a(t,u))||d.enumerable});return o};var E=o=>h(i({},"__esModule",{value:!0}),o);var b={};N(b,{documentHasFocusStrict:()=>g,getBoundingRectLite:()=>w,getScrollOffsets:()=>y,nodeToAbsoluteXPath:()=>$,resolveDeepActiveElement:()=>T});function y(){try{let o=window.scrollX??window.pageXOffset??document.documentElement?.scrollLeft??0,t=window.scrollY??window.pageYOffset??document.documentElement?.scrollTop??0;return{sx:Number(o)||0,sy:Number(t)||0}}catch{return{sx:0,sy:0}}}function w(){try{let o=this.getBoundingClientRect();return{left:Number(o?.left??0)||0,top:Number(o?.top??0)||0}}catch{return{left:0,top:0}}}function T(){try{return(t=>{let n=t.activeElement??null;for(;n&&n.shadowRoot&&n.shadowRoot.activeElement;)n=n.shadowRoot.activeElement;return n??null})(document)}catch{return null}}function $(){return(t=>{try{let n=e=>{if(!e||!e.parentNode)return 1;let l=1,m=`${e.nodeType}:${(e.nodeName||"").toLowerCase()}`;for(let c=e.previousSibling;c;c=c.previousSibling)`${c.nodeType}:${(c.nodeName||"").toLowerCase()}`===m&&(l+=1);return l},d=e=>{if(!e||e.nodeType===Node.DOCUMENT_NODE)return"";if(e.nodeType===Node.DOCUMENT_FRAGMENT_NODE)return"//";if(e.nodeType===Node.TEXT_NODE)return`text()[${n(e)}]`;if(e.nodeType===Node.COMMENT_NODE)return`comment()[${n(e)}]`;let l=(e.nodeName||"").toLowerCase();return`${l.includes(":")?`*[name()=\'${l}\']`:l}[${n(e)}]`},u=[],s=t;for(;s;){if(s.nodeType===Node.DOCUMENT_FRAGMENT_NODE){u.push("//"),s=s.host??null;continue}let e=d(s);e&&u.push(e),s=s.parentNode}u.reverse();let r="";for(let e of u)e==="//"?r=r?r.endsWith("/")?`${r}/`:`${r}//`:"//":r=r?r.endsWith("/")?`${r}${e}`:`${r}/${e}`:`/${e}`;return r||"/"}catch{return"/"}})(this)}function g(){try{return document.hasFocus()===!0}catch{return!1}}return E(b);})();\n globalThis.__stagehandA11yScripts = __stagehandA11yScriptsFactory;\n}';
9
9
  exports.a11yScriptSources = {
10
- "documentHasFocusStrict": "function h(){try{return document.hasFocus()===!0}catch{return!1}}",
11
- "getBoundingRectLite": "function f(){try{let r=this.getBoundingClientRect();return{left:Number(r?.left??0)||0,top:Number(r?.top??0)||0}}catch{return{left:0,top:0}}}",
12
- "getScrollOffsets": "function a(){try{let r=window.scrollX??window.pageXOffset??document.documentElement?.scrollLeft??0,s=window.scrollY??window.pageYOffset??document.documentElement?.scrollTop??0;return{sx:Number(r)||0,sy:Number(s)||0}}catch{return{sx:0,sy:0}}}",
13
- "nodeToAbsoluteXPath": "function N(){return(s=>{try{let n=e=>{if(!e||!e.parentNode)return 1;let u=1,d=`${e.nodeType}:${(e.nodeName||\"\").toLowerCase()}`;for(let l=e.previousSibling;l;l=l.previousSibling)`${l.nodeType}:${(l.nodeName||\"\").toLowerCase()}`===d&&(u+=1);return u},i=e=>{if(!e||e.nodeType===Node.DOCUMENT_NODE)return\"\";if(e.nodeType===Node.DOCUMENT_FRAGMENT_NODE)return\"//\";if(e.nodeType===Node.TEXT_NODE)return`text()[${n(e)}]`;if(e.nodeType===Node.COMMENT_NODE)return`comment()[${n(e)}]`;let u=(e.nodeName||\"\").toLowerCase();return`${u.includes(\":\")?`*[name()='${u}']`:u}[${n(e)}]`},c=[],o=s;for(;o;){if(o.nodeType===Node.DOCUMENT_FRAGMENT_NODE){c.push(\"//\"),o=o.host??null;continue}let e=i(o);e&&c.push(e),o=o.parentNode}c.reverse();let t=\"\";for(let e of c)e===\"//\"?t=t?t.endsWith(\"/\")?`${t}/`:`${t}//`:\"//\":t=t?t.endsWith(\"/\")?`${t}${e}`:`${t}/${e}`:`/${e}`;return t||\"/\"}catch{return\"/\"}})(this)}",
14
- "resolveDeepActiveElement": "function p(){try{return(s=>{let n=s.activeElement??null;for(;n&&n.shadowRoot&&n.shadowRoot.activeElement;)n=n.shadowRoot.activeElement;return n??null})(document)}catch{return null}}"
10
+ documentHasFocusStrict: "function h(){try{return document.hasFocus()===!0}catch{return!1}}",
11
+ getBoundingRectLite: "function f(){try{let r=this.getBoundingClientRect();return{left:Number(r?.left??0)||0,top:Number(r?.top??0)||0}}catch{return{left:0,top:0}}}",
12
+ getScrollOffsets: "function a(){try{let r=window.scrollX??window.pageXOffset??document.documentElement?.scrollLeft??0,s=window.scrollY??window.pageYOffset??document.documentElement?.scrollTop??0;return{sx:Number(r)||0,sy:Number(s)||0}}catch{return{sx:0,sy:0}}}",
13
+ nodeToAbsoluteXPath: 'function N(){return(s=>{try{let n=e=>{if(!e||!e.parentNode)return 1;let u=1,d=`${e.nodeType}:${(e.nodeName||"").toLowerCase()}`;for(let l=e.previousSibling;l;l=l.previousSibling)`${l.nodeType}:${(l.nodeName||"").toLowerCase()}`===d&&(u+=1);return u},i=e=>{if(!e||e.nodeType===Node.DOCUMENT_NODE)return"";if(e.nodeType===Node.DOCUMENT_FRAGMENT_NODE)return"//";if(e.nodeType===Node.TEXT_NODE)return`text()[${n(e)}]`;if(e.nodeType===Node.COMMENT_NODE)return`comment()[${n(e)}]`;let u=(e.nodeName||"").toLowerCase();return`${u.includes(":")?`*[name()=\'${u}\']`:u}[${n(e)}]`},c=[],o=s;for(;o;){if(o.nodeType===Node.DOCUMENT_FRAGMENT_NODE){c.push("//"),o=o.host??null;continue}let e=i(o);e&&c.push(e),o=o.parentNode}c.reverse();let t="";for(let e of c)e==="//"?t=t?t.endsWith("/")?`${t}/`:`${t}//`:"//":t=t?t.endsWith("/")?`${t}${e}`:`${t}/${e}`:`/${e}`;return t||"/"}catch{return"/"}})(this)}',
14
+ resolveDeepActiveElement: "function p(){try{return(s=>{let n=s.activeElement??null;for(;n&&n.shadowRoot&&n.shadowRoot.activeElement;)n=n.shadowRoot.activeElement;return n??null})(document)}catch{return null}}",
15
15
  };
16
16
  exports.a11yScriptGlobalRefs = {
17
- "documentHasFocusStrict": "globalThis.__stagehandA11yScripts.documentHasFocusStrict",
18
- "getBoundingRectLite": "globalThis.__stagehandA11yScripts.getBoundingRectLite",
19
- "getScrollOffsets": "globalThis.__stagehandA11yScripts.getScrollOffsets",
20
- "nodeToAbsoluteXPath": "globalThis.__stagehandA11yScripts.nodeToAbsoluteXPath",
21
- "resolveDeepActiveElement": "globalThis.__stagehandA11yScripts.resolveDeepActiveElement"
17
+ documentHasFocusStrict: "globalThis.__stagehandA11yScripts.documentHasFocusStrict",
18
+ getBoundingRectLite: "globalThis.__stagehandA11yScripts.getBoundingRectLite",
19
+ getScrollOffsets: "globalThis.__stagehandA11yScripts.getScrollOffsets",
20
+ nodeToAbsoluteXPath: "globalThis.__stagehandA11yScripts.nodeToAbsoluteXPath",
21
+ resolveDeepActiveElement: "globalThis.__stagehandA11yScripts.resolveDeepActiveElement",
22
22
  };
23
23
  //# sourceMappingURL=a11yScripts.generated.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"a11yScripts.generated.js","sourceRoot":"","sources":["../../../../../../lib/v3/dom/build/a11yScripts.generated.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACU,QAAA,mBAAmB,GAAG,4uEAA4uE,CAAC;AACnwE,QAAA,iBAAiB,GAAG;IAC/B,wBAAwB,EAAE,mEAAmE;IAC7F,qBAAqB,EAAE,8IAA8I;IACrK,kBAAkB,EAAE,mPAAmP;IACvQ,qBAAqB,EAAE,o5BAAo5B;IAC36B,0BAA0B,EAAE,uLAAuL;CAC3M,CAAC;AACE,QAAA,oBAAoB,GAAG;IAClC,wBAAwB,EAAE,0DAA0D;IACpF,qBAAqB,EAAE,uDAAuD;IAC9E,kBAAkB,EAAE,oDAAoD;IACxE,qBAAqB,EAAE,uDAAuD;IAC9E,0BAA0B,EAAE,4DAA4D;CAChF,CAAC","sourcesContent":["/*\n * AUTO-GENERATED FILE. DO NOT EDIT.\n * Update sources in lib/v3/dom/a11yScripts and run genA11yScripts.ts.\n */\nexport const a11yScriptBootstrap = \"if (!globalThis.__stagehandA11yScripts) { var __stagehandA11yScriptsFactory=(()=>{var i=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var N=(o,t)=>{for(var n in t)i(o,n,{get:t[n],enumerable:!0})},h=(o,t,n,d)=>{if(t&&typeof t==\\\"object\\\"||typeof t==\\\"function\\\")for(let u of f(t))!p.call(o,u)&&u!==n&&i(o,u,{get:()=>t[u],enumerable:!(d=a(t,u))||d.enumerable});return o};var E=o=>h(i({},\\\"__esModule\\\",{value:!0}),o);var b={};N(b,{documentHasFocusStrict:()=>g,getBoundingRectLite:()=>w,getScrollOffsets:()=>y,nodeToAbsoluteXPath:()=>$,resolveDeepActiveElement:()=>T});function y(){try{let o=window.scrollX??window.pageXOffset??document.documentElement?.scrollLeft??0,t=window.scrollY??window.pageYOffset??document.documentElement?.scrollTop??0;return{sx:Number(o)||0,sy:Number(t)||0}}catch{return{sx:0,sy:0}}}function w(){try{let o=this.getBoundingClientRect();return{left:Number(o?.left??0)||0,top:Number(o?.top??0)||0}}catch{return{left:0,top:0}}}function T(){try{return(t=>{let n=t.activeElement??null;for(;n&&n.shadowRoot&&n.shadowRoot.activeElement;)n=n.shadowRoot.activeElement;return n??null})(document)}catch{return null}}function $(){return(t=>{try{let n=e=>{if(!e||!e.parentNode)return 1;let l=1,m=`${e.nodeType}:${(e.nodeName||\\\"\\\").toLowerCase()}`;for(let c=e.previousSibling;c;c=c.previousSibling)`${c.nodeType}:${(c.nodeName||\\\"\\\").toLowerCase()}`===m&&(l+=1);return l},d=e=>{if(!e||e.nodeType===Node.DOCUMENT_NODE)return\\\"\\\";if(e.nodeType===Node.DOCUMENT_FRAGMENT_NODE)return\\\"//\\\";if(e.nodeType===Node.TEXT_NODE)return`text()[${n(e)}]`;if(e.nodeType===Node.COMMENT_NODE)return`comment()[${n(e)}]`;let l=(e.nodeName||\\\"\\\").toLowerCase();return`${l.includes(\\\":\\\")?`*[name()='${l}']`:l}[${n(e)}]`},u=[],s=t;for(;s;){if(s.nodeType===Node.DOCUMENT_FRAGMENT_NODE){u.push(\\\"//\\\"),s=s.host??null;continue}let e=d(s);e&&u.push(e),s=s.parentNode}u.reverse();let r=\\\"\\\";for(let e of u)e===\\\"//\\\"?r=r?r.endsWith(\\\"/\\\")?`${r}/`:`${r}//`:\\\"//\\\":r=r?r.endsWith(\\\"/\\\")?`${r}${e}`:`${r}/${e}`:`/${e}`;return r||\\\"/\\\"}catch{return\\\"/\\\"}})(this)}function g(){try{return document.hasFocus()===!0}catch{return!1}}return E(b);})();\\n globalThis.__stagehandA11yScripts = __stagehandA11yScriptsFactory;\\n}\";\nexport const a11yScriptSources = {\n \"documentHasFocusStrict\": \"function h(){try{return document.hasFocus()===!0}catch{return!1}}\",\n \"getBoundingRectLite\": \"function f(){try{let r=this.getBoundingClientRect();return{left:Number(r?.left??0)||0,top:Number(r?.top??0)||0}}catch{return{left:0,top:0}}}\",\n \"getScrollOffsets\": \"function a(){try{let r=window.scrollX??window.pageXOffset??document.documentElement?.scrollLeft??0,s=window.scrollY??window.pageYOffset??document.documentElement?.scrollTop??0;return{sx:Number(r)||0,sy:Number(s)||0}}catch{return{sx:0,sy:0}}}\",\n \"nodeToAbsoluteXPath\": \"function N(){return(s=>{try{let n=e=>{if(!e||!e.parentNode)return 1;let u=1,d=`${e.nodeType}:${(e.nodeName||\\\"\\\").toLowerCase()}`;for(let l=e.previousSibling;l;l=l.previousSibling)`${l.nodeType}:${(l.nodeName||\\\"\\\").toLowerCase()}`===d&&(u+=1);return u},i=e=>{if(!e||e.nodeType===Node.DOCUMENT_NODE)return\\\"\\\";if(e.nodeType===Node.DOCUMENT_FRAGMENT_NODE)return\\\"//\\\";if(e.nodeType===Node.TEXT_NODE)return`text()[${n(e)}]`;if(e.nodeType===Node.COMMENT_NODE)return`comment()[${n(e)}]`;let u=(e.nodeName||\\\"\\\").toLowerCase();return`${u.includes(\\\":\\\")?`*[name()='${u}']`:u}[${n(e)}]`},c=[],o=s;for(;o;){if(o.nodeType===Node.DOCUMENT_FRAGMENT_NODE){c.push(\\\"//\\\"),o=o.host??null;continue}let e=i(o);e&&c.push(e),o=o.parentNode}c.reverse();let t=\\\"\\\";for(let e of c)e===\\\"//\\\"?t=t?t.endsWith(\\\"/\\\")?`${t}/`:`${t}//`:\\\"//\\\":t=t?t.endsWith(\\\"/\\\")?`${t}${e}`:`${t}/${e}`:`/${e}`;return t||\\\"/\\\"}catch{return\\\"/\\\"}})(this)}\",\n \"resolveDeepActiveElement\": \"function p(){try{return(s=>{let n=s.activeElement??null;for(;n&&n.shadowRoot&&n.shadowRoot.activeElement;)n=n.shadowRoot.activeElement;return n??null})(document)}catch{return null}}\"\n} as const;\nexport const a11yScriptGlobalRefs = {\n \"documentHasFocusStrict\": \"globalThis.__stagehandA11yScripts.documentHasFocusStrict\",\n \"getBoundingRectLite\": \"globalThis.__stagehandA11yScripts.getBoundingRectLite\",\n \"getScrollOffsets\": \"globalThis.__stagehandA11yScripts.getScrollOffsets\",\n \"nodeToAbsoluteXPath\": \"globalThis.__stagehandA11yScripts.nodeToAbsoluteXPath\",\n \"resolveDeepActiveElement\": \"globalThis.__stagehandA11yScripts.resolveDeepActiveElement\"\n} as const;\nexport type A11yScriptName = keyof typeof a11yScriptSources;\n"]}
1
+ {"version":3,"file":"a11yScripts.generated.js","sourceRoot":"","sources":["../../../../../../lib/v3/dom/build/a11yScripts.generated.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACU,QAAA,mBAAmB,GAC9B,4sEAA4sE,CAAC;AAClsE,QAAA,iBAAiB,GAAG;IAC/B,sBAAsB,EACpB,mEAAmE;IACrE,mBAAmB,EACjB,8IAA8I;IAChJ,gBAAgB,EACd,mPAAmP;IACrP,mBAAmB,EACjB,03BAA03B;IAC53B,wBAAwB,EACtB,uLAAuL;CACjL,CAAC;AACE,QAAA,oBAAoB,GAAG;IAClC,sBAAsB,EACpB,0DAA0D;IAC5D,mBAAmB,EAAE,uDAAuD;IAC5E,gBAAgB,EAAE,oDAAoD;IACtE,mBAAmB,EAAE,uDAAuD;IAC5E,wBAAwB,EACtB,4DAA4D;CACtD,CAAC","sourcesContent":["/*\n * AUTO-GENERATED FILE. DO NOT EDIT.\n * Update sources in lib/v3/dom/a11yScripts and run genA11yScripts.ts.\n */\nexport const a11yScriptBootstrap =\n 'if (!globalThis.__stagehandA11yScripts) { var __stagehandA11yScriptsFactory=(()=>{var i=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var N=(o,t)=>{for(var n in t)i(o,n,{get:t[n],enumerable:!0})},h=(o,t,n,d)=>{if(t&&typeof t==\"object\"||typeof t==\"function\")for(let u of f(t))!p.call(o,u)&&u!==n&&i(o,u,{get:()=>t[u],enumerable:!(d=a(t,u))||d.enumerable});return o};var E=o=>h(i({},\"__esModule\",{value:!0}),o);var b={};N(b,{documentHasFocusStrict:()=>g,getBoundingRectLite:()=>w,getScrollOffsets:()=>y,nodeToAbsoluteXPath:()=>$,resolveDeepActiveElement:()=>T});function y(){try{let o=window.scrollX??window.pageXOffset??document.documentElement?.scrollLeft??0,t=window.scrollY??window.pageYOffset??document.documentElement?.scrollTop??0;return{sx:Number(o)||0,sy:Number(t)||0}}catch{return{sx:0,sy:0}}}function w(){try{let o=this.getBoundingClientRect();return{left:Number(o?.left??0)||0,top:Number(o?.top??0)||0}}catch{return{left:0,top:0}}}function T(){try{return(t=>{let n=t.activeElement??null;for(;n&&n.shadowRoot&&n.shadowRoot.activeElement;)n=n.shadowRoot.activeElement;return n??null})(document)}catch{return null}}function $(){return(t=>{try{let n=e=>{if(!e||!e.parentNode)return 1;let l=1,m=`${e.nodeType}:${(e.nodeName||\"\").toLowerCase()}`;for(let c=e.previousSibling;c;c=c.previousSibling)`${c.nodeType}:${(c.nodeName||\"\").toLowerCase()}`===m&&(l+=1);return l},d=e=>{if(!e||e.nodeType===Node.DOCUMENT_NODE)return\"\";if(e.nodeType===Node.DOCUMENT_FRAGMENT_NODE)return\"//\";if(e.nodeType===Node.TEXT_NODE)return`text()[${n(e)}]`;if(e.nodeType===Node.COMMENT_NODE)return`comment()[${n(e)}]`;let l=(e.nodeName||\"\").toLowerCase();return`${l.includes(\":\")?`*[name()=\\'${l}\\']`:l}[${n(e)}]`},u=[],s=t;for(;s;){if(s.nodeType===Node.DOCUMENT_FRAGMENT_NODE){u.push(\"//\"),s=s.host??null;continue}let e=d(s);e&&u.push(e),s=s.parentNode}u.reverse();let r=\"\";for(let e of u)e===\"//\"?r=r?r.endsWith(\"/\")?`${r}/`:`${r}//`:\"//\":r=r?r.endsWith(\"/\")?`${r}${e}`:`${r}/${e}`:`/${e}`;return r||\"/\"}catch{return\"/\"}})(this)}function g(){try{return document.hasFocus()===!0}catch{return!1}}return E(b);})();\\n globalThis.__stagehandA11yScripts = __stagehandA11yScriptsFactory;\\n}';\nexport const a11yScriptSources = {\n documentHasFocusStrict:\n \"function h(){try{return document.hasFocus()===!0}catch{return!1}}\",\n getBoundingRectLite:\n \"function f(){try{let r=this.getBoundingClientRect();return{left:Number(r?.left??0)||0,top:Number(r?.top??0)||0}}catch{return{left:0,top:0}}}\",\n getScrollOffsets:\n \"function a(){try{let r=window.scrollX??window.pageXOffset??document.documentElement?.scrollLeft??0,s=window.scrollY??window.pageYOffset??document.documentElement?.scrollTop??0;return{sx:Number(r)||0,sy:Number(s)||0}}catch{return{sx:0,sy:0}}}\",\n nodeToAbsoluteXPath:\n 'function N(){return(s=>{try{let n=e=>{if(!e||!e.parentNode)return 1;let u=1,d=`${e.nodeType}:${(e.nodeName||\"\").toLowerCase()}`;for(let l=e.previousSibling;l;l=l.previousSibling)`${l.nodeType}:${(l.nodeName||\"\").toLowerCase()}`===d&&(u+=1);return u},i=e=>{if(!e||e.nodeType===Node.DOCUMENT_NODE)return\"\";if(e.nodeType===Node.DOCUMENT_FRAGMENT_NODE)return\"//\";if(e.nodeType===Node.TEXT_NODE)return`text()[${n(e)}]`;if(e.nodeType===Node.COMMENT_NODE)return`comment()[${n(e)}]`;let u=(e.nodeName||\"\").toLowerCase();return`${u.includes(\":\")?`*[name()=\\'${u}\\']`:u}[${n(e)}]`},c=[],o=s;for(;o;){if(o.nodeType===Node.DOCUMENT_FRAGMENT_NODE){c.push(\"//\"),o=o.host??null;continue}let e=i(o);e&&c.push(e),o=o.parentNode}c.reverse();let t=\"\";for(let e of c)e===\"//\"?t=t?t.endsWith(\"/\")?`${t}/`:`${t}//`:\"//\":t=t?t.endsWith(\"/\")?`${t}${e}`:`${t}/${e}`:`/${e}`;return t||\"/\"}catch{return\"/\"}})(this)}',\n resolveDeepActiveElement:\n \"function p(){try{return(s=>{let n=s.activeElement??null;for(;n&&n.shadowRoot&&n.shadowRoot.activeElement;)n=n.shadowRoot.activeElement;return n??null})(document)}catch{return null}}\",\n} as const;\nexport const a11yScriptGlobalRefs = {\n documentHasFocusStrict:\n \"globalThis.__stagehandA11yScripts.documentHasFocusStrict\",\n getBoundingRectLite: \"globalThis.__stagehandA11yScripts.getBoundingRectLite\",\n getScrollOffsets: \"globalThis.__stagehandA11yScripts.getScrollOffsets\",\n nodeToAbsoluteXPath: \"globalThis.__stagehandA11yScripts.nodeToAbsoluteXPath\",\n resolveDeepActiveElement:\n \"globalThis.__stagehandA11yScripts.resolveDeepActiveElement\",\n} as const;\nexport type A11yScriptName = keyof typeof a11yScriptSources;\n"]}
@@ -5,55 +5,55 @@ exports.locatorScriptGlobalRefs = exports.locatorScriptSources = exports.locator
5
5
  * AUTO-GENERATED FILE. DO NOT EDIT.
6
6
  * Update sources in lib/v3/dom/locatorScripts and run genLocatorScripts.ts.
7
7
  */
8
- exports.locatorScriptBootstrap = "if (!globalThis.__stagehandLocatorScripts) { var __stagehandLocatorScriptsFactory=(()=>{var M=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var Q=Object.prototype.hasOwnProperty;var Z=(e,t)=>{for(var n in t)M(e,n,{get:t[n],enumerable:!0})},j=(e,t,n,o)=>{if(t&&typeof t==\"object\"||typeof t==\"function\")for(let r of U(t))!Q.call(e,r)&&r!==n&&M(e,r,{get:()=>t[r],enumerable:!(o=K(t,r))||o.enumerable});return e};var J=e=>j(M({},\"__esModule\",{value:!0}),e);var Oe={};Z(Oe,{assignFilePayloadsToInputElement:()=>te,countCssMatchesPierce:()=>Me,countCssMatchesPrimary:()=>Ce,countTextMatches:()=>Le,countXPathMatchesMainWorld:()=>Pe,dispatchDomClick:()=>ne,ensureFileInputElement:()=>ee,fillElementValue:()=>se,focusElement:()=>le,isElementChecked:()=>ce,isElementVisible:()=>ae,prepareElementForTyping:()=>v,readElementInnerHTML:()=>me,readElementInnerText:()=>fe,readElementInputValue:()=>ue,readElementTextContent:()=>de,resolveCssSelector:()=>ve,resolveCssSelectorPierce:()=>Te,resolveTextSelector:()=>Re,resolveXPathMainWorld:()=>Ne,scrollElementToPercent:()=>oe,selectElementOptions:()=>ie,waitForSelector:()=>_e});function ee(){try{return(this.tagName?.toLowerCase()??\"\")!==\"input\"?!1:String(this.type??\"\").toLowerCase()===\"file\"}catch{return!1}}function te(e){try{let t=this;if(!t||t.tagName?.toLowerCase()!==\"input\"||(t.type??\"\").toLowerCase()!==\"file\")return!1;let n=(()=>{try{return new DataTransfer}catch{return null}})();if(!n)return!1;let o=Array.isArray(e)?e:[];for(let r of o){if(!r)continue;let l=r.name||\"upload.bin\",s=r.mimeType||\"application/octet-stream\",i=typeof r.lastModified==\"number\"?r.lastModified:Date.now(),a=window.atob(r.base64??\"\"),d=new Uint8Array(a.length);for(let p=0;p<a.length;p+=1)d[p]=a.charCodeAt(p);let f=new Blob([d],{type:s}),c=new File([f],l,{type:s,lastModified:i});n.items.add(c)}return t.files=n.files,t.dispatchEvent(new Event(\"input\",{bubbles:!0})),t.dispatchEvent(new Event(\"change\",{bubbles:!0})),!0}catch{return!1}}function ne(e){let t=e??{};try{let n=new MouseEvent(\"click\",{bubbles:!!t.bubbles,cancelable:!!t.cancelable,composed:!!t.composed,detail:typeof t.detail==\"number\"?t.detail:1,view:this?.ownerDocument?.defaultView??window});this.dispatchEvent(n)}catch{try{this.click()}catch{}}}function oe(e){let t=n=>{if(typeof n==\"number\"&&Number.isFinite(n))return n;let o=String(n??\"\").trim();if(!o)return 0;let r=parseFloat(o.replace(\"%\",\"\"));return Number.isNaN(r)||!Number.isFinite(r)?0:r};try{let n=Math.max(0,Math.min(t(e),100)),o=this,r=o.tagName?.toLowerCase()??\"\";if(r===\"html\"||r===\"body\"){let c=(o.ownerDocument?.scrollingElement||o.ownerDocument?.documentElement||o.ownerDocument?.body||document.scrollingElement||document.documentElement||document.body)?.scrollHeight??document.body.scrollHeight??0,p=o.ownerDocument?.defaultView?.innerHeight??window.innerHeight,w=Math.max(0,c-p)*(n/100);return o.ownerDocument?.defaultView?.scrollTo({top:w,left:o.ownerDocument?.defaultView?.scrollX??window.scrollX??0,behavior:\"smooth\"}),!0}let s=o.scrollHeight??0,i=o.clientHeight??0,d=Math.max(0,s-i)*(n/100);return o.scrollTo({top:d,left:o.scrollLeft??0,behavior:\"smooth\"}),!0}catch{return!1}}var H=new Set([\"color\",\"date\",\"datetime-local\",\"month\",\"range\",\"time\",\"week\"]),re=new Set([\"\",\"email\",\"number\",\"password\",\"search\",\"tel\",\"text\",\"url\"]);function v(){try{let e=this;if(!e.isConnected)return!1;let t=e.ownerDocument||document,n=t.defaultView||window;try{typeof e.focus==\"function\"&&e.focus()}catch{}if(e instanceof n.HTMLInputElement||e instanceof n.HTMLTextAreaElement){try{if(typeof e.select==\"function\")return e.select(),!0}catch{}try{let o=(e.value??\"\").length;if(typeof e.setSelectionRange==\"function\")return e.setSelectionRange(0,o),!0}catch{}return!0}if(e.isContentEditable){let o=t.getSelection?.(),r=t.createRange?.();if(o&&r)try{r.selectNodeContents(e),o.removeAllRanges(),o.addRange(r)}catch{}return!0}return!1}catch{return!1}}function se(e){let t=this;if(!t.isConnected)return{status:\"error\",reason:\"notconnected\"};let o=(t.ownerDocument||document).defaultView||window,r=e??\"\";try{let l=s=>{let i;if(typeof o.InputEvent==\"function\")try{i=new o.InputEvent(\"input\",{bubbles:!0,composed:!0,data:s,inputType:\"insertText\"})}catch{i=new o.Event(\"input\",{bubbles:!0,composed:!0})}else i=new o.Event(\"input\",{bubbles:!0,composed:!0});t.dispatchEvent(i);let a=new o.Event(\"change\",{bubbles:!0});t.dispatchEvent(a)};if(t instanceof o.HTMLInputElement){let s=(t.type||\"\").toLowerCase();if(!re.has(s)&&!H.has(s))return{status:\"error\",reason:`unsupported-input-type:${s}`};let i=e;if(s===\"number\"){let a=e.trim();if(a!==\"\"&&Number.isNaN(Number(a)))return{status:\"error\",reason:\"invalid-number-value\"};i=a}if(r=i,H.has(s)){let a=e.trim();r=a,v.call(t);let d=o.HTMLInputElement.prototype,c=Object.getOwnPropertyDescriptor(d,\"value\")?.set;return typeof c==\"function\"?c.call(t,a):t.value=a,t._valueTracker?.setValue?.(a),t.value!==a?{status:\"error\",reason:\"malformed-value\"}:(l(a),{status:\"done\"})}return v.call(t),{status:\"needsinput\",value:i}}return t instanceof o.HTMLTextAreaElement?(v.call(t),r=e,{status:\"needsinput\",value:e}):t instanceof o.HTMLSelectElement?{status:\"error\",reason:\"unsupported-element\"}:t.isContentEditable?(v.call(t),r=e,{status:\"needsinput\",value:e}):{status:\"error\",reason:\"unsupported-element\"}}catch(l){let s=\"exception\";if(l&&typeof l==\"object\"){let i=l.message;typeof i==\"string\"&&i.trim().length>0&&(s=`exception:${i}`)}return{status:\"needsinput\",value:r,reason:s}}}function le(){try{typeof this.focus==\"function\"&&this.focus()}catch{}}function ie(e){try{if(!(this instanceof HTMLSelectElement))return[];let t=Array.isArray(e)?e:[e],n=new Set(t.map(s=>String(s??\"\").trim())),o=s=>{let i=(s.label||s.textContent||\"\").trim(),a=String(s.value??\"\").trim();return n.has(i)||n.has(a)};if(this.multiple)for(let s of Array.from(this.options))s.selected=o(s);else{let s=!1;for(let i of Array.from(this.options))!s&&o(i)?(i.selected=!0,this.value=i.value,s=!0):i.selected=!1}let r=new Event(\"input\",{bubbles:!0}),l=new Event(\"change\",{bubbles:!0});return this.dispatchEvent(r),this.dispatchEvent(l),Array.from(this.selectedOptions).map(s=>s.value)}catch{return[]}}function ae(){try{let e=this;if(!e.isConnected)return!1;let t=e.ownerDocument?.defaultView?.getComputedStyle(e)??window.getComputedStyle(e);if(!t||t.display===\"none\"||t.visibility===\"hidden\")return!1;let n=parseFloat(t.opacity??\"1\");if(!Number.isFinite(n)||n===0)return!1;let o=e.getBoundingClientRect();return!(!o||Math.max(o.width,o.height)===0||e.getClientRects().length===0)}catch{return!1}}function ce(){try{let e=this;if((e.tagName||\"\").toLowerCase()===\"input\"){let o=e.type?.toLowerCase()??\"\";if(o===\"checkbox\"||o===\"radio\")return!!e.checked}let n=e.getAttribute?.(\"aria-checked\");return n!=null?n===\"true\":!1}catch{return!1}}function ue(){try{let e=this,t=(e.tagName||\"\").toLowerCase();return t===\"input\"||t===\"textarea\"||t===\"select\"?String(e.value??\"\"):e.isContentEditable?String(e.textContent??\"\"):\"\"}catch{return\"\"}}function de(){try{return String(this.textContent??\"\")}catch{return\"\"}}function me(){try{return String(this.innerHTML??\"\")}catch{return\"\"}}function fe(){try{let e=this,t=e.innerText;if(typeof t==\"string\"&&t.length>0)return t;let n=e.textContent;return typeof n==\"string\"?n:\"\"}catch{return\"\"}}function O(e){let t=String(e||\"\").trim().replace(/^xpath=/i,\"\");if(!t)return[];let n=[],o=0;for(;o<t.length;){let r=\"child\";t.startsWith(\"//\",o)?(r=\"desc\",o+=2):t[o]===\"/\"&&(r=\"child\",o+=1);let l=o,s=0,i=null;for(;o<t.length;){let c=t[o];if(i)c===i&&(i=null);else if(c===\"'\"||c==='\"')i=c;else if(c===\"[\")s++;else if(c===\"]\")s--;else if(c===\"/\"&&s===0)break;o+=1}let a=t.slice(l,o).trim();if(!a)continue;let{tag:d,predicates:f}=pe(a);n.push({axis:r,tag:d,predicates:f})}return n}function he(e){let t=[],n=0;for(;n<e.length;){if(e[n]!==\"[\"){n++;continue}n++;let o=n,r=null;for(;n<e.length;){let l=e[n];if(r)l===r&&(r=null);else if(l===\"'\"||l==='\"')r=l;else if(l===\"]\")break;n++}t.push(e.slice(o,n).trim()),n++}return t}function pe(e){let t=e.indexOf(\"[\");if(t===-1)return{tag:e===\"\"?\"*\":e.toLowerCase(),predicates:[]};let n=e.slice(0,t).trim(),o=n===\"\"?\"*\":n.toLowerCase(),r=e.slice(t),l=[];for(let s of he(r)){let i=T(s);i&&l.push(i)}return{tag:o,predicates:l}}function T(e){let t=e.trim();if(!t)return null;let n=A(t,\"or\");if(n.length>1){let l=n.map(s=>T(s)).filter(Boolean);return l.length!==n.length?null:{type:\"or\",predicates:l}}let o=A(t,\"and\");if(o.length>1){let l=o.map(s=>T(s)).filter(Boolean);return l.length!==o.length?null:{type:\"and\",predicates:l}}let r=we(t,\"not\");if(r!=null){let l=T(r);return l?{type:\"not\",predicate:l}:null}return ge(t)}function ge(e){let t=/^(?:'([^']*)'|\"([^\"]*)\")$/,n=\"[a-zA-Z_][\\\\w.-]*\",o=`(?:'([^']*)'|\"([^\"]*)\")`;if(/^\\d+$/.test(e))return{type:\"index\",index:Math.max(1,Number(e))};let r=e.match(new RegExp(`^normalize-space\\\\(\\\\s*@(${n})\\\\s*\\\\)\\\\s*=\\\\s*${o}$`));if(r)return{type:\"attrEquals\",name:r[1],value:r[2]??r[3]??\"\",normalize:!0};let l=e.match(new RegExp(`^normalize-space\\\\(\\\\s*(?:text\\\\(\\\\)|\\\\.)\\\\s*\\\\)\\\\s*=\\\\s*${o}$`));if(l)return{type:\"textEquals\",value:l[1]??l[2]??\"\",normalize:!0};let s=e.match(new RegExp(`^@(${n})\\\\s*=\\\\s*${o}$`));if(s)return{type:\"attrEquals\",name:s[1],value:s[2]??s[3]??\"\"};let i=e.match(new RegExp(`^@(${n})$`));if(i)return{type:\"attrExists\",name:i[1]};let a=e.match(new RegExp(`^contains\\\\(\\\\s*@(${n})\\\\s*,\\\\s*${o}\\\\s*\\\\)$`));if(a)return{type:\"attrContains\",name:a[1],value:a[2]??a[3]??\"\"};let d=e.match(new RegExp(`^starts-with\\\\(\\\\s*@(${n})\\\\s*,\\\\s*${o}\\\\s*\\\\)$`));if(d)return{type:\"attrStartsWith\",name:d[1],value:d[2]??d[3]??\"\"};let f=e.match(new RegExp(`^(?:text\\\\(\\\\)|\\\\.)\\\\s*=\\\\s*${o}$`));if(f)return{type:\"textEquals\",value:f[1]??f[2]??\"\"};let c=e.match(new RegExp(`^contains\\\\(\\\\s*(?:text\\\\(\\\\)|\\\\.)\\\\s*,\\\\s*${o}\\\\s*\\\\)$`));return c?{type:\"textContains\",value:c[1]??c[2]??\"\"}:(t.test(e),null)}function A(e,t){let n=[],o=0,r=0,l=null,s=0;for(;s<e.length;){let i=e[s];if(l){i===l&&(l=null),s+=1;continue}if(i===\"'\"||i==='\"'){l=i,s+=1;continue}if(i===\"(\"){r+=1,s+=1;continue}if(i===\")\"){r=Math.max(0,r-1),s+=1;continue}if(r===0&&Ee(e,s,t)){n.push(e.slice(o,s).trim()),s+=t.length,o=s;continue}s+=1}return n.push(e.slice(o).trim()),n.filter(i=>i.length>0)}function Ee(e,t,n){if(!e.startsWith(n,t))return!1;let o=t>0?e[t-1]:\" \";if(o===\"@\")return!1;let r=t+n.length<e.length?e[t+n.length]:\" \";return W(o)&&W(r)}function W(e){return!/[a-zA-Z0-9_.-]/.test(e)}function we(e,t){let n=`${t}(`;if(!e.startsWith(n)||!e.endsWith(\")\"))return null;let o=e.slice(n.length,-1);return ye(o)?o:null}function ye(e){let t=0,n=null;for(let o=0;o<e.length;o+=1){let r=e[o];if(n){r===n&&(n=null);continue}if(r===\"'\"||r==='\"'){n=r;continue}if(r===\"(\"?t+=1:r===\")\"&&(t-=1),t<0)return!1}return t===0}var be=e=>e.replace(/\\s+/g,\" \").trim();function _(e){return String(e.textContent??\"\")}function S(e,t){return t?be(e):e}function R(e,t){switch(t.type){case\"and\":return t.predicates.every(n=>R(e,n));case\"or\":return t.predicates.some(n=>R(e,n));case\"not\":return!R(e,t.predicate);case\"attrExists\":return e.getAttribute(t.name)!==null;case\"attrEquals\":{let n=e.getAttribute(t.name);return n===null?!1:S(n,t.normalize)===S(t.value,t.normalize)}case\"attrContains\":{let n=e.getAttribute(t.name);return n===null?!1:S(n,t.normalize).includes(S(t.value,t.normalize))}case\"attrStartsWith\":{let n=e.getAttribute(t.name);return n===null?!1:S(n,t.normalize).startsWith(S(t.value,t.normalize))}case\"textEquals\":return S(_(e),t.normalize)===S(t.value,t.normalize);case\"textContains\":return S(_(e),t.normalize).includes(S(t.value,t.normalize));case\"index\":return!0;default:return!0}}function q(e,t){let n=e;for(let o of t){if(!n.length)return[];if(o.type===\"index\"){let r=o.index-1;n=r>=0&&r<n.length?[n[r]]:[];continue}n=n.filter(r=>R(r,o))}return n}var P=e=>{let t=String(e??\"\").trim();return t?t.replace(/^xpath=/i,\"\").trim():\"\"};function I(e,t){return k(e,0,t)}function k(e,t,n){if(!Number.isFinite(t)||t<0)return null;let o=P(e);if(!o)return null;let r=Math.floor(t),l=n?.pierceShadow!==!1,s=l?z():null;if(!l)return X(o,r).value;if(!s?.hasShadow){let a=X(o,r);return a.error?N(o,s?.getClosedRoot)[r]??null:a.value}return N(o,s.getClosedRoot)[r]??null}function $(e,t){let n=P(e);if(!n)return 0;let o=t?.pierceShadow!==!1,r=o?z():null;if(!o)return F(n).count;if(!r?.hasShadow){let l=F(n);return l.error?N(n,r?.getClosedRoot).length:l.count}return N(n,r.getClosedRoot).length}function N(e,t){let n=P(e);if(!n)return[];let o=O(n);if(!o.length)return[];let r=t??null,l=[document];for(let s of o){let i=[],a=new Set;for(let d of l){if(!d)continue;let f=s.axis===\"child\"?L(d,r):Se(d,r);if(!f.length)continue;let c=f.filter(g=>xe(g,s)),p=q(c,s.predicates);for(let g of p)a.has(g)||(a.add(g),i.push(g))}if(!i.length)return[];l=i}return l}function xe(e,t){return t.tag===\"*\"?!0:e.localName===t.tag}function z(){let e=window.__stagehandV3__,t=e&&typeof e.getClosedRoot==\"function\"?o=>{try{return e.getClosedRoot(o)??null}catch{return null}}:null,n=!1;try{if(e&&typeof e.stats==\"function\"){let o=e.stats();n=(o?.open??0)>0||(o?.closed??0)>0}}catch{}if(!n)try{let o=document.createTreeWalker(document,NodeFilter.SHOW_ELEMENT);for(;o.nextNode();)if(o.currentNode.shadowRoot){n=!0;break}}catch{}return{getClosedRoot:t,hasShadow:n}}function L(e,t){let n=[];if(!e)return n;if(e instanceof Document)return e.documentElement&&n.push(e.documentElement),n;if(e instanceof ShadowRoot||e instanceof DocumentFragment)return n.push(...Array.from(e.children??[])),n;if(e instanceof Element){n.push(...Array.from(e.children??[]));let o=e.shadowRoot;if(o&&n.push(...Array.from(o.children??[])),t){let r=t(e);r&&n.push(...Array.from(r.children??[]))}return n}return n}function Se(e,t){let n=[],o=new Set,r=[...L(e,t)].reverse();for(;r.length;){let l=r.pop();if(!l||o.has(l))continue;o.add(l),n.push(l);let s=L(l,t);for(let i=s.length-1;i>=0;i-=1)r.push(s[i])}return n}function X(e,t){try{return{value:document.evaluate(e,document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotItem(t),error:!1}}catch{return{value:null,error:!0}}}function F(e){try{return{count:document.evaluate(e,document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotLength,error:!1}}catch{return{count:0,error:!0}}}var C=e=>{let t=Number(e??0);return!Number.isFinite(t)||t<0?0:Math.floor(t)},V=(e,t)=>{if(!e)return[];let n=new WeakSet,o=new Set,r=[],l=[document],s=i=>{if(!(!i||n.has(i)||r.length>=t)){n.add(i);try{let a=i.querySelectorAll(e);for(let d of a)if(!o.has(d)&&(o.add(d),r.push(d),r.length>=t))return}catch{}try{let d=(i instanceof Document?i:i.host?.ownerDocument??document).createTreeWalker(i,NodeFilter.SHOW_ELEMENT),f;for(;f=d.nextNode();){if(!(f instanceof Element))continue;let c=f.shadowRoot;c&&l.push(c)}}catch{}}};for(;l.length&&r.length<t;){let i=l.shift();i&&s(i)}return r};function ve(e,t){let n=String(e??\"\").trim();if(!n)return null;let o=C(t);return V(n,o+1)[o]??null}function Te(e,t){let n=String(e??\"\").trim();if(!n)return null;let o=C(t),r=window.__stagehandV3__;if(!r||typeof r.getClosedRoot!=\"function\")return V(n,o+1)[o]??null;let l=c=>{try{return r.getClosedRoot(c)??null}catch{return null}},s=new WeakSet,i=new Set,a=[],d=[document],f=c=>{if(!(!c||s.has(c)||a.length>=o+1)){s.add(c);try{let p=c.querySelectorAll(n);for(let g of p)if(!i.has(g)&&(i.add(g),a.push(g),a.length>=o+1))return}catch{}try{let g=(c instanceof Document?c:c.host?.ownerDocument??document).createTreeWalker(c,NodeFilter.SHOW_ELEMENT),w;for(;w=g.nextNode();){if(!(w instanceof Element))continue;let x=w.shadowRoot;x&&d.push(x);let y=l(w);y&&d.push(y)}}catch{}}};for(;d.length&&a.length<o+1;){let c=d.shift();c&&f(c)}return a[o]??null}function Re(e,t){let n=String(e??\"\");if(!n)return null;let o=n.toLowerCase(),r=C(t),l=new Set([\"SCRIPT\",\"STYLE\",\"TEMPLATE\",\"NOSCRIPT\",\"HEAD\",\"TITLE\",\"LINK\",\"META\",\"HTML\",\"BODY\"]),s=u=>{if(!u)return!1;let h=u.tagName?.toUpperCase()??\"\";return l.has(h)},i=u=>{try{if(s(u))return\"\";let h=u.innerText;if(typeof h==\"string\"&&h.trim())return h.trim()}catch{}try{let h=u.textContent;if(typeof h==\"string\")return h.trim()}catch{}return\"\"},a=u=>{let h=i(u);return!!h&&h.toLowerCase().includes(o)},d=window.__stagehandV3__,f=d&&typeof d.getClosedRoot==\"function\"?u=>{try{return d.getClosedRoot(u)??null}catch{return null}}:u=>null,c=new WeakSet,p=[],g=[],w=u=>{!u||c.has(u)||(c.add(u),p.push(u))},x=u=>{try{return(u instanceof Document?u:u?.ownerDocument??document).createTreeWalker(u,NodeFilter.SHOW_ELEMENT)}catch{return null}};for(w(document);p.length;){let u=p.shift();if(!u)continue;u instanceof Element&&a(u)&&g.push({element:u,tag:u.tagName??\"\",id:u.id??\"\",className:u.className??\"\",text:i(u)});let h=x(u);if(!h)continue;let E;for(;E=h.nextNode();){if(!(E instanceof Element))continue;a(E)&&g.push({element:E,tag:E.tagName??\"\",id:E.id??\"\",className:E.className??\"\",text:i(E)});let b=E.shadowRoot;b&&w(b);let D=f(E);D&&w(D)}}let y=[];for(let u of g){let h=u.element,E=!1;for(let b of g)if(u!==b)try{if(h.contains(b.element)){E=!0;break}}catch{}E||y.push(u)}return y[r]?.element??null}function Ne(e,t){let n=C(t);return k(e,n,{pierceShadow:!0})}function Ce(e){let t=String(e??\"\").trim();if(!t)return 0;let n=new WeakSet,o=r=>{if(!r||n.has(r))return 0;n.add(r);let l=0;try{let s=r;typeof s.querySelectorAll==\"function\"&&(l+=s.querySelectorAll(t).length)}catch{}try{let i=(r instanceof Document?r:r?.ownerDocument??document).createTreeWalker(r,NodeFilter.SHOW_ELEMENT),a;for(;a=i.nextNode();)a instanceof Element&&a.shadowRoot&&(l+=o(a.shadowRoot))}catch{}return l};try{return o(document)}catch{try{return document.querySelectorAll(t).length}catch{return 0}}}function Me(e){let t=String(e??\"\").trim();if(!t)return 0;let n=window.__stagehandV3__;if(!n||typeof n.getClosedRoot!=\"function\")try{return document.querySelectorAll(t).length}catch{return 0}let o=new WeakSet,r=[],l=a=>{!a||o.has(a)||(o.add(a),r.push(a))};l(document);let s=0,i=a=>{let d=a.shadowRoot;d&&l(d);try{let f=n.getClosedRoot(a);f&&l(f)}catch{}};for(;r.length;){let a=r.shift();if(a){try{let d=a;typeof d.querySelectorAll==\"function\"&&(s+=d.querySelectorAll(t).length)}catch{}try{let f=(a instanceof Document?a:a instanceof ShadowRoot?a.host?.ownerDocument??document:a.ownerDocument??document).createTreeWalker(a,NodeFilter.SHOW_ELEMENT),c;for(;c=f.nextNode();)c instanceof Element&&i(c)}catch{}}}return s}function Le(e){let t=String(e??\"\");if(!t)return{count:0,sample:[],error:null};let n=t.toLowerCase(),o=new Set([\"SCRIPT\",\"STYLE\",\"TEMPLATE\",\"NOSCRIPT\",\"HEAD\",\"TITLE\",\"LINK\",\"META\",\"HTML\",\"BODY\"]),r=m=>{if(!m)return!1;let u=m.tagName?.toUpperCase()??\"\";return o.has(u)},l=m=>{try{if(r(m))return\"\";let u=m.innerText;if(typeof u==\"string\"&&u.trim())return u.trim()}catch{}try{let u=m.textContent;if(typeof u==\"string\")return u.trim()}catch{}return\"\"},s=m=>{let u=l(m);return!!u&&u.toLowerCase().includes(n)},i=window.__stagehandV3__,a=i&&typeof i.getClosedRoot==\"function\"?m=>{try{return i.getClosedRoot(m)??null}catch{return null}}:m=>null,d=new WeakSet,f=[],c=m=>{!m||d.has(m)||(d.add(m),f.push(m))},p=m=>{try{return(m instanceof Document?m:m?.ownerDocument??document).createTreeWalker(m,NodeFilter.SHOW_ELEMENT)}catch{return null}},g=[];for(c(document);f.length;){let m=f.shift();if(!m)continue;m instanceof Element&&s(m)&&g.push({element:m,tag:m.tagName??\"\",id:m.id??\"\",className:m.className??\"\",text:l(m)});let u=p(m);if(!u)continue;let h;for(;h=u.nextNode();){if(!(h instanceof Element))continue;s(h)&&g.push({element:h,tag:h.tagName??\"\",id:h.id??\"\",className:h.className??\"\",text:l(h)});let E=h.shadowRoot;E&&c(E);let b=a(h);b&&c(b)}}let w=[];for(let m of g){let u=m.element,h=!1;for(let E of g)if(m!==E)try{if(u.contains(E.element)){h=!0;break}}catch{}h||w.push(m)}let x=w.length,y=w.slice(0,5).map(m=>({tag:m.tag,id:m.id,class:m.className,text:m.text}));return{count:x,sample:y,error:null}}function Pe(e){return $(e,{pierceShadow:!0})}var ke=e=>e.startsWith(\"xpath=\")||e.startsWith(\"/\"),De=e=>{try{let t=window.__stagehandV3__;if(t&&typeof t.getClosedRoot==\"function\")return t.getClosedRoot(e)??null}catch{}return null},Y=e=>e.shadowRoot?e.shadowRoot:De(e),He=(e,t,n)=>{try{let l=e.querySelector(t);if(l)return l}catch{}if(!n)return null;let o=new WeakSet,r=[e];for(;r.length>0;){let l=r.shift();if(!(!l||o.has(l))){o.add(l);try{let s=l.querySelector(t);if(s)return s}catch{}try{let i=(l instanceof Document?l:l.host?.ownerDocument??document).createTreeWalker(l,NodeFilter.SHOW_ELEMENT),a;for(;a=i.nextNode();){if(!(a instanceof Element))continue;let d=Y(a);d&&!o.has(d)&&r.push(d)}}catch{}}}return null},Ae=(e,t)=>I(e,{pierceShadow:t}),B=(e,t)=>ke(e)?Ae(e,t):He(document,e,t),G=(e,t)=>{if(t===\"detached\")return e===null;if(t===\"attached\")return e!==null;if(e===null)return!1;if(t===\"hidden\")try{let n=window.getComputedStyle(e),o=e.getBoundingClientRect();return n.display===\"none\"||n.visibility===\"hidden\"||n.opacity===\"0\"||o.width===0||o.height===0}catch{return!1}try{let n=window.getComputedStyle(e),o=e.getBoundingClientRect();return n.display!==\"none\"&&n.visibility!==\"hidden\"&&n.opacity!==\"0\"&&o.width>0&&o.height>0}catch{return!1}},We=(e,t)=>{let n=new WeakSet,o=l=>{let s=Y(l);if(s&&!n.has(s)){n.add(s);let i=new MutationObserver(e);i.observe(s,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[\"style\",\"class\",\"hidden\",\"disabled\"]}),t.push(i);for(let a of Array.from(s.children))o(a)}for(let i of Array.from(l.children))o(i)},r=document.documentElement||document.body;r&&o(r)};function _e(e,t,n,o){let r=String(e??\"\").trim(),l=String(t??\"visible\")||\"visible\",s=typeof n==\"number\"&&n>0?n:3e4,i=o!==!1;return new Promise((a,d)=>{let f=null,c=null,p=!1,g=()=>{f!==null&&(clearTimeout(f),f=null)},w=B(r,i);if(G(w,l)){p=!0,a(!0);return}let x=[],y=()=>{for(let E of x)E.disconnect();c&&(document.removeEventListener(\"DOMContentLoaded\",c),c=null)},m=()=>{if(p)return;let E=B(r,i);G(E,l)&&(p=!0,g(),y(),a(!0))};if(!(document.body||document.documentElement)){c=()=>{document.removeEventListener(\"DOMContentLoaded\",c),c=null,m(),h()},document.addEventListener(\"DOMContentLoaded\",c),f=setTimeout(()=>{p||(p=!0,g(),y(),d(new Error(`waitForSelector: Timeout ${s}ms exceeded waiting for \"${r}\" to be ${l}`)))},s);return}let h=()=>{let E=document.body||document.documentElement;if(!E)return;let b=new MutationObserver(m);b.observe(E,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[\"style\",\"class\",\"hidden\",\"disabled\"]}),x.push(b),i&&We(m,x)};h(),f=setTimeout(()=>{p||(p=!0,g(),y(),d(new Error(`waitForSelector: Timeout ${s}ms exceeded waiting for \"${r}\" to be ${l}`)))},s)})}return J(Oe);})();\n globalThis.__stagehandLocatorScripts = __stagehandLocatorScriptsFactory;\n}";
8
+ exports.locatorScriptBootstrap = 'if (!globalThis.__stagehandLocatorScripts) { var __stagehandLocatorScriptsFactory=(()=>{var M=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var Q=Object.prototype.hasOwnProperty;var Z=(e,t)=>{for(var n in t)M(e,n,{get:t[n],enumerable:!0})},j=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of U(t))!Q.call(e,r)&&r!==n&&M(e,r,{get:()=>t[r],enumerable:!(o=K(t,r))||o.enumerable});return e};var J=e=>j(M({},"__esModule",{value:!0}),e);var Oe={};Z(Oe,{assignFilePayloadsToInputElement:()=>te,countCssMatchesPierce:()=>Me,countCssMatchesPrimary:()=>Ce,countTextMatches:()=>Le,countXPathMatchesMainWorld:()=>Pe,dispatchDomClick:()=>ne,ensureFileInputElement:()=>ee,fillElementValue:()=>se,focusElement:()=>le,isElementChecked:()=>ce,isElementVisible:()=>ae,prepareElementForTyping:()=>v,readElementInnerHTML:()=>me,readElementInnerText:()=>fe,readElementInputValue:()=>ue,readElementTextContent:()=>de,resolveCssSelector:()=>ve,resolveCssSelectorPierce:()=>Te,resolveTextSelector:()=>Re,resolveXPathMainWorld:()=>Ne,scrollElementToPercent:()=>oe,selectElementOptions:()=>ie,waitForSelector:()=>_e});function ee(){try{return(this.tagName?.toLowerCase()??"")!=="input"?!1:String(this.type??"").toLowerCase()==="file"}catch{return!1}}function te(e){try{let t=this;if(!t||t.tagName?.toLowerCase()!=="input"||(t.type??"").toLowerCase()!=="file")return!1;let n=(()=>{try{return new DataTransfer}catch{return null}})();if(!n)return!1;let o=Array.isArray(e)?e:[];for(let r of o){if(!r)continue;let l=r.name||"upload.bin",s=r.mimeType||"application/octet-stream",i=typeof r.lastModified=="number"?r.lastModified:Date.now(),a=window.atob(r.base64??""),d=new Uint8Array(a.length);for(let p=0;p<a.length;p+=1)d[p]=a.charCodeAt(p);let f=new Blob([d],{type:s}),c=new File([f],l,{type:s,lastModified:i});n.items.add(c)}return t.files=n.files,t.dispatchEvent(new Event("input",{bubbles:!0})),t.dispatchEvent(new Event("change",{bubbles:!0})),!0}catch{return!1}}function ne(e){let t=e??{};try{let n=new MouseEvent("click",{bubbles:!!t.bubbles,cancelable:!!t.cancelable,composed:!!t.composed,detail:typeof t.detail=="number"?t.detail:1,view:this?.ownerDocument?.defaultView??window});this.dispatchEvent(n)}catch{try{this.click()}catch{}}}function oe(e){let t=n=>{if(typeof n=="number"&&Number.isFinite(n))return n;let o=String(n??"").trim();if(!o)return 0;let r=parseFloat(o.replace("%",""));return Number.isNaN(r)||!Number.isFinite(r)?0:r};try{let n=Math.max(0,Math.min(t(e),100)),o=this,r=o.tagName?.toLowerCase()??"";if(r==="html"||r==="body"){let c=(o.ownerDocument?.scrollingElement||o.ownerDocument?.documentElement||o.ownerDocument?.body||document.scrollingElement||document.documentElement||document.body)?.scrollHeight??document.body.scrollHeight??0,p=o.ownerDocument?.defaultView?.innerHeight??window.innerHeight,w=Math.max(0,c-p)*(n/100);return o.ownerDocument?.defaultView?.scrollTo({top:w,left:o.ownerDocument?.defaultView?.scrollX??window.scrollX??0,behavior:"smooth"}),!0}let s=o.scrollHeight??0,i=o.clientHeight??0,d=Math.max(0,s-i)*(n/100);return o.scrollTo({top:d,left:o.scrollLeft??0,behavior:"smooth"}),!0}catch{return!1}}var H=new Set(["color","date","datetime-local","month","range","time","week"]),re=new Set(["","email","number","password","search","tel","text","url"]);function v(){try{let e=this;if(!e.isConnected)return!1;let t=e.ownerDocument||document,n=t.defaultView||window;try{typeof e.focus=="function"&&e.focus()}catch{}if(e instanceof n.HTMLInputElement||e instanceof n.HTMLTextAreaElement){try{if(typeof e.select=="function")return e.select(),!0}catch{}try{let o=(e.value??"").length;if(typeof e.setSelectionRange=="function")return e.setSelectionRange(0,o),!0}catch{}return!0}if(e.isContentEditable){let o=t.getSelection?.(),r=t.createRange?.();if(o&&r)try{r.selectNodeContents(e),o.removeAllRanges(),o.addRange(r)}catch{}return!0}return!1}catch{return!1}}function se(e){let t=this;if(!t.isConnected)return{status:"error",reason:"notconnected"};let o=(t.ownerDocument||document).defaultView||window,r=e??"";try{let l=s=>{let i;if(typeof o.InputEvent=="function")try{i=new o.InputEvent("input",{bubbles:!0,composed:!0,data:s,inputType:"insertText"})}catch{i=new o.Event("input",{bubbles:!0,composed:!0})}else i=new o.Event("input",{bubbles:!0,composed:!0});t.dispatchEvent(i);let a=new o.Event("change",{bubbles:!0});t.dispatchEvent(a)};if(t instanceof o.HTMLInputElement){let s=(t.type||"").toLowerCase();if(!re.has(s)&&!H.has(s))return{status:"error",reason:`unsupported-input-type:${s}`};let i=e;if(s==="number"){let a=e.trim();if(a!==""&&Number.isNaN(Number(a)))return{status:"error",reason:"invalid-number-value"};i=a}if(r=i,H.has(s)){let a=e.trim();r=a,v.call(t);let d=o.HTMLInputElement.prototype,c=Object.getOwnPropertyDescriptor(d,"value")?.set;return typeof c=="function"?c.call(t,a):t.value=a,t._valueTracker?.setValue?.(a),t.value!==a?{status:"error",reason:"malformed-value"}:(l(a),{status:"done"})}return v.call(t),{status:"needsinput",value:i}}return t instanceof o.HTMLTextAreaElement?(v.call(t),r=e,{status:"needsinput",value:e}):t instanceof o.HTMLSelectElement?{status:"error",reason:"unsupported-element"}:t.isContentEditable?(v.call(t),r=e,{status:"needsinput",value:e}):{status:"error",reason:"unsupported-element"}}catch(l){let s="exception";if(l&&typeof l=="object"){let i=l.message;typeof i=="string"&&i.trim().length>0&&(s=`exception:${i}`)}return{status:"needsinput",value:r,reason:s}}}function le(){try{typeof this.focus=="function"&&this.focus()}catch{}}function ie(e){try{if(!(this instanceof HTMLSelectElement))return[];let t=Array.isArray(e)?e:[e],n=new Set(t.map(s=>String(s??"").trim())),o=s=>{let i=(s.label||s.textContent||"").trim(),a=String(s.value??"").trim();return n.has(i)||n.has(a)};if(this.multiple)for(let s of Array.from(this.options))s.selected=o(s);else{let s=!1;for(let i of Array.from(this.options))!s&&o(i)?(i.selected=!0,this.value=i.value,s=!0):i.selected=!1}let r=new Event("input",{bubbles:!0}),l=new Event("change",{bubbles:!0});return this.dispatchEvent(r),this.dispatchEvent(l),Array.from(this.selectedOptions).map(s=>s.value)}catch{return[]}}function ae(){try{let e=this;if(!e.isConnected)return!1;let t=e.ownerDocument?.defaultView?.getComputedStyle(e)??window.getComputedStyle(e);if(!t||t.display==="none"||t.visibility==="hidden")return!1;let n=parseFloat(t.opacity??"1");if(!Number.isFinite(n)||n===0)return!1;let o=e.getBoundingClientRect();return!(!o||Math.max(o.width,o.height)===0||e.getClientRects().length===0)}catch{return!1}}function ce(){try{let e=this;if((e.tagName||"").toLowerCase()==="input"){let o=e.type?.toLowerCase()??"";if(o==="checkbox"||o==="radio")return!!e.checked}let n=e.getAttribute?.("aria-checked");return n!=null?n==="true":!1}catch{return!1}}function ue(){try{let e=this,t=(e.tagName||"").toLowerCase();return t==="input"||t==="textarea"||t==="select"?String(e.value??""):e.isContentEditable?String(e.textContent??""):""}catch{return""}}function de(){try{return String(this.textContent??"")}catch{return""}}function me(){try{return String(this.innerHTML??"")}catch{return""}}function fe(){try{let e=this,t=e.innerText;if(typeof t=="string"&&t.length>0)return t;let n=e.textContent;return typeof n=="string"?n:""}catch{return""}}function O(e){let t=String(e||"").trim().replace(/^xpath=/i,"");if(!t)return[];let n=[],o=0;for(;o<t.length;){let r="child";t.startsWith("//",o)?(r="desc",o+=2):t[o]==="/"&&(r="child",o+=1);let l=o,s=0,i=null;for(;o<t.length;){let c=t[o];if(i)c===i&&(i=null);else if(c==="\'"||c===\'"\')i=c;else if(c==="[")s++;else if(c==="]")s--;else if(c==="/"&&s===0)break;o+=1}let a=t.slice(l,o).trim();if(!a)continue;let{tag:d,predicates:f}=pe(a);n.push({axis:r,tag:d,predicates:f})}return n}function he(e){let t=[],n=0;for(;n<e.length;){if(e[n]!=="["){n++;continue}n++;let o=n,r=null;for(;n<e.length;){let l=e[n];if(r)l===r&&(r=null);else if(l==="\'"||l===\'"\')r=l;else if(l==="]")break;n++}t.push(e.slice(o,n).trim()),n++}return t}function pe(e){let t=e.indexOf("[");if(t===-1)return{tag:e===""?"*":e.toLowerCase(),predicates:[]};let n=e.slice(0,t).trim(),o=n===""?"*":n.toLowerCase(),r=e.slice(t),l=[];for(let s of he(r)){let i=T(s);i&&l.push(i)}return{tag:o,predicates:l}}function T(e){let t=e.trim();if(!t)return null;let n=A(t,"or");if(n.length>1){let l=n.map(s=>T(s)).filter(Boolean);return l.length!==n.length?null:{type:"or",predicates:l}}let o=A(t,"and");if(o.length>1){let l=o.map(s=>T(s)).filter(Boolean);return l.length!==o.length?null:{type:"and",predicates:l}}let r=we(t,"not");if(r!=null){let l=T(r);return l?{type:"not",predicate:l}:null}return ge(t)}function ge(e){let t=/^(?:\'([^\']*)\'|"([^"]*)")$/,n="[a-zA-Z_][\\\\w.-]*",o=`(?:\'([^\']*)\'|"([^"]*)")`;if(/^\\d+$/.test(e))return{type:"index",index:Math.max(1,Number(e))};let r=e.match(new RegExp(`^normalize-space\\\\(\\\\s*@(${n})\\\\s*\\\\)\\\\s*=\\\\s*${o}$`));if(r)return{type:"attrEquals",name:r[1],value:r[2]??r[3]??"",normalize:!0};let l=e.match(new RegExp(`^normalize-space\\\\(\\\\s*(?:text\\\\(\\\\)|\\\\.)\\\\s*\\\\)\\\\s*=\\\\s*${o}$`));if(l)return{type:"textEquals",value:l[1]??l[2]??"",normalize:!0};let s=e.match(new RegExp(`^@(${n})\\\\s*=\\\\s*${o}$`));if(s)return{type:"attrEquals",name:s[1],value:s[2]??s[3]??""};let i=e.match(new RegExp(`^@(${n})$`));if(i)return{type:"attrExists",name:i[1]};let a=e.match(new RegExp(`^contains\\\\(\\\\s*@(${n})\\\\s*,\\\\s*${o}\\\\s*\\\\)$`));if(a)return{type:"attrContains",name:a[1],value:a[2]??a[3]??""};let d=e.match(new RegExp(`^starts-with\\\\(\\\\s*@(${n})\\\\s*,\\\\s*${o}\\\\s*\\\\)$`));if(d)return{type:"attrStartsWith",name:d[1],value:d[2]??d[3]??""};let f=e.match(new RegExp(`^(?:text\\\\(\\\\)|\\\\.)\\\\s*=\\\\s*${o}$`));if(f)return{type:"textEquals",value:f[1]??f[2]??""};let c=e.match(new RegExp(`^contains\\\\(\\\\s*(?:text\\\\(\\\\)|\\\\.)\\\\s*,\\\\s*${o}\\\\s*\\\\)$`));return c?{type:"textContains",value:c[1]??c[2]??""}:(t.test(e),null)}function A(e,t){let n=[],o=0,r=0,l=null,s=0;for(;s<e.length;){let i=e[s];if(l){i===l&&(l=null),s+=1;continue}if(i==="\'"||i===\'"\'){l=i,s+=1;continue}if(i==="("){r+=1,s+=1;continue}if(i===")"){r=Math.max(0,r-1),s+=1;continue}if(r===0&&Ee(e,s,t)){n.push(e.slice(o,s).trim()),s+=t.length,o=s;continue}s+=1}return n.push(e.slice(o).trim()),n.filter(i=>i.length>0)}function Ee(e,t,n){if(!e.startsWith(n,t))return!1;let o=t>0?e[t-1]:" ";if(o==="@")return!1;let r=t+n.length<e.length?e[t+n.length]:" ";return W(o)&&W(r)}function W(e){return!/[a-zA-Z0-9_.-]/.test(e)}function we(e,t){let n=`${t}(`;if(!e.startsWith(n)||!e.endsWith(")"))return null;let o=e.slice(n.length,-1);return ye(o)?o:null}function ye(e){let t=0,n=null;for(let o=0;o<e.length;o+=1){let r=e[o];if(n){r===n&&(n=null);continue}if(r==="\'"||r===\'"\'){n=r;continue}if(r==="("?t+=1:r===")"&&(t-=1),t<0)return!1}return t===0}var be=e=>e.replace(/\\s+/g," ").trim();function _(e){return String(e.textContent??"")}function S(e,t){return t?be(e):e}function R(e,t){switch(t.type){case"and":return t.predicates.every(n=>R(e,n));case"or":return t.predicates.some(n=>R(e,n));case"not":return!R(e,t.predicate);case"attrExists":return e.getAttribute(t.name)!==null;case"attrEquals":{let n=e.getAttribute(t.name);return n===null?!1:S(n,t.normalize)===S(t.value,t.normalize)}case"attrContains":{let n=e.getAttribute(t.name);return n===null?!1:S(n,t.normalize).includes(S(t.value,t.normalize))}case"attrStartsWith":{let n=e.getAttribute(t.name);return n===null?!1:S(n,t.normalize).startsWith(S(t.value,t.normalize))}case"textEquals":return S(_(e),t.normalize)===S(t.value,t.normalize);case"textContains":return S(_(e),t.normalize).includes(S(t.value,t.normalize));case"index":return!0;default:return!0}}function q(e,t){let n=e;for(let o of t){if(!n.length)return[];if(o.type==="index"){let r=o.index-1;n=r>=0&&r<n.length?[n[r]]:[];continue}n=n.filter(r=>R(r,o))}return n}var P=e=>{let t=String(e??"").trim();return t?t.replace(/^xpath=/i,"").trim():""};function I(e,t){return k(e,0,t)}function k(e,t,n){if(!Number.isFinite(t)||t<0)return null;let o=P(e);if(!o)return null;let r=Math.floor(t),l=n?.pierceShadow!==!1,s=l?z():null;if(!l)return X(o,r).value;if(!s?.hasShadow){let a=X(o,r);return a.error?N(o,s?.getClosedRoot)[r]??null:a.value}return N(o,s.getClosedRoot)[r]??null}function $(e,t){let n=P(e);if(!n)return 0;let o=t?.pierceShadow!==!1,r=o?z():null;if(!o)return F(n).count;if(!r?.hasShadow){let l=F(n);return l.error?N(n,r?.getClosedRoot).length:l.count}return N(n,r.getClosedRoot).length}function N(e,t){let n=P(e);if(!n)return[];let o=O(n);if(!o.length)return[];let r=t??null,l=[document];for(let s of o){let i=[],a=new Set;for(let d of l){if(!d)continue;let f=s.axis==="child"?L(d,r):Se(d,r);if(!f.length)continue;let c=f.filter(g=>xe(g,s)),p=q(c,s.predicates);for(let g of p)a.has(g)||(a.add(g),i.push(g))}if(!i.length)return[];l=i}return l}function xe(e,t){return t.tag==="*"?!0:e.localName===t.tag}function z(){let e=window.__stagehandV3__,t=e&&typeof e.getClosedRoot=="function"?o=>{try{return e.getClosedRoot(o)??null}catch{return null}}:null,n=!1;try{if(e&&typeof e.stats=="function"){let o=e.stats();n=(o?.open??0)>0||(o?.closed??0)>0}}catch{}if(!n)try{let o=document.createTreeWalker(document,NodeFilter.SHOW_ELEMENT);for(;o.nextNode();)if(o.currentNode.shadowRoot){n=!0;break}}catch{}return{getClosedRoot:t,hasShadow:n}}function L(e,t){let n=[];if(!e)return n;if(e instanceof Document)return e.documentElement&&n.push(e.documentElement),n;if(e instanceof ShadowRoot||e instanceof DocumentFragment)return n.push(...Array.from(e.children??[])),n;if(e instanceof Element){n.push(...Array.from(e.children??[]));let o=e.shadowRoot;if(o&&n.push(...Array.from(o.children??[])),t){let r=t(e);r&&n.push(...Array.from(r.children??[]))}return n}return n}function Se(e,t){let n=[],o=new Set,r=[...L(e,t)].reverse();for(;r.length;){let l=r.pop();if(!l||o.has(l))continue;o.add(l),n.push(l);let s=L(l,t);for(let i=s.length-1;i>=0;i-=1)r.push(s[i])}return n}function X(e,t){try{return{value:document.evaluate(e,document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotItem(t),error:!1}}catch{return{value:null,error:!0}}}function F(e){try{return{count:document.evaluate(e,document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotLength,error:!1}}catch{return{count:0,error:!0}}}var C=e=>{let t=Number(e??0);return!Number.isFinite(t)||t<0?0:Math.floor(t)},V=(e,t)=>{if(!e)return[];let n=new WeakSet,o=new Set,r=[],l=[document],s=i=>{if(!(!i||n.has(i)||r.length>=t)){n.add(i);try{let a=i.querySelectorAll(e);for(let d of a)if(!o.has(d)&&(o.add(d),r.push(d),r.length>=t))return}catch{}try{let d=(i instanceof Document?i:i.host?.ownerDocument??document).createTreeWalker(i,NodeFilter.SHOW_ELEMENT),f;for(;f=d.nextNode();){if(!(f instanceof Element))continue;let c=f.shadowRoot;c&&l.push(c)}}catch{}}};for(;l.length&&r.length<t;){let i=l.shift();i&&s(i)}return r};function ve(e,t){let n=String(e??"").trim();if(!n)return null;let o=C(t);return V(n,o+1)[o]??null}function Te(e,t){let n=String(e??"").trim();if(!n)return null;let o=C(t),r=window.__stagehandV3__;if(!r||typeof r.getClosedRoot!="function")return V(n,o+1)[o]??null;let l=c=>{try{return r.getClosedRoot(c)??null}catch{return null}},s=new WeakSet,i=new Set,a=[],d=[document],f=c=>{if(!(!c||s.has(c)||a.length>=o+1)){s.add(c);try{let p=c.querySelectorAll(n);for(let g of p)if(!i.has(g)&&(i.add(g),a.push(g),a.length>=o+1))return}catch{}try{let g=(c instanceof Document?c:c.host?.ownerDocument??document).createTreeWalker(c,NodeFilter.SHOW_ELEMENT),w;for(;w=g.nextNode();){if(!(w instanceof Element))continue;let x=w.shadowRoot;x&&d.push(x);let y=l(w);y&&d.push(y)}}catch{}}};for(;d.length&&a.length<o+1;){let c=d.shift();c&&f(c)}return a[o]??null}function Re(e,t){let n=String(e??"");if(!n)return null;let o=n.toLowerCase(),r=C(t),l=new Set(["SCRIPT","STYLE","TEMPLATE","NOSCRIPT","HEAD","TITLE","LINK","META","HTML","BODY"]),s=u=>{if(!u)return!1;let h=u.tagName?.toUpperCase()??"";return l.has(h)},i=u=>{try{if(s(u))return"";let h=u.innerText;if(typeof h=="string"&&h.trim())return h.trim()}catch{}try{let h=u.textContent;if(typeof h=="string")return h.trim()}catch{}return""},a=u=>{let h=i(u);return!!h&&h.toLowerCase().includes(o)},d=window.__stagehandV3__,f=d&&typeof d.getClosedRoot=="function"?u=>{try{return d.getClosedRoot(u)??null}catch{return null}}:u=>null,c=new WeakSet,p=[],g=[],w=u=>{!u||c.has(u)||(c.add(u),p.push(u))},x=u=>{try{return(u instanceof Document?u:u?.ownerDocument??document).createTreeWalker(u,NodeFilter.SHOW_ELEMENT)}catch{return null}};for(w(document);p.length;){let u=p.shift();if(!u)continue;u instanceof Element&&a(u)&&g.push({element:u,tag:u.tagName??"",id:u.id??"",className:u.className??"",text:i(u)});let h=x(u);if(!h)continue;let E;for(;E=h.nextNode();){if(!(E instanceof Element))continue;a(E)&&g.push({element:E,tag:E.tagName??"",id:E.id??"",className:E.className??"",text:i(E)});let b=E.shadowRoot;b&&w(b);let D=f(E);D&&w(D)}}let y=[];for(let u of g){let h=u.element,E=!1;for(let b of g)if(u!==b)try{if(h.contains(b.element)){E=!0;break}}catch{}E||y.push(u)}return y[r]?.element??null}function Ne(e,t){let n=C(t);return k(e,n,{pierceShadow:!0})}function Ce(e){let t=String(e??"").trim();if(!t)return 0;let n=new WeakSet,o=r=>{if(!r||n.has(r))return 0;n.add(r);let l=0;try{let s=r;typeof s.querySelectorAll=="function"&&(l+=s.querySelectorAll(t).length)}catch{}try{let i=(r instanceof Document?r:r?.ownerDocument??document).createTreeWalker(r,NodeFilter.SHOW_ELEMENT),a;for(;a=i.nextNode();)a instanceof Element&&a.shadowRoot&&(l+=o(a.shadowRoot))}catch{}return l};try{return o(document)}catch{try{return document.querySelectorAll(t).length}catch{return 0}}}function Me(e){let t=String(e??"").trim();if(!t)return 0;let n=window.__stagehandV3__;if(!n||typeof n.getClosedRoot!="function")try{return document.querySelectorAll(t).length}catch{return 0}let o=new WeakSet,r=[],l=a=>{!a||o.has(a)||(o.add(a),r.push(a))};l(document);let s=0,i=a=>{let d=a.shadowRoot;d&&l(d);try{let f=n.getClosedRoot(a);f&&l(f)}catch{}};for(;r.length;){let a=r.shift();if(a){try{let d=a;typeof d.querySelectorAll=="function"&&(s+=d.querySelectorAll(t).length)}catch{}try{let f=(a instanceof Document?a:a instanceof ShadowRoot?a.host?.ownerDocument??document:a.ownerDocument??document).createTreeWalker(a,NodeFilter.SHOW_ELEMENT),c;for(;c=f.nextNode();)c instanceof Element&&i(c)}catch{}}}return s}function Le(e){let t=String(e??"");if(!t)return{count:0,sample:[],error:null};let n=t.toLowerCase(),o=new Set(["SCRIPT","STYLE","TEMPLATE","NOSCRIPT","HEAD","TITLE","LINK","META","HTML","BODY"]),r=m=>{if(!m)return!1;let u=m.tagName?.toUpperCase()??"";return o.has(u)},l=m=>{try{if(r(m))return"";let u=m.innerText;if(typeof u=="string"&&u.trim())return u.trim()}catch{}try{let u=m.textContent;if(typeof u=="string")return u.trim()}catch{}return""},s=m=>{let u=l(m);return!!u&&u.toLowerCase().includes(n)},i=window.__stagehandV3__,a=i&&typeof i.getClosedRoot=="function"?m=>{try{return i.getClosedRoot(m)??null}catch{return null}}:m=>null,d=new WeakSet,f=[],c=m=>{!m||d.has(m)||(d.add(m),f.push(m))},p=m=>{try{return(m instanceof Document?m:m?.ownerDocument??document).createTreeWalker(m,NodeFilter.SHOW_ELEMENT)}catch{return null}},g=[];for(c(document);f.length;){let m=f.shift();if(!m)continue;m instanceof Element&&s(m)&&g.push({element:m,tag:m.tagName??"",id:m.id??"",className:m.className??"",text:l(m)});let u=p(m);if(!u)continue;let h;for(;h=u.nextNode();){if(!(h instanceof Element))continue;s(h)&&g.push({element:h,tag:h.tagName??"",id:h.id??"",className:h.className??"",text:l(h)});let E=h.shadowRoot;E&&c(E);let b=a(h);b&&c(b)}}let w=[];for(let m of g){let u=m.element,h=!1;for(let E of g)if(m!==E)try{if(u.contains(E.element)){h=!0;break}}catch{}h||w.push(m)}let x=w.length,y=w.slice(0,5).map(m=>({tag:m.tag,id:m.id,class:m.className,text:m.text}));return{count:x,sample:y,error:null}}function Pe(e){return $(e,{pierceShadow:!0})}var ke=e=>e.startsWith("xpath=")||e.startsWith("/"),De=e=>{try{let t=window.__stagehandV3__;if(t&&typeof t.getClosedRoot=="function")return t.getClosedRoot(e)??null}catch{}return null},Y=e=>e.shadowRoot?e.shadowRoot:De(e),He=(e,t,n)=>{try{let l=e.querySelector(t);if(l)return l}catch{}if(!n)return null;let o=new WeakSet,r=[e];for(;r.length>0;){let l=r.shift();if(!(!l||o.has(l))){o.add(l);try{let s=l.querySelector(t);if(s)return s}catch{}try{let i=(l instanceof Document?l:l.host?.ownerDocument??document).createTreeWalker(l,NodeFilter.SHOW_ELEMENT),a;for(;a=i.nextNode();){if(!(a instanceof Element))continue;let d=Y(a);d&&!o.has(d)&&r.push(d)}}catch{}}}return null},Ae=(e,t)=>I(e,{pierceShadow:t}),B=(e,t)=>ke(e)?Ae(e,t):He(document,e,t),G=(e,t)=>{if(t==="detached")return e===null;if(t==="attached")return e!==null;if(e===null)return!1;if(t==="hidden")try{let n=window.getComputedStyle(e),o=e.getBoundingClientRect();return n.display==="none"||n.visibility==="hidden"||n.opacity==="0"||o.width===0||o.height===0}catch{return!1}try{let n=window.getComputedStyle(e),o=e.getBoundingClientRect();return n.display!=="none"&&n.visibility!=="hidden"&&n.opacity!=="0"&&o.width>0&&o.height>0}catch{return!1}},We=(e,t)=>{let n=new WeakSet,o=l=>{let s=Y(l);if(s&&!n.has(s)){n.add(s);let i=new MutationObserver(e);i.observe(s,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style","class","hidden","disabled"]}),t.push(i);for(let a of Array.from(s.children))o(a)}for(let i of Array.from(l.children))o(i)},r=document.documentElement||document.body;r&&o(r)};function _e(e,t,n,o){let r=String(e??"").trim(),l=String(t??"visible")||"visible",s=typeof n=="number"&&n>0?n:3e4,i=o!==!1;return new Promise((a,d)=>{let f=null,c=null,p=!1,g=()=>{f!==null&&(clearTimeout(f),f=null)},w=B(r,i);if(G(w,l)){p=!0,a(!0);return}let x=[],y=()=>{for(let E of x)E.disconnect();c&&(document.removeEventListener("DOMContentLoaded",c),c=null)},m=()=>{if(p)return;let E=B(r,i);G(E,l)&&(p=!0,g(),y(),a(!0))};if(!(document.body||document.documentElement)){c=()=>{document.removeEventListener("DOMContentLoaded",c),c=null,m(),h()},document.addEventListener("DOMContentLoaded",c),f=setTimeout(()=>{p||(p=!0,g(),y(),d(new Error(`waitForSelector: Timeout ${s}ms exceeded waiting for "${r}" to be ${l}`)))},s);return}let h=()=>{let E=document.body||document.documentElement;if(!E)return;let b=new MutationObserver(m);b.observe(E,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style","class","hidden","disabled"]}),x.push(b),i&&We(m,x)};h(),f=setTimeout(()=>{p||(p=!0,g(),y(),d(new Error(`waitForSelector: Timeout ${s}ms exceeded waiting for "${r}" to be ${l}`)))},s)})}return J(Oe);})();\n globalThis.__stagehandLocatorScripts = __stagehandLocatorScriptsFactory;\n}';
9
9
  exports.locatorScriptSources = {
10
- "assignFilePayloadsToInputElement": "function ce(e){try{let t=this;if(!t||t.tagName?.toLowerCase()!==\"input\"||(t.type??\"\").toLowerCase()!==\"file\")return!1;let n=(()=>{try{return new DataTransfer}catch{return null}})();if(!n)return!1;let o=Array.isArray(e)?e:[];for(let r of o){if(!r)continue;let l=r.name||\"upload.bin\",s=r.mimeType||\"application/octet-stream\",i=typeof r.lastModified==\"number\"?r.lastModified:Date.now(),a=window.atob(r.base64??\"\"),d=new Uint8Array(a.length);for(let p=0;p<a.length;p+=1)d[p]=a.charCodeAt(p);let f=new Blob([d],{type:s}),c=new File([f],l,{type:s,lastModified:i});n.items.add(c)}return t.files=n.files,t.dispatchEvent(new Event(\"input\",{bubbles:!0})),t.dispatchEvent(new Event(\"change\",{bubbles:!0})),!0}catch{return!1}}",
11
- "countCssMatchesPierce": "function He(e){let t=String(e??\"\").trim();if(!t)return 0;let n=window.__stagehandV3__;if(!n||typeof n.getClosedRoot!=\"function\")try{return document.querySelectorAll(t).length}catch{return 0}let o=new WeakSet,r=[],l=a=>{!a||o.has(a)||(o.add(a),r.push(a))};l(document);let s=0,i=a=>{let d=a.shadowRoot;d&&l(d);try{let f=n.getClosedRoot(a);f&&l(f)}catch{}};for(;r.length;){let a=r.shift();if(a){try{let d=a;typeof d.querySelectorAll==\"function\"&&(s+=d.querySelectorAll(t).length)}catch{}try{let f=(a instanceof Document?a:a instanceof ShadowRoot?a.host?.ownerDocument??document:a.ownerDocument??document).createTreeWalker(a,NodeFilter.SHOW_ELEMENT),c;for(;c=f.nextNode();)c instanceof Element&&i(c)}catch{}}}return s}",
12
- "countCssMatchesPrimary": "function De(e){let t=String(e??\"\").trim();if(!t)return 0;let n=new WeakSet,o=r=>{if(!r||n.has(r))return 0;n.add(r);let l=0;try{let s=r;typeof s.querySelectorAll==\"function\"&&(l+=s.querySelectorAll(t).length)}catch{}try{let i=(r instanceof Document?r:r?.ownerDocument??document).createTreeWalker(r,NodeFilter.SHOW_ELEMENT),a;for(;a=i.nextNode();)a instanceof Element&&a.shadowRoot&&(l+=o(a.shadowRoot))}catch{}return l};try{return o(document)}catch{try{return document.querySelectorAll(t).length}catch{return 0}}}",
13
- "countTextMatches": "function Ae(e){let t=String(e??\"\");if(!t)return{count:0,sample:[],error:null};let n=t.toLowerCase(),o=new Set([\"SCRIPT\",\"STYLE\",\"TEMPLATE\",\"NOSCRIPT\",\"HEAD\",\"TITLE\",\"LINK\",\"META\",\"HTML\",\"BODY\"]),r=m=>{if(!m)return!1;let u=m.tagName?.toUpperCase()??\"\";return o.has(u)},l=m=>{try{if(r(m))return\"\";let u=m.innerText;if(typeof u==\"string\"&&u.trim())return u.trim()}catch{}try{let u=m.textContent;if(typeof u==\"string\")return u.trim()}catch{}return\"\"},s=m=>{let u=l(m);return!!u&&u.toLowerCase().includes(n)},i=window.__stagehandV3__,a=i&&typeof i.getClosedRoot==\"function\"?m=>{try{return i.getClosedRoot(m)??null}catch{return null}}:m=>null,d=new WeakSet,f=[],c=m=>{!m||d.has(m)||(d.add(m),f.push(m))},p=m=>{try{return(m instanceof Document?m:m?.ownerDocument??document).createTreeWalker(m,NodeFilter.SHOW_ELEMENT)}catch{return null}},g=[];for(c(document);f.length;){let m=f.shift();if(!m)continue;m instanceof Element&&s(m)&&g.push({element:m,tag:m.tagName??\"\",id:m.id??\"\",className:m.className??\"\",text:l(m)});let u=p(m);if(!u)continue;let h;for(;h=u.nextNode();){if(!(h instanceof Element))continue;s(h)&&g.push({element:h,tag:h.tagName??\"\",id:h.id??\"\",className:h.className??\"\",text:l(h)});let E=h.shadowRoot;E&&c(E);let b=a(h);b&&c(b)}}let w=[];for(let m of g){let u=m.element,h=!1;for(let E of g)if(m!==E)try{if(u.contains(E.element)){h=!0;break}}catch{}h||w.push(m)}let x=w.length,y=w.slice(0,5).map(m=>({tag:m.tag,id:m.id,class:m.className,text:m.text}));return{count:x,sample:y,error:null}}",
14
- "countXPathMatchesMainWorld": "function We(e){return I(e,{pierceShadow:!0})}",
15
- "dispatchDomClick": "function ue(e){let t=e??{};try{let n=new MouseEvent(\"click\",{bubbles:!!t.bubbles,cancelable:!!t.cancelable,composed:!!t.composed,detail:typeof t.detail==\"number\"?t.detail:1,view:this?.ownerDocument?.defaultView??window});this.dispatchEvent(n)}catch{try{this.click()}catch{}}}",
16
- "ensureFileInputElement": "function ae(){try{return(this.tagName?.toLowerCase()??\"\")!==\"input\"?!1:String(this.type??\"\").toLowerCase()===\"file\"}catch{return!1}}",
17
- "fillElementValue": "function me(e){let t=this;if(!t.isConnected)return{status:\"error\",reason:\"notconnected\"};let o=(t.ownerDocument||document).defaultView||window,r=e??\"\";try{let l=s=>{let i;if(typeof o.InputEvent==\"function\")try{i=new o.InputEvent(\"input\",{bubbles:!0,composed:!0,data:s,inputType:\"insertText\"})}catch{i=new o.Event(\"input\",{bubbles:!0,composed:!0})}else i=new o.Event(\"input\",{bubbles:!0,composed:!0});t.dispatchEvent(i);let a=new o.Event(\"change\",{bubbles:!0});t.dispatchEvent(a)};if(t instanceof o.HTMLInputElement){let s=(t.type||\"\").toLowerCase();if(!Y.has(s)&&!D.has(s))return{status:\"error\",reason:`unsupported-input-type:${s}`};let i=e;if(s===\"number\"){let a=e.trim();if(a!==\"\"&&Number.isNaN(Number(a)))return{status:\"error\",reason:\"invalid-number-value\"};i=a}if(r=i,D.has(s)){let a=e.trim();r=a,v.call(t);let d=o.HTMLInputElement.prototype,c=Object.getOwnPropertyDescriptor(d,\"value\")?.set;return typeof c==\"function\"?c.call(t,a):t.value=a,t._valueTracker?.setValue?.(a),t.value!==a?{status:\"error\",reason:\"malformed-value\"}:(l(a),{status:\"done\"})}return v.call(t),{status:\"needsinput\",value:i}}return t instanceof o.HTMLTextAreaElement?(v.call(t),r=e,{status:\"needsinput\",value:e}):t instanceof o.HTMLSelectElement?{status:\"error\",reason:\"unsupported-element\"}:t.isContentEditable?(v.call(t),r=e,{status:\"needsinput\",value:e}):{status:\"error\",reason:\"unsupported-element\"}}catch(l){let s=\"exception\";if(l&&typeof l==\"object\"){let i=l.message;typeof i==\"string\"&&i.trim().length>0&&(s=`exception:${i}`)}return{status:\"needsinput\",value:r,reason:s}}}",
18
- "focusElement": "function fe(){try{typeof this.focus==\"function\"&&this.focus()}catch{}}",
19
- "isElementChecked": "function ge(){try{let e=this;if((e.tagName||\"\").toLowerCase()===\"input\"){let o=e.type?.toLowerCase()??\"\";if(o===\"checkbox\"||o===\"radio\")return!!e.checked}let n=e.getAttribute?.(\"aria-checked\");return n!=null?n===\"true\":!1}catch{return!1}}",
20
- "isElementVisible": "function pe(){try{let e=this;if(!e.isConnected)return!1;let t=e.ownerDocument?.defaultView?.getComputedStyle(e)??window.getComputedStyle(e);if(!t||t.display===\"none\"||t.visibility===\"hidden\")return!1;let n=parseFloat(t.opacity??\"1\");if(!Number.isFinite(n)||n===0)return!1;let o=e.getBoundingClientRect();return!(!o||Math.max(o.width,o.height)===0||e.getClientRects().length===0)}catch{return!1}}",
21
- "prepareElementForTyping": "function v(){try{let e=this;if(!e.isConnected)return!1;let t=e.ownerDocument||document,n=t.defaultView||window;try{typeof e.focus==\"function\"&&e.focus()}catch{}if(e instanceof n.HTMLInputElement||e instanceof n.HTMLTextAreaElement){try{if(typeof e.select==\"function\")return e.select(),!0}catch{}try{let o=(e.value??\"\").length;if(typeof e.setSelectionRange==\"function\")return e.setSelectionRange(0,o),!0}catch{}return!0}if(e.isContentEditable){let o=t.getSelection?.(),r=t.createRange?.();if(o&&r)try{r.selectNodeContents(e),o.removeAllRanges(),o.addRange(r)}catch{}return!0}return!1}catch{return!1}}",
22
- "readElementInnerHTML": "function ye(){try{return String(this.innerHTML??\"\")}catch{return\"\"}}",
23
- "readElementInnerText": "function be(){try{let e=this,t=e.innerText;if(typeof t==\"string\"&&t.length>0)return t;let n=e.textContent;return typeof n==\"string\"?n:\"\"}catch{return\"\"}}",
24
- "readElementInputValue": "function Ee(){try{let e=this,t=(e.tagName||\"\").toLowerCase();return t===\"input\"||t===\"textarea\"||t===\"select\"?String(e.value??\"\"):e.isContentEditable?String(e.textContent??\"\"):\"\"}catch{return\"\"}}",
25
- "readElementTextContent": "function we(){try{return String(this.textContent??\"\")}catch{return\"\"}}",
26
- "resolveCssSelector": "function Ne(e,t){let n=String(e??\"\").trim();if(!n)return null;let o=C(t);return z(n,o+1)[o]??null}",
27
- "resolveCssSelectorPierce": "function Ce(e,t){let n=String(e??\"\").trim();if(!n)return null;let o=C(t),r=window.__stagehandV3__;if(!r||typeof r.getClosedRoot!=\"function\")return z(n,o+1)[o]??null;let l=c=>{try{return r.getClosedRoot(c)??null}catch{return null}},s=new WeakSet,i=new Set,a=[],d=[document],f=c=>{if(!(!c||s.has(c)||a.length>=o+1)){s.add(c);try{let p=c.querySelectorAll(n);for(let g of p)if(!i.has(g)&&(i.add(g),a.push(g),a.length>=o+1))return}catch{}try{let g=(c instanceof Document?c:c.host?.ownerDocument??document).createTreeWalker(c,NodeFilter.SHOW_ELEMENT),w;for(;w=g.nextNode();){if(!(w instanceof Element))continue;let x=w.shadowRoot;x&&d.push(x);let y=l(w);y&&d.push(y)}}catch{}}};for(;d.length&&a.length<o+1;){let c=d.shift();c&&f(c)}return a[o]??null}",
28
- "resolveTextSelector": "function Me(e,t){let n=String(e??\"\");if(!n)return null;let o=n.toLowerCase(),r=C(t),l=new Set([\"SCRIPT\",\"STYLE\",\"TEMPLATE\",\"NOSCRIPT\",\"HEAD\",\"TITLE\",\"LINK\",\"META\",\"HTML\",\"BODY\"]),s=u=>{if(!u)return!1;let h=u.tagName?.toUpperCase()??\"\";return l.has(h)},i=u=>{try{if(s(u))return\"\";let h=u.innerText;if(typeof h==\"string\"&&h.trim())return h.trim()}catch{}try{let h=u.textContent;if(typeof h==\"string\")return h.trim()}catch{}return\"\"},a=u=>{let h=i(u);return!!h&&h.toLowerCase().includes(o)},d=window.__stagehandV3__,f=d&&typeof d.getClosedRoot==\"function\"?u=>{try{return d.getClosedRoot(u)??null}catch{return null}}:u=>null,c=new WeakSet,p=[],g=[],w=u=>{!u||c.has(u)||(c.add(u),p.push(u))},x=u=>{try{return(u instanceof Document?u:u?.ownerDocument??document).createTreeWalker(u,NodeFilter.SHOW_ELEMENT)}catch{return null}};for(w(document);p.length;){let u=p.shift();if(!u)continue;u instanceof Element&&a(u)&&g.push({element:u,tag:u.tagName??\"\",id:u.id??\"\",className:u.className??\"\",text:i(u)});let h=x(u);if(!h)continue;let E;for(;E=h.nextNode();){if(!(E instanceof Element))continue;a(E)&&g.push({element:E,tag:E.tagName??\"\",id:E.id??\"\",className:E.className??\"\",text:i(E)});let b=E.shadowRoot;b&&w(b);let k=f(E);k&&w(k)}}let y=[];for(let u of g){let h=u.element,E=!1;for(let b of g)if(u!==b)try{if(h.contains(b.element)){E=!0;break}}catch{}E||y.push(u)}return y[r]?.element??null}",
29
- "resolveXPathMainWorld": "function Le(e,t){let n=C(t);return P(e,n,{pierceShadow:!0})}",
30
- "scrollElementToPercent": "function de(e){let t=n=>{if(typeof n==\"number\"&&Number.isFinite(n))return n;let o=String(n??\"\").trim();if(!o)return 0;let r=parseFloat(o.replace(\"%\",\"\"));return Number.isNaN(r)||!Number.isFinite(r)?0:r};try{let n=Math.max(0,Math.min(t(e),100)),o=this,r=o.tagName?.toLowerCase()??\"\";if(r===\"html\"||r===\"body\"){let c=(o.ownerDocument?.scrollingElement||o.ownerDocument?.documentElement||o.ownerDocument?.body||document.scrollingElement||document.documentElement||document.body)?.scrollHeight??document.body.scrollHeight??0,p=o.ownerDocument?.defaultView?.innerHeight??window.innerHeight,w=Math.max(0,c-p)*(n/100);return o.ownerDocument?.defaultView?.scrollTo({top:w,left:o.ownerDocument?.defaultView?.scrollX??window.scrollX??0,behavior:\"smooth\"}),!0}let s=o.scrollHeight??0,i=o.clientHeight??0,d=Math.max(0,s-i)*(n/100);return o.scrollTo({top:d,left:o.scrollLeft??0,behavior:\"smooth\"}),!0}catch{return!1}}",
31
- "selectElementOptions": "function he(e){try{if(!(this instanceof HTMLSelectElement))return[];let t=Array.isArray(e)?e:[e],n=new Set(t.map(s=>String(s??\"\").trim())),o=s=>{let i=(s.label||s.textContent||\"\").trim(),a=String(s.value??\"\").trim();return n.has(i)||n.has(a)};if(this.multiple)for(let s of Array.from(this.options))s.selected=o(s);else{let s=!1;for(let i of Array.from(this.options))!s&&o(i)?(i.selected=!0,this.value=i.value,s=!0):i.selected=!1}let r=new Event(\"input\",{bubbles:!0}),l=new Event(\"change\",{bubbles:!0});return this.dispatchEvent(r),this.dispatchEvent(l),Array.from(this.selectedOptions).map(s=>s.value)}catch{return[]}}",
32
- "waitForSelector": "function qe(e,t,n,o){let r=String(e??\"\").trim(),l=String(t??\"visible\")||\"visible\",s=typeof n==\"number\"&&n>0?n:3e4,i=o!==!1;return new Promise((a,d)=>{let f=null,c=null,p=!1,g=()=>{f!==null&&(clearTimeout(f),f=null)},w=V(r,i);if(B(w,l)){p=!0,a(!0);return}let x=[],y=()=>{for(let E of x)E.disconnect();c&&(document.removeEventListener(\"DOMContentLoaded\",c),c=null)},m=()=>{if(p)return;let E=V(r,i);B(E,l)&&(p=!0,g(),y(),a(!0))};if(!(document.body||document.documentElement)){c=()=>{document.removeEventListener(\"DOMContentLoaded\",c),c=null,m(),h()},document.addEventListener(\"DOMContentLoaded\",c),f=setTimeout(()=>{p||(p=!0,g(),y(),d(new Error(`waitForSelector: Timeout ${s}ms exceeded waiting for \"${r}\" to be ${l}`)))},s);return}let h=()=>{let E=document.body||document.documentElement;if(!E)return;let b=new MutationObserver(m);b.observe(E,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[\"style\",\"class\",\"hidden\",\"disabled\"]}),x.push(b),i&&ie(m,x)};h(),f=setTimeout(()=>{p||(p=!0,g(),y(),d(new Error(`waitForSelector: Timeout ${s}ms exceeded waiting for \"${r}\" to be ${l}`)))},s)})}"
10
+ assignFilePayloadsToInputElement: 'function ce(e){try{let t=this;if(!t||t.tagName?.toLowerCase()!=="input"||(t.type??"").toLowerCase()!=="file")return!1;let n=(()=>{try{return new DataTransfer}catch{return null}})();if(!n)return!1;let o=Array.isArray(e)?e:[];for(let r of o){if(!r)continue;let l=r.name||"upload.bin",s=r.mimeType||"application/octet-stream",i=typeof r.lastModified=="number"?r.lastModified:Date.now(),a=window.atob(r.base64??""),d=new Uint8Array(a.length);for(let p=0;p<a.length;p+=1)d[p]=a.charCodeAt(p);let f=new Blob([d],{type:s}),c=new File([f],l,{type:s,lastModified:i});n.items.add(c)}return t.files=n.files,t.dispatchEvent(new Event("input",{bubbles:!0})),t.dispatchEvent(new Event("change",{bubbles:!0})),!0}catch{return!1}}',
11
+ countCssMatchesPierce: 'function He(e){let t=String(e??"").trim();if(!t)return 0;let n=window.__stagehandV3__;if(!n||typeof n.getClosedRoot!="function")try{return document.querySelectorAll(t).length}catch{return 0}let o=new WeakSet,r=[],l=a=>{!a||o.has(a)||(o.add(a),r.push(a))};l(document);let s=0,i=a=>{let d=a.shadowRoot;d&&l(d);try{let f=n.getClosedRoot(a);f&&l(f)}catch{}};for(;r.length;){let a=r.shift();if(a){try{let d=a;typeof d.querySelectorAll=="function"&&(s+=d.querySelectorAll(t).length)}catch{}try{let f=(a instanceof Document?a:a instanceof ShadowRoot?a.host?.ownerDocument??document:a.ownerDocument??document).createTreeWalker(a,NodeFilter.SHOW_ELEMENT),c;for(;c=f.nextNode();)c instanceof Element&&i(c)}catch{}}}return s}',
12
+ countCssMatchesPrimary: 'function De(e){let t=String(e??"").trim();if(!t)return 0;let n=new WeakSet,o=r=>{if(!r||n.has(r))return 0;n.add(r);let l=0;try{let s=r;typeof s.querySelectorAll=="function"&&(l+=s.querySelectorAll(t).length)}catch{}try{let i=(r instanceof Document?r:r?.ownerDocument??document).createTreeWalker(r,NodeFilter.SHOW_ELEMENT),a;for(;a=i.nextNode();)a instanceof Element&&a.shadowRoot&&(l+=o(a.shadowRoot))}catch{}return l};try{return o(document)}catch{try{return document.querySelectorAll(t).length}catch{return 0}}}',
13
+ countTextMatches: 'function Ae(e){let t=String(e??"");if(!t)return{count:0,sample:[],error:null};let n=t.toLowerCase(),o=new Set(["SCRIPT","STYLE","TEMPLATE","NOSCRIPT","HEAD","TITLE","LINK","META","HTML","BODY"]),r=m=>{if(!m)return!1;let u=m.tagName?.toUpperCase()??"";return o.has(u)},l=m=>{try{if(r(m))return"";let u=m.innerText;if(typeof u=="string"&&u.trim())return u.trim()}catch{}try{let u=m.textContent;if(typeof u=="string")return u.trim()}catch{}return""},s=m=>{let u=l(m);return!!u&&u.toLowerCase().includes(n)},i=window.__stagehandV3__,a=i&&typeof i.getClosedRoot=="function"?m=>{try{return i.getClosedRoot(m)??null}catch{return null}}:m=>null,d=new WeakSet,f=[],c=m=>{!m||d.has(m)||(d.add(m),f.push(m))},p=m=>{try{return(m instanceof Document?m:m?.ownerDocument??document).createTreeWalker(m,NodeFilter.SHOW_ELEMENT)}catch{return null}},g=[];for(c(document);f.length;){let m=f.shift();if(!m)continue;m instanceof Element&&s(m)&&g.push({element:m,tag:m.tagName??"",id:m.id??"",className:m.className??"",text:l(m)});let u=p(m);if(!u)continue;let h;for(;h=u.nextNode();){if(!(h instanceof Element))continue;s(h)&&g.push({element:h,tag:h.tagName??"",id:h.id??"",className:h.className??"",text:l(h)});let E=h.shadowRoot;E&&c(E);let b=a(h);b&&c(b)}}let w=[];for(let m of g){let u=m.element,h=!1;for(let E of g)if(m!==E)try{if(u.contains(E.element)){h=!0;break}}catch{}h||w.push(m)}let x=w.length,y=w.slice(0,5).map(m=>({tag:m.tag,id:m.id,class:m.className,text:m.text}));return{count:x,sample:y,error:null}}',
14
+ countXPathMatchesMainWorld: "function We(e){return I(e,{pierceShadow:!0})}",
15
+ dispatchDomClick: 'function ue(e){let t=e??{};try{let n=new MouseEvent("click",{bubbles:!!t.bubbles,cancelable:!!t.cancelable,composed:!!t.composed,detail:typeof t.detail=="number"?t.detail:1,view:this?.ownerDocument?.defaultView??window});this.dispatchEvent(n)}catch{try{this.click()}catch{}}}',
16
+ ensureFileInputElement: 'function ae(){try{return(this.tagName?.toLowerCase()??"")!=="input"?!1:String(this.type??"").toLowerCase()==="file"}catch{return!1}}',
17
+ fillElementValue: 'function me(e){let t=this;if(!t.isConnected)return{status:"error",reason:"notconnected"};let o=(t.ownerDocument||document).defaultView||window,r=e??"";try{let l=s=>{let i;if(typeof o.InputEvent=="function")try{i=new o.InputEvent("input",{bubbles:!0,composed:!0,data:s,inputType:"insertText"})}catch{i=new o.Event("input",{bubbles:!0,composed:!0})}else i=new o.Event("input",{bubbles:!0,composed:!0});t.dispatchEvent(i);let a=new o.Event("change",{bubbles:!0});t.dispatchEvent(a)};if(t instanceof o.HTMLInputElement){let s=(t.type||"").toLowerCase();if(!Y.has(s)&&!D.has(s))return{status:"error",reason:`unsupported-input-type:${s}`};let i=e;if(s==="number"){let a=e.trim();if(a!==""&&Number.isNaN(Number(a)))return{status:"error",reason:"invalid-number-value"};i=a}if(r=i,D.has(s)){let a=e.trim();r=a,v.call(t);let d=o.HTMLInputElement.prototype,c=Object.getOwnPropertyDescriptor(d,"value")?.set;return typeof c=="function"?c.call(t,a):t.value=a,t._valueTracker?.setValue?.(a),t.value!==a?{status:"error",reason:"malformed-value"}:(l(a),{status:"done"})}return v.call(t),{status:"needsinput",value:i}}return t instanceof o.HTMLTextAreaElement?(v.call(t),r=e,{status:"needsinput",value:e}):t instanceof o.HTMLSelectElement?{status:"error",reason:"unsupported-element"}:t.isContentEditable?(v.call(t),r=e,{status:"needsinput",value:e}):{status:"error",reason:"unsupported-element"}}catch(l){let s="exception";if(l&&typeof l=="object"){let i=l.message;typeof i=="string"&&i.trim().length>0&&(s=`exception:${i}`)}return{status:"needsinput",value:r,reason:s}}}',
18
+ focusElement: 'function fe(){try{typeof this.focus=="function"&&this.focus()}catch{}}',
19
+ isElementChecked: 'function ge(){try{let e=this;if((e.tagName||"").toLowerCase()==="input"){let o=e.type?.toLowerCase()??"";if(o==="checkbox"||o==="radio")return!!e.checked}let n=e.getAttribute?.("aria-checked");return n!=null?n==="true":!1}catch{return!1}}',
20
+ isElementVisible: 'function pe(){try{let e=this;if(!e.isConnected)return!1;let t=e.ownerDocument?.defaultView?.getComputedStyle(e)??window.getComputedStyle(e);if(!t||t.display==="none"||t.visibility==="hidden")return!1;let n=parseFloat(t.opacity??"1");if(!Number.isFinite(n)||n===0)return!1;let o=e.getBoundingClientRect();return!(!o||Math.max(o.width,o.height)===0||e.getClientRects().length===0)}catch{return!1}}',
21
+ prepareElementForTyping: 'function v(){try{let e=this;if(!e.isConnected)return!1;let t=e.ownerDocument||document,n=t.defaultView||window;try{typeof e.focus=="function"&&e.focus()}catch{}if(e instanceof n.HTMLInputElement||e instanceof n.HTMLTextAreaElement){try{if(typeof e.select=="function")return e.select(),!0}catch{}try{let o=(e.value??"").length;if(typeof e.setSelectionRange=="function")return e.setSelectionRange(0,o),!0}catch{}return!0}if(e.isContentEditable){let o=t.getSelection?.(),r=t.createRange?.();if(o&&r)try{r.selectNodeContents(e),o.removeAllRanges(),o.addRange(r)}catch{}return!0}return!1}catch{return!1}}',
22
+ readElementInnerHTML: 'function ye(){try{return String(this.innerHTML??"")}catch{return""}}',
23
+ readElementInnerText: 'function be(){try{let e=this,t=e.innerText;if(typeof t=="string"&&t.length>0)return t;let n=e.textContent;return typeof n=="string"?n:""}catch{return""}}',
24
+ readElementInputValue: 'function Ee(){try{let e=this,t=(e.tagName||"").toLowerCase();return t==="input"||t==="textarea"||t==="select"?String(e.value??""):e.isContentEditable?String(e.textContent??""):""}catch{return""}}',
25
+ readElementTextContent: 'function we(){try{return String(this.textContent??"")}catch{return""}}',
26
+ resolveCssSelector: 'function Ne(e,t){let n=String(e??"").trim();if(!n)return null;let o=C(t);return z(n,o+1)[o]??null}',
27
+ resolveCssSelectorPierce: 'function Ce(e,t){let n=String(e??"").trim();if(!n)return null;let o=C(t),r=window.__stagehandV3__;if(!r||typeof r.getClosedRoot!="function")return z(n,o+1)[o]??null;let l=c=>{try{return r.getClosedRoot(c)??null}catch{return null}},s=new WeakSet,i=new Set,a=[],d=[document],f=c=>{if(!(!c||s.has(c)||a.length>=o+1)){s.add(c);try{let p=c.querySelectorAll(n);for(let g of p)if(!i.has(g)&&(i.add(g),a.push(g),a.length>=o+1))return}catch{}try{let g=(c instanceof Document?c:c.host?.ownerDocument??document).createTreeWalker(c,NodeFilter.SHOW_ELEMENT),w;for(;w=g.nextNode();){if(!(w instanceof Element))continue;let x=w.shadowRoot;x&&d.push(x);let y=l(w);y&&d.push(y)}}catch{}}};for(;d.length&&a.length<o+1;){let c=d.shift();c&&f(c)}return a[o]??null}',
28
+ resolveTextSelector: 'function Me(e,t){let n=String(e??"");if(!n)return null;let o=n.toLowerCase(),r=C(t),l=new Set(["SCRIPT","STYLE","TEMPLATE","NOSCRIPT","HEAD","TITLE","LINK","META","HTML","BODY"]),s=u=>{if(!u)return!1;let h=u.tagName?.toUpperCase()??"";return l.has(h)},i=u=>{try{if(s(u))return"";let h=u.innerText;if(typeof h=="string"&&h.trim())return h.trim()}catch{}try{let h=u.textContent;if(typeof h=="string")return h.trim()}catch{}return""},a=u=>{let h=i(u);return!!h&&h.toLowerCase().includes(o)},d=window.__stagehandV3__,f=d&&typeof d.getClosedRoot=="function"?u=>{try{return d.getClosedRoot(u)??null}catch{return null}}:u=>null,c=new WeakSet,p=[],g=[],w=u=>{!u||c.has(u)||(c.add(u),p.push(u))},x=u=>{try{return(u instanceof Document?u:u?.ownerDocument??document).createTreeWalker(u,NodeFilter.SHOW_ELEMENT)}catch{return null}};for(w(document);p.length;){let u=p.shift();if(!u)continue;u instanceof Element&&a(u)&&g.push({element:u,tag:u.tagName??"",id:u.id??"",className:u.className??"",text:i(u)});let h=x(u);if(!h)continue;let E;for(;E=h.nextNode();){if(!(E instanceof Element))continue;a(E)&&g.push({element:E,tag:E.tagName??"",id:E.id??"",className:E.className??"",text:i(E)});let b=E.shadowRoot;b&&w(b);let k=f(E);k&&w(k)}}let y=[];for(let u of g){let h=u.element,E=!1;for(let b of g)if(u!==b)try{if(h.contains(b.element)){E=!0;break}}catch{}E||y.push(u)}return y[r]?.element??null}',
29
+ resolveXPathMainWorld: "function Le(e,t){let n=C(t);return P(e,n,{pierceShadow:!0})}",
30
+ scrollElementToPercent: 'function de(e){let t=n=>{if(typeof n=="number"&&Number.isFinite(n))return n;let o=String(n??"").trim();if(!o)return 0;let r=parseFloat(o.replace("%",""));return Number.isNaN(r)||!Number.isFinite(r)?0:r};try{let n=Math.max(0,Math.min(t(e),100)),o=this,r=o.tagName?.toLowerCase()??"";if(r==="html"||r==="body"){let c=(o.ownerDocument?.scrollingElement||o.ownerDocument?.documentElement||o.ownerDocument?.body||document.scrollingElement||document.documentElement||document.body)?.scrollHeight??document.body.scrollHeight??0,p=o.ownerDocument?.defaultView?.innerHeight??window.innerHeight,w=Math.max(0,c-p)*(n/100);return o.ownerDocument?.defaultView?.scrollTo({top:w,left:o.ownerDocument?.defaultView?.scrollX??window.scrollX??0,behavior:"smooth"}),!0}let s=o.scrollHeight??0,i=o.clientHeight??0,d=Math.max(0,s-i)*(n/100);return o.scrollTo({top:d,left:o.scrollLeft??0,behavior:"smooth"}),!0}catch{return!1}}',
31
+ selectElementOptions: 'function he(e){try{if(!(this instanceof HTMLSelectElement))return[];let t=Array.isArray(e)?e:[e],n=new Set(t.map(s=>String(s??"").trim())),o=s=>{let i=(s.label||s.textContent||"").trim(),a=String(s.value??"").trim();return n.has(i)||n.has(a)};if(this.multiple)for(let s of Array.from(this.options))s.selected=o(s);else{let s=!1;for(let i of Array.from(this.options))!s&&o(i)?(i.selected=!0,this.value=i.value,s=!0):i.selected=!1}let r=new Event("input",{bubbles:!0}),l=new Event("change",{bubbles:!0});return this.dispatchEvent(r),this.dispatchEvent(l),Array.from(this.selectedOptions).map(s=>s.value)}catch{return[]}}',
32
+ waitForSelector: 'function qe(e,t,n,o){let r=String(e??"").trim(),l=String(t??"visible")||"visible",s=typeof n=="number"&&n>0?n:3e4,i=o!==!1;return new Promise((a,d)=>{let f=null,c=null,p=!1,g=()=>{f!==null&&(clearTimeout(f),f=null)},w=V(r,i);if(B(w,l)){p=!0,a(!0);return}let x=[],y=()=>{for(let E of x)E.disconnect();c&&(document.removeEventListener("DOMContentLoaded",c),c=null)},m=()=>{if(p)return;let E=V(r,i);B(E,l)&&(p=!0,g(),y(),a(!0))};if(!(document.body||document.documentElement)){c=()=>{document.removeEventListener("DOMContentLoaded",c),c=null,m(),h()},document.addEventListener("DOMContentLoaded",c),f=setTimeout(()=>{p||(p=!0,g(),y(),d(new Error(`waitForSelector: Timeout ${s}ms exceeded waiting for "${r}" to be ${l}`)))},s);return}let h=()=>{let E=document.body||document.documentElement;if(!E)return;let b=new MutationObserver(m);b.observe(E,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style","class","hidden","disabled"]}),x.push(b),i&&ie(m,x)};h(),f=setTimeout(()=>{p||(p=!0,g(),y(),d(new Error(`waitForSelector: Timeout ${s}ms exceeded waiting for "${r}" to be ${l}`)))},s)})}',
33
33
  };
34
34
  exports.locatorScriptGlobalRefs = {
35
- "assignFilePayloadsToInputElement": "globalThis.__stagehandLocatorScripts.assignFilePayloadsToInputElement",
36
- "countCssMatchesPierce": "globalThis.__stagehandLocatorScripts.countCssMatchesPierce",
37
- "countCssMatchesPrimary": "globalThis.__stagehandLocatorScripts.countCssMatchesPrimary",
38
- "countTextMatches": "globalThis.__stagehandLocatorScripts.countTextMatches",
39
- "countXPathMatchesMainWorld": "globalThis.__stagehandLocatorScripts.countXPathMatchesMainWorld",
40
- "dispatchDomClick": "globalThis.__stagehandLocatorScripts.dispatchDomClick",
41
- "ensureFileInputElement": "globalThis.__stagehandLocatorScripts.ensureFileInputElement",
42
- "fillElementValue": "globalThis.__stagehandLocatorScripts.fillElementValue",
43
- "focusElement": "globalThis.__stagehandLocatorScripts.focusElement",
44
- "isElementChecked": "globalThis.__stagehandLocatorScripts.isElementChecked",
45
- "isElementVisible": "globalThis.__stagehandLocatorScripts.isElementVisible",
46
- "prepareElementForTyping": "globalThis.__stagehandLocatorScripts.prepareElementForTyping",
47
- "readElementInnerHTML": "globalThis.__stagehandLocatorScripts.readElementInnerHTML",
48
- "readElementInnerText": "globalThis.__stagehandLocatorScripts.readElementInnerText",
49
- "readElementInputValue": "globalThis.__stagehandLocatorScripts.readElementInputValue",
50
- "readElementTextContent": "globalThis.__stagehandLocatorScripts.readElementTextContent",
51
- "resolveCssSelector": "globalThis.__stagehandLocatorScripts.resolveCssSelector",
52
- "resolveCssSelectorPierce": "globalThis.__stagehandLocatorScripts.resolveCssSelectorPierce",
53
- "resolveTextSelector": "globalThis.__stagehandLocatorScripts.resolveTextSelector",
54
- "resolveXPathMainWorld": "globalThis.__stagehandLocatorScripts.resolveXPathMainWorld",
55
- "scrollElementToPercent": "globalThis.__stagehandLocatorScripts.scrollElementToPercent",
56
- "selectElementOptions": "globalThis.__stagehandLocatorScripts.selectElementOptions",
57
- "waitForSelector": "globalThis.__stagehandLocatorScripts.waitForSelector"
35
+ assignFilePayloadsToInputElement: "globalThis.__stagehandLocatorScripts.assignFilePayloadsToInputElement",
36
+ countCssMatchesPierce: "globalThis.__stagehandLocatorScripts.countCssMatchesPierce",
37
+ countCssMatchesPrimary: "globalThis.__stagehandLocatorScripts.countCssMatchesPrimary",
38
+ countTextMatches: "globalThis.__stagehandLocatorScripts.countTextMatches",
39
+ countXPathMatchesMainWorld: "globalThis.__stagehandLocatorScripts.countXPathMatchesMainWorld",
40
+ dispatchDomClick: "globalThis.__stagehandLocatorScripts.dispatchDomClick",
41
+ ensureFileInputElement: "globalThis.__stagehandLocatorScripts.ensureFileInputElement",
42
+ fillElementValue: "globalThis.__stagehandLocatorScripts.fillElementValue",
43
+ focusElement: "globalThis.__stagehandLocatorScripts.focusElement",
44
+ isElementChecked: "globalThis.__stagehandLocatorScripts.isElementChecked",
45
+ isElementVisible: "globalThis.__stagehandLocatorScripts.isElementVisible",
46
+ prepareElementForTyping: "globalThis.__stagehandLocatorScripts.prepareElementForTyping",
47
+ readElementInnerHTML: "globalThis.__stagehandLocatorScripts.readElementInnerHTML",
48
+ readElementInnerText: "globalThis.__stagehandLocatorScripts.readElementInnerText",
49
+ readElementInputValue: "globalThis.__stagehandLocatorScripts.readElementInputValue",
50
+ readElementTextContent: "globalThis.__stagehandLocatorScripts.readElementTextContent",
51
+ resolveCssSelector: "globalThis.__stagehandLocatorScripts.resolveCssSelector",
52
+ resolveCssSelectorPierce: "globalThis.__stagehandLocatorScripts.resolveCssSelectorPierce",
53
+ resolveTextSelector: "globalThis.__stagehandLocatorScripts.resolveTextSelector",
54
+ resolveXPathMainWorld: "globalThis.__stagehandLocatorScripts.resolveXPathMainWorld",
55
+ scrollElementToPercent: "globalThis.__stagehandLocatorScripts.scrollElementToPercent",
56
+ selectElementOptions: "globalThis.__stagehandLocatorScripts.selectElementOptions",
57
+ waitForSelector: "globalThis.__stagehandLocatorScripts.waitForSelector",
58
58
  };
59
59
  //# sourceMappingURL=locatorScripts.generated.js.map