Example 1 — Read pdfViewerEnabled
Log the current Boolean value.
console.log(navigator.pdfViewerEnabled); How It Works
Most modern desktop browsers return true. Some locked-down or minimal environments return false.

navigator.pdfViewerEnabled is a read-only Boolean that tells you whether the browser can show PDF files inline. Learn the MDN check pattern, how it replaces legacy MIME sniffing, UI messaging when PDFs download instead, five examples, and try-it labs.
Read-only property
Boolean
Widely available
Inline PDF OK
Download / external
Legacy PDF sniffing
Many apps link to invoices, manuals, or reports as PDF files. Users expect either an in-browser preview or a download. Guessing that behavior from old plugin / MIME lists was fragile.
navigator.pdfViewerEnabled answers one clear question: can this browser display PDFs inline when navigating to them? If not, the PDF is downloaded and may open in an external application.
MDN: this property replaces several legacy ways of inferring inline PDF support. Prefer it over digging through navigator.mimeTypes for application/pdf.
pdfViewerEnabled PropertyThink of it as a green / red light for inline PDF viewing. You read it once (or when choosing UI copy) — you never assign to it.
Navigator interface.General form of the property:
navigator.pdfViewerEnabled // MDN pattern:
if (!navigator.pdfViewerEnabled) {
// The browser does not support inline viewing of PDF files.
}
// Positive branch:
if (navigator.pdfViewerEnabled) {
console.log("Inline PDF viewing looks available");
} | Goal | Code |
|---|---|
| Read the flag | navigator.pdfViewerEnabled |
| No inline PDF? | if (!navigator.pdfViewerEnabled) { … } |
| Inline PDF OK? | if (navigator.pdfViewerEnabled) { … } |
| Type | typeof navigator.pdfViewerEnabled === "boolean" |
| Writable? | No (read-only) |
| Status (MDN) | Baseline Widely available |
Four facts to remember about navigator.pdfViewerEnabled.
booleantrue / false
widelySince March 2023
read-onlyNo assignment
PDF UXInline vs download
pdfViewerEnabled vs mimeTypesnavigator.pdfViewerEnabled | navigator.mimeTypes PDF check | |
|---|---|---|
| Question | Can PDFs open inline? | Is application/pdf listed? |
| API shape | Simple Boolean | MimeTypeArray membership |
| MDN guidance | Preferred for new code | Legacy / secondary signal |
| Typical use | Choose link / embed UX | Older detection scripts |
| Use together? | Optional for debugging — make production PDF decisions with pdfViewerEnabled | |
Examples follow MDN navigator.pdfViewerEnabled patterns. Prefer Try It Yourself to inspect your browser. Use View Output for expected messaging.
Read the Boolean and apply the MDN check.
pdfViewerEnabledLog the current Boolean value.
console.log(navigator.pdfViewerEnabled); Most modern desktop browsers return true. Some locked-down or minimal environments return false.
if (!pdfViewerEnabled) CheckBranch when inline PDF viewing is not supported.
if (!navigator.pdfViewerEnabled) {
console.log("Inline PDF viewing not supported");
} else {
console.log("Inline PDF viewing looks available");
} This is MDN’s recommended shape: treat false as “expect download / external handling.”
User messaging, legacy comparison, and a reusable helper.
Build copy for a docs / invoice download button.
const msg = navigator.pdfViewerEnabled
? "PDF will open in the browser when possible."
: "PDF will download — open it with a PDF app.";
console.log(msg); Set expectations before the click so a download does not feel like a broken preview.
mimeTypesSee how the modern flag relates to the old PDF MIME check.
const pdfEnabled = Boolean(navigator.pdfViewerEnabled);
const mimePdf =
navigator.mimeTypes && "application/pdf" in navigator.mimeTypes;
console.log("pdfViewerEnabled: " + pdfEnabled);
console.log("mimeTypes has application/pdf: " + Boolean(mimePdf));
console.log("Prefer pdfViewerEnabled for new PDF UI decisions"); They often agree on modern browsers. Still use pdfViewerEnabled as the primary decision API.
Return a small object you can reuse in UI components.
function pdfViewStatus() {
const inline = Boolean(navigator.pdfViewerEnabled);
return {
inline,
suggestedTarget: inline ? "_blank" : "_self",
tip: inline
? "Open PDF in a new tab for an inline preview."
: "Expect a download; offer a clear Download PDF label."
};
}
console.log(JSON.stringify(pdfViewStatus(), null, 2)); Keep the Boolean as the source of truth; derive labels and link targets from it.
pdfViewerEnabled in support debug panels.navigator.pdfViewerEnabled WorksAccess navigator.pdfViewerEnabled in your script.
Returns true if inline PDF viewing is supported.
Choose preview, new-tab, or download-oriented messaging.
Prefer this flag over old mimeTypes / plugin checks.
Navigator.navigator.pdfViewerEnabled is Baseline Widely available across modern browsers (MDN: since March 2023). Use it as the primary check for inline PDF viewing support.
Read the Boolean to choose View vs Download messaging. Prefer it over legacy mimeTypes PDF sniffing.
Bottom line: Check navigator.pdfViewerEnabled, warn when false, and keep production PDF UI decisions on this Baseline Boolean.
navigator.pdfViewerEnabled is a simple, Baseline Boolean for inline PDF viewing. Use the MDN if (!navigator.pdfViewerEnabled) pattern to set expectations, and prefer it over legacy mimeTypes sniffing.
Continue with permissions, mimeTypes, or the JavaScript hub.
falsetrue overrides Content-Disposition: attachmentpdfViewerEnabledfalsepdfViewerEnabledBaseline Boolean — inline PDF viewing or download.
boolean
TypeInline PDF OK
PreviewDownload / external
Fallbackread-only
APIBaseline
ModernBefore pdfViewerEnabled, sites often probed plugins or navigator.mimeTypes["application/pdf"]. Those signals became noisy as browsers reduced plugin APIs for privacy and security — this Boolean is the clean replacement.
Permissions API entry point for granted / prompt / denied.
8 people found this page helpful