I am using puppeteer to perform some action and to take screen shots. The entire process has multiple authentication, first Gmail login, then the SSO redirects to Microsoft and from them we get into the application. The problem that i am facing is, when i set my browser - headless : false, everything works fine, but when i set my headless: true, the Gmail started asking for captcha and some time it says, the browser is not safe.
I have been trying to sort this out for quite some time and i am completely blinded. I have read throug the internet and found lot of options like seting up useragent, adding preference etc, but non of them are working.
Here is my simple code and with the screen shots.
// puppeteer-extra is a drop-in replacement for puppeteer,
// it augments the installed puppeteer with plugin functionality
const puppeteer = require('puppeteer-extra');
//puppeteer.use(require('puppeteer-extra-plugin-stealth')());
// add stealth plugin and use defaults (all evasion techniques)
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
console.log(StealthPlugin.availableEvasions);
puppeteer.use(StealthPlugin());
//const RecaptchaPlugin = require('puppeteer-extra-plugin-recaptcha')
//const puppeteer = require('puppeteer')
// puppeteer usage as normal
puppeteer.launch({ headless: true, executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', setUserAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.61 Safari/537.36' }).then(async browser => {
console.log('Running tests..')
const page = await browser.newPage()
//await page.setUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.61 Safari/537.36')
await page.goto('https://accounts.google.com/signin/v2/identifier?service=mail&passive=1209600&osid=1&continue=https%3A%2F%2Fmail.google.com%2Fmail%2Fu%2F0%2F&followup=https%3A%2F%2Fmail.google.com%2Fmail%2Fu%2F0%2F&emr=1&flowName=GlifWebSignIn&flowEntry=ServiceLogin')
await page.waitForTimeout(5000)
await page.setViewport({ width: 1300, height: 950 });
await page.waitForTimeout(1000)
await page.screenshot({path: '1.png', fullPage: true})
await page.waitForSelector('[type="email"]')
await page.type('[type="email"]', 'nxxxx@xxxx.com');
await page.keyboard.press('Enter');
await page.waitForTimeout(1000);
//await page.solveRecaptchas()
//await page.waitForNavigation({'waitUntil':'domcontentloaded'});
await page.screenshot({path: '2.png', fullPage: true})
await page.screenshot({ path: 'testresult.png', fullPage: true })
await browser.close()
console.log(`All done, check the screenshot. ✨`)
})
I have updated only a part of my code, but still, the result is the same, unless i bypass the detection , i am unable to move forward. please find the screen shot attached.
All i wanted is to b pass this stage and go to the next screen.....
Please help.... :(