question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Couldn't sign you in" Google account login fails in headless mode in Google Cloud Functions

See original GitHub issue

Hi everyone,

I’m trying to make a script that would login to Medium to export article’s stats. Medium allows Google authentication so I’m using that. It runs without any issue on my laptop (MacOS) but I get the message (attached to this issue) that I couldn’t sign in when run in Google Cloud Functions. Basically this login failure message appears after the screen where you enter your username.

  • Puppeteer version: 1.18.1 (also tested with 1.19.0, same result)
  • Platform / OS version: Google Cloud Functions
  • Node.js version: 8

What steps will reproduce the problem?

I deployed the code below to Google Cloud Functions.

exports.exportMediumStats = (req, res) => {
  const puppeteer = require('puppeteer');
  const url = "https://medium.com/m/signin?redirect=https%3A%2F%2Fmedium.com%2F&operation=login";
  let image;

  // Main function that will scrap Medium stats page using puppeteer
  async function main() {
    const browser = await puppeteer.launch({
      headless: true,
      args: ['--no-sandbox', '--disable-setuid-sandbox'],
    });
    const page = await browser.newPage();
    await page.goto(url, { waitUntil: "networkidle2" });
    console.log('Clicking on google login...');
    await page.click('.button--withChrome.button--large');
    await page.mainFrame().waitForSelector('#identifierId');
    console.log('Typing email...');
    await page.type('#identifierId', process.env.MEDIUM_USERNAME);
    await page.mainFrame().waitForSelector('#identifierNext');
    console.log('Clicking next button...');
    await page.click('#identifierNext');
    await page.waitFor(3000);
    image = await page.screenshot(); 

    console.log('Closing browser...');
    await browser.close();
  }

  main()
  .then(url => {
    res.setHeader("content-type", "image/jpeg");
    res.status(200).send(image);
  })
  .catch(err => {
    console.error(err);
    res.status(500).send("An Error occured" + err);  
  })
};

What is the expected result? I should get the screen where I would type my password. I works perfectly on my local machine in both non-headless and headless modes. Also it used to work on Google Cloud Functions at the beginning but it doesn’t for some time now.

What happens instead? The login fails with a message displayed in the attached picture below. The failure message is:

Couldn't sign you in
For your protection, you can't sign in from this device.
Try again later, or sign in from another device.

couldnt_sign_in

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:18
  • Comments:21

github_iconTop GitHub Comments

11reactions
VladymyrPylypchatincommented, Nov 5, 2019

Hey. I was able to solve the problem!

I am running my script on Digital Ocean Droplet with Ubuntu 18

  1. I followed this instruction https://github.com/berstend/puppeteer-extra/tree/master/packages/puppeteer-extra-plugin-stealth

  2. Then I installed xvfb https://www.npmjs.com/package/xvfb to run puppeteer in headfull mode

Then the most important. Without these steps, Google will still block you.

  1. I installed chrome instance via command line

  2. Launch browser with chrome-launcher package

Code example


        const puppeteer = require("puppeteer-extra")
        const pluginStealth = require("puppeteer-extra-plugin-stealth")
        puppeteer.use(pluginStealth())
        const chromeLauncher = require('chrome-launcher');
        const axios = require('axios');
        const Xvfb = require('xvfb');

        const xvfb = new Xvfb();
        xvfb.startSync();
        const chromeConfig = {
                chromePath: "/usr/bin/google-chrome-stable"
        }

        const chrome = await chromeLauncher.launch(chromeConfig);
        const response = await axios.get(`http://localhost:${chrome.port}/json/version`);
        const { webSocketDebuggerUrl } = response.data;
        const browser = await puppeteer.connect({ browserWSEndpoint: webSocketDebuggerUrl });
        
        //log in into google account....

Good luck! 😃

8reactions
VladymyrPylypchatincommented, Oct 7, 2019

Hi! I have got the same problem. I run puppeteer in the non-headless mode and also implemented the recommendation from this article https://intoli.com/blog/making-chrome-headless-undetectable/ After all the steps, I still receive this message.

Is anyone have a solution to this problem? I would really appreciate any help.

Have a nice day 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't sign in to the Admin console - Cloud Identity Help
Option 1: Sign in with an Incognito window ... Select New Incognito Window. In the Incognito window's address field, enter admin.google.com and press...
Read more >
Playwright - "Verify it's you" message only for chromium, while ...
When Google determines that a user is logging in from an unknown device or a new location, they may prompt the user with...
Read more >
Troubleshooting Cloud Functions - Google Cloud
Runtime service account missing project bucket permissions while deploying a function. Cloud Functions can only be triggered by events from Cloud Storage ...
Read more >
How to fix Couldn't sign you in Google Account chrome
When i try to sign into google account chrome says ' Couldn't sign you in'. The browser you 're using doesn't support JavaScript, ......
Read more >
Using Puppeteer in Google Cloud Functions - Romin Irani's Blog
Ever since I heard the term headless Chrome, I have been curious about what that exactly means and the kind of applications that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found