mozilla/pdf.js · error · Error

doc.outerAppWindowRect is read-only

Error message

doc.outerAppWindowRect is read-only

What it means

`Doc.outerAppWindowRect` returns `[left, top, right, bottom]` describing the outer bounds of the host application window. In a browser context there is no enclosing application window, so PDF.js returns `[0,0,0,0]`. The Acrobat spec marks it read-only; PDF.js's throwing setter enforces that and prevents scripts from pretending to resize a non-existent window.

Source

Thrown at src/scripting_api/doc.js:550

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

  get numTemplates() {
    return 0;
  }

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

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Delete the assignment — there is no app window to size in the browser viewer.
  2. Control viewer layout via the embedding page/iframe CSS instead of through the script.
  3. Run legacy scripts under try/catch so the unsupported write is logged and skipped.

Example fix

// before
doc.outerAppWindowRect = [0, 0, 1024, 768];

// after
// (remove) — not applicable in a browser viewer; returns [0,0,0,0]
Defensive patterns

Strategy: try-catch

Validate before calling

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

Try / catch

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

Prevention

When it happens

Trigger: A script assigns to `doc.outerAppWindowRect` (e.g. `doc.outerAppWindowRect = [0,0,800,600];`), attempting to resize/reposition the application. The setter throws immediately.

Common situations: Scripts written for desktop Acrobat that reposition the app window on open; window-management code copied from an SDK sample; scripts run unchanged in the PDF.js viewer.

Related errors


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