Document jumps back to first page

Q:
We are programmatically setting the current page in WebViewer on the documentLoaded event but after a second WebViewer jumps back to the first page on some files. Why is happening and how can I fix it?

A:
This is likely because the document has an “open” action that sets the current page to the first page. WebViewer includes the action as part of the XFDF data and parses this asynchronously so there might be a bit of a delay before the open action is triggered.

To work around this what you can do is ignore any GoTo open actions that are triggered on the document.

const { Actions, docViewer } = instance;
const onTriggered = Actions.GoTo.prototype.onTriggered;
Actions.GoTo.prototype.onTriggered = function(target, event) {
  if (target === docViewer.getDocument() && event.name === 'Open') {
    return;
}

  onTriggered.apply(this, arguments);
};