{"record":{"id":"af7d06fe6ce5740a","repo":"mozilla/pdf.js","slug":"doc-xfaforeground-is-read-only","errorCode":null,"errorMessage":"doc.XFAForeground is read-only","messagePattern":"doc\\.XFAForeground is read-only","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/scripting_api/doc.js","lineNumber":711,"sourceCode":"\n  set viewState(_) {\n    throw new Error(\"doc.viewState is read-only\");\n  }\n\n  get xfa() {\n    return this._xfa;\n  }\n\n  set xfa(_) {\n    throw new Error(\"doc.xfa is read-only\");\n  }\n\n  get XFAForeground() {\n    return false;\n  }\n\n  set XFAForeground(_) {\n    throw new Error(\"doc.XFAForeground is read-only\");\n  }\n\n  get zoomType() {\n    return this._zoomType;\n  }\n\n  set zoomType(type) {\n    if (!this._userActivation) {\n      return;\n    }\n    this._userActivation = false;\n\n    if (typeof type !== \"string\") {\n      return;\n    }\n    switch (type) {\n      case ZoomType.none:\n        this._send({ command: \"zoom\", value: 1 });","sourceCodeStart":693,"sourceCodeEnd":729,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/scripting_api/doc.js#L693-L729","documentation":"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.","triggerScenarios":"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.","commonSituations":"Casing confusion between `xfa` and `XFAForeground`; legacy scripts that set foreground flags from older Acrobat versions; generic 'save/restore all properties' code.","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."],"exampleFix":"// before\nthis.doc.XFAForeground = true;\n// after\n// XFAForeground is read-only and always false in PDF.js; omit the assignment.","handlingStrategy":"try-catch","validationCode":"const READ_ONLY_DOC_PROPS = new Set(['URL','viewState','xfa','XFAForeground']);\nfunction isWritableDocProp(key) {\n  return !READ_ONLY_DOC_PROPS.has(key);\n}","typeGuard":null,"tryCatchPattern":"try {\n  doc.XFAForeground = v;\n} catch (e) {\n  // constant false in PDF.js; ignore\n}","preventionTips":["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."],"tags":["scripting-api","xfa","read-only","acrobat-js"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}