@@ -311,30 +311,43 @@ 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 ()
333
+
334
+ # Workaround for Windows: Chrome is not typically found in the PATH, so
335
+ # need to supply the exact binary location manually.
336
+ if platform .system () == "Windows" :
337
+ webdriver_options .binary_location = path_to_chrome_driver
338
+
331
339
webdriver_options .add_argument ("start-maximized" )
332
340
webdriver_options .add_argument ("disable-infobars" )
333
341
# Doesn't seem to be needed.
334
342
# webdriver_options.add_argument('--disable-gpu') # noqa: ERA001
335
343
webdriver_options .add_argument ("--disable-extensions" )
336
344
webdriver_options .add_argument ("--headless=chrome" )
337
- # FIXME: This is not nice but otherwise it does not work in Ubuntu 24-based Docker image.
345
+
346
+ # Docker disables some syscalls that are required for Chrome's sandbox to work.
347
+ # https://stackoverflow.com/questions/68855734/how-to-setup-chrome-sandbox-on-docker-container
348
+ # We prefer isolation of the container over isolation of tabs within Chrome,
349
+ # and thus disable the sandbox.
350
+ # See also:
338
351
# https://github.com/SeleniumHQ/selenium/issues/15327#issuecomment-2689287561
339
352
webdriver_options .add_argument ("--no-sandbox" )
340
353
0 commit comments