Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PDF viewer failing on Edge (not based on Chromium) #297

Merged

Conversation

danxuliu
Copy link
Member

Since version v2.4.456 the PDF.js library is published as two different packages, a non-translated/non-polyfilled build for modern browsers and an ES5 compatible build for older browsers.

The PDF viewer was using the build for modern browsers, so it did not work, for example, on Edge (the original version not based on Chromium). This has been changed to use the ES5 build instead for maximum compatibility.

Unfortunately, the ES5 build requires allowing "unsafe-eval" in the iframe where the PDF.js library is loaded :-( Note that we had to fight this already in the past, but back then we just stayed on a version that happened to work. Now it seems that we either allow unsafe-eval in the iframe or we drop support for browser that are not compatible with the default PDF.js build (if we want to stay on an updated version, which we of course do ;-) ). See issue 11036 in https://github.com/mozilla/pdf.js/issues (not linked directly to avoid polluting the issue with more back references) for more information.

An even more unfortunate part of the history is that I found out that PDF.js provides an ES5 compatible package after wasting hours fighting with Babel, Webpack and so on 🤦 I am so frustrated right now :-P

How to test

  • Open the Files app in Edge (or, for example, Firefox 52)
  • Upload a PDF file
  • Click on the PDF file

Result with this pull request

The PDF file is shown.

Result without this pull request

The PDF file is not shown.

@danxuliu
Copy link
Member Author

/backport to stable20

Since version v2.4.456 the PDF.js library is published as two different
packages, a non-translated/non-polyfilled build for modern browsers and
an ES5 compatible build for older browsers.

The PDF viewer was using the build for modern browsers, so it did not
work, for example, on Edge (the original version not based on Chromium).
This has been changed to use the ES5 build instead for maximum
compatibility.

Unfortunately, the ES5 build requires allowing "unsafe-eval" in the
iframe where the PDF.js library is loaded.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
@danxuliu danxuliu force-pushed the fix-pdf-viewer-failing-on-edge-not-based-on-chromium branch from c5c49da to cf41c80 Compare January 28, 2021 13:01
@danxuliu danxuliu merged commit e02a5a0 into master Jan 28, 2021
@delete-merged-branch delete-merged-branch bot deleted the fix-pdf-viewer-failing-on-edge-not-based-on-chromium branch January 28, 2021 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants