stagehand 4.5.0a0.dev1707__tar.gz → 4.5.0a0.dev1709__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. {stagehand-4.5.0a0.dev1707 → stagehand-4.5.0a0.dev1709}/PKG-INFO +1 -1
  2. {stagehand-4.5.0a0.dev1707 → stagehand-4.5.0a0.dev1709}/pyproject.toml +1 -1
  3. stagehand-4.5.0a0.dev1709/src/stagehand/_extension/content-script.js +1 -0
  4. stagehand-4.5.0a0.dev1709/src/stagehand/_extension/offscreen/service-worker-heartbeat.js +1 -0
  5. stagehand-4.5.0a0.dev1709/src/stagehand/_extension/service-worker.js +300 -0
  6. stagehand-4.5.0a0.dev1709/src/stagehand/_extension/wake-service-worker.js +1 -0
  7. {stagehand-4.5.0a0.dev1707 → stagehand-4.5.0a0.dev1709}/src/stagehand/_generated/protocol_version.py +1 -1
  8. stagehand-4.5.0a0.dev1707/src/stagehand/_extension/content-script.js +0 -1170
  9. stagehand-4.5.0a0.dev1707/src/stagehand/_extension/offscreen/service-worker-heartbeat.js +0 -21
  10. stagehand-4.5.0a0.dev1707/src/stagehand/_extension/service-worker.js +0 -72496
  11. stagehand-4.5.0a0.dev1707/src/stagehand/_extension/wake-service-worker.js +0 -3
  12. {stagehand-4.5.0a0.dev1707 → stagehand-4.5.0a0.dev1709}/README.md +0 -0
  13. {stagehand-4.5.0a0.dev1707 → stagehand-4.5.0a0.dev1709}/src/stagehand/__init__.py +0 -0
  14. {stagehand-4.5.0a0.dev1707 → stagehand-4.5.0a0.dev1709}/src/stagehand/_extension/blank.html +0 -0
  15. {stagehand-4.5.0a0.dev1707 → stagehand-4.5.0a0.dev1709}/src/stagehand/_extension/manifest.json +0 -0
  16. {stagehand-4.5.0a0.dev1707 → stagehand-4.5.0a0.dev1709}/src/stagehand/_extension/offscreen/service-worker-heartbeat.html +0 -0
  17. {stagehand-4.5.0a0.dev1707 → stagehand-4.5.0a0.dev1709}/src/stagehand/_extension/wake-service-worker.html +0 -0
  18. {stagehand-4.5.0a0.dev1707 → stagehand-4.5.0a0.dev1709}/src/stagehand/_generated/__init__.py +0 -0
  19. {stagehand-4.5.0a0.dev1707 → stagehand-4.5.0a0.dev1709}/src/stagehand/_generated/input_types.py +0 -0
  20. {stagehand-4.5.0a0.dev1707 → stagehand-4.5.0a0.dev1709}/src/stagehand/_generated/models.py +0 -0
  21. {stagehand-4.5.0a0.dev1707 → stagehand-4.5.0a0.dev1709}/src/stagehand/_sdk_identity.py +0 -0
  22. {stagehand-4.5.0a0.dev1707 → stagehand-4.5.0a0.dev1709}/src/stagehand/_validation.py +0 -0
  23. {stagehand-4.5.0a0.dev1707 → stagehand-4.5.0a0.dev1709}/src/stagehand/browser.py +0 -0
  24. {stagehand-4.5.0a0.dev1707 → stagehand-4.5.0a0.dev1709}/src/stagehand/browser_clipboard.py +0 -0
  25. {stagehand-4.5.0a0.dev1707 → stagehand-4.5.0a0.dev1709}/src/stagehand/browser_context.py +0 -0
  26. {stagehand-4.5.0a0.dev1707 → stagehand-4.5.0a0.dev1709}/src/stagehand/browserbase_connection.py +0 -0
  27. {stagehand-4.5.0a0.dev1707 → stagehand-4.5.0a0.dev1709}/src/stagehand/browserbase_rpc.py +0 -0
  28. {stagehand-4.5.0a0.dev1707 → stagehand-4.5.0a0.dev1709}/src/stagehand/browserbase_services.py +0 -0
  29. {stagehand-4.5.0a0.dev1707 → stagehand-4.5.0a0.dev1709}/src/stagehand/browserbase_session.py +0 -0
  30. {stagehand-4.5.0a0.dev1707 → stagehand-4.5.0a0.dev1709}/src/stagehand/browserbase_transport.py +0 -0
  31. {stagehand-4.5.0a0.dev1707 → stagehand-4.5.0a0.dev1709}/src/stagehand/cdp_client.py +0 -0
  32. {stagehand-4.5.0a0.dev1707 → stagehand-4.5.0a0.dev1709}/src/stagehand/client_models.py +0 -0
  33. {stagehand-4.5.0a0.dev1707 → stagehand-4.5.0a0.dev1709}/src/stagehand/client_types.py +0 -0
  34. {stagehand-4.5.0a0.dev1707 → stagehand-4.5.0a0.dev1709}/src/stagehand/extension_assets.py +0 -0
  35. {stagehand-4.5.0a0.dev1707 → stagehand-4.5.0a0.dev1709}/src/stagehand/file_upload.py +0 -0
  36. {stagehand-4.5.0a0.dev1707 → stagehand-4.5.0a0.dev1709}/src/stagehand/locator.py +0 -0
  37. {stagehand-4.5.0a0.dev1707 → stagehand-4.5.0a0.dev1709}/src/stagehand/page.py +0 -0
  38. {stagehand-4.5.0a0.dev1707 → stagehand-4.5.0a0.dev1709}/src/stagehand/py.typed +0 -0
  39. {stagehand-4.5.0a0.dev1707 → stagehand-4.5.0a0.dev1709}/src/stagehand/response.py +0 -0
  40. {stagehand-4.5.0a0.dev1707 → stagehand-4.5.0a0.dev1709}/src/stagehand/rpc_client.py +0 -0
  41. {stagehand-4.5.0a0.dev1707 → stagehand-4.5.0a0.dev1709}/src/stagehand/stagehand.py +0 -0
  42. {stagehand-4.5.0a0.dev1707 → stagehand-4.5.0a0.dev1709}/src/stagehand/timeouts.py +0 -0
  43. {stagehand-4.5.0a0.dev1707 → stagehand-4.5.0a0.dev1709}/src/stagehand/webmcp.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: stagehand
3
- Version: 4.5.0a0.dev1707
3
+ Version: 4.5.0a0.dev1709
4
4
  Summary: Browserbase's SDK for building browser agents
5
5
  Keywords: ai,agent,ai-agent,browser,browser-agent,browser-automation,computer-use,headless,playwright,cdp,llm,automation,web-scraping,testing
6
6
  Author: Browserbase
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "stagehand"
3
- version = "4.5.0a0.dev1707"
3
+ version = "4.5.0a0.dev1709"
4
4
  description = "Browserbase's SDK for building browser agents"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
@@ -0,0 +1 @@
1
+ (()=>{function parseXPathSteps(e){let t=String(e||``).trim().replace(/^xpath=/i,``);if(!t)return[];let n=[],r=0;for(;r<t.length;){let e=`child`;t.startsWith(`//`,r)?(e=`desc`,r+=2):t[r]===`/`&&(e=`child`,r+=1);let i=r,a=0,o=null;for(;r<t.length;){let e=t[r];if(o)e===o&&(o=null);else if(e===`'`||e===`"`)o=e;else if(e===`[`)a++;else if(e===`]`)a--;else if(e===`/`&&a===0)break;r+=1}let s=t.slice(i,r).trim();if(!s)continue;let{tag:c,predicates:l}=parseStep(s);n.push({axis:e,tag:c,predicates:l})}return n}function extractPredicates(e){let t=[],n=0;for(;n<e.length;){if(e[n]!==`[`){n++;continue}n++;let r=n,i=null;for(;n<e.length;){let t=e[n];if(i)t===i&&(i=null);else if(t===`'`||t===`"`)i=t;else if(t===`]`)break;n++}t.push(e.slice(r,n).trim()),n++}return t}function parseStep(e){let t=e.indexOf(`[`);if(t===-1)return{tag:e===``?`*`:e.toLowerCase(),predicates:[]};let n=e.slice(0,t).trim(),r=n===``?`*`:n.toLowerCase(),i=e.slice(t),a=[];for(let e of extractPredicates(i)){let t=parsePredicateExpression(e);t&&a.push(t)}return{tag:r,predicates:a}}function parsePredicateExpression(e){let t=e.trim();if(!t)return null;let n=splitTopLevel(t,`or`);if(n.length>1){let e=n.map(e=>parsePredicateExpression(e)).filter(Boolean);return e.length===n.length?{type:`or`,predicates:e}:null}let r=splitTopLevel(t,`and`);if(r.length>1){let e=r.map(e=>parsePredicateExpression(e)).filter(Boolean);return e.length===r.length?{type:`and`,predicates:e}:null}let i=unwrapFunctionCall(t,`not`);if(i!=null){let e=parsePredicateExpression(i);return e?{type:`not`,predicate:e}:null}return parseAtomicPredicate(t)}function parseAtomicPredicate(e){let t=/^(?:'([^']*)'|"([^"]*)")$/,n=`[a-zA-Z_][\\w.-]*`,r=`(?:'([^']*)'|"([^"]*)")`;if(/^\d+$/.test(e))return{type:`index`,index:Math.max(1,Number(e))};let i=e.match(RegExp(`^normalize-space\\(\\s*@(${n})\\s*\\)\\s*=\\s*${r}$`));if(i)return{type:`attrEquals`,name:i[1],value:i[2]??i[3]??``,normalize:!0};let a=e.match(RegExp(`^normalize-space\\(\\s*(text\\(\\)|\\.)\\s*\\)\\s*=\\s*${r}$`));if(a)return{type:`textEquals`,value:a[2]??a[3]??``,normalize:!0,source:textSource(a[1])};let o=e.match(RegExp(`^@(${n})\\s*=\\s*${r}$`));if(o)return{type:`attrEquals`,name:o[1],value:o[2]??o[3]??``};let s=e.match(RegExp(`^@(${n})$`));if(s)return{type:`attrExists`,name:s[1]};let c=e.match(RegExp(`^contains\\(\\s*@(${n})\\s*,\\s*${r}\\s*\\)$`));if(c)return{type:`attrContains`,name:c[1],value:c[2]??c[3]??``};let l=e.match(RegExp(`^starts-with\\(\\s*@(${n})\\s*,\\s*${r}\\s*\\)$`));if(l)return{type:`attrStartsWith`,name:l[1],value:l[2]??l[3]??``};let u=e.match(RegExp(`^(text\\(\\)|\\.)\\s*=\\s*${r}$`));if(u)return{type:`textEquals`,value:u[2]??u[3]??``,source:textSource(u[1])};let d=e.match(RegExp(`^contains\\(\\s*(text\\(\\)|\\.)\\s*,\\s*${r}\\s*\\)$`));return d?{type:`textContains`,value:d[2]??d[3]??``,source:textSource(d[1])}:(t.test(e),null)}function splitTopLevel(e,t){let n=[],r=0,i=0,a=null,o=0;for(;o<e.length;){let s=e[o];if(a){s===a&&(a=null),o+=1;continue}if(s===`'`||s===`"`){a=s,o+=1;continue}if(s===`(`){i+=1,o+=1;continue}if(s===`)`){i=Math.max(0,i-1),o+=1;continue}if(i===0&&isKeywordAt(e,o,t)){n.push(e.slice(r,o).trim()),o+=t.length,r=o;continue}o+=1}return n.push(e.slice(r).trim()),n.filter(e=>e.length>0)}function isKeywordAt(e,t,n){if(!e.startsWith(n,t))return!1;let r=t>0?e[t-1]:` `;if(r===`@`)return!1;let i=t+n.length<e.length?e[t+n.length]:` `;return isBoundary(r)&&isBoundary(i)}function isBoundary(e){return!/[a-zA-Z0-9_.-]/.test(e)}function unwrapFunctionCall(e,t){let n=`${t}(`;if(!e.startsWith(n)||!e.endsWith(`)`))return null;let r=e.slice(n.length,-1);return hasBalancedParens(r)?r:null}function hasBalancedParens(e){let t=0,n=null;for(let r=0;r<e.length;r+=1){let i=e[r];if(n){i===n&&(n=null);continue}if(i===`'`||i===`"`){n=i;continue}if(i===`(`?t+=1:i===`)`&&--t,t<0)return!1}return t===0}var normalizeSpace=e=>e.replace(/\s+/g,` `).trim(),e=3;function textSource(e){return e===`text()`?`text`:`self`}function textValue(e){return String(e.textContent??``)}function childTextValues(t){let n=[];for(let r of Array.from(t.childNodes))r.nodeType===e&&n.push(String(r.nodeValue??``));return n}function firstChildTextValue(e){return childTextValues(e)[0]??``}function normalizeMaybe(e,t){return t?normalizeSpace(e):e}function evaluatePredicate(e,t){switch(t.type){case`and`:return t.predicates.every(t=>evaluatePredicate(e,t));case`or`:return t.predicates.some(t=>evaluatePredicate(e,t));case`not`:return!evaluatePredicate(e,t.predicate);case`attrExists`:return e.getAttribute(t.name)!==null;case`attrEquals`:{let n=e.getAttribute(t.name);return n!==null&&normalizeMaybe(n,t.normalize)===normalizeMaybe(t.value,t.normalize)}case`attrContains`:{let n=e.getAttribute(t.name);return n!==null&&normalizeMaybe(n,t.normalize).includes(normalizeMaybe(t.value,t.normalize))}case`attrStartsWith`:{let n=e.getAttribute(t.name);return n!==null&&normalizeMaybe(n,t.normalize).startsWith(normalizeMaybe(t.value,t.normalize))}case`textEquals`:{let n=normalizeMaybe(t.value,t.normalize);return t.source===`text`?t.normalize?normalizeSpace(firstChildTextValue(e))===n:childTextValues(e).some(e=>e===n):normalizeMaybe(textValue(e),t.normalize)===n}case`textContains`:return normalizeMaybe(t.source===`text`?firstChildTextValue(e):textValue(e),t.normalize).includes(normalizeMaybe(t.value,t.normalize));case`index`:return!0;default:return!0}}function applyPredicates(e,t){let n=e;for(let e of t){if(!n.length)return[];if(e.type===`index`){let t=e.index-1;n=t>=0&&t<n.length?[n[t]]:[];continue}n=n.filter(t=>evaluatePredicate(t,e))}return n}function getOpenOrClosedShadowRoot(e){try{if(e instanceof HTMLElement){let t=globalThis.chrome?.dom?.openOrClosedShadowRoot(e);if(t)return t}}catch{}try{return e.shadowRoot??null}catch{return null}}function documentHasShadowRoot(){try{let e=document.createTreeWalker(document,NodeFilter.SHOW_ELEMENT);for(;e.nextNode();)if(getOpenOrClosedShadowRoot(e.currentNode))return!0}catch{}return!1}var normalizeXPath=e=>{let t=String(e??``).trim();return t?t.replace(/^xpath=/i,``).trim():``};function resolveXPathFirst(e,t){return resolveXPathAtIndex(e,0,t)}function resolveXPathAtIndex(e,t,n){if(!Number.isFinite(t)||t<0)return null;let r=normalizeXPath(e);if(!r)return null;let i=Math.floor(t),a=n?.pierceShadow!==!1,o=a?getShadowContext():null;if(!a)return resolveNativeAtIndexWithError(r,i).value;if(!o?.hasShadow){let e=resolveNativeAtIndexWithError(r,i);return e.error?resolveXPathComposedMatches(r,o?.getShadowRoot)[i]??null:e.value}let s=resolveStagehandShadowHopMatches(r,o.getShadowRoot);return s.length>0?s[i]??null:resolveXPathComposedMatches(r,o.getShadowRoot)[i]??null}function countXPathMatches(e,t){let n=normalizeXPath(e);if(!n)return 0;let r=t?.pierceShadow!==!1,i=r?getShadowContext():null;if(!r)return resolveNativeCountWithError(n).count;if(!i?.hasShadow){let e=resolveNativeCountWithError(n);return e.error?resolveXPathComposedMatches(n,i?.getShadowRoot).length:e.count}let a=resolveStagehandShadowHopMatches(n,i.getShadowRoot).length;return a>0?a:resolveXPathComposedMatches(n,i.getShadowRoot).length}function resolveXPathComposedMatches(e,t){let n=normalizeXPath(e);if(!n)return[];let r=parseXPathSteps(n);if(!r.length)return[];let i=t??null,a=[document];for(let e of r){let t=[],n=new Set;for(let r of a){let a=e.axis===`child`?composedChildren(r,i):composedDescendants(r,i);if(!a.length)continue;let o=applyPredicates(a.filter(t=>matchesTag(t,e)),e.predicates);for(let e of o)n.has(e)||(n.add(e),t.push(e))}if(!t.length)return[];a=t}return a}function resolveStagehandShadowHopMatches(e,t){let n=normalizeXPath(e);if(!n)return[];let r=parseXPathSteps(n);if(!r.some((e,t)=>e.axis===`desc`&&t>0))return[];let i=t??null,a=[document];for(let e=0;e<r.length;e+=1){let t=r[e],n=[],o=new Set;for(let r of a){let a=t.axis===`child`?domChildren(r):e===0?composedDescendants(r,i):shadowRootChildren(r,i);if(!a.length)continue;let s=applyPredicates(a.filter(e=>matchesTag(e,t)),t.predicates);for(let e of s)o.has(e)||(o.add(e),n.push(e))}if(!n.length)return[];a=n}return a}function matchesTag(e,t){return t.tag===`*`||e.localName===t.tag}function getShadowContext(){return{getShadowRoot:getOpenOrClosedShadowRoot,hasShadow:documentHasShadowRoot()}}function composedChildren(e,t){let 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 r=t?.(e)??getOpenOrClosedShadowRoot(e);return r&&n.push(...Array.from(r.children??[])),n}return n}function domChildren(e){let t=[];return e instanceof Document?(e.documentElement&&t.push(e.documentElement),t):((e instanceof ShadowRoot||e instanceof DocumentFragment||e instanceof Element)&&t.push(...Array.from(e.children??[])),t)}function shadowRootChildren(e,t){let n=[];if(!(e instanceof Element))return n;let r=t?.(e)??getOpenOrClosedShadowRoot(e);return r&&n.push(...Array.from(r.children??[])),n}function composedDescendants(e,t){let n=[],r=new Set,i=[...composedChildren(e,t)].reverse();for(;i.length;){let e=i.pop();if(r.has(e))continue;r.add(e),n.push(e);let a=composedChildren(e,t);for(let e=a.length-1;e>=0;--e)i.push(a[e])}return n}function resolveNativeAtIndexWithError(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 resolveNativeCountWithError(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 countCssMatchesPrimary(e){let t=String(e??``).trim();if(!t)return 0;let n=new WeakSet,visit=e=>{if(!e||n.has(e))return 0;n.add(e);let r=0;try{let n=e;typeof n.querySelectorAll==`function`&&(r+=n.querySelectorAll(t).length)}catch{}try{let t=(e instanceof Document?e:e?.ownerDocument??document).createTreeWalker(e,NodeFilter.SHOW_ELEMENT),n;for(;n=t.nextNode();)if(n instanceof Element){let e=getOpenOrClosedShadowRoot(n);e&&(r+=visit(e))}}catch{}return r};try{return visit(document)}catch{try{return document.querySelectorAll(t).length}catch{return 0}}}function countTextMatches(e){let t=String(e??``);if(!t)return{count:0,sample:[],error:null};let n=t.toLowerCase(),r=new Set([`SCRIPT`,`STYLE`,`TEMPLATE`,`NOSCRIPT`,`HEAD`,`TITLE`,`LINK`,`META`,`HTML`,`BODY`]),shouldSkip=e=>{if(!e)return!1;let t=e.tagName?.toUpperCase()??``;return r.has(t)},extractText=e=>{try{if(shouldSkip(e))return``;let t=e.innerText;if(typeof t==`string`&&t.trim())return t.trim()}catch{}try{let t=e.textContent;if(typeof t==`string`)return t.trim()}catch{}return``},matches=e=>{let t=extractText(e);return!!t&&t.toLowerCase().includes(n)},i=new WeakSet,a=[],enqueue=e=>{!e||i.has(e)||(i.add(e),a.push(e))},walkerFor=e=>{try{return(e instanceof Document?e:e?.ownerDocument??document).createTreeWalker(e,NodeFilter.SHOW_ELEMENT)}catch{return null}},o=[];for(enqueue(document);a.length;){let e=a.shift();if(!e)continue;e instanceof Element&&matches(e)&&o.push({element:e,tag:e.tagName??``,id:e.id??``,className:e.className??``,text:extractText(e)});let t=walkerFor(e);if(!t)continue;let n;for(;n=t.nextNode();){if(!(n instanceof Element))continue;matches(n)&&o.push({element:n,tag:n.tagName??``,id:n.id??``,className:n.className??``,text:extractText(n)});let e=getOpenOrClosedShadowRoot(n);e&&enqueue(e)}}let s=[];for(let e of o){let t=e.element,n=!1;for(let r of o)if(e!==r)try{if(t.contains(r.element)){n=!0;break}}catch{}n||s.push(e)}return{count:s.length,sample:s.slice(0,5).map(e=>({tag:e.tag,id:e.id,class:e.className,text:e.text})),error:null}}function countXPathMatchesMainWorld(e){return countXPathMatches(e,{pierceShadow:!0})}var t=`__v3_cursor_overlay__`,n=null,r=null,i=!1;function positionCursor(e,t,n){e.style.left=`${Math.max(0,t)}px`,e.style.top=`${Math.max(0,n)}px`}function scheduleInstall(){if(i)return;i=!0;let retry=()=>{i=!1,installCursorOverlay()};document.addEventListener(`DOMContentLoaded`,retry,{once:!0}),globalThis.setTimeout(retry,100)}function installCursorOverlay(){try{if(n?.isConnected)return!0;let e=document.getElementById(t);if(e instanceof HTMLDivElement)n=e;else{let e=document.documentElement??document.body??document.head;if(!e)return scheduleInstall(),!1;let r=document.createElement(`div`);r.id=t,r.style.position=`fixed`,r.style.left=`0px`,r.style.top=`0px`,r.style.width=`16px`,r.style.height=`24px`,r.style.zIndex=`2147483647`,r.style.pointerEvents=`none`,r.style.userSelect=`none`,r.style.mixBlendMode=`normal`,r.style.contain=`layout style paint`,r.style.willChange=`transform,left,top`,r.innerHTML=`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="24" viewBox="0 0 16 24"><path d="M1 0 L1 22 L6 14 L15 14 Z" fill="black" stroke="white" stroke-width="0.7"/></svg>`,e.appendChild(r),n=r}return r&&=(positionCursor(n,r[0],r[1]),null),!0}catch{return!1}}function moveCursorOverlay(e,t){return r=[e,t],!installCursorOverlay()||!n?!1:(positionCursor(n,e,t),r=null,!0)}var parseTargetIndex=e=>{let t=Number(e??0);return!Number.isFinite(t)||t<0?0:Math.floor(t)},collectCssMatches=(e,t)=>{if(!e)return[];let n=new WeakSet,r=new Set,i=[],a=[document],visit=o=>{if(!(!o||n.has(o)||i.length>=t)){n.add(o);try{let n=o.querySelectorAll(e);for(let e of n)if(!r.has(e)&&(r.add(e),i.push(e),i.length>=t))return}catch{}try{let e=(o instanceof Document?o:o.host?.ownerDocument??document).createTreeWalker(o,NodeFilter.SHOW_ELEMENT),t;for(;t=e.nextNode();){if(!(t instanceof Element))continue;let e=getOpenOrClosedShadowRoot(t);e&&a.push(e)}}catch{}}};for(;a.length&&i.length<t;){let e=a.shift();e&&visit(e)}return i};function resolveCssSelector(e,t){let n=String(e??``).trim();if(!n)return null;let r=parseTargetIndex(t);return collectCssMatches(n,r+1)[r]??null}function resolveTextSelector(e,t){let n=String(e??``);if(!n)return null;let r=n.toLowerCase(),i=parseTargetIndex(t),a=new Set([`SCRIPT`,`STYLE`,`TEMPLATE`,`NOSCRIPT`,`HEAD`,`TITLE`,`LINK`,`META`,`HTML`,`BODY`]),shouldSkip=e=>{if(!e)return!1;let t=e.tagName?.toUpperCase()??``;return a.has(t)},extractText=e=>{try{if(shouldSkip(e))return``;let t=e.innerText;if(typeof t==`string`&&t.trim())return t.trim()}catch{}try{let t=e.textContent;if(typeof t==`string`)return t.trim()}catch{}return``},matches=e=>{let t=extractText(e);return!!t&&t.toLowerCase().includes(r)},o=new WeakSet,s=[],c=[],enqueue=e=>{!e||o.has(e)||(o.add(e),s.push(e))},walkerFor=e=>{try{return(e instanceof Document?e:e?.ownerDocument??document).createTreeWalker(e,NodeFilter.SHOW_ELEMENT)}catch{return null}};for(enqueue(document);s.length;){let e=s.shift();if(!e)continue;e instanceof Element&&matches(e)&&c.push({element:e,tag:e.tagName??``,id:e.id??``,className:e.className??``,text:extractText(e)});let t=walkerFor(e);if(!t)continue;let n;for(;n=t.nextNode();){if(!(n instanceof Element))continue;matches(n)&&c.push({element:n,tag:n.tagName??``,id:n.id??``,className:n.className??``,text:extractText(n)});let e=getOpenOrClosedShadowRoot(n);e&&enqueue(e)}}let l=[];for(let e of c){let t=e.element,n=!1;for(let r of c)if(e!==r)try{if(t.contains(r.element)){n=!0;break}}catch{}n||l.push(e)}return l[i]?.element??null}function resolveXPathMainWorld(e,t){return resolveXPathAtIndex(e,parseTargetIndex(t),{pierceShadow:!0})}var isXPath=e=>e.startsWith(`xpath=`)||e.startsWith(`/`),deepQuerySelector=(e,t,n)=>{try{let n=e.querySelector(t);if(n)return n}catch{}if(!n)return null;let r=new WeakSet,i=[e];for(;i.length>0;){let e=i.shift();if(!(!e||r.has(e))){r.add(e);try{let n=e.querySelector(t);if(n)return n}catch{}try{let t=(e instanceof Document?e:e.host?.ownerDocument??document).createTreeWalker(e,NodeFilter.SHOW_ELEMENT),n;for(;n=t.nextNode();){if(!(n instanceof Element))continue;let e=getOpenOrClosedShadowRoot(n);e&&!r.has(e)&&i.push(e)}}catch{}}}return null},deepXPathQuery=(e,t)=>resolveXPathFirst(e,{pierceShadow:t}),findElement=(e,t)=>isXPath(e)?deepXPathQuery(e,t):deepQuerySelector(document,e,t),checkState=(e,t)=>{if(t===`detached`)return e===null;if(t===`attached`)return e!==null;if(e===null)return!1;if(t===`hidden`)try{let t=window.getComputedStyle(e),n=e.getBoundingClientRect();return t.display===`none`||t.visibility===`hidden`||t.opacity===`0`||n.width===0||n.height===0}catch{return!1}try{let t=window.getComputedStyle(e),n=e.getBoundingClientRect();return t.display!==`none`&&t.visibility!==`hidden`&&t.opacity!==`0`&&n.width>0&&n.height>0}catch{return!1}},setupShadowObservers=(e,t,n)=>{let r=new WeakSet,observeShadowRoots=n=>{let i=getOpenOrClosedShadowRoot(n);if(i&&!r.has(i)){r.add(i);let n=new MutationObserver(()=>{e(),scan()});t.push(n),n.observe(i,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`style`,`class`,`hidden`,`disabled`]});for(let e of Array.from(i.children))observeShadowRoots(e)}for(let e of Array.from(n.children))observeShadowRoots(e)},i=document.documentElement||document.body,scan=()=>{!n()&&i&&observeShadowRoots(i)};return scan(),scan};function createSelectorWait(e,t,n,r){let i=String(e??``).trim(),a=String(t??`visible`)||`visible`,o=typeof n==`number`&&n>=0?n:3e4,s=r!==!1,dispose=()=>{},c=new Promise((e,t)=>{let n=!1,r,c,domReadyHandler,l,u=[],settle=i=>{if(!n){n=!0,clearTimeout(r),clearInterval(c);for(let e of u)e.disconnect();u.length=0,l=void 0,domReadyHandler&&=(document.removeEventListener(`DOMContentLoaded`,domReadyHandler),void 0),i?t(i):e(!0)}};dispose=()=>settle(Error(`Selector wait disposed`));let check=()=>{if(!n)try{checkState(findElement(i,s),a)&&settle()}catch(e){settle(e instanceof Error?e:Error(String(e)))}},setupObservers=()=>{if(n)return;let e=document.body||document.documentElement;if(e)try{let t=new MutationObserver(()=>{check(),l?.()});u.push(t),t.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`style`,`class`,`hidden`,`disabled`]}),s&&(l=setupShadowObservers(check,u,()=>n),c=setInterval(()=>{l?.(),check()},100))}catch(e){settle(e instanceof Error?e:Error(String(e)))}};check(),!n&&(document.body||document.documentElement?setupObservers():(domReadyHandler=()=>{n||(document.removeEventListener(`DOMContentLoaded`,domReadyHandler),domReadyHandler=void 0,check(),setupObservers())},document.addEventListener(`DOMContentLoaded`,domReadyHandler)),!n&&o>0&&(r=setTimeout(()=>settle(Error(`waitForSelector: Timeout ${o}ms exceeded waiting for "${i}" to be ${a}`)),o)))});return c.catch(()=>{}),{promise:c,dispose:()=>dispose()}}var a=Object.freeze({countCssMatchesPrimary,countTextMatches,countXPathMatchesMainWorld,getOpenOrClosedShadowRoot,installCursorOverlay,moveCursorOverlay,resolveCssSelector,resolveTextSelector,resolveXPathMainWorld,createSelectorWait}),o=globalThis;if(o.__stagehandExtensionWorld||Object.defineProperty(o,"__stagehandExtensionWorld",{configurable:!1,enumerable:!1,writable:!1,value:Object.freeze({name:`stagehand`,version:`stagehand.v4`})}),o.__stagehandLocatorScripts||Object.defineProperty(o,"__stagehandLocatorScripts",{configurable:!1,enumerable:!1,writable:!1,value:a}),!o.__stagehandLocatorWorld){let e=typeof globalThis.chrome?.dom?.openOrClosedShadowRoot==`function`;Object.defineProperty(o,"__stagehandLocatorWorld",{configurable:!1,enumerable:!1,writable:!1,value:Object.freeze({kind:e?`extension`:`cdp-fallback`,closedShadowRoots:e})})}})();
@@ -0,0 +1 @@
1
+ var e=1e3,t=null;function sendServiceWorkerHeartbeat(){t?.postMessage({type:`StagehandExtensionServiceWorkerHeartbeat`,at:new Date().toISOString()})}function connectServiceWorkerHeartbeatPort(){t=chrome.runtime.connect({name:`StagehandExtensionServiceWorkerHeartbeat`}),t.onDisconnect.addListener(()=>{t=null,setTimeout(connectServiceWorkerHeartbeatPort,250)}),sendServiceWorkerHeartbeat()}connectServiceWorkerHeartbeatPort(),setInterval(sendServiceWorkerHeartbeat,e);