browser-automator
Advanced tools
Comparing version 3.5.47 to 3.5.49
@@ -1,1 +0,1 @@ | ||
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var a=t();for(var n in a)("object"==typeof exports?exports:e)[n]=a[n]}}(this,(()=>(()=>{"use strict";var e={148:function(e,t,a){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=n(a(869)),o=a(16),r=async e=>{await chrome.scripting.executeScript({target:{tabId:e},func:o.selfIntegration}).catch((()=>{}))};t.default=class{availablePages=[];constructor(){onbeforeunload=e=>(e.preventDefault(),this.close(),!1),this.syncListeners()}pages(){return this.availablePages}async close(){try{onbeforeunload=null,await Promise.all(this.availablePages.map((async e=>{const{tabId:t,originWindowId:a,activeInOrigin:n,onBeforeClose:i}=e;i&&i(),a?(a!==(await chrome.tabs.get(t)).windowId&&await chrome.tabs.move(t,{index:-1,windowId:a}),n&&await chrome.tabs.update(t,{active:!0})):await e.close()}))),this.availablePages=[],this.syncListeners()}catch(e){throw e}}async newPage({tabId:e,windowId:t,originWindowId:a,activeInOrigin:n,windowOptions:o,tabOptions:l}={}){try{t?e?l&&await chrome.tabs.update(e,l):await chrome.tabs.create({url:"about:blank",...l}).then((t=>{e=t.id})):(await chrome.windows.create({type:"popup",focused:!0,width:1e3,left:Math.round(.5*(screen.availWidth-1e3)),height:650,top:Math.round(.5*(screen.availHeight-650)),...e?{tabId:e}:{url:"about:blank"},...o||{}}).then((a=>{e=a.tabs[0].id,t=a.id})),l&&await chrome.tabs.update(e,l));const s=new i.default({browser:this,tabId:e,windowId:t,...a?{originWindowId:a,activeInOrigin:n||!1}:{}});return this.availablePages.push(s),this?.onPageAdded?.(s),this.syncListeners(),r(e),s}catch(e){throw e}}onPageAdded;onPageClose;onPageUpdate;handleTabRemove=(e,t)=>{const a=this.availablePages.findIndex((({tabId:t})=>t===e));-1!==a&&(this?.onPageClose?.(e,t),this.availablePages.splice(a,1))};handleTabUpdate=(e,t,a)=>{const n=this.availablePages.findIndex((({tabId:t})=>t===e));-1!==n&&(this?.onPageUpdate?.(this.availablePages[n]),"complete"===t.status&&a.url?.match(/^HTTP/i)&&r(e))};syncListeners(){this.availablePages.length?(chrome.tabs.onUpdated.hasListener(this.handleTabUpdate)||chrome.tabs.onUpdated.addListener(this.handleTabUpdate),chrome.tabs.onRemoved.hasListener(this.handleTabRemove)||chrome.tabs.onRemoved.addListener(this.handleTabRemove)):(chrome.tabs.onUpdated.hasListener(this.handleTabUpdate)&&chrome.tabs.onUpdated.removeListener(this.handleTabUpdate),chrome.tabs.onRemoved.hasListener(this.handleTabRemove)&&chrome.tabs.onRemoved.removeListener(this.handleTabRemove))}}},792:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=class{page;elementPath;tagName;async handleCall(e,t){return await this.page.evaluate({func:(e,t,a)=>a?window.Self.ElementActions.handleCall(e,t,a):window.Self.ElementActions.handleCall(e,t),args:t?[this.elementPath,e,t]:[this.elementPath,e]})}async handleGet(e){return await this.page.evaluate({func:(e,t)=>window.Self.ElementActions.handleGet(e,t),args:[this.elementPath,e]})}async handleSet(e,t){return await this.page.evaluate({func:(e,t,a)=>window.Self.ElementActions.handleSet(e,t,a),args:[this.elementPath,e,t]})}async getTagName(){return this.tagName||(this.tagName=await this.handleGet("tagName")),this.tagName}async getInnerText(){return await this.handleGet("innerText")}async getInnerHTML(){return await this.handleGet("innerHTML")}async setInnerHTML(e){return await this.handleSet("innerHTML",e)}async click(){return await this.handleCall("click")}async focus(){return await this.handleCall("focus")}async scrollIntoView(e){return await this.handleCall("scrollIntoView",[e])}async getAttribute(e){return await this.handleCall("getAttribute",[e])}async setAttribute(e,t){return await this.handleCall("setAttribute",[e,t])}async getElement(e,t=-1){return await this.page.getElement(e,t,this.elementPath)}async getElements(e){return await this.page.getElements(e,this.elementPath)}async input(e){return await this.page.evaluate({func:(e,t)=>{const a=window.Self.ElementActions.getElement(t);return!!a&&(window.Self.setValue(a,e),!0)},args:[e,this.elementPath]})}async execPaste(){return await this.page.evaluate({func:e=>{const t=window.Self.ElementActions.getElement(e);return!!t&&(window.Self.triggerPaste(t),!0)},args:[this.elementPath]})}async triggerEvent(e){return await this.page.evaluate({func:(e,t)=>{const a=window.Self.ElementActions.getElement(t);return!!a&&(window.Self.triggerEvent(a,e),!0)},args:[e,this.elementPath]})}constructor(e,t,a){this.page=e,this.elementPath=t,a&&(this.tagName=a)}}},419:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.chooseProperties=t.omitProperties=t.setValue=t.triggerEvent=t.getRandomFromArray=t.blobToDataUrl=t.imageBitmapFromUrl=t.cropImageOffscreen=t.doDelay=void 0,t.doDelay=async e=>new Promise((t=>setTimeout(t,e))),t.cropImageOffscreen=(e,t,a,n,i)=>{var o=new OffscreenCanvas(t,a);return o.getContext("2d").drawImage(e,n,i,t,a,0,0,t,a),o},t.imageBitmapFromUrl=async e=>await fetch(e).then((e=>e.blob())).then((async e=>createImageBitmap(e))),t.blobToDataUrl=async e=>new Promise((t=>{let a=new FileReader;a.onload=function(){t(this.result)},a.readAsDataURL(e)})),t.getRandomFromArray=e=>e[Math.floor(Math.random()*e.length)];const a=(e,t)=>{e.dispatchEvent(new Event(t,{bubbles:!0,cancelable:!0}))};t.triggerEvent=a,t.setValue=(e,t)=>{e.tagName.match(/INPUT|TEXTAREA|SELECT/i)?e.value=t:e.innerHTML=t,a(e,"focus"),a(e,"keydown"),a(e,"keypress"),a(e,"keyup"),a(e,"input"),a(e,"change"),a(e,"blur")},t.omitProperties=(e,t)=>Object.fromEntries(Object.entries(e).filter((([e])=>!t.includes(e)))),t.chooseProperties=(e,t)=>Object.fromEntries(Object.entries(e).filter((([e])=>t.includes(e))))},633:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.defaultPageConfigurations=t.defaultActionOptions=void 0,t.defaultActionOptions={scrollToElementBeforeAction:!0,scrollIntoViewOptions:{behavior:"smooth",block:"center"}},t.defaultPageConfigurations={tryLimit:30,delay:1e3,...t.defaultActionOptions}},869:function(e,t,a){var n=this&&this.__createBinding||(Object.create?function(e,t,a,n){void 0===n&&(n=a);var i=Object.getOwnPropertyDescriptor(t,a);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[a]}}),Object.defineProperty(e,n,i)}:function(e,t,a,n){void 0===n&&(n=a),e[n]=t[a]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var a in e)"default"!==a&&Object.prototype.hasOwnProperty.call(e,a)&&n(t,e,a);return i(t,e),t},r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const l=r(a(792)),s=a(419),c=a(633),h=o(a(16));t.default=class{browser;tabId;windowId;originWindowId;activeInOrigin;onBeforeClose;configurations=c.defaultPageConfigurations;async handleGlitch(e){return`${e}\nPage URL: '${await chrome.tabs.get(this.tabId).then((({url:e})=>e)).catch((()=>"N/A"))}'`}configure(e){this.configurations={...this.configurations,...e}}constructor({tabId:e,windowId:t,originWindowId:a,activeInOrigin:n,browser:i}){this.tabId=e,this.windowId=t,this.browser=i,a&&(this.originWindowId=a),n&&(this.activeInOrigin=n),this.elementCatcher.catch=this.elementCatcher.catch.bind(this),this.elementCatcher.terminate=this.elementCatcher.terminate.bind(this),this.manualClick.enable=this.manualClick.enable.bind(this),this.manualClick.disable=this.manualClick.disable.bind(this)}async goto(e,{waitUntil:t}={waitUntil:"domcontentloaded"}){try{let a;if(await chrome.tabs.update(this.tabId,{url:"about:blank"}),await chrome.tabs.update(this.tabId,{url:e}),"load"===t)do{await(0,s.doDelay)(this.configurations.delay),a=await chrome.tabs.get(this.tabId)}while("about:blank"===a.pendingUrl||"about:blank"===a.url);else if(t="domcontentloaded")do{await(0,s.doDelay)(this.configurations.delay),a=await chrome.tabs.get(this.tabId)}while("about:blank"===a.pendingUrl||"about:blank"===a.url||"complete"!==a.status)}catch(t){throw await this.handleGlitch(`Failed to navigate to URL '${e}'.\n${t}`)}}async reload(){try{await this.goto(await this.url())}catch(e){throw await this.handleGlitch(`Failed to reload the page.\n${e}`)}}async url(){try{const{url:e}=await chrome.tabs.get(this.tabId);return e}catch(e){throw await this.handleGlitch(`Failed to get the URL of the page.\n${e}`)}}async close(){try{await chrome.windows.remove(this.windowId).catch((()=>{}))}catch(e){throw await this.handleGlitch(`Failed to close the page.\n${e}`)}}async zoom(e){try{e!==await chrome.tabs.getZoom(this.tabId)&&await chrome.tabs.setZoom(this.tabId,e)}catch(e){throw await this.handleGlitch(`Failed to zoom the page.\n${e}`)}}async bringToFront(){try{await chrome.windows.update(this.windowId,{focused:!0})}catch(e){throw await this.handleGlitch(`Failed to bring the page to the front.\n${e}`)}}async hideFromFront(){try{await chrome.windows.update(this.windowId,{focused:!1})}catch(e){throw await this.handleGlitch(`Failed to hide the page from the front.\n${e}`)}}async evaluate(){let e={};try{if("function"==typeof arguments[0]){const[t,a,n]=arguments;e={func:t,args:a,...n||{}}}else if(Array.isArray(arguments[0])){const[t,a,n]=arguments;e={files:t,args:a,...n||{}}}else e=arguments[0];const t=await chrome.scripting.executeScript({target:{tabId:this.tabId,...(0,s.chooseProperties)(e,["allFrames","frameIds","documentIds"])},world:"ISOLATED",...(0,s.chooseProperties)(e,["func","files","args","world"])});return t?.[0]?.result}catch(t){throw await this.handleGlitch(`Failed to evaluate ${e?.func?`function '${e.func?.name}' with arguments '${JSON.stringify(e.args||[])}'`:`file(s) '${JSON.stringify(e.files||[])}'`} '' on the page.\n${t}`)}}async waitFor(e,t,a={}){try{let n,i=a.tryLimit||this.configurations.tryLimit,o=a.delay||this.configurations.delay;for(;!(n=await e(...t))&&i;)i--,await(0,s.doDelay)(o);if(n)return n;throw new Error("Waiting timed out...")}catch(a){throw await this.handleGlitch(`Glitch while waiting for function '${e?.name}' with arguments '${JSON.stringify(t||[])}'.\n${a}`)}}async waitForNavigation(e={}){try{const t=await this.url();await this.waitFor((async e=>await this.url()!==e),[t],e)}catch(e){throw await this.handleGlitch(`Glitch while waiting for navigation.\n${e}`)}}async waitForSelector(e,t={},a=-1){try{await this.waitFor((async e=>this.evaluate(e)),[{func:(e,t)=>!!window.Self.getElementBySelectors(e,document,t),args:[e,a]}],t)}catch(t){throw await this.handleGlitch(`Glitch while waiting for the CSS Selectors '${e}'${-1===a?"":`[${a}]`}.\n${t}`)}}async waitForXPath(e,t={},a=-1){try{await this.waitFor((async e=>this.evaluate(e)),[{func:(e,t)=>!!window.Self.getElementByXPath(e,document,t),args:[e,a]}],t)}catch(t){throw await this.handleGlitch(`Glitch while waiting for the XPath '${e}'${-1===a?"":`[${a}]`}.\n${t}`)}}async waitForElement(e,t={},a=-1){if(await(h.default.isXPath(e)?this.waitForXPath:this.waitForSelector)(e,t,a).then((()=>!0)).catch((()=>!1)))return await this.getElement(e,a)}async waitForElementMiss(e,t={},a=-1){return await this.waitFor((async e=>this.evaluate(e)),[{func:h.default.isXPath(e)?(e,t)=>!window.Self.getElementByXPath(e,document,t):(e,t)=>!window.Self.getElementBySelectors(e,document,t),args:[e,a]}],t).then((()=>!0)).catch((()=>!1))}element(e,t=-1){const a=`${e}⟮${t}⟯`;return new l.default(this,a)}async getElement(e,t=-1,a){const n=`${a?`${a}→${e}`:e}⟮${t}⟯`,{tagName:i}=await this.evaluate({func:e=>{const t=window.Self.ElementActions.getElement(e);return t?{tagName:t.tagName}:{}},args:[n]});if(i)return new l.default(this,n,i)}async getElements(e,t){const a=await this.evaluate({func:(e,t)=>{const a=t?window.Self.ElementActions.getElement(t):document;if(a)return window.Self.getElements(e,a).map((({tagName:a},n)=>({tagName:a,elementPath:t?`${t}→${e}⟮${n}⟯`:`${e}⟮${n}⟯`})))},args:[e,t]});return a?.map((({tagName:e,elementPath:t})=>new l.default(this,t,e)))}async elementExists(e,t=-1){try{return await this.evaluate({func:(e,t)=>!!window.Self.getElement(e,document,t),args:[e,t]})}catch(a){throw await this.handleGlitch(`Glitch while checking if element with the CSS Selectors or XPath '${e}'${-1===t?"":`[${t}]`} exists.\n${a}`)}}async click(e,t=-1){try{if(!await this.evaluate({func:(e,t,a)=>window.Self.click(e,t,a),args:[e,t,this.configurations]}))throw new Error("No element(s) found for the given CSS Selectors or XPath.")}catch(a){throw await this.handleGlitch(`Failed to click on element with the CSS Selectors or XPath '${e}'${-1===t?"":`[${t}]`}.\n${a}`)}}execCopy(e){const t=document.createElement("textarea");t.innerHTML=e,document.body.appendChild(t),t.select(),document.execCommand("copy"),t.remove()}async execPasteTo(e,t=-1){try{if(!await this.evaluate({func:(e,t,a)=>window.Self.execPasteTo(e,t,a),args:[e,t,this.configurations]}))throw new Error("No element(s) found for the given CSS Selectors or XPath.")}catch(a){throw await this.handleGlitch(`Failed to paste to element with the CSS Selectors or XPath '${e}'${-1===t?"":`[${t}]`}.\n${a}`)}}async triggerEvent(e,t,a=-1){try{if(!await this.evaluate({func:(e,t,a,{scrollToElementBeforeAction:n,scrollIntoViewOptions:i})=>{const o=window.Self.getElement(e,document,a);return!!o&&(n&&o.scrollIntoView(i),window.Self.triggerEvent(o,t),!0)},args:[e,t,a,this.configurations]}))throw new Error("No element(s) found for the given CSS Selectors or XPath.")}catch(n){throw await this.handleGlitch(`Failed to trigger event '${t}' on element with the CSS Selectors or XPath '${e}'${-1===a?"":`[${a}]`}.\n${n}`)}}async input(e,t,a=-1){try{if(!await this.evaluate({func:(e,t,a,n)=>window.Self.input(e,t,a,n),args:[e,t,a,this.configurations]}))throw new Error("No element(s) found for the given CSS Selectors or XPath.")}catch(n){throw await this.handleGlitch(`Failed to input value '${t}' into element with the CSS Selectors or XPath '${e}'${-1===a?"":`[${a}]`}.\n${n}`)}}async uploadFiles(e,t,a){try{const n=a?"MAIN":"ISOLATED",i=await this.evaluate({world:n,func:e=>(window.transmittedFiles||(window.transmittedFiles=[]),window.transmittedFiles.push(e)-1),args:[t.map((({name:e},a)=>Object.assign({name:e},t[a].blob&&(t[a].blobUrl=URL.createObjectURL(t[a].blob))?{blobUrl:t[a].blobUrl}:{dataUrl:""})))]});for(let e=0;e<t.length;e++)if(t[e].dataUrl){let a=t[e].dataUrl.length,o=5242880,r=0;for(;r<a;)await this.evaluate({world:n,func:(e,t,a)=>{window.transmittedFiles[e][t].dataUrl+=a},args:[i,e,t[e].dataUrl.substr(r,o)]}),r+=o}await this.evaluate((async(e,t,a=-1,{scrollToElementBeforeAction:n,scrollIntoViewOptions:i})=>{const o=t?t.match(/^(\/|\.\/|\()/)?document.evaluate(t,document.documentElement,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue:document.querySelector(t):window.Self.elementCatcher.current?.elements[a];return!!o&&(n&&o.scrollIntoView(i),o.files=window.Self.filesToFileList(await Promise.all(window.transmittedFiles[e].map((async({blobUrl:e,dataUrl:t,name:a})=>e?window.Self.blobToFile(await window.Self.getBlob(e),a):window.Self.dataUrlToFile(t,a))))),window.Self.triggerEvent(o,"input"),window.Self.triggerEvent(o,"change"),delete window.transmittedFiles[e],0===window.transmittedFiles.filter(Boolean).length&&delete window.transmittedFiles,!0)}),[i,e,a,this.configurations],{world:n}),t.forEach((({blobUrl:e})=>URL.revokeObjectURL(e)))}catch(e){throw await this.handleGlitch(`Failed to upload files.\n${e}`)}}async screenshot({clip:e}){try{let t=await chrome.tabs.captureVisibleTab(this.windowId,{format:"png"});if(e){const{width:a,height:n,x:i,y:o}=e,r=await(0,s.cropImageOffscreen)(await(0,s.imageBitmapFromUrl)(t),a,n,i,o);t=await(0,s.blobToDataUrl)(await r.convertToBlob())}return t}catch(e){throw await this.handleGlitch(`Failed to take a screenshot.\n${e}`)}}elementCatcher={catch:async function(e){try{await this.evaluate({world:"MAIN",func:()=>window.Self?.exists()})||await this.evaluate({world:"MAIN",func:h.selfIntegration}),await this.evaluate({world:"MAIN",func:e=>window.Self.elementCatcher.catch(e),args:[e]})}catch(e){throw e}},terminate:async function(){try{await this.evaluate({world:"MAIN",func:()=>window.Self?.elementCatcher.terminate()})}catch(e){throw e}}};manualClick={enable:async function(){try{await this.evaluate((()=>window.Self.manualClick.enable()))}catch(e){throw e}},disable:async function(){try{await this.evaluate((()=>window.Self.manualClick.disable()))}catch(e){throw e}}}}},16:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.selfIntegration=void 0;const a=(e=!0)=>{const t={scrollToElementBeforeAction:!0,scrollIntoViewOptions:{behavior:"smooth",block:"center"}},a={tryLimit:30,delay:1e3,...t},n=async e=>new Promise((t=>setTimeout(t,e))),i=(e,t)=>{e.dispatchEvent(new Event(t,{bubbles:!0,cancelable:!0}))},o=(e,t)=>{e.tagName.match(/INPUT|TEXTAREA|SELECT/i)?e.value=t:e.innerHTML=t,i(e,"focus"),i(e,"keydown"),i(e,"keypress"),i(e,"keyup"),i(e,"input"),i(e,"change"),i(e,"blur")},r=e=>{e.focus(),"INPUT"!==e.tagName&&"TEXTAREA"!==e.tagName||e.select(),document.execCommand("paste")},l=e=>e.match(/^(\/|\.\/|\()/),s=(e,t=document,a=-1)=>-1===a?document.evaluate(e,t,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue:document.evaluate(e,t,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotItem(a),c=(e,t=document)=>{let a=[],n=document.evaluate(e,t,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);for(let e=0;e<n.snapshotLength;e++)a.push(n.snapshotItem(e));return a},h=(e,t=document,a=-1)=>-1===a?t.querySelector(e):t.querySelectorAll(e)[a],d=(e,t=document)=>Array.from(t.querySelectorAll(e)),u=(e,t=document,a=-1)=>l(e)?s(e,t,a):h(e,t,a),w={catch:e=>!w.current&&(w.current={originalFunc:document.createElement,elements:[],tagNames:e.map((e=>e.toUpperCase()))},document.createElement=function(){const e=w.current?.originalFunc.apply(this,arguments);return w.current?.tagNames.includes(e.tagName)&&w.current.elements.push(e),e},!0),terminate:()=>!!w.current&&(document.createElement=w.current.originalFunc,delete w.current,!0)},m={enable:()=>{m.current&&(m.current.element.remove(),delete m.current)},disable:()=>{m.current||(m.current={element:document.createElement("div")},m.current.element.style="width: 100%; height: 100%; position: fixed; top: 0; cursor: not-allowed; z-index: 12500; left: 0;",m.current.element.addEventListener("contextmenu",(e=>e.preventDefault())),document.body.appendChild(m.current.element))}},f=()=>location.href,g=async(e,t,i={})=>{let o,r=i.tryLimit||a.tryLimit,l=i.delay||a.delay;for(;!(o=await e(...t))&&r;)r--,await n(l);if(o)return o;throw new Error("Waiting timed out...")};class b{static elements=new Map;static getElement(e){let t=this.elements.get(e);if(t)return t;for(const a of e.split("→")){let[,e,n]=a.match(/(.+)⟮([0-9-]+)⟯$/);n=Number(n),t=u(e,t||document,n)}return t?(this.elements.size>50&&this.elements.delete(this.elements.keys().next().value),this.elements.set(e,t),t):void 0}static handleCall(e,t,a){const n=this.getElement(e);return a?n?.[t](...a):n?.[t]()}static handleGet(e,t){const a=this.getElement(e);return a?.[t]}static handleSet(e,t,a){this.getElement(e)[t]=a}}const y={exists:()=>!0,ElementActions:b,getElement:u,getElements:(e,t=document)=>l(e)?c(e,t):d(e,t),getElementBySelectors:h,getElementsBySelectors:d,getElementByXPath:s,getElementsByXPath:c,triggerEvent:i,triggerPaste:r,setValue:o,isXPath:l,filesToFileList:e=>{const t=new DataTransfer;for(const a of e)t.items.add(a);return t.files},getBlob:e=>new Promise((t=>{var a=new XMLHttpRequest;a.open("GET",e,!0),a.responseType="blob",a.onload=()=>t(a.response),a.send()})),dataUrlToFile:(e,t)=>{let[a,n]=e.split(",");a=a.match(/:(.*?);/)[1],n=atob(n);let i=n.length,o=new Uint8Array(i);for(;i--;)o[i]=n.charCodeAt(i);return new File([o],t,{type:a})},blobToFile:(e,t)=>new File([e],t,{type:e.type}),goto:e=>location.href=e,reload:()=>location.reload(),url:f,close:()=>globalThis.close(),zoom:e=>document.body.style.zoom=e,waitFor:g,waitForNavigation:async(e={})=>{const t=f();await g((async e=>f()!==e),[t],e)},waitForElement:async(e,t={},a=-1)=>{await g(l(e)?(e,t)=>!!s(e,document,t):(e,t)=>!!h(e,document,t),[e,a],t)},waitForElementMiss:async(e,t={},a=-1)=>{await g(l(e)?(e,t)=>!s(e,document,t):(e,t)=>!h(e,document,t),[e,a],t)},click:(e,a=-1,{scrollToElementBeforeAction:n,scrollIntoViewOptions:i}=t)=>{const o=u(e,document,a);return!!o&&(n&&o.scrollIntoView(i),o.click(),!0)},elementExists:(e,t=-1)=>!!u(e,document,t),execPasteTo:(e,a=-1,{scrollToElementBeforeAction:n,scrollIntoViewOptions:i}=t)=>{const o=u(e,document,a);return!!o&&(n&&o.scrollIntoView(i),r(o),!0)},input:(e,a,n=-1,{scrollToElementBeforeAction:i,scrollIntoViewOptions:r}=t)=>{const l=u(e,document,n);return!!l&&(i&&l.scrollIntoView(r),o(l,a),!0)},elementCatcher:w,manualClick:m};return e&&!window.Self?.exists?.()&&(window.Self=y),y};t.selfIntegration=a;const n=a(!1);t.default=n}},t={};return function a(n){var i=t[n];if(void 0!==i)return i.exports;var o=t[n]={exports:{}};return e[n].call(o.exports,o,o.exports,a),o.exports}(148)})())); | ||
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var a=t();for(var n in a)("object"==typeof exports?exports:e)[n]=a[n]}}(this,(()=>(()=>{"use strict";var e={148:function(e,t,a){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=n(a(869)),o=a(16),r=async e=>{await chrome.scripting.executeScript({target:{tabId:e},func:o.selfIntegration}).catch((()=>{}))};t.default=class{availablePages=[];constructor(){onbeforeunload=e=>(e.preventDefault(),this.close(),!1),this.syncListeners()}pages(){return this.availablePages}async close(){try{onbeforeunload=null,await Promise.all(this.availablePages.map((async e=>{const{tabId:t,originWindowId:a,activeInOrigin:n,onBeforeClose:i}=e;i&&i(),a?(a!==(await chrome.tabs.get(t)).windowId&&await chrome.tabs.move(t,{index:-1,windowId:a}),n&&await chrome.tabs.update(t,{active:!0})):await e.close()}))),this.availablePages=[],this.syncListeners()}catch(e){throw e}}async newPage({tabId:e,windowId:t,originWindowId:a,activeInOrigin:n,windowOptions:o,tabOptions:l}={}){try{t?e?l&&await chrome.tabs.update(e,l):await chrome.tabs.create({url:"about:blank",...l}).then((t=>{e=t.id})):(await chrome.windows.create({type:"popup",focused:!0,width:1e3,left:Math.round(.5*(screen.availWidth-1e3)),height:650,top:Math.round(.5*(screen.availHeight-650)),...e?{tabId:e}:{url:"about:blank"},...o||{}}).then((a=>{e=a.tabs[0].id,t=a.id})),l&&await chrome.tabs.update(e,l));const s=new i.default({browser:this,tabId:e,windowId:t,...a?{originWindowId:a,activeInOrigin:n||!1}:{}});return this.availablePages.push(s),this?.onPageAdded?.(s),this.syncListeners(),r(e),s}catch(e){throw e}}onPageAdded;onPageClose;onPageUpdate;handleTabRemove=(e,t)=>{const a=this.availablePages.findIndex((({tabId:t})=>t===e));-1!==a&&(this?.onPageClose?.(e,t),this.availablePages.splice(a,1))};handleTabUpdate=(e,t,a)=>{const n=this.availablePages.findIndex((({tabId:t})=>t===e));-1!==n&&(this?.onPageUpdate?.(this.availablePages[n]),"complete"===t.status&&a.url?.match(/^HTTP/i)&&r(e))};syncListeners(){this.availablePages.length?(chrome.tabs.onUpdated.hasListener(this.handleTabUpdate)||chrome.tabs.onUpdated.addListener(this.handleTabUpdate),chrome.tabs.onRemoved.hasListener(this.handleTabRemove)||chrome.tabs.onRemoved.addListener(this.handleTabRemove)):(chrome.tabs.onUpdated.hasListener(this.handleTabUpdate)&&chrome.tabs.onUpdated.removeListener(this.handleTabUpdate),chrome.tabs.onRemoved.hasListener(this.handleTabRemove)&&chrome.tabs.onRemoved.removeListener(this.handleTabRemove))}}},792:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=class{page;elementPath;tagName;async handleCall(e,t){return await this.page.evaluate({func:(e,t,a)=>a?window.Self.ElementActions.handleCall(e,t,a):window.Self.ElementActions.handleCall(e,t),args:t?[this.elementPath,e,t]:[this.elementPath,e]})}async handleGet(e){return await this.page.evaluate({func:(e,t)=>window.Self.ElementActions.handleGet(e,t),args:[this.elementPath,e]})}async handleSet(e,t){return await this.page.evaluate({func:(e,t,a)=>window.Self.ElementActions.handleSet(e,t,a),args:[this.elementPath,e,t]})}async getTagName(){return this.tagName||(this.tagName=await this.handleGet("tagName")),this.tagName}async getInnerText(){return await this.handleGet("innerText")}async getInnerHTML(){return await this.handleGet("innerHTML")}async setInnerHTML(e){return await this.handleSet("innerHTML",e)}async click(){return await this.handleCall("click")}async focus(){return await this.handleCall("focus")}async scrollIntoView(e){return await this.handleCall("scrollIntoView",[e])}async getAttribute(e){return await this.handleCall("getAttribute",[e])}async setAttribute(e,t){return await this.handleCall("setAttribute",[e,t])}async getElement(e,t=-1){return await this.page.getElement(e,t,this.elementPath)}async getElements(e){return await this.page.getElements(e,this.elementPath)}async input(e){return await this.page.evaluate({func:(e,t)=>{const a=window.Self.ElementActions.getElement(t);return!!a&&(window.Self.setValue(a,e),!0)},args:[e,this.elementPath]})}async execPaste(){return await this.page.evaluate({func:e=>{const t=window.Self.ElementActions.getElement(e);return!!t&&(window.Self.triggerPaste(t),!0)},args:[this.elementPath]})}async triggerEvent(e){return await this.page.evaluate({func:(e,t)=>{const a=window.Self.ElementActions.getElement(t);return!!a&&(window.Self.triggerEvent(a,e),!0)},args:[e,this.elementPath]})}constructor(e,t,a){this.page=e,this.elementPath=t,a&&(this.tagName=a)}}},419:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.chooseProperties=t.omitProperties=t.setValue=t.triggerEvent=t.getRandomFromArray=t.blobToDataUrl=t.imageBitmapFromUrl=t.cropImageOffscreen=t.doDelay=void 0,t.doDelay=async e=>new Promise((t=>setTimeout(t,e))),t.cropImageOffscreen=(e,t,a,n,i)=>{var o=new OffscreenCanvas(t,a);return o.getContext("2d").drawImage(e,n,i,t,a,0,0,t,a),o},t.imageBitmapFromUrl=async e=>await fetch(e).then((e=>e.blob())).then((async e=>createImageBitmap(e))),t.blobToDataUrl=async e=>new Promise((t=>{let a=new FileReader;a.onload=function(){t(this.result)},a.readAsDataURL(e)})),t.getRandomFromArray=e=>e[Math.floor(Math.random()*e.length)];const a=(e,t)=>{e.dispatchEvent(new Event(t,{bubbles:!0,cancelable:!0}))};t.triggerEvent=a,t.setValue=(e,t)=>{e.tagName.match(/INPUT|TEXTAREA|SELECT/i)?e.value=t:e.innerHTML=t,a(e,"focus"),a(e,"keydown"),a(e,"keypress"),a(e,"keyup"),a(e,"input"),a(e,"change"),a(e,"blur")},t.omitProperties=(e,t)=>Object.fromEntries(Object.entries(e).filter((([e])=>!t.includes(e)))),t.chooseProperties=(e,t)=>Object.fromEntries(Object.entries(e).filter((([e])=>t.includes(e))))},633:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.defaultPageConfigurations=t.defaultActionOptions=void 0,t.defaultActionOptions={scrollToElementBeforeAction:!0,scrollIntoViewOptions:{behavior:"smooth",block:"center"}},t.defaultPageConfigurations={tryLimit:30,delay:1e3,...t.defaultActionOptions}},869:function(e,t,a){var n=this&&this.__createBinding||(Object.create?function(e,t,a,n){void 0===n&&(n=a);var i=Object.getOwnPropertyDescriptor(t,a);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[a]}}),Object.defineProperty(e,n,i)}:function(e,t,a,n){void 0===n&&(n=a),e[n]=t[a]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var a in e)"default"!==a&&Object.prototype.hasOwnProperty.call(e,a)&&n(t,e,a);return i(t,e),t},r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const l=r(a(792)),s=a(419),c=a(633),h=o(a(16));t.default=class{browser;tabId;windowId;originWindowId;activeInOrigin;onBeforeClose;configurations=c.defaultPageConfigurations;async handleGlitch(e){return`${e}\nPage URL: '${await chrome.tabs.get(this.tabId).then((({url:e})=>e)).catch((()=>"N/A"))}'`}configure(e){this.configurations={...this.configurations,...e}}constructor({tabId:e,windowId:t,originWindowId:a,activeInOrigin:n,browser:i}){this.tabId=e,this.windowId=t,this.browser=i,a&&(this.originWindowId=a),n&&(this.activeInOrigin=n),this.elementCatcher.catch=this.elementCatcher.catch.bind(this),this.elementCatcher.terminate=this.elementCatcher.terminate.bind(this),this.manualClick.enable=this.manualClick.enable.bind(this),this.manualClick.disable=this.manualClick.disable.bind(this)}async goto(e,{waitUntil:t}={waitUntil:"domcontentloaded"}){try{if(await chrome.tabs.update(this.tabId,{url:"about:blank"}),"about:blank"===e)return;let a;if(await chrome.tabs.update(this.tabId,{url:e}),"load"===t)do{await(0,s.doDelay)(this.configurations.delay),a=await chrome.tabs.get(this.tabId)}while("about:blank"===a.pendingUrl||"about:blank"===a.url);else if(t="domcontentloaded")do{await(0,s.doDelay)(this.configurations.delay),a=await chrome.tabs.get(this.tabId)}while("about:blank"===a.pendingUrl||"about:blank"===a.url||"complete"!==a.status)}catch(t){throw await this.handleGlitch(`Failed to navigate to URL '${e}'.\n${t}`)}}async reload(){try{await this.goto(await this.url())}catch(e){throw await this.handleGlitch(`Failed to reload the page.\n${e}`)}}async url(){try{const{url:e}=await chrome.tabs.get(this.tabId);return e}catch(e){throw await this.handleGlitch(`Failed to get the URL of the page.\n${e}`)}}async close(){try{await chrome.windows.remove(this.windowId).catch((()=>{}))}catch(e){throw await this.handleGlitch(`Failed to close the page.\n${e}`)}}async zoom(e){try{e!==await chrome.tabs.getZoom(this.tabId)&&await chrome.tabs.setZoom(this.tabId,e)}catch(e){throw await this.handleGlitch(`Failed to zoom the page.\n${e}`)}}async bringToFront(){try{await chrome.windows.update(this.windowId,{focused:!0})}catch(e){throw await this.handleGlitch(`Failed to bring the page to the front.\n${e}`)}}async hideFromFront(){try{await chrome.windows.update(this.windowId,{focused:!1})}catch(e){throw await this.handleGlitch(`Failed to hide the page from the front.\n${e}`)}}async evaluate(){let e={};try{if("function"==typeof arguments[0]){const[t,a,n]=arguments;e={func:t,args:a,...n||{}}}else if(Array.isArray(arguments[0])){const[t,a,n]=arguments;e={files:t,args:a,...n||{}}}else e=arguments[0];const t=await chrome.scripting.executeScript({target:{tabId:this.tabId,...(0,s.chooseProperties)(e,["allFrames","frameIds","documentIds"])},world:"ISOLATED",...(0,s.chooseProperties)(e,["func","files","args","world"])});return t?.[0]?.result}catch(t){throw await this.handleGlitch(`Failed to evaluate ${e?.func?`function '${e.func?.name}' with arguments '${JSON.stringify(e.args||[])}'`:`file(s) '${JSON.stringify(e.files||[])}'`} '' on the page.\n${t}`)}}async waitFor(e,t,a={}){try{let n,i=a.tryLimit||this.configurations.tryLimit,o=a.delay||this.configurations.delay;for(;!(n=await e(...t))&&i;)i--,await(0,s.doDelay)(o);if(n)return n;throw new Error("Waiting timed out...")}catch(a){throw await this.handleGlitch(`Glitch while waiting for function '${e?.name}' with arguments '${JSON.stringify(t||[])}'.\n${a}`)}}async waitForNavigation(e={}){try{const t=await this.url();await this.waitFor((async e=>await this.url()!==e),[t],e)}catch(e){throw await this.handleGlitch(`Glitch while waiting for navigation.\n${e}`)}}async waitForSelector(e,t={},a=-1){try{await this.waitFor((async e=>this.evaluate(e)),[{func:(e,t)=>!!window.Self.getElementBySelectors(e,document,t),args:[e,a]}],t)}catch(t){throw await this.handleGlitch(`Glitch while waiting for the CSS Selectors '${e}'${-1===a?"":`[${a}]`}.\n${t}`)}}async waitForXPath(e,t={},a=-1){try{await this.waitFor((async e=>this.evaluate(e)),[{func:(e,t)=>!!window.Self.getElementByXPath(e,document,t),args:[e,a]}],t)}catch(t){throw await this.handleGlitch(`Glitch while waiting for the XPath '${e}'${-1===a?"":`[${a}]`}.\n${t}`)}}async waitForElement(e,t={},a=-1){if(await(h.default.isXPath(e)?this.waitForXPath:this.waitForSelector)(e,t,a).then((()=>!0)).catch((()=>!1)))return await this.getElement(e,a)}async waitForElementMiss(e,t={},a=-1){return await this.waitFor((async e=>this.evaluate(e)),[{func:h.default.isXPath(e)?(e,t)=>!window.Self.getElementByXPath(e,document,t):(e,t)=>!window.Self.getElementBySelectors(e,document,t),args:[e,a]}],t).then((()=>!0)).catch((()=>!1))}element(e,t=-1){const a=`${e}⟮${t}⟯`;return new l.default(this,a)}async getElement(e,t=-1,a){const n=`${a?`${a}→${e}`:e}⟮${t}⟯`,{tagName:i}=await this.evaluate({func:e=>{const t=window.Self.ElementActions.getElement(e);return t?{tagName:t.tagName}:{}},args:[n]});if(i)return new l.default(this,n,i)}async getElements(e,t){const a=await this.evaluate({func:(e,t)=>{const a=t?window.Self.ElementActions.getElement(t):document;if(a)return window.Self.getElements(e,a).map((({tagName:a},n)=>({tagName:a,elementPath:t?`${t}→${e}⟮${n}⟯`:`${e}⟮${n}⟯`})))},args:[e,t]});return a?.map((({tagName:e,elementPath:t})=>new l.default(this,t,e)))}async elementExists(e,t=-1){try{return await this.evaluate({func:(e,t)=>!!window.Self.getElement(e,document,t),args:[e,t]})}catch(a){throw await this.handleGlitch(`Glitch while checking if element with the CSS Selectors or XPath '${e}'${-1===t?"":`[${t}]`} exists.\n${a}`)}}async click(e,t=-1){try{if(!await this.evaluate({func:(e,t,a)=>window.Self.click(e,t,a),args:[e,t,this.configurations]}))throw new Error("No element(s) found for the given CSS Selectors or XPath.")}catch(a){throw await this.handleGlitch(`Failed to click on element with the CSS Selectors or XPath '${e}'${-1===t?"":`[${t}]`}.\n${a}`)}}execCopy(e){const t=document.createElement("textarea");t.innerHTML=e,document.body.appendChild(t),t.select(),document.execCommand("copy"),t.remove()}async execPasteTo(e,t=-1){try{if(!await this.evaluate({func:(e,t,a)=>window.Self.execPasteTo(e,t,a),args:[e,t,this.configurations]}))throw new Error("No element(s) found for the given CSS Selectors or XPath.")}catch(a){throw await this.handleGlitch(`Failed to paste to element with the CSS Selectors or XPath '${e}'${-1===t?"":`[${t}]`}.\n${a}`)}}async triggerEvent(e,t,a=-1){try{if(!await this.evaluate({func:(e,t,a,{scrollToElementBeforeAction:n,scrollIntoViewOptions:i})=>{const o=window.Self.getElement(e,document,a);return!!o&&(n&&o.scrollIntoView(i),window.Self.triggerEvent(o,t),!0)},args:[e,t,a,this.configurations]}))throw new Error("No element(s) found for the given CSS Selectors or XPath.")}catch(n){throw await this.handleGlitch(`Failed to trigger event '${t}' on element with the CSS Selectors or XPath '${e}'${-1===a?"":`[${a}]`}.\n${n}`)}}async input(e,t,a=-1){try{if(!await this.evaluate({func:(e,t,a,n)=>window.Self.input(e,t,a,n),args:[e,t,a,this.configurations]}))throw new Error("No element(s) found for the given CSS Selectors or XPath.")}catch(n){throw await this.handleGlitch(`Failed to input value '${t}' into element with the CSS Selectors or XPath '${e}'${-1===a?"":`[${a}]`}.\n${n}`)}}async uploadFiles(e,t,a){try{const n=a?"MAIN":"ISOLATED",i=await this.evaluate({world:n,func:e=>(window.transmittedFiles||(window.transmittedFiles=[]),window.transmittedFiles.push(e)-1),args:[t.map((({name:e},a)=>Object.assign({name:e},t[a].blob&&(t[a].blobUrl=URL.createObjectURL(t[a].blob))?{blobUrl:t[a].blobUrl}:{dataUrl:""})))]});for(let e=0;e<t.length;e++)if(t[e].dataUrl){let a=t[e].dataUrl.length,o=5242880,r=0;for(;r<a;)await this.evaluate({world:n,func:(e,t,a)=>{window.transmittedFiles[e][t].dataUrl+=a},args:[i,e,t[e].dataUrl.substr(r,o)]}),r+=o}await this.evaluate((async(e,t,a=-1,{scrollToElementBeforeAction:n,scrollIntoViewOptions:i})=>{const o=t?t.match(/^(\/|\.\/|\()/)?document.evaluate(t,document.documentElement,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue:document.querySelector(t):window.Self.elementCatcher.current?.elements[a];return!!o&&(n&&o.scrollIntoView(i),o.files=window.Self.filesToFileList(await Promise.all(window.transmittedFiles[e].map((async({blobUrl:e,dataUrl:t,name:a})=>e?window.Self.blobToFile(await window.Self.getBlob(e),a):window.Self.dataUrlToFile(t,a))))),window.Self.triggerEvent(o,"input"),window.Self.triggerEvent(o,"change"),delete window.transmittedFiles[e],0===window.transmittedFiles.filter(Boolean).length&&delete window.transmittedFiles,!0)}),[i,e,a,this.configurations],{world:n}),t.forEach((({blobUrl:e})=>URL.revokeObjectURL(e)))}catch(e){throw await this.handleGlitch(`Failed to upload files.\n${e}`)}}async screenshot({clip:e}){try{let t=await chrome.tabs.captureVisibleTab(this.windowId,{format:"png"});if(e){const{width:a,height:n,x:i,y:o}=e,r=await(0,s.cropImageOffscreen)(await(0,s.imageBitmapFromUrl)(t),a,n,i,o);t=await(0,s.blobToDataUrl)(await r.convertToBlob())}return t}catch(e){throw await this.handleGlitch(`Failed to take a screenshot.\n${e}`)}}elementCatcher={catch:async function(e){try{await this.evaluate({world:"MAIN",func:()=>window.Self?.exists()})||await this.evaluate({world:"MAIN",func:h.selfIntegration}),await this.evaluate({world:"MAIN",func:e=>window.Self.elementCatcher.catch(e),args:[e]})}catch(e){throw e}},terminate:async function(){try{await this.evaluate({world:"MAIN",func:()=>window.Self?.elementCatcher.terminate()})}catch(e){throw e}}};manualClick={enable:async function(){try{await this.evaluate((()=>window.Self.manualClick.enable()))}catch(e){throw e}},disable:async function(){try{await this.evaluate((()=>window.Self.manualClick.disable()))}catch(e){throw e}}}}},16:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.selfIntegration=void 0;const a=(e=!0)=>{const t={scrollToElementBeforeAction:!0,scrollIntoViewOptions:{behavior:"smooth",block:"center"}},a={tryLimit:30,delay:1e3,...t},n=async e=>new Promise((t=>setTimeout(t,e))),i=(e,t)=>{e.dispatchEvent(new Event(t,{bubbles:!0,cancelable:!0}))},o=(e,t)=>{e.tagName.match(/INPUT|TEXTAREA|SELECT/i)?e.value=t:e.innerHTML=t,i(e,"focus"),i(e,"keydown"),i(e,"keypress"),i(e,"keyup"),i(e,"input"),i(e,"change"),i(e,"blur")},r=e=>{e.focus(),"INPUT"!==e.tagName&&"TEXTAREA"!==e.tagName||e.select(),document.execCommand("paste")},l=e=>e.match(/^(\/|\.\/|\()/),s=(e,t=document,a=-1)=>-1===a?document.evaluate(e,t,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue:document.evaluate(e,t,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotItem(a),c=(e,t=document)=>{let a=[],n=document.evaluate(e,t,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);for(let e=0;e<n.snapshotLength;e++)a.push(n.snapshotItem(e));return a},h=(e,t=document,a=-1)=>-1===a?t.querySelector(e):t.querySelectorAll(e)[a],d=(e,t=document)=>Array.from(t.querySelectorAll(e)),u=(e,t=document,a=-1)=>l(e)?s(e,t,a):h(e,t,a),w={catch:e=>!w.current&&(w.current={originalFunc:document.createElement,elements:[],tagNames:e.map((e=>e.toUpperCase()))},document.createElement=function(){const e=w.current?.originalFunc.apply(this,arguments);return w.current?.tagNames.includes(e.tagName)&&w.current.elements.push(e),e},!0),terminate:()=>!!w.current&&(document.createElement=w.current.originalFunc,delete w.current,!0)},m={enable:()=>{m.current&&(m.current.element.remove(),delete m.current)},disable:()=>{m.current||(m.current={element:document.createElement("div")},m.current.element.style="width: 100%; height: 100%; position: fixed; top: 0; cursor: not-allowed; z-index: 12500; left: 0;",m.current.element.addEventListener("contextmenu",(e=>e.preventDefault())),document.body.appendChild(m.current.element))}},f=()=>location.href,g=async(e,t,i={})=>{let o,r=i.tryLimit||a.tryLimit,l=i.delay||a.delay;for(;!(o=await e(...t))&&r;)r--,await n(l);if(o)return o;throw new Error("Waiting timed out...")};class b{static elements=new Map;static getElement(e){let t=this.elements.get(e);if(t)return t;for(const a of e.split("→")){let[,e,n]=a.match(/(.+)⟮([0-9-]+)⟯$/);n=Number(n),t=u(e,t||document,n)}return t?(this.elements.size>50&&this.elements.delete(this.elements.keys().next().value),this.elements.set(e,t),t):void 0}static handleCall(e,t,a){const n=this.getElement(e);return a?n?.[t](...a):n?.[t]()}static handleGet(e,t){const a=this.getElement(e);return a?.[t]}static handleSet(e,t,a){this.getElement(e)[t]=a}}const y={exists:()=>!0,ElementActions:b,getElement:u,getElements:(e,t=document)=>l(e)?c(e,t):d(e,t),getElementBySelectors:h,getElementsBySelectors:d,getElementByXPath:s,getElementsByXPath:c,triggerEvent:i,triggerPaste:r,setValue:o,isXPath:l,filesToFileList:e=>{const t=new DataTransfer;for(const a of e)t.items.add(a);return t.files},getBlob:e=>new Promise((t=>{var a=new XMLHttpRequest;a.open("GET",e,!0),a.responseType="blob",a.onload=()=>t(a.response),a.send()})),dataUrlToFile:(e,t)=>{let[a,n]=e.split(",");a=a.match(/:(.*?);/)[1],n=atob(n);let i=n.length,o=new Uint8Array(i);for(;i--;)o[i]=n.charCodeAt(i);return new File([o],t,{type:a})},blobToFile:(e,t)=>new File([e],t,{type:e.type}),goto:e=>location.href=e,reload:()=>location.reload(),url:f,close:()=>globalThis.close(),zoom:e=>document.body.style.zoom=e,waitFor:g,waitForNavigation:async(e={})=>{const t=f();await g((async e=>f()!==e),[t],e)},waitForElement:async(e,t={},a=-1)=>{await g(l(e)?(e,t)=>!!s(e,document,t):(e,t)=>!!h(e,document,t),[e,a],t)},waitForElementMiss:async(e,t={},a=-1)=>{await g(l(e)?(e,t)=>!s(e,document,t):(e,t)=>!h(e,document,t),[e,a],t)},click:(e,a=-1,{scrollToElementBeforeAction:n,scrollIntoViewOptions:i}=t)=>{const o=u(e,document,a);return!!o&&(n&&o.scrollIntoView(i),o.click(),!0)},elementExists:(e,t=-1)=>!!u(e,document,t),execPasteTo:(e,a=-1,{scrollToElementBeforeAction:n,scrollIntoViewOptions:i}=t)=>{const o=u(e,document,a);return!!o&&(n&&o.scrollIntoView(i),r(o),!0)},input:(e,a,n=-1,{scrollToElementBeforeAction:i,scrollIntoViewOptions:r}=t)=>{const l=u(e,document,n);return!!l&&(i&&l.scrollIntoView(r),o(l,a),!0)},elementCatcher:w,manualClick:m};return e&&!window.Self?.exists?.()&&(window.Self=y),y};t.selfIntegration=a;const n=a(!1);t.default=n}},t={};return function a(n){var i=t[n];if(void 0!==i)return i.exports;var o=t[n]={exports:{}};return e[n].call(o.exports,o,o.exports,a),o.exports}(148)})())); |
@@ -1,1 +0,1 @@ | ||
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var a=t();for(var n in a)("object"==typeof exports?exports:e)[n]=a[n]}}(this,(()=>(()=>{"use strict";var e={148:function(e,t,a){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=n(a(869)),o=a(16),r=async e=>{await chrome.scripting.executeScript({target:{tabId:e},func:o.selfIntegration}).catch((()=>{}))};t.default=class{availablePages=[];constructor(){onbeforeunload=e=>(e.preventDefault(),this.close(),!1),this.syncListeners()}pages(){return this.availablePages}async close(){try{onbeforeunload=null,await Promise.all(this.availablePages.map((async e=>{const{tabId:t,originWindowId:a,activeInOrigin:n,onBeforeClose:i}=e;i&&i(),a?(a!==(await chrome.tabs.get(t)).windowId&&await chrome.tabs.move(t,{index:-1,windowId:a}),n&&await chrome.tabs.update(t,{active:!0})):await e.close()}))),this.availablePages=[],this.syncListeners()}catch(e){throw e}}async newPage({tabId:e,windowId:t,originWindowId:a,activeInOrigin:n,windowOptions:o,tabOptions:l}={}){try{t?e?l&&await chrome.tabs.update(e,l):await chrome.tabs.create({url:"about:blank",...l}).then((t=>{e=t.id})):(await chrome.windows.create({type:"popup",focused:!0,width:1e3,left:Math.round(.5*(screen.availWidth-1e3)),height:650,top:Math.round(.5*(screen.availHeight-650)),...e?{tabId:e}:{url:"about:blank"},...o||{}}).then((a=>{e=a.tabs[0].id,t=a.id})),l&&await chrome.tabs.update(e,l));const s=new i.default({browser:this,tabId:e,windowId:t,...a?{originWindowId:a,activeInOrigin:n||!1}:{}});return this.availablePages.push(s),this?.onPageAdded?.(s),this.syncListeners(),r(e),s}catch(e){throw e}}onPageAdded;onPageClose;onPageUpdate;handleTabRemove=(e,t)=>{const a=this.availablePages.findIndex((({tabId:t})=>t===e));-1!==a&&(this?.onPageClose?.(e,t),this.availablePages.splice(a,1))};handleTabUpdate=(e,t,a)=>{const n=this.availablePages.findIndex((({tabId:t})=>t===e));-1!==n&&(this?.onPageUpdate?.(this.availablePages[n]),"complete"===t.status&&a.url?.match(/^HTTP/i)&&r(e))};syncListeners(){this.availablePages.length?(chrome.tabs.onUpdated.hasListener(this.handleTabUpdate)||chrome.tabs.onUpdated.addListener(this.handleTabUpdate),chrome.tabs.onRemoved.hasListener(this.handleTabRemove)||chrome.tabs.onRemoved.addListener(this.handleTabRemove)):(chrome.tabs.onUpdated.hasListener(this.handleTabUpdate)&&chrome.tabs.onUpdated.removeListener(this.handleTabUpdate),chrome.tabs.onRemoved.hasListener(this.handleTabRemove)&&chrome.tabs.onRemoved.removeListener(this.handleTabRemove))}}},792:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=class{page;elementPath;tagName;async handleCall(e,t){return await this.page.evaluate({func:(e,t,a)=>a?window.Self.ElementActions.handleCall(e,t,a):window.Self.ElementActions.handleCall(e,t),args:t?[this.elementPath,e,t]:[this.elementPath,e]})}async handleGet(e){return await this.page.evaluate({func:(e,t)=>window.Self.ElementActions.handleGet(e,t),args:[this.elementPath,e]})}async handleSet(e,t){return await this.page.evaluate({func:(e,t,a)=>window.Self.ElementActions.handleSet(e,t,a),args:[this.elementPath,e,t]})}async getTagName(){return this.tagName||(this.tagName=await this.handleGet("tagName")),this.tagName}async getInnerText(){return await this.handleGet("innerText")}async getInnerHTML(){return await this.handleGet("innerHTML")}async setInnerHTML(e){return await this.handleSet("innerHTML",e)}async click(){return await this.handleCall("click")}async focus(){return await this.handleCall("focus")}async scrollIntoView(e){return await this.handleCall("scrollIntoView",[e])}async getAttribute(e){return await this.handleCall("getAttribute",[e])}async setAttribute(e,t){return await this.handleCall("setAttribute",[e,t])}async getElement(e,t=-1){return await this.page.getElement(e,t,this.elementPath)}async getElements(e){return await this.page.getElements(e,this.elementPath)}async input(e){return await this.page.evaluate({func:(e,t)=>{const a=window.Self.ElementActions.getElement(t);return!!a&&(window.Self.setValue(a,e),!0)},args:[e,this.elementPath]})}async execPaste(){return await this.page.evaluate({func:e=>{const t=window.Self.ElementActions.getElement(e);return!!t&&(window.Self.triggerPaste(t),!0)},args:[this.elementPath]})}async triggerEvent(e){return await this.page.evaluate({func:(e,t)=>{const a=window.Self.ElementActions.getElement(t);return!!a&&(window.Self.triggerEvent(a,e),!0)},args:[e,this.elementPath]})}constructor(e,t,a){this.page=e,this.elementPath=t,a&&(this.tagName=a)}}},156:function(e,t,a){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.Self=t.delay=t.Page=t.Browser=void 0;const i=n(a(148));t.Browser=i.default;const o=a(419);Object.defineProperty(t,"delay",{enumerable:!0,get:function(){return o.doDelay}});const r=n(a(869));t.Page=r.default;const l=n(a(16));t.Self=l.default;const s={launch:function(){return new i.default}};t.default=s},419:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.chooseProperties=t.omitProperties=t.setValue=t.triggerEvent=t.getRandomFromArray=t.blobToDataUrl=t.imageBitmapFromUrl=t.cropImageOffscreen=t.doDelay=void 0,t.doDelay=async e=>new Promise((t=>setTimeout(t,e))),t.cropImageOffscreen=(e,t,a,n,i)=>{var o=new OffscreenCanvas(t,a);return o.getContext("2d").drawImage(e,n,i,t,a,0,0,t,a),o},t.imageBitmapFromUrl=async e=>await fetch(e).then((e=>e.blob())).then((async e=>createImageBitmap(e))),t.blobToDataUrl=async e=>new Promise((t=>{let a=new FileReader;a.onload=function(){t(this.result)},a.readAsDataURL(e)})),t.getRandomFromArray=e=>e[Math.floor(Math.random()*e.length)];const a=(e,t)=>{e.dispatchEvent(new Event(t,{bubbles:!0,cancelable:!0}))};t.triggerEvent=a,t.setValue=(e,t)=>{e.tagName.match(/INPUT|TEXTAREA|SELECT/i)?e.value=t:e.innerHTML=t,a(e,"focus"),a(e,"keydown"),a(e,"keypress"),a(e,"keyup"),a(e,"input"),a(e,"change"),a(e,"blur")},t.omitProperties=(e,t)=>Object.fromEntries(Object.entries(e).filter((([e])=>!t.includes(e)))),t.chooseProperties=(e,t)=>Object.fromEntries(Object.entries(e).filter((([e])=>t.includes(e))))},633:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.defaultPageConfigurations=t.defaultActionOptions=void 0,t.defaultActionOptions={scrollToElementBeforeAction:!0,scrollIntoViewOptions:{behavior:"smooth",block:"center"}},t.defaultPageConfigurations={tryLimit:30,delay:1e3,...t.defaultActionOptions}},869:function(e,t,a){var n=this&&this.__createBinding||(Object.create?function(e,t,a,n){void 0===n&&(n=a);var i=Object.getOwnPropertyDescriptor(t,a);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[a]}}),Object.defineProperty(e,n,i)}:function(e,t,a,n){void 0===n&&(n=a),e[n]=t[a]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var a in e)"default"!==a&&Object.prototype.hasOwnProperty.call(e,a)&&n(t,e,a);return i(t,e),t},r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const l=r(a(792)),s=a(419),c=a(633),h=o(a(16));t.default=class{browser;tabId;windowId;originWindowId;activeInOrigin;onBeforeClose;configurations=c.defaultPageConfigurations;async handleGlitch(e){return`${e}\nPage URL: '${await chrome.tabs.get(this.tabId).then((({url:e})=>e)).catch((()=>"N/A"))}'`}configure(e){this.configurations={...this.configurations,...e}}constructor({tabId:e,windowId:t,originWindowId:a,activeInOrigin:n,browser:i}){this.tabId=e,this.windowId=t,this.browser=i,a&&(this.originWindowId=a),n&&(this.activeInOrigin=n),this.elementCatcher.catch=this.elementCatcher.catch.bind(this),this.elementCatcher.terminate=this.elementCatcher.terminate.bind(this),this.manualClick.enable=this.manualClick.enable.bind(this),this.manualClick.disable=this.manualClick.disable.bind(this)}async goto(e,{waitUntil:t}={waitUntil:"domcontentloaded"}){try{let a;if(await chrome.tabs.update(this.tabId,{url:"about:blank"}),await chrome.tabs.update(this.tabId,{url:e}),"load"===t)do{await(0,s.doDelay)(this.configurations.delay),a=await chrome.tabs.get(this.tabId)}while("about:blank"===a.pendingUrl||"about:blank"===a.url);else if(t="domcontentloaded")do{await(0,s.doDelay)(this.configurations.delay),a=await chrome.tabs.get(this.tabId)}while("about:blank"===a.pendingUrl||"about:blank"===a.url||"complete"!==a.status)}catch(t){throw await this.handleGlitch(`Failed to navigate to URL '${e}'.\n${t}`)}}async reload(){try{await this.goto(await this.url())}catch(e){throw await this.handleGlitch(`Failed to reload the page.\n${e}`)}}async url(){try{const{url:e}=await chrome.tabs.get(this.tabId);return e}catch(e){throw await this.handleGlitch(`Failed to get the URL of the page.\n${e}`)}}async close(){try{await chrome.windows.remove(this.windowId).catch((()=>{}))}catch(e){throw await this.handleGlitch(`Failed to close the page.\n${e}`)}}async zoom(e){try{e!==await chrome.tabs.getZoom(this.tabId)&&await chrome.tabs.setZoom(this.tabId,e)}catch(e){throw await this.handleGlitch(`Failed to zoom the page.\n${e}`)}}async bringToFront(){try{await chrome.windows.update(this.windowId,{focused:!0})}catch(e){throw await this.handleGlitch(`Failed to bring the page to the front.\n${e}`)}}async hideFromFront(){try{await chrome.windows.update(this.windowId,{focused:!1})}catch(e){throw await this.handleGlitch(`Failed to hide the page from the front.\n${e}`)}}async evaluate(){let e={};try{if("function"==typeof arguments[0]){const[t,a,n]=arguments;e={func:t,args:a,...n||{}}}else if(Array.isArray(arguments[0])){const[t,a,n]=arguments;e={files:t,args:a,...n||{}}}else e=arguments[0];const t=await chrome.scripting.executeScript({target:{tabId:this.tabId,...(0,s.chooseProperties)(e,["allFrames","frameIds","documentIds"])},world:"ISOLATED",...(0,s.chooseProperties)(e,["func","files","args","world"])});return t?.[0]?.result}catch(t){throw await this.handleGlitch(`Failed to evaluate ${e?.func?`function '${e.func?.name}' with arguments '${JSON.stringify(e.args||[])}'`:`file(s) '${JSON.stringify(e.files||[])}'`} '' on the page.\n${t}`)}}async waitFor(e,t,a={}){try{let n,i=a.tryLimit||this.configurations.tryLimit,o=a.delay||this.configurations.delay;for(;!(n=await e(...t))&&i;)i--,await(0,s.doDelay)(o);if(n)return n;throw new Error("Waiting timed out...")}catch(a){throw await this.handleGlitch(`Glitch while waiting for function '${e?.name}' with arguments '${JSON.stringify(t||[])}'.\n${a}`)}}async waitForNavigation(e={}){try{const t=await this.url();await this.waitFor((async e=>await this.url()!==e),[t],e)}catch(e){throw await this.handleGlitch(`Glitch while waiting for navigation.\n${e}`)}}async waitForSelector(e,t={},a=-1){try{await this.waitFor((async e=>this.evaluate(e)),[{func:(e,t)=>!!window.Self.getElementBySelectors(e,document,t),args:[e,a]}],t)}catch(t){throw await this.handleGlitch(`Glitch while waiting for the CSS Selectors '${e}'${-1===a?"":`[${a}]`}.\n${t}`)}}async waitForXPath(e,t={},a=-1){try{await this.waitFor((async e=>this.evaluate(e)),[{func:(e,t)=>!!window.Self.getElementByXPath(e,document,t),args:[e,a]}],t)}catch(t){throw await this.handleGlitch(`Glitch while waiting for the XPath '${e}'${-1===a?"":`[${a}]`}.\n${t}`)}}async waitForElement(e,t={},a=-1){if(await(h.default.isXPath(e)?this.waitForXPath:this.waitForSelector)(e,t,a).then((()=>!0)).catch((()=>!1)))return await this.getElement(e,a)}async waitForElementMiss(e,t={},a=-1){return await this.waitFor((async e=>this.evaluate(e)),[{func:h.default.isXPath(e)?(e,t)=>!window.Self.getElementByXPath(e,document,t):(e,t)=>!window.Self.getElementBySelectors(e,document,t),args:[e,a]}],t).then((()=>!0)).catch((()=>!1))}element(e,t=-1){const a=`${e}⟮${t}⟯`;return new l.default(this,a)}async getElement(e,t=-1,a){const n=`${a?`${a}→${e}`:e}⟮${t}⟯`,{tagName:i}=await this.evaluate({func:e=>{const t=window.Self.ElementActions.getElement(e);return t?{tagName:t.tagName}:{}},args:[n]});if(i)return new l.default(this,n,i)}async getElements(e,t){const a=await this.evaluate({func:(e,t)=>{const a=t?window.Self.ElementActions.getElement(t):document;if(a)return window.Self.getElements(e,a).map((({tagName:a},n)=>({tagName:a,elementPath:t?`${t}→${e}⟮${n}⟯`:`${e}⟮${n}⟯`})))},args:[e,t]});return a?.map((({tagName:e,elementPath:t})=>new l.default(this,t,e)))}async elementExists(e,t=-1){try{return await this.evaluate({func:(e,t)=>!!window.Self.getElement(e,document,t),args:[e,t]})}catch(a){throw await this.handleGlitch(`Glitch while checking if element with the CSS Selectors or XPath '${e}'${-1===t?"":`[${t}]`} exists.\n${a}`)}}async click(e,t=-1){try{if(!await this.evaluate({func:(e,t,a)=>window.Self.click(e,t,a),args:[e,t,this.configurations]}))throw new Error("No element(s) found for the given CSS Selectors or XPath.")}catch(a){throw await this.handleGlitch(`Failed to click on element with the CSS Selectors or XPath '${e}'${-1===t?"":`[${t}]`}.\n${a}`)}}execCopy(e){const t=document.createElement("textarea");t.innerHTML=e,document.body.appendChild(t),t.select(),document.execCommand("copy"),t.remove()}async execPasteTo(e,t=-1){try{if(!await this.evaluate({func:(e,t,a)=>window.Self.execPasteTo(e,t,a),args:[e,t,this.configurations]}))throw new Error("No element(s) found for the given CSS Selectors or XPath.")}catch(a){throw await this.handleGlitch(`Failed to paste to element with the CSS Selectors or XPath '${e}'${-1===t?"":`[${t}]`}.\n${a}`)}}async triggerEvent(e,t,a=-1){try{if(!await this.evaluate({func:(e,t,a,{scrollToElementBeforeAction:n,scrollIntoViewOptions:i})=>{const o=window.Self.getElement(e,document,a);return!!o&&(n&&o.scrollIntoView(i),window.Self.triggerEvent(o,t),!0)},args:[e,t,a,this.configurations]}))throw new Error("No element(s) found for the given CSS Selectors or XPath.")}catch(n){throw await this.handleGlitch(`Failed to trigger event '${t}' on element with the CSS Selectors or XPath '${e}'${-1===a?"":`[${a}]`}.\n${n}`)}}async input(e,t,a=-1){try{if(!await this.evaluate({func:(e,t,a,n)=>window.Self.input(e,t,a,n),args:[e,t,a,this.configurations]}))throw new Error("No element(s) found for the given CSS Selectors or XPath.")}catch(n){throw await this.handleGlitch(`Failed to input value '${t}' into element with the CSS Selectors or XPath '${e}'${-1===a?"":`[${a}]`}.\n${n}`)}}async uploadFiles(e,t,a){try{const n=a?"MAIN":"ISOLATED",i=await this.evaluate({world:n,func:e=>(window.transmittedFiles||(window.transmittedFiles=[]),window.transmittedFiles.push(e)-1),args:[t.map((({name:e},a)=>Object.assign({name:e},t[a].blob&&(t[a].blobUrl=URL.createObjectURL(t[a].blob))?{blobUrl:t[a].blobUrl}:{dataUrl:""})))]});for(let e=0;e<t.length;e++)if(t[e].dataUrl){let a=t[e].dataUrl.length,o=5242880,r=0;for(;r<a;)await this.evaluate({world:n,func:(e,t,a)=>{window.transmittedFiles[e][t].dataUrl+=a},args:[i,e,t[e].dataUrl.substr(r,o)]}),r+=o}await this.evaluate((async(e,t,a=-1,{scrollToElementBeforeAction:n,scrollIntoViewOptions:i})=>{const o=t?t.match(/^(\/|\.\/|\()/)?document.evaluate(t,document.documentElement,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue:document.querySelector(t):window.Self.elementCatcher.current?.elements[a];return!!o&&(n&&o.scrollIntoView(i),o.files=window.Self.filesToFileList(await Promise.all(window.transmittedFiles[e].map((async({blobUrl:e,dataUrl:t,name:a})=>e?window.Self.blobToFile(await window.Self.getBlob(e),a):window.Self.dataUrlToFile(t,a))))),window.Self.triggerEvent(o,"input"),window.Self.triggerEvent(o,"change"),delete window.transmittedFiles[e],0===window.transmittedFiles.filter(Boolean).length&&delete window.transmittedFiles,!0)}),[i,e,a,this.configurations],{world:n}),t.forEach((({blobUrl:e})=>URL.revokeObjectURL(e)))}catch(e){throw await this.handleGlitch(`Failed to upload files.\n${e}`)}}async screenshot({clip:e}){try{let t=await chrome.tabs.captureVisibleTab(this.windowId,{format:"png"});if(e){const{width:a,height:n,x:i,y:o}=e,r=await(0,s.cropImageOffscreen)(await(0,s.imageBitmapFromUrl)(t),a,n,i,o);t=await(0,s.blobToDataUrl)(await r.convertToBlob())}return t}catch(e){throw await this.handleGlitch(`Failed to take a screenshot.\n${e}`)}}elementCatcher={catch:async function(e){try{await this.evaluate({world:"MAIN",func:()=>window.Self?.exists()})||await this.evaluate({world:"MAIN",func:h.selfIntegration}),await this.evaluate({world:"MAIN",func:e=>window.Self.elementCatcher.catch(e),args:[e]})}catch(e){throw e}},terminate:async function(){try{await this.evaluate({world:"MAIN",func:()=>window.Self?.elementCatcher.terminate()})}catch(e){throw e}}};manualClick={enable:async function(){try{await this.evaluate((()=>window.Self.manualClick.enable()))}catch(e){throw e}},disable:async function(){try{await this.evaluate((()=>window.Self.manualClick.disable()))}catch(e){throw e}}}}},16:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.selfIntegration=void 0;const a=(e=!0)=>{const t={scrollToElementBeforeAction:!0,scrollIntoViewOptions:{behavior:"smooth",block:"center"}},a={tryLimit:30,delay:1e3,...t},n=async e=>new Promise((t=>setTimeout(t,e))),i=(e,t)=>{e.dispatchEvent(new Event(t,{bubbles:!0,cancelable:!0}))},o=(e,t)=>{e.tagName.match(/INPUT|TEXTAREA|SELECT/i)?e.value=t:e.innerHTML=t,i(e,"focus"),i(e,"keydown"),i(e,"keypress"),i(e,"keyup"),i(e,"input"),i(e,"change"),i(e,"blur")},r=e=>{e.focus(),"INPUT"!==e.tagName&&"TEXTAREA"!==e.tagName||e.select(),document.execCommand("paste")},l=e=>e.match(/^(\/|\.\/|\()/),s=(e,t=document,a=-1)=>-1===a?document.evaluate(e,t,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue:document.evaluate(e,t,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotItem(a),c=(e,t=document)=>{let a=[],n=document.evaluate(e,t,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);for(let e=0;e<n.snapshotLength;e++)a.push(n.snapshotItem(e));return a},h=(e,t=document,a=-1)=>-1===a?t.querySelector(e):t.querySelectorAll(e)[a],d=(e,t=document)=>Array.from(t.querySelectorAll(e)),u=(e,t=document,a=-1)=>l(e)?s(e,t,a):h(e,t,a),w={catch:e=>!w.current&&(w.current={originalFunc:document.createElement,elements:[],tagNames:e.map((e=>e.toUpperCase()))},document.createElement=function(){const e=w.current?.originalFunc.apply(this,arguments);return w.current?.tagNames.includes(e.tagName)&&w.current.elements.push(e),e},!0),terminate:()=>!!w.current&&(document.createElement=w.current.originalFunc,delete w.current,!0)},m={enable:()=>{m.current&&(m.current.element.remove(),delete m.current)},disable:()=>{m.current||(m.current={element:document.createElement("div")},m.current.element.style="width: 100%; height: 100%; position: fixed; top: 0; cursor: not-allowed; z-index: 12500; left: 0;",m.current.element.addEventListener("contextmenu",(e=>e.preventDefault())),document.body.appendChild(m.current.element))}},f=()=>location.href,g=async(e,t,i={})=>{let o,r=i.tryLimit||a.tryLimit,l=i.delay||a.delay;for(;!(o=await e(...t))&&r;)r--,await n(l);if(o)return o;throw new Error("Waiting timed out...")};class b{static elements=new Map;static getElement(e){let t=this.elements.get(e);if(t)return t;for(const a of e.split("→")){let[,e,n]=a.match(/(.+)⟮([0-9-]+)⟯$/);n=Number(n),t=u(e,t||document,n)}return t?(this.elements.size>50&&this.elements.delete(this.elements.keys().next().value),this.elements.set(e,t),t):void 0}static handleCall(e,t,a){const n=this.getElement(e);return a?n?.[t](...a):n?.[t]()}static handleGet(e,t){const a=this.getElement(e);return a?.[t]}static handleSet(e,t,a){this.getElement(e)[t]=a}}const y={exists:()=>!0,ElementActions:b,getElement:u,getElements:(e,t=document)=>l(e)?c(e,t):d(e,t),getElementBySelectors:h,getElementsBySelectors:d,getElementByXPath:s,getElementsByXPath:c,triggerEvent:i,triggerPaste:r,setValue:o,isXPath:l,filesToFileList:e=>{const t=new DataTransfer;for(const a of e)t.items.add(a);return t.files},getBlob:e=>new Promise((t=>{var a=new XMLHttpRequest;a.open("GET",e,!0),a.responseType="blob",a.onload=()=>t(a.response),a.send()})),dataUrlToFile:(e,t)=>{let[a,n]=e.split(",");a=a.match(/:(.*?);/)[1],n=atob(n);let i=n.length,o=new Uint8Array(i);for(;i--;)o[i]=n.charCodeAt(i);return new File([o],t,{type:a})},blobToFile:(e,t)=>new File([e],t,{type:e.type}),goto:e=>location.href=e,reload:()=>location.reload(),url:f,close:()=>globalThis.close(),zoom:e=>document.body.style.zoom=e,waitFor:g,waitForNavigation:async(e={})=>{const t=f();await g((async e=>f()!==e),[t],e)},waitForElement:async(e,t={},a=-1)=>{await g(l(e)?(e,t)=>!!s(e,document,t):(e,t)=>!!h(e,document,t),[e,a],t)},waitForElementMiss:async(e,t={},a=-1)=>{await g(l(e)?(e,t)=>!s(e,document,t):(e,t)=>!h(e,document,t),[e,a],t)},click:(e,a=-1,{scrollToElementBeforeAction:n,scrollIntoViewOptions:i}=t)=>{const o=u(e,document,a);return!!o&&(n&&o.scrollIntoView(i),o.click(),!0)},elementExists:(e,t=-1)=>!!u(e,document,t),execPasteTo:(e,a=-1,{scrollToElementBeforeAction:n,scrollIntoViewOptions:i}=t)=>{const o=u(e,document,a);return!!o&&(n&&o.scrollIntoView(i),r(o),!0)},input:(e,a,n=-1,{scrollToElementBeforeAction:i,scrollIntoViewOptions:r}=t)=>{const l=u(e,document,n);return!!l&&(i&&l.scrollIntoView(r),o(l,a),!0)},elementCatcher:w,manualClick:m};return e&&!window.Self?.exists?.()&&(window.Self=y),y};t.selfIntegration=a;const n=a(!1);t.default=n}},t={};return function a(n){var i=t[n];if(void 0!==i)return i.exports;var o=t[n]={exports:{}};return e[n].call(o.exports,o,o.exports,a),o.exports}(156)})())); | ||
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var a=t();for(var n in a)("object"==typeof exports?exports:e)[n]=a[n]}}(this,(()=>(()=>{"use strict";var e={148:function(e,t,a){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=n(a(869)),o=a(16),r=async e=>{await chrome.scripting.executeScript({target:{tabId:e},func:o.selfIntegration}).catch((()=>{}))};t.default=class{availablePages=[];constructor(){onbeforeunload=e=>(e.preventDefault(),this.close(),!1),this.syncListeners()}pages(){return this.availablePages}async close(){try{onbeforeunload=null,await Promise.all(this.availablePages.map((async e=>{const{tabId:t,originWindowId:a,activeInOrigin:n,onBeforeClose:i}=e;i&&i(),a?(a!==(await chrome.tabs.get(t)).windowId&&await chrome.tabs.move(t,{index:-1,windowId:a}),n&&await chrome.tabs.update(t,{active:!0})):await e.close()}))),this.availablePages=[],this.syncListeners()}catch(e){throw e}}async newPage({tabId:e,windowId:t,originWindowId:a,activeInOrigin:n,windowOptions:o,tabOptions:l}={}){try{t?e?l&&await chrome.tabs.update(e,l):await chrome.tabs.create({url:"about:blank",...l}).then((t=>{e=t.id})):(await chrome.windows.create({type:"popup",focused:!0,width:1e3,left:Math.round(.5*(screen.availWidth-1e3)),height:650,top:Math.round(.5*(screen.availHeight-650)),...e?{tabId:e}:{url:"about:blank"},...o||{}}).then((a=>{e=a.tabs[0].id,t=a.id})),l&&await chrome.tabs.update(e,l));const s=new i.default({browser:this,tabId:e,windowId:t,...a?{originWindowId:a,activeInOrigin:n||!1}:{}});return this.availablePages.push(s),this?.onPageAdded?.(s),this.syncListeners(),r(e),s}catch(e){throw e}}onPageAdded;onPageClose;onPageUpdate;handleTabRemove=(e,t)=>{const a=this.availablePages.findIndex((({tabId:t})=>t===e));-1!==a&&(this?.onPageClose?.(e,t),this.availablePages.splice(a,1))};handleTabUpdate=(e,t,a)=>{const n=this.availablePages.findIndex((({tabId:t})=>t===e));-1!==n&&(this?.onPageUpdate?.(this.availablePages[n]),"complete"===t.status&&a.url?.match(/^HTTP/i)&&r(e))};syncListeners(){this.availablePages.length?(chrome.tabs.onUpdated.hasListener(this.handleTabUpdate)||chrome.tabs.onUpdated.addListener(this.handleTabUpdate),chrome.tabs.onRemoved.hasListener(this.handleTabRemove)||chrome.tabs.onRemoved.addListener(this.handleTabRemove)):(chrome.tabs.onUpdated.hasListener(this.handleTabUpdate)&&chrome.tabs.onUpdated.removeListener(this.handleTabUpdate),chrome.tabs.onRemoved.hasListener(this.handleTabRemove)&&chrome.tabs.onRemoved.removeListener(this.handleTabRemove))}}},792:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=class{page;elementPath;tagName;async handleCall(e,t){return await this.page.evaluate({func:(e,t,a)=>a?window.Self.ElementActions.handleCall(e,t,a):window.Self.ElementActions.handleCall(e,t),args:t?[this.elementPath,e,t]:[this.elementPath,e]})}async handleGet(e){return await this.page.evaluate({func:(e,t)=>window.Self.ElementActions.handleGet(e,t),args:[this.elementPath,e]})}async handleSet(e,t){return await this.page.evaluate({func:(e,t,a)=>window.Self.ElementActions.handleSet(e,t,a),args:[this.elementPath,e,t]})}async getTagName(){return this.tagName||(this.tagName=await this.handleGet("tagName")),this.tagName}async getInnerText(){return await this.handleGet("innerText")}async getInnerHTML(){return await this.handleGet("innerHTML")}async setInnerHTML(e){return await this.handleSet("innerHTML",e)}async click(){return await this.handleCall("click")}async focus(){return await this.handleCall("focus")}async scrollIntoView(e){return await this.handleCall("scrollIntoView",[e])}async getAttribute(e){return await this.handleCall("getAttribute",[e])}async setAttribute(e,t){return await this.handleCall("setAttribute",[e,t])}async getElement(e,t=-1){return await this.page.getElement(e,t,this.elementPath)}async getElements(e){return await this.page.getElements(e,this.elementPath)}async input(e){return await this.page.evaluate({func:(e,t)=>{const a=window.Self.ElementActions.getElement(t);return!!a&&(window.Self.setValue(a,e),!0)},args:[e,this.elementPath]})}async execPaste(){return await this.page.evaluate({func:e=>{const t=window.Self.ElementActions.getElement(e);return!!t&&(window.Self.triggerPaste(t),!0)},args:[this.elementPath]})}async triggerEvent(e){return await this.page.evaluate({func:(e,t)=>{const a=window.Self.ElementActions.getElement(t);return!!a&&(window.Self.triggerEvent(a,e),!0)},args:[e,this.elementPath]})}constructor(e,t,a){this.page=e,this.elementPath=t,a&&(this.tagName=a)}}},156:function(e,t,a){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.Self=t.delay=t.Page=t.Browser=void 0;const i=n(a(148));t.Browser=i.default;const o=a(419);Object.defineProperty(t,"delay",{enumerable:!0,get:function(){return o.doDelay}});const r=n(a(869));t.Page=r.default;const l=n(a(16));t.Self=l.default;const s={launch:function(){return new i.default}};t.default=s},419:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.chooseProperties=t.omitProperties=t.setValue=t.triggerEvent=t.getRandomFromArray=t.blobToDataUrl=t.imageBitmapFromUrl=t.cropImageOffscreen=t.doDelay=void 0,t.doDelay=async e=>new Promise((t=>setTimeout(t,e))),t.cropImageOffscreen=(e,t,a,n,i)=>{var o=new OffscreenCanvas(t,a);return o.getContext("2d").drawImage(e,n,i,t,a,0,0,t,a),o},t.imageBitmapFromUrl=async e=>await fetch(e).then((e=>e.blob())).then((async e=>createImageBitmap(e))),t.blobToDataUrl=async e=>new Promise((t=>{let a=new FileReader;a.onload=function(){t(this.result)},a.readAsDataURL(e)})),t.getRandomFromArray=e=>e[Math.floor(Math.random()*e.length)];const a=(e,t)=>{e.dispatchEvent(new Event(t,{bubbles:!0,cancelable:!0}))};t.triggerEvent=a,t.setValue=(e,t)=>{e.tagName.match(/INPUT|TEXTAREA|SELECT/i)?e.value=t:e.innerHTML=t,a(e,"focus"),a(e,"keydown"),a(e,"keypress"),a(e,"keyup"),a(e,"input"),a(e,"change"),a(e,"blur")},t.omitProperties=(e,t)=>Object.fromEntries(Object.entries(e).filter((([e])=>!t.includes(e)))),t.chooseProperties=(e,t)=>Object.fromEntries(Object.entries(e).filter((([e])=>t.includes(e))))},633:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.defaultPageConfigurations=t.defaultActionOptions=void 0,t.defaultActionOptions={scrollToElementBeforeAction:!0,scrollIntoViewOptions:{behavior:"smooth",block:"center"}},t.defaultPageConfigurations={tryLimit:30,delay:1e3,...t.defaultActionOptions}},869:function(e,t,a){var n=this&&this.__createBinding||(Object.create?function(e,t,a,n){void 0===n&&(n=a);var i=Object.getOwnPropertyDescriptor(t,a);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[a]}}),Object.defineProperty(e,n,i)}:function(e,t,a,n){void 0===n&&(n=a),e[n]=t[a]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var a in e)"default"!==a&&Object.prototype.hasOwnProperty.call(e,a)&&n(t,e,a);return i(t,e),t},r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const l=r(a(792)),s=a(419),c=a(633),h=o(a(16));t.default=class{browser;tabId;windowId;originWindowId;activeInOrigin;onBeforeClose;configurations=c.defaultPageConfigurations;async handleGlitch(e){return`${e}\nPage URL: '${await chrome.tabs.get(this.tabId).then((({url:e})=>e)).catch((()=>"N/A"))}'`}configure(e){this.configurations={...this.configurations,...e}}constructor({tabId:e,windowId:t,originWindowId:a,activeInOrigin:n,browser:i}){this.tabId=e,this.windowId=t,this.browser=i,a&&(this.originWindowId=a),n&&(this.activeInOrigin=n),this.elementCatcher.catch=this.elementCatcher.catch.bind(this),this.elementCatcher.terminate=this.elementCatcher.terminate.bind(this),this.manualClick.enable=this.manualClick.enable.bind(this),this.manualClick.disable=this.manualClick.disable.bind(this)}async goto(e,{waitUntil:t}={waitUntil:"domcontentloaded"}){try{if(await chrome.tabs.update(this.tabId,{url:"about:blank"}),"about:blank"===e)return;let a;if(await chrome.tabs.update(this.tabId,{url:e}),"load"===t)do{await(0,s.doDelay)(this.configurations.delay),a=await chrome.tabs.get(this.tabId)}while("about:blank"===a.pendingUrl||"about:blank"===a.url);else if(t="domcontentloaded")do{await(0,s.doDelay)(this.configurations.delay),a=await chrome.tabs.get(this.tabId)}while("about:blank"===a.pendingUrl||"about:blank"===a.url||"complete"!==a.status)}catch(t){throw await this.handleGlitch(`Failed to navigate to URL '${e}'.\n${t}`)}}async reload(){try{await this.goto(await this.url())}catch(e){throw await this.handleGlitch(`Failed to reload the page.\n${e}`)}}async url(){try{const{url:e}=await chrome.tabs.get(this.tabId);return e}catch(e){throw await this.handleGlitch(`Failed to get the URL of the page.\n${e}`)}}async close(){try{await chrome.windows.remove(this.windowId).catch((()=>{}))}catch(e){throw await this.handleGlitch(`Failed to close the page.\n${e}`)}}async zoom(e){try{e!==await chrome.tabs.getZoom(this.tabId)&&await chrome.tabs.setZoom(this.tabId,e)}catch(e){throw await this.handleGlitch(`Failed to zoom the page.\n${e}`)}}async bringToFront(){try{await chrome.windows.update(this.windowId,{focused:!0})}catch(e){throw await this.handleGlitch(`Failed to bring the page to the front.\n${e}`)}}async hideFromFront(){try{await chrome.windows.update(this.windowId,{focused:!1})}catch(e){throw await this.handleGlitch(`Failed to hide the page from the front.\n${e}`)}}async evaluate(){let e={};try{if("function"==typeof arguments[0]){const[t,a,n]=arguments;e={func:t,args:a,...n||{}}}else if(Array.isArray(arguments[0])){const[t,a,n]=arguments;e={files:t,args:a,...n||{}}}else e=arguments[0];const t=await chrome.scripting.executeScript({target:{tabId:this.tabId,...(0,s.chooseProperties)(e,["allFrames","frameIds","documentIds"])},world:"ISOLATED",...(0,s.chooseProperties)(e,["func","files","args","world"])});return t?.[0]?.result}catch(t){throw await this.handleGlitch(`Failed to evaluate ${e?.func?`function '${e.func?.name}' with arguments '${JSON.stringify(e.args||[])}'`:`file(s) '${JSON.stringify(e.files||[])}'`} '' on the page.\n${t}`)}}async waitFor(e,t,a={}){try{let n,i=a.tryLimit||this.configurations.tryLimit,o=a.delay||this.configurations.delay;for(;!(n=await e(...t))&&i;)i--,await(0,s.doDelay)(o);if(n)return n;throw new Error("Waiting timed out...")}catch(a){throw await this.handleGlitch(`Glitch while waiting for function '${e?.name}' with arguments '${JSON.stringify(t||[])}'.\n${a}`)}}async waitForNavigation(e={}){try{const t=await this.url();await this.waitFor((async e=>await this.url()!==e),[t],e)}catch(e){throw await this.handleGlitch(`Glitch while waiting for navigation.\n${e}`)}}async waitForSelector(e,t={},a=-1){try{await this.waitFor((async e=>this.evaluate(e)),[{func:(e,t)=>!!window.Self.getElementBySelectors(e,document,t),args:[e,a]}],t)}catch(t){throw await this.handleGlitch(`Glitch while waiting for the CSS Selectors '${e}'${-1===a?"":`[${a}]`}.\n${t}`)}}async waitForXPath(e,t={},a=-1){try{await this.waitFor((async e=>this.evaluate(e)),[{func:(e,t)=>!!window.Self.getElementByXPath(e,document,t),args:[e,a]}],t)}catch(t){throw await this.handleGlitch(`Glitch while waiting for the XPath '${e}'${-1===a?"":`[${a}]`}.\n${t}`)}}async waitForElement(e,t={},a=-1){if(await(h.default.isXPath(e)?this.waitForXPath:this.waitForSelector)(e,t,a).then((()=>!0)).catch((()=>!1)))return await this.getElement(e,a)}async waitForElementMiss(e,t={},a=-1){return await this.waitFor((async e=>this.evaluate(e)),[{func:h.default.isXPath(e)?(e,t)=>!window.Self.getElementByXPath(e,document,t):(e,t)=>!window.Self.getElementBySelectors(e,document,t),args:[e,a]}],t).then((()=>!0)).catch((()=>!1))}element(e,t=-1){const a=`${e}⟮${t}⟯`;return new l.default(this,a)}async getElement(e,t=-1,a){const n=`${a?`${a}→${e}`:e}⟮${t}⟯`,{tagName:i}=await this.evaluate({func:e=>{const t=window.Self.ElementActions.getElement(e);return t?{tagName:t.tagName}:{}},args:[n]});if(i)return new l.default(this,n,i)}async getElements(e,t){const a=await this.evaluate({func:(e,t)=>{const a=t?window.Self.ElementActions.getElement(t):document;if(a)return window.Self.getElements(e,a).map((({tagName:a},n)=>({tagName:a,elementPath:t?`${t}→${e}⟮${n}⟯`:`${e}⟮${n}⟯`})))},args:[e,t]});return a?.map((({tagName:e,elementPath:t})=>new l.default(this,t,e)))}async elementExists(e,t=-1){try{return await this.evaluate({func:(e,t)=>!!window.Self.getElement(e,document,t),args:[e,t]})}catch(a){throw await this.handleGlitch(`Glitch while checking if element with the CSS Selectors or XPath '${e}'${-1===t?"":`[${t}]`} exists.\n${a}`)}}async click(e,t=-1){try{if(!await this.evaluate({func:(e,t,a)=>window.Self.click(e,t,a),args:[e,t,this.configurations]}))throw new Error("No element(s) found for the given CSS Selectors or XPath.")}catch(a){throw await this.handleGlitch(`Failed to click on element with the CSS Selectors or XPath '${e}'${-1===t?"":`[${t}]`}.\n${a}`)}}execCopy(e){const t=document.createElement("textarea");t.innerHTML=e,document.body.appendChild(t),t.select(),document.execCommand("copy"),t.remove()}async execPasteTo(e,t=-1){try{if(!await this.evaluate({func:(e,t,a)=>window.Self.execPasteTo(e,t,a),args:[e,t,this.configurations]}))throw new Error("No element(s) found for the given CSS Selectors or XPath.")}catch(a){throw await this.handleGlitch(`Failed to paste to element with the CSS Selectors or XPath '${e}'${-1===t?"":`[${t}]`}.\n${a}`)}}async triggerEvent(e,t,a=-1){try{if(!await this.evaluate({func:(e,t,a,{scrollToElementBeforeAction:n,scrollIntoViewOptions:i})=>{const o=window.Self.getElement(e,document,a);return!!o&&(n&&o.scrollIntoView(i),window.Self.triggerEvent(o,t),!0)},args:[e,t,a,this.configurations]}))throw new Error("No element(s) found for the given CSS Selectors or XPath.")}catch(n){throw await this.handleGlitch(`Failed to trigger event '${t}' on element with the CSS Selectors or XPath '${e}'${-1===a?"":`[${a}]`}.\n${n}`)}}async input(e,t,a=-1){try{if(!await this.evaluate({func:(e,t,a,n)=>window.Self.input(e,t,a,n),args:[e,t,a,this.configurations]}))throw new Error("No element(s) found for the given CSS Selectors or XPath.")}catch(n){throw await this.handleGlitch(`Failed to input value '${t}' into element with the CSS Selectors or XPath '${e}'${-1===a?"":`[${a}]`}.\n${n}`)}}async uploadFiles(e,t,a){try{const n=a?"MAIN":"ISOLATED",i=await this.evaluate({world:n,func:e=>(window.transmittedFiles||(window.transmittedFiles=[]),window.transmittedFiles.push(e)-1),args:[t.map((({name:e},a)=>Object.assign({name:e},t[a].blob&&(t[a].blobUrl=URL.createObjectURL(t[a].blob))?{blobUrl:t[a].blobUrl}:{dataUrl:""})))]});for(let e=0;e<t.length;e++)if(t[e].dataUrl){let a=t[e].dataUrl.length,o=5242880,r=0;for(;r<a;)await this.evaluate({world:n,func:(e,t,a)=>{window.transmittedFiles[e][t].dataUrl+=a},args:[i,e,t[e].dataUrl.substr(r,o)]}),r+=o}await this.evaluate((async(e,t,a=-1,{scrollToElementBeforeAction:n,scrollIntoViewOptions:i})=>{const o=t?t.match(/^(\/|\.\/|\()/)?document.evaluate(t,document.documentElement,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue:document.querySelector(t):window.Self.elementCatcher.current?.elements[a];return!!o&&(n&&o.scrollIntoView(i),o.files=window.Self.filesToFileList(await Promise.all(window.transmittedFiles[e].map((async({blobUrl:e,dataUrl:t,name:a})=>e?window.Self.blobToFile(await window.Self.getBlob(e),a):window.Self.dataUrlToFile(t,a))))),window.Self.triggerEvent(o,"input"),window.Self.triggerEvent(o,"change"),delete window.transmittedFiles[e],0===window.transmittedFiles.filter(Boolean).length&&delete window.transmittedFiles,!0)}),[i,e,a,this.configurations],{world:n}),t.forEach((({blobUrl:e})=>URL.revokeObjectURL(e)))}catch(e){throw await this.handleGlitch(`Failed to upload files.\n${e}`)}}async screenshot({clip:e}){try{let t=await chrome.tabs.captureVisibleTab(this.windowId,{format:"png"});if(e){const{width:a,height:n,x:i,y:o}=e,r=await(0,s.cropImageOffscreen)(await(0,s.imageBitmapFromUrl)(t),a,n,i,o);t=await(0,s.blobToDataUrl)(await r.convertToBlob())}return t}catch(e){throw await this.handleGlitch(`Failed to take a screenshot.\n${e}`)}}elementCatcher={catch:async function(e){try{await this.evaluate({world:"MAIN",func:()=>window.Self?.exists()})||await this.evaluate({world:"MAIN",func:h.selfIntegration}),await this.evaluate({world:"MAIN",func:e=>window.Self.elementCatcher.catch(e),args:[e]})}catch(e){throw e}},terminate:async function(){try{await this.evaluate({world:"MAIN",func:()=>window.Self?.elementCatcher.terminate()})}catch(e){throw e}}};manualClick={enable:async function(){try{await this.evaluate((()=>window.Self.manualClick.enable()))}catch(e){throw e}},disable:async function(){try{await this.evaluate((()=>window.Self.manualClick.disable()))}catch(e){throw e}}}}},16:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.selfIntegration=void 0;const a=(e=!0)=>{const t={scrollToElementBeforeAction:!0,scrollIntoViewOptions:{behavior:"smooth",block:"center"}},a={tryLimit:30,delay:1e3,...t},n=async e=>new Promise((t=>setTimeout(t,e))),i=(e,t)=>{e.dispatchEvent(new Event(t,{bubbles:!0,cancelable:!0}))},o=(e,t)=>{e.tagName.match(/INPUT|TEXTAREA|SELECT/i)?e.value=t:e.innerHTML=t,i(e,"focus"),i(e,"keydown"),i(e,"keypress"),i(e,"keyup"),i(e,"input"),i(e,"change"),i(e,"blur")},r=e=>{e.focus(),"INPUT"!==e.tagName&&"TEXTAREA"!==e.tagName||e.select(),document.execCommand("paste")},l=e=>e.match(/^(\/|\.\/|\()/),s=(e,t=document,a=-1)=>-1===a?document.evaluate(e,t,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue:document.evaluate(e,t,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotItem(a),c=(e,t=document)=>{let a=[],n=document.evaluate(e,t,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);for(let e=0;e<n.snapshotLength;e++)a.push(n.snapshotItem(e));return a},h=(e,t=document,a=-1)=>-1===a?t.querySelector(e):t.querySelectorAll(e)[a],d=(e,t=document)=>Array.from(t.querySelectorAll(e)),u=(e,t=document,a=-1)=>l(e)?s(e,t,a):h(e,t,a),w={catch:e=>!w.current&&(w.current={originalFunc:document.createElement,elements:[],tagNames:e.map((e=>e.toUpperCase()))},document.createElement=function(){const e=w.current?.originalFunc.apply(this,arguments);return w.current?.tagNames.includes(e.tagName)&&w.current.elements.push(e),e},!0),terminate:()=>!!w.current&&(document.createElement=w.current.originalFunc,delete w.current,!0)},m={enable:()=>{m.current&&(m.current.element.remove(),delete m.current)},disable:()=>{m.current||(m.current={element:document.createElement("div")},m.current.element.style="width: 100%; height: 100%; position: fixed; top: 0; cursor: not-allowed; z-index: 12500; left: 0;",m.current.element.addEventListener("contextmenu",(e=>e.preventDefault())),document.body.appendChild(m.current.element))}},f=()=>location.href,g=async(e,t,i={})=>{let o,r=i.tryLimit||a.tryLimit,l=i.delay||a.delay;for(;!(o=await e(...t))&&r;)r--,await n(l);if(o)return o;throw new Error("Waiting timed out...")};class b{static elements=new Map;static getElement(e){let t=this.elements.get(e);if(t)return t;for(const a of e.split("→")){let[,e,n]=a.match(/(.+)⟮([0-9-]+)⟯$/);n=Number(n),t=u(e,t||document,n)}return t?(this.elements.size>50&&this.elements.delete(this.elements.keys().next().value),this.elements.set(e,t),t):void 0}static handleCall(e,t,a){const n=this.getElement(e);return a?n?.[t](...a):n?.[t]()}static handleGet(e,t){const a=this.getElement(e);return a?.[t]}static handleSet(e,t,a){this.getElement(e)[t]=a}}const y={exists:()=>!0,ElementActions:b,getElement:u,getElements:(e,t=document)=>l(e)?c(e,t):d(e,t),getElementBySelectors:h,getElementsBySelectors:d,getElementByXPath:s,getElementsByXPath:c,triggerEvent:i,triggerPaste:r,setValue:o,isXPath:l,filesToFileList:e=>{const t=new DataTransfer;for(const a of e)t.items.add(a);return t.files},getBlob:e=>new Promise((t=>{var a=new XMLHttpRequest;a.open("GET",e,!0),a.responseType="blob",a.onload=()=>t(a.response),a.send()})),dataUrlToFile:(e,t)=>{let[a,n]=e.split(",");a=a.match(/:(.*?);/)[1],n=atob(n);let i=n.length,o=new Uint8Array(i);for(;i--;)o[i]=n.charCodeAt(i);return new File([o],t,{type:a})},blobToFile:(e,t)=>new File([e],t,{type:e.type}),goto:e=>location.href=e,reload:()=>location.reload(),url:f,close:()=>globalThis.close(),zoom:e=>document.body.style.zoom=e,waitFor:g,waitForNavigation:async(e={})=>{const t=f();await g((async e=>f()!==e),[t],e)},waitForElement:async(e,t={},a=-1)=>{await g(l(e)?(e,t)=>!!s(e,document,t):(e,t)=>!!h(e,document,t),[e,a],t)},waitForElementMiss:async(e,t={},a=-1)=>{await g(l(e)?(e,t)=>!s(e,document,t):(e,t)=>!h(e,document,t),[e,a],t)},click:(e,a=-1,{scrollToElementBeforeAction:n,scrollIntoViewOptions:i}=t)=>{const o=u(e,document,a);return!!o&&(n&&o.scrollIntoView(i),o.click(),!0)},elementExists:(e,t=-1)=>!!u(e,document,t),execPasteTo:(e,a=-1,{scrollToElementBeforeAction:n,scrollIntoViewOptions:i}=t)=>{const o=u(e,document,a);return!!o&&(n&&o.scrollIntoView(i),r(o),!0)},input:(e,a,n=-1,{scrollToElementBeforeAction:i,scrollIntoViewOptions:r}=t)=>{const l=u(e,document,n);return!!l&&(i&&l.scrollIntoView(r),o(l,a),!0)},elementCatcher:w,manualClick:m};return e&&!window.Self?.exists?.()&&(window.Self=y),y};t.selfIntegration=a;const n=a(!1);t.default=n}},t={};return function a(n){var i=t[n];if(void 0!==i)return i.exports;var o=t[n]={exports:{}};return e[n].call(o.exports,o,o.exports,a),o.exports}(156)})())); |
@@ -1,1 +0,1 @@ | ||
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var a=e();for(var n in a)("object"==typeof exports?exports:t)[n]=a[n]}}(this,(()=>(()=>{"use strict";var t={792:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=class{page;elementPath;tagName;async handleCall(t,e){return await this.page.evaluate({func:(t,e,a)=>a?window.Self.ElementActions.handleCall(t,e,a):window.Self.ElementActions.handleCall(t,e),args:e?[this.elementPath,t,e]:[this.elementPath,t]})}async handleGet(t){return await this.page.evaluate({func:(t,e)=>window.Self.ElementActions.handleGet(t,e),args:[this.elementPath,t]})}async handleSet(t,e){return await this.page.evaluate({func:(t,e,a)=>window.Self.ElementActions.handleSet(t,e,a),args:[this.elementPath,t,e]})}async getTagName(){return this.tagName||(this.tagName=await this.handleGet("tagName")),this.tagName}async getInnerText(){return await this.handleGet("innerText")}async getInnerHTML(){return await this.handleGet("innerHTML")}async setInnerHTML(t){return await this.handleSet("innerHTML",t)}async click(){return await this.handleCall("click")}async focus(){return await this.handleCall("focus")}async scrollIntoView(t){return await this.handleCall("scrollIntoView",[t])}async getAttribute(t){return await this.handleCall("getAttribute",[t])}async setAttribute(t,e){return await this.handleCall("setAttribute",[t,e])}async getElement(t,e=-1){return await this.page.getElement(t,e,this.elementPath)}async getElements(t){return await this.page.getElements(t,this.elementPath)}async input(t){return await this.page.evaluate({func:(t,e)=>{const a=window.Self.ElementActions.getElement(e);return!!a&&(window.Self.setValue(a,t),!0)},args:[t,this.elementPath]})}async execPaste(){return await this.page.evaluate({func:t=>{const e=window.Self.ElementActions.getElement(t);return!!e&&(window.Self.triggerPaste(e),!0)},args:[this.elementPath]})}async triggerEvent(t){return await this.page.evaluate({func:(t,e)=>{const a=window.Self.ElementActions.getElement(e);return!!a&&(window.Self.triggerEvent(a,t),!0)},args:[t,this.elementPath]})}constructor(t,e,a){this.page=t,this.elementPath=e,a&&(this.tagName=a)}}},419:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.chooseProperties=e.omitProperties=e.setValue=e.triggerEvent=e.getRandomFromArray=e.blobToDataUrl=e.imageBitmapFromUrl=e.cropImageOffscreen=e.doDelay=void 0,e.doDelay=async t=>new Promise((e=>setTimeout(e,t))),e.cropImageOffscreen=(t,e,a,n,i)=>{var o=new OffscreenCanvas(e,a);return o.getContext("2d").drawImage(t,n,i,e,a,0,0,e,a),o},e.imageBitmapFromUrl=async t=>await fetch(t).then((t=>t.blob())).then((async t=>createImageBitmap(t))),e.blobToDataUrl=async t=>new Promise((e=>{let a=new FileReader;a.onload=function(){e(this.result)},a.readAsDataURL(t)})),e.getRandomFromArray=t=>t[Math.floor(Math.random()*t.length)];const a=(t,e)=>{t.dispatchEvent(new Event(e,{bubbles:!0,cancelable:!0}))};e.triggerEvent=a,e.setValue=(t,e)=>{t.tagName.match(/INPUT|TEXTAREA|SELECT/i)?t.value=e:t.innerHTML=e,a(t,"focus"),a(t,"keydown"),a(t,"keypress"),a(t,"keyup"),a(t,"input"),a(t,"change"),a(t,"blur")},e.omitProperties=(t,e)=>Object.fromEntries(Object.entries(t).filter((([t])=>!e.includes(t)))),e.chooseProperties=(t,e)=>Object.fromEntries(Object.entries(t).filter((([t])=>e.includes(t))))},633:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.defaultPageConfigurations=e.defaultActionOptions=void 0,e.defaultActionOptions={scrollToElementBeforeAction:!0,scrollIntoViewOptions:{behavior:"smooth",block:"center"}},e.defaultPageConfigurations={tryLimit:30,delay:1e3,...e.defaultActionOptions}},869:function(t,e,a){var n=this&&this.__createBinding||(Object.create?function(t,e,a,n){void 0===n&&(n=a);var i=Object.getOwnPropertyDescriptor(e,a);i&&!("get"in i?!e.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return e[a]}}),Object.defineProperty(t,n,i)}:function(t,e,a,n){void 0===n&&(n=a),t[n]=e[a]}),i=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),o=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var a in t)"default"!==a&&Object.prototype.hasOwnProperty.call(t,a)&&n(e,t,a);return i(e,t),e},r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const l=r(a(792)),s=a(419),c=a(633),h=o(a(16));e.default=class{browser;tabId;windowId;originWindowId;activeInOrigin;onBeforeClose;configurations=c.defaultPageConfigurations;async handleGlitch(t){return`${t}\nPage URL: '${await chrome.tabs.get(this.tabId).then((({url:t})=>t)).catch((()=>"N/A"))}'`}configure(t){this.configurations={...this.configurations,...t}}constructor({tabId:t,windowId:e,originWindowId:a,activeInOrigin:n,browser:i}){this.tabId=t,this.windowId=e,this.browser=i,a&&(this.originWindowId=a),n&&(this.activeInOrigin=n),this.elementCatcher.catch=this.elementCatcher.catch.bind(this),this.elementCatcher.terminate=this.elementCatcher.terminate.bind(this),this.manualClick.enable=this.manualClick.enable.bind(this),this.manualClick.disable=this.manualClick.disable.bind(this)}async goto(t,{waitUntil:e}={waitUntil:"domcontentloaded"}){try{let a;if(await chrome.tabs.update(this.tabId,{url:"about:blank"}),await chrome.tabs.update(this.tabId,{url:t}),"load"===e)do{await(0,s.doDelay)(this.configurations.delay),a=await chrome.tabs.get(this.tabId)}while("about:blank"===a.pendingUrl||"about:blank"===a.url);else if(e="domcontentloaded")do{await(0,s.doDelay)(this.configurations.delay),a=await chrome.tabs.get(this.tabId)}while("about:blank"===a.pendingUrl||"about:blank"===a.url||"complete"!==a.status)}catch(e){throw await this.handleGlitch(`Failed to navigate to URL '${t}'.\n${e}`)}}async reload(){try{await this.goto(await this.url())}catch(t){throw await this.handleGlitch(`Failed to reload the page.\n${t}`)}}async url(){try{const{url:t}=await chrome.tabs.get(this.tabId);return t}catch(t){throw await this.handleGlitch(`Failed to get the URL of the page.\n${t}`)}}async close(){try{await chrome.windows.remove(this.windowId).catch((()=>{}))}catch(t){throw await this.handleGlitch(`Failed to close the page.\n${t}`)}}async zoom(t){try{t!==await chrome.tabs.getZoom(this.tabId)&&await chrome.tabs.setZoom(this.tabId,t)}catch(t){throw await this.handleGlitch(`Failed to zoom the page.\n${t}`)}}async bringToFront(){try{await chrome.windows.update(this.windowId,{focused:!0})}catch(t){throw await this.handleGlitch(`Failed to bring the page to the front.\n${t}`)}}async hideFromFront(){try{await chrome.windows.update(this.windowId,{focused:!1})}catch(t){throw await this.handleGlitch(`Failed to hide the page from the front.\n${t}`)}}async evaluate(){let t={};try{if("function"==typeof arguments[0]){const[e,a,n]=arguments;t={func:e,args:a,...n||{}}}else if(Array.isArray(arguments[0])){const[e,a,n]=arguments;t={files:e,args:a,...n||{}}}else t=arguments[0];const e=await chrome.scripting.executeScript({target:{tabId:this.tabId,...(0,s.chooseProperties)(t,["allFrames","frameIds","documentIds"])},world:"ISOLATED",...(0,s.chooseProperties)(t,["func","files","args","world"])});return e?.[0]?.result}catch(e){throw await this.handleGlitch(`Failed to evaluate ${t?.func?`function '${t.func?.name}' with arguments '${JSON.stringify(t.args||[])}'`:`file(s) '${JSON.stringify(t.files||[])}'`} '' on the page.\n${e}`)}}async waitFor(t,e,a={}){try{let n,i=a.tryLimit||this.configurations.tryLimit,o=a.delay||this.configurations.delay;for(;!(n=await t(...e))&&i;)i--,await(0,s.doDelay)(o);if(n)return n;throw new Error("Waiting timed out...")}catch(a){throw await this.handleGlitch(`Glitch while waiting for function '${t?.name}' with arguments '${JSON.stringify(e||[])}'.\n${a}`)}}async waitForNavigation(t={}){try{const e=await this.url();await this.waitFor((async t=>await this.url()!==t),[e],t)}catch(t){throw await this.handleGlitch(`Glitch while waiting for navigation.\n${t}`)}}async waitForSelector(t,e={},a=-1){try{await this.waitFor((async t=>this.evaluate(t)),[{func:(t,e)=>!!window.Self.getElementBySelectors(t,document,e),args:[t,a]}],e)}catch(e){throw await this.handleGlitch(`Glitch while waiting for the CSS Selectors '${t}'${-1===a?"":`[${a}]`}.\n${e}`)}}async waitForXPath(t,e={},a=-1){try{await this.waitFor((async t=>this.evaluate(t)),[{func:(t,e)=>!!window.Self.getElementByXPath(t,document,e),args:[t,a]}],e)}catch(e){throw await this.handleGlitch(`Glitch while waiting for the XPath '${t}'${-1===a?"":`[${a}]`}.\n${e}`)}}async waitForElement(t,e={},a=-1){if(await(h.default.isXPath(t)?this.waitForXPath:this.waitForSelector)(t,e,a).then((()=>!0)).catch((()=>!1)))return await this.getElement(t,a)}async waitForElementMiss(t,e={},a=-1){return await this.waitFor((async t=>this.evaluate(t)),[{func:h.default.isXPath(t)?(t,e)=>!window.Self.getElementByXPath(t,document,e):(t,e)=>!window.Self.getElementBySelectors(t,document,e),args:[t,a]}],e).then((()=>!0)).catch((()=>!1))}element(t,e=-1){const a=`${t}⟮${e}⟯`;return new l.default(this,a)}async getElement(t,e=-1,a){const n=`${a?`${a}→${t}`:t}⟮${e}⟯`,{tagName:i}=await this.evaluate({func:t=>{const e=window.Self.ElementActions.getElement(t);return e?{tagName:e.tagName}:{}},args:[n]});if(i)return new l.default(this,n,i)}async getElements(t,e){const a=await this.evaluate({func:(t,e)=>{const a=e?window.Self.ElementActions.getElement(e):document;if(a)return window.Self.getElements(t,a).map((({tagName:a},n)=>({tagName:a,elementPath:e?`${e}→${t}⟮${n}⟯`:`${t}⟮${n}⟯`})))},args:[t,e]});return a?.map((({tagName:t,elementPath:e})=>new l.default(this,e,t)))}async elementExists(t,e=-1){try{return await this.evaluate({func:(t,e)=>!!window.Self.getElement(t,document,e),args:[t,e]})}catch(a){throw await this.handleGlitch(`Glitch while checking if element with the CSS Selectors or XPath '${t}'${-1===e?"":`[${e}]`} exists.\n${a}`)}}async click(t,e=-1){try{if(!await this.evaluate({func:(t,e,a)=>window.Self.click(t,e,a),args:[t,e,this.configurations]}))throw new Error("No element(s) found for the given CSS Selectors or XPath.")}catch(a){throw await this.handleGlitch(`Failed to click on element with the CSS Selectors or XPath '${t}'${-1===e?"":`[${e}]`}.\n${a}`)}}execCopy(t){const e=document.createElement("textarea");e.innerHTML=t,document.body.appendChild(e),e.select(),document.execCommand("copy"),e.remove()}async execPasteTo(t,e=-1){try{if(!await this.evaluate({func:(t,e,a)=>window.Self.execPasteTo(t,e,a),args:[t,e,this.configurations]}))throw new Error("No element(s) found for the given CSS Selectors or XPath.")}catch(a){throw await this.handleGlitch(`Failed to paste to element with the CSS Selectors or XPath '${t}'${-1===e?"":`[${e}]`}.\n${a}`)}}async triggerEvent(t,e,a=-1){try{if(!await this.evaluate({func:(t,e,a,{scrollToElementBeforeAction:n,scrollIntoViewOptions:i})=>{const o=window.Self.getElement(t,document,a);return!!o&&(n&&o.scrollIntoView(i),window.Self.triggerEvent(o,e),!0)},args:[t,e,a,this.configurations]}))throw new Error("No element(s) found for the given CSS Selectors or XPath.")}catch(n){throw await this.handleGlitch(`Failed to trigger event '${e}' on element with the CSS Selectors or XPath '${t}'${-1===a?"":`[${a}]`}.\n${n}`)}}async input(t,e,a=-1){try{if(!await this.evaluate({func:(t,e,a,n)=>window.Self.input(t,e,a,n),args:[t,e,a,this.configurations]}))throw new Error("No element(s) found for the given CSS Selectors or XPath.")}catch(n){throw await this.handleGlitch(`Failed to input value '${e}' into element with the CSS Selectors or XPath '${t}'${-1===a?"":`[${a}]`}.\n${n}`)}}async uploadFiles(t,e,a){try{const n=a?"MAIN":"ISOLATED",i=await this.evaluate({world:n,func:t=>(window.transmittedFiles||(window.transmittedFiles=[]),window.transmittedFiles.push(t)-1),args:[e.map((({name:t},a)=>Object.assign({name:t},e[a].blob&&(e[a].blobUrl=URL.createObjectURL(e[a].blob))?{blobUrl:e[a].blobUrl}:{dataUrl:""})))]});for(let t=0;t<e.length;t++)if(e[t].dataUrl){let a=e[t].dataUrl.length,o=5242880,r=0;for(;r<a;)await this.evaluate({world:n,func:(t,e,a)=>{window.transmittedFiles[t][e].dataUrl+=a},args:[i,t,e[t].dataUrl.substr(r,o)]}),r+=o}await this.evaluate((async(t,e,a=-1,{scrollToElementBeforeAction:n,scrollIntoViewOptions:i})=>{const o=e?e.match(/^(\/|\.\/|\()/)?document.evaluate(e,document.documentElement,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue:document.querySelector(e):window.Self.elementCatcher.current?.elements[a];return!!o&&(n&&o.scrollIntoView(i),o.files=window.Self.filesToFileList(await Promise.all(window.transmittedFiles[t].map((async({blobUrl:t,dataUrl:e,name:a})=>t?window.Self.blobToFile(await window.Self.getBlob(t),a):window.Self.dataUrlToFile(e,a))))),window.Self.triggerEvent(o,"input"),window.Self.triggerEvent(o,"change"),delete window.transmittedFiles[t],0===window.transmittedFiles.filter(Boolean).length&&delete window.transmittedFiles,!0)}),[i,t,a,this.configurations],{world:n}),e.forEach((({blobUrl:t})=>URL.revokeObjectURL(t)))}catch(t){throw await this.handleGlitch(`Failed to upload files.\n${t}`)}}async screenshot({clip:t}){try{let e=await chrome.tabs.captureVisibleTab(this.windowId,{format:"png"});if(t){const{width:a,height:n,x:i,y:o}=t,r=await(0,s.cropImageOffscreen)(await(0,s.imageBitmapFromUrl)(e),a,n,i,o);e=await(0,s.blobToDataUrl)(await r.convertToBlob())}return e}catch(t){throw await this.handleGlitch(`Failed to take a screenshot.\n${t}`)}}elementCatcher={catch:async function(t){try{await this.evaluate({world:"MAIN",func:()=>window.Self?.exists()})||await this.evaluate({world:"MAIN",func:h.selfIntegration}),await this.evaluate({world:"MAIN",func:t=>window.Self.elementCatcher.catch(t),args:[t]})}catch(t){throw t}},terminate:async function(){try{await this.evaluate({world:"MAIN",func:()=>window.Self?.elementCatcher.terminate()})}catch(t){throw t}}};manualClick={enable:async function(){try{await this.evaluate((()=>window.Self.manualClick.enable()))}catch(t){throw t}},disable:async function(){try{await this.evaluate((()=>window.Self.manualClick.disable()))}catch(t){throw t}}}}},16:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.selfIntegration=void 0;const a=(t=!0)=>{const e={scrollToElementBeforeAction:!0,scrollIntoViewOptions:{behavior:"smooth",block:"center"}},a={tryLimit:30,delay:1e3,...e},n=async t=>new Promise((e=>setTimeout(e,t))),i=(t,e)=>{t.dispatchEvent(new Event(e,{bubbles:!0,cancelable:!0}))},o=(t,e)=>{t.tagName.match(/INPUT|TEXTAREA|SELECT/i)?t.value=e:t.innerHTML=e,i(t,"focus"),i(t,"keydown"),i(t,"keypress"),i(t,"keyup"),i(t,"input"),i(t,"change"),i(t,"blur")},r=t=>{t.focus(),"INPUT"!==t.tagName&&"TEXTAREA"!==t.tagName||t.select(),document.execCommand("paste")},l=t=>t.match(/^(\/|\.\/|\()/),s=(t,e=document,a=-1)=>-1===a?document.evaluate(t,e,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue:document.evaluate(t,e,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotItem(a),c=(t,e=document)=>{let a=[],n=document.evaluate(t,e,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);for(let t=0;t<n.snapshotLength;t++)a.push(n.snapshotItem(t));return a},h=(t,e=document,a=-1)=>-1===a?e.querySelector(t):e.querySelectorAll(t)[a],u=(t,e=document)=>Array.from(e.querySelectorAll(t)),d=(t,e=document,a=-1)=>l(t)?s(t,e,a):h(t,e,a),w={catch:t=>!w.current&&(w.current={originalFunc:document.createElement,elements:[],tagNames:t.map((t=>t.toUpperCase()))},document.createElement=function(){const t=w.current?.originalFunc.apply(this,arguments);return w.current?.tagNames.includes(t.tagName)&&w.current.elements.push(t),t},!0),terminate:()=>!!w.current&&(document.createElement=w.current.originalFunc,delete w.current,!0)},m={enable:()=>{m.current&&(m.current.element.remove(),delete m.current)},disable:()=>{m.current||(m.current={element:document.createElement("div")},m.current.element.style="width: 100%; height: 100%; position: fixed; top: 0; cursor: not-allowed; z-index: 12500; left: 0;",m.current.element.addEventListener("contextmenu",(t=>t.preventDefault())),document.body.appendChild(m.current.element))}},f=()=>location.href,g=async(t,e,i={})=>{let o,r=i.tryLimit||a.tryLimit,l=i.delay||a.delay;for(;!(o=await t(...e))&&r;)r--,await n(l);if(o)return o;throw new Error("Waiting timed out...")};class y{static elements=new Map;static getElement(t){let e=this.elements.get(t);if(e)return e;for(const a of t.split("→")){let[,t,n]=a.match(/(.+)⟮([0-9-]+)⟯$/);n=Number(n),e=d(t,e||document,n)}return e?(this.elements.size>50&&this.elements.delete(this.elements.keys().next().value),this.elements.set(t,e),e):void 0}static handleCall(t,e,a){const n=this.getElement(t);return a?n?.[e](...a):n?.[e]()}static handleGet(t,e){const a=this.getElement(t);return a?.[e]}static handleSet(t,e,a){this.getElement(t)[e]=a}}const b={exists:()=>!0,ElementActions:y,getElement:d,getElements:(t,e=document)=>l(t)?c(t,e):u(t,e),getElementBySelectors:h,getElementsBySelectors:u,getElementByXPath:s,getElementsByXPath:c,triggerEvent:i,triggerPaste:r,setValue:o,isXPath:l,filesToFileList:t=>{const e=new DataTransfer;for(const a of t)e.items.add(a);return e.files},getBlob:t=>new Promise((e=>{var a=new XMLHttpRequest;a.open("GET",t,!0),a.responseType="blob",a.onload=()=>e(a.response),a.send()})),dataUrlToFile:(t,e)=>{let[a,n]=t.split(",");a=a.match(/:(.*?);/)[1],n=atob(n);let i=n.length,o=new Uint8Array(i);for(;i--;)o[i]=n.charCodeAt(i);return new File([o],e,{type:a})},blobToFile:(t,e)=>new File([t],e,{type:t.type}),goto:t=>location.href=t,reload:()=>location.reload(),url:f,close:()=>globalThis.close(),zoom:t=>document.body.style.zoom=t,waitFor:g,waitForNavigation:async(t={})=>{const e=f();await g((async t=>f()!==t),[e],t)},waitForElement:async(t,e={},a=-1)=>{await g(l(t)?(t,e)=>!!s(t,document,e):(t,e)=>!!h(t,document,e),[t,a],e)},waitForElementMiss:async(t,e={},a=-1)=>{await g(l(t)?(t,e)=>!s(t,document,e):(t,e)=>!h(t,document,e),[t,a],e)},click:(t,a=-1,{scrollToElementBeforeAction:n,scrollIntoViewOptions:i}=e)=>{const o=d(t,document,a);return!!o&&(n&&o.scrollIntoView(i),o.click(),!0)},elementExists:(t,e=-1)=>!!d(t,document,e),execPasteTo:(t,a=-1,{scrollToElementBeforeAction:n,scrollIntoViewOptions:i}=e)=>{const o=d(t,document,a);return!!o&&(n&&o.scrollIntoView(i),r(o),!0)},input:(t,a,n=-1,{scrollToElementBeforeAction:i,scrollIntoViewOptions:r}=e)=>{const l=d(t,document,n);return!!l&&(i&&l.scrollIntoView(r),o(l,a),!0)},elementCatcher:w,manualClick:m};return t&&!window.Self?.exists?.()&&(window.Self=b),b};e.selfIntegration=a;const n=a(!1);e.default=n}},e={};return function a(n){var i=e[n];if(void 0!==i)return i.exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,a),o.exports}(869)})())); | ||
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var a=e();for(var n in a)("object"==typeof exports?exports:t)[n]=a[n]}}(this,(()=>(()=>{"use strict";var t={792:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=class{page;elementPath;tagName;async handleCall(t,e){return await this.page.evaluate({func:(t,e,a)=>a?window.Self.ElementActions.handleCall(t,e,a):window.Self.ElementActions.handleCall(t,e),args:e?[this.elementPath,t,e]:[this.elementPath,t]})}async handleGet(t){return await this.page.evaluate({func:(t,e)=>window.Self.ElementActions.handleGet(t,e),args:[this.elementPath,t]})}async handleSet(t,e){return await this.page.evaluate({func:(t,e,a)=>window.Self.ElementActions.handleSet(t,e,a),args:[this.elementPath,t,e]})}async getTagName(){return this.tagName||(this.tagName=await this.handleGet("tagName")),this.tagName}async getInnerText(){return await this.handleGet("innerText")}async getInnerHTML(){return await this.handleGet("innerHTML")}async setInnerHTML(t){return await this.handleSet("innerHTML",t)}async click(){return await this.handleCall("click")}async focus(){return await this.handleCall("focus")}async scrollIntoView(t){return await this.handleCall("scrollIntoView",[t])}async getAttribute(t){return await this.handleCall("getAttribute",[t])}async setAttribute(t,e){return await this.handleCall("setAttribute",[t,e])}async getElement(t,e=-1){return await this.page.getElement(t,e,this.elementPath)}async getElements(t){return await this.page.getElements(t,this.elementPath)}async input(t){return await this.page.evaluate({func:(t,e)=>{const a=window.Self.ElementActions.getElement(e);return!!a&&(window.Self.setValue(a,t),!0)},args:[t,this.elementPath]})}async execPaste(){return await this.page.evaluate({func:t=>{const e=window.Self.ElementActions.getElement(t);return!!e&&(window.Self.triggerPaste(e),!0)},args:[this.elementPath]})}async triggerEvent(t){return await this.page.evaluate({func:(t,e)=>{const a=window.Self.ElementActions.getElement(e);return!!a&&(window.Self.triggerEvent(a,t),!0)},args:[t,this.elementPath]})}constructor(t,e,a){this.page=t,this.elementPath=e,a&&(this.tagName=a)}}},419:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.chooseProperties=e.omitProperties=e.setValue=e.triggerEvent=e.getRandomFromArray=e.blobToDataUrl=e.imageBitmapFromUrl=e.cropImageOffscreen=e.doDelay=void 0,e.doDelay=async t=>new Promise((e=>setTimeout(e,t))),e.cropImageOffscreen=(t,e,a,n,i)=>{var o=new OffscreenCanvas(e,a);return o.getContext("2d").drawImage(t,n,i,e,a,0,0,e,a),o},e.imageBitmapFromUrl=async t=>await fetch(t).then((t=>t.blob())).then((async t=>createImageBitmap(t))),e.blobToDataUrl=async t=>new Promise((e=>{let a=new FileReader;a.onload=function(){e(this.result)},a.readAsDataURL(t)})),e.getRandomFromArray=t=>t[Math.floor(Math.random()*t.length)];const a=(t,e)=>{t.dispatchEvent(new Event(e,{bubbles:!0,cancelable:!0}))};e.triggerEvent=a,e.setValue=(t,e)=>{t.tagName.match(/INPUT|TEXTAREA|SELECT/i)?t.value=e:t.innerHTML=e,a(t,"focus"),a(t,"keydown"),a(t,"keypress"),a(t,"keyup"),a(t,"input"),a(t,"change"),a(t,"blur")},e.omitProperties=(t,e)=>Object.fromEntries(Object.entries(t).filter((([t])=>!e.includes(t)))),e.chooseProperties=(t,e)=>Object.fromEntries(Object.entries(t).filter((([t])=>e.includes(t))))},633:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.defaultPageConfigurations=e.defaultActionOptions=void 0,e.defaultActionOptions={scrollToElementBeforeAction:!0,scrollIntoViewOptions:{behavior:"smooth",block:"center"}},e.defaultPageConfigurations={tryLimit:30,delay:1e3,...e.defaultActionOptions}},869:function(t,e,a){var n=this&&this.__createBinding||(Object.create?function(t,e,a,n){void 0===n&&(n=a);var i=Object.getOwnPropertyDescriptor(e,a);i&&!("get"in i?!e.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return e[a]}}),Object.defineProperty(t,n,i)}:function(t,e,a,n){void 0===n&&(n=a),t[n]=e[a]}),i=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),o=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var a in t)"default"!==a&&Object.prototype.hasOwnProperty.call(t,a)&&n(e,t,a);return i(e,t),e},r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const l=r(a(792)),s=a(419),c=a(633),h=o(a(16));e.default=class{browser;tabId;windowId;originWindowId;activeInOrigin;onBeforeClose;configurations=c.defaultPageConfigurations;async handleGlitch(t){return`${t}\nPage URL: '${await chrome.tabs.get(this.tabId).then((({url:t})=>t)).catch((()=>"N/A"))}'`}configure(t){this.configurations={...this.configurations,...t}}constructor({tabId:t,windowId:e,originWindowId:a,activeInOrigin:n,browser:i}){this.tabId=t,this.windowId=e,this.browser=i,a&&(this.originWindowId=a),n&&(this.activeInOrigin=n),this.elementCatcher.catch=this.elementCatcher.catch.bind(this),this.elementCatcher.terminate=this.elementCatcher.terminate.bind(this),this.manualClick.enable=this.manualClick.enable.bind(this),this.manualClick.disable=this.manualClick.disable.bind(this)}async goto(t,{waitUntil:e}={waitUntil:"domcontentloaded"}){try{if(await chrome.tabs.update(this.tabId,{url:"about:blank"}),"about:blank"===t)return;let a;if(await chrome.tabs.update(this.tabId,{url:t}),"load"===e)do{await(0,s.doDelay)(this.configurations.delay),a=await chrome.tabs.get(this.tabId)}while("about:blank"===a.pendingUrl||"about:blank"===a.url);else if(e="domcontentloaded")do{await(0,s.doDelay)(this.configurations.delay),a=await chrome.tabs.get(this.tabId)}while("about:blank"===a.pendingUrl||"about:blank"===a.url||"complete"!==a.status)}catch(e){throw await this.handleGlitch(`Failed to navigate to URL '${t}'.\n${e}`)}}async reload(){try{await this.goto(await this.url())}catch(t){throw await this.handleGlitch(`Failed to reload the page.\n${t}`)}}async url(){try{const{url:t}=await chrome.tabs.get(this.tabId);return t}catch(t){throw await this.handleGlitch(`Failed to get the URL of the page.\n${t}`)}}async close(){try{await chrome.windows.remove(this.windowId).catch((()=>{}))}catch(t){throw await this.handleGlitch(`Failed to close the page.\n${t}`)}}async zoom(t){try{t!==await chrome.tabs.getZoom(this.tabId)&&await chrome.tabs.setZoom(this.tabId,t)}catch(t){throw await this.handleGlitch(`Failed to zoom the page.\n${t}`)}}async bringToFront(){try{await chrome.windows.update(this.windowId,{focused:!0})}catch(t){throw await this.handleGlitch(`Failed to bring the page to the front.\n${t}`)}}async hideFromFront(){try{await chrome.windows.update(this.windowId,{focused:!1})}catch(t){throw await this.handleGlitch(`Failed to hide the page from the front.\n${t}`)}}async evaluate(){let t={};try{if("function"==typeof arguments[0]){const[e,a,n]=arguments;t={func:e,args:a,...n||{}}}else if(Array.isArray(arguments[0])){const[e,a,n]=arguments;t={files:e,args:a,...n||{}}}else t=arguments[0];const e=await chrome.scripting.executeScript({target:{tabId:this.tabId,...(0,s.chooseProperties)(t,["allFrames","frameIds","documentIds"])},world:"ISOLATED",...(0,s.chooseProperties)(t,["func","files","args","world"])});return e?.[0]?.result}catch(e){throw await this.handleGlitch(`Failed to evaluate ${t?.func?`function '${t.func?.name}' with arguments '${JSON.stringify(t.args||[])}'`:`file(s) '${JSON.stringify(t.files||[])}'`} '' on the page.\n${e}`)}}async waitFor(t,e,a={}){try{let n,i=a.tryLimit||this.configurations.tryLimit,o=a.delay||this.configurations.delay;for(;!(n=await t(...e))&&i;)i--,await(0,s.doDelay)(o);if(n)return n;throw new Error("Waiting timed out...")}catch(a){throw await this.handleGlitch(`Glitch while waiting for function '${t?.name}' with arguments '${JSON.stringify(e||[])}'.\n${a}`)}}async waitForNavigation(t={}){try{const e=await this.url();await this.waitFor((async t=>await this.url()!==t),[e],t)}catch(t){throw await this.handleGlitch(`Glitch while waiting for navigation.\n${t}`)}}async waitForSelector(t,e={},a=-1){try{await this.waitFor((async t=>this.evaluate(t)),[{func:(t,e)=>!!window.Self.getElementBySelectors(t,document,e),args:[t,a]}],e)}catch(e){throw await this.handleGlitch(`Glitch while waiting for the CSS Selectors '${t}'${-1===a?"":`[${a}]`}.\n${e}`)}}async waitForXPath(t,e={},a=-1){try{await this.waitFor((async t=>this.evaluate(t)),[{func:(t,e)=>!!window.Self.getElementByXPath(t,document,e),args:[t,a]}],e)}catch(e){throw await this.handleGlitch(`Glitch while waiting for the XPath '${t}'${-1===a?"":`[${a}]`}.\n${e}`)}}async waitForElement(t,e={},a=-1){if(await(h.default.isXPath(t)?this.waitForXPath:this.waitForSelector)(t,e,a).then((()=>!0)).catch((()=>!1)))return await this.getElement(t,a)}async waitForElementMiss(t,e={},a=-1){return await this.waitFor((async t=>this.evaluate(t)),[{func:h.default.isXPath(t)?(t,e)=>!window.Self.getElementByXPath(t,document,e):(t,e)=>!window.Self.getElementBySelectors(t,document,e),args:[t,a]}],e).then((()=>!0)).catch((()=>!1))}element(t,e=-1){const a=`${t}⟮${e}⟯`;return new l.default(this,a)}async getElement(t,e=-1,a){const n=`${a?`${a}→${t}`:t}⟮${e}⟯`,{tagName:i}=await this.evaluate({func:t=>{const e=window.Self.ElementActions.getElement(t);return e?{tagName:e.tagName}:{}},args:[n]});if(i)return new l.default(this,n,i)}async getElements(t,e){const a=await this.evaluate({func:(t,e)=>{const a=e?window.Self.ElementActions.getElement(e):document;if(a)return window.Self.getElements(t,a).map((({tagName:a},n)=>({tagName:a,elementPath:e?`${e}→${t}⟮${n}⟯`:`${t}⟮${n}⟯`})))},args:[t,e]});return a?.map((({tagName:t,elementPath:e})=>new l.default(this,e,t)))}async elementExists(t,e=-1){try{return await this.evaluate({func:(t,e)=>!!window.Self.getElement(t,document,e),args:[t,e]})}catch(a){throw await this.handleGlitch(`Glitch while checking if element with the CSS Selectors or XPath '${t}'${-1===e?"":`[${e}]`} exists.\n${a}`)}}async click(t,e=-1){try{if(!await this.evaluate({func:(t,e,a)=>window.Self.click(t,e,a),args:[t,e,this.configurations]}))throw new Error("No element(s) found for the given CSS Selectors or XPath.")}catch(a){throw await this.handleGlitch(`Failed to click on element with the CSS Selectors or XPath '${t}'${-1===e?"":`[${e}]`}.\n${a}`)}}execCopy(t){const e=document.createElement("textarea");e.innerHTML=t,document.body.appendChild(e),e.select(),document.execCommand("copy"),e.remove()}async execPasteTo(t,e=-1){try{if(!await this.evaluate({func:(t,e,a)=>window.Self.execPasteTo(t,e,a),args:[t,e,this.configurations]}))throw new Error("No element(s) found for the given CSS Selectors or XPath.")}catch(a){throw await this.handleGlitch(`Failed to paste to element with the CSS Selectors or XPath '${t}'${-1===e?"":`[${e}]`}.\n${a}`)}}async triggerEvent(t,e,a=-1){try{if(!await this.evaluate({func:(t,e,a,{scrollToElementBeforeAction:n,scrollIntoViewOptions:i})=>{const o=window.Self.getElement(t,document,a);return!!o&&(n&&o.scrollIntoView(i),window.Self.triggerEvent(o,e),!0)},args:[t,e,a,this.configurations]}))throw new Error("No element(s) found for the given CSS Selectors or XPath.")}catch(n){throw await this.handleGlitch(`Failed to trigger event '${e}' on element with the CSS Selectors or XPath '${t}'${-1===a?"":`[${a}]`}.\n${n}`)}}async input(t,e,a=-1){try{if(!await this.evaluate({func:(t,e,a,n)=>window.Self.input(t,e,a,n),args:[t,e,a,this.configurations]}))throw new Error("No element(s) found for the given CSS Selectors or XPath.")}catch(n){throw await this.handleGlitch(`Failed to input value '${e}' into element with the CSS Selectors or XPath '${t}'${-1===a?"":`[${a}]`}.\n${n}`)}}async uploadFiles(t,e,a){try{const n=a?"MAIN":"ISOLATED",i=await this.evaluate({world:n,func:t=>(window.transmittedFiles||(window.transmittedFiles=[]),window.transmittedFiles.push(t)-1),args:[e.map((({name:t},a)=>Object.assign({name:t},e[a].blob&&(e[a].blobUrl=URL.createObjectURL(e[a].blob))?{blobUrl:e[a].blobUrl}:{dataUrl:""})))]});for(let t=0;t<e.length;t++)if(e[t].dataUrl){let a=e[t].dataUrl.length,o=5242880,r=0;for(;r<a;)await this.evaluate({world:n,func:(t,e,a)=>{window.transmittedFiles[t][e].dataUrl+=a},args:[i,t,e[t].dataUrl.substr(r,o)]}),r+=o}await this.evaluate((async(t,e,a=-1,{scrollToElementBeforeAction:n,scrollIntoViewOptions:i})=>{const o=e?e.match(/^(\/|\.\/|\()/)?document.evaluate(e,document.documentElement,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue:document.querySelector(e):window.Self.elementCatcher.current?.elements[a];return!!o&&(n&&o.scrollIntoView(i),o.files=window.Self.filesToFileList(await Promise.all(window.transmittedFiles[t].map((async({blobUrl:t,dataUrl:e,name:a})=>t?window.Self.blobToFile(await window.Self.getBlob(t),a):window.Self.dataUrlToFile(e,a))))),window.Self.triggerEvent(o,"input"),window.Self.triggerEvent(o,"change"),delete window.transmittedFiles[t],0===window.transmittedFiles.filter(Boolean).length&&delete window.transmittedFiles,!0)}),[i,t,a,this.configurations],{world:n}),e.forEach((({blobUrl:t})=>URL.revokeObjectURL(t)))}catch(t){throw await this.handleGlitch(`Failed to upload files.\n${t}`)}}async screenshot({clip:t}){try{let e=await chrome.tabs.captureVisibleTab(this.windowId,{format:"png"});if(t){const{width:a,height:n,x:i,y:o}=t,r=await(0,s.cropImageOffscreen)(await(0,s.imageBitmapFromUrl)(e),a,n,i,o);e=await(0,s.blobToDataUrl)(await r.convertToBlob())}return e}catch(t){throw await this.handleGlitch(`Failed to take a screenshot.\n${t}`)}}elementCatcher={catch:async function(t){try{await this.evaluate({world:"MAIN",func:()=>window.Self?.exists()})||await this.evaluate({world:"MAIN",func:h.selfIntegration}),await this.evaluate({world:"MAIN",func:t=>window.Self.elementCatcher.catch(t),args:[t]})}catch(t){throw t}},terminate:async function(){try{await this.evaluate({world:"MAIN",func:()=>window.Self?.elementCatcher.terminate()})}catch(t){throw t}}};manualClick={enable:async function(){try{await this.evaluate((()=>window.Self.manualClick.enable()))}catch(t){throw t}},disable:async function(){try{await this.evaluate((()=>window.Self.manualClick.disable()))}catch(t){throw t}}}}},16:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.selfIntegration=void 0;const a=(t=!0)=>{const e={scrollToElementBeforeAction:!0,scrollIntoViewOptions:{behavior:"smooth",block:"center"}},a={tryLimit:30,delay:1e3,...e},n=async t=>new Promise((e=>setTimeout(e,t))),i=(t,e)=>{t.dispatchEvent(new Event(e,{bubbles:!0,cancelable:!0}))},o=(t,e)=>{t.tagName.match(/INPUT|TEXTAREA|SELECT/i)?t.value=e:t.innerHTML=e,i(t,"focus"),i(t,"keydown"),i(t,"keypress"),i(t,"keyup"),i(t,"input"),i(t,"change"),i(t,"blur")},r=t=>{t.focus(),"INPUT"!==t.tagName&&"TEXTAREA"!==t.tagName||t.select(),document.execCommand("paste")},l=t=>t.match(/^(\/|\.\/|\()/),s=(t,e=document,a=-1)=>-1===a?document.evaluate(t,e,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue:document.evaluate(t,e,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotItem(a),c=(t,e=document)=>{let a=[],n=document.evaluate(t,e,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);for(let t=0;t<n.snapshotLength;t++)a.push(n.snapshotItem(t));return a},h=(t,e=document,a=-1)=>-1===a?e.querySelector(t):e.querySelectorAll(t)[a],u=(t,e=document)=>Array.from(e.querySelectorAll(t)),d=(t,e=document,a=-1)=>l(t)?s(t,e,a):h(t,e,a),w={catch:t=>!w.current&&(w.current={originalFunc:document.createElement,elements:[],tagNames:t.map((t=>t.toUpperCase()))},document.createElement=function(){const t=w.current?.originalFunc.apply(this,arguments);return w.current?.tagNames.includes(t.tagName)&&w.current.elements.push(t),t},!0),terminate:()=>!!w.current&&(document.createElement=w.current.originalFunc,delete w.current,!0)},m={enable:()=>{m.current&&(m.current.element.remove(),delete m.current)},disable:()=>{m.current||(m.current={element:document.createElement("div")},m.current.element.style="width: 100%; height: 100%; position: fixed; top: 0; cursor: not-allowed; z-index: 12500; left: 0;",m.current.element.addEventListener("contextmenu",(t=>t.preventDefault())),document.body.appendChild(m.current.element))}},f=()=>location.href,g=async(t,e,i={})=>{let o,r=i.tryLimit||a.tryLimit,l=i.delay||a.delay;for(;!(o=await t(...e))&&r;)r--,await n(l);if(o)return o;throw new Error("Waiting timed out...")};class y{static elements=new Map;static getElement(t){let e=this.elements.get(t);if(e)return e;for(const a of t.split("→")){let[,t,n]=a.match(/(.+)⟮([0-9-]+)⟯$/);n=Number(n),e=d(t,e||document,n)}return e?(this.elements.size>50&&this.elements.delete(this.elements.keys().next().value),this.elements.set(t,e),e):void 0}static handleCall(t,e,a){const n=this.getElement(t);return a?n?.[e](...a):n?.[e]()}static handleGet(t,e){const a=this.getElement(t);return a?.[e]}static handleSet(t,e,a){this.getElement(t)[e]=a}}const b={exists:()=>!0,ElementActions:y,getElement:d,getElements:(t,e=document)=>l(t)?c(t,e):u(t,e),getElementBySelectors:h,getElementsBySelectors:u,getElementByXPath:s,getElementsByXPath:c,triggerEvent:i,triggerPaste:r,setValue:o,isXPath:l,filesToFileList:t=>{const e=new DataTransfer;for(const a of t)e.items.add(a);return e.files},getBlob:t=>new Promise((e=>{var a=new XMLHttpRequest;a.open("GET",t,!0),a.responseType="blob",a.onload=()=>e(a.response),a.send()})),dataUrlToFile:(t,e)=>{let[a,n]=t.split(",");a=a.match(/:(.*?);/)[1],n=atob(n);let i=n.length,o=new Uint8Array(i);for(;i--;)o[i]=n.charCodeAt(i);return new File([o],e,{type:a})},blobToFile:(t,e)=>new File([t],e,{type:t.type}),goto:t=>location.href=t,reload:()=>location.reload(),url:f,close:()=>globalThis.close(),zoom:t=>document.body.style.zoom=t,waitFor:g,waitForNavigation:async(t={})=>{const e=f();await g((async t=>f()!==t),[e],t)},waitForElement:async(t,e={},a=-1)=>{await g(l(t)?(t,e)=>!!s(t,document,e):(t,e)=>!!h(t,document,e),[t,a],e)},waitForElementMiss:async(t,e={},a=-1)=>{await g(l(t)?(t,e)=>!s(t,document,e):(t,e)=>!h(t,document,e),[t,a],e)},click:(t,a=-1,{scrollToElementBeforeAction:n,scrollIntoViewOptions:i}=e)=>{const o=d(t,document,a);return!!o&&(n&&o.scrollIntoView(i),o.click(),!0)},elementExists:(t,e=-1)=>!!d(t,document,e),execPasteTo:(t,a=-1,{scrollToElementBeforeAction:n,scrollIntoViewOptions:i}=e)=>{const o=d(t,document,a);return!!o&&(n&&o.scrollIntoView(i),r(o),!0)},input:(t,a,n=-1,{scrollToElementBeforeAction:i,scrollIntoViewOptions:r}=e)=>{const l=d(t,document,n);return!!l&&(i&&l.scrollIntoView(r),o(l,a),!0)},elementCatcher:w,manualClick:m};return t&&!window.Self?.exists?.()&&(window.Self=b),b};e.selfIntegration=a;const n=a(!1);e.default=n}},e={};return function a(n){var i=e[n];if(void 0!==i)return i.exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,a),o.exports}(869)})())); |
{ | ||
"name": "browser-automator", | ||
"version": "3.5.47", | ||
"version": "3.5.49", | ||
"description": "Puppeteer alternative for Chrome extensions. A module for Chrome extensions that functions similarly to Puppeteer.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
116225