-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Consider a standardized way to detect PDF in HTML? #3462
Comments
This makes sense to me; although navigator.plugins/mimeTypes are kind of weird implementation-defined voodoo-land, they are web-observable, and to the extent people are depending on them we should probably try to lock them down. Especially if that can be useful for web authors. My Safari Tech Preview install also has similar entries, including both application/pdf and text/pdf. It seems like one way to detect in a cross-browser way today is const supportsPDF = "application/pdf" in navigator.mimeTypes; Do you think we should codify this in the standard somehow, beyond what is already there in the spec for navigator.plugins/navigator.mimeTypes? What's there seems pretty good to me, but perhaps you had something specific in mind? |
That's a nice feature detect, and probably good enough for a casual check. What I don't know is whether there is some deeper behavior that sites are somehow trying to take advantage of with their more complex checks, e.g., looking for specific name or description values. If there really aren't web-facing feature differentiation in the various PDF implementations, then perhaps suggesting a "typical" generic PDF entry in the plugins collection would help encourage use of the simple feature detect you note above. |
Hmm, I see. My guess would be that sites weren't aware you could write such simple feature detection code, but I'm not sure. Do you think we should address this at the authoring guidance level, e.g. give advice on how to feature detect PDF? Or at the browser level, by e.g. giving advice that all browsers include one of the three strings you listed in your example in the OP for the |
I think it would be fine to include "application/pdf" if it's supported via the internal viewer. Exactly where and how it's included would need to be specced, of course. The inconsistency with other internally-supported types (HTML, images, JSON, various XML types, etc) is a bit annoying, of course. Is PDF the only type we need to worry about here? Firefox used to report all types supported via internal viewer or plug-in or helper app in navigator.mimeTypes until we changed to our current behavior in https://bugzilla.mozilla.org/show_bug.cgi?id=1144204, so it's possible the more-complicated detects are trying to work around that.... |
I'd be interested in a concrete proposal for something browser-level. E.g. we could specify just application/pdf, but everyone already does that, and that wouldn't suffice for the |
Firefox doesn't, fwiw. |
... I could swear I tested .... at least on my work computer ... but on my home computer both mimeTypes and plugins are empty, indeed. I'm prepared to say I was misremembering my work computer's results. That does make things more interesting. |
I looked through here, but didn't see anything specific to PDF... I'd love to clear-out our plugins/mimeTypes collections like Firefox has done :-) Maybe we could add a simple feature-detect property in the spirt of legacy |
Right, nothing specific to PDF, but unless a browser believes it doesn't support application/pdf, or specifically desires not to expose its support for it, the spec says you should include it. We could call it out as a specific case that's been found important for web compat, to be sure, and after realizing Firefox doesn't have anything there, that seems like an especially good idea. With regard to further work, I'd again like to clarify our goals. I've seen three in this thread so far:
These each have rather different solutions in my mind. I'll hide them behind a My solutions for 1, 2, and 3
|
No, it doesn't. The spec says:
And it explicitly says that
The built-in PDF renderer in Firefox does in fact act as a child browsing contet and does in fact introduce Node objects to the Document's DOM. So per a not-between-the-lines reading of the spec, it is not a "plugin" and must not be reflected in Now you could argue that the spec doesn't say what it means, but Firefox does implement exactly what the spec says (and in fact we changed our implementation to not expose |
Ah OK, I didn't realize that's how Firefox implemented it, although it makes sense now that I think about how pdf.js works. Interesting. It seems that given this, the current spec mechanism doesn't serve well for feature detection of "can the browser view this MIME type". We could either introduce a new mechanism for that, or we could revise the spec to change the meaning of navigator.mimeTypes/plugins, on the grounds that the revised definition is more useful. |
Before exploring solutions involving a new API, I would like to gain a better understanding of the problem to be solved first.
Adding a formal API to detect PDF support would increase the user's fingerprint. Before adding it there ought to be a strong argument in favour of websites behaving differently depending on whether the browser includes PDF support, versus making it impossible to detect through mimeTypes/plugins. |
Regarding use cases, I can think of two off the top of my head:
For case 1, some in-browser feature detect is really helpful. If the support can't be detected, it's likely that the UA will re-direct the resource request to another content handler on the system (if one is installed), and the experience will not be seamless in the browser as expected). For case 2 (maybe the majority of situations), I don't know that there's a way the web platform can provide this information reliably. Since there is no "isContentHandlerInstalled" that might be able to query the OS's content handler info, it's just hit-or-miss whether clicking the link will allow the user to view the PDF. Of course, if the PDF support is advertised as a browser-supported feature, then the site at least has that guarantee on a particular UA (and doesn't need to put up the PDF reader notice). Yes, there is an increase in fingerprinting risk, though the ubiquity of PDF reader support in the browser means this impact would be negligible, I think. |
OK, but what action would the site take if support is not detected? For example, I have pdf.js turned off in Firefox explicitly because I do not want my PDFs rendering in iframes like this... ;)
Note that Firefox used to provide that information in navigator.mimeTypes until we stopped.
People can and do disable PDF support in their browsers. Witness all the threads asking how to do it in Chrome (not too simple, but they do have a UI for it). |
@travisleithead Thanks for providing some use cases. I can recognise the utility in the first case (though I prefer PDFs to stay in their own context), but for the second I think it'd be more appropriate for the browser or OS to suggest a way to open PDF files rather than the website. I should be clear - my main concern with this API (besides fingerprinting) is that it might end up being used to hide PDF files from user agents which do not advertise built-in support. Whether done intentionally or not, this would negatively impact those who require an external reader and might eventually force non-PDF supporting user agents to lie about their support in order to receive access to the document at all. I feel that this risk outweighs the potential utility of an API, though I understand that this argument may not resonate with everyone. I'm satisfied now that I've voiced my concern. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
It seems that all browsers support rendering PDFs in a nested browsing context so rather than detection I think we might have to say something about that. (When it works, whether MIME types are enforced, etc.) |
Oh cool, we closed a 3.5 year old issue :) 6770de4 |
(for anyone finding this in google, and hoping to find a solution... at present there doesn't seem to be any browser support for |
After running across a site interoperability issues in Edge, we'd like to raise the possibility of a standard (or suggested) way for surfacing a UA's support of PDFs. Would love both opinions and proposals.
Today, among Chrome, Edge, and Firefox, Chrome and Edge both add an entry (or entries) into the
navigator.plugins
andnavigator.mimeTypes
collections such as:{type: "application/pdf", suffixes: "pdf", description: ""}
{type: "application/x-google-chrome-pdf", suffixes: "pdf", description: "Portable Document Format"}
{type: "application/pdf", suffixes: "pdf", description: "Edge PDF Viewer"}
E.g., the site
honda.it
tries to detect a variety of potential strings here:var p=["Chrome PDF Viewer","WebKit built-in PDF","Adobe Acrobat"];
Sites are starting to take an interest in these. Perhaps we should come up with a vender-neutral way of advertising support for PDF?
The text was updated successfully, but these errors were encountered: