Puppeteer bypass recaptcha and fetch all cookies in headless mode

2.6k Views Asked by At
const puppeteer = require('puppeteer');
(async () => {
    const browser = await puppeteer.launch({args: ['--no-sandbox']});
    const page = await browser.newPage();

    try {
        await page.goto('https://www.allabout*****.org', {waitUntil: 'networkidle2'}); // 59 second - load - domcontentloaded - networkidle2
        const cookies = await page._client.send('Network.getAllCookies');
        JSON.stringify(cookies, null, 4);

    } catch (e) {

    }
    await browser.close();
})();

Tried above code to fetch all cookies but it only takes cookies before accepting captcha. After accepting captcha also, it sets cookies, that are not getting in the cookie list. How can I escape captcha using puppeteer in headless mode ( headless: true)?

Tried different independent node modules, puppeteer helpers, nothing worked.

1

There are 1 best solutions below

7
Naimur Rahman On

I just tried your code and realized that you used {waitUntil: "load"}. I just replaced that with {waitUntil: "networkidle2"} and removed the timeout(still used headless:true) and it showed me the CookieScriptConsent on cookie list.