Volck
Volck

Reputation: 374

How to log in to google account using Playwright or Puppeteer?

Could someone please help me, I need to log in to my google account using Puppeteer or Playwright. Is there a way to do it ?

Upvotes: 1

Views: 6098

Answers (1)

theDavidBarton
theDavidBarton

Reputation: 8851

Most of the cases Google prevents login for headless browsers/bots. You may see some similar message when you try it:

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.

You need to make sure that you are able to login with your script in "headful" mode by giving the credentials (with page.click and page.type like a real user would) and submitting the form.* If it works headful but you need it to work in headless mode then you can use puppeteer-extra package with puppeteer-extra-plugin-stealth. Examples can be get from puppeteer-extra docs. FYI: pptr-extra uses older puppeteer 2.x as its base, you may loose some functionalities even if it can be used together with the original puppeteer library.

*If there will be a need to handle two-factor authentication that makes the task more complex. You can be sure Google does its best to prevent bots from logging in.

+ You can test your puppeteer Chromium instance if it is detected as headless browser here: https://arh.antoinevastel.com/bots/areyouheadless

Upvotes: 0

Related Questions