PDFObject icon indicating copy to clipboard operation
PDFObject copied to clipboard

Navigator.pdfViewerEnabled support?

Open jhyot opened this issue 1 year ago • 8 comments

Are there plans to integrate Navigator.pdfViewerEnabled as a replacement for Navigator.mimetypes? https://caniuse.com/mdn-api_navigator_pdfviewerenabled

jhyot avatar Jun 20 '23 13:06 jhyot

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.

pipwerks avatar Jun 21 '23 05:06 pipwerks

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;
}

theodore-s-beers avatar Jun 22 '23 14:06 theodore-s-beers

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.

pipwerks avatar Jun 22 '23 22:06 pipwerks

@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 avatar Jun 23 '23 23:06 pipwerks

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.

theodore-s-beers avatar Jun 25 '23 15:06 theodore-s-beers

Does the mobile browser support change after this? Is there a updated table somewhere which mobile browsers work?

silverwind avatar Jun 27 '23 18:06 silverwind

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.

pipwerks avatar Jun 27 '23 20:06 pipwerks

@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)

jhyot avatar Jun 28 '23 13:06 jhyot