0

I got problem with my script where I am logging in to site. I am using puppeteer-extra-plugin-stealth to prevent headless detection.

The code works fine when running with headless: false. I manage to log in to the page and the page redirects me to the home page.

But in headless: true It goes through the same process but after clicking the login button the site tries to redirect me to the main page, but the site then acts like I'm not logged in.

In both cases, login cookies are stored in the browser.

I could find any solution so far.

My code:

const puppeteer = require('puppeteer-extra')
const {executablePath} = require('puppeteer')
const StealthPlugin = require('puppeteer-extra-plugin-stealth')
puppeteer.use(StealthPlugin())

const browser = await puppeteer.launch({
        "headless": true,
        "ignoreHTTPSErrors": true,
        "executablePath" = executablePath()
      });
const page = await browser.newPage();

await page.goto(url, {
        waitUntil: "networkidle0",
      });

await page.waitForSelector("x");
await page.click("x");

await page.waitForSelector("x");
await page.type("x", username);
await page.click("x");

await page.waitForSelector("x");
await page.waitForFunction(() => {
        const input = document.querySelector("x");
        return input && input.offsetWidth > 0 && input.offsetHeight > 0;
      });
await page.type("x", password);
await page.click("x");

console.log(await page.cookies())
Sunderam Dubey
  • 1
  • 11
  • 20
  • 40

0 Answers0