Optimized deployment of Webviewer breaks on Chrome browsers with version 92 and higher

Product: WebViewer

Product Version: 7.3.* , 8.*

Please give a brief summary of your issue:
After rolling out version 92+ of Google Chrome browser WebViewer reports error “Failed to find PDF worker files. This project is not set up to work with PDF files”

Please describe your issue and provide steps to reproduce it:
The current build of our applications creates an optimized version of WebViewer for our organization. Since we only use Google Chrome and Edge Chromium the wasm and asm.js versions of the PDF SDK are excluded. The past few weeks the organization started to deploy version 92 of the browsers. Immediately after a user received this version, the WebViewer was not able to open the PDF files anymore.

When reproducing the issue locally with disableLogs: false, i detected three warnings indication the cause;

PDFworker.js?isfull=false&disableLogs=0:46 Failed to load lean/PDFNetCWasm.br.js.mem
PDFworker.js?isfull=false&disableLogs=0:46 Failed to load lean/PDFNetCWasm.gz.js.mem
PDFworker.js?isfull=false&disableLogs=0:46 Failed to load lean/PDFNetCWasm.js

Instead of loading the available ThreadedWasm files it now attempts to load the Wasm files, which are not available in our build. Adding the Wasm files to the build resolves the error messages and restores the functionality to open PDF files. (No full regression test executed though)

Instead of loading the available ThreadedWasm files it now attempts to load the Wasm files, which are not available in our build. Adding the Wasm files to the build resolves the error messages and restores the functionality to open PDF files. (No full regression test executed though)

When opening the application in Chrome 91 the following warning was logged by the browser;

CoreControls.js:541 [Deprecation] SharedArrayBuffer will require cross-origin isolation as of M91, around May 2021. See https://developer.chrome.com/blog/enabling-shared-array-buffer/ for more details.

Since the SharedArrayBuffer has been removed in version 92, i am confident hat this is the issue. On line 541 of CoreControls the WebAssembly is loaded as in instance of the SharedArrayBuffer.

new WebAssembly.Memory({initial:1,maximum:1,shared:!0})).buffer instanceof w.SharedArrayBuffer}}c

Please provide a link to a minimal sample where the issue is reproducible:

Hello,
Thanks for contacting us for support.
Chrome 92 requires a new configuration if you want to be able to load WebAssembly threads https://www.pdftron.com/documentation/web/faq/wasm-threads/
The reason why you got the error and why you no longer got the error when you added files back is that you deleted the files required for non-threaded workers
Here are two solutions:

  1. you can try to follow those steps on the guide so that threads work again
  2. if you are not able to configure it you can add the non-threaded worker files back

Hi Jhou,

I added the Cross-Origin-Embedder-Policy and Cross-Origin-Opener-Policy to the response headers.
New Jack out the box is that the Cross-Origin-Opener-Policy requires that the response is delivered using the HTTPS protocol or ‘localhost’ is used as the origin. So locally it does work, remainins me to enablin SSL on our development and test environments after receiving the proper certificates.

Cheers,
Peter

Hi Peter
Let us know if you have other questions

Best,
Jack

Hi Jack,

Seems that the issue is back in Chrome 94. Could not find any references in the Chrome 94 updates;

Uncaught (in promise) h {name: 'WorkerError', stack: 'WorkerError: The worker has encountered an error\n …er/assets/webviewer/core/CoreControls.js:117:372)', message: 'The worker has encountered an error', userMessage: 'error.EmsWorkerError'}

When opening in Chrome 93 there is no issue.
Chrome Version 94.0.4606.81 (64-bits) breaks
Microsoft Edge Version 94.0.992.38 (32-bits) still works fine.

Hi Peter
Could you please give us your configuration so that we can deep-dive your issue? We just checked on our showcase in Chrome 94 and threads seem to be working https://www.pdftron.com/webviewer/demo/

Best,
Jack

Hi Jack,

As mentioned we use(d) an optimized version of PDFTron. Because the application is an AngularjJS (1.8) application and Grunt is used as the build tool we had to write our own optimization. This optimizations was based on the 7.3.0 optimizer-for-prod.js script. The Grunt config for the optimization was;

   npm_static_assets: [
      /* Interpretation of PDFtron optimize-for-prod.js and
       * https://www.pdftron.com/documentation/web/guides/optimizing-lib-folder/#optimize-via-script
       */
      /* Base PDFTron files */
      {
        src: '*',
        cwd: 'node_modules/@pdftron/webviewer/public/core',
        dest: 'build/assets/webviewer/core',
        expand: true
      },
      {
        src: '**/*',
        cwd: 'node_modules/@pdftron/webviewer/public/core/assets',
        dest: 'build/assets/webviewer/core/assets',
        expand: true
      },
      {
        src: '**/*',
        cwd: 'node_modules/@pdftron/webviewer/public/core/external',
        dest: 'build/assets/webviewer/core/external',
        expand: true
      },
      /*  Base /pdf files */
      {
        src: ['pdfnet.res', 'PDFworker.js', 'ResizableWorker.js', 'iframe.html', 'WasmThread.js'],
        cwd: 'node_modules/@pdftron/webviewer/public/core/pdf',
        dest: 'build/assets/webviewer/core/pdf',
        expand: true
      },
      /* /pdf/lean ThreadedWasm files for full API */
      {
        src: '*ThreadedWasm*',
        cwd: 'node_modules/@pdftron/webviewer/public/core/pdf/lean',
        dest: 'build/assets/webviewer/core/pdf/lean',
        filter: 'isFile',
        expand: true
      },
      {
        src: ['MemGrow.wasm', 'MemGrow.worker.js'],
        cwd: 'node_modules/@pdftron/webviewer/public/core/pdf/simple_wasm',
        dest: 'build/assets/webviewer/core/pdf/simple_wasm',
        filter: 'isFile',
        expand: true
      },
      /* ui folder */
      {
        src: '**/*',
        cwd: 'node_modules/@pdftron/webviewer/public/ui',
        dest: 'build/assets/webviewer/ui',
        expand: true
      }
    ]

This config, using ThreadedWasm only, worked fine up-till Chrome 93. Due to another issue where PDFTron changes to tablet mode in lower resolutions we also had to upgrade to PDFTron 8. PDFTron had similar issues with version 8. I re-evaluated the optimizer-for-prod.js scriptin version 8 and changed the following in the optimized version.

  • Added PDFNet.js
  • Changed from Lean to Full (and change fullAPI: true in config)
  • Added all Wasm files, not only threadedwasm
  • Added ‘MemGrow.js.mem’, ‘MemGrow.js’

So in short, with the following optimized build on 8.1 it works in Chrome 94

 npm_static_assets: [
      /* Interpretation of PDFtron optimize-for-prod.js and
       * https://www.pdftron.com/documentation/web/guides/optimizing-lib-folder/#optimize-via-script
       */
      /* Base PDFTron files */
      {
        src: '*',
        cwd: 'node_modules/@pdftron/webviewer/public/core',
        dest: 'build/assets/webviewer/core',
        expand: true
      },
      {
        src: '**/*',
        cwd: 'node_modules/@pdftron/webviewer/public/core/assets',
        dest: 'build/assets/webviewer/core/assets',
        expand: true
      },
      {
        src: '**/*',
        cwd: 'node_modules/@pdftron/webviewer/public/core/external',
        dest: 'build/assets/webviewer/core/external',
        expand: true
      },
      /*  Base /pdf files */
      {
        src: ['pdfnet.res', 'PDFNet.js', 'PDFworker.js', 'ResizableWorker.js', 'iframe.html', 'WasmThread.js'],
        cwd: 'node_modules/@pdftron/webviewer/public/core/pdf',
        dest: 'build/assets/webviewer/core/pdf',
        expand: true
      },
      /* /pdf/lean ThreadedWasm files for full API */
      {
        src: '*',
        cwd: 'node_modules/@pdftron/webviewer/public/core/pdf/full',
        dest: 'build/assets/webviewer/core/pdf/full',
        filter: 'isFile',
        expand: true
      },
      {
        src: ['MemGrow.wasm', 'MemGrow.worker.js', 'MemGrow.js.mem', 'MemGrow.js'],
        cwd: 'node_modules/@pdftron/webviewer/public/core/pdf/simple_wasm',
        dest: 'build/assets/webviewer/core/pdf/simple_wasm',
        filter: 'isFile',
        expand: true
      },
      /* ui folder */
      {
        src: '**/*',
        cwd: 'node_modules/@pdftron/webviewer/public/ui',
        dest: 'build/assets/webviewer/ui',
        expand: true
      }
    ]

Hi Peter,
Just confused, do you mean you fixed the issue according to the following optimized build on 8.1?

Best,
Jack

Hi Jack,

We had to upgrade to 8.x anyway because we needed to enable DesktopModeOnly, a feature which was not available in 7.x.

So i upgraded WebViewer to 8.3 AND re-evaluated the optimizer-for-prod.js script. Based on that re-evaluation i adapted our script based on these results. After that i compared our optimized build with the version in de node_modules folder after running the optimizer-for-prod.js script.

Also with 92+ i actually meant version 93 and higher, version 92 worked as expected. Optimized build broke in our case after upgrading the Chromium engine to 93. Sorry about being unclear in that.

Cheers,
Peter

Hi Peter
Thanks for your information. However, it is still hard for me to reproduce your issue. Can you provide your code with your environment so that I can directly run it?

Jack