Get the Chrome version number via OS-specific auto-detection.
()
| 79 | |
| 80 | |
| 81 | def get_chrome_version(): |
| 82 | """Get the Chrome version number via OS-specific auto-detection.""" |
| 83 | full_version = None |
| 84 | |
| 85 | if platform.system() == 'Windows': |
| 86 | try: |
| 87 | import winreg |
| 88 | |
| 89 | def _read_registry(root, key, value): |
| 90 | try: |
| 91 | with winreg.OpenKey(root, key) as hkey: |
| 92 | val, _ = winreg.QueryValueEx(hkey, value) |
| 93 | return val |
| 94 | except Exception: |
| 95 | return None |
| 96 | |
| 97 | keys = [ |
| 98 | r'SOFTWARE\Google\Chrome\BLBeacon', |
| 99 | r'SOFTWARE\Wow6432Node\Google\Chrome\BLBeacon', |
| 100 | ] |
| 101 | version_str = None |
| 102 | for key in keys: |
| 103 | version_str = _read_registry( |
| 104 | winreg.HKEY_CURRENT_USER, key, 'Version' |
| 105 | ) |
| 106 | if version_str: |
| 107 | break |
| 108 | |
| 109 | if not version_str: |
| 110 | print( |
| 111 | 'Error: The Chrome version could not be read ' |
| 112 | 'from the Windows registry.' |
| 113 | ) |
| 114 | sys.exit(1) |
| 115 | |
| 116 | full_version = ( |
| 117 | version_str.split()[-1].strip() |
| 118 | if version_str.split() |
| 119 | else version_str.strip() |
| 120 | ) |
| 121 | |
| 122 | except ImportError: |
| 123 | print("Error: The 'winreg' module is required on Windows.") |
| 124 | sys.exit(1) |
| 125 | except Exception as e: |
| 126 | print(f"Error reading Windows registry: {e}") |
| 127 | sys.exit(1) |
| 128 | |
| 129 | else: |
| 130 | chrome_executable = _find_chrome_executable() |
| 131 | |
| 132 | if not chrome_executable: |
| 133 | print( |
| 134 | 'Error: Could not find the Google Chrome or Chromium ' |
| 135 | 'executable in common locations.' |
| 136 | ) |
| 137 | sys.exit(1) |
| 138 |
no test coverage detected