berstend / puppeteer-extra

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

[Bug] `PuppeteerExtraPluginRecaptcha` error has no information and cannot be evaluated #740

Open markcellus opened 1 year ago

markcellus commented 1 year ago

Describe the bug

Currently, when using the puppeteer-extra-plugin-recaptcha package with throwOnError set to true and a PuppeteerExtraPluginRecaptcha error is thrown here, the argument passed to Error is an object. So the information on the error gets lost, leaving no way for consumer code to know about what caused the error.

It just outputs the following as a console warning:

PuppeteerExtraPluginRecaptcha: An error occured during "getRecaptchaSolutions": {
_vendor: 'recaptcha',
provider: '2captcha',
id: '[redacted]',
requestAt: 2021-05-09T01:35:25.450Z,
error: 'Error: 2captcha error: [redacted]'
}

...and the thrown error is an empty object, so it can't be evaluated:

try {
        let { captchas } = await page.findRecaptchas();
        if (!captchas.length) {
            return;
        }
        await page.solveRecaptchas();
    } catch (e) {
        console.log(e) // <== cannot evaluate this error because it has no information
    }
markcellus commented 1 year ago

I've opened https://github.com/berstend/puppeteer-extra/pull/741 to attempt to address. Open to any feedback! Thanks!