mirror of
https://github.com/FlareSolverr/FlareSolverr.git
synced 2025-06-08 12:35:30 +00:00
Fix Chrome version detection on Windows
This commit is contained in:
parent
60a22625be
commit
ecaac2e1d9
55
src/utils.py
55
src/utils.py
@ -1,6 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
|
|
||||||
from selenium.webdriver.chrome.webdriver import WebDriver
|
from selenium.webdriver.chrome.webdriver import WebDriver
|
||||||
import undetected_chromedriver as uc
|
import undetected_chromedriver as uc
|
||||||
@ -79,16 +80,58 @@ def get_chrome_major_version() -> str:
|
|||||||
if CHROME_MAJOR_VERSION is not None:
|
if CHROME_MAJOR_VERSION is not None:
|
||||||
return CHROME_MAJOR_VERSION
|
return CHROME_MAJOR_VERSION
|
||||||
|
|
||||||
chrome_path = uc.find_chrome_executable()
|
if os.name == 'nt':
|
||||||
# Example 1: 'Chromium 104.0.5112.79 Arch Linux\n'
|
try:
|
||||||
# Example 2: 'Google Chrome 104.0.5112.79 Arch Linux\n'
|
stream = os.popen(
|
||||||
process = os.popen(f"{chrome_path} --version")
|
'reg query "HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Google Chrome"')
|
||||||
complete_version = process.read()
|
output = stream.read()
|
||||||
process.close()
|
# Example: '104.0.5112.79'
|
||||||
|
complete_version = extract_version_registry(output)
|
||||||
|
except Exception:
|
||||||
|
# Example: '104.0.5112.79'
|
||||||
|
complete_version = extract_version_folder()
|
||||||
|
else:
|
||||||
|
chrome_path = uc.find_chrome_executable()
|
||||||
|
process = os.popen(f'"{chrome_path}" --version')
|
||||||
|
# Example 1: 'Chromium 104.0.5112.79 Arch Linux\n'
|
||||||
|
# Example 2: 'Google Chrome 104.0.5112.79 Arch Linux\n'
|
||||||
|
complete_version = process.read()
|
||||||
|
process.close()
|
||||||
|
|
||||||
CHROME_MAJOR_VERSION = complete_version.split('.')[0].split(' ')[-1]
|
CHROME_MAJOR_VERSION = complete_version.split('.')[0].split(' ')[-1]
|
||||||
|
logging.info(f"Chrome major version: {CHROME_MAJOR_VERSION}")
|
||||||
return CHROME_MAJOR_VERSION
|
return CHROME_MAJOR_VERSION
|
||||||
|
|
||||||
|
|
||||||
|
def extract_version_registry(output) -> str:
|
||||||
|
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 ''
|
||||||
|
|
||||||
|
|
||||||
|
def extract_version_folder() -> str:
|
||||||
|
# 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 ''
|
||||||
|
|
||||||
|
|
||||||
def get_user_agent(driver=None) -> str:
|
def get_user_agent(driver=None) -> str:
|
||||||
global USER_AGENT
|
global USER_AGENT
|
||||||
if USER_AGENT is not None:
|
if USER_AGENT is not None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user