mozilla/pdf.js · error · Error

doc.XFAForeground is read-only

Error message

doc.XFAForeground is read-only

What it means

Thrown by the setter of `XFAForeground` on the Acrobat JavaScript `Doc` object (src/scripting_api/doc.js:710). `XFAForeground` indicates whether the XFA presentation is rendered in the foreground; PDF.js always reports `false` and forbids writes. It is an informational property, so assignment is never meaningful.

Source

Thrown at src/scripting_api/doc.js:711

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

  get xfa() {
    return this._xfa;
  }

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

  get XFAForeground() {
    return false;
  }

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

  get zoomType() {
    return this._zoomType;
  }

  set zoomType(type) {
    if (!this._userActivation) {
      return;
    }
    this._userActivation = false;

    if (typeof type !== "string") {
      return;
    }
    switch (type) {
      case ZoomType.none:
        this._send({ command: "zoom", value: 1 });

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Delete the assignment to `XFAForeground`; the value is constant (`false`) in PDF.js.
  2. If generating scripts programmatically, filter out the known read-only doc properties before emitting assignments.
  3. Wrap the assignment in try/catch when the write is best-effort.

Example fix

// before
this.doc.XFAForeground = true;
// after
// XFAForeground is read-only and always false in PDF.js; omit the assignment.
Defensive patterns

Strategy: try-catch

Validate before calling

const READ_ONLY_DOC_PROPS = new Set(['URL','viewState','xfa','XFAForeground']);
function isWritableDocProp(key) {
  return !READ_ONLY_DOC_PROPS.has(key);
}

Try / catch

try {
  doc.XFAForeground = v;
} catch (e) {
  // constant false in PDF.js; ignore
}

Prevention

When it happens

Trigger: A PDF script executes `doc.XFAForeground = true;` (note the capitalization — the Acrobat API uses mixed case, so casing mistakes still hit this setter). Triggered by form tooling that round-trips every property when serializing/deserializing a document state object.

Common situations: Casing confusion between `xfa` and `XFAForeground`; legacy scripts that set foreground flags from older Acrobat versions; generic 'save/restore all properties' code.

Related errors


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