Clear error message

Product: WebViewer

Product Version: 8.3.0-20211201

Please give a brief summary of your issue:

We’re displaying a custom error message in loadDocument's onError callback, i.e.

webViewer.Core.documentViewer.loadDocument(documentMeta.source, {
    onError(error) {
        // ...
        webViewer.UI.showErrorMessage('Unable to preview file.');

Is there a way to clear this error message when loading a subsequent document given a single instantiation of WebViewer? Should the error message automatically be cleared when webViewer.UI.closeDocument() is invoked?


You can close the modal with instance.UI.closeElements: PDFTron WebViewer Namespace: UI. Here is a guide on it as well:

Currently, the error modal component is not hooked up to close when the document viewer triggers an unload event. This is likely since there were a few cases when the error needs to be up once the document is closed. You can listen for the documentUnloaded event (PDFTron WebViewer Class: DocumentViewer) yourself and close the modal when the closeDocument API is called.

Andy Huang


This doesn’t seem to work immediately in the close context (i.e. the dialog is still visible when the next document loads):


Does the UI need to be additionally refreshed?

Hm, I am not sure how you are using the code but it seems to work fine when I am testing.


In my testing, I first handle closing the modal on documentUnload:

instance.docViewer.addEventListener('documentUnloaded', () => {

I have a preloaded document but I call showErrorMessage shortly after to make the modal appear.

instance.UI.showErrorMessage('Unable to preview file.');

I then use closeDocument to close the document and I reload another document. The modal does not reappear or stay on the viewer after doing so.

Are there specific steps you are taking? Does it only occur for you if you use onError?

Does it only occur for you if you use onError ?

Yes, this issue does seemed to be scoped to the onError callback context, i.e.

  1. load a problematic document that results in an error (i.e. source URL 400s)
  2. load another document (the error modal remains visible)
  3. load another document (the error modal clears)

Hm, I don’t seem to be able to reproduce this. The onError doesn’t seem to trigger on my end. Perhaps you could try listening to this instead?

Otherwise, I might need the file you were testing with or sample where the issue is reproducible.