0

Before instantiating a new undetected-chromedriver - instance, I ensure that the latest ChromeDriver version is installed via the python-chromedriver-autoinstaller library as mentioned in this post:

import chromedriver_autoinstaller
chromedriver_autoinstaller.install()

'C:\\Users\\username\\project_path\\lib\\site-packages\\chromedriver_autoinstaller\\106\\chromedriver.exe'

As can be seen, it automatically installs version 106, but in the error message (caused by the intent to instantiate the undetected Chrome Driver via UndetectedChromeDriver.Chrome(options=self._browser_options)), it states I need the next version 107:

selenium.common.exceptions.WebDriverException: Message: unknown error: cannot connect to chrome at 127.0.0.1:... from session not created: This version of ChromeDriver only supports Chrome version 107 Current browser version is 106.0.5249.119

Another conventional way of automatically installing the required chromedriver did not work either:

from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
import undetected_chromedriver as UndetectedChromeDriver

return UndetectedChromeDriver.Chrome(
    options=self._browser_options,
    service=ChromeService(ChromeDriverManager().install()))

I need to deploy this remotely, so there should be a way to automatically get and install the required ChromeDriver - version.

The full error message with traceback is as follows:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\username\project_path\lib\site-packages\undetected_chromedriver\__init__.py", line 103, in __init__
    def __init__(
  File "C:\Users\username\project_path\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 35, in __init__
    def __init__(self, executable_path=DEFAULT_EXECUTABLE_PATH, port=DEFAULT_PORT,
  File "C:\Users\username\project_path\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 37, in __init__
    def __init__(self, browser_name, vendor_prefix,
  File "C:\Users\username\project_path\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 195, in __init__
    def __init__(self, command_executor='http://127.0.0.1:4444',
  File "C:\Users\username\project_path\lib\site-packages\undetected_chromedriver\__init__.py", line 599, in start_session
    def start_session(self, capabilities=None, browser_profile=None):
  File "C:\Users\username\project_path\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 346, in start_session
    def start_session(self, capabilities: dict, browser_profile=None) -> None:
  File "C:\Users\username\project_path\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 408, in execute
    def execute(self, driver_command: str, params: dict = None) -> dict:
  File "C:\Users\username\project_path\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 102, in check_response
    def check_response(self, response: Dict[str, Any]) -> None:

selenium.common.exceptions.WebDriverException: Message: unknown error: cannot connect to chrome at 127.0.0.1:...
from session not created: This version of ChromeDriver only supports Chrome version 107
Current browser version is 106.0.5249.119

Stacktrace:

Backtrace:
    Ordinal0 [0x00FEACD3+2075859]
    Ordinal0 [0x00F7EE61+1633889]
    Ordinal0 [0x00E7B7BD+571325]
    Ordinal0 [0x00E9DFCD+712653]
    Ordinal0 [0x00E96D24+683300]
    Ordinal0 [0x00E96B01+682753]
    Ordinal0 [0x00ECDBD3+908243]
    Ordinal0 [0x00ECD6AA+906922]
    Ordinal0 [0x00EC7136+880950]
    Ordinal0 [0x00E9FEFD+720637]
    Ordinal0 [0x00EA0F3F+724799]
    GetHandleVerifier [0x0129EED2+2769538]
    GetHandleVerifier [0x01290D95+2711877]
    GetHandleVerifier [0x0107A03A+521194]
    GetHandleVerifier [0x01078DA0+516432]
    Ordinal0 [0x00F8682C+1665068]
    Ordinal0 [0x00F8B128+1683752]
    Ordinal0 [0x00F8B215+1683989]
    Ordinal0 [0x00F96484+1729668]
    BaseThreadInitThunk [0x774CFA29+25]
    RtlGetAppContainerNamedObjectPath [0x779E7BBE+286]
    RtlGetAppContainerNamedObjectPath [0x779E7B8E+238]

EDIT (more info about Chrome Version):

C:\Users\username>REG QUERY HKEY_CURRENT_USER\Software\Google\Chrome\BLBeacon /v Version

HKEY_CURRENT_USER\Software\Google\Chrome\BLBeacon
    Version    REG_SZ    106.0.5249.119
Andreas L.
  • 3,239
  • 5
  • 26
  • 65

1 Answers1

0

I've ran into the same issue just yesterday !

after spending some time looking for solutions, I found this thread from 2016 suggesting that google chrome doesn't change its version in the registry when it auto-updates. It would explain why KEY_CURRENT_USER\Software\Google\Chrome\BLBeacon is of an older version than your current browser one.

This is obviously quite annoying as chromedriver_autoinstaller uses this exact value in order to determine the current browser version, thus creating this error.

I haven't found any solutions in order to solve this exact issue but managed to find another way to automatically download the latest correct chrome driver using the webdriver_manager library (which essentially does the same as chromedriver_autoinstaller but with some additional features such as the possibility to give it an exact chrome driver version) ! It uses this thread that manages to get the proper current browser version using the command prompt. The downside of it is that it requires a hard coded path to the browser executable :

import re
import subprocess

chrome_version = subprocess.check_output(
    r'wmic datafile where name="C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe" get Version /value',
    shell=True
    )
    
# Retrieve the current browser major version
chrome_version = re.sub('Version=', '', chrome_version.decode('utf-8').strip()).split('.')[0]

Once the version is retrieved, we can manually find out its associated chrome driver version thanks to the Google API and then instantiate a ChromeDriverManager with it (inspired by how webdriver_manager internally works) :

import urllib
from webdriver_manager.chrome import ChromeDriverManager

latest_release_url = "https://chromedriver.storage.googleapis.com/LATEST_RELEASE"

latest_release_url_version = f"{latest_release_url}_{chrome_version}"

with urllib.request.urlopen(latest_release_url_version) as response:
    chrome_driver_version = response.read().decode("utf-8")

chromedriver_filepath = ChromeDriverManager(version=chrome_driver_version).install()

I hope this error will be fixed one day as this workaround doesn't look very robust, but it seems doing the job. Also, I've opened an issue on webdriver_manager's GitHub repository and might do the same with chromedriver_autoinstaller.

Hope it helps !

Roman
  • 1