bitcrowd / chromic_pdf

Convenient HTML to PDF/A rendering library for Elixir based on Chrome & Ghostscript
Apache License 2.0
392 stars 36 forks source link

Will this work with msEdge and Google Chrome for Testing? #307

Open CharlesOkwuagwu opened 3 weeks ago

CharlesOkwuagwu commented 3 weeks ago

Hi,

I'm trying this _chromicpdf on WIndows10 with Google Chrome for Testing as well as msEdge.

I have downloaded a local copy of Chrome for Testing, and stored the Chrome.exe location in my system PATH: C:\Tools\chrome-win64\Chrome.exe

I am unable to load beyond this error:

01:04:41.145 [error] GenServer #PID<0.2959.0> terminating
** (ChromicPDF.Connection.ConnectionLostError) Chrome has stopped or was terminated by an external program.

If this happened while you were printing a PDF, this may be a problem with Chrome itelf.
If this happens at startup and you are running inside a Docker container with a Linux-based
image, please see the "Chrome Sandbox in Docker containers" section of the documentation.

Either way, to see Chrome's error output, configure ChromicPDF with the option

    discard_stderr: false

    (chromic_pdf 1.15.2) lib/chromic_pdf/pdf/connection/local.ex:53: ChromicPDF.Connection.Local.handle_info/2
    (stdlib 5.2.3) gen_server.erl:1095: :gen_server.try_handle_info/3
    (stdlib 5.2.3) gen_server.erl:1183: :gen_server.handle_msg/6
    (stdlib 5.2.3) proc_lib.erl:241: :proc_lib.init_p_do_apply/3
Last message: {:DOWN, #Reference<0.458662647.298582017.191736>, :port, #Port<0.8>, :normal}

For msEdge (also a Chromium based browser), which comes bundled on windows 10,11 and windows-server 2019+, I tried adding msedge.exe to @default_executables

@default_executables [
    "chromium-browser",
    "chromium",
    "chrome.exe",
    "msedge.exe",
    "google-chrome",
    "/usr/bin/chromium-browser",
    "/usr/bin/chromium",
    "/usr/bin/google-chrome",
    "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
    "/Applications/Chromium.app/Contents/MacOS/Chromium"
  ]

Please can you guide on how to troubleshoot the above two scenarios.

Thanks

andreasknoepfle commented 3 weeks ago

You can pass in a custom chrome_executable option to specify an alternative chrome path (e.g. in your application.ex as described here):

https://hexdocs.pm/chromic_pdf/ChromicPDF.html#module-custom-command-line-switches

But I doubt that msEdge will work, since we rely on command line options to pass into chrome, which will most likely be different for msEdge. But adding the chrome_executable: "C:\Tools\chrome-win64\Chrome.exe" will most likely work. One note here is that most contributors to this codebase work with Linux or MacOS, so the Windows support might be somewhat less often tested. But we already heard of users being successful with it.

CharlesOkwuagwu commented 3 weeks ago

Thanks for your response.

I have applied chrome_executable: "C:\Tools\chrome-win64\Chrome.exe"

config :demo, :chromic_pdf,
  discard_stderr: false,
  chrome_executable: "C:/Tools/chrome-win64/Chrome.exe"

it comes up with the same errors:

09:41:25.298 [error] GenServer #PID<0.561.0> terminating
** (ChromicPDF.Connection.ConnectionLostError) Chrome has stopped or was terminated by an external program.

If this happened while you were printing a PDF, this may be a problem with Chrome itelf.
If this happens at startup and you are running inside a Docker container with a Linux-based
image, please see the "Chrome Sandbox in Docker containers" section of the documentation.

Either way, to see Chrome's error output, configure ChromicPDF with the option

    discard_stderr: false

    (chromic_pdf 1.15.2) lib/chromic_pdf/pdf/connection/local.ex:53: ChromicPDF.Connection.Local.handle_info/2
    (stdlib 5.2.3) gen_server.erl:1095: :gen_server.try_handle_info/3
    (stdlib 5.2.3) gen_server.erl:1183: :gen_server.handle_msg/6
    (stdlib 5.2.3) proc_lib.erl:241: :proc_lib.init_p_do_apply/3
Last message: {:DOWN, #Reference<0.2340099235.2257846276.60362>, :port, #Port<0.7>, :normal}
andreasknoepfle commented 3 weeks ago

Have you tried running the downloaded chrome yourself? Does it run?

If you run chromic_pdf, do you see the instance of chrome coming up in the task manager?

The message that you are seeing is chromic_pdf getting a message from the port that the chrome process died.

andreasknoepfle commented 3 weeks ago

To me it looks more like chrome crashes and less like it is not found, since I would expect a different error in that case (maybe experiment by setting the chome_executable to something not existing to see if that would return a different error).