Việt Cường
Việt Cường

Reputation: 41

Undetected chromedriver keeps crashing on Replit?

On Replit normal selenium works fine but undetected chromedriver (the python library) doesn't seem to work, here's my code:

import undetected_chromedriver as uc
driver = uc.Chrome()
driver.get('https://google.com')

I keep getting this error:

Traceback (most recent call last):
  File "main.py", line 4, in <module>
    driver = uc.Chrome()
  File "/home/runner/fff/venv/lib/python3.8/site-packages/undetected_chromedriver/__init__.py", line 401, in __init__
    super(Chrome, self).__init__(
  File "/home/runner/fff/venv/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
    super().__init__(DesiredCapabilities.CHROME['browserName'], "goog",
  File "/home/runner/fff/venv/lib/python3.8/site-packages/selenium/webdriver/chromium/webdriver.py", line 89, in __init__
    self.service.start()
  File "/home/runner/fff/venv/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 98, in start
    self.assert_process_still_running()
  File "/home/runner/fff/venv/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 110, in assert_process_still_running
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: Service /home/runner/.local/share/undetected_chromedriver/9366826a81e09122_chromedriver unexpectedly exited. Status code was: 127

Does anyone know how to fix it? Please help, thanks so much!

Upvotes: 4

Views: 852

Answers (2)

Jediweirdo
Jediweirdo

Reputation: 37

This was happening to me, but I found a way to fix it well enough to run. Essentially, Replit's chromium-browser and the chromedriver used by undetected_chromedriver are different versions. So, you'll have to manually assign it a chromedriver to use. Here's how:

  1. Open up the replit shell and put in chromedriver --help. If you get prompted about the command not being installed, say yes. After it's done running, it should return something like this:
/nix/store/n4qcnqy0isnvxcpcgv6i2z9ql9wsxksw-chromedriver-114.0.5735.90
Usage: /nix/store/n4qcnqy0isnvxcpcgv6i2z9ql9wsxksw-chromedriver-114.0.5735.90/bin/chromedriver [OPTIONS]

Options
[insert a list of commands here]

Copy the directory labeled as "Usage" using ctrl+shift+c or via the right click menu (Replit copy/paste can be weird sometimes)

  1. Any file in the nix directory needs permission in order to be accessed via a program. So, before you leave the shell, run chmod 777 path/to/chromedriver
  2. Going back to your code, you need to add an argument when you initialize uc. Copy/paste the following into your code:
import undetected_chromedriver as uc
driver = uc.Chrome(headless=True,use_subprocess=False, driver_executable_path = "path/to/chromedriver")

Upvotes: 1

Hikmet23
Hikmet23

Reputation: 1

import undetected_chromedriver as uc
if __name__ == '__main__':
    driver = uc.Chrome(subprocess = True)
    driver.maximize_window()

There is nothing wrong with your code.You just have to use subprocess when you create driver.

Upvotes: -1

Related Questions