After upgrading Webviewer from 7.x to 8.z rendering events not triggered

In current code we use the eventlisteners beginRendering and finishedRendering to measure the end user experience. After upgrading the WebViewer from 7.3.3 to 8.1 these events are not triggered anymore.

In the documentation these events seem to have been unchanged.
https://www.pdftron.com/api/web/Core.DocumentViewer.html#event:finishedRendering

Other events like documentLoaded and loaderror are still working as expected.

Am i overlooking something?

Cheers,
Peter

Hi Peter,

I just tried this in WebViewer 8.1 and it seems to be working for me. Here is the code I used to test it:

const { documentViewer } = instance.Core;

documentViewer.addEventListener('beginRendering', () => {
  console.log('begin rendering');
});

documentViewer.addEventListener('finishedRendering', () => {
  console.log('finish rendering');
});

Can you provide me the steps you used to test it so I can reproduce on my end?

Matt

Hi Matt,

Code looks like this;

const webviewerInstance = instance => {
    ...
instance.iframeWindow.addEventListener('loaderror', function (err) {
   ....
});

instance.iframeWindow.addEventListener('documentLoaded', () => {
   ...
});

instance.iframeWindow.addEventListener('beginRendering', () => {
   ...
});

instance.iframeWindow.addEventListener('finishedRendering', () => {
   ...
});

The documentLoaded and loaderror events in the example above are handled, beginRendering and finishedRendering not. Based on your example is see that the addEventListerer has been moved to Core. (And reviewing the code further detect some more missed method migrations from instance to instance.Core and instance.UI

const webviewerInstance = instance => {

const { documentViewer } = instance.Core;
    ...
documentViewer .addEventListener('loaderror', function (err) {
   ....
});

documentViewer.addEventListener('documentLoaded', () => {
   ...
});

documentViewer.addEventListener('beginRendering', () => {
   ...
});

documentViewer.addEventListener('finishedRendering', () => {
   ...
});

Seems that in 8.x for some events and methods aliaseses are in place for the ‘old’ version of the WebViewer, and therefore 7.x syntax still works on 8.x for some methods. For example setTheme is still available on the instance as well as in instance.UI

Cheers,
Peter

Hmm, I just tried with your code with the events on the iframeWindow in 7.3.3 and I don’t see the beginRendering or finishedRendering events being handled, which is what I would expect since they’re fired on DocumentViewer.

Events that would be handled on instance.iframeWindow in version 7.x are now found on instance.UI in 8.x. You can see the list of UI events here PDFTron WebViewer Namespace: UI

Other events that were on DocumentViewer previously should continue to be there PDFTron WebViewer Class: DocumentViewer

Note that documentLoaded is currently on both since historically it’s been part of the UI and we’ve kept it for backwards compatibility, but it’s also on DocumentViewer because you can load DocumentViewer directly without the WebViewer UI and it’s useful in that scenario.

So if in doubt about where the event should be I would recommend referring to the API docs as it should list out which events are fired on which objects.

Matt