title: Unable to sign into google with selenium automation because of "This browser or app may not be secure."
body: <p>I am trying to login to google with selenium and I keep getting the error that &quot;This browser or app may not be secure.&quot;</p>
  <p>The function I use to log in is:</p>
  <pre><code>async function loginToChrome(driver, username, password) {
    await driver.get(&quot;https://accounts.google.com/signin&quot;);
    await driver.sleep(1000);
    let email_phone = await driver.findElement(
      By.xpath(&quot;//input[@id='identifierId']&quot;)
    );
    await email_phone.sendKeys(username);
    await driver.findElement(By.id(&quot;identifierNext&quot;)).click();
    await driver.sleep(1000);
  
    let passEl = await driver.findElement(By.xpath(&quot;//input[@name='password']&quot;));
    await passEl.sendKeys(password);
    await driver.findElement(By.id(&quot;passwordNext&quot;)).click();
    await driver.sleep(1000);
  }
  </code></pre>
  <p>It is the same problem as
  <a href="https://stackoverflow.com/questions/59433453/unable-to-log-into-google-account-in-selenium-chrome-driver">https://stackoverflow.com/questions/59433453/unable-to-log-into-google-account-in-selenium-chrome-driver</a>
  and
  <a href="https://stackoverflow.com/questions/59276975/couldnt-sign-you-in-this-browser-or-app-may-be-insecure-python-selenium-chrome">https://stackoverflow.com/questions/59276975/couldnt-sign-you-in-this-browser-or-app-may-be-insecure-python-selenium-chrome</a></p>
  <p>I have tried using both the chrome and firefox web drivers and both don't work.
  I have also tried doing <code>.excludeSwitches(['enable-automation'])</code> which also didn't help.</p>
  <p>This made me think that maybe the sign-in page could detect that I was running in an automated environment.
  I tried this solution that would hide that the app is running in a web driver: <a href="https://stackoverflow.com/questions/33225947/can-a-website-detect-when-you-are-using-selenium-with-chromedriver">Can a website detect when you are using selenium with chromedriver?</a></p>
  <p>I have also looked into the <code>User-Agent</code> to see if that was the problem but what I have found is that it is identical to my regular chrome one.</p>
  <p>All of this has not worked which makes leaves me stuck. I have seen solutions that say to use an already created user profile from your normal installation of chrome, but this wouldn't work for my use case.</p>
  <p>Has anyone found the solution to this? I have been searching for hours and have come up empty-handed.</p>
  <p><strong>EDIT:</strong>
  It seems like this has been getting a lot of attention recently. I found a solution that allowed me to continue to use an automated client without having too many problems. Switching to Puppeteer.
  Look into these packages:</p>
  <pre><code>    &quot;puppeteer&quot;,
      &quot;puppeteer-extra&quot;,
      &quot;puppeteer-extra-plugin-stealth&quot;
  </code></pre>
  <p>EDIT 2:
  I have seen this get a lot of attention recently. I found the code that I ended up using to login. I used puppeteer instead of selenium to do this</p>
  <pre><code>async function login(
    page: Page,
    username: string,
    password: string,
    backup: string
  ) {
    await page.goto(&quot;https://accounts.google.com/&quot;);
  
    await page.waitForNavigation();
  
    await page.waitForSelector('input[type=&quot;email&quot;]');
    await page.click('input[type=&quot;email&quot;]');
  
    await page.waitForNavigation();
  
    //TODO : change to your email
    await page.type('input[type=&quot;email&quot;]', username);
    await page.waitForSelector(&quot;#identifierNext&quot;);
    await page.click(&quot;#identifierNext&quot;);
  
    await page.waitFor(1000);
  
    await page.waitForSelector('input[type=&quot;password&quot;]');
    await page.click('input[type=&quot;password&quot;]');
    await page.waitFor(500);
    //TODO : change to your password
    await page.type('input[type=&quot;password&quot;]', password);
  
    await page.waitForSelector(&quot;#passwordNext&quot;);
    await page.click(&quot;#passwordNext&quot;);
    await page.waitForNavigation();
  }
  </code></pre>