javascriptc#puppeteerpuppeteer-sharp

How can I log JavaScript errors from Puppeteer-Sharp?


I have a C# app that uses Puppeteer-Sharp to convert HTML pages to PDF. Everything works great except for one issue. I have a fieldset within which a JavaScript file is used to move checkboxes from the right of the question to the left. When I view the original HTML, the checkboxes have been moved, but in the PDF they are still on the right side. I would like to find out what is going wrong, but I don't know how to get Puppeteer-Sharp to output any error information.

I found this question/answer, which sounds like it is the solution, but I'm not sure what the person actually did or how to make use of it. How do I get readable browser/page errors out of puppeteer-sharp?


Solution

  • The best I could find was this, from an issue on hardkoded/puppeteer-sharp on github:

    var page = await browser.NewPageAsync();
    page.PageError += (sender, eventArgs) =>
    {
       Console.WriteLine("Error Found:");
       Console.WriteLine($"     {eventArgs.Message}");
    };