@@ -311,30 +311,44 @@ 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 ()
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+
331339 webdriver_options .add_argument ("start-maximized" )
332340 webdriver_options .add_argument ("disable-infobars" )
333341 # Doesn't seem to be needed.
334342 # webdriver_options.add_argument('--disable-gpu') # noqa: ERA001
335343 webdriver_options .add_argument ("--disable-extensions" )
336344 webdriver_options .add_argument ("--headless=chrome" )
337345 # FIXME: This is not nice but otherwise it does not work in Ubuntu 24-based Docker image.
346+
347+ # Docker disables some syscalls that are required for Chrome's sandbox to work.
348+ # https://stackoverflow.com/questions/68855734/how-to-setup-chrome-sandbox-on-docker-container
349+ # We prefer isolation of the container over isolation of tabs within Chrome,
350+ # and thus disable the sandbox.
351+ # See also:
338352 # https://github.com/SeleniumHQ/selenium/issues/15327#issuecomment-2689287561
339353 webdriver_options .add_argument ("--no-sandbox" )
340354
0 commit comments