berstend / puppeteer-extra

💯 Teach puppeteer new tricks through plugins.
https://extra.community
MIT License
6.41k stars 739 forks source link

[Bug] Puppeteer-extra-plugin-recaptcha does not solve invisible hcapctha in headless true #814

Open marcosandrade22 opened 1 year ago

marcosandrade22 commented 1 year ago

Describe the bug

Plugin Stopped detecting hcaptcha on my site.

It was working normally, I can see the captcha. But the plugin cannot identify. stopped working about 15 to 20 days ago

Code Snippet erro_login

const RecaptchaPlugin = require('puppeteer-extra-plugin-recaptcha')

puppeteer.use( RecaptchaPlugin({ provider: { id: '2captcha', token: 'xxxx' // REPLACE THIS WITH YOUR OWN 2CAPTCHA API KEY ⚡ }, visualFeedback: true // colorize reCAPTCHAs (violet = detected, green = solved) }) ) puppeteer.launch({ headless: true, ignoreHTTPSErrors: true, args: ['--no-sandbox', '--disable-setuid-sandbox', '--incognito'], }).then(async function(browser) {

    const page = await browser.newPage()

await page.goto('https://www8.receita.fazenda.gov.br/SimplesNacional/Aplicacoes/ATSPO/pgmei.app/Identificacao') await page.solveRecaptchas()

Versions Captura de Tela 2023-06-13 às 16 04 42

"dependencies": { "cookie-parser": "~1.4.4", "debug": "~2.6.9", "ejs": "^3.1.9", "express": "^4.18.2", "file-system": "^2.2.2", "fs": "0.0.1-security", "http-errors": "~1.6.3", "jade": "~1.11.0", "morgan": "~1.9.1", "node-iframe": "^1.5.10", "puppeteer": "^10.4.0", "puppeteer-extra": "^3.3.6", "puppeteer-extra-plugin-recaptcha": "^3.6.8", "puppeteer-extra-plugin-stealth": "^2.11.2" }

dekelev commented 1 year ago

Not sure if it's related, but I just noticed an issue with mootools-core.js file that is being loaded in some websites, where the mootools script overrides the Array.from method and breaks its behavior when it gets called with a Set.

For example:

const array = [1, 1]
Array.from(new Set(array))

results in: [{1}] - First array item is a Set object

instead of: [1]

That breaks the detection of reCaptcha in the puppeteer-extra-plugin-recaptcha module, because it is calling: Array.from(new Set(results)) where results is an array of IFrame IDs.

The issue can be solved by replacing the Array.from(new Set(results)) call to [...new Set(results)] in the getIframesIds method.

marcosandrade22 commented 1 year ago

Thanks for the help, I changed the files: content.js index.esm.js index.cjs.js

Leaving it this way Array.from([new Set(results)]); but I'm still being blocked by the invisible captcha.

marcosandrade22 commented 1 year ago

I installed a local version of the app and ran it with headless: false and the invisible hcaptcha was resolved, the problem seems to be with headless: true. Locally, I have a graphical interface that allows me to show the browser, but on a production server without an interface, this option does not work.

divyesh-puri commented 8 months ago

I struggle with this too for few days, but finally able to figure out the solution for it. I am initializing the same way as its been done in docs but I have changed how I am writing await page.solveRecaptchas()

Here's my code

for (const frame of page.mainFrame().childFrames()) {
  // Attempt to solve any potential captchas in those frames
  const { captchas, filtered, solutions, solved, error } =
    await frame.solveRecaptchas();

  console.log(solved);
}

// logic to press "Next" btn or whatever the site presents if it doesn't navigate forward