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
- Delete the assignment to `XFAForeground`; the value is constant (`false`) in PDF.js.
- If generating scripts programmatically, filter out the known read-only doc properties before emitting assignments.
- 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
- Treat XFAForeground as a constant (false); do not branch logic on writing it.
- Watch casing: both 'xfa' and 'XFAForeground' are read-only but distinct properties.
- Filter known read-only names before emitting assignments from code generators.
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
- doc.xfa is read-only
- app.activeDocs is read-only
- app.constants is read-only
- app.formsVersion is read-only
- app.fromPDFConverters is read-only
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/af7d06fe6ce5740a.
Report an issue: GitHub.