fix : more linux issues
This commit is contained in:
+1
-1
@@ -10,7 +10,7 @@ RUN apt-get update -y && apt-get install -y \
|
|||||||
unzip \
|
unzip \
|
||||||
xvfb \
|
xvfb \
|
||||||
libxss1 \
|
libxss1 \
|
||||||
libappindicator1 \
|
#libappindicator1 \
|
||||||
fonts-liberation \
|
fonts-liberation \
|
||||||
libnss3 \
|
libnss3 \
|
||||||
libatk1.0-0 \
|
libatk1.0-0 \
|
||||||
|
|||||||
+1
-4
@@ -1,4 +1,4 @@
|
|||||||
version: '3'
|
version: '3.8'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
redis:
|
redis:
|
||||||
@@ -77,9 +77,6 @@ services:
|
|||||||
dockerfile: Dockerfile.backend
|
dockerfile: Dockerfile.backend
|
||||||
ports:
|
ports:
|
||||||
- ${BACKEND_PORT:-7777}:${BACKEND_PORT:-7777}
|
- ${BACKEND_PORT:-7777}:${BACKEND_PORT:-7777}
|
||||||
- ${OLLAMA_PORT:-11434}:${OLLAMA_PORT:-11434}
|
|
||||||
- ${LM_STUDIO_PORT:-1234}:${LM_STUDIO_PORT:-1234}
|
|
||||||
- ${CUSTOM_ADDITIONAL_LLM_PORT:-8000}:${CUSTOM_ADDITIONAL_LLM_PORT:-8000}
|
|
||||||
volumes:
|
volumes:
|
||||||
- ./:/app
|
- ./:/app
|
||||||
- ${WORK_DIR:-.}:/opt/workspace
|
- ${WORK_DIR:-.}:/opt/workspace
|
||||||
|
|||||||
+57
-43
@@ -121,29 +121,8 @@ def bypass_ssl() -> str:
|
|||||||
pretty_print("Bypassing SSL verification issues, we strongly advice you update your certifi SSL certificate.", color="warning")
|
pretty_print("Bypassing SSL verification issues, we strongly advice you update your certifi SSL certificate.", color="warning")
|
||||||
ssl._create_default_https_context = ssl._create_unverified_context
|
ssl._create_default_https_context = ssl._create_unverified_context
|
||||||
|
|
||||||
def create_undetected_chromedriver(service, chrome_options) -> webdriver.Chrome:
|
def create_chrome_options(headless=False, stealth_mode=True, crx_path="./crx/nopecha.crx", lang="en") -> Options:
|
||||||
"""Create an undetected ChromeDriver instance."""
|
"""Create Chrome options - separated for reusability."""
|
||||||
try:
|
|
||||||
driver = uc.Chrome(service=service, options=chrome_options)
|
|
||||||
except Exception as e:
|
|
||||||
pretty_print(f"Failed to create Chrome driver: {str(e)}. Trying to bypass SSL...", color="failure")
|
|
||||||
try:
|
|
||||||
bypass_ssl()
|
|
||||||
driver = uc.Chrome(service=service, options=chrome_options)
|
|
||||||
except Exception as e:
|
|
||||||
pretty_print(f"Failed to create Chrome driver, fallback failed:\n{str(e)}.", color="failure")
|
|
||||||
raise e
|
|
||||||
raise e
|
|
||||||
driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")
|
|
||||||
return driver
|
|
||||||
|
|
||||||
def create_driver(headless=False, stealth_mode=True, crx_path="./crx/nopecha.crx", lang="en") -> webdriver.Chrome:
|
|
||||||
"""Create a Chrome WebDriver with specified options."""
|
|
||||||
# Warn if trying to run non-headless in Docker
|
|
||||||
if not headless and os.path.exists('/.dockerenv'):
|
|
||||||
print("[WARNING] Running non-headless browser in Docker may fail!")
|
|
||||||
print("[WARNING] Consider setting headless=True or headless_browser=True in config.ini")
|
|
||||||
|
|
||||||
chrome_options = Options()
|
chrome_options = Options()
|
||||||
chrome_path = get_chrome_path()
|
chrome_path = get_chrome_path()
|
||||||
|
|
||||||
@@ -152,17 +131,17 @@ def create_driver(headless=False, stealth_mode=True, crx_path="./crx/nopecha.crx
|
|||||||
chrome_options.binary_location = chrome_path
|
chrome_options.binary_location = chrome_path
|
||||||
|
|
||||||
if headless:
|
if headless:
|
||||||
#chrome_options.add_argument("--headless")
|
|
||||||
chrome_options.add_argument("--headless=new")
|
chrome_options.add_argument("--headless=new")
|
||||||
chrome_options.add_argument("--disable-gpu")
|
chrome_options.add_argument("--disable-gpu")
|
||||||
chrome_options.add_argument("--disable-webgl")
|
chrome_options.add_argument("--disable-webgl")
|
||||||
user_data_dir = tempfile.mkdtemp()
|
|
||||||
user_agent = get_random_user_agent()
|
user_agent = get_random_user_agent()
|
||||||
width, height = (1920, 1080)
|
width, height = (1920, 1080)
|
||||||
user_data_dir = tempfile.mkdtemp(prefix="chrome_profile_")
|
profile_dir = f"/tmp/chrome_profile_{uuid.uuid4().hex[:8]}"
|
||||||
|
|
||||||
|
# Core options
|
||||||
chrome_options.add_argument("--no-sandbox")
|
chrome_options.add_argument("--no-sandbox")
|
||||||
chrome_options.add_argument('--disable-dev-shm-usage')
|
chrome_options.add_argument('--disable-dev-shm-usage')
|
||||||
profile_dir = f"/tmp/chrome_profile_{uuid.uuid4().hex[:8]}"
|
|
||||||
chrome_options.add_argument(f'--user-data-dir={profile_dir}')
|
chrome_options.add_argument(f'--user-data-dir={profile_dir}')
|
||||||
chrome_options.add_argument(f"--accept-lang={lang}-{lang.upper()},{lang};q=0.9")
|
chrome_options.add_argument(f"--accept-lang={lang}-{lang.upper()},{lang};q=0.9")
|
||||||
chrome_options.add_argument("--disable-extensions")
|
chrome_options.add_argument("--disable-extensions")
|
||||||
@@ -182,28 +161,14 @@ def create_driver(headless=False, stealth_mode=True, crx_path="./crx/nopecha.crx
|
|||||||
chrome_options.add_argument("--disable-blink-features=AutomationControlled")
|
chrome_options.add_argument("--disable-blink-features=AutomationControlled")
|
||||||
chrome_options.add_argument(f'user-agent={user_agent["ua"]}')
|
chrome_options.add_argument(f'user-agent={user_agent["ua"]}')
|
||||||
chrome_options.add_argument(f'--window-size={width},{height}')
|
chrome_options.add_argument(f'--window-size={width},{height}')
|
||||||
|
|
||||||
if not stealth_mode:
|
if not stealth_mode:
|
||||||
if not os.path.exists(crx_path):
|
if not os.path.exists(crx_path):
|
||||||
pretty_print(f"Anti-captcha CRX not found at {crx_path}.", color="failure")
|
pretty_print(f"Anti-captcha CRX not found at {crx_path}.", color="failure")
|
||||||
else:
|
else:
|
||||||
chrome_options.add_extension(crx_path)
|
chrome_options.add_extension(crx_path)
|
||||||
|
|
||||||
chromedriver_path = install_chromedriver()
|
if not stealth_mode:
|
||||||
|
|
||||||
service = Service(chromedriver_path)
|
|
||||||
if stealth_mode:
|
|
||||||
chrome_options.add_argument("--disable-blink-features=AutomationControlled")
|
|
||||||
driver = create_undetected_chromedriver(service, chrome_options)
|
|
||||||
chrome_version = driver.capabilities['browserVersion']
|
|
||||||
stealth(driver,
|
|
||||||
languages=["en-US", "en"],
|
|
||||||
vendor=user_agent["vendor"],
|
|
||||||
platform="Win64" if "windows" in user_agent["ua"].lower() else "MacIntel" if "mac" in user_agent["ua"].lower() else "Linux x86_64",
|
|
||||||
webgl_vendor="Intel Inc.",
|
|
||||||
renderer="Intel Iris OpenGL Engine",
|
|
||||||
fix_hairline=True,
|
|
||||||
)
|
|
||||||
return driver
|
|
||||||
security_prefs = {
|
security_prefs = {
|
||||||
"profile.default_content_setting_values.geolocation": 0,
|
"profile.default_content_setting_values.geolocation": 0,
|
||||||
"profile.default_content_setting_values.notifications": 0,
|
"profile.default_content_setting_values.notifications": 0,
|
||||||
@@ -227,6 +192,55 @@ def create_driver(headless=False, stealth_mode=True, crx_path="./crx/nopecha.crx
|
|||||||
chrome_options.add_experimental_option("prefs", security_prefs)
|
chrome_options.add_experimental_option("prefs", security_prefs)
|
||||||
chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
|
chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
|
||||||
chrome_options.add_experimental_option('useAutomationExtension', False)
|
chrome_options.add_experimental_option('useAutomationExtension', False)
|
||||||
|
|
||||||
|
return chrome_options
|
||||||
|
|
||||||
|
def create_undetected_chromedriver(service, chrome_options) -> webdriver.Chrome:
|
||||||
|
"""Create an undetected ChromeDriver instance with proper error handling."""
|
||||||
|
try:
|
||||||
|
driver = uc.Chrome(service=service, options=chrome_options)
|
||||||
|
except Exception as e:
|
||||||
|
pretty_print(f"Failed to create Chrome driver: {str(e)}. Trying to bypass SSL...", color="failure")
|
||||||
|
try:
|
||||||
|
bypass_ssl()
|
||||||
|
# Create NEW options object - this is the key fix
|
||||||
|
fresh_options = create_chrome_options(
|
||||||
|
headless=any("--headless" in arg for arg in chrome_options.arguments),
|
||||||
|
stealth_mode=True, # We're in stealth mode if we reach this point
|
||||||
|
crx_path="./crx/nopecha.crx" # Default path
|
||||||
|
)
|
||||||
|
driver = uc.Chrome(service=service, options=fresh_options)
|
||||||
|
except Exception as e:
|
||||||
|
pretty_print(f"Failed to create Chrome driver, fallback failed:\n{str(e)}.", color="failure")
|
||||||
|
raise e
|
||||||
|
|
||||||
|
driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")
|
||||||
|
return driver
|
||||||
|
|
||||||
|
def create_driver(headless=False, stealth_mode=True, crx_path="./crx/nopecha.crx", lang="en") -> webdriver.Chrome:
|
||||||
|
"""Create a Chrome WebDriver with specified options."""
|
||||||
|
# Warn if trying to run non-headless in Docker
|
||||||
|
if not headless and os.path.exists('/.dockerenv'):
|
||||||
|
print("[WARNING] Running non-headless browser in Docker may fail!")
|
||||||
|
print("[WARNING] Consider setting headless=True or headless_browser=True in config.ini")
|
||||||
|
|
||||||
|
chrome_options = create_chrome_options(headless, stealth_mode, crx_path, lang)
|
||||||
|
chromedriver_path = install_chromedriver()
|
||||||
|
service = Service(chromedriver_path)
|
||||||
|
|
||||||
|
if stealth_mode:
|
||||||
|
driver = create_undetected_chromedriver(service, chrome_options)
|
||||||
|
user_agent = get_random_user_agent()
|
||||||
|
stealth(driver,
|
||||||
|
languages=["en-US", "en"],
|
||||||
|
vendor=user_agent["vendor"],
|
||||||
|
platform="Win64" if "windows" in user_agent["ua"].lower() else "MacIntel" if "mac" in user_agent["ua"].lower() else "Linux x86_64",
|
||||||
|
webgl_vendor="Intel Inc.",
|
||||||
|
renderer="Intel Iris OpenGL Engine",
|
||||||
|
fix_hairline=True,
|
||||||
|
)
|
||||||
|
return driver
|
||||||
|
else:
|
||||||
return webdriver.Chrome(service=service, options=chrome_options)
|
return webdriver.Chrome(service=service, options=chrome_options)
|
||||||
|
|
||||||
class Browser:
|
class Browser:
|
||||||
|
|||||||
+9
-10
@@ -64,19 +64,18 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if Docker Compose is installed
|
# Check if Docker Compose is installed
|
||||||
if ! command_exists docker-compose && ! docker compose version >/dev/null 2>&1; then
|
# Prefer the newer 'docker compose' command if available
|
||||||
echo "Error: Docker Compose is not installed. Please install it first."
|
if docker compose version >/dev/null 2>&1; then
|
||||||
echo "On Ubuntu: sudo apt install docker-compose"
|
echo "Using newer docker compose (v2)."
|
||||||
echo "Or via pip: pip install docker-compose"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if command_exists "docker compose"; then
|
|
||||||
echo "Using newer docker compose (not docker-compose)."
|
|
||||||
COMPOSE_CMD="docker compose"
|
COMPOSE_CMD="docker compose"
|
||||||
else
|
elif command_exists docker-compose; then
|
||||||
echo "Using old docker-compose."
|
echo "Using old docker-compose."
|
||||||
COMPOSE_CMD="docker-compose"
|
COMPOSE_CMD="docker-compose"
|
||||||
|
else
|
||||||
|
echo "Error: Docker Compose is not installed. Please install it first."
|
||||||
|
echo "On Ubuntu: sudo apt install docker-compose-plugin"
|
||||||
|
echo "Or install Docker Desktop which includes compose v2"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if docker-compose.yml exists
|
# Check if docker-compose.yml exists
|
||||||
|
|||||||
Reference in New Issue
Block a user