aw1875 / puppeteer-hcaptcha

A library to solve hcaptcha challenges that are automated within puppeteer. You can automatically set response values where they should be so the only thing left for you is submitting the page or you can get the response token.
https://www.npmjs.com/package/puppeteer-hcaptcha
138 stars 38 forks source link

Error during hCaptcha post-solve token set call - selector g-recaptcha-response not found #19

Closed straxus closed 2 years ago

straxus commented 3 years ago

I'm seeing the following error being thrown from within the hCaptcha code during an attempt to solve a CloudFlare hCaptcha:

Error: Evaluation failed: TypeError: Cannot set property 'value' of null
    at <anonymous>:3:67
    at ExecutionContext._evaluateInternal (/.../node_modules/puppeteer-core/lib/cjs/puppeteer/common/ExecutionContext.js:218:19)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async ExecutionContext.evaluate (/.../node_modules/puppeteer-core/lib/cjs/puppeteer/common/ExecutionContext.js:107:16)
    at async hcaptcha (/.../node_modules/puppeteer-hcaptcha/hcaptcha.js:254:3)
    at async [calling code]

Looking at hcaptcha.js, I see that this is the function which appears to be failing:

  await page.evaluate((token) => {
    document.querySelector('[name="h-captcha-response"]').value = token;
    document.querySelector('[name="g-recaptcha-response"]').value = token;
  }, token)

This implies that it completed the captcha solving process but then blew up afterwards because one of these fields was not present - when I debugged this, I found that g-recaptcha-response was not guaranteed to be present in the page and once I removed that set, everything worked as expected.

landaida commented 3 years ago

I tested many many times and the hcaptcha never solved for me

awxlfy commented 3 years ago

I believe hCaptcha has changed something major as I've been seeing that a bunch of the solvers are not working now. I'm a little busy with work right now but I will try to take a deep dive look at it soon and see if I can reverse whatever change they made and fix this issue.

awxlfy commented 3 years ago

@straxus @landaida I have a potential fix but not sure if its the actual fix since I don't have time to test. If you guys want to try it out let me know and I can let you know what to do

landaida commented 3 years ago

Hi @aw1875 I have time to test, thanks

landaida commented 3 years ago

Hi @aw1875 check my improvements, now I get tokens but the site that I tried to scrap doesn't accept this token as a good token

hcaptcha.js

jairoxyz commented 3 years ago

They have new asset url https://newassets.hcaptcha.com/c/420b6d0a/hsl.js. Although the code is the same, maybe it plays a role in the header. Also, together with answers and mousemovements they are sending back browser footprint. Maybe it's needed for correct token generation.

return-true-if-false commented 2 years ago

I heard that they also use a callback function to encrypt the token, though I'm not sure how true this information is (and it might be only on cloudflare sites) (2captcha blog post)

aw1875 commented 2 years ago

Hi everyone! I was busy with school but have updated the NPM package as well as this repo to dynamically get the version needed for the assets. This should solve any issues that were present but please let me know if you still encounter an issue.

aw1875 commented 2 years ago

I'm seeing the following error being thrown from within the hCaptcha code during an attempt to solve a CloudFlare hCaptcha:

Error: Evaluation failed: TypeError: Cannot set property 'value' of null
    at <anonymous>:3:67
    at ExecutionContext._evaluateInternal (/.../node_modules/puppeteer-core/lib/cjs/puppeteer/common/ExecutionContext.js:218:19)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async ExecutionContext.evaluate (/.../node_modules/puppeteer-core/lib/cjs/puppeteer/common/ExecutionContext.js:107:16)
    at async hcaptcha (/.../node_modules/puppeteer-hcaptcha/hcaptcha.js:254:3)
    at async [calling code]

Looking at hcaptcha.js, I see that this is the function which appears to be failing:

  await page.evaluate((token) => {
    document.querySelector('[name="h-captcha-response"]').value = token;
    document.querySelector('[name="g-recaptcha-response"]').value = token;
  }, token)

This implies that it completed the captcha solving process but then blew up afterwards because one of these fields was not present - when I debugged this, I found that g-recaptcha-response was not guaranteed to be present in the page and once I removed that set, everything worked as expected.

Also, as for this. It seems hCaptcha had removed this part of the solution a while ago and I just hadn't updated the files yet. Should be all fixed in the most recent version.

aw1875 commented 2 years ago

I will be closing this issue due to inactivity. If anyone has any other issues feel free to open a new one so I can look into it!