{"record":{"id":"936dfe0e01f51ca6","repo":"mozilla/pdf.js","slug":"field-page-is-read-only","errorCode":null,"errorMessage":"field.page is read-only","messagePattern":"field\\.page is read-only","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/scripting_api/field.js","lineNumber":202,"sourceCode":"    if (Color._isValidColor(color)) {\n      this._strokeColor = color;\n    }\n  }\n\n  get borderColor() {\n    return this.strokeColor;\n  }\n\n  set borderColor(color) {\n    this.strokeColor = color;\n  }\n\n  get page() {\n    return this._page;\n  }\n\n  set page(_) {\n    throw new Error(\"field.page is read-only\");\n  }\n\n  get rotation() {\n    return this._rotation;\n  }\n\n  set rotation(angle) {\n    angle = Math.floor(angle);\n    if (angle % 90 !== 0) {\n      throw new Error(\"Invalid rotation: must be a multiple of 90\");\n    }\n    angle %= 360;\n    if (angle < 0) {\n      angle += 360;\n    }\n    this._rotation = angle;\n  }\n","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/scripting_api/field.js#L184-L220","documentation":"Thrown by the setter of `Field.page` (src/scripting_api/field.js:202). The page on which a field lives is an intrinsic property set from the PDF structure during construction; it cannot be moved by assignment. The getter returns `this._page`.","triggerScenarios":"Executing `f.page = 2;` attempting to relocate a field to another page, or generic copy/restore logic that writes back every read property including `page`.","commonSituations":"Cloning field configuration across pages; scripts mis-translating a 'go to page' intent (`f.page` read is fine, write is not); round-tripping a field-snapshot object.","solutions":["Do not assign `page`; to navigate, use `doc.pageNum = f.page` (read the property instead).","Maintain a blocklist of read-only field properties (`page`, `numItems`, etc.) and skip them during property-copy loops.","Wrap in try/catch if the assignment originates in code you cannot change."],"exampleFix":"// before\nf.page = targetPage;\n// after\ndoc.pageNum = f.page; // navigate instead of relocating the field","handlingStrategy":"try-catch","validationCode":"const READ_ONLY_FIELD_PROPS = new Set(['page','numItems']);\nfunction safeAssignField(field, key, value) {\n  if (READ_ONLY_FIELD_PROPS.has(key)) return false;\n  field[key] = value;\n  return true;\n}","typeGuard":null,"tryCatchPattern":"try {\n  f.page = target;\n} catch (e) {\n  // page is read-only; navigate the doc instead\n  doc.pageNum = f.page;\n}","preventionTips":["Read f.page to navigate (doc.pageNum = f.page); never relocate via assignment.","Skip read-only names when cloning field state.","Distinguish 'go to the field's page' from 'move the field'."],"tags":["scripting-api","field","read-only","acrobat-js"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}