Skip to content

API Reference

This module has only one function: get_chrome_version(). It returns the version of the Chrome installed on the system.

extract_version_folder()

Extracts the Chrome version from the folder name.

Check if the Chrome folder exists in the x32 or x64 Program Files folders.

Source code in chrome_version/core.py
def extract_version_folder():
    """Extracts the Chrome version from the folder name.

    Check if the Chrome folder exists in the x32 or x64 Program Files folders.
    """
    for i in range(2):
        path = "C:\\Program Files" + (" (x86)" if i else "") + "\\Google\\Chrome\\Application"
        if os.path.isdir(path):
            paths = [f.path for f in os.scandir(path) if f.is_dir()]
            for path in paths:
                filename = os.path.basename(path)
                pattern = "\d+\.\d+\.\d+\.\d+"
                match = re.search(pattern, filename)
                if match and match.group():
                    # Found a Chrome version.
                    return match.group(0)

    return None

extract_version_registry(output)

Extracts the Chrome version from the registry output.

Source code in chrome_version/core.py
def extract_version_registry(output):
    """Extracts the Chrome version from the registry output."""
    try:
        google_version = ""
        for letter in output[output.rindex("DisplayVersion    REG_SZ") + 24 :]:
            if letter != "\n":
                google_version += letter
            else:
                break
        return google_version.strip()
    except TypeError:
        return

get_chrome_version()

Gets the Chrome version.

Source code in chrome_version/core.py
def get_chrome_version():
    """Gets the Chrome version."""
    version = None
    install_path = None

    try:
        if platform == "linux" or platform == "linux2":
            # linux
            install_path = "/usr/bin/google-chrome"
        elif platform == "darwin":
            # OS X
            install_path = "/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"
        elif platform == "win32":
            # Windows...
            try:
                # Try registry key.
                stream = os.popen(
                    'reg query "HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Google Chrome"'
                )
                output = stream.read()
                version = extract_version_registry(output)
            except Exception:
                # Try folder path.
                version = extract_version_folder()
    except Exception as ex:
        print(ex)

    version = os.popen(f"{install_path} --version").read().strip("Google Chrome ").strip() if install_path else version

    return version