mozilla/pdf.js · error · Error

doc.innerAppWindowRect is read-only

Error message

doc.innerAppWindowRect is read-only

What it means

PDF.js's scripting sandbox (src/scripting_api) implements the Acrobat JavaScript `doc` object inside a QuickJS sandbox. Per the Acrobat API specification this property is read-only, so the class defines a getter that returns the current value and a setter that unconditionally throws `Error("doc.<prop> is read-only")`. The throw aborts the currently executing sandboxed script event and is reported back to the host. `innerAppWindowRect` is the application inner window rectangle; pdf.js always returns `[0,0,0,0]` and forbids writes.

Source

Thrown at src/scripting_api/doc.js:410

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

  get info() {
    return this._info;
  }

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

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

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

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

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

  get isModal() {
    return false;
  }

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

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Remove the assignment to `doc.innerAppWindowRect`; read it through the getter instead.
  2. Window geometry is controlled by the host browser, not the sandboxed script.
  3. If you cannot edit the PDF's embedded script, wrap the statement in try/catch so the rest of the form logic still runs.

Example fix

// before
doc.innerAppWindowRect = [0,0,800,600];
// after
// innerAppWindowRect is read-only — drop the assignment; read via doc.innerAppWindowRect
Defensive patterns

Strategy: validation

Validate before calling

// Known read-only doc properties (PDF.js scripting_api/doc.js)
const READONLY_DOC_PROPS = new Set([
  'author','bookmarkRoot','creator','dataObjects','docID',
  'documentFileName','dynamicXFAForm','external','filesize','hidden',
  'hostContainer','icons','info','innerAppWindowRect','innerDocWindowRect',
  'isModal','keywords','modDate'
]);
if (READONLY_DOC_PROPS.has('innerAppWindowRect')) {
  // skip the write; innerAppWindowRect is read-only in pdf.js
  console.warn('doc.innerAppWindowRect is read-only in pdf.js');
} else {
  doc.innerAppWindowRect = value;
}

Type guard

// Known read-only doc properties (PDF.js scripting_api/doc.js)
const READONLY_DOC_PROPS = new Set([
  'author','bookmarkRoot','creator','dataObjects','docID',
  'documentFileName','dynamicXFAForm','external','filesize','hidden',
  'hostContainer','icons','info','innerAppWindowRect','innerDocWindowRect',
  'isModal','keywords','modDate'
]);
const isReadOnlyDocProp = (name) => READONLY_DOC_PROPS.has(name);
// usage: if (!isReadOnlyDocProp('keywords')) doc.keywords = v;

Try / catch

try {
  doc.innerAppWindowRect = value;
} catch (e) {
  // pdf.js throws Error('doc.innerAppWindowRect is read-only')
  if (/is read-only/.test(e.message)) { /* swallow, expected */ }
  else { throw e; }
}

Prevention

When it happens

Trigger: A sandboxed PDF form/script executes an assignment to the property, e.g. `doc.innerAppWindowRect = value;` or `doc.innerAppWindowRect++`. Because the setter always throws (there is no condition), any write attempt triggers it.

Common situations: Scripts ported from desktop Acrobat where window geometry was set; forms that try to stamp runtime state into document metadata on save/open; and PDFs generated by tools that emit non-spec-compliant JavaScript.

Related errors


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