kaliiiiiiiiii / Selenium-Profiles

undetected Selenium using chromedriver and emulation / device profiles
Other
273 stars 29 forks source link

Google Colab WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 1 #10

Closed kaliiiiiiiiii closed 1 year ago

kaliiiiiiiiii commented 1 year ago

Yust checked Selenium with chome using Selenium-Profiles with this script: https://colab.research.google.com/github/kaliiiiiiiiii/Selenium-Profiles/blob/master/google-colab/selenium_profiles.ipynb#scrollTo=P8P_90I2cZXq

And I can confirm, that it doesn't work anymore.

My error code was:

/usr/local/lib/python3.8/dist-packages/selenium_profiles/scripts/profiles.py:112: UserWarning: Might be more likely to get detected with sandbox set to False!
  warnings.warn('Might be more likely to get detected with sandbox set to False!')
---------------------------------------------------------------------------
WebDriverException                        Traceback (most recent call last)
<ipython-input-4-8dcbedddfdca> in <module>
      9 
     10 display.start_display()
---> 11 driver = mydriver.start(profiles.Windows(), uc_driver=False)  # or .Android

4 frames
/usr/local/lib/python3.8/dist-packages/selenium_profiles/driver.py in start(self, profile, uc_driver)
     82 
     83             # Actual start of chrome
---> 84             self.driver = webdriver.Chrome(options=self.options)  # start selenium webdriver
     85 
     86         self.driver.get('http://motherfuckingwebsite.com/')  # wait browser to start

/usr/local/lib/python3.8/dist-packages/selenium/webdriver/chrome/webdriver.py in __init__(self, executable_path, port, options, service_args, desired_capabilities, service_log_path, chrome_options, service, keep_alive)
     79             service = Service(executable_path, port, service_args, service_log_path)
     80 
---> 81         super().__init__(
     82             DesiredCapabilities.CHROME["browserName"],
     83             "goog",

/usr/local/lib/python3.8/dist-packages/selenium/webdriver/chromium/webdriver.py in __init__(self, browser_name, vendor_prefix, port, options, service_args, desired_capabilities, service_log_path, service, keep_alive)
    101 
    102         self.service = service
--> 103         self.service.start()
    104 
    105         try:

/usr/local/lib/python3.8/dist-packages/selenium/webdriver/common/service.py in start(self)
    104         count = 0
    105         while True:
--> 106             self.assert_process_still_running()
    107             if self.is_connectable():
    108                 break

/usr/local/lib/python3.8/dist-packages/selenium/webdriver/common/service.py in assert_process_still_running(self)
    117         return_code = self.process.poll()
    118         if return_code:
--> 119             raise WebDriverException(f"Service {self.path} unexpectedly exited. Status code was: {return_code}")
    120 
    121     def is_connectable(self) -> bool:

WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 1

Also, yesterday it still worked

kaliiiiiiiiii commented 1 year ago

https://stackoverflow.com/questions/75155063/selenium-use-chrome-on-colab-got-unexpectedly-exited

https://github.com/googlecolab/colabtools/issues/3347

kaliiiiiiiiii commented 1 year ago

Ubuntu 20.04+ no longer distributes chromium-browser outside of a snap package, you can install a compatible version from the Debian buster repository:

 %%shell
 # Ubuntu no longer distributes chromium-browser outside of snap
 #
 # Proposed solution: https://askubuntu.com/questions/1204571/how-to-install-chromium-without-snap

 # Add debian buster
 cat > /etc/apt/sources.list.d/debian.list <<'EOF'
 deb [arch=amd64 signed-by=/usr/share/keyrings/debian-buster.gpg] http://deb.debian.org/debian buster main
 deb [arch=amd64 signed-by=/usr/share/keyrings/debian-buster-updates.gpg] http://deb.debian.org/debian buster-updates main
 deb [arch=amd64 signed-by=/usr/share/keyrings/debian-security-buster.gpg] http://deb.debian.org/debian-security buster/updates main
 EOF

 # Add keys
 apt-key adv --keyserver keyserver.ubuntu.com --recv-keys DCC9EFBF77E11517
 apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 648ACFD622F3D138
 apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 112695A0E562B32A

 apt-key export 77E11517 | gpg --dearmour -o /usr/share/keyrings/debian-buster.gpg
 apt-key export 22F3D138 | gpg --dearmour -o /usr/share/keyrings/debian-buster-updates.gpg
 apt-key export E562B32A | gpg --dearmour -o /usr/share/keyrings/debian-security-buster.gpg

 # Prefer debian repo for chromium* packages only
 # Note the double-blank lines between entries
 cat > /etc/apt/preferences.d/chromium.pref << 'EOF'
 Package: *
 Pin: release a=eoan
 Pin-Priority: 500

 Package: *
 Pin: origin "deb.debian.org"
 Pin-Priority: 300

 Package: chromium*
 Pin: origin "deb.debian.org"
 Pin-Priority: 700
 EOF

 # Install chromium and chromium-driver
 apt-get update
 apt-get install chromium chromium-driver

 # Install selenium
 pip install selenium

Example script:

 from selenium import webdriver
 from selenium.webdriver.chrome.options import Options

 options = Options()
 options.add_argument("--headless") # or use pyvirtualdiplay
 options.add_argument("--no-sandbox") # needed, because colab runs as root

 options.headless = True

 driver = webdriver.Chrome("/usr/bin/chromedriver", options=options)

 driver.get("https://github.com/kaliiiiiiiiii/Selenium-Profiles")
 print(driver.title)
 driver.quit()

resource: https://github.com/googlecolab/colabtools/issues/3347#issuecomment-1387453484

See Google-Colab (file: google-colab/selenium_profiles.ipynb) for an example

kaliiiiiiiiii commented 1 year ago

Fixed with https://github.com/kaliiiiiiiiii/Selenium-Profiles/pull/30