'Google: Couldn't Sign you in (the browser or app may be insecure) using selenium automation

So I have been trying to access my gmail or Google Colab Notebooks through selenium. Instead of authenticating through Email and Password I am starting the chromedriver with an already saved Google Chrome Profile, but it throws this:

enter image description here

I have tried every single solution that used to work before but it ain't working now, some of the solutions that I tried are:

  • Disabling Two Factor authentication
  • Allowing Less secure app access
  • Disabling every single flag that I know that lets websites detect that website is being controlled by a bot.
  • Trying to login using some other site's Google OAuth.
  • Trying different Viewports
  • The user agent is also the same that is used when logging in without selenium manually.
 options = Options()
 options.add_argument('--user-data-dir=/home/mubbashir/.config/google-chrome')
 options.add_argument('--profile-directory=Default')
 options.add_argument("--disable-blink-features")
 options.add_argument('--disable-web-security')
 options.add_argument('--allow-running-insecure-content')
 options.add_argument('--disable-blink-features=AutomationControlled')
 options.add_experimental_option("excludeSwitches", ["enable-automation"])
 options.add_experimental_option('useAutomationExtension', False)
 options.add_argument('--start-maximized')
 options.add_argument('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)  Chrome/89.0.4389.114 Safari/537.36')

Nothing works at all! I am kinda stuck and any help would be very much appreciated.

Thank you so much!



Solution 1:[1]

For anyone facing this, the easiest way is to use cookies.

Download Colab's Cookies for that particular account.

In selenium, add them to your webdriver first and then go to the notebook link.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mubbashir Ali