Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to login to google account with playwright?

I have following source code and run it in headful mode. I can input email address. But, after that, there is message that saying "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.".

Do I need to set additional header or something else?

Here is my source code.

const playwright = require('playwright');
const cookiePath = '/home/ubuntu/.config/chromium/Default';
browser['chromium'] = await playwright['chromium'].launchPersistentContext(cookiePath,{
  headless: false,
  args: [
      `--disable-extensions-except=${pathToExtension}`,
      `--load-extension=${pathToExtension}`,
      ],
});
const page = await browser['chromium'].newPage();
const login_url = "https://accounts.google.com/signin/v2/identifier?hl=ja&flowName=GlifWebSignIn&flowEntry=ServiceLogin"; 
await page.goto(login_url);
await page.fill('#identifierId',userinfo['id']);
await page.click("#identifierNext");
await page.fill('[name=password]',userinfo['password']);
await page.click("#passwordNext");
like image 845
Leo S Avatar asked Dec 19 '25 12:12

Leo S


1 Answers

This works for me:
add --disable-blink-features=AutomationControlled to your args.

like image 79
Shuangcheng Ni Avatar answered Dec 21 '25 06:12

Shuangcheng Ni



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!