@handstage/dom 0.0.1 → 1.0.0
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.
- package/README.md +3 -0
- package/dist/build/a11yScripts.generated.js +11 -11
- package/dist/build/locatorScripts.generated.js +47 -47
- package/dist/build/reRenderScriptContent.js +1 -1
- package/dist/build/screenshotScripts.generated.js +1 -1
- package/dist/build/scriptV3Content.js +1 -1
- package/package.json +6 -6
- package/src/build/a11yScripts.generated.ts +14 -22
- package/src/build/locatorScripts.generated.ts +50 -89
- package/src/build/reRenderScriptContent.ts +1 -1
- package/src/build/screenshotScripts.generated.ts +3 -4
- package/src/build/scriptV3Content.ts +1 -1
package/README.md
ADDED
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
* AUTO-GENERATED FILE. DO NOT EDIT.
|
|
3
3
|
* Update sources in pkgs/dom/src/a11yScripts and run genA11yScripts.ts.
|
|
4
4
|
*/
|
|
5
|
-
export const a11yScriptBootstrap =
|
|
5
|
+
export const a11yScriptBootstrap = "if (!globalThis.__handstageA11yScripts) { \"use strict\";var __handstageA11yScriptsFactory=(()=>{var d=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var N=(n,t)=>{for(var o in t)d(n,o,{get:t[o],enumerable:!0})},h=(n,t,o,i)=>{if(t&&typeof t==\"object\"||typeof t==\"function\")for(let u of f(t))!p.call(n,u)&&u!==o&&d(n,u,{get:()=>t[u],enumerable:!(i=a(t,u))||i.enumerable});return n};var E=n=>h(d({},\"__esModule\",{value:!0}),n);var b={};N(b,{documentHasFocusStrict:()=>g,getBoundingRectLite:()=>w,getScrollOffsets:()=>y,nodeToAbsoluteXPath:()=>$,resolveDeepActiveElement:()=>T});function y(){try{let n=window.scrollX??window.pageXOffset??document.documentElement?.scrollLeft??0,t=window.scrollY??window.pageYOffset??document.documentElement?.scrollTop??0;return{sx:Number(n)||0,sy:Number(t)||0}}catch{return{sx:0,sy:0}}}function w(){try{let n=this.getBoundingClientRect();return{left:Number(n?.left??0)||0,top:Number(n?.top??0)||0}}catch{return{left:0,top:0}}}function T(){try{return(t=>{let o=t.activeElement??null;for(;o?.shadowRoot?.activeElement;)o=o.shadowRoot.activeElement;return o??null})(document)}catch{return null}}function $(){return(t=>{try{let o=e=>{if(!e?.parentNode)return 1;let s=1,m=`${e.nodeType}:${(e.nodeName||\"\").toLowerCase()}`;for(let c=e.previousSibling;c;c=c.previousSibling)`${c.nodeType}:${(c.nodeName||\"\").toLowerCase()}`===m&&(s+=1);return s},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()[${o(e)}]`;if(e.nodeType===Node.COMMENT_NODE)return`comment()[${o(e)}]`;let s=(e.nodeName||\"\").toLowerCase();return`${s.includes(\":\")?`*[name()='${s}']`:s}[${o(e)}]`},u=[],l=t;for(;l;){if(l.nodeType===Node.DOCUMENT_FRAGMENT_NODE){u.push(\"//\"),l=l.host??null;continue}let e=i(l);e&&u.push(e),l=l.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.__handstageA11yScripts = __handstageA11yScriptsFactory;\n}";
|
|
6
6
|
export const a11yScriptSources = {
|
|
7
|
-
documentHasFocusStrict: "function h() {\n try {\n return document.hasFocus() === !0;\n } catch {\n return !1;\n }\n}",
|
|
8
|
-
getBoundingRectLite: "function f() {\n try {\n let r = this.getBoundingClientRect();\n return { left: Number(r?.left ?? 0) || 0, top: Number(r?.top ?? 0) || 0 };\n } catch {\n return { left: 0, top: 0 };\n }\n}",
|
|
9
|
-
getScrollOffsets: "function a() {\n try {\n let r = window.scrollX ?? window.pageXOffset ?? document.documentElement?.scrollLeft ?? 0,
|
|
10
|
-
nodeToAbsoluteXPath:
|
|
11
|
-
resolveDeepActiveElement: "function p() {\n try {\n return ((
|
|
7
|
+
"documentHasFocusStrict": "function h() {\n try {\n return document.hasFocus() === !0;\n } catch {\n return !1;\n }\n}",
|
|
8
|
+
"getBoundingRectLite": "function f() {\n try {\n let r = this.getBoundingClientRect();\n return { left: Number(r?.left ?? 0) || 0, top: Number(r?.top ?? 0) || 0 };\n } catch {\n return { left: 0, top: 0 };\n }\n}",
|
|
9
|
+
"getScrollOffsets": "function a() {\n try {\n let r = window.scrollX ?? window.pageXOffset ?? document.documentElement?.scrollLeft ?? 0, l = window.scrollY ?? window.pageYOffset ?? document.documentElement?.scrollTop ?? 0;\n return { sx: Number(r) || 0, sy: Number(l) || 0 };\n } catch {\n return { sx: 0, sy: 0 };\n }\n}",
|
|
10
|
+
"nodeToAbsoluteXPath": "function N() {\n return ((l) => {\n try {\n let n = (e) => {\n if (!e?.parentNode)\n return 1;\n let u = 1, i = `${e.nodeType}:${(e.nodeName || \"\").toLowerCase()}`;\n for (let s = e.previousSibling;s; s = s.previousSibling)\n `${s.nodeType}:${(s.nodeName || \"\").toLowerCase()}` === i && (u += 1);\n return u;\n }, d = (e) => {\n if (!e || e.nodeType === Node.DOCUMENT_NODE)\n return \"\";\n if (e.nodeType === Node.DOCUMENT_FRAGMENT_NODE)\n return \"//\";\n if (e.nodeType === Node.TEXT_NODE)\n return `text()[${n(e)}]`;\n if (e.nodeType === Node.COMMENT_NODE)\n return `comment()[${n(e)}]`;\n let u = (e.nodeName || \"\").toLowerCase();\n return `${u.includes(\":\") ? `*[name()='${u}']` : u}[${n(e)}]`;\n }, c = [], o = l;\n for (;o; ) {\n if (o.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {\n c.push(\"//\"), o = o.host ?? null;\n continue;\n }\n let e = d(o);\n e && c.push(e), o = o.parentNode;\n }\n c.reverse();\n let t = \"\";\n for (let e of c)\n e === \"//\" ? t = t ? t.endsWith(\"/\") ? `${t}/` : `${t}//` : \"//\" : t = t ? t.endsWith(\"/\") ? `${t}${e}` : `${t}/${e}` : `/${e}`;\n return t || \"/\";\n } catch {\n return \"/\";\n }\n })(this);\n}",
|
|
11
|
+
"resolveDeepActiveElement": "function p() {\n try {\n return ((l) => {\n let n = l.activeElement ?? null;\n for (;n?.shadowRoot?.activeElement; )\n n = n.shadowRoot.activeElement;\n return n ?? null;\n })(document);\n } catch {\n return null;\n }\n}"
|
|
12
12
|
};
|
|
13
13
|
export const a11yScriptGlobalRefs = {
|
|
14
|
-
documentHasFocusStrict: "globalThis.
|
|
15
|
-
getBoundingRectLite: "globalThis.
|
|
16
|
-
getScrollOffsets: "globalThis.
|
|
17
|
-
nodeToAbsoluteXPath: "globalThis.
|
|
18
|
-
resolveDeepActiveElement: "globalThis.
|
|
14
|
+
"documentHasFocusStrict": "globalThis.__handstageA11yScripts.documentHasFocusStrict",
|
|
15
|
+
"getBoundingRectLite": "globalThis.__handstageA11yScripts.getBoundingRectLite",
|
|
16
|
+
"getScrollOffsets": "globalThis.__handstageA11yScripts.getScrollOffsets",
|
|
17
|
+
"nodeToAbsoluteXPath": "globalThis.__handstageA11yScripts.nodeToAbsoluteXPath",
|
|
18
|
+
"resolveDeepActiveElement": "globalThis.__handstageA11yScripts.resolveDeepActiveElement"
|
|
19
19
|
};
|
|
@@ -2,54 +2,54 @@
|
|
|
2
2
|
* AUTO-GENERATED FILE. DO NOT EDIT.
|
|
3
3
|
* Update sources in pkgs/dom/src/locatorScripts and run genLocatorScripts.ts.
|
|
4
4
|
*/
|
|
5
|
-
export const locatorScriptBootstrap = 'if (!globalThis.__stagehandLocatorScripts) { "use strict";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:()=>he,countCssMatchesPierce:()=>ue,countCssMatchesPrimary:()=>ce,countTextMatches:()=>de,countXPathMatchesMainWorld:()=>me,dispatchDomClick:()=>pe,ensureFileInputElement:()=>fe,fillElementValue:()=>we,focusElement:()=>ye,isElementChecked:()=>Se,isElementVisible:()=>xe,prepareElementForTyping:()=>v,readElementInnerHTML:()=>Re,readElementInnerText:()=>Ne,readElementInputValue:()=>ve,readElementTextContent:()=>Te,resolveCssSelector:()=>Ce,resolveCssSelectorPierce:()=>Me,resolveTextSelector:()=>Le,resolveXPathMainWorld:()=>Pe,scrollElementToPercent:()=>ge,selectElementOptions:()=>be,waitForSelector:()=>_e});function _(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}=te(a);n.push({axis:r,tag:d,predicates:f})}return n}function ee(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 te(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 ee(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=H(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=H(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=re(t,"not");if(r!=null){let l=T(r);return l?{type:"not",predicate:l}:null}return ne(t)}function ne(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 H(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&&oe(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 oe(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 A(o)&&A(r)}function A(e){return!/[a-zA-Z0-9_.-]/.test(e)}function re(e,t){let n=`${t}(`;if(!e.startsWith(n)||!e.endsWith(")"))return null;let o=e.slice(n.length,-1);return se(o)?o:null}function se(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 le=e=>e.replace(/\\s+/g," ").trim();function W(e){return String(e.textContent??"")}function S(e,t){return t?le(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(W(e),t.normalize)===S(t.value,t.normalize);case"textContains":return S(W(e),t.normalize).includes(S(t.value,t.normalize));case"index":return!0;default:return!0}}function O(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 F(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?$():null;if(!l)return q(o,r).value;if(!s?.hasShadow){let a=q(o,r);return a.error?N(o,s?.getClosedRoot)[r]??null:a.value}return N(o,s.getClosedRoot)[r]??null}function I(e,t){let n=P(e);if(!n)return 0;let o=t?.pierceShadow!==!1,r=o?$():null;if(!o)return X(n).count;if(!r?.hasShadow){let l=X(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=_(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):ae(d,r);if(!f.length)continue;let c=f.filter(g=>ie(g,s)),p=O(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 ie(e,t){return t.tag==="*"?!0:e.localName===t.tag}function $(){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 ae(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 q(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 X(e){try{return{count:document.evaluate(e,document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotLength,error:!1}}catch{return{count:0,error:!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 ue(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 de(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 me(e){return I(e,{pierceShadow:!0})}function fe(){try{return(this.tagName?.toLowerCase()??"")!=="input"?!1:String(this.type??"").toLowerCase()==="file"}catch{return!1}}function he(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 pe(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 ge(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 z=new Set(["color","date","datetime-local","month","range","time","week"]),Ee=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 we(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(!Ee.has(s)&&!z.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,z.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 ye(){try{typeof this.focus=="function"&&this.focus()}catch{}}function be(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 xe(){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 Se(){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 ve(){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 Te(){try{return String(this.textContent??"")}catch{return""}}function Re(){try{return String(this.innerHTML??"")}catch{return""}}function Ne(){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""}}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 Ce(e,t){let n=String(e??"").trim();if(!n)return null;let o=C(t);return V(n,o+1)[o]??null}function Me(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 Le(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 Pe(e,t){let n=C(t);return k(e,n,{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)=>F(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}';
|
|
5
|
+
export const locatorScriptBootstrap = "if (!globalThis.__handstageLocatorScripts) { \"use strict\";var __handstageLocatorScriptsFactory=(()=>{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 Xe={};Z(Xe,{assignFilePayloadsToInputElement:()=>he,countCssMatchesPierce:()=>ue,countCssMatchesPrimary:()=>ce,countTextMatches:()=>de,countXPathMatchesMainWorld:()=>me,dispatchDomClick:()=>pe,ensureFileInputElement:()=>fe,fillElementValue:()=>we,focusElement:()=>ye,isElementChecked:()=>Se,isElementVisible:()=>xe,prepareElementForTyping:()=>v,readElementInnerHTML:()=>Re,readElementInnerText:()=>Ce,readElementInputValue:()=>ve,readElementTextContent:()=>Te,resolveCssSelector:()=>Ne,resolveCssSelectorPierce:()=>Me,resolveTextSelector:()=>Le,resolveXPathMainWorld:()=>Pe,scrollElementToPercent:()=>ge,selectElementOptions:()=>be,waitForSelector:()=>Oe});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}=te(a);n.push({axis:r,tag:d,predicates:f})}return n}function ee(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 te(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 ee(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=H(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=H(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=re(t,\"not\");if(r!=null){let l=T(r);return l?{type:\"not\",predicate:l}:null}return ne(t)}function ne(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 H(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&&oe(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 oe(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 A(o)&&A(r)}function A(e){return!/[a-zA-Z0-9_.-]/.test(e)}function re(e,t){let n=`${t}(`;if(!e.startsWith(n)||!e.endsWith(\")\"))return null;let o=e.slice(n.length,-1);return se(o)?o:null}function se(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 le=e=>e.replace(/\\s+/g,\" \").trim();function W(e){return String(e.textContent??\"\")}function S(e,t){return t?le(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(W(e),t.normalize)===S(t.value,t.normalize);case\"textContains\":return S(W(e),t.normalize).includes(S(t.value,t.normalize));case\"index\":return!0;default:return!0}}function X(e,t){let n=e;for(let o of t){if(!n.length)return[];if(o.type===\"index\"){let r=o.index-1;if(r>=0&&r<n.length){let l=n[r];if(!l)throw new Error(\"XPath predicate index resolved empty\");n=[l]}else n=[];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 F(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?$():null;if(!l)return _(o,r).value;if(!s?.hasShadow){let a=_(o,r);return a.error?C(o,s?.getClosedRoot)[r]??null:a.value}return C(o,s.getClosedRoot)[r]??null}function I(e,t){let n=P(e);if(!n)return 0;let o=t?.pierceShadow!==!1,r=o?$():null;if(!o)return q(n).count;if(!r?.hasShadow){let l=q(n);return l.error?C(n,r?.getClosedRoot).length:l.count}return C(n,r.getClosedRoot).length}function C(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):ae(d,r);if(!f.length)continue;let c=f.filter(p=>ie(p,s)),E=X(c,s.predicates);for(let p of E)a.has(p)||(a.add(p),i.push(p))}if(!i.length)return[];l=i}return l}function ie(e,t){return t.tag===\"*\"?!0:e.localName===t.tag}function $(){let e=window.__handstageV3__,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 ae(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){let a=s[i];if(!a)throw new Error(\"XPath composed child missing during traversal\");r.push(a)}}return n}function _(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 q(e){try{return{count:document.evaluate(e,document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotLength,error:!1}}catch{return{count:0,error:!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);for(let a=i.nextNode();a;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 ue(e){let t=String(e??\"\").trim();if(!t)return 0;let n=window.__handstageV3__;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);for(let c=f.nextNode();c;c=f.nextNode())c instanceof Element&&i(c)}catch{}}}return s}function de(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.__handstageV3__,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))},E=m=>{try{return(m instanceof Document?m:m?.ownerDocument??document).createTreeWalker(m,NodeFilter.SHOW_ELEMENT)}catch{return null}},p=[];for(c(document);f.length;){let m=f.shift();if(!m)continue;m instanceof Element&&s(m)&&p.push({element:m,tag:m.tagName??\"\",id:m.id??\"\",className:m.className??\"\",text:l(m)});let u=E(m);if(u)for(let h=u.nextNode();h;h=u.nextNode()){if(!(h instanceof Element))continue;s(h)&&p.push({element:h,tag:h.tagName??\"\",id:h.id??\"\",className:h.className??\"\",text:l(h)});let g=h.shadowRoot;g&&c(g);let b=a(h);b&&c(b)}}let w=[];for(let m of p){let u=m.element,h=!1;for(let g of p)if(m!==g)try{if(u.contains(g.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 me(e){return I(e,{pierceShadow:!0})}function fe(){try{return(this.tagName?.toLowerCase()??\"\")!==\"input\"?!1:String(this.type??\"\").toLowerCase()===\"file\"}catch{return!1}}function he(e){try{let t=this;if(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 E=0;E<a.length;E+=1)d[E]=a.charCodeAt(E);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 pe(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 ge(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,E=o.ownerDocument?.defaultView?.innerHeight??window.innerHeight,w=Math.max(0,c-E)*(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 z=new Set([\"color\",\"date\",\"datetime-local\",\"month\",\"range\",\"time\",\"week\"]),Ee=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 we(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(!Ee.has(s)&&!z.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,z.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 ye(){try{typeof this.focus==\"function\"&&this.focus()}catch{}}function be(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 xe(){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 Se(){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 ve(){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 Te(){try{return String(this.textContent??\"\")}catch{return\"\"}}function Re(){try{return String(this.innerHTML??\"\")}catch{return\"\"}}function Ce(){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\"\"}}var N=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);for(let f=d.nextNode();f;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 Ne(e,t){let n=String(e??\"\").trim();if(!n)return null;let o=N(t);return V(n,o+1)[o]??null}function Me(e,t){let n=String(e??\"\").trim();if(!n)return null;let o=N(t),r=window.__handstageV3__;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 E=c.querySelectorAll(n);for(let p of E)if(!i.has(p)&&(i.add(p),a.push(p),a.length>=o+1))return}catch{}try{let p=(c instanceof Document?c:c.host?.ownerDocument??document).createTreeWalker(c,NodeFilter.SHOW_ELEMENT);for(let w=p.nextNode();w;w=p.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 Le(e,t){let n=String(e??\"\");if(!n)return null;let o=n.toLowerCase(),r=N(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.__handstageV3__,f=d&&typeof d.getClosedRoot==\"function\"?u=>{try{return d.getClosedRoot(u)??null}catch{return null}}:u=>null,c=new WeakSet,E=[],p=[],w=u=>{!u||c.has(u)||(c.add(u),E.push(u))},x=u=>{try{return(u instanceof Document?u:u?.ownerDocument??document).createTreeWalker(u,NodeFilter.SHOW_ELEMENT)}catch{return null}};for(w(document);E.length;){let u=E.shift();if(!u)continue;u instanceof Element&&a(u)&&p.push({element:u,tag:u.tagName??\"\",id:u.id??\"\",className:u.className??\"\",text:i(u)});let h=x(u);if(h)for(let g=h.nextNode();g;g=h.nextNode()){if(!(g instanceof Element))continue;a(g)&&p.push({element:g,tag:g.tagName??\"\",id:g.id??\"\",className:g.className??\"\",text:i(g)});let b=g.shadowRoot;b&&w(b);let D=f(g);D&&w(D)}}let y=[];for(let u of p){let h=u.element,g=!1;for(let b of p)if(u!==b)try{if(h.contains(b.element)){g=!0;break}}catch{}g||y.push(u)}return y[r]?.element??null}function Pe(e,t){let n=N(t);return k(e,n,{pierceShadow:!0})}var ke=e=>e.startsWith(\"xpath=\")||e.startsWith(\"/\"),De=e=>{try{let t=window.__handstageV3__;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);for(let a=i.nextNode();a;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)=>F(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 Oe(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,E=!1,p=()=>{f!==null&&(clearTimeout(f),f=null)},w=B(r,i);if(G(w,l)){E=!0,a(!0);return}let x=[],y=()=>{for(let g of x)g.disconnect();c&&(document.removeEventListener(\"DOMContentLoaded\",c),c=null)},m=()=>{if(E)return;let g=B(r,i);G(g,l)&&(E=!0,p(),y(),a(!0))};if(!(document.body||document.documentElement)){c=()=>{if(!c)throw new Error(\"DOMContentLoaded handler missing during cleanup\");document.removeEventListener(\"DOMContentLoaded\",c),c=null,m(),h()},document.addEventListener(\"DOMContentLoaded\",c),f=setTimeout(()=>{E||(E=!0,p(),y(),d(new Error(`waitForSelector: Timeout ${s}ms exceeded waiting for \"${r}\" to be ${l}`)))},s);return}let h=()=>{let g=document.body||document.documentElement;if(!g)return;let b=new MutationObserver(m);b.observe(g,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[\"style\",\"class\",\"hidden\",\"disabled\"]}),x.push(b),i&&We(m,x)};h(),f=setTimeout(()=>{E||(E=!0,p(),y(),d(new Error(`waitForSelector: Timeout ${s}ms exceeded waiting for \"${r}\" to be ${l}`)))},s)})}return J(Xe);})();\n globalThis.__handstageLocatorScripts = __handstageLocatorScriptsFactory;\n}";
|
|
6
6
|
export const locatorScriptSources = {
|
|
7
|
-
assignFilePayloadsToInputElement:
|
|
8
|
-
countCssMatchesPierce:
|
|
9
|
-
countCssMatchesPrimary:
|
|
10
|
-
countTextMatches:
|
|
11
|
-
countXPathMatchesMainWorld: "function pe(e) {\n return F(e, { pierceShadow: !0 });\n}",
|
|
12
|
-
dispatchDomClick:
|
|
13
|
-
ensureFileInputElement:
|
|
14
|
-
fillElementValue:
|
|
15
|
-
focusElement:
|
|
16
|
-
isElementChecked:
|
|
17
|
-
isElementVisible:
|
|
18
|
-
prepareElementForTyping:
|
|
19
|
-
readElementInnerHTML:
|
|
20
|
-
readElementInnerText:
|
|
21
|
-
readElementInputValue:
|
|
22
|
-
readElementTextContent:
|
|
23
|
-
resolveCssSelector:
|
|
24
|
-
resolveCssSelectorPierce:
|
|
25
|
-
resolveTextSelector:
|
|
26
|
-
resolveXPathMainWorld: "function We(e, t) {\n let n =
|
|
27
|
-
scrollElementToPercent:
|
|
28
|
-
selectElementOptions:
|
|
29
|
-
waitForSelector:
|
|
7
|
+
"assignFilePayloadsToInputElement": "function we(e) {\n try {\n let t = this;\n if (t?.tagName?.toLowerCase() !== \"input\" || (t.type ?? \"\").toLowerCase() !== \"file\")\n return !1;\n let n = (() => {\n try {\n return new DataTransfer;\n } catch {\n return null;\n }\n })();\n if (!n)\n return !1;\n let o = Array.isArray(e) ? e : [];\n for (let r of o) {\n if (!r)\n continue;\n 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);\n for (let E = 0;E < a.length; E += 1)\n d[E] = a.charCodeAt(E);\n let f = new Blob([d], { type: s }), c = new File([f], l, { type: s, lastModified: i });\n n.items.add(c);\n }\n return t.files = n.files, t.dispatchEvent(new Event(\"input\", { bubbles: !0 })), t.dispatchEvent(new Event(\"change\", { bubbles: !0 })), !0;\n } catch {\n return !1;\n }\n}",
|
|
8
|
+
"countCssMatchesPierce": "function fe(e) {\n let t = String(e ?? \"\").trim();\n if (!t)\n return 0;\n let n = window.__handstageV3__;\n if (!n || typeof n.getClosedRoot != \"function\")\n try {\n return document.querySelectorAll(t).length;\n } catch {\n return 0;\n }\n let o = new WeakSet, r = [], l = (a) => {\n !a || o.has(a) || (o.add(a), r.push(a));\n };\n l(document);\n let s = 0, i = (a) => {\n let d = a.shadowRoot;\n d && l(d);\n try {\n let f = n.getClosedRoot(a);\n f && l(f);\n } catch {}\n };\n for (;r.length; ) {\n let a = r.shift();\n if (a) {\n try {\n let d = a;\n typeof d.querySelectorAll == \"function\" && (s += d.querySelectorAll(t).length);\n } catch {}\n try {\n let f = (a instanceof Document ? a : a instanceof ShadowRoot ? a.host?.ownerDocument ?? document : a.ownerDocument ?? document).createTreeWalker(a, NodeFilter.SHOW_ELEMENT);\n for (let c = f.nextNode();c; c = f.nextNode())\n c instanceof Element && i(c);\n } catch {}\n }\n }\n return s;\n}",
|
|
9
|
+
"countCssMatchesPrimary": "function me(e) {\n let t = String(e ?? \"\").trim();\n if (!t)\n return 0;\n let n = new WeakSet, o = (r) => {\n if (!r || n.has(r))\n return 0;\n n.add(r);\n let l = 0;\n try {\n let s = r;\n typeof s.querySelectorAll == \"function\" && (l += s.querySelectorAll(t).length);\n } catch {}\n try {\n let i = (r instanceof Document ? r : r?.ownerDocument ?? document).createTreeWalker(r, NodeFilter.SHOW_ELEMENT);\n for (let a = i.nextNode();a; a = i.nextNode())\n a instanceof Element && a.shadowRoot && (l += o(a.shadowRoot));\n } catch {}\n return l;\n };\n try {\n return o(document);\n } catch {\n try {\n return document.querySelectorAll(t).length;\n } catch {\n return 0;\n }\n }\n}",
|
|
10
|
+
"countTextMatches": "function he(e) {\n let t = String(e ?? \"\");\n if (!t)\n return { count: 0, sample: [], error: null };\n let n = t.toLowerCase(), o = new Set([\"SCRIPT\", \"STYLE\", \"TEMPLATE\", \"NOSCRIPT\", \"HEAD\", \"TITLE\", \"LINK\", \"META\", \"HTML\", \"BODY\"]), r = (m) => {\n if (!m)\n return !1;\n let u = m.tagName?.toUpperCase() ?? \"\";\n return o.has(u);\n }, l = (m) => {\n try {\n if (r(m))\n return \"\";\n let u = m.innerText;\n if (typeof u == \"string\" && u.trim())\n return u.trim();\n } catch {}\n try {\n let u = m.textContent;\n if (typeof u == \"string\")\n return u.trim();\n } catch {}\n return \"\";\n }, s = (m) => {\n let u = l(m);\n return !!u && u.toLowerCase().includes(n);\n }, i = window.__handstageV3__, a = i && typeof i.getClosedRoot == \"function\" ? (m) => {\n try {\n return i.getClosedRoot(m) ?? null;\n } catch {\n return null;\n }\n } : (m) => null, d = new WeakSet, f = [], c = (m) => {\n !m || d.has(m) || (d.add(m), f.push(m));\n }, E = (m) => {\n try {\n return (m instanceof Document ? m : m?.ownerDocument ?? document).createTreeWalker(m, NodeFilter.SHOW_ELEMENT);\n } catch {\n return null;\n }\n }, p = [];\n for (c(document);f.length; ) {\n let m = f.shift();\n if (!m)\n continue;\n m instanceof Element && s(m) && p.push({ element: m, tag: m.tagName ?? \"\", id: m.id ?? \"\", className: m.className ?? \"\", text: l(m) });\n let u = E(m);\n if (u)\n for (let h = u.nextNode();h; h = u.nextNode()) {\n if (!(h instanceof Element))\n continue;\n s(h) && p.push({ element: h, tag: h.tagName ?? \"\", id: h.id ?? \"\", className: h.className ?? \"\", text: l(h) });\n let g = h.shadowRoot;\n g && c(g);\n let b = a(h);\n b && c(b);\n }\n }\n let w = [];\n for (let m of p) {\n let u = m.element, h = !1;\n for (let g of p)\n if (m !== g)\n try {\n if (u.contains(g.element)) {\n h = !0;\n break;\n }\n } catch {}\n h || w.push(m);\n }\n let x = w.length, y = w.slice(0, 5).map((m) => ({ tag: m.tag, id: m.id, class: m.className, text: m.text }));\n return { count: x, sample: y, error: null };\n}",
|
|
11
|
+
"countXPathMatchesMainWorld": "function pe(e) {\n return F(e, { pierceShadow: !0 });\n}",
|
|
12
|
+
"dispatchDomClick": "function ye(e) {\n let t = e ?? {};\n try {\n 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 });\n this.dispatchEvent(n);\n } catch {\n try {\n this.click();\n } catch {}\n }\n}",
|
|
13
|
+
"ensureFileInputElement": "function Ee() {\n try {\n return (this.tagName?.toLowerCase() ?? \"\") !== \"input\" ? !1 : String(this.type ?? \"\").toLowerCase() === \"file\";\n } catch {\n return !1;\n }\n}",
|
|
14
|
+
"fillElementValue": "function xe(e) {\n let t = this;\n if (!t.isConnected)\n return { status: \"error\", reason: \"notconnected\" };\n let o = (t.ownerDocument || document).defaultView || window, r = e ?? \"\";\n try {\n let l = (s) => {\n let i;\n if (typeof o.InputEvent == \"function\")\n try {\n i = new o.InputEvent(\"input\", { bubbles: !0, composed: !0, data: s, inputType: \"insertText\" });\n } catch {\n i = new o.Event(\"input\", { bubbles: !0, composed: !0 });\n }\n else\n i = new o.Event(\"input\", { bubbles: !0, composed: !0 });\n t.dispatchEvent(i);\n let a = new o.Event(\"change\", { bubbles: !0 });\n t.dispatchEvent(a);\n };\n if (t instanceof o.HTMLInputElement) {\n let s = (t.type || \"\").toLowerCase();\n if (!ne.has(s) && !$.has(s))\n return { status: \"error\", reason: `unsupported-input-type:${s}` };\n let i = e;\n if (s === \"number\") {\n let a = e.trim();\n if (a !== \"\" && Number.isNaN(Number(a)))\n return { status: \"error\", reason: \"invalid-number-value\" };\n i = a;\n }\n if (r = i, $.has(s)) {\n let a = e.trim();\n r = a, C.call(t);\n let d = o.HTMLInputElement.prototype, c = Object.getOwnPropertyDescriptor(d, \"value\")?.set;\n 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\" });\n }\n return C.call(t), { status: \"needsinput\", value: i };\n }\n return t instanceof o.HTMLTextAreaElement ? (C.call(t), r = e, { status: \"needsinput\", value: e }) : t instanceof o.HTMLSelectElement ? { status: \"error\", reason: \"unsupported-element\" } : t.isContentEditable ? (C.call(t), r = e, { status: \"needsinput\", value: e }) : { status: \"error\", reason: \"unsupported-element\" };\n } catch (l) {\n let s = \"exception\";\n if (l && typeof l == \"object\") {\n let i = l.message;\n typeof i == \"string\" && i.trim().length > 0 && (s = `exception:${i}`);\n }\n return { status: \"needsinput\", value: r, reason: s };\n }\n}",
|
|
15
|
+
"focusElement": "function Se() {\n try {\n typeof this.focus == \"function\" && this.focus();\n } catch {}\n}",
|
|
16
|
+
"isElementChecked": "function Re() {\n try {\n let e = this;\n if ((e.tagName || \"\").toLowerCase() === \"input\") {\n let o = e.type?.toLowerCase() ?? \"\";\n if (o === \"checkbox\" || o === \"radio\")\n return !!e.checked;\n }\n let n = e.getAttribute?.(\"aria-checked\");\n return n != null ? n === \"true\" : !1;\n } catch {\n return !1;\n }\n}",
|
|
17
|
+
"isElementVisible": "function Te() {\n try {\n let e = this;\n if (!e.isConnected)\n return !1;\n let t = e.ownerDocument?.defaultView?.getComputedStyle(e) ?? window.getComputedStyle(e);\n if (!t || t.display === \"none\" || t.visibility === \"hidden\")\n return !1;\n let n = parseFloat(t.opacity ?? \"1\");\n if (!Number.isFinite(n) || n === 0)\n return !1;\n let o = e.getBoundingClientRect();\n return !(!o || Math.max(o.width, o.height) === 0 || e.getClientRects().length === 0);\n } catch {\n return !1;\n }\n}",
|
|
18
|
+
"prepareElementForTyping": "function C() {\n try {\n let e = this;\n if (!e.isConnected)\n return !1;\n let t = e.ownerDocument || document, n = t.defaultView || window;\n try {\n typeof e.focus == \"function\" && e.focus();\n } catch {}\n if (e instanceof n.HTMLInputElement || e instanceof n.HTMLTextAreaElement) {\n try {\n if (typeof e.select == \"function\")\n return e.select(), !0;\n } catch {}\n try {\n let o = (e.value ?? \"\").length;\n if (typeof e.setSelectionRange == \"function\")\n return e.setSelectionRange(0, o), !0;\n } catch {}\n return !0;\n }\n if (e.isContentEditable) {\n let o = t.getSelection?.(), r = t.createRange?.();\n if (o && r)\n try {\n r.selectNodeContents(e), o.removeAllRanges(), o.addRange(r);\n } catch {}\n return !0;\n }\n return !1;\n } catch {\n return !1;\n }\n}",
|
|
19
|
+
"readElementInnerHTML": "function Me() {\n try {\n return String(this.innerHTML ?? \"\");\n } catch {\n return \"\";\n }\n}",
|
|
20
|
+
"readElementInnerText": "function Le() {\n try {\n let e = this, t = e.innerText;\n if (typeof t == \"string\" && t.length > 0)\n return t;\n let n = e.textContent;\n return typeof n == \"string\" ? n : \"\";\n } catch {\n return \"\";\n }\n}",
|
|
21
|
+
"readElementInputValue": "function Ce() {\n try {\n let e = this, t = (e.tagName || \"\").toLowerCase();\n return t === \"input\" || t === \"textarea\" || t === \"select\" ? String(e.value ?? \"\") : e.isContentEditable ? String(e.textContent ?? \"\") : \"\";\n } catch {\n return \"\";\n }\n}",
|
|
22
|
+
"readElementTextContent": "function Ne() {\n try {\n return String(this.textContent ?? \"\");\n } catch {\n return \"\";\n }\n}",
|
|
23
|
+
"resolveCssSelector": "function De(e, t) {\n let n = String(e ?? \"\").trim();\n if (!n)\n return null;\n let o = N(t);\n return z(n, o + 1)[o] ?? null;\n}",
|
|
24
|
+
"resolveCssSelectorPierce": "function He(e, t) {\n let n = String(e ?? \"\").trim();\n if (!n)\n return null;\n let o = N(t), r = window.__handstageV3__;\n if (!r || typeof r.getClosedRoot != \"function\")\n return z(n, o + 1)[o] ?? null;\n let l = (c) => {\n try {\n return r.getClosedRoot(c) ?? null;\n } catch {\n return null;\n }\n }, s = new WeakSet, i = new Set, a = [], d = [document], f = (c) => {\n if (!(!c || s.has(c) || a.length >= o + 1)) {\n s.add(c);\n try {\n let E = c.querySelectorAll(n);\n for (let p of E)\n if (!i.has(p) && (i.add(p), a.push(p), a.length >= o + 1))\n return;\n } catch {}\n try {\n let p = (c instanceof Document ? c : c.host?.ownerDocument ?? document).createTreeWalker(c, NodeFilter.SHOW_ELEMENT);\n for (let w = p.nextNode();w; w = p.nextNode()) {\n if (!(w instanceof Element))\n continue;\n let x = w.shadowRoot;\n x && d.push(x);\n let y = l(w);\n y && d.push(y);\n }\n } catch {}\n }\n };\n for (;d.length && a.length < o + 1; ) {\n let c = d.shift();\n c && f(c);\n }\n return a[o] ?? null;\n}",
|
|
25
|
+
"resolveTextSelector": "function Ae(e, t) {\n let n = String(e ?? \"\");\n if (!n)\n return null;\n let o = n.toLowerCase(), r = N(t), l = new Set([\"SCRIPT\", \"STYLE\", \"TEMPLATE\", \"NOSCRIPT\", \"HEAD\", \"TITLE\", \"LINK\", \"META\", \"HTML\", \"BODY\"]), s = (u) => {\n if (!u)\n return !1;\n let h = u.tagName?.toUpperCase() ?? \"\";\n return l.has(h);\n }, i = (u) => {\n try {\n if (s(u))\n return \"\";\n let h = u.innerText;\n if (typeof h == \"string\" && h.trim())\n return h.trim();\n } catch {}\n try {\n let h = u.textContent;\n if (typeof h == \"string\")\n return h.trim();\n } catch {}\n return \"\";\n }, a = (u) => {\n let h = i(u);\n return !!h && h.toLowerCase().includes(o);\n }, d = window.__handstageV3__, f = d && typeof d.getClosedRoot == \"function\" ? (u) => {\n try {\n return d.getClosedRoot(u) ?? null;\n } catch {\n return null;\n }\n } : (u) => null, c = new WeakSet, E = [], p = [], w = (u) => {\n !u || c.has(u) || (c.add(u), E.push(u));\n }, x = (u) => {\n try {\n return (u instanceof Document ? u : u?.ownerDocument ?? document).createTreeWalker(u, NodeFilter.SHOW_ELEMENT);\n } catch {\n return null;\n }\n };\n for (w(document);E.length; ) {\n let u = E.shift();\n if (!u)\n continue;\n u instanceof Element && a(u) && p.push({ element: u, tag: u.tagName ?? \"\", id: u.id ?? \"\", className: u.className ?? \"\", text: i(u) });\n let h = x(u);\n if (h)\n for (let g = h.nextNode();g; g = h.nextNode()) {\n if (!(g instanceof Element))\n continue;\n a(g) && p.push({ element: g, tag: g.tagName ?? \"\", id: g.id ?? \"\", className: g.className ?? \"\", text: i(g) });\n let b = g.shadowRoot;\n b && w(b);\n let k = f(g);\n k && w(k);\n }\n }\n let y = [];\n for (let u of p) {\n let h = u.element, g = !1;\n for (let b of p)\n if (u !== b)\n try {\n if (h.contains(b.element)) {\n g = !0;\n break;\n }\n } catch {}\n g || y.push(u);\n }\n return y[r]?.element ?? null;\n}",
|
|
26
|
+
"resolveXPathMainWorld": "function We(e, t) {\n let n = N(t);\n return P(e, n, { pierceShadow: !0 });\n}",
|
|
27
|
+
"scrollElementToPercent": "function be(e) {\n let t = (n) => {\n if (typeof n == \"number\" && Number.isFinite(n))\n return n;\n let o = String(n ?? \"\").trim();\n if (!o)\n return 0;\n let r = parseFloat(o.replace(\"%\", \"\"));\n return Number.isNaN(r) || !Number.isFinite(r) ? 0 : r;\n };\n try {\n let n = Math.max(0, Math.min(t(e), 100)), o = this, r = o.tagName?.toLowerCase() ?? \"\";\n if (r === \"html\" || r === \"body\") {\n let c = (o.ownerDocument?.scrollingElement || o.ownerDocument?.documentElement || o.ownerDocument?.body || document.scrollingElement || document.documentElement || document.body)?.scrollHeight ?? document.body.scrollHeight ?? 0, E = o.ownerDocument?.defaultView?.innerHeight ?? window.innerHeight, w = Math.max(0, c - E) * (n / 100);\n return o.ownerDocument?.defaultView?.scrollTo({ top: w, left: o.ownerDocument?.defaultView?.scrollX ?? window.scrollX ?? 0, behavior: \"smooth\" }), !0;\n }\n let s = o.scrollHeight ?? 0, i = o.clientHeight ?? 0, d = Math.max(0, s - i) * (n / 100);\n return o.scrollTo({ top: d, left: o.scrollLeft ?? 0, behavior: \"smooth\" }), !0;\n } catch {\n return !1;\n }\n}",
|
|
28
|
+
"selectElementOptions": "function ve(e) {\n try {\n if (!(this instanceof HTMLSelectElement))\n return [];\n let t = Array.isArray(e) ? e : [e], n = new Set(t.map((s) => String(s ?? \"\").trim())), o = (s) => {\n let i = (s.label || s.textContent || \"\").trim(), a = String(s.value ?? \"\").trim();\n return n.has(i) || n.has(a);\n };\n if (this.multiple)\n for (let s of Array.from(this.options))\n s.selected = o(s);\n else {\n let s = !1;\n for (let i of Array.from(this.options))\n !s && o(i) ? (i.selected = !0, this.value = i.value, s = !0) : i.selected = !1;\n }\n let r = new Event(\"input\", { bubbles: !0 }), l = new Event(\"change\", { bubbles: !0 });\n return this.dispatchEvent(r), this.dispatchEvent(l), Array.from(this.selectedOptions).map((s) => s.value);\n } catch {\n return [];\n }\n}",
|
|
29
|
+
"waitForSelector": "function _e(e, t, n, o) {\n let r = String(e ?? \"\").trim(), l = String(t ?? \"visible\") || \"visible\", s = typeof n == \"number\" && n > 0 ? n : 30000, i = o !== !1;\n return new Promise((a, d) => {\n let f = null, c = null, E = !1, p = () => {\n f !== null && (clearTimeout(f), f = null);\n }, w = V(r, i);\n if (B(w, l)) {\n E = !0, a(!0);\n return;\n }\n let x = [], y = () => {\n for (let g of x)\n g.disconnect();\n c && (document.removeEventListener(\"DOMContentLoaded\", c), c = null);\n }, m = () => {\n if (E)\n return;\n let g = V(r, i);\n B(g, l) && (E = !0, p(), y(), a(!0));\n };\n if (!(document.body || document.documentElement)) {\n c = () => {\n if (!c)\n throw Error(\"DOMContentLoaded handler missing during cleanup\");\n document.removeEventListener(\"DOMContentLoaded\", c), c = null, m(), h();\n }, document.addEventListener(\"DOMContentLoaded\", c), f = setTimeout(() => {\n E || (E = !0, p(), y(), d(Error(`waitForSelector: Timeout ${s}ms exceeded waiting for \"${r}\" to be ${l}`)));\n }, s);\n return;\n }\n let h = () => {\n let g = document.body || document.documentElement;\n if (!g)\n return;\n let b = new MutationObserver(m);\n b.observe(g, { childList: !0, subtree: !0, attributes: !0, attributeFilter: [\"style\", \"class\", \"hidden\", \"disabled\"] }), x.push(b), i && ie(m, x);\n };\n h(), f = setTimeout(() => {\n E || (E = !0, p(), y(), d(Error(`waitForSelector: Timeout ${s}ms exceeded waiting for \"${r}\" to be ${l}`)));\n }, s);\n });\n}"
|
|
30
30
|
};
|
|
31
31
|
export const locatorScriptGlobalRefs = {
|
|
32
|
-
assignFilePayloadsToInputElement: "globalThis.
|
|
33
|
-
countCssMatchesPierce: "globalThis.
|
|
34
|
-
countCssMatchesPrimary: "globalThis.
|
|
35
|
-
countTextMatches: "globalThis.
|
|
36
|
-
countXPathMatchesMainWorld: "globalThis.
|
|
37
|
-
dispatchDomClick: "globalThis.
|
|
38
|
-
ensureFileInputElement: "globalThis.
|
|
39
|
-
fillElementValue: "globalThis.
|
|
40
|
-
focusElement: "globalThis.
|
|
41
|
-
isElementChecked: "globalThis.
|
|
42
|
-
isElementVisible: "globalThis.
|
|
43
|
-
prepareElementForTyping: "globalThis.
|
|
44
|
-
readElementInnerHTML: "globalThis.
|
|
45
|
-
readElementInnerText: "globalThis.
|
|
46
|
-
readElementInputValue: "globalThis.
|
|
47
|
-
readElementTextContent: "globalThis.
|
|
48
|
-
resolveCssSelector: "globalThis.
|
|
49
|
-
resolveCssSelectorPierce: "globalThis.
|
|
50
|
-
resolveTextSelector: "globalThis.
|
|
51
|
-
resolveXPathMainWorld: "globalThis.
|
|
52
|
-
scrollElementToPercent: "globalThis.
|
|
53
|
-
selectElementOptions: "globalThis.
|
|
54
|
-
waitForSelector: "globalThis.
|
|
32
|
+
"assignFilePayloadsToInputElement": "globalThis.__handstageLocatorScripts.assignFilePayloadsToInputElement",
|
|
33
|
+
"countCssMatchesPierce": "globalThis.__handstageLocatorScripts.countCssMatchesPierce",
|
|
34
|
+
"countCssMatchesPrimary": "globalThis.__handstageLocatorScripts.countCssMatchesPrimary",
|
|
35
|
+
"countTextMatches": "globalThis.__handstageLocatorScripts.countTextMatches",
|
|
36
|
+
"countXPathMatchesMainWorld": "globalThis.__handstageLocatorScripts.countXPathMatchesMainWorld",
|
|
37
|
+
"dispatchDomClick": "globalThis.__handstageLocatorScripts.dispatchDomClick",
|
|
38
|
+
"ensureFileInputElement": "globalThis.__handstageLocatorScripts.ensureFileInputElement",
|
|
39
|
+
"fillElementValue": "globalThis.__handstageLocatorScripts.fillElementValue",
|
|
40
|
+
"focusElement": "globalThis.__handstageLocatorScripts.focusElement",
|
|
41
|
+
"isElementChecked": "globalThis.__handstageLocatorScripts.isElementChecked",
|
|
42
|
+
"isElementVisible": "globalThis.__handstageLocatorScripts.isElementVisible",
|
|
43
|
+
"prepareElementForTyping": "globalThis.__handstageLocatorScripts.prepareElementForTyping",
|
|
44
|
+
"readElementInnerHTML": "globalThis.__handstageLocatorScripts.readElementInnerHTML",
|
|
45
|
+
"readElementInnerText": "globalThis.__handstageLocatorScripts.readElementInnerText",
|
|
46
|
+
"readElementInputValue": "globalThis.__handstageLocatorScripts.readElementInputValue",
|
|
47
|
+
"readElementTextContent": "globalThis.__handstageLocatorScripts.readElementTextContent",
|
|
48
|
+
"resolveCssSelector": "globalThis.__handstageLocatorScripts.resolveCssSelector",
|
|
49
|
+
"resolveCssSelectorPierce": "globalThis.__handstageLocatorScripts.resolveCssSelectorPierce",
|
|
50
|
+
"resolveTextSelector": "globalThis.__handstageLocatorScripts.resolveTextSelector",
|
|
51
|
+
"resolveXPathMainWorld": "globalThis.__handstageLocatorScripts.resolveXPathMainWorld",
|
|
52
|
+
"scrollElementToPercent": "globalThis.__handstageLocatorScripts.scrollElementToPercent",
|
|
53
|
+
"selectElementOptions": "globalThis.__handstageLocatorScripts.selectElementOptions",
|
|
54
|
+
"waitForSelector": "globalThis.__handstageLocatorScripts.waitForSelector"
|
|
55
55
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const reRenderScriptContent = '"use strict";(()=>{function s(){try{let o=window.
|
|
1
|
+
export const reRenderScriptContent = '"use strict";(()=>{function s(){try{let o=window.__handstageV3__;if(!o||typeof o.getClosedRoot!="function")return;let t=[],r=document.createTreeWalker(document,NodeFilter.SHOW_ELEMENT);for(;r.nextNode();){let e=r.currentNode,n=e.tagName?.toLowerCase()??"";if(!n.includes("-")||typeof customElements?.get!="function"||!customElements.get(n))continue;let c=!!e.shadowRoot,i=!!o.getClosedRoot(e);c||i||t.push(e)}for(let e of t)try{let n=e.cloneNode(!0);e.replaceWith(n)}catch{}o.stats&&t.length&&console.info("[v3-piercer] rerender",{count:t.length})}catch(o){console.info("[v3-piercer] rerender error",{message:String(o??"")})}}s();})();\n';
|
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
* Update sources in pkgs/dom/src/screenshotScripts and run genScreenshotScripts.ts.
|
|
4
4
|
*/
|
|
5
5
|
export const screenshotScriptSources = {
|
|
6
|
-
resolveMaskRect:
|
|
6
|
+
"resolveMaskRect": "function h(r) {\n function u(t, e) {\n try {\n return t && typeof t.closest == \"function\" ? t.closest(e) : null;\n } catch {\n return null;\n }\n }\n function s(t, e) {\n try {\n return !!t && typeof t.matches == \"function\" && t.matches(e);\n } catch {\n return !1;\n }\n }\n function c(t) {\n let e = u(t, \"dialog[open]\");\n if (e)\n return e;\n let l = u(t, \"[popover]\");\n return l && s(l, \":popover-open\") ? l : null;\n }\n if (!this || typeof this.getBoundingClientRect != \"function\")\n return null;\n let n = this.getBoundingClientRect();\n if (!n)\n return null;\n let i = window.getComputedStyle(this);\n if (!i || i.visibility === \"hidden\" || i.display === \"none\" || n.width <= 0 || n.height <= 0)\n return null;\n let o = c(this);\n if (o) {\n let t = o.getBoundingClientRect();\n if (!t)\n return null;\n let e = null;\n if (r)\n try {\n let l = o.getAttribute(\"data-handstage-mask-root\");\n l?.startsWith(r) ? e = l : (e = `${r}_root_${Math.random().toString(36).slice(2)}`, o.setAttribute(\"data-handstage-mask-root\", e));\n } catch {\n e = null;\n }\n return { x: n.left - t.left - (o.clientLeft || 0) + (o.scrollLeft || 0), y: n.top - t.top - (o.clientTop || 0) + (o.scrollTop || 0), width: n.width, height: n.height, rootToken: e };\n }\n return { x: n.left + window.scrollX, y: n.top + window.scrollY, width: n.width, height: n.height, rootToken: null };\n}"
|
|
7
7
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const v3ScriptContent = '"use strict";(()=>{function s(c={}){let r=e=>{let{hostToRoot:o}=e;window.
|
|
1
|
+
export const v3ScriptContent = '"use strict";(()=>{function s(c={}){let r=e=>{let{hostToRoot:o}=e;window.__handstageV3__={getClosedRoot:a=>o.get(a),stats:()=>({installed:!0,url:location.href,isTop:window.top===window,open:e.openCount,closed:e.closedCount})}},n=Element.prototype.attachShadow;if(n.__v3Patched&&n.__v3State){n.__v3State.debug=!0,r(n.__v3State);return}let t={hostToRoot:new WeakMap,openCount:0,closedCount:0,debug:!0},l=n,d=function(e){let o=e?.mode??"open",a=l.call(this,e);try{t.hostToRoot.set(this,a),o==="closed"?t.closedCount++:t.openCount++,t.debug&&console.info("[v3-piercer] attachShadow",{tag:this.tagName?.toLowerCase()??"",mode:o,url:location.href})}catch{}return a};if(d.__v3Patched=!0,d.__v3State=t,Object.defineProperty(Element.prototype,"attachShadow",{configurable:!0,writable:!0,value:d}),c.tagExisting)try{let e=document.createTreeWalker(document,NodeFilter.SHOW_ELEMENT);for(;e.nextNode();){let o=e.currentNode;o.shadowRoot&&(t.hostToRoot.set(o,o.shadowRoot),t.openCount++)}}catch{}window.__handstageV3Injected=!0,r(t),t.debug&&console.info("[v3-piercer] installed",{url:location.href,isTop:window.top===window,readyState:document.readyState})}s({debug:!0,tagExisting:!1});})();\n';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@handstage/dom",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"src/build/a11yScripts.generated.ts"
|
|
39
39
|
],
|
|
40
40
|
"scripts": {
|
|
41
|
-
"build": "tsc -p tsconfig.build.json",
|
|
41
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
42
42
|
"build-dom-scripts": "bun run build-dom-scripts:dom & bun run build-dom-scripts:locator & bun run build-dom-scripts:screenshot & bun run build-dom-scripts:a11y & wait",
|
|
43
43
|
"build-dom-scripts:dom": "bun src/genDomScripts.ts",
|
|
44
44
|
"build-dom-scripts:locator": "bun src/genLocatorScripts.ts",
|
|
@@ -46,9 +46,9 @@
|
|
|
46
46
|
"build-dom-scripts:a11y": "bun src/genA11yScripts.ts"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@types/bun": "
|
|
50
|
-
"@types/node": "^
|
|
51
|
-
"esbuild": "^0.
|
|
52
|
-
"typescript": "^
|
|
49
|
+
"@types/bun": "1.3.14",
|
|
50
|
+
"@types/node": "^25.9.1",
|
|
51
|
+
"esbuild": "^0.28.0",
|
|
52
|
+
"typescript": "^6.0.3"
|
|
53
53
|
}
|
|
54
54
|
}
|
|
@@ -2,27 +2,19 @@
|
|
|
2
2
|
* AUTO-GENERATED FILE. DO NOT EDIT.
|
|
3
3
|
* Update sources in pkgs/dom/src/a11yScripts and run genA11yScripts.ts.
|
|
4
4
|
*/
|
|
5
|
-
export const a11yScriptBootstrap =
|
|
6
|
-
'if (!globalThis.__stagehandA11yScripts) { "use strict";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}'
|
|
5
|
+
export const a11yScriptBootstrap = "if (!globalThis.__handstageA11yScripts) { \"use strict\";var __handstageA11yScriptsFactory=(()=>{var d=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var N=(n,t)=>{for(var o in t)d(n,o,{get:t[o],enumerable:!0})},h=(n,t,o,i)=>{if(t&&typeof t==\"object\"||typeof t==\"function\")for(let u of f(t))!p.call(n,u)&&u!==o&&d(n,u,{get:()=>t[u],enumerable:!(i=a(t,u))||i.enumerable});return n};var E=n=>h(d({},\"__esModule\",{value:!0}),n);var b={};N(b,{documentHasFocusStrict:()=>g,getBoundingRectLite:()=>w,getScrollOffsets:()=>y,nodeToAbsoluteXPath:()=>$,resolveDeepActiveElement:()=>T});function y(){try{let n=window.scrollX??window.pageXOffset??document.documentElement?.scrollLeft??0,t=window.scrollY??window.pageYOffset??document.documentElement?.scrollTop??0;return{sx:Number(n)||0,sy:Number(t)||0}}catch{return{sx:0,sy:0}}}function w(){try{let n=this.getBoundingClientRect();return{left:Number(n?.left??0)||0,top:Number(n?.top??0)||0}}catch{return{left:0,top:0}}}function T(){try{return(t=>{let o=t.activeElement??null;for(;o?.shadowRoot?.activeElement;)o=o.shadowRoot.activeElement;return o??null})(document)}catch{return null}}function $(){return(t=>{try{let o=e=>{if(!e?.parentNode)return 1;let s=1,m=`${e.nodeType}:${(e.nodeName||\"\").toLowerCase()}`;for(let c=e.previousSibling;c;c=c.previousSibling)`${c.nodeType}:${(c.nodeName||\"\").toLowerCase()}`===m&&(s+=1);return s},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()[${o(e)}]`;if(e.nodeType===Node.COMMENT_NODE)return`comment()[${o(e)}]`;let s=(e.nodeName||\"\").toLowerCase();return`${s.includes(\":\")?`*[name()='${s}']`:s}[${o(e)}]`},u=[],l=t;for(;l;){if(l.nodeType===Node.DOCUMENT_FRAGMENT_NODE){u.push(\"//\"),l=l.host??null;continue}let e=i(l);e&&u.push(e),l=l.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.__handstageA11yScripts = __handstageA11yScriptsFactory;\n}";
|
|
7
6
|
export const a11yScriptSources = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
nodeToAbsoluteXPath:
|
|
15
|
-
'function N() {\n return ((s) => {\n try {\n let n = (e) => {\n if (!e || !e.parentNode)\n return 1;\n let u = 1, d = `${e.nodeType}:${(e.nodeName || "").toLowerCase()}`;\n for (let l = e.previousSibling;l; l = l.previousSibling)\n `${l.nodeType}:${(l.nodeName || "").toLowerCase()}` === d && (u += 1);\n return u;\n }, i = (e) => {\n if (!e || e.nodeType === Node.DOCUMENT_NODE)\n return "";\n if (e.nodeType === Node.DOCUMENT_FRAGMENT_NODE)\n return "//";\n if (e.nodeType === Node.TEXT_NODE)\n return `text()[${n(e)}]`;\n if (e.nodeType === Node.COMMENT_NODE)\n return `comment()[${n(e)}]`;\n let u = (e.nodeName || "").toLowerCase();\n return `${u.includes(":") ? `*[name()=\'${u}\']` : u}[${n(e)}]`;\n }, c = [], o = s;\n for (;o; ) {\n if (o.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {\n c.push("//"), o = o.host ?? null;\n continue;\n }\n let e = i(o);\n e && c.push(e), o = o.parentNode;\n }\n c.reverse();\n let t = "";\n for (let e of c)\n e === "//" ? t = t ? t.endsWith("/") ? `${t}/` : `${t}//` : "//" : t = t ? t.endsWith("/") ? `${t}${e}` : `${t}/${e}` : `/${e}`;\n return t || "/";\n } catch {\n return "/";\n }\n })(this);\n}',
|
|
16
|
-
resolveDeepActiveElement:
|
|
17
|
-
"function p() {\n try {\n return ((s) => {\n let n = s.activeElement ?? null;\n for (;n && n.shadowRoot && n.shadowRoot.activeElement; )\n n = n.shadowRoot.activeElement;\n return n ?? null;\n })(document);\n } catch {\n return null;\n }\n}",
|
|
18
|
-
} as const
|
|
7
|
+
"documentHasFocusStrict": "function h() {\n try {\n return document.hasFocus() === !0;\n } catch {\n return !1;\n }\n}",
|
|
8
|
+
"getBoundingRectLite": "function f() {\n try {\n let r = this.getBoundingClientRect();\n return { left: Number(r?.left ?? 0) || 0, top: Number(r?.top ?? 0) || 0 };\n } catch {\n return { left: 0, top: 0 };\n }\n}",
|
|
9
|
+
"getScrollOffsets": "function a() {\n try {\n let r = window.scrollX ?? window.pageXOffset ?? document.documentElement?.scrollLeft ?? 0, l = window.scrollY ?? window.pageYOffset ?? document.documentElement?.scrollTop ?? 0;\n return { sx: Number(r) || 0, sy: Number(l) || 0 };\n } catch {\n return { sx: 0, sy: 0 };\n }\n}",
|
|
10
|
+
"nodeToAbsoluteXPath": "function N() {\n return ((l) => {\n try {\n let n = (e) => {\n if (!e?.parentNode)\n return 1;\n let u = 1, i = `${e.nodeType}:${(e.nodeName || \"\").toLowerCase()}`;\n for (let s = e.previousSibling;s; s = s.previousSibling)\n `${s.nodeType}:${(s.nodeName || \"\").toLowerCase()}` === i && (u += 1);\n return u;\n }, d = (e) => {\n if (!e || e.nodeType === Node.DOCUMENT_NODE)\n return \"\";\n if (e.nodeType === Node.DOCUMENT_FRAGMENT_NODE)\n return \"//\";\n if (e.nodeType === Node.TEXT_NODE)\n return `text()[${n(e)}]`;\n if (e.nodeType === Node.COMMENT_NODE)\n return `comment()[${n(e)}]`;\n let u = (e.nodeName || \"\").toLowerCase();\n return `${u.includes(\":\") ? `*[name()='${u}']` : u}[${n(e)}]`;\n }, c = [], o = l;\n for (;o; ) {\n if (o.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {\n c.push(\"//\"), o = o.host ?? null;\n continue;\n }\n let e = d(o);\n e && c.push(e), o = o.parentNode;\n }\n c.reverse();\n let t = \"\";\n for (let e of c)\n e === \"//\" ? t = t ? t.endsWith(\"/\") ? `${t}/` : `${t}//` : \"//\" : t = t ? t.endsWith(\"/\") ? `${t}${e}` : `${t}/${e}` : `/${e}`;\n return t || \"/\";\n } catch {\n return \"/\";\n }\n })(this);\n}",
|
|
11
|
+
"resolveDeepActiveElement": "function p() {\n try {\n return ((l) => {\n let n = l.activeElement ?? null;\n for (;n?.shadowRoot?.activeElement; )\n n = n.shadowRoot.activeElement;\n return n ?? null;\n })(document);\n } catch {\n return null;\n }\n}"
|
|
12
|
+
} as const;
|
|
19
13
|
export const a11yScriptGlobalRefs = {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
} as const
|
|
28
|
-
export type A11yScriptName = keyof typeof a11yScriptSources
|
|
14
|
+
"documentHasFocusStrict": "globalThis.__handstageA11yScripts.documentHasFocusStrict",
|
|
15
|
+
"getBoundingRectLite": "globalThis.__handstageA11yScripts.getBoundingRectLite",
|
|
16
|
+
"getScrollOffsets": "globalThis.__handstageA11yScripts.getScrollOffsets",
|
|
17
|
+
"nodeToAbsoluteXPath": "globalThis.__handstageA11yScripts.nodeToAbsoluteXPath",
|
|
18
|
+
"resolveDeepActiveElement": "globalThis.__handstageA11yScripts.resolveDeepActiveElement"
|
|
19
|
+
} as const;
|
|
20
|
+
export type A11yScriptName = keyof typeof a11yScriptSources;
|
|
@@ -2,94 +2,55 @@
|
|
|
2
2
|
* AUTO-GENERATED FILE. DO NOT EDIT.
|
|
3
3
|
* Update sources in pkgs/dom/src/locatorScripts and run genLocatorScripts.ts.
|
|
4
4
|
*/
|
|
5
|
-
export const locatorScriptBootstrap =
|
|
6
|
-
'if (!globalThis.__stagehandLocatorScripts) { "use strict";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:()=>he,countCssMatchesPierce:()=>ue,countCssMatchesPrimary:()=>ce,countTextMatches:()=>de,countXPathMatchesMainWorld:()=>me,dispatchDomClick:()=>pe,ensureFileInputElement:()=>fe,fillElementValue:()=>we,focusElement:()=>ye,isElementChecked:()=>Se,isElementVisible:()=>xe,prepareElementForTyping:()=>v,readElementInnerHTML:()=>Re,readElementInnerText:()=>Ne,readElementInputValue:()=>ve,readElementTextContent:()=>Te,resolveCssSelector:()=>Ce,resolveCssSelectorPierce:()=>Me,resolveTextSelector:()=>Le,resolveXPathMainWorld:()=>Pe,scrollElementToPercent:()=>ge,selectElementOptions:()=>be,waitForSelector:()=>_e});function _(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}=te(a);n.push({axis:r,tag:d,predicates:f})}return n}function ee(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 te(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 ee(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=H(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=H(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=re(t,"not");if(r!=null){let l=T(r);return l?{type:"not",predicate:l}:null}return ne(t)}function ne(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 H(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&&oe(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 oe(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 A(o)&&A(r)}function A(e){return!/[a-zA-Z0-9_.-]/.test(e)}function re(e,t){let n=`${t}(`;if(!e.startsWith(n)||!e.endsWith(")"))return null;let o=e.slice(n.length,-1);return se(o)?o:null}function se(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 le=e=>e.replace(/\\s+/g," ").trim();function W(e){return String(e.textContent??"")}function S(e,t){return t?le(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(W(e),t.normalize)===S(t.value,t.normalize);case"textContains":return S(W(e),t.normalize).includes(S(t.value,t.normalize));case"index":return!0;default:return!0}}function O(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 F(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?$():null;if(!l)return q(o,r).value;if(!s?.hasShadow){let a=q(o,r);return a.error?N(o,s?.getClosedRoot)[r]??null:a.value}return N(o,s.getClosedRoot)[r]??null}function I(e,t){let n=P(e);if(!n)return 0;let o=t?.pierceShadow!==!1,r=o?$():null;if(!o)return X(n).count;if(!r?.hasShadow){let l=X(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=_(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):ae(d,r);if(!f.length)continue;let c=f.filter(g=>ie(g,s)),p=O(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 ie(e,t){return t.tag==="*"?!0:e.localName===t.tag}function $(){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 ae(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 q(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 X(e){try{return{count:document.evaluate(e,document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotLength,error:!1}}catch{return{count:0,error:!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 ue(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 de(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 me(e){return I(e,{pierceShadow:!0})}function fe(){try{return(this.tagName?.toLowerCase()??"")!=="input"?!1:String(this.type??"").toLowerCase()==="file"}catch{return!1}}function he(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 pe(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 ge(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 z=new Set(["color","date","datetime-local","month","range","time","week"]),Ee=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 we(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(!Ee.has(s)&&!z.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,z.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 ye(){try{typeof this.focus=="function"&&this.focus()}catch{}}function be(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 xe(){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 Se(){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 ve(){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 Te(){try{return String(this.textContent??"")}catch{return""}}function Re(){try{return String(this.innerHTML??"")}catch{return""}}function Ne(){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""}}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 Ce(e,t){let n=String(e??"").trim();if(!n)return null;let o=C(t);return V(n,o+1)[o]??null}function Me(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 Le(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 Pe(e,t){let n=C(t);return k(e,n,{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)=>F(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}'
|
|
5
|
+
export const locatorScriptBootstrap = "if (!globalThis.__handstageLocatorScripts) { \"use strict\";var __handstageLocatorScriptsFactory=(()=>{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 Xe={};Z(Xe,{assignFilePayloadsToInputElement:()=>he,countCssMatchesPierce:()=>ue,countCssMatchesPrimary:()=>ce,countTextMatches:()=>de,countXPathMatchesMainWorld:()=>me,dispatchDomClick:()=>pe,ensureFileInputElement:()=>fe,fillElementValue:()=>we,focusElement:()=>ye,isElementChecked:()=>Se,isElementVisible:()=>xe,prepareElementForTyping:()=>v,readElementInnerHTML:()=>Re,readElementInnerText:()=>Ce,readElementInputValue:()=>ve,readElementTextContent:()=>Te,resolveCssSelector:()=>Ne,resolveCssSelectorPierce:()=>Me,resolveTextSelector:()=>Le,resolveXPathMainWorld:()=>Pe,scrollElementToPercent:()=>ge,selectElementOptions:()=>be,waitForSelector:()=>Oe});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}=te(a);n.push({axis:r,tag:d,predicates:f})}return n}function ee(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 te(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 ee(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=H(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=H(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=re(t,\"not\");if(r!=null){let l=T(r);return l?{type:\"not\",predicate:l}:null}return ne(t)}function ne(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 H(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&&oe(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 oe(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 A(o)&&A(r)}function A(e){return!/[a-zA-Z0-9_.-]/.test(e)}function re(e,t){let n=`${t}(`;if(!e.startsWith(n)||!e.endsWith(\")\"))return null;let o=e.slice(n.length,-1);return se(o)?o:null}function se(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 le=e=>e.replace(/\\s+/g,\" \").trim();function W(e){return String(e.textContent??\"\")}function S(e,t){return t?le(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(W(e),t.normalize)===S(t.value,t.normalize);case\"textContains\":return S(W(e),t.normalize).includes(S(t.value,t.normalize));case\"index\":return!0;default:return!0}}function X(e,t){let n=e;for(let o of t){if(!n.length)return[];if(o.type===\"index\"){let r=o.index-1;if(r>=0&&r<n.length){let l=n[r];if(!l)throw new Error(\"XPath predicate index resolved empty\");n=[l]}else n=[];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 F(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?$():null;if(!l)return _(o,r).value;if(!s?.hasShadow){let a=_(o,r);return a.error?C(o,s?.getClosedRoot)[r]??null:a.value}return C(o,s.getClosedRoot)[r]??null}function I(e,t){let n=P(e);if(!n)return 0;let o=t?.pierceShadow!==!1,r=o?$():null;if(!o)return q(n).count;if(!r?.hasShadow){let l=q(n);return l.error?C(n,r?.getClosedRoot).length:l.count}return C(n,r.getClosedRoot).length}function C(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):ae(d,r);if(!f.length)continue;let c=f.filter(p=>ie(p,s)),E=X(c,s.predicates);for(let p of E)a.has(p)||(a.add(p),i.push(p))}if(!i.length)return[];l=i}return l}function ie(e,t){return t.tag===\"*\"?!0:e.localName===t.tag}function $(){let e=window.__handstageV3__,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 ae(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){let a=s[i];if(!a)throw new Error(\"XPath composed child missing during traversal\");r.push(a)}}return n}function _(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 q(e){try{return{count:document.evaluate(e,document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotLength,error:!1}}catch{return{count:0,error:!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);for(let a=i.nextNode();a;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 ue(e){let t=String(e??\"\").trim();if(!t)return 0;let n=window.__handstageV3__;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);for(let c=f.nextNode();c;c=f.nextNode())c instanceof Element&&i(c)}catch{}}}return s}function de(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.__handstageV3__,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))},E=m=>{try{return(m instanceof Document?m:m?.ownerDocument??document).createTreeWalker(m,NodeFilter.SHOW_ELEMENT)}catch{return null}},p=[];for(c(document);f.length;){let m=f.shift();if(!m)continue;m instanceof Element&&s(m)&&p.push({element:m,tag:m.tagName??\"\",id:m.id??\"\",className:m.className??\"\",text:l(m)});let u=E(m);if(u)for(let h=u.nextNode();h;h=u.nextNode()){if(!(h instanceof Element))continue;s(h)&&p.push({element:h,tag:h.tagName??\"\",id:h.id??\"\",className:h.className??\"\",text:l(h)});let g=h.shadowRoot;g&&c(g);let b=a(h);b&&c(b)}}let w=[];for(let m of p){let u=m.element,h=!1;for(let g of p)if(m!==g)try{if(u.contains(g.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 me(e){return I(e,{pierceShadow:!0})}function fe(){try{return(this.tagName?.toLowerCase()??\"\")!==\"input\"?!1:String(this.type??\"\").toLowerCase()===\"file\"}catch{return!1}}function he(e){try{let t=this;if(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 E=0;E<a.length;E+=1)d[E]=a.charCodeAt(E);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 pe(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 ge(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,E=o.ownerDocument?.defaultView?.innerHeight??window.innerHeight,w=Math.max(0,c-E)*(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 z=new Set([\"color\",\"date\",\"datetime-local\",\"month\",\"range\",\"time\",\"week\"]),Ee=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 we(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(!Ee.has(s)&&!z.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,z.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 ye(){try{typeof this.focus==\"function\"&&this.focus()}catch{}}function be(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 xe(){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 Se(){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 ve(){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 Te(){try{return String(this.textContent??\"\")}catch{return\"\"}}function Re(){try{return String(this.innerHTML??\"\")}catch{return\"\"}}function Ce(){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\"\"}}var N=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);for(let f=d.nextNode();f;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 Ne(e,t){let n=String(e??\"\").trim();if(!n)return null;let o=N(t);return V(n,o+1)[o]??null}function Me(e,t){let n=String(e??\"\").trim();if(!n)return null;let o=N(t),r=window.__handstageV3__;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 E=c.querySelectorAll(n);for(let p of E)if(!i.has(p)&&(i.add(p),a.push(p),a.length>=o+1))return}catch{}try{let p=(c instanceof Document?c:c.host?.ownerDocument??document).createTreeWalker(c,NodeFilter.SHOW_ELEMENT);for(let w=p.nextNode();w;w=p.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 Le(e,t){let n=String(e??\"\");if(!n)return null;let o=n.toLowerCase(),r=N(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.__handstageV3__,f=d&&typeof d.getClosedRoot==\"function\"?u=>{try{return d.getClosedRoot(u)??null}catch{return null}}:u=>null,c=new WeakSet,E=[],p=[],w=u=>{!u||c.has(u)||(c.add(u),E.push(u))},x=u=>{try{return(u instanceof Document?u:u?.ownerDocument??document).createTreeWalker(u,NodeFilter.SHOW_ELEMENT)}catch{return null}};for(w(document);E.length;){let u=E.shift();if(!u)continue;u instanceof Element&&a(u)&&p.push({element:u,tag:u.tagName??\"\",id:u.id??\"\",className:u.className??\"\",text:i(u)});let h=x(u);if(h)for(let g=h.nextNode();g;g=h.nextNode()){if(!(g instanceof Element))continue;a(g)&&p.push({element:g,tag:g.tagName??\"\",id:g.id??\"\",className:g.className??\"\",text:i(g)});let b=g.shadowRoot;b&&w(b);let D=f(g);D&&w(D)}}let y=[];for(let u of p){let h=u.element,g=!1;for(let b of p)if(u!==b)try{if(h.contains(b.element)){g=!0;break}}catch{}g||y.push(u)}return y[r]?.element??null}function Pe(e,t){let n=N(t);return k(e,n,{pierceShadow:!0})}var ke=e=>e.startsWith(\"xpath=\")||e.startsWith(\"/\"),De=e=>{try{let t=window.__handstageV3__;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);for(let a=i.nextNode();a;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)=>F(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 Oe(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,E=!1,p=()=>{f!==null&&(clearTimeout(f),f=null)},w=B(r,i);if(G(w,l)){E=!0,a(!0);return}let x=[],y=()=>{for(let g of x)g.disconnect();c&&(document.removeEventListener(\"DOMContentLoaded\",c),c=null)},m=()=>{if(E)return;let g=B(r,i);G(g,l)&&(E=!0,p(),y(),a(!0))};if(!(document.body||document.documentElement)){c=()=>{if(!c)throw new Error(\"DOMContentLoaded handler missing during cleanup\");document.removeEventListener(\"DOMContentLoaded\",c),c=null,m(),h()},document.addEventListener(\"DOMContentLoaded\",c),f=setTimeout(()=>{E||(E=!0,p(),y(),d(new Error(`waitForSelector: Timeout ${s}ms exceeded waiting for \"${r}\" to be ${l}`)))},s);return}let h=()=>{let g=document.body||document.documentElement;if(!g)return;let b=new MutationObserver(m);b.observe(g,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[\"style\",\"class\",\"hidden\",\"disabled\"]}),x.push(b),i&&We(m,x)};h(),f=setTimeout(()=>{E||(E=!0,p(),y(),d(new Error(`waitForSelector: Timeout ${s}ms exceeded waiting for \"${r}\" to be ${l}`)))},s)})}return J(Xe);})();\n globalThis.__handstageLocatorScripts = __handstageLocatorScriptsFactory;\n}";
|
|
7
6
|
export const locatorScriptSources = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
readElementInnerHTML:
|
|
33
|
-
'function Me() {\n try {\n return String(this.innerHTML ?? "");\n } catch {\n return "";\n }\n}',
|
|
34
|
-
readElementInnerText:
|
|
35
|
-
'function Le() {\n try {\n let e = this, t = e.innerText;\n if (typeof t == "string" && t.length > 0)\n return t;\n let n = e.textContent;\n return typeof n == "string" ? n : "";\n } catch {\n return "";\n }\n}',
|
|
36
|
-
readElementInputValue:
|
|
37
|
-
'function Ne() {\n try {\n let e = this, t = (e.tagName || "").toLowerCase();\n return t === "input" || t === "textarea" || t === "select" ? String(e.value ?? "") : e.isContentEditable ? String(e.textContent ?? "") : "";\n } catch {\n return "";\n }\n}',
|
|
38
|
-
readElementTextContent:
|
|
39
|
-
'function Ce() {\n try {\n return String(this.textContent ?? "");\n } catch {\n return "";\n }\n}',
|
|
40
|
-
resolveCssSelector:
|
|
41
|
-
'function De(e, t) {\n let n = String(e ?? "").trim();\n if (!n)\n return null;\n let o = C(t);\n return z(n, o + 1)[o] ?? null;\n}',
|
|
42
|
-
resolveCssSelectorPierce:
|
|
43
|
-
'function He(e, t) {\n let n = String(e ?? "").trim();\n if (!n)\n return null;\n let o = C(t), r = window.__stagehandV3__;\n if (!r || typeof r.getClosedRoot != "function")\n return z(n, o + 1)[o] ?? null;\n let l = (c) => {\n try {\n return r.getClosedRoot(c) ?? null;\n } catch {\n return null;\n }\n }, s = new WeakSet, i = new Set, a = [], d = [document], f = (c) => {\n if (!(!c || s.has(c) || a.length >= o + 1)) {\n s.add(c);\n try {\n let p = c.querySelectorAll(n);\n for (let g of p)\n if (!i.has(g) && (i.add(g), a.push(g), a.length >= o + 1))\n return;\n } catch {}\n try {\n let g = (c instanceof Document ? c : c.host?.ownerDocument ?? document).createTreeWalker(c, NodeFilter.SHOW_ELEMENT), w;\n for (;w = g.nextNode(); ) {\n if (!(w instanceof Element))\n continue;\n let x = w.shadowRoot;\n x && d.push(x);\n let y = l(w);\n y && d.push(y);\n }\n } catch {}\n }\n };\n for (;d.length && a.length < o + 1; ) {\n let c = d.shift();\n c && f(c);\n }\n return a[o] ?? null;\n}',
|
|
44
|
-
resolveTextSelector:
|
|
45
|
-
'function Ae(e, t) {\n let n = String(e ?? "");\n if (!n)\n return null;\n let o = n.toLowerCase(), r = C(t), l = new Set(["SCRIPT", "STYLE", "TEMPLATE", "NOSCRIPT", "HEAD", "TITLE", "LINK", "META", "HTML", "BODY"]), s = (u) => {\n if (!u)\n return !1;\n let h = u.tagName?.toUpperCase() ?? "";\n return l.has(h);\n }, i = (u) => {\n try {\n if (s(u))\n return "";\n let h = u.innerText;\n if (typeof h == "string" && h.trim())\n return h.trim();\n } catch {}\n try {\n let h = u.textContent;\n if (typeof h == "string")\n return h.trim();\n } catch {}\n return "";\n }, a = (u) => {\n let h = i(u);\n return !!h && h.toLowerCase().includes(o);\n }, d = window.__stagehandV3__, f = d && typeof d.getClosedRoot == "function" ? (u) => {\n try {\n return d.getClosedRoot(u) ?? null;\n } catch {\n return null;\n }\n } : (u) => null, c = new WeakSet, p = [], g = [], w = (u) => {\n !u || c.has(u) || (c.add(u), p.push(u));\n }, x = (u) => {\n try {\n return (u instanceof Document ? u : u?.ownerDocument ?? document).createTreeWalker(u, NodeFilter.SHOW_ELEMENT);\n } catch {\n return null;\n }\n };\n for (w(document);p.length; ) {\n let u = p.shift();\n if (!u)\n continue;\n u instanceof Element && a(u) && g.push({ element: u, tag: u.tagName ?? "", id: u.id ?? "", className: u.className ?? "", text: i(u) });\n let h = x(u);\n if (!h)\n continue;\n let E;\n for (;E = h.nextNode(); ) {\n if (!(E instanceof Element))\n continue;\n a(E) && g.push({ element: E, tag: E.tagName ?? "", id: E.id ?? "", className: E.className ?? "", text: i(E) });\n let b = E.shadowRoot;\n b && w(b);\n let k = f(E);\n k && w(k);\n }\n }\n let y = [];\n for (let u of g) {\n let h = u.element, E = !1;\n for (let b of g)\n if (u !== b)\n try {\n if (h.contains(b.element)) {\n E = !0;\n break;\n }\n } catch {}\n E || y.push(u);\n }\n return y[r]?.element ?? null;\n}',
|
|
46
|
-
resolveXPathMainWorld:
|
|
47
|
-
"function We(e, t) {\n let n = C(t);\n return P(e, n, { pierceShadow: !0 });\n}",
|
|
48
|
-
scrollElementToPercent:
|
|
49
|
-
'function be(e) {\n let t = (n) => {\n if (typeof n == "number" && Number.isFinite(n))\n return n;\n let o = String(n ?? "").trim();\n if (!o)\n return 0;\n let r = parseFloat(o.replace("%", ""));\n return Number.isNaN(r) || !Number.isFinite(r) ? 0 : r;\n };\n try {\n let n = Math.max(0, Math.min(t(e), 100)), o = this, r = o.tagName?.toLowerCase() ?? "";\n if (r === "html" || r === "body") {\n 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);\n return o.ownerDocument?.defaultView?.scrollTo({ top: w, left: o.ownerDocument?.defaultView?.scrollX ?? window.scrollX ?? 0, behavior: "smooth" }), !0;\n }\n let s = o.scrollHeight ?? 0, i = o.clientHeight ?? 0, d = Math.max(0, s - i) * (n / 100);\n return o.scrollTo({ top: d, left: o.scrollLeft ?? 0, behavior: "smooth" }), !0;\n } catch {\n return !1;\n }\n}',
|
|
50
|
-
selectElementOptions:
|
|
51
|
-
'function ve(e) {\n try {\n if (!(this instanceof HTMLSelectElement))\n return [];\n let t = Array.isArray(e) ? e : [e], n = new Set(t.map((s) => String(s ?? "").trim())), o = (s) => {\n let i = (s.label || s.textContent || "").trim(), a = String(s.value ?? "").trim();\n return n.has(i) || n.has(a);\n };\n if (this.multiple)\n for (let s of Array.from(this.options))\n s.selected = o(s);\n else {\n let s = !1;\n for (let i of Array.from(this.options))\n !s && o(i) ? (i.selected = !0, this.value = i.value, s = !0) : i.selected = !1;\n }\n let r = new Event("input", { bubbles: !0 }), l = new Event("change", { bubbles: !0 });\n return this.dispatchEvent(r), this.dispatchEvent(l), Array.from(this.selectedOptions).map((s) => s.value);\n } catch {\n return [];\n }\n}',
|
|
52
|
-
waitForSelector:
|
|
53
|
-
'function qe(e, t, n, o) {\n let r = String(e ?? "").trim(), l = String(t ?? "visible") || "visible", s = typeof n == "number" && n > 0 ? n : 30000, i = o !== !1;\n return new Promise((a, d) => {\n let f = null, c = null, p = !1, g = () => {\n f !== null && (clearTimeout(f), f = null);\n }, w = V(r, i);\n if (B(w, l)) {\n p = !0, a(!0);\n return;\n }\n let x = [], y = () => {\n for (let E of x)\n E.disconnect();\n c && (document.removeEventListener("DOMContentLoaded", c), c = null);\n }, m = () => {\n if (p)\n return;\n let E = V(r, i);\n B(E, l) && (p = !0, g(), y(), a(!0));\n };\n if (!(document.body || document.documentElement)) {\n c = () => {\n document.removeEventListener("DOMContentLoaded", c), c = null, m(), h();\n }, document.addEventListener("DOMContentLoaded", c), f = setTimeout(() => {\n p || (p = !0, g(), y(), d(Error(`waitForSelector: Timeout ${s}ms exceeded waiting for "${r}" to be ${l}`)));\n }, s);\n return;\n }\n let h = () => {\n let E = document.body || document.documentElement;\n if (!E)\n return;\n let b = new MutationObserver(m);\n b.observe(E, { childList: !0, subtree: !0, attributes: !0, attributeFilter: ["style", "class", "hidden", "disabled"] }), x.push(b), i && ie(m, x);\n };\n h(), f = setTimeout(() => {\n p || (p = !0, g(), y(), d(Error(`waitForSelector: Timeout ${s}ms exceeded waiting for "${r}" to be ${l}`)));\n }, s);\n });\n}',
|
|
54
|
-
} as const
|
|
7
|
+
"assignFilePayloadsToInputElement": "function we(e) {\n try {\n let t = this;\n if (t?.tagName?.toLowerCase() !== \"input\" || (t.type ?? \"\").toLowerCase() !== \"file\")\n return !1;\n let n = (() => {\n try {\n return new DataTransfer;\n } catch {\n return null;\n }\n })();\n if (!n)\n return !1;\n let o = Array.isArray(e) ? e : [];\n for (let r of o) {\n if (!r)\n continue;\n 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);\n for (let E = 0;E < a.length; E += 1)\n d[E] = a.charCodeAt(E);\n let f = new Blob([d], { type: s }), c = new File([f], l, { type: s, lastModified: i });\n n.items.add(c);\n }\n return t.files = n.files, t.dispatchEvent(new Event(\"input\", { bubbles: !0 })), t.dispatchEvent(new Event(\"change\", { bubbles: !0 })), !0;\n } catch {\n return !1;\n }\n}",
|
|
8
|
+
"countCssMatchesPierce": "function fe(e) {\n let t = String(e ?? \"\").trim();\n if (!t)\n return 0;\n let n = window.__handstageV3__;\n if (!n || typeof n.getClosedRoot != \"function\")\n try {\n return document.querySelectorAll(t).length;\n } catch {\n return 0;\n }\n let o = new WeakSet, r = [], l = (a) => {\n !a || o.has(a) || (o.add(a), r.push(a));\n };\n l(document);\n let s = 0, i = (a) => {\n let d = a.shadowRoot;\n d && l(d);\n try {\n let f = n.getClosedRoot(a);\n f && l(f);\n } catch {}\n };\n for (;r.length; ) {\n let a = r.shift();\n if (a) {\n try {\n let d = a;\n typeof d.querySelectorAll == \"function\" && (s += d.querySelectorAll(t).length);\n } catch {}\n try {\n let f = (a instanceof Document ? a : a instanceof ShadowRoot ? a.host?.ownerDocument ?? document : a.ownerDocument ?? document).createTreeWalker(a, NodeFilter.SHOW_ELEMENT);\n for (let c = f.nextNode();c; c = f.nextNode())\n c instanceof Element && i(c);\n } catch {}\n }\n }\n return s;\n}",
|
|
9
|
+
"countCssMatchesPrimary": "function me(e) {\n let t = String(e ?? \"\").trim();\n if (!t)\n return 0;\n let n = new WeakSet, o = (r) => {\n if (!r || n.has(r))\n return 0;\n n.add(r);\n let l = 0;\n try {\n let s = r;\n typeof s.querySelectorAll == \"function\" && (l += s.querySelectorAll(t).length);\n } catch {}\n try {\n let i = (r instanceof Document ? r : r?.ownerDocument ?? document).createTreeWalker(r, NodeFilter.SHOW_ELEMENT);\n for (let a = i.nextNode();a; a = i.nextNode())\n a instanceof Element && a.shadowRoot && (l += o(a.shadowRoot));\n } catch {}\n return l;\n };\n try {\n return o(document);\n } catch {\n try {\n return document.querySelectorAll(t).length;\n } catch {\n return 0;\n }\n }\n}",
|
|
10
|
+
"countTextMatches": "function he(e) {\n let t = String(e ?? \"\");\n if (!t)\n return { count: 0, sample: [], error: null };\n let n = t.toLowerCase(), o = new Set([\"SCRIPT\", \"STYLE\", \"TEMPLATE\", \"NOSCRIPT\", \"HEAD\", \"TITLE\", \"LINK\", \"META\", \"HTML\", \"BODY\"]), r = (m) => {\n if (!m)\n return !1;\n let u = m.tagName?.toUpperCase() ?? \"\";\n return o.has(u);\n }, l = (m) => {\n try {\n if (r(m))\n return \"\";\n let u = m.innerText;\n if (typeof u == \"string\" && u.trim())\n return u.trim();\n } catch {}\n try {\n let u = m.textContent;\n if (typeof u == \"string\")\n return u.trim();\n } catch {}\n return \"\";\n }, s = (m) => {\n let u = l(m);\n return !!u && u.toLowerCase().includes(n);\n }, i = window.__handstageV3__, a = i && typeof i.getClosedRoot == \"function\" ? (m) => {\n try {\n return i.getClosedRoot(m) ?? null;\n } catch {\n return null;\n }\n } : (m) => null, d = new WeakSet, f = [], c = (m) => {\n !m || d.has(m) || (d.add(m), f.push(m));\n }, E = (m) => {\n try {\n return (m instanceof Document ? m : m?.ownerDocument ?? document).createTreeWalker(m, NodeFilter.SHOW_ELEMENT);\n } catch {\n return null;\n }\n }, p = [];\n for (c(document);f.length; ) {\n let m = f.shift();\n if (!m)\n continue;\n m instanceof Element && s(m) && p.push({ element: m, tag: m.tagName ?? \"\", id: m.id ?? \"\", className: m.className ?? \"\", text: l(m) });\n let u = E(m);\n if (u)\n for (let h = u.nextNode();h; h = u.nextNode()) {\n if (!(h instanceof Element))\n continue;\n s(h) && p.push({ element: h, tag: h.tagName ?? \"\", id: h.id ?? \"\", className: h.className ?? \"\", text: l(h) });\n let g = h.shadowRoot;\n g && c(g);\n let b = a(h);\n b && c(b);\n }\n }\n let w = [];\n for (let m of p) {\n let u = m.element, h = !1;\n for (let g of p)\n if (m !== g)\n try {\n if (u.contains(g.element)) {\n h = !0;\n break;\n }\n } catch {}\n h || w.push(m);\n }\n let x = w.length, y = w.slice(0, 5).map((m) => ({ tag: m.tag, id: m.id, class: m.className, text: m.text }));\n return { count: x, sample: y, error: null };\n}",
|
|
11
|
+
"countXPathMatchesMainWorld": "function pe(e) {\n return F(e, { pierceShadow: !0 });\n}",
|
|
12
|
+
"dispatchDomClick": "function ye(e) {\n let t = e ?? {};\n try {\n 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 });\n this.dispatchEvent(n);\n } catch {\n try {\n this.click();\n } catch {}\n }\n}",
|
|
13
|
+
"ensureFileInputElement": "function Ee() {\n try {\n return (this.tagName?.toLowerCase() ?? \"\") !== \"input\" ? !1 : String(this.type ?? \"\").toLowerCase() === \"file\";\n } catch {\n return !1;\n }\n}",
|
|
14
|
+
"fillElementValue": "function xe(e) {\n let t = this;\n if (!t.isConnected)\n return { status: \"error\", reason: \"notconnected\" };\n let o = (t.ownerDocument || document).defaultView || window, r = e ?? \"\";\n try {\n let l = (s) => {\n let i;\n if (typeof o.InputEvent == \"function\")\n try {\n i = new o.InputEvent(\"input\", { bubbles: !0, composed: !0, data: s, inputType: \"insertText\" });\n } catch {\n i = new o.Event(\"input\", { bubbles: !0, composed: !0 });\n }\n else\n i = new o.Event(\"input\", { bubbles: !0, composed: !0 });\n t.dispatchEvent(i);\n let a = new o.Event(\"change\", { bubbles: !0 });\n t.dispatchEvent(a);\n };\n if (t instanceof o.HTMLInputElement) {\n let s = (t.type || \"\").toLowerCase();\n if (!ne.has(s) && !$.has(s))\n return { status: \"error\", reason: `unsupported-input-type:${s}` };\n let i = e;\n if (s === \"number\") {\n let a = e.trim();\n if (a !== \"\" && Number.isNaN(Number(a)))\n return { status: \"error\", reason: \"invalid-number-value\" };\n i = a;\n }\n if (r = i, $.has(s)) {\n let a = e.trim();\n r = a, C.call(t);\n let d = o.HTMLInputElement.prototype, c = Object.getOwnPropertyDescriptor(d, \"value\")?.set;\n 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\" });\n }\n return C.call(t), { status: \"needsinput\", value: i };\n }\n return t instanceof o.HTMLTextAreaElement ? (C.call(t), r = e, { status: \"needsinput\", value: e }) : t instanceof o.HTMLSelectElement ? { status: \"error\", reason: \"unsupported-element\" } : t.isContentEditable ? (C.call(t), r = e, { status: \"needsinput\", value: e }) : { status: \"error\", reason: \"unsupported-element\" };\n } catch (l) {\n let s = \"exception\";\n if (l && typeof l == \"object\") {\n let i = l.message;\n typeof i == \"string\" && i.trim().length > 0 && (s = `exception:${i}`);\n }\n return { status: \"needsinput\", value: r, reason: s };\n }\n}",
|
|
15
|
+
"focusElement": "function Se() {\n try {\n typeof this.focus == \"function\" && this.focus();\n } catch {}\n}",
|
|
16
|
+
"isElementChecked": "function Re() {\n try {\n let e = this;\n if ((e.tagName || \"\").toLowerCase() === \"input\") {\n let o = e.type?.toLowerCase() ?? \"\";\n if (o === \"checkbox\" || o === \"radio\")\n return !!e.checked;\n }\n let n = e.getAttribute?.(\"aria-checked\");\n return n != null ? n === \"true\" : !1;\n } catch {\n return !1;\n }\n}",
|
|
17
|
+
"isElementVisible": "function Te() {\n try {\n let e = this;\n if (!e.isConnected)\n return !1;\n let t = e.ownerDocument?.defaultView?.getComputedStyle(e) ?? window.getComputedStyle(e);\n if (!t || t.display === \"none\" || t.visibility === \"hidden\")\n return !1;\n let n = parseFloat(t.opacity ?? \"1\");\n if (!Number.isFinite(n) || n === 0)\n return !1;\n let o = e.getBoundingClientRect();\n return !(!o || Math.max(o.width, o.height) === 0 || e.getClientRects().length === 0);\n } catch {\n return !1;\n }\n}",
|
|
18
|
+
"prepareElementForTyping": "function C() {\n try {\n let e = this;\n if (!e.isConnected)\n return !1;\n let t = e.ownerDocument || document, n = t.defaultView || window;\n try {\n typeof e.focus == \"function\" && e.focus();\n } catch {}\n if (e instanceof n.HTMLInputElement || e instanceof n.HTMLTextAreaElement) {\n try {\n if (typeof e.select == \"function\")\n return e.select(), !0;\n } catch {}\n try {\n let o = (e.value ?? \"\").length;\n if (typeof e.setSelectionRange == \"function\")\n return e.setSelectionRange(0, o), !0;\n } catch {}\n return !0;\n }\n if (e.isContentEditable) {\n let o = t.getSelection?.(), r = t.createRange?.();\n if (o && r)\n try {\n r.selectNodeContents(e), o.removeAllRanges(), o.addRange(r);\n } catch {}\n return !0;\n }\n return !1;\n } catch {\n return !1;\n }\n}",
|
|
19
|
+
"readElementInnerHTML": "function Me() {\n try {\n return String(this.innerHTML ?? \"\");\n } catch {\n return \"\";\n }\n}",
|
|
20
|
+
"readElementInnerText": "function Le() {\n try {\n let e = this, t = e.innerText;\n if (typeof t == \"string\" && t.length > 0)\n return t;\n let n = e.textContent;\n return typeof n == \"string\" ? n : \"\";\n } catch {\n return \"\";\n }\n}",
|
|
21
|
+
"readElementInputValue": "function Ce() {\n try {\n let e = this, t = (e.tagName || \"\").toLowerCase();\n return t === \"input\" || t === \"textarea\" || t === \"select\" ? String(e.value ?? \"\") : e.isContentEditable ? String(e.textContent ?? \"\") : \"\";\n } catch {\n return \"\";\n }\n}",
|
|
22
|
+
"readElementTextContent": "function Ne() {\n try {\n return String(this.textContent ?? \"\");\n } catch {\n return \"\";\n }\n}",
|
|
23
|
+
"resolveCssSelector": "function De(e, t) {\n let n = String(e ?? \"\").trim();\n if (!n)\n return null;\n let o = N(t);\n return z(n, o + 1)[o] ?? null;\n}",
|
|
24
|
+
"resolveCssSelectorPierce": "function He(e, t) {\n let n = String(e ?? \"\").trim();\n if (!n)\n return null;\n let o = N(t), r = window.__handstageV3__;\n if (!r || typeof r.getClosedRoot != \"function\")\n return z(n, o + 1)[o] ?? null;\n let l = (c) => {\n try {\n return r.getClosedRoot(c) ?? null;\n } catch {\n return null;\n }\n }, s = new WeakSet, i = new Set, a = [], d = [document], f = (c) => {\n if (!(!c || s.has(c) || a.length >= o + 1)) {\n s.add(c);\n try {\n let E = c.querySelectorAll(n);\n for (let p of E)\n if (!i.has(p) && (i.add(p), a.push(p), a.length >= o + 1))\n return;\n } catch {}\n try {\n let p = (c instanceof Document ? c : c.host?.ownerDocument ?? document).createTreeWalker(c, NodeFilter.SHOW_ELEMENT);\n for (let w = p.nextNode();w; w = p.nextNode()) {\n if (!(w instanceof Element))\n continue;\n let x = w.shadowRoot;\n x && d.push(x);\n let y = l(w);\n y && d.push(y);\n }\n } catch {}\n }\n };\n for (;d.length && a.length < o + 1; ) {\n let c = d.shift();\n c && f(c);\n }\n return a[o] ?? null;\n}",
|
|
25
|
+
"resolveTextSelector": "function Ae(e, t) {\n let n = String(e ?? \"\");\n if (!n)\n return null;\n let o = n.toLowerCase(), r = N(t), l = new Set([\"SCRIPT\", \"STYLE\", \"TEMPLATE\", \"NOSCRIPT\", \"HEAD\", \"TITLE\", \"LINK\", \"META\", \"HTML\", \"BODY\"]), s = (u) => {\n if (!u)\n return !1;\n let h = u.tagName?.toUpperCase() ?? \"\";\n return l.has(h);\n }, i = (u) => {\n try {\n if (s(u))\n return \"\";\n let h = u.innerText;\n if (typeof h == \"string\" && h.trim())\n return h.trim();\n } catch {}\n try {\n let h = u.textContent;\n if (typeof h == \"string\")\n return h.trim();\n } catch {}\n return \"\";\n }, a = (u) => {\n let h = i(u);\n return !!h && h.toLowerCase().includes(o);\n }, d = window.__handstageV3__, f = d && typeof d.getClosedRoot == \"function\" ? (u) => {\n try {\n return d.getClosedRoot(u) ?? null;\n } catch {\n return null;\n }\n } : (u) => null, c = new WeakSet, E = [], p = [], w = (u) => {\n !u || c.has(u) || (c.add(u), E.push(u));\n }, x = (u) => {\n try {\n return (u instanceof Document ? u : u?.ownerDocument ?? document).createTreeWalker(u, NodeFilter.SHOW_ELEMENT);\n } catch {\n return null;\n }\n };\n for (w(document);E.length; ) {\n let u = E.shift();\n if (!u)\n continue;\n u instanceof Element && a(u) && p.push({ element: u, tag: u.tagName ?? \"\", id: u.id ?? \"\", className: u.className ?? \"\", text: i(u) });\n let h = x(u);\n if (h)\n for (let g = h.nextNode();g; g = h.nextNode()) {\n if (!(g instanceof Element))\n continue;\n a(g) && p.push({ element: g, tag: g.tagName ?? \"\", id: g.id ?? \"\", className: g.className ?? \"\", text: i(g) });\n let b = g.shadowRoot;\n b && w(b);\n let k = f(g);\n k && w(k);\n }\n }\n let y = [];\n for (let u of p) {\n let h = u.element, g = !1;\n for (let b of p)\n if (u !== b)\n try {\n if (h.contains(b.element)) {\n g = !0;\n break;\n }\n } catch {}\n g || y.push(u);\n }\n return y[r]?.element ?? null;\n}",
|
|
26
|
+
"resolveXPathMainWorld": "function We(e, t) {\n let n = N(t);\n return P(e, n, { pierceShadow: !0 });\n}",
|
|
27
|
+
"scrollElementToPercent": "function be(e) {\n let t = (n) => {\n if (typeof n == \"number\" && Number.isFinite(n))\n return n;\n let o = String(n ?? \"\").trim();\n if (!o)\n return 0;\n let r = parseFloat(o.replace(\"%\", \"\"));\n return Number.isNaN(r) || !Number.isFinite(r) ? 0 : r;\n };\n try {\n let n = Math.max(0, Math.min(t(e), 100)), o = this, r = o.tagName?.toLowerCase() ?? \"\";\n if (r === \"html\" || r === \"body\") {\n let c = (o.ownerDocument?.scrollingElement || o.ownerDocument?.documentElement || o.ownerDocument?.body || document.scrollingElement || document.documentElement || document.body)?.scrollHeight ?? document.body.scrollHeight ?? 0, E = o.ownerDocument?.defaultView?.innerHeight ?? window.innerHeight, w = Math.max(0, c - E) * (n / 100);\n return o.ownerDocument?.defaultView?.scrollTo({ top: w, left: o.ownerDocument?.defaultView?.scrollX ?? window.scrollX ?? 0, behavior: \"smooth\" }), !0;\n }\n let s = o.scrollHeight ?? 0, i = o.clientHeight ?? 0, d = Math.max(0, s - i) * (n / 100);\n return o.scrollTo({ top: d, left: o.scrollLeft ?? 0, behavior: \"smooth\" }), !0;\n } catch {\n return !1;\n }\n}",
|
|
28
|
+
"selectElementOptions": "function ve(e) {\n try {\n if (!(this instanceof HTMLSelectElement))\n return [];\n let t = Array.isArray(e) ? e : [e], n = new Set(t.map((s) => String(s ?? \"\").trim())), o = (s) => {\n let i = (s.label || s.textContent || \"\").trim(), a = String(s.value ?? \"\").trim();\n return n.has(i) || n.has(a);\n };\n if (this.multiple)\n for (let s of Array.from(this.options))\n s.selected = o(s);\n else {\n let s = !1;\n for (let i of Array.from(this.options))\n !s && o(i) ? (i.selected = !0, this.value = i.value, s = !0) : i.selected = !1;\n }\n let r = new Event(\"input\", { bubbles: !0 }), l = new Event(\"change\", { bubbles: !0 });\n return this.dispatchEvent(r), this.dispatchEvent(l), Array.from(this.selectedOptions).map((s) => s.value);\n } catch {\n return [];\n }\n}",
|
|
29
|
+
"waitForSelector": "function _e(e, t, n, o) {\n let r = String(e ?? \"\").trim(), l = String(t ?? \"visible\") || \"visible\", s = typeof n == \"number\" && n > 0 ? n : 30000, i = o !== !1;\n return new Promise((a, d) => {\n let f = null, c = null, E = !1, p = () => {\n f !== null && (clearTimeout(f), f = null);\n }, w = V(r, i);\n if (B(w, l)) {\n E = !0, a(!0);\n return;\n }\n let x = [], y = () => {\n for (let g of x)\n g.disconnect();\n c && (document.removeEventListener(\"DOMContentLoaded\", c), c = null);\n }, m = () => {\n if (E)\n return;\n let g = V(r, i);\n B(g, l) && (E = !0, p(), y(), a(!0));\n };\n if (!(document.body || document.documentElement)) {\n c = () => {\n if (!c)\n throw Error(\"DOMContentLoaded handler missing during cleanup\");\n document.removeEventListener(\"DOMContentLoaded\", c), c = null, m(), h();\n }, document.addEventListener(\"DOMContentLoaded\", c), f = setTimeout(() => {\n E || (E = !0, p(), y(), d(Error(`waitForSelector: Timeout ${s}ms exceeded waiting for \"${r}\" to be ${l}`)));\n }, s);\n return;\n }\n let h = () => {\n let g = document.body || document.documentElement;\n if (!g)\n return;\n let b = new MutationObserver(m);\n b.observe(g, { childList: !0, subtree: !0, attributes: !0, attributeFilter: [\"style\", \"class\", \"hidden\", \"disabled\"] }), x.push(b), i && ie(m, x);\n };\n h(), f = setTimeout(() => {\n E || (E = !0, p(), y(), d(Error(`waitForSelector: Timeout ${s}ms exceeded waiting for \"${r}\" to be ${l}`)));\n }, s);\n });\n}"
|
|
30
|
+
} as const;
|
|
55
31
|
export const locatorScriptGlobalRefs = {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
"globalThis.__stagehandLocatorScripts.readElementTextContent",
|
|
82
|
-
resolveCssSelector: "globalThis.__stagehandLocatorScripts.resolveCssSelector",
|
|
83
|
-
resolveCssSelectorPierce:
|
|
84
|
-
"globalThis.__stagehandLocatorScripts.resolveCssSelectorPierce",
|
|
85
|
-
resolveTextSelector:
|
|
86
|
-
"globalThis.__stagehandLocatorScripts.resolveTextSelector",
|
|
87
|
-
resolveXPathMainWorld:
|
|
88
|
-
"globalThis.__stagehandLocatorScripts.resolveXPathMainWorld",
|
|
89
|
-
scrollElementToPercent:
|
|
90
|
-
"globalThis.__stagehandLocatorScripts.scrollElementToPercent",
|
|
91
|
-
selectElementOptions:
|
|
92
|
-
"globalThis.__stagehandLocatorScripts.selectElementOptions",
|
|
93
|
-
waitForSelector: "globalThis.__stagehandLocatorScripts.waitForSelector",
|
|
94
|
-
} as const
|
|
95
|
-
export type LocatorScriptName = keyof typeof locatorScriptSources
|
|
32
|
+
"assignFilePayloadsToInputElement": "globalThis.__handstageLocatorScripts.assignFilePayloadsToInputElement",
|
|
33
|
+
"countCssMatchesPierce": "globalThis.__handstageLocatorScripts.countCssMatchesPierce",
|
|
34
|
+
"countCssMatchesPrimary": "globalThis.__handstageLocatorScripts.countCssMatchesPrimary",
|
|
35
|
+
"countTextMatches": "globalThis.__handstageLocatorScripts.countTextMatches",
|
|
36
|
+
"countXPathMatchesMainWorld": "globalThis.__handstageLocatorScripts.countXPathMatchesMainWorld",
|
|
37
|
+
"dispatchDomClick": "globalThis.__handstageLocatorScripts.dispatchDomClick",
|
|
38
|
+
"ensureFileInputElement": "globalThis.__handstageLocatorScripts.ensureFileInputElement",
|
|
39
|
+
"fillElementValue": "globalThis.__handstageLocatorScripts.fillElementValue",
|
|
40
|
+
"focusElement": "globalThis.__handstageLocatorScripts.focusElement",
|
|
41
|
+
"isElementChecked": "globalThis.__handstageLocatorScripts.isElementChecked",
|
|
42
|
+
"isElementVisible": "globalThis.__handstageLocatorScripts.isElementVisible",
|
|
43
|
+
"prepareElementForTyping": "globalThis.__handstageLocatorScripts.prepareElementForTyping",
|
|
44
|
+
"readElementInnerHTML": "globalThis.__handstageLocatorScripts.readElementInnerHTML",
|
|
45
|
+
"readElementInnerText": "globalThis.__handstageLocatorScripts.readElementInnerText",
|
|
46
|
+
"readElementInputValue": "globalThis.__handstageLocatorScripts.readElementInputValue",
|
|
47
|
+
"readElementTextContent": "globalThis.__handstageLocatorScripts.readElementTextContent",
|
|
48
|
+
"resolveCssSelector": "globalThis.__handstageLocatorScripts.resolveCssSelector",
|
|
49
|
+
"resolveCssSelectorPierce": "globalThis.__handstageLocatorScripts.resolveCssSelectorPierce",
|
|
50
|
+
"resolveTextSelector": "globalThis.__handstageLocatorScripts.resolveTextSelector",
|
|
51
|
+
"resolveXPathMainWorld": "globalThis.__handstageLocatorScripts.resolveXPathMainWorld",
|
|
52
|
+
"scrollElementToPercent": "globalThis.__handstageLocatorScripts.scrollElementToPercent",
|
|
53
|
+
"selectElementOptions": "globalThis.__handstageLocatorScripts.selectElementOptions",
|
|
54
|
+
"waitForSelector": "globalThis.__handstageLocatorScripts.waitForSelector"
|
|
55
|
+
} as const;
|
|
56
|
+
export type LocatorScriptName = keyof typeof locatorScriptSources;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const reRenderScriptContent =
|
|
2
|
-
'"use strict";(()=>{function s(){try{let o=window.
|
|
2
|
+
'"use strict";(()=>{function s(){try{let o=window.__handstageV3__;if(!o||typeof o.getClosedRoot!="function")return;let t=[],r=document.createTreeWalker(document,NodeFilter.SHOW_ELEMENT);for(;r.nextNode();){let e=r.currentNode,n=e.tagName?.toLowerCase()??"";if(!n.includes("-")||typeof customElements?.get!="function"||!customElements.get(n))continue;let c=!!e.shadowRoot,i=!!o.getClosedRoot(e);c||i||t.push(e)}for(let e of t)try{let n=e.cloneNode(!0);e.replaceWith(n)}catch{}o.stats&&t.length&&console.info("[v3-piercer] rerender",{count:t.length})}catch(o){console.info("[v3-piercer] rerender error",{message:String(o??"")})}}s();})();\n'
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* Update sources in pkgs/dom/src/screenshotScripts and run genScreenshotScripts.ts.
|
|
4
4
|
*/
|
|
5
5
|
export const screenshotScriptSources = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export type ScreenshotScriptName = keyof typeof screenshotScriptSources
|
|
6
|
+
"resolveMaskRect": "function h(r) {\n function u(t, e) {\n try {\n return t && typeof t.closest == \"function\" ? t.closest(e) : null;\n } catch {\n return null;\n }\n }\n function s(t, e) {\n try {\n return !!t && typeof t.matches == \"function\" && t.matches(e);\n } catch {\n return !1;\n }\n }\n function c(t) {\n let e = u(t, \"dialog[open]\");\n if (e)\n return e;\n let l = u(t, \"[popover]\");\n return l && s(l, \":popover-open\") ? l : null;\n }\n if (!this || typeof this.getBoundingClientRect != \"function\")\n return null;\n let n = this.getBoundingClientRect();\n if (!n)\n return null;\n let i = window.getComputedStyle(this);\n if (!i || i.visibility === \"hidden\" || i.display === \"none\" || n.width <= 0 || n.height <= 0)\n return null;\n let o = c(this);\n if (o) {\n let t = o.getBoundingClientRect();\n if (!t)\n return null;\n let e = null;\n if (r)\n try {\n let l = o.getAttribute(\"data-handstage-mask-root\");\n l?.startsWith(r) ? e = l : (e = `${r}_root_${Math.random().toString(36).slice(2)}`, o.setAttribute(\"data-handstage-mask-root\", e));\n } catch {\n e = null;\n }\n return { x: n.left - t.left - (o.clientLeft || 0) + (o.scrollLeft || 0), y: n.top - t.top - (o.clientTop || 0) + (o.scrollTop || 0), width: n.width, height: n.height, rootToken: e };\n }\n return { x: n.left + window.scrollX, y: n.top + window.scrollY, width: n.width, height: n.height, rootToken: null };\n}"
|
|
7
|
+
} as const;
|
|
8
|
+
export type ScreenshotScriptName = keyof typeof screenshotScriptSources;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const v3ScriptContent =
|
|
2
|
-
'"use strict";(()=>{function s(c={}){let r=e=>{let{hostToRoot:o}=e;window.
|
|
2
|
+
'"use strict";(()=>{function s(c={}){let r=e=>{let{hostToRoot:o}=e;window.__handstageV3__={getClosedRoot:a=>o.get(a),stats:()=>({installed:!0,url:location.href,isTop:window.top===window,open:e.openCount,closed:e.closedCount})}},n=Element.prototype.attachShadow;if(n.__v3Patched&&n.__v3State){n.__v3State.debug=!0,r(n.__v3State);return}let t={hostToRoot:new WeakMap,openCount:0,closedCount:0,debug:!0},l=n,d=function(e){let o=e?.mode??"open",a=l.call(this,e);try{t.hostToRoot.set(this,a),o==="closed"?t.closedCount++:t.openCount++,t.debug&&console.info("[v3-piercer] attachShadow",{tag:this.tagName?.toLowerCase()??"",mode:o,url:location.href})}catch{}return a};if(d.__v3Patched=!0,d.__v3State=t,Object.defineProperty(Element.prototype,"attachShadow",{configurable:!0,writable:!0,value:d}),c.tagExisting)try{let e=document.createTreeWalker(document,NodeFilter.SHOW_ELEMENT);for(;e.nextNode();){let o=e.currentNode;o.shadowRoot&&(t.hostToRoot.set(o,o.shadowRoot),t.openCount++)}}catch{}window.__handstageV3Injected=!0,r(t),t.debug&&console.info("[v3-piercer] installed",{url:location.href,isTop:window.top===window,readyState:document.readyState})}s({debug:!0,tagExisting:!1});})();\n'
|