berstend / puppeteer-extra

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

[Bug] puppeteer-extra-plugin-stealth causes ReCaptcha v2s to reload until it gives an error #655

Closed tacohitbox closed 2 years ago

tacohitbox commented 2 years ago

Describe the bug

I was using a combination of puppeteer-extra-plugin-stealth and puppeteer-extra-plugin-recaptcha on sites with CAPTCHAs on them until I started to notice an issue where the CAPTCHA was reloading before the CAPTCHA was solved, until an error was given (The CAPTCHA would either say "Cannot reconnect to ReCAPTCHA" or the app would crash.)

This is an example of what I'm talking about.

const pup = require("puppeteer-extra");
const stl = require("puppeteer-extra-plugin-stealth");
const cap = require("puppeteer-extra-plugin-recaptcha");

(async function() {
  pup.use(stl);
  pup.use(cap({
    provider: {
      id: "2captcha",
      token: "[redacted]"
    }
  }));

  let b = await pup.launch({headless: false});
  let p = await b.newPage();

  await p.goto("https://google.com/recaptcha/api2/demo");
  await p.solveRecaptchas();
  await p.click("#recaptcha-demo-submit");
})();

However, I found a workaround for other people who have a similar issue, simply disable the "iframe.contentWindow" evasion before launching your browser.

An example of this code would be this:

const pup = require("puppeteer-extra");
const stlh = require("puppeteer-extra-plugin-stealth");
const cap = require("puppeteer-extra-plugin-recaptcha");

(async function() {
  let stl = stlh();
  stl.enabledEvasions.delete("iframe.contentWindow")
  console.log(stl.enabledEvasions);
  pup.use(stl);
  pup.use(cap({
    provider: {
      id: "2captcha",
      token: "[redacted]"
    }
  }));

  let b = await pup.launch({headless: false});
  let p = await b.newPage();

  await p.goto("https://google.com/recaptcha/api2/demo");
  await p.solveRecaptchas();
  await p.click("#recaptcha-demo-submit");
})();

I still reported this issue, as the evasion is probably not functioning as intended.

Versions

 System:
    OS: Linux 5.18 Arch Linux
    CPU: (12) x64 AMD Ryzen 5 2600 Six-Core Processor
    Memory: 15.02 GB / 31.30 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 18.3.0 - /usr/bin/node
    npm: 8.10.0 - /usr/bin/npm
  npmPackages:
    puppeteer: ^13.5.2 => 13.7.0 
    puppeteer-extra: ^3.2.3 => 3.3.0 
    puppeteer-extra-plugin-adblocker: ^2.12.0 => 2.13.0 
    puppeteer-extra-plugin-recaptcha: ^3.5.0 => 3.6.0 
    puppeteer-extra-plugin-stealth: ^2.9.0 => 2.10.0 
berstend commented 2 years ago

Mhm, we just updated the iframe.contentWindow evasion in the latest stealth release to actually make it break less things :-/ Will test if this is a regression tomorrow

berstend commented 2 years ago

Can't confirm 🤔

image

Your first code snippet has a typo, should be pup.use(stl())

const pup = require("puppeteer-extra");
const stl = require("puppeteer-extra-plugin-stealth");
const cap = require("puppeteer-extra-plugin-recaptcha");

(async function() {
  pup.use(stl());
  pup.use(cap({
    provider: {
      id: "2captcha",
      token: process.env.TWOCAPTCHA_KEY
    }
  }));

  let b = await pup.launch({headless: false});
  let p = await b.newPage();

  await p.goto("https://google.com/recaptcha/api2/demo");
  await p.solveRecaptchas();
  await p.click("#recaptcha-demo-submit");
})();
  Binaries:
    Node: 16.15.0 - ~/.nvm-intel/versions/node/v16.15.0/bin/node
    Yarn: 1.22.19 - ~/.nvm-intel/versions/node/v16.15.0/bin/yarn
    npm: 8.5.5 - ~/.nvm-intel/versions/node/v16.15.0/bin/npm
  npmPackages:
    puppeteer: ^14.4.1 => 14.4.1 
    puppeteer-extra: ^3.3.0 => 3.3.0 
    puppeteer-extra-plugin-adblocker: ^2.13.0 => 2.13.0 
    puppeteer-extra-plugin-recaptcha: ^3.6.0 => 3.6.0 
    puppeteer-extra-plugin-stealth: ^2.10.0 => 2.10.0 
berstend commented 2 years ago

Can confirm with hcaptcha:

const puppeteer = require("puppeteer-extra")
const stealth = require("puppeteer-extra-plugin-stealth")()
stealth.enabledEvasions.delete("iframe.contentWindow")
puppeteer.use(stealth)

;(async function () {
  const browser = await puppeteer.launch({ headless: false })
  const page = await browser.newPage()
  await page.goto("https://democaptcha.com/demo-form-eng/hcaptcha.html")
  // then click on checkbox and see challenge popup
})()

This is connected to #565 - I'll probably roll that back until we had time for a better fix

berstend commented 2 years ago

We've reverted the captcha iframe breaking changes in #657

Successfully published:
 - puppeteer-extra-plugin-stealth@2.10.1

Closing this for now :)

tacohitbox commented 2 years ago

Thanks!