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
JavaScript Message Listener
With IronPDF's ChromePdfRenderOptions.JavascriptMessageListener property, you may add a Method callback to be invoked whenever a browser console message becomes available. Learn more about this feature by visiting the IronPDF Documentation on Javascript Console Messages.
Related Docs Links
Ready to get started? Version: 2024.12 just released