diff --git a/src/component/CaptchaComp.js b/src/component/CaptchaComp.js index 932237f..f8aff65 100644 --- a/src/component/CaptchaComp.js +++ b/src/component/CaptchaComp.js @@ -67,12 +67,16 @@ class CaptchaComp { return fetch(this.getUrl(params), this.getParams()).then(res => res.json()) } + getSiteKey(src) { + let keys = ['k', 'sitekey'] + let q = url.parse(src, true).query + keys = keys.map(key => q[key]).filter(k => k) + return keys.length ? keys[0] : logger.throwError('Googlekey not found', { src: src }) + } + requestResolve(driver) { return driver.findElement(By.css('#hcaptcha iframe')).getAttribute('src') - .then(src => { - let googlekey = url.parse(src, true).query.k - if (!googlekey) logger.throwError('Googlekey not found', { src: src }) - }) + .then(src => this.getSiteKey(src)) .then(googlekey => { return driver.getCurrentUrl().then(pageurl => { return this.request({ googlekey: googlekey, pageurl: pageurl }).then(res => { @@ -95,7 +99,7 @@ class CaptchaComp { while (res.request == 'CAPCHA_NOT_READY') { logger.info('Retry get recap answer in %d senconds', this.api.retryTimeout / 1000) await this.sleep(this.api.retryTimeout) - retryLimit = retryLimit - 1 + retryLimit = retryLimit - 1 res = await this.request({ id: id }) if (retryLimit == 0) break }