I am trying to solve a captcha on a page using Puppeteer. I have the captcha answer being properly solved and I am triggering the data-callback function for the captcha. In this case, it's handleCaptcha('ANSWER'). If I run this function in the developer console, it accepts the answer and moves to the next page. If I run it using page[0].evaluate(`handleCaptcha("${answer}")`); in puppeteer, it just refreshes the page.
Here is the code:
twoClient = new Client(global.twocaptchakey, {
timeout: 300000,
polling: 5000,
throwErrors: true
});
// This function takes between 10-300 seconds
const response = await twoClient.decodeRecaptchaV2({
googlekey: global.sitekey,
pageurl: page[0].url()
});
const answer = response._text;
console.log("Captcha Answer:");
console.log(answer);
//Here is the problem code
page[0].evaluate(`handleCaptcha("${answer}")`);
// page[0].evaluate(answer => {
// handleCaptcha(answer);
// }, answer)
//Make sure that no code running later interferes with this
await page[0].waitFor(10000);
This uses Infosimple's Node TwoCaptcha wrapper
I've tried both variations of evaluate() as shown above, single and double quotes, etc. The evaluate() function works fine (tested on alerts). When I run handleCaptcha('ANSWER');, in the console, I use the answer logged above, so I know that the two functions are running the same thing.
Here is the same bug popping up in a library. I noticed that in both cases, this is happening on a PerimeterX page. Is it possible for them to modify the behavior of Puppeteer?
In case you want it, here is the full code (mostly from ramsessalcedo/chegg-bot).