{"record":{"id":"10793c9d7dd838a9","repo":"mozilla/pdf.js","slug":"doc-innerappwindowrect-is-read-only","errorCode":null,"errorMessage":"doc.innerAppWindowRect is read-only","messagePattern":"doc\\.innerAppWindowRect is read-only","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/scripting_api/doc.js","lineNumber":410,"sourceCode":"\n  set icons(_) {\n    throw new Error(\"doc.icons is read-only\");\n  }\n\n  get info() {\n    return this._info;\n  }\n\n  set info(_) {\n    throw new Error(\"doc.info is read-only\");\n  }\n\n  get innerAppWindowRect() {\n    return [0, 0, 0, 0];\n  }\n\n  set innerAppWindowRect(_) {\n    throw new Error(\"doc.innerAppWindowRect is read-only\");\n  }\n\n  get innerDocWindowRect() {\n    return [0, 0, 0, 0];\n  }\n\n  set innerDocWindowRect(_) {\n    throw new Error(\"doc.innerDocWindowRect is read-only\");\n  }\n\n  get isModal() {\n    return false;\n  }\n\n  set isModal(_) {\n    throw new Error(\"doc.isModal is read-only\");\n  }\n","sourceCodeStart":392,"sourceCodeEnd":428,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/scripting_api/doc.js#L392-L428","documentation":"PDF.js's scripting sandbox (src/scripting_api) implements the Acrobat JavaScript `doc` object inside a QuickJS sandbox. Per the Acrobat API specification this property is read-only, so the class defines a getter that returns the current value and a setter that unconditionally throws `Error(\"doc.<prop> is read-only\")`. The throw aborts the currently executing sandboxed script event and is reported back to the host. `innerAppWindowRect` is the application inner window rectangle; pdf.js always returns `[0,0,0,0]` and forbids writes.","triggerScenarios":"A sandboxed PDF form/script executes an assignment to the property, e.g. `doc.innerAppWindowRect = value;` or `doc.innerAppWindowRect++`. Because the setter always throws (there is no condition), any write attempt triggers it.","commonSituations":"Scripts ported from desktop Acrobat where window geometry was set; forms that try to stamp runtime state into document metadata on save/open; and PDFs generated by tools that emit non-spec-compliant JavaScript.","solutions":["Remove the assignment to `doc.innerAppWindowRect`; read it through the getter instead.","Window geometry is controlled by the host browser, not the sandboxed script.","If you cannot edit the PDF's embedded script, wrap the statement in try/catch so the rest of the form logic still runs."],"exampleFix":"// before\ndoc.innerAppWindowRect = [0,0,800,600];\n// after\n// innerAppWindowRect is read-only — drop the assignment; read via doc.innerAppWindowRect","handlingStrategy":"validation","validationCode":"// Known read-only doc properties (PDF.js scripting_api/doc.js)\nconst READONLY_DOC_PROPS = new Set([\n  'author','bookmarkRoot','creator','dataObjects','docID',\n  'documentFileName','dynamicXFAForm','external','filesize','hidden',\n  'hostContainer','icons','info','innerAppWindowRect','innerDocWindowRect',\n  'isModal','keywords','modDate'\n]);\nif (READONLY_DOC_PROPS.has('innerAppWindowRect')) {\n  // skip the write; innerAppWindowRect is read-only in pdf.js\n  console.warn('doc.innerAppWindowRect is read-only in pdf.js');\n} else {\n  doc.innerAppWindowRect = value;\n}","typeGuard":"// Known read-only doc properties (PDF.js scripting_api/doc.js)\nconst READONLY_DOC_PROPS = new Set([\n  'author','bookmarkRoot','creator','dataObjects','docID',\n  'documentFileName','dynamicXFAForm','external','filesize','hidden',\n  'hostContainer','icons','info','innerAppWindowRect','innerDocWindowRect',\n  'isModal','keywords','modDate'\n]);\nconst isReadOnlyDocProp = (name) => READONLY_DOC_PROPS.has(name);\n// usage: if (!isReadOnlyDocProp('keywords')) doc.keywords = v;","tryCatchPattern":"try {\n  doc.innerAppWindowRect = value;\n} catch (e) {\n  // pdf.js throws Error('doc.innerAppWindowRect is read-only')\n  if (/is read-only/.test(e.message)) { /* swallow, expected */ }\n  else { throw e; }\n}","preventionTips":["Treat every property listed in the Acrobat JS reference as read-only unless pdf.js provides a setter that stores the value.","Before assigning, check `isReadOnlyDocProp('innerAppWindowRect')` or grep the setter in src/scripting_api/doc.js for a `throw`.","When porting scripts from Acrobat, run them against the pdf.js sandbox in the dev server first to surface writes early.","Prefer reading metadata through the Info dictionary at PDF authoring time rather than mutating it from a script."],"tags":["scripting","acrobat-api","read-only"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}