@@ -311,30 +311,40 @@ def create_webdriver(
311311) -> webdriver .Chrome :
312312 print ("html2print: creating ChromeDriver service." , flush = True ) # noqa: T201
313313
314- path_to_chrome : str
314+ path_to_chrome_driver : str
315315 if chromedriver_argument is None :
316- path_to_chrome = ChromeDriverManager ().get_chrome_driver (
316+ path_to_chrome_driver = ChromeDriverManager ().get_chrome_driver (
317317 path_to_cache_dir
318318 )
319319 else :
320- path_to_chrome = chromedriver_argument
321- print (f"html2print: ChromeDriver available at path: { path_to_chrome } " ) # noqa: T201
320+ path_to_chrome_driver = chromedriver_argument
321+ print ( # noqa: T201
322+ f"html2print: ChromeDriver available at path: { path_to_chrome_driver } "
323+ )
322324
323325 if debug :
324326 service = Service (
325- path_to_chrome , log_output = PATH_TO_CHROME_DRIVER_DEBUG_LOG
327+ path_to_chrome_driver , log_output = PATH_TO_CHROME_DRIVER_DEBUG_LOG
326328 )
327329 else :
328- service = Service (path_to_chrome )
330+ service = Service (path_to_chrome_driver )
329331
330332 webdriver_options = Options ()
331333 webdriver_options .add_argument ("start-maximized" )
332334 webdriver_options .add_argument ("disable-infobars" )
333335 # Doesn't seem to be needed.
334336 # webdriver_options.add_argument('--disable-gpu') # noqa: ERA001
335337 webdriver_options .add_argument ("--disable-extensions" )
336- webdriver_options .add_argument ("--headless=chrome" )
337- # FIXME: This is not nice but otherwise it does not work in Ubuntu 24-based Docker image.
338+
339+ # Use --headless=new, as it seems to be more stable on Windows (available since Chrome 109).
340+ # see https://www.selenium.dev/blog/2023/headless-is-going-away/
341+ webdriver_options .add_argument ("--headless=new" )
342+
343+ # Docker disables some syscalls that are required for Chrome's sandbox to work.
344+ # https://stackoverflow.com/questions/68855734/how-to-setup-chrome-sandbox-on-docker-container
345+ # We prefer isolation of the container over isolation of tabs within Chrome,
346+ # and thus disable the sandbox.
347+ # See also:
338348 # https://github.com/SeleniumHQ/selenium/issues/15327#issuecomment-2689287561
339349 webdriver_options .add_argument ("--no-sandbox" )
340350
0 commit comments