d out after "+callbackTimeout+"ms"});},callbackTimeout);});} let promise=new Promise((resolve,reject)=>{let lines=functionString.split("\n");let prefixLines=[];while(lines&&lines[0].startsWith("//")){prefixLines.push(lines.shift());} functionString=lines.join("\n");let prefix=prefixLines.join("\n") if(prefix) prefix+="\n";let functionValue=evaluate(prefix+"(async "+functionString+")");if(typeof functionValue!=="function") reject(new TypeError("Script did not evaluate to a function."));this._clearStaleNodes();let argumentValues=argumentStrings.map(this._jsonParse,this);if(expectsImplicitCallbackArgument) argumentValues.push(resolve);let resultPromise=functionValue.apply(null,argumentValues);let promises=[resultPromise];if(timeoutPromise) promises.push(timeoutPromise);Promise.race(promises).then(result=>{if(!expectsImplicitCallbackArgument){resolve(result);}}).catch(error=>{reject(error);});}); let promises=[promise];if(timeoutPromise) promises.push(timeoutPromise);return Promise.race(promises).finally(()=>{if(timeoutIdentifier){clearTimeout(timeoutIdentifier);}});} _jsonParse(string) {if(!string) return undefined;return JSON.parse(string,(key,value)=>this._reviveJSONValue(key,value));} _jsonStringify(value) {return JSON.stringify(this._jsonClone(value));} _reviveJSONValue(key,value) {if(value&&typeof value==="object"&&value[sessionNodePropertyName]) return this._nodeForIdentifier(value[sessionNodePropertyName]);return value;} _isCollection(value){switch(Object.prototype.toString.call(value)){case"[object Arguments]":case"[object Array]":case"[object FileList]":case"[object HTMLAllCollection]":case"[object HTMLCollection]":case"[object HTMLFormControlsCollection]":case"[object HTMLOptionsCollection]":case"[object NodeList]":return true;} return false;} _checkCyclic(value,stack=[]) {function isCyclic(value,proxy,stack=[]){if(value===undefined||value===null) return false;if(typeof value==="boolean"||typeof value==="number"||typeof value==="string") return false;if(value instanceof Node) return false;if(stack.includes(value)) return true;if(proxy._isCollection(value)){stack.push(value);for(let i=0;ithis._jsonClone(item));} if(value instanceof Node) return this._createNodeHandle(value);if(typeof value.toJSON==="function") return value.toJSON();let customObject={};for(let property in value){this._checkCyclic(value);customObject[property]=this._jsonClone(value[property]);} return customObject;} _createNodeHandle(node) {if(node.ownerDocument!==window.document||!node.isConnected) throw{name:"NodeNotFound",message:"Stale element found when trying to create the node handle"};return{[sessionNodePropertyName]:this._identifierForNode(node)};} _nodeForIdentifier(identifier) {if(!isValidNodeIdentifier(identifier)) throw{name:"InvalidNodeIdentifier",message:"Node identifier '"+identifier+"' is invalid"};let node=this._idToNodeMap.get(identifier);if(node) return node;throw{name:"NodeNotFound",message:"Node with identifier '"+identifier+"' was not found"};} _identifierForNode(node) {let identifier=this._nodeToIdMap.get(node);if(identifier) return identifier;identifier="node-"+createUUID();this._nodeToIdMap.set(node,identifier);this._idToNodeMap.set(identifier,node);return identifier;} _clearStaleNodes() {for(var[node,identifier]of this._nodeToIdMap){const rootNode=node.getRootNode({composed:true});if(rootNode!==document){this._nodeToIdMap.delete(node);this._idToNodeMap.delete(identifier);}}}};return new AutomationSessionProxy;})