mozilla/pdf.js · error · Error
app.viewerType is read-only
Error message
app.viewerType is read-only
What it means
app.viewerType exposes the compiled VIEWER_TYPE constant (identifying PDF.js as the viewer). It is fixed per build and read-only; the setter throws. The throw prevents spoofing the viewer identity.
Source
Thrown at src/scripting_api/app.js:388
/* has been deprecated and it's now equivalent to toolbar */
this.toolbar = value;
}
get toolbarVertical() {
return this.toolbar;
}
set toolbarVertical(value) {
/* has been deprecated and it's now equivalent to toolbar */
this.toolbar = value;
}
get viewerType() {
return VIEWER_TYPE;
}
set viewerType(_) {
throw new Error("app.viewerType is read-only");
}
get viewerVariation() {
return VIEWER_VARIATION;
}
set viewerVariation(_) {
throw new Error("app.viewerVariation is read-only");
}
get viewerVersion() {
return VIEWER_VERSION;
}
set viewerVersion(_) {
throw new Error("app.viewerVersion is read-only");
}
View on GitHub (pinned to 5903d58d58)
Solutions
- Read app.viewerType for viewer-specific branching (expect the PDF.js identifier).
- Gate features on your own capability checks, not by rewriting viewerType.
- If a different identifier is truly required, build PDF.js from source with a custom constant.
Example fix
// before
app.viewerType = 'Exchange-Pro';
// after
if (app.viewerType === VIEWER_TYPE) { /* pdf.js path */ } Defensive patterns
Strategy: validation
Validate before calling
// app.viewerType is a build constant; read only. const isPdfJs = (app) => app.viewerType === VIEWER_TYPE;
Type guard
const isViewerTypeString = (v) => typeof v === 'string' && v.length > 0;
Try / catch
try { /* code that may assign app.viewerType */ }
catch (e) { if (!/viewerType is read-only/.test(e.message)) throw e; } Prevention
- Gate features on app.viewerType rather than spoofing it.
- Rebuild PDF.js from source if a different identifier is truly required.
- Document the expected viewerType for your integration.
When it happens
Trigger: Any assignment app.viewerType = 'Exchange-Pro' (or any value) in PDF JavaScript or caller code hits the throw at src/scripting_api/app.js:388.
Common situations: Scripts trying to impersonate Acrobat Professional to unlock menu actions; feature checks that mistakenly write instead of read.
Related errors
- app.formsVersion is read-only
- app.viewerVariation is read-only
- app.viewerVersion is read-only
- app.activeDocs is read-only
- app.constants is read-only
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/93974b3fa243bd97.
Report an issue: GitHub.