@@ -311,30 +311,40 @@ def create_webdriver(
311
311
) -> webdriver .Chrome :
312
312
print ("html2print: creating ChromeDriver service." , flush = True ) # noqa: T201
313
313
314
- path_to_chrome : str
314
+ path_to_chrome_driver : str
315
315
if chromedriver_argument is None :
316
- path_to_chrome = ChromeDriverManager ().get_chrome_driver (
316
+ path_to_chrome_driver = ChromeDriverManager ().get_chrome_driver (
317
317
path_to_cache_dir
318
318
)
319
319
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
+ )
322
324
323
325
if debug :
324
326
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
326
328
)
327
329
else :
328
- service = Service (path_to_chrome )
330
+ service = Service (path_to_chrome_driver )
329
331
330
332
webdriver_options = Options ()
331
333
webdriver_options .add_argument ("start-maximized" )
332
334
webdriver_options .add_argument ("disable-infobars" )
333
335
# Doesn't seem to be needed.
334
336
# webdriver_options.add_argument('--disable-gpu') # noqa: ERA001
335
337
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:
338
348
# https://github.com/SeleniumHQ/selenium/issues/15327#issuecomment-2689287561
339
349
webdriver_options .add_argument ("--no-sandbox" )
340
350
0 commit comments