为什么 Puppeteer-Extra 的 solveRecaptchas() "not a function"?

Why is Puppeteer-Extra's solveRecaptchas() "not a function"?

我正在尝试使用 Puppeteer 和 puppeteer-extra-plugin-recaptcha through Apify 来解决登录页面上的 Recaptcha。

我会及时进行完全登录。现在,我正在尝试使用 Google 的演示来做 Recaptcha 解决方案。 puppeteer-extra-plugin-recaptcha 通过 API 键点击 2captcha 服务来解决问题。

不幸的是,在我的代码中,重要的 solveRecaptchas() 抛出错误:

TypeError: page.solveRecaptchas is not a function

完整错误:

2021-10-17T10:04:54.502Z ERROR PuppeteerCrawler: handleRequestFunction failed, reclaiming failed request back to the list or queue {"url":"https://www.google.com/recaptcha/api2/demo","retryCount":1,"id":"ylMuptksDTSkKJl"}
2021-10-17T10:04:54.504Z   TypeError: page.solveRecaptchas is not a function
2021-10-17T10:04:54.505Z       at PuppeteerCrawler.handlePageFunction (/home/myuser/main.js:85:28)
2021-10-17T10:04:54.507Z       at PuppeteerCrawler._handleRequestFunction (/home/myuser/node_modules/apify/build/crawlers/browser_crawler.js:324:52)
2021-10-17T10:04:54.509Z       at processTicksAndRejections (node:internal/process/task_queues:96:5)
2021-10-17T10:04:54.511Z       at async PuppeteerCrawler._runTaskFunction (/home/myuser/node_modules/apify/build/crawlers/basic_crawler.js:431:13)
2021-10-17T10:04:54.513Z       at async AutoscaledPool._maybeRunTask (/home/myuser/node_modules/apify/build/autoscaling/autoscaled_pool.js:408:17)

我的代码:

/**************************************/
/*          Setup requires            */
/**************************************/
const Apify = require("apify");
const puppeteer = require("puppeteer-extra");
const PuppeteerExtraPluginRecaptcha = require("puppeteer-extra-plugin-recaptcha");
const StealthPlugin = require("puppeteer-extra-plugin-stealth");
// puppeteer.use(StealthPlugin()); // Should this be used?



/**************************************/
/*          Use Recaptcha             */
/**************************************/
function addPlugins() {
  const captchaOptions = {
    provider: {
      id: "2captcha",
      token: "my-2captcha-api-key",
    },
    solveInactiveChallenges: true,
    visualFeedback: true,
  };
  puppeteer.use(PuppeteerExtraPluginRecaptcha(captchaOptions));
}



/**************************************/
/*           Through Apify?           */
/**************************************/
Apify.main(
    async () => {

    /**************************************/
    /*             Cue up URL             */
    /**************************************/
    // Is this what to do and where to do it?
    // cf. https://reposhub.com/nodejs/http/apifytech-apify-js.html
    const requestQueue = await Apify.openRequestQueue();
    await requestQueue.addRequest(
        {
            url: "https://www.google.com/recaptcha/api2/demo",
        }
    );
    // const pseudoUrls = [new Apify.PseudoUrl('https://www.iana.org/[.*]')];


    /**************************************/
    /*         Puppeteer Crawler          */
    /**************************************/
    const crawler = new Apify.PuppeteerCrawler(
        {
            requestQueue,
            launchContext: {
            launcher: puppeteer,
            launchOptions: {
                devtools: false,
                headless: false,
                ignoreHTTPSErrors: true,
                defaultViewport: { width: 1366, height: 768 },
                timeout: 60 * 1000,
                args: [
                "--no-sandbox",
                "--disable-web-security",
                "--disable-setuid-sandbox",
                "--disable-features=IsolateOrigins,site-per-process",
                "--flag-switches-begin --disable-site-isolation-trials --flag-switches-end",
                ],
            },
        },
        handlePageFunction: async ({ request, page }) => {

            // ...some code
            // Should URL be enqueued here, not above?
           
            // solve captcha (if one exists)
            await page.solveRecaptchas(); // https://github.com/berstend/puppeteer-extra/issues/184
            
            // additional code

        },
    });

    await crawler.run();

    }
);

我了解到的可能原因包括:

这可能是您提供的示例中的一个遗漏,但您似乎没有在任何地方调用 addPlugins() 函数,因此根本没有使用该插件。