"Couldn't sign you in" Google account login fails in headless mode in Google Cloud Functions
See original GitHub issueHi 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.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:18
- Comments:21
Top GitHub Comments
Hey. I was able to solve the problem!
I am running my script on Digital Ocean Droplet with Ubuntu 18
I followed this instruction https://github.com/berstend/puppeteer-extra/tree/master/packages/puppeteer-extra-plugin-stealth
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.
I installed chrome instance via command line
Launch browser with chrome-launcher package
Code example
Good luck! 😃
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 😃