mozilla/pdf.js · error · Error
doc.pageWindowRect is read-only
Error message
doc.pageWindowRect is read-only
What it means
`Doc.pageWindowRect` returns `[left, top, right, bottom]` describing the page window rectangle. PDF.js returns `[0,0,0,0]` (browser viewer has no such windowing concept). It is read-only by the Acrobat spec, and the throwing setter rejects scripts that try to set it.
Source
Thrown at src/scripting_api/doc.js:583
set pageNum(value) {
if (!this._userActivation) {
return;
}
this._userActivation = false;
if (typeof value !== "number" || value < 0 || value >= this._numPages) {
return;
}
this._send({ command: "page-num", value });
this._pageNum = value;
}
get pageWindowRect() {
return [0, 0, 0, 0];
}
set pageWindowRect(_) {
throw new Error("doc.pageWindowRect is read-only");
}
get path() {
return "";
}
set path(_) {
throw new Error("doc.path is read-only");
}
get permStatusReady() {
return true;
}
set permStatusReady(_) {
throw new Error("doc.permStatusReady is read-only");
}
View on GitHub (pinned to 5903d58d58)
Solutions
- Drop the assignment — the value is read-only and constant `[0,0,0,0]` in PDF.js.
- Use viewer-level zoom/layout controls to affect page display instead.
- Run untrusted scripts through a try/catch boundary.
Example fix
// before doc.pageWindowRect = [0, 0, 612, 792]; // after // (remove) — read-only; returns [0,0,0,0] in PDF.js
Defensive patterns
Strategy: try-catch
Validate before calling
const READ_ONLY_DOC_PROPS = new Set(['pageWindowRect','outerAppWindowRect' /* ... */]);
function assertsNoReadOnlyWrite(scriptSrc) {
for (const p of READ_ONLY_DOC_PROPS) {
if (new RegExp(`\\bdoc\\.${p}\\s*=[^=]`).test(scriptSrc)) {
throw new Error(`Script writes read-only property doc.${p}`);
}
}
}
assertsNoReadOnlyWrite(myScript); Type guard
function isReadOnlyDocProp(doc, prop) {
const desc = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(doc), prop)
|| Object.getOwnPropertyDescriptor(doc, prop);
return !!desc && !!desc.get && !desc.set;
}
isReadOnlyDocProp(doc, 'pageWindowRect'); // true Try / catch
try {
doc.pageWindowRect = [0,0,612,792];
} catch (e) {
if (/pageWindowRect is read-only/.test(e.message)) console.warn(e.message);
else throw e;
} Prevention
- Page-window geometry is not exposed in the browser viewer; do not write it.
- Use viewer zoom/layout APIs to affect page display.
- Guard legacy scripts with try/catch at the dispatch boundary.
When it happens
Trigger: A script assigns to `doc.pageWindowRect` (e.g. `doc.pageWindowRect = [0,0,500,500];`). The setter throws at that line.
Common situations: Scripts targeting desktop Acrobat windowing; layout/snapshot scripts; code blindly probing all properties.
Related errors
- doc.outerAppWindowRect is read-only
- doc.outerDocWindowRect is read-only
- doc.numTemplates is read-only
- doc.requiresFullSave is read-only
- doc.sounds is read-only
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/35518e74456c0c2f.
Report an issue: GitHub.