如何从Puppeteer-Sharp记录JavaScript错误?

huangapple go评论67阅读模式
英文:

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?

英文:

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?

答案1

得分: 1

以下是已翻译的内容:

最好的我找到的是这个,来自 hardkoded/puppeteer-sharp 在 GitHub 上的问题

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

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}");
};

huangapple
  • 本文由 发表于 2023年2月14日 03:45:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/75440539.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定