pipwerks / PDFObject

A lightweight JavaScript utility for dynamically embedding PDFs in HTML documents.
http://pdfobject.com/
Other
2.39k stars 986 forks source link

Firefox parameter pdfjs.disabled is not detected #266

Closed SuperPat45 closed 2 years ago

SuperPat45 commented 2 years ago

Firefox has the ability to disable PDF rendering with the parameter pdfjs.disabled. PDFObject does not detect this, so the PDF is not rendered, but downloaded.

I am afraid that it is undetectable without causing a download.

I met an organization that disabled it and in this case PDFObject can not help me

theodore-s-beers commented 2 years ago

You could try with the forcePDFJS option.

I just tested this in Firefox. Set pdfjs.disabled and clicked around Philip's examples to see if any of them worked. The one with forcePDFJS does. I guess this is a way of circumventing the browser config.

pipwerks commented 2 years ago

Firefox purposely prevents web pages from being able to detect PDF support, as an anti-fingerprinting technique.

Unfortunately, there's not much we can do on the PDFObject side, since Firefox disables feature detection. Two potential workarounds if you're concerned about pdfjs.disabled being set to true: 1. Add a snippet of text above your embed that says "Can't see the PDF? Click here" (or similar), with the link triggering a forced PDFJS embed, or 2. Always place a link for downloading the PDF next to your embedded PDF. Both options provide access to the PDF in situations where the browser won't render the PDF, including Firefox when pdfjs.disabled is true and on Android and iOS devices, which don't natively support PDF embeds.

SuperPat45 commented 2 years ago

Since Firefox 99 and Chrome 94, it can now be detected with the parameter : navigator.pdfViewerEnabled

https://developer.mozilla.org/en-US/docs/Web/API/Navigator/pdfViewerEnabled

PDFObject should rely on this!

pipwerks commented 2 years ago

Hey, that's great. I hadn't heard. It's about time! I will look into it.

pipwerks commented 2 years ago

@SuperPat45 FYI, I will be incorporating a check for navigator.pdfViewerEnabled in an upcoming release, but navigator.pdfViewerEnabled is not fully supported by all browsers yet, so it's not a simple drop-in replacement. Still, great to see it available and actively supported by most browsers!