Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Bug] await page.solveRecaptchas() stopped working a couple of weeks ago with TimeoutError: Waiting failed: 10000ms exceeded #895

Open
ivictbor opened this issue Jun 13, 2024 · 2 comments
Labels
issue: bug report A bug has been reported needs triage

Comments

@ivictbor
Copy link

I was using puppeteer-extra-plugin-recaptcha with 2captcha for a several monthes, and some time ago it stopped working, I did not make any changes in project. Now I enabled logs and saw next:

puppeteer-extra-plugin:recaptcha onPageCreated about:blank +0ms
🔑 doing login

  puppeteer-extra-plugin:recaptcha solveRecaptchas +0ms
  puppeteer-extra-plugin:recaptcha findRecaptchas +0ms
  puppeteer-extra-plugin:recaptcha hasRecaptchaScriptTag true +0ms
  puppeteer-extra-plugin:recaptcha waitForRecaptchaClient - start 2024-06-13T09:02:20.516Z +0ms
  puppeteer-extra-plugin:recaptcha TimeoutError: Waiting failed: 10000ms exceeded
  puppeteer-extra-plugin:recaptcha     at new WaitTask (/home/ivan/code/xx/xxx/node_modules/puppeteer-core/lib/cjs/puppeteer/common/WaitTask.js:50:34)
  puppeteer-extra-plugin:recaptcha     at IsolatedWorld.waitForFunction (/home/ivan/code/xxx/yyyy/node_modules/puppeteer-core/lib/cjs/puppeteer/api/Realm.js:25:26)
  puppeteer-extra-plugin:recaptcha     at CdpFrame.waitForFunction (/home/ivan/code/xxx/yyyy/node_modules/puppeteer-core/lib/cjs/puppeteer/api/Frame.js:504:43)
  puppeteer-extra-plugin:recaptcha     at CdpFrame.<anonymous> (/home/ivan/code/xxx/yyyy/node_modules/puppeteer-core/lib/cjs/puppeteer/util/decorators.js:98:27)
  puppeteer-extra-plugin:recaptcha     at CdpPage.waitForFunction (/home/ivan/code/xxx/yyyy/node_modules/puppeteer-core/lib/cjs/puppeteer/api/Page.js:1375:37)
  puppeteer-extra-plugin:recaptcha     at PuppeteerExtraPluginRecaptcha.findRecaptchas (/home/ivan/code/xxx/yyyy/node_modules/puppeteer-extra-plugin-recaptcha/dist/index.cjs.js:983:18)
  puppeteer-extra-plugin:recaptcha     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
  puppeteer-extra-plugin:recaptcha     at async PuppeteerExtraPluginRecaptcha.solveRecaptchas (/home/ivan/code/xxx/yyyy/node_modules/puppeteer-extra-plugin-recaptcha/dist/index.cjs.js:1092:66)
  puppeteer-extra-plugin:recaptcha     at async holder.doLogin (/home/ivan/code/xxx/yyyy/index.js:134:5)
  puppeteer-extra-plugin:recaptcha     at async init (/home/ivan/code/xxx/yyyy/index.js:278:7) +0ms
  puppeteer-extra-plugin:recaptcha waitForRecaptchaClient - end 2024-06-13T09:02:30.520Z +0ms
  puppeteer-extra-plugin:recaptcha hasHcaptchaScriptTag false +0ms
  puppeteer-extra-plugin:recaptcha _generateContentScript recaptcha findRecaptchas undefined +0ms
  puppeteer-extra-plugin:recaptcha:cs Intialized {"url":"https://www.xxx.com//account-security/#","opts":{"visualFeedback":true,"debugBinding":"___pepr_cs"}} +0ms
  puppeteer-extra-plugin:recaptcha:cs findRecaptchas {"url":"https://www.xxx.com//account-security/#","hasClients":false} +2ms
  puppeteer-extra-plugin:recaptcha _generateContentScript hcaptcha findRecaptchas undefined +0ms
  puppeteer-extra-plugin:recaptcha Filter results: 0 of 0 captchas filtered from results. +0ms
  puppeteer-extra-plugin:recaptcha findRecaptchas { captchas: [], filtered: [], error: null } +0ms
  puppeteer-extra-plugin:recaptcha solveRecaptchas { captchas: [], filtered: [], solutions: [], solved: [], error: null } +0ms
  puppeteer-extra-plugin:recaptcha solveRecaptchas +0ms
  puppeteer-extra-plugin:recaptcha findRecaptchas +0ms
  puppeteer-extra-plugin:recaptcha hasRecaptchaScriptTag false +0ms
  puppeteer-extra-plugin:recaptcha hasHcaptchaScriptTag false +0ms

On a screenshot I see cloudflare captcha

@ivictbor ivictbor added issue: bug report A bug has been reported needs triage labels Jun 13, 2024
@LessThanGreaterThan
Copy link

so if i understand this correctly, you see on the page cloudflare turnstile, and are confused why recaptcha doesn't work ?

@olobarius
Copy link

olobarius commented Sep 4, 2024

I assume you are using the rebrowser puppeteer runtime leak patches in alwaysIsolated mode.
Somewhere it reads that page.waitForFunction will not work in this case.
But node_modules/puppeteer-extra-plugin-recaptcha/dist/index.js is using page.waitForFunction as a convenience to wait for captchas to be fully loaded.
You can fix your problem by commenting out the waitForFunction block and make sure (by manually waiting a bit) that captchas are fully loaded.

   async findRecaptchas(page) {
        this.debug('findRecaptchas');
        // As this might be called very early while recaptcha is still loading
        // we add some extra waiting logic for developer convenience.
        const hasRecaptchaScriptTag = await page.$(`script[src*="/recaptcha/api.js"], script[src*="/recaptcha/enterprise.js"]`);
        this.debug('hasRecaptchaScriptTag', !!hasRecaptchaScriptTag);
        /*
        if (hasRecaptchaScriptTag) {
            this.debug('waitForRecaptchaClient - start', new Date());
            await page
                .waitForFunction(`
        (function() {
          return Object.keys((window.___grecaptcha_cfg || {}).clients || {}).length
        })()
      `, { polling: 200, timeout: 10 * 1000 })
                .catch(this.debug);
            this.debug('waitForRecaptchaClient - end', new Date()); // used as timer
        }
        */
        const hasHcaptchaScriptTag = await page.$(`script[src*="hcaptcha.com/1/api.js"]`);
        this.debug('hasHcaptchaScriptTag', !!hasHcaptchaScriptTag);
        /*
        if (hasHcaptchaScriptTag) {
            this.debug('wait:hasHcaptchaScriptTag - start', new Date());
            await page.waitForFunction(`
        (function() {
          return window.hcaptcha
        })()
      `, { polling: 200, timeout: 10 * 1000 });
            this.debug('wait:hasHcaptchaScriptTag - end', new Date()); // used as timer
        }
        */
        const onDebugBindingCalled = (message, data) => {
            this.contentScriptDebug(message, data);
        };

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
issue: bug report A bug has been reported needs triage
Projects
None yet
Development

No branches or pull requests

3 participants