Skip to content

login into gmail fails for unknown reason

I am trying to login into my gmail with puppeteer to lower the risk of recaptcha

here is my code

    await page.goto('', {timeout: 60000})
        .catch(function (error) {
            throw new Error('TimeoutBrows');
    await page.waitForSelector('#identifierId' , { visible: true });
    await page.type('#identifierId' , 'myemail');
    await Promise.all(['#identifierNext') ,
        page.waitForSelector('.whsOnd' , { visible: true })
    await page.type('#password .whsOnd' ,  "mypassword");
    await  page.waitFor(5000);

but i always end up with this message

enter image description here

I even tried to just open the login window with puppeteer and fill the login form manually myself, but even that failed.

Am I missing something ?

When I look into console there is a failed ajax call just after login.

Request URL:
Request Method: POST
Status Code: 401
Remote Address:
Referrer Policy: no-referrer-when-downgrade


I’ve inspected your code and it seems to be correct despite of some selectors. Also, I had to add a couple of timeouts in order to make it work. However, I failed to reproduce your issue so I’ll just post the code that worked for me.

const puppeteer = require('puppeteer');
(async () => {
    const browser = await puppeteer.launch({headless: false});
    const page = await browser.newPage();
    await page.goto('', {timeout: 60000})
        .catch(function (error) {
            throw new Error('TimeoutBrows');
    await page.screenshot({path: './1.png'});

Please, note that I run browser in normal, not headless mode. If you take a look at screenshot at this position, you will see that it is correct Google login form Google login form after the first step

The rest of the code is responsible for entering password

const puppeteer = require('puppeteer');
(async () => {
    await page.waitForSelector('#identifierId', {visible: true});
    await page.type('#identifierId', 'my@email');
    await Promise.all(['#identifierNext'),
        page.waitForSelector('.whsOnd', {visible: true})
    await page.waitForSelector('input[name=password]', {visible: true});
    await page.type('input[name=password]', "my.password");
    await page.waitForSelector('#passwordNext', {visible: true});
    await page.waitFor(1000);
    await page.waitFor(5000);

Please also note few differences from your code – the selector for password field is different. I had to add await page.waitForSelector('#passwordNext', {visible: true}); and a small timeout after that so the button could be clicked successfully.

I’ve tested all the code above and it worked successfully. Please, let me know if you still need some help or facing troubles with my example.