2020from selenium .webdriver .chrome .service import Service
2121from webdriver_manager .core .os_manager import ChromeType , OperationSystemManager
2222
23- __version__ = "0.0.14 "
23+ __version__ = "0.0.15a2 "
2424
2525PATH_TO_HTML2PDF_JS = os .path .join (
2626 os .path .dirname (os .path .join (__file__ )), "html2pdf_js" , "html2pdf.min.js"
2727)
2828
2929DEFAULT_CACHE_DIR = os .path .join (Path .home (), ".html2print" , "chromedriver" )
3030
31+ PATH_TO_CHROME_DRIVER_DEBUG_LOG = "/tmp/chromedriver.log"
32+
3133# HTML2PDF.js prints unicode symbols to console. The following makes it work on
3234# Windows which otherwise complains:
3335# UnicodeEncodeError: 'charmap' codec can't encode characters in position 129-130: character maps to <undefined>
@@ -303,7 +305,10 @@ class Done(Exception):
303305
304306
305307def create_webdriver (
306- chromedriver : Optional [str ], path_to_cache_dir : str , page_load_timeout : int
308+ chromedriver : Optional [str ],
309+ path_to_cache_dir : str ,
310+ page_load_timeout : int ,
311+ debug : bool = False ,
307312) -> webdriver .Chrome :
308313 print ("html2print: creating ChromeDriver service." , flush = True ) # noqa: T201
309314 if chromedriver is None :
@@ -314,13 +319,20 @@ def create_webdriver(
314319 path_to_chrome = chromedriver
315320 print (f"html2print: ChromeDriver available at path: { path_to_chrome } " ) # noqa: T201
316321
317- service = Service (path_to_chrome )
322+ if debug :
323+ service = Service (
324+ path_to_chrome , log_output = PATH_TO_CHROME_DRIVER_DEBUG_LOG
325+ )
326+ else :
327+ service = Service (path_to_chrome )
318328
319329 webdriver_options = Options ()
320330 webdriver_options .add_argument ("start-maximized" )
321331 webdriver_options .add_argument ("disable-infobars" )
332+ # Doesn't seem to be needed.
333+ # webdriver_options.add_argument('--disable-gpu') # noqa: ERA001
322334 webdriver_options .add_argument ("--disable-extensions" )
323- webdriver_options .add_argument ("--headless" )
335+ webdriver_options .add_argument ("--headless=chrome " )
324336 # FIXME: This is not nice but otherwise it does not work in Ubuntu 24-based Docker image.
325337 # https://github.com/SeleniumHQ/selenium/issues/15327#issuecomment-2689287561
326338 webdriver_options .add_argument ("--no-sandbox" )
@@ -415,6 +427,14 @@ def main():
415427 "HTML file, load it, and let HTML2PDF.js finish its job."
416428 ),
417429 )
430+ command_parser_print .add_argument (
431+ "--debug" ,
432+ action = "store_true" ,
433+ help = (
434+ f"Enables ChromeDriver logging to a file: "
435+ f"{ PATH_TO_CHROME_DRIVER_DEBUG_LOG } ."
436+ ),
437+ )
418438 command_parser_print .add_argument (
419439 "paths" , nargs = "+" , help = "Paths to input HTML file."
420440 )
@@ -442,7 +462,10 @@ def main():
442462 args .cache_dir if args .cache_dir is not None else DEFAULT_CACHE_DIR
443463 )
444464 driver = create_webdriver (
445- args .chromedriver , path_to_cache_dir , page_load_timeout
465+ args .chromedriver ,
466+ path_to_cache_dir ,
467+ page_load_timeout ,
468+ debug = args .debug ,
446469 )
447470
448471 @atexit .register
0 commit comments