Custom error handling when loading PDFs

Hi I’m using (still) WebViewer 5.1.0. Is there a way to custom handle errors occurring when loading pdfs? For instance, I have a .png file which I renamed to .pdf, thus making it an “invalid pdf”. When I try to load it with the webViewer I get an error in the console (which is correct): “Uncaught (in promise) PDF header not found. The file is not a valid PDF document.”
I would like to be able to intercept such errors and execute my own callback if possible.
I have added
$(document).on(‘error’, function(e) { //some code })
$(window).on(‘error’, function(e) { //some code })

in my config.js file but none of that works. Is there a chance to set a custom callback?
Best regards


Would you be able to try this approach? Here:

window.addEventListener(‘loaderror’, function(error) {
var error = error.detail?.message || error.detail || error.message;
console.log("Error occured: ", error);//or any message

Best Regards,
Sardor Isakov
Software Developer
PDFTron Systems, Inc.

Hello, does the error object have status and message properties? Or maybe I’m doing something wrong? Because in my case I only get the detail property and I need to be able to show the user a more descriptive error.