Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion chromedriver_binary/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import subprocess
import re
import platform
import array
import ctypes

try:
from urllib.request import urlopen, URLError
Expand Down Expand Up @@ -111,11 +113,39 @@ def get_chrome_major_version():
if sys.platform == "darwin":
browser_executables.insert(0, "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome")

get_major_version = lambda version: re.match(r'.*?((?P<major>\d+)\.(\d+\.){2,3}\d+).*?', version).group('major')

for browser_executable in browser_executables:
try:
version = subprocess.check_output([browser_executable, '--version'])
return re.match(r'.*?((?P<major>\d+)\.(\d+\.){2,3}\d+).*?', version.decode('utf-8')).group('major')

return get_major_version(version.decode('utf-8'))

except Exception:
if sys.platform.startswith('win') or sys.platform.startswith('cygwin'):
try:
import winreg
with winreg.OpenKeyEx(winreg.HKEY_CURRENT_USER, r"Software\Google\Chrome\BLBeacon") as key:
version = winreg.QueryValueEx(key, "version")[0]

return get_major_version(version)

except Exception:
roots = list(filter(None, [os.getenv('LocalAppData'), os.getenv('ProgramFiles'), os.getenv('ProgramFiles(x86)'), os.getenv('ProgramW6432')]))

for root in roots:
try:
# https://stackoverflow.com/questions/580924/how-to-access-a-files-properties-on-windows
document = os.path.join(root, 'Google', 'Chrome', 'Application', browser_executable + '.exe')

name = document.replace(os.path.sep, f'{os.path.sep}{os.path.sep}')

version = subprocess.check_output(['wmic', 'datafile', 'where', f'name="{name}"', 'get', 'Version', '/value'])

return get_major_version(version.decode('utf-8').strip())

except Exception:
pass
pass


Expand Down