How to prevent links from being opened on a PDF in WebViewer?

Here is the code snippet where you can override the function that gets called when a link is being opened:

In WebViewer 8.3+:

WebViewer(
  {
    initialDoc: 'mydoc.pdf',
    path: '/lib',
  },
  document.getElementById('viewer')
).then((instance) => {
  const { Actions, Annotations } = instance.Core;

  Actions.setCustomOnTriggeredHandler(Actions.URI, (target, event, documentViewer, options) => {
    if (target instanceof Annotations.Link) {
      return;
    }
    options.originalOnTriggered(target, event, documentViewer);
  });
});

In older versions:

WebViewer(
  {
    initialDoc: 'mydoc.pdf',
    path: '/lib',
  },
  document.getElementById('viewer')
).then((instance) => {
  const { Actions, Annotations } = instance;
  const onTriggered = Actions.URI.prototype.onTriggered;
  Actions.URI.prototype.onTriggered = function(target, event) {
    if (target instanceof Annotations.Link) {
      return;
    }
    onTriggered.apply(this, arguments);
  };
});