JavaScript消息监听器
利用 IronPDF 的 "ChromePdfRenderOptions.JavascriptMessageListener "属性,你可以添加一个方法回调,以便在浏览器控制台消息可用时调用。 请访问IronPdf 有关 Javascript 控制台消息的文档.
using IronPdf; using System; var renderOptions = new ChromePdfRenderOptions { // Method callback to be invoked whenever a browser console message becomes available: JavascriptMessageListener = message => Console.WriteLine($"JS: {message}"), Javascript = "console.log('foo');", }; var pdf = new ChromePdfRenderer { RenderingOptions = renderOptions }.RenderHtmlAsPdf("<h1> Hello World </h1>"); // Example of JavaScript that will cause an error: renderOptions.Javascript = "document.querySelector('non-existent').style.color='foo';"; // message => Uncaught TypeError: Cannot read properties of null (reading 'style')
Imports IronPdf Imports System Private renderOptions = New ChromePdfRenderOptions With { .JavascriptMessageListener = Sub(message) Console.WriteLine($"JS: {message}"), .Javascript = "console.log('foo');" } Private pdf = New ChromePdfRenderer With {.RenderingOptions = renderOptions}.RenderHtmlAsPdf("<h1> Hello World </h1>") ' Example of JavaScript that will cause an error: renderOptions.Javascript = "document.querySelector('non-existent').style.color='foo';" ' message => Uncaught TypeError: Cannot read properties of null (reading 'style')
Install-Package IronPdf
利用 IronPDF 的 "ChromePdfRenderOptions.JavascriptMessageListener "属性,你可以添加一个方法回调,以便在浏览器控制台消息可用时调用。 请访问IronPdf 有关 Javascript 控制台消息的文档.