Sicos1977 / ChromiumHtmlToPdf

Convert HTML to PDF with a Chromium based browser
432 stars 85 forks source link

Microsoft Edge exited unexpectedly after upgrading to latest 128 version #163

Closed ganeshgurav-dow closed 2 weeks ago

ganeshgurav-dow commented 2 months ago

Due to recent upgrade with MS Edge to v128, HTML to PDF is failing for us, we also tried using below code but that also fails. If we downgrade the edge browser back to v127 then all works fine, but we can't downgrade for all users due to security compliance.

converter.AddChromiumArgument("--disable-dev-shm-usage"); converter.AddChromiumArgument("--disable-features=PrintCompositorLPAC"); converter.UseOldHeadlessMode = true;

below is the error message it gives:

ChromiumHtmlToPdfLib.Exceptions.ChromiumException: Microsoft Edge exited unexpectedly, \r\n at ChromiumHtmlToPdfLib.Converter.StartChromiumHeadless()\r\n at ChromiumHtmlToPdfLib.Converter.Convert(OutputFormat outputFormat, Object input, Stream outputStream, PageSettings pageSettings, String waitForWindowStatus, Int32 waitForWindowsStatusTimeout, Nullable1 conversionTimeout, Nullable1 mediaLoadTimeout, ILogger logger)\r\n at ChromiumHtmlToPdfLib.Converter.ConvertToPdf(String html, Stream outputStream, PageSettings pageSettings, String waitForWindowStatus, Int32 waitForWindowsStatusTimeout, Nullable1 conversionTimeout, Nullable1 mediaLoadTimeout, ILogger logger)\r\n

It will be great if this can be fixed or any workaround that we can try.

Thank you, Ganesh.

Sicos1977 commented 2 months ago

Try turning on debug logging and see if that gives a clue why it is failing.

    /// <summary>
    ///     Enables Chromium logging;<br/>
    ///     - The output will be saved to the file <b>chrome_debug.log</b> in Chrome's user data directory<br/>
    ///     - Logs are overwritten each time you restart chrome<br/>
    /// </summary>
    /// <remarks>
    ///     If the environment variable CHROME_LOG_FILE is set, Chrome will write its debug log to its specified location.<br/>
    ///     Example: Setting CHROME_LOG_FILE to "chrome_debug.log" will cause the log file to be written to the Chrome process's<br/>
    ///     current working directory while setting it to "D:\chrome_debug.log" will write the log to the root of your computer's D: drive.
    /// </remarks>
    public bool EnableChromiumLogging { get; set; }
lc200 commented 2 months ago

Just to add that I'm getting the exact same error, this is with Google Chrome having been updated to 128, rolling back to version 127 and it works fine again.

ganeshgurav-dow commented 2 months ago

I resolved it by adding below code:

converter.AddChromiumArgument("--headless=old");

Looks like the default behavior in the chromium browser has changed for headless mode.

lc200 commented 2 months ago

Many thanks, that has sorted it. Presumably the headless old method is depreciated and may disappear in time?

ganeshgurav-dow commented 2 months ago

Yes it seems like they plan to deprecate old headless mode or make it available as a seperate binary:

image

@Sicos1977, any idea on how this can be taken care?

JBMiller commented 2 months ago

I spent the last few hours dealing with this "exited unexpectedly error" when running on my Windows Server 2019. Works fine locally. As for how it can be taken care of: I made a custom build of the ChromiumHtmlToPdf library and deployed that version with my application on my Windows Server and it worked by specifying "=old" when applying the "--headless" argument.

See PR: https://github.com/Sicos1977/ChromiumHtmlToPdf/pull/167

PS: I would like to note that I use Google Chrome in my use-case, not Edge. Haven't tested Edge, but I would presume the solution would work for Edge as well.