puppeteer-extra icon indicating copy to clipboard operation
puppeteer-extra copied to clipboard

[Bug] Does not detect captcha on Yahoo log in page

Open harvard1932 opened this issue 3 years ago • 5 comments

Using both, still will not solve captcha on the page: await page.waitForTimeout(1900); await page.solveRecaptchas() for (const frame of page.mainFrame().childFrames()) { // Attempt to solve any potential reCAPTCHAs in those frames await frame.solveRecaptchas() }

And yahoo uses recaptcha in frame, which still does not work.

harvard1932 avatar Dec 15 '20 00:12 harvard1932

@harvard1932 can you paste debug logs here (mentioned in the readme)?

Also it'd be helpful if you provide a demo link and screenshots of the recaptcha iframe in the DOM.

berstend avatar Jan 13 '21 15:01 berstend

I have some similar issue when getting a Page element from a Target:

export async function setupPage() {
  browser = await puppeteer.connect({
    browserURL: 'http://localhost:5858',
  });

  const targets = await browser.targets();
  const target = targets.find(t => t.url() === 'https://some_url.com');
  page = await target.page();
}

--> on the page object retrieved from the target there is no captcha related functions attached and calling the function findRecaptchas() results in an error: TypeError: _page__WEBPACK_IMPORTED_MODULE_3__.page.findRecaptchas is not a function

When using instead directly a page of a browser everything works fine

export async function setupPage() {
  browser = await puppeteer.connect({
    browserURL: 'http://localhost:5858',
  });

  const pages = await browser.pages();
  page = pages[0];
}

In some cases you cannot use the simple browser.pages() solution because this does not give you any iframes/webviews from the site you want to attach to. So it would be nice if the captcha resolve functions would also be accessible on the Page elements retrieved from a Target.

zartinn avatar Jan 13 '21 20:01 zartinn

I found a workaround by looking into your source code:

I created a reference of The RecaptchaPlugin and then called the findRecaptchas() method directly on the plugin object and provided the page as parameter:

export const plugin: PuppeteerExtraPluginRecaptcha = RecaptchaPlugin({
    provider: {
      id: 'xxx',
      token: 'xxx',
    },
    visualFeedback: true,
  });
puppeteer.use(plugin)

// ....later in the code when having the final page with captcha ready:

let { captchas, error } = await plugin.findRecaptchas(page);

So it works also with the pages from a target object. Maybe you can assign the functions also to these type of pages and it should work out of the box.

zartinn avatar Jan 13 '21 21:01 zartinn

@zartinn thanks for digging into this! 💪

It looks like your intent is to use the recaptcha plugin on existing pages, which is supported with a workaround.

I'm in the middle of releasing the new playwright supporting rewrite of the extra framework, including an updated recaptcha plugin with improved documentation that explains how to do that: https://github.com/berstend/puppeteer-extra/tree/automation-extra/packages/plugin-recaptcha#solving-captchas-in-pre-existing-browser-pages

Warning: This links to the new automation-extra branch, which isn't released yet, the documentation regarding existing pages still applies to the current recaptcha plugin version as well though:

image

berstend avatar Jan 14 '21 14:01 berstend

Ah, apologies - seems like you were aware of that workaround already and your comments were specific to supporting browser.targets() as well. Good that you find a workaround now, I'll be looking into supporting this use case natively.

berstend avatar Jan 14 '21 14:01 berstend