chromic_pdf icon indicating copy to clipboard operation
chromic_pdf copied to clipboard

Will this work with msEdge and Google Chrome for Testing?

Open CharlesOkwuagwu opened this issue 1 year ago • 4 comments

Hi,

I'm trying this chromic_pdf 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

CharlesOkwuagwu avatar Jun 10 '24 00:06 CharlesOkwuagwu

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.

andreasknoepfle avatar Jun 10 '24 07:06 andreasknoepfle

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}

CharlesOkwuagwu avatar Jun 10 '24 08:06 CharlesOkwuagwu

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 avatar Jun 10 '24 11:06 andreasknoepfle

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).

andreasknoepfle avatar Jun 10 '24 11:06 andreasknoepfle

Going to close this for now. @CharlesOkwuagwu please re-open if you have further questions.

maltoe avatar Jul 28 '24 10:07 maltoe

This simple config launches msEdge

port =
      Port.open(
        {:spawn_executable, "C:\\Windows\\System32\\cmd.exe"},
        [
          :binary,
          :exit_status,
          :stderr_to_stdout,
          :hide,
          {:args,
           [
             "/c",
             "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe",
             "--remote-debugging-port=9222",
             "--headless"
           ]}
        ]
      )

CharlesOkwuagwu avatar Feb 11 '25 12:02 CharlesOkwuagwu