Firefox issues with PDFtron WebViewer intialization

Hi there,

We are using the WebViewer successfully in Chrome to do some text searching on PDF documents, however the same code fails on Firefox. This is the setup code (using Webpacker for assets) -

CoreControls.setWorkerPath(’/packs/webviewer/core’)
PDFNet.initialize()
.then(() => PDFNet.addResourceSearchPath(’/packs/webviewer’))
.then(() => {
setSearchTerms(terms)
setSearchCount(0)
})

In Firefox, we get the following error in console -

Unknown action from worker: pdfNetAddResourceSearchPath PDFworker.js:1:13232
Error: Unknown action from worker: pdfNetAddResourceSearchPath

As far as I’m aware, the WebViewer is supported across major browsers. Anything we might be doing wrong?

Thanks,
Xavier Hocquet

You are using WebViewer in full mode and without WebViewer UI? Have you loaded PDFNet.js file?

Sardor Isakov

Software Developer

PDFTron Systems, Inc.

I’m not the main developer on this side of things so apologies if anything sounds confusing coming from me.

It looks like we are loading both in order to use CoreControls to use some of the searching functionality. We are using the WebViewer UI to display documents. We have the following included in the page -

And just to reiterate, the same method calls work successfully in Chrome.

Thanks

Xavier

New forum account for tracking replies. Latest response from Google Groups -

No, there are no network errors during page load or the error for this action. Both PDFnet.js and CoreControls.js are loaded successfully

Unfortunately, I cannot reproduce this error, I used this setup and opened in Chrome and Firefox:

((exports) => {

  CoreControls.setWorkerPath('../../../core');
  PDFNet.initialize().then(
    () => PDFNet.addResourceSearchPath('/packs/webviewer')
  ).then(
    () => {
      setSearchTerms(terms);
      setSearchCount(0);
    }
  );

})(window);

========
HTML

<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <link rel="stylesheet" href="../../style.css">
    <script src="../../../core/CoreControls.js"></script>
    <script src="../../../core/pdf/PDFNet.js"></script>
    <title>JavaScript PDF Viewer Demo</title>
  </head>
  <body>
    <div id="viewer"></div>
    <script src="test.js"></script>
  </body>
</html>

However I cannot see error messages.

Would you be able to share the whole setup?

Hey, thanks for the feedback however we’ve identified our issue. There were two -

  • First, we were still using display: none; somewhere in a parent component which is a known issue with Firefox and PDFtron Webviewer
  • Second, we were loading the CoreControls in additional to WebViewer.js, when we could just get CoreControls from the WebViewer import in the first place

That sounds great that you were able to find the cause of the issue. Let us know if anything else comes up.