ultrafunkamsterdam / undetected-chromedriver

Custom Selenium Chromedriver | Zero-Config | Passes ALL bot mitigation systems (like Distil / Imperva/ Datadadome / CloudFlare IUAM)
https://github.com/UltrafunkAmsterdam/undetected-chromedriver
GNU General Public License v3.0
9.64k stars 1.14k forks source link

Error Chrome 118 #1605

Open ggnetoo opened 11 months ago

ggnetoo commented 11 months ago

Tried update Webdriver + Selenium too, but the error persists after update Chrome to version 118.

Patch Chrome: /root/.wdm/drivers/chromedriver/linux64/118.0.5993.70/chromedriver-linux64/chromedriver

driver = webdriver.Chrome(driver_executable_path=ChromeDriverManager().install(), options=chrome_options, enable_cdp_events=True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/undetected_chromedriver/__init__.py", line 469, in __init__
    super(Chrome, self).__init__(
  File "/usr/local/lib/python3.11/dist-packages/selenium/webdriver/chrome/webdriver.py", line 45, in __init__
    super().__init__(
  File "/usr/local/lib/python3.11/dist-packages/selenium/webdriver/chromium/webdriver.py", line 56, in __init__
    super().__init__(
  File "/usr/local/lib/python3.11/dist-packages/selenium/webdriver/remote/webdriver.py", line 205, in __init__
    self.start_session(capabilities)
  File "/usr/local/lib/python3.11/dist-packages/undetected_chromedriver/__init__.py", line 727, in start_session
    super(selenium.webdriver.chrome.webdriver.WebDriver, self).start_session(
  File "/usr/local/lib/python3.11/dist-packages/selenium/webdriver/remote/webdriver.py", line 289, in start_session
    response = self.execute(Command.NEW_SESSION, caps)["value"]
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/selenium/webdriver/remote/webdriver.py", line 344, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.11/dist-packages/selenium/webdriver/remote/errorhandler.py", line 229, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot connect to chrome at 127.0.0.1:53893
from chrome not reachable
Stacktrace:
#0 0x559bca97ffb3 <unknown>
#1 0x559bca6532f6 <unknown>
#2 0x559bca63effa <unknown>
#3 0x559bca68aa3c <unknown>
#4 0x559bca6822a9 <unknown>
#5 0x559bca6c5ac6 <unknown>
#6 0x559bca6bc713 <unknown>
#7 0x559bca68f18b <unknown>
#8 0x559bca68ff7e <unknown>
#9 0x559bca9458d8 <unknown>
#10 0x559bca949800 <unknown>
#11 0x559bca953cfc <unknown>
#12 0x559bca94a418 <unknown>
#13 0x559bca91742f <unknown>
#14 0x559bca96e4e8 <unknown>
#15 0x559bca96e6b4 <unknown>
#16 0x559bca97f143 <unknown>
#17 0x7fb40aa94ac3 <unknown>
yangex commented 11 months ago

It seems that version 118 is not yet supported, perhaps you need to go back to version 117

gutsintheshell commented 11 months ago

Fixed on mac by switching to beta release on OSX.

Change browser binary path in candidates.update method call line 879 inside undected_chromedriver init.py file to "/Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta".

Hope it work for you too 🤟

faizanalhassan commented 11 months ago

I also had this issue. After debugging I found if there is chromedriver binary available in patcher.data_path location, it will always pick that even though you set driver_executable_path=ChromeDriverManager().install().

pistachiomatt commented 11 months ago

@faizanalhassan Can you explain your fix in more words?

faizanalhassan commented 11 months ago

So, recently in a project I was using undetected-chromedriver and it was giving me an error that chromedriver.exe version is 114. I rechecked my chromedriver.exe was 118 and I was passing its path correctly through driver_executable_path parameter. So, I debugged the library code to review where the executable_path is updated.

During debugging, I noticed that these lines are causing the problem:

https://github.com/ultrafunkamsterdam/undetected-chromedriver/blob/cea80717c5a3d95ccf5c40e6e38081d5454ec7a5/undetected_chromedriver/patcher.py#L132-L141

So, even user has given a custom chromedriver path, it will always first check patcher.data_path directory. And if found chromedriver binary it will set that as executable path (self.executable_path = str(most_recent)).

I removed all chromedriver binaries from that path and then my custom path was correctly used and no error was raised.

I think the solution is to move the below lines to the top of this method. https://github.com/ultrafunkamsterdam/undetected-chromedriver/blob/cea80717c5a3d95ccf5c40e6e38081d5454ec7a5/undetected_chromedriver/patcher.py#L147-L152

faizanalhassan commented 11 months ago

Created a PR #1638 to fix this. Please check if works.