mozilla/pdf.js · error · Error
app.numPlugins is read-only
Error message
app.numPlugins is read-only
What it means
app.numPlugins returns 0 because PDF.js loads no Acrobat-style plugins. It is a viewer-managed count and is not assignable; the setter throws. The throw prevents spoofing the plugin count.
Source
Thrown at src/scripting_api/app.js:281
set media(_) {
throw new Error("app.media is read-only");
}
get monitors() {
return [];
}
set monitors(_) {
throw new Error("app.monitors is read-only");
}
get numPlugins() {
return 0;
}
set numPlugins(_) {
throw new Error("app.numPlugins is read-only");
}
get openInPlace() {
return this._openInPlace;
}
set openInPlace(val) {
this._openInPlace = val;
/* TODO */
}
get platform() {
return this._platform;
}
set platform(_) {
throw new Error("app.platform is read-only");
}View on GitHub (pinned to 5903d58d58)
Solutions
- Read app.numPlugins (always 0 in PDF.js) for capability detection.
- Gate plugin-dependent features on app.numPlugins > 0, expecting false.
- Do not attempt to change the value from document scripts.
Example fix
// before
app.numPlugins = 3;
// after
if (app.numPlugins > 0) { /* ... */ } else { /* unsupported */ } Defensive patterns
Strategy: validation
Validate before calling
// app.numPlugins is always 0 in pdf.js. const pluginsAvailable = (app) => app.numPlugins > 0;
Type guard
const isNonNegativeInt = (v) => Number.isInteger(v) && v >= 0;
Try / catch
try { /* code that may assign app.numPlugins */ }
catch (e) { if (!/numPlugins is read-only/.test(e.message)) throw e; } Prevention
- Gate plugin features on numPlugins/plugins length.
- Expect 0 and an empty array in pdf.js.
- Never try to fake plugin counts from document JS.
When it happens
Trigger: PDF JavaScript or caller runs app.numPlugins = N; the setter at src/scripting_api/app.js:281 throws regardless of value.
Common situations: Scripts trying to fake plugin availability to gate features; authors confusing the stub with a registry length.
Related errors
- app.fromPDFConverters is read-only
- app.monitors is read-only
- app.plugins 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/af10e673dcebe224.
Report an issue: GitHub.