mozilla/pdf.js · error · Error

doc.outerDocWindowRect is read-only

Error message

doc.outerDocWindowRect is read-only

What it means

`Doc.outerDocWindowRect` returns `[left, top, right, bottom]` for the outer bounds of the document window (the area showing the PDF). PDF.js returns `[0,0,0,0]` because the browser viewer does not expose a discrete document window. Per the Acrobat spec it is read-only; the throwing setter mirrors that and rejects attempts to reshape the non-existent window.

Source

Thrown at src/scripting_api/doc.js:558

  set numTemplates(_) {
    throw new Error("doc.numTemplates is read-only");
  }

  get outerAppWindowRect() {
    return [0, 0, 0, 0];
  }

  set outerAppWindowRect(_) {
    throw new Error("doc.outerAppWindowRect is read-only");
  }

  get outerDocWindowRect() {
    return [0, 0, 0, 0];
  }

  set outerDocWindowRect(_) {
    throw new Error("doc.outerDocWindowRect is read-only");
  }

  get pageNum() {
    return this._pageNum;
  }

  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;
  }

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Remove the assignment; the property is read-only and returns `[0,0,0,0]` in PDF.js.
  2. Drive viewer sizing through the host page (container CSS, viewer zoom/layout APIs).
  3. Wrap script execution in try/catch to tolerate the unsupported write.

Example fix

// before
doc.outerDocWindowRect = [10, 10, 900, 700];

// after
// (remove) — returns [0,0,0,0] in PDF.js
Defensive patterns

Strategy: try-catch

Validate before calling

const READ_ONLY_DOC_PROPS = new Set(['outerDocWindowRect','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, 'outerDocWindowRect'); // true

Try / catch

try {
  doc.outerDocWindowRect = [0,0,900,700];
} catch (e) {
  if (/outerDocWindowRect is read-only/.test(e.message)) console.warn(e.message);
  else throw e;
}

Prevention

When it happens

Trigger: A script writes `doc.outerDocWindowRect = [...];` to resize the document pane. The setter throws on assignment.

Common situations: Desktop-Acrobat scripts that reposition the doc window; layout-restore scripts ported to the browser; code copied from SDK examples.

Related errors


AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13). Data as JSON: /api/errors/ebf142f673101d95. Report an issue: GitHub.