“This browser or app may not be secure” error while attempting to login in to Gmail account using GeckoDriver Firefox through Selenium and Python “This browser or app may not be secure” error while attempting to login in to Gmail account using GeckoDriver Firefox through Selenium and Python selenium selenium

“This browser or app may not be secure” error while attempting to login in to Gmail account using GeckoDriver Firefox through Selenium and Python


This Google Support page states that sign in via browsers that "Use automation testing frameworks" is being disabled for the following security reasons and Google advices to do "Sign in with Google" using browser-based OAuth 2.0 authentication service.

As some websites, like stackoverflow.com allow you to sign in to their services using "Sign in with Google" it must happen via Google OAuth 2.0 authentication. This implicates that doing so you are also indirectly signing in to your Google account and therefore you can use all the Google services.

So you can fully automatically sign in to your Google account, e.g. by using a Python script, by performing these actions in your code:

  1. Open a new browser window that is controlled by selenium webdriver
  2. In the same window load the StackOverflow login page (or any other site that uses "Sign in with Google")
  3. Choose for "Log in with Google"
  4. Provide your Google account credentials and login to StackOverflow
  5. Load the Google mailbox by opening https://mail.google.com/ or https://www.gmail.com/

This way you land down in your Gmail mailbox without performing any manual actions.

Please remember to add some 5s delays between different actions as doing it too quickly or too frequently can be recognized by StackOverflow as malicious automated actions and you can get blocked and you will need to make the manual I'm not a robot verification


I can't login google with selenium or headless-chromium-php,but we can login google with chrome first, and find the "Profile Path" in "chrome://version/", for example my profile path is "/home/diyism/.config/google-chrome/Profile 2", then I copy it into "/home/diyism/.config/google-chrome/selenium-profiles/default", and run headless-chromium-php:

$factory = new \HeadlessChromium\BrowserFactory('/opt/google/chrome/chrome');$browser = $factory->createBrowser([        'headless' => false,        'keepAlive' => true,        'userDataDir'=>'/home/diyism/.config/google-chrome/selenium-profiles'    ]);$page = $browser->createPage();$page->navigate('https://mail.google.com')->waitForNavigation();$pageTitle = $page->evaluate('document.title')->getReturnValue();sleep(20);$page->screenshot()->saveToFile('gmail.inbox.list.png');

Now I can see my gmail inbox list in gmail.inbox.list.png.


I haven't really solved this but there is a workaround. If just logging in is your sole purpose then this might not be useful for you but if you wanna perform further operations and logging in using google is getting in your way then:

  • You can manually login in your chrome browser.

  • Use your default chrome profile to launch chrome.

  • To find path to your chrome profile data you need to type chrome://version/ in your address bar .

      options = webdriver.ChromeOptions()  options.add_argument("user-data-dir=<Path to your chrome profile>")  chrome_driver_path = "C:/Users/..."  driver = webdriver.Chrome(executable_path=chrome_driver_path, chrome_options=options)
  • This would skip your login steps