PDFObject
PDFObject copied to clipboard
Navigator.pdfViewerEnabled support?
Are there plans to integrate Navigator.pdfViewerEnabled
as a replacement for Navigator.mimetypes
?
https://caniuse.com/mdn-api_navigator_pdfviewerenabled
Hi Janne. Yes, I plan to incorporate pdfViewerEnabled
. I've been waiting for it to be more widely supported. Thanks for the reminder, it looks like all the major browser vendors made a big push over the past year to roll out pdfViewerEnabled
. Safari iOS finally adopted it in March as part of iOS 16.
There are still plenty of older browsers and OSes that won't support pdfViewerEnabled
, so there will need to be conditional logic that falls back to the older approaches when needed.
I don't have an ETA but I'll work on it soon.
The logic would look something like this. First, use the pdfViewerEnabled
value if there is one. Second, exclude mobile devices. Third, check for a modern browser, PDF.js, etc.
function supportsPDFs() {
let pdfViewerEnabled = window.navigator.pdfViewerEnabled;
if (typeof pdfViewerEnabled === "boolean") {
return pdfViewerEnabled;
}
if (isMobileDevice) {
return false;
}
if (isModernBrowser || isFirefoxWithPDFJS || (isIE && supportsPdfActiveX())) {
return true;
}
return false;
}
Thanks, yes this is the direction I'm headed. I also plan to refactor to eliminate unnecessary checks/declarations where possible, such as the IE ActiveX check.
@jhyot I just uploaded a beta version of 2.3 which has some significant changes, including introducing navigator.pdfViewerEnabled
. I've tested against all major browsers, locally and via BrowserStack. Everything works as expected in my tests.
I'd appreciate it if you can check it out and let me know if you encounter any issues. https://pdfobject.com/dev/ and https://github.com/pipwerks/PDFObject/tree/2.3-dev (changes are listed in the 2.3 branch readme). Thanks
I haven't done extensive testing, but I read through the recent commits, and it looks good to me. The only problem I noticed (a missing typeof
) was already fixed.
Does the mobile browser support change after this? Is there a updated table somewhere which mobile browsers work?
Mobile browsers still do not support inline PDFs. https://caniuse.com/pdf-viewer
Safari for iOS displays the first page of a PDF, and without any PDF toolbar, so it's considered a broken implementation.
@jhyot I just uploaded a beta version of 2.3 which has some significant changes, including introducing
navigator.pdfViewerEnabled
. I've tested against all major browsers, locally and via BrowserStack. Everything works as expected in my tests.I'd appreciate it if you can check it out and let me know if you encounter any issues. https://pdfobject.com/dev/ and https://github.com/pipwerks/PDFObject/tree/2.3-dev (changes are listed in the 2.3 branch readme). Thanks
@pipwerks I am currently not using PDFObject, so cannot test it (my original question arose during evaluation whether we could use it in future)