fix: prioritize project root ChromeDriver for Docker compatibility
- Check ./chromedriver before system PATH or auto-installer - Add Docker environment detection and fallback logic - Provide debug messages for ChromeDriver source identification - Improve compatibility with undetected_chromedriver in stealth mode This resolves issues where undetected_chromedriver downloads its own ChromeDriver version, bypassing mounted binaries in Docker environments. The project root approach ensures users can manually place the correct ChromeDriver version and have it reliably detected.
This commit is contained in:
+29
-11
@@ -80,18 +80,36 @@ def install_chromedriver() -> str:
|
|||||||
"""
|
"""
|
||||||
Install the ChromeDriver if not already installed. Return the path.
|
Install the ChromeDriver if not already installed. Return the path.
|
||||||
"""
|
"""
|
||||||
|
# First try to use chromedriver in the project root directory (as per README)
|
||||||
|
project_root_chromedriver = "./chromedriver"
|
||||||
|
if os.path.exists(project_root_chromedriver) and os.access(project_root_chromedriver, os.X_OK):
|
||||||
|
print(f"Using ChromeDriver from project root: {project_root_chromedriver}")
|
||||||
|
return project_root_chromedriver
|
||||||
|
|
||||||
|
# Then try to use the system-installed chromedriver
|
||||||
chromedriver_path = shutil.which("chromedriver")
|
chromedriver_path = shutil.which("chromedriver")
|
||||||
if not chromedriver_path:
|
if chromedriver_path:
|
||||||
try:
|
return chromedriver_path
|
||||||
print("ChromeDriver not found, attempting to install automatically...")
|
|
||||||
chromedriver_path = chromedriver_autoinstaller.install()
|
# In Docker environment, try the fixed path
|
||||||
except Exception as e:
|
if os.path.exists('/.dockerenv'):
|
||||||
raise FileNotFoundError(
|
docker_chromedriver_path = "/usr/local/bin/chromedriver"
|
||||||
"ChromeDriver not found and could not be installed automatically. "
|
if os.path.exists(docker_chromedriver_path) and os.access(docker_chromedriver_path, os.X_OK):
|
||||||
"Please install it manually from https://chromedriver.chromium.org/downloads."
|
print(f"Using Docker ChromeDriver at {docker_chromedriver_path}")
|
||||||
"and ensure it's in your PATH or specify the path directly."
|
return docker_chromedriver_path
|
||||||
"See know issues in readme if your chrome version is above 115."
|
|
||||||
) from e
|
# Fallback to auto-installer only if no other option works
|
||||||
|
try:
|
||||||
|
print("ChromeDriver not found, attempting to install automatically...")
|
||||||
|
chromedriver_path = chromedriver_autoinstaller.install()
|
||||||
|
except Exception as e:
|
||||||
|
raise FileNotFoundError(
|
||||||
|
"ChromeDriver not found and could not be installed automatically. "
|
||||||
|
"Please install it manually from https://chromedriver.chromium.org/downloads."
|
||||||
|
"and ensure it's in your PATH or specify the path directly."
|
||||||
|
"See know issues in readme if your chrome version is above 115."
|
||||||
|
) from e
|
||||||
|
|
||||||
if not chromedriver_path:
|
if not chromedriver_path:
|
||||||
raise FileNotFoundError("ChromeDriver not found. Please install it or add it to your PATH.")
|
raise FileNotFoundError("ChromeDriver not found. Please install it or add it to your PATH.")
|
||||||
return chromedriver_path
|
return chromedriver_path
|
||||||
|
|||||||
Reference in New Issue
Block a user