mozilla/pdf.js · error · Error
app.monitors is read-only
Error message
app.monitors is read-only
What it means
app.monitors returns an empty array (PDF.js exposes no monitor enumeration). It is a viewer-managed list, so the setter throws. Assignment is rejected unconditionally.
Source
Thrown at src/scripting_api/app.js:273
set language(_) {
throw new Error("app.language is read-only");
}
get media() {
return undefined;
}
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 */
}View on GitHub (pinned to 5903d58d58)
Solutions
- Read app.monitors only; expect [] in PDF.js.
- Obtain screen geometry from the host page/window APIs instead.
- Do not attempt to push into the returned array expecting persistence.
Example fix
// before
app.monitors = [{ width: 1920 }];
// after
const monitors = app.monitors; // [] in pdf.js; use host APIs instead Defensive patterns
Strategy: validation
Validate before calling
// app.monitors always returns [] in pdf.js. const monitorCount = (app) => app.monitors.length;
Type guard
const isMonitorList = (v) => Array.isArray(v);
Try / catch
try { /* code that may assign app.monitors */ }
catch (e) { if (!/monitors is read-only/.test(e.message)) throw e; } Prevention
- Treat viewer-enumeration properties as read-only.
- Use host screen APIs for geometry.
- Do not push into returned arrays.
When it happens
Trigger: Any assignment app.monitors = [...] in PDF JavaScript or API test code hits the throw at src/scripting_api/app.js:273.
Common situations: Scripts trying to register or fake monitor entries for layout logic; authors assuming the array is extensible.
Related errors
- app.fromPDFConverters is read-only
- app.numPlugins 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/d89aaad698612247.
Report an issue: GitHub.