{"record":{"id":"a8bbdcb8177bc7b8","repo":"mozilla/pdf.js","slug":"doc-xfa-is-read-only","errorCode":null,"errorMessage":"doc.xfa is read-only","messagePattern":"doc\\.xfa is read-only","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/scripting_api/doc.js","lineNumber":703,"sourceCode":"\n  set URL(_) {\n    throw new Error(\"doc.URL is read-only\");\n  }\n\n  get viewState() {\n    return undefined;\n  }\n\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    }","sourceCodeStart":685,"sourceCodeEnd":721,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/scripting_api/doc.js#L685-L721","documentation":"Thrown by the setter of the `xfa` property on the Acrobat JavaScript `Doc` object in PDF.js's scripting sandbox (src/scripting_api/doc.js:702). In the Acrobat API, `doc.xfa` exposes the underlying XFA (XML Forms Architecture) DOM node; PDF.js treats it as an intrinsic, non-writable attribute and throws on any assignment. The getter returns `this._xfa` (the XFA object parsed by the core layer, or undefined for non-XFA documents).","triggerScenarios":"A script embedded in a PDF assigns to `doc.xfa` (or `this.doc.xfa`), e.g. `this.doc.xfa = newXfa;`, or generic form-filler code that copies whole objects via `Object.assign(doc, {...})` which hits the setter. Also triggered by libraries that try to 'reset' a form by reassigning every enumerable-looking property.","commonSituations":"XFA form migration where an author assumed the XFA tree could be swapped at runtime; porting an Acrobat script from a reader that silently ignored the assignment; an aggressive form-reset routine that blindly writes known property names.","solutions":["Remove the assignment to `doc.xfa` — it is read-only by design; mutate the XFA tree through its own methods instead of replacing the reference.","If a generic routine is assigning, skip read-only members by name before writing (guard with a known-readonly list).","Wrap the assignment in try/catch if the write is best-effort, so a single read-only field does not abort the whole script."],"exampleFix":"// before\nthis.doc.xfa = newXfa;\n// after\n// do not reassign; xfa is read-only. Read it only:\nconst xfa = this.doc.xfa;","handlingStrategy":"try-catch","validationCode":"// These Doc properties are intrinsic and never writable in PDF.js.\nconst READ_ONLY_DOC_PROPS = new Set(['URL','viewState','xfa','XFAForeground']);\nfunction safeAssignDoc(doc, key, value) {\n  if (READ_ONLY_DOC_PROPS.has(key)) return false; // skip\n  doc[key] = value;\n  return true;\n}","typeGuard":null,"tryCatchPattern":"try {\n  doc.xfa = candidate;\n} catch (e) {\n  // xfa is read-only in PDF.js; proceed without the assignment\n}","preventionTips":["Never assign to xfa/XFAForeground/URL/viewState; read them only.","In generic copy/restore code, maintain a read-only property blocklist and skip those keys.","When porting Acrobat scripts, replace XFA-tree swaps with mutation of the existing XFA nodes."],"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"}