Added a warning for people that try to run a non-headless browser in a docker container. It errors in a very unhelpful way, and so this code tells the user in the output what's happening and also forces headless = True. If a user actually means to run a non-headless browser and view via X11 or something then the warning/output will lead them to the right place that they need to tweak.

This commit is contained in:
Christian Coleman
2025-06-22 02:39:20 -04:00
parent 12a6705724
commit c7ffe46771
2 changed files with 47 additions and 2 deletions
+5
View File
@@ -121,6 +121,11 @@ def create_undetected_chromedriver(service, chrome_options) -> webdriver.Chrome:
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_path = get_chrome_path()