/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/puppeteer-extra-plugin-recaptcha-anti-captcha@1.0.4/dist/index.cjs.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
/*!
 * puppeteer-extra-plugin-recaptcha v3.6.7 by berstend
 * https://github.com/berstend/puppeteer-extra/tree/master/packages/puppeteer-extra-plugin-recaptcha
 * @license MIT
 */
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var puppeteerExtraPlugin=require("puppeteer-extra-plugin"),Debug=_interopDefault(require("debug"));const ac=require("@antiadmin/anticaptchaofficial"),ContentScriptDefaultOpts={visualFeedback:!0,debugBinding:void 0},ContentScriptDefaultData={solutions:[]};class RecaptchaContentScript{constructor(e=ContentScriptDefaultOpts,t=ContentScriptDefaultData){this.log=(e,t)=>{this.opts.debugBinding&&window.top[this.opts.debugBinding]&&window.top[this.opts.debugBinding](e,JSON.stringify(t))},this._pick=e=>t=>e.reduce(((e,r)=>Object.assign(Object.assign({},e),{[r]:t[r]})),{}),this._isVisible=e=>!!(e.offsetWidth||e.offsetHeight||"function"==typeof e.getClientRects&&e.getClientRects().length),void 0===globalThis.__name&&(globalThis.__defProp=Object.defineProperty,globalThis.__name=(e,t)=>globalThis.__defProp(e,"name",{value:t,configurable:!0})),this.opts=e,this.data=t,this.frameSources=this._generateFrameSources(),this.log("Intialized",{url:document.location.href,opts:this.opts})}_isInViewport(e){const t=e.getBoundingClientRect();return t.top>=0&&t.left>=0&&t.bottom<=(window.innerHeight||document.documentElement.clientHeight&&t.right<=(window.innerWidth||document.documentElement.clientWidth))}_flattenObject(e,t=2,r=!0){const i=e=>e&&"object"==typeof e,n=e=>e&&e instanceof HTMLElement;let s={};for(let a=0;a<t;a++)e=Object.keys(s).length?s:e,Object.keys(e).forEach((t=>{r&&n(e[t])||(i(e[t])?Object.keys(e[t]).forEach((a=>{if(r&&n(e[t][a]))return;const o=i(e[t][a])?`obj_${t}_${a}`:`${a}`;s[o]=e[t][a]})):s[t]=e[t])}));return s}_getKeyByValue(e,t){return Object.keys(e).find((r=>e[r]===t))}async _waitUntilDocumentReady(){return new Promise((function(e){if(!document||!window)return e(null);if(/^loaded|^i|^c/.test(document.readyState))return e(null);function t(){e(null),document.removeEventListener("DOMContentLoaded",t),window.removeEventListener("load",t)}document.addEventListener("DOMContentLoaded",t),window.addEventListener("load",t)}))}_paintCaptchaBusy(e){try{this.opts.visualFeedback&&(e.style.filter="opacity(60%) hue-rotate(400deg)")}catch(e){}return e}_paintCaptchaSolved(e){try{this.opts.visualFeedback&&(e.style.filter="opacity(60%) hue-rotate(230deg)")}catch(e){}return e}_findVisibleIframeNodes(){return Array.from(document.querySelectorAll(this.getFrameSelectorForId("anchor","")))}_findVisibleIframeNodeById(e){return document.querySelector(this.getFrameSelectorForId("anchor",e))}_hideChallengeWindowIfPresent(e=""){let t=document.querySelector(this.getFrameSelectorForId("bframe",e));if(this.log(" - _hideChallengeWindowIfPresent",{id:e,hasFrame:!!t}),t){for(;t&&t.parentElement&&t.parentElement!==document.body;)t=t.parentElement;t&&(t.style.visibility="hidden")}}_generateFrameSources(){const e=["google.com","www.google.com","recaptcha.net","www.recaptcha.net"],t=["http","https"].flatMap((t=>e.map((e=>`${t}://${e}`)))),r={anchor:["/recaptcha/api2/anchor","/recaptcha/enterprise/anchor"],bframe:["/recaptcha/api2/bframe","/recaptcha/enterprise/bframe"]};return{anchor:t.flatMap((e=>r.anchor.map((t=>`${e}${t}`)))),bframe:t.flatMap((e=>r.bframe.map((t=>`${e}${t}`))))}}getFrameSelectorForId(e="anchor",t=""){const r="anchor"===e?"a":"c";return this.frameSources[e].map((e=>`iframe[src^='${e}'][name^="${r}-${t}"]`)).join(",")}getClients(){if(window&&window.__google_recaptcha_client&&window.___grecaptcha_cfg&&window.___grecaptcha_cfg.clients&&Object.keys(window.___grecaptcha_cfg.clients).length)return window.___grecaptcha_cfg.clients}getVisibleIframesIds(){const e=this._findVisibleIframeNodes().filter((e=>this._isVisible(e))).map((e=>this._paintCaptchaBusy(e))).filter((e=>e&&e.getAttribute("name"))).map((e=>e.getAttribute("name")||"")).map((e=>e.split("-").slice(-1)[0])).filter((e=>e));return this.log("getVisibleIframesIds",e),e}getInvisibleIframesIds(){const e=this._findVisibleIframeNodes().filter((e=>e&&e.getAttribute("name"))).map((e=>e.getAttribute("name")||"")).map((e=>e.split("-").slice(-1)[0])).filter((e=>e)).filter((e=>document.querySelectorAll(this.getFrameSelectorForId("bframe",e)).length));return this.log("getInvisibleIframesIds",e),e}getIframesIds(){const e=[...this.getVisibleIframesIds(),...this.getInvisibleIframesIds()];this.log("getIframesIds",e);const t=Array.from(new Set(e));return this.log("getIframesIds - dedup",t),t}isEnterpriseCaptcha(e){if(!e)return!1;const t=[`[name^="a-${e}"]`,`[name^="c-${e}"]`].map((e=>'iframe[src*="/recaptcha/"][src*="/enterprise/"]'+e)).join(",");return document.querySelectorAll(t).length>0}isInvisible(e){if(!e)return!1;const t=`iframe[src*="/recaptcha/"][src*="/anchor"][name="a-${e}"][src*="&size=invisible"]`;return document.querySelectorAll(t).length>0}hasActiveChallengePopup(e){if(!e)return!1;const t=`iframe[src*="/recaptcha/"][src*="/bframe"][name="c-${e}"]`,r=document.querySelector(t);return!!r&&this._isInViewport(r)}hasChallengeFrame(e){return!!e&&document.querySelectorAll(this.getFrameSelectorForId("bframe",e)).length>0}isInViewport(e){if(!e)return;const t=[`[name^="a-${e}"]`,`[name^="c-${e}"]`].map((e=>'iframe[src*="recaptcha"]'+e)).join(","),r=document.querySelector(t);return!!r&&this._isInViewport(r)}getResponseInputById(e){if(!e)return;const t=this._findVisibleIframeNodeById(e);if(!t)return;const r=t.closest("form");return r?r.querySelector("[name='g-recaptcha-response']"):document&&document.body?document.body.querySelector("[name='g-recaptcha-response']"):void 0}getClientById(e){if(!e)return;const t=this.getClients();let r=Object.values(t||{}).filter((t=>this._getKeyByValue(t,e))).shift();if(this.log(" - getClientById:client",{id:e,hasClient:!!r}),r){try{r=this._flattenObject(r),r.widgetId=r.id,r.id=e,this.log(" - getClientById:client:flatten",{id:e,hasClient:!!r})}catch(e){this.log(" - getClientById:client ERROR",e.toString())}return r}}extractInfoFromClient(e){if(!e)return;const t=this._pick(["sitekey","callback"])(e);return t.sitekey?(t._vendor="recaptcha",t.id=e.id,t.s=e.s,t.widgetId=e.widgetId,t.display=this._pick(["size","top","left","width","height","theme"])(e),e&&e.action&&(t.action=e.action),t.callback&&"function"==typeof t.callback&&(t.callback=t.callback.name||"anonymous"),document&&document.location&&(t.url=document.location.href),t):void 0}async findRecaptchas(){const e={captchas:[],error:null};try{await this._waitUntilDocumentReady();const t=this.getClients();if(this.log("findRecaptchas",{url:document.location.href,hasClients:!!t}),!t)return e;e.captchas=this.getIframesIds().map((e=>this.getClientById(e))).map((e=>this.extractInfoFromClient(e))).map((e=>{if(this.log(" - captchas:info",e),!e)return;const t=this.getResponseInputById(e.id);return e.hasResponseElement=!!t,e})).filter((e=>!!e&&!!e.sitekey)).map((e=>(e.sitekey=e.sitekey.trim(),e.isEnterprise=this.isEnterpriseCaptcha(e.id),e.isInViewport=this.isInViewport(e.id),e.isInvisible=this.isInvisible(e.id),e._type="checkbox",e.isInvisible&&(e._type="invisible",e.hasActiveChallengePopup=this.hasActiveChallengePopup(e.id),e.hasChallengeFrame=this.hasChallengeFrame(e.id),e.hasChallengeFrame||(e._type="score")),e)))}catch(t){return e.error=t,e}return this.log("findRecaptchas - result",{captchaNum:e.captchas.length,result:e}),e}async enterRecaptchaSolutions(){const result={solved:[],error:null};try{await this._waitUntilDocumentReady();const clients=this.getClients();if(this.log("enterRecaptchaSolutions",{url:document.location.href,hasClients:!!clients,solutionNum:this.data.solutions.length}),!clients)return result.error="No recaptchas found",result;const solutions=this.data.solutions;if(!solutions||!solutions.length)return result.error="No solutions provided",result;result.solved=this.data.solutions.map((solution=>{const client=this.getClientById(solution.id);this.log(" - client",!!client);const solved={_vendor:"recaptcha",id:client.id,responseElement:!1,responseCallback:!1},$iframe=this._findVisibleIframeNodeById(solved.id);if(this.log(" - $iframe",!!$iframe),!$iframe)return solved.error=`Iframe not found for id '${solved.id}'`,solved;this.hasActiveChallengePopup(solved.id)&&this._hideChallengeWindowIfPresent(solved.id);const $input=this.getResponseInputById(solved.id);if(this.log(" - $input",!!$input),$input&&($input.innerHTML=solution.text,solved.responseElement=!0),this.log(" - callback",!!client.callback),client.callback)try{this.log(" - callback - type",{typeof:typeof client.callback,value:""+client.callback}),"function"==typeof client.callback?client.callback.call(window,solution.text):(eval(client.callback).call(window,solution.text),this.log(" - callback - aftereval")),solved.responseCallback=!0}catch(e){solved.error=e}return solved.isSolved=solved.responseCallback||solved.responseElement,solved.solvedAt=new Date,this._paintCaptchaSolved($iframe),this.log(" - solved",solved),solved}))}catch(e){return result.error=e,result}return this.log("enterRecaptchaSolutions - finished",result),result}}const ContentScriptDefaultOpts$1={visualFeedback:!0},ContentScriptDefaultData$1={solutions:[]};class HcaptchaContentScript{constructor(e=ContentScriptDefaultOpts$1,t=ContentScriptDefaultData$1){this.baseUrls=["assets.hcaptcha.com/captcha/v1/","newassets.hcaptcha.com/captcha/v1/"],void 0===globalThis.__name&&(globalThis.__defProp=Object.defineProperty,globalThis.__name=(e,t)=>globalThis.__defProp(e,"name",{value:t,configurable:!0})),this.opts=e,this.data=t}async _waitUntilDocumentReady(){return new Promise((function(e){if(!document||!window)return e(null);if(/^loaded|^i|^c/.test(document.readyState))return e(null);function t(){e(null),document.removeEventListener("DOMContentLoaded",t),window.removeEventListener("load",t)}document.addEventListener("DOMContentLoaded",t),window.addEventListener("load",t)}))}_paintCaptchaBusy(e){try{this.opts.visualFeedback&&(e.style.filter="opacity(60%) hue-rotate(400deg)")}catch(e){}return e}_findRegularCheckboxes(){const e=document.querySelectorAll(this.baseUrls.map((e=>`iframe[src*='${e}'][data-hcaptcha-widget-id]:not([src*='invisible'])`)).join(","));return Array.from(e)}_findActiveChallenges(){const e=document.querySelectorAll(this.baseUrls.map((e=>`div[style*='visible'] iframe[src*='${e}'][src*='hcaptcha.html']`)).join(","));return Array.from(e)}_extractInfoFromIframes(e){return e.map((e=>e.src.replace(".html#",".html?"))).map((e=>{const{searchParams:t}=new URL(e);return{_vendor:"hcaptcha",url:document.location.href,id:t.get("id"),sitekey:t.get("sitekey"),display:{size:t.get("size")||"normal"}}}))}async findRecaptchas(){const e={captchas:[],error:null};try{await this._waitUntilDocumentReady();const t=[...this._findRegularCheckboxes(),...this._findActiveChallenges()];if(!t.length)return e;e.captchas=this._extractInfoFromIframes(t),t.forEach((e=>{this._paintCaptchaBusy(e)}))}catch(t){return e.error=t,e}return e}async enterRecaptchaSolutions(){const e={solved:[],error:null};try{await this._waitUntilDocumentReady();const t=this.data.solutions;if(!t||!t.length)return e.error="No solutions provided",e;e.solved=t.filter((e=>"hcaptcha"===e._vendor)).filter((e=>!0===e.hasSolution)).map((e=>(window.postMessage(JSON.stringify({id:e.id,label:"challenge-closed",source:"hcaptcha",contents:{event:"challenge-passed",expiration:120,response:e.text}}),"*"),{_vendor:e._vendor,id:e.id,isSolved:!0,solvedAt:new Date})))}catch(t){return e.error=t,e}return e}}var https=require("https"),url=require("url"),querystring=require("querystring"),apiKey,apiInUrl="https://2captcha.com/in.php",apiResUrl="https://2captcha.com/res.php",SOFT_ID="4689",defaultOptions={pollingInterval:2e3,retries:3};function pollCaptcha(e,t,r,i){r=r.bind({options:t,captchaId:e});var n=setInterval((function(){var t=url.parse(apiResUrl+"?action=get&soft_id="+SOFT_ID+"&key="+apiKey+"&id="+e),s=https.request(t,(function(t){var s="";t.on("data",(function(e){s+=e})),t.on("end",(function(){if("CAPCHA_NOT_READY"!==s){clearInterval(n);var t=s.split("|");"OK"!==t[0]?i(t[0]):i(null,{id:e,text:t[1]},r),i=function(){}}}))}));s.on("error",(function(e){s.destroy(),i(e)})),s.end()}),t.pollingInterval||defaultOptions.pollingInterval)}const setApiKey=function(e){apiKey=e},decodeReCaptcha=function(e,t,r,i,n,s){s||(s=n,n=defaultOptions);var a=url.parse(apiInUrl);a.method="POST";var o=Object.assign({method:e,key:apiKey,soft_id:SOFT_ID,pageurl:r},i);"userrecaptcha"===e&&(o.googlekey=t),"hcaptcha"===e&&(o.sitekey=t),o=querystring.stringify(o);var c=https.request(a,(function(a){var o="";a.on("data",(function(e){o+=e})),a.on("end",(function(){var a=o.split("|");if("OK"!==a[0])return s(a[0]);pollCaptcha(a[1],n,(function(n){var a=s;if(report(this.captchaId),n)return a("CAPTCHA_FAILED");this.options.retries||(this.options.retries=defaultOptions.retries),this.options.retries>1?(this.options.retries=this.options.retries-1,decodeReCaptcha(e,t,r,i,this.options,s)):a("CAPTCHA_FAILED_TOO_MANY_TIMES")}),s)}))}));c.on("error",(function(e){c.destroy(),s(e)})),c.write(o),c.end()},report=function(e){var t=apiResUrl+"?action=reportbad&soft_id="+SOFT_ID+"&key="+apiKey+"&id="+e,r=url.parse(t);https.request(r,(function(e){})).end()},PROVIDER_ID="2captcha",debug=Debug(`puppeteer-extra-plugin:recaptcha:${PROVIDER_ID}`),secondsBetweenDates=(e,t)=>(t.getTime()-e.getTime())/1e3,providerOptsDefaults={useEnterpriseFlag:!1,useActionValue:!0};async function decodeRecaptchaAsync(e,t,r,i,n,s={pollingInterval:2e3}){return new Promise((a=>{const o=(e,t,r)=>a({err:e,result:t,invalid:r});try{setApiKey(e);let a="userrecaptcha";"hcaptcha"===t&&(a="hcaptcha"),decodeReCaptcha(a,r,i,n,s,o)}catch(e){return a({err:e})}}))}async function getSolutions(e=[],t="",r={}){r=Object.assign(Object.assign({},providerOptsDefaults),r);const i=await Promise.all(e.map((e=>getSolution(e,t,r))));return{solutions:i,error:i.find((e=>!!e.error))}}async function getSolution(e,t,r){const i={_vendor:e._vendor,provider:PROVIDER_ID};try{if(!(e&&e.sitekey&&e.url&&e.id))throw new Error("Missing data in captcha");i.id=e.id,i.requestAt=new Date,debug("Requesting solution..",i);const n={};e.s&&(n["data-s"]=e.s),r.useActionValue&&e.action&&(n.action=e.action),r.useEnterpriseFlag&&e.isEnterprise&&(n.enterprise=1),process.env["2CAPTCHA_PROXY_TYPE"]&&process.env["2CAPTCHA_PROXY_ADDRESS"]&&(n.proxytype=process.env["2CAPTCHA_PROXY_TYPE"].toUpperCase(),n.proxy=process.env["2CAPTCHA_PROXY_ADDRESS"]);const{err:s,result:a,invalid:o}=await decodeRecaptchaAsync(t,e._vendor,e.sitekey,e.url,n);if(debug("Got response",{err:s,result:a,invalid:o}),s)throw new Error(`${PROVIDER_ID} error: ${s}`);if(!a||!a.text||!a.id)throw new Error(`${PROVIDER_ID} error: Missing response data: ${a}`);i.providerCaptchaId=a.id,i.text=a.text,i.responseAt=new Date,i.hasSolution=!!i.text,i.duration=secondsBetweenDates(i.requestAt,i.responseAt)}catch(e){debug("Error",e),i.error=e.toString()}return i}const BuiltinSolutionProviders=[{id:PROVIDER_ID,fn:getSolutions}];class PuppeteerExtraPluginRecaptcha extends puppeteerExtraPlugin.PuppeteerExtraPlugin{constructor(e){super(e),this.debugBindingName="___pepr_cs",this.debug("Initialized",this.opts),this.contentScriptDebug=this.debug.extend("cs")}get name(){return"recaptcha"}get defaults(){return{visualFeedback:!0,throwOnError:!1,solveInViewportOnly:!1,solveScoreBased:!1,solveInactiveChallenges:!1}}get opts(){return super.opts}get contentScriptOpts(){const{visualFeedback:e}=this.opts;return{visualFeedback:e,debugBinding:this.contentScriptDebug.enabled?this.debugBindingName:void 0}}_generateContentScript(e,t,r){this.debug("_generateContentScript",e,t,r);let i=RecaptchaContentScript.toString(),n="RecaptchaContentScript";return"hcaptcha"===e&&(i=HcaptchaContentScript.toString(),n="HcaptchaContentScript"),i=i.replace(/class \{/,`class ${n} {`),`(async() => {\n      const DATA = ${JSON.stringify(r||null)}\n      const OPTS = ${JSON.stringify(this.contentScriptOpts)}\n\n      ${i}\n      const script = new ${n}(OPTS, DATA)\n      return script.${t}()\n    })()`}_filterRecaptchas(e=[]){const t=e.map((e=>("invisible"!==e._type||e.hasActiveChallengePopup||this.opts.solveInactiveChallenges||(e.filtered=!0,e.filteredReason="solveInactiveChallenges"),"score"!==e._type||this.opts.solveScoreBased||(e.filtered=!0,e.filteredReason="solveScoreBased"),"checkbox"===e._type&&!e.isInViewport&&this.opts.solveInViewportOnly&&(e.filtered=!0,e.filteredReason="solveInViewportOnly"),e.filtered&&this.debug("Filtered out captcha based on provided options",{id:e.id,reason:e.filteredReason,captcha:e}),e)));return{captchas:t.filter((e=>!e.filtered)),filtered:t.filter((e=>e.filtered))}}async findRecaptchas(e){this.debug("findRecaptchas");const t=await e.$('script[src*="/recaptcha/api.js"], script[src*="/recaptcha/enterprise.js"]');this.debug("hasRecaptchaScriptTag",!!t),t&&(this.debug("waitForRecaptchaClient - start",new Date),await e.waitForFunction("\n        (function() {\n          return Object.keys((window.___grecaptcha_cfg || {}).clients || {}).length\n        })()\n      ",{polling:200,timeout:1e4}).catch(this.debug),this.debug("waitForRecaptchaClient - end",new Date));const r=await e.$('script[src*="hcaptcha.com/1/api.js"]');this.debug("hasHcaptchaScriptTag",!!r),r&&(this.debug("wait:hasHcaptchaScriptTag - start",new Date),await e.waitForFunction("\n        (function() {\n          return window.hcaptcha\n        })()\n      ",{polling:200,timeout:1e4}),this.debug("wait:hasHcaptchaScriptTag - end",new Date));const i=(e,t)=>{this.contentScriptDebug(e,t)};this.contentScriptDebug.enabled&&"exposeFunction"in e&&await e.exposeFunction(this.debugBindingName,i);const n=await e.evaluate(this._generateContentScript("recaptcha","findRecaptchas")),s=await e.evaluate(this._generateContentScript("hcaptcha","findRecaptchas")),a=this._filterRecaptchas(n.captchas);this.debug(`Filter results: ${a.filtered.length} of ${a.captchas.length} captchas filtered from results.`);const o={captchas:[...a.captchas,...s.captchas],filtered:a.filtered,error:n.error||s.error};if(this.debug("findRecaptchas",o),this.opts.throwOnError&&o.error)throw new Error(o.error);return o}async solvedAntigate(e){const t=ac.settings.taskId,r={rqdata:"rqdata from target website",sentry:!0},i=new Date,n=e._vendor;let s;if("hcaptcha"===n)s=await ac.solveHCaptchaProxyless(e.url,e.sitekey,"",r,false,false);else if("score"===e._type){const t=e?.action?e.action:"";this.debug("ACTION",t),s=await ac.solveRecaptchaV3(e.url,e.sitekey,.7,t)}else s=e.isEnterprise?await ac.solveRecaptchaV2EnterpriseProxyless(e.url,e.sitekey,{s:e.s}):await ac.solveRecaptchaV2Proxyless(e.url,e.sitekey,e.isInvisible);const a=new Date;this.debug("CAPTCHA",s);return{_vendor:n,provider:"antigate",id:e.id,requestAt:i,providerCaptchaId:t,text:s,responseAt:a,hasSolution:!0,duration:secondsBetweenDates(i,a)}}async getRecaptchaSolutions(e,t){if(this.debug("getRecaptchaSolutions",{captchaNum:e.length}),!(t=t||this.opts.provider)||!t.token&&!t.fn||t.token&&"XXXXXXX"===t.token&&!t.fn)throw new Error("Please provide a solution provider to the plugin.");if(this.debug("PROVIDER",t.id),this.debug("PROVIDER",e),"antigate"===t.id){const r={solutions:[],error:void 0};ac.setAPIKey(t.token),ac.shutUp(),ac.setSoftId(1193),this.debug("TOKEN",t.token),this.debug("CAPTCHA",e);for(let t=0;t<e.length;t++)r.solutions.push(this.solvedAntigate(e[t]));return r.solutions=await Promise.all(r.solutions),this.debug("SOLUTION",r),r}{let r=t.fn;if(!r){const e=BuiltinSolutionProviders.find((e=>e.id===(t||{}).id));if(!e||!e.fn)throw new Error(`Cannot find builtin provider with id '${t.id}'.`);r=e.fn}const i=await r.call(this,e,t.token,t.opts||{});if(i.error=i.error||i.solutions.find((e=>!!e.error)),this.debug("getRecaptchaSolutions",i),i&&i.error&&console.warn('PuppeteerExtraPluginRecaptcha: An error occured during "getRecaptchaSolutions":',i.error),this.opts.throwOnError&&i.error)throw new Error(i.error);return this.debug("RESPONSE",i),i}}async enterRecaptchaSolutions(e,t){this.debug("enterRecaptchaSolutions",{solutions:t});const r=!!t.find((e=>"recaptcha"===e._vendor))?await e.evaluate(this._generateContentScript("recaptcha","enterRecaptchaSolutions",{solutions:t})):{solved:[]},i=!!t.find((e=>"hcaptcha"===e._vendor))?await e.evaluate(this._generateContentScript("hcaptcha","enterRecaptchaSolutions",{solutions:t})):{solved:[]},n={solved:[...r.solved,...i.solved],error:r.error||i.error};if(n.error=n.error||n.solved.find((e=>!!e.error)),this.debug("enterRecaptchaSolutions",n),this.opts.throwOnError&&n.error)throw new Error(n.error);return n}async solveRecaptchas(e){this.debug("solveRecaptchas");const t={captchas:[],filtered:[],solutions:[],solved:[],error:null};try{const{captchas:r,filtered:i,error:n}=await this.findRecaptchas(e);if(t.captchas=r,t.filtered=i,r.length){const{solutions:r,error:i}=await this.getRecaptchaSolutions(t.captchas);t.solutions=r;const{solved:s,error:a}=await this.enterRecaptchaSolutions(e,t.solutions);t.solved=s,t.error=n||i||a}}catch(e){t.error=e.toString()}if(this.debug("solveRecaptchas",t),this.opts.throwOnError&&t.error)throw new Error(t.error);return t}_addCustomMethods(e){e.findRecaptchas=async()=>this.findRecaptchas(e),e.getRecaptchaSolutions=async(e,t)=>this.getRecaptchaSolutions(e,t),e.enterRecaptchaSolutions=async t=>this.enterRecaptchaSolutions(e,t),e.solveRecaptchas=async()=>this.solveRecaptchas(e)}async onPageCreated(e){this.debug("onPageCreated",e.url()),await e.setBypassCSP(!0),this._addCustomMethods(e),e.on("frameattached",(e=>{e&&this._addCustomMethods(e)}))}async onBrowser(e){const t=await e.pages();for(const e of t){this._addCustomMethods(e);for(const t of e.mainFrame().childFrames())this._addCustomMethods(t)}}}const defaultExport=e=>new PuppeteerExtraPluginRecaptcha(e||{});exports.BuiltinSolutionProviders=BuiltinSolutionProviders,exports.PuppeteerExtraPluginRecaptcha=PuppeteerExtraPluginRecaptcha,exports.default=defaultExport,module.exports=exports.default||{},Object.entries(exports).forEach((([e,t])=>{module.exports[e]=t}));
//# sourceMappingURL=/sm/d3821dd7cd17c1aa7cbce4360981c5af4dc77f3f05cf09471d5aa8f1e620f1fe.map