{"record":{"id":"ebf142f673101d95","repo":"mozilla/pdf.js","slug":"doc-outerdocwindowrect-is-read-only","errorCode":null,"errorMessage":"doc.outerDocWindowRect is read-only","messagePattern":"doc\\.outerDocWindowRect is read-only","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/scripting_api/doc.js","lineNumber":558,"sourceCode":"\n  set numTemplates(_) {\n    throw new Error(\"doc.numTemplates is read-only\");\n  }\n\n  get outerAppWindowRect() {\n    return [0, 0, 0, 0];\n  }\n\n  set outerAppWindowRect(_) {\n    throw new Error(\"doc.outerAppWindowRect is read-only\");\n  }\n\n  get outerDocWindowRect() {\n    return [0, 0, 0, 0];\n  }\n\n  set outerDocWindowRect(_) {\n    throw new Error(\"doc.outerDocWindowRect is read-only\");\n  }\n\n  get pageNum() {\n    return this._pageNum;\n  }\n\n  set pageNum(value) {\n    if (!this._userActivation) {\n      return;\n    }\n    this._userActivation = false;\n\n    if (typeof value !== \"number\" || value < 0 || value >= this._numPages) {\n      return;\n    }\n    this._send({ command: \"page-num\", value });\n    this._pageNum = value;\n  }","sourceCodeStart":540,"sourceCodeEnd":576,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/scripting_api/doc.js#L540-L576","documentation":"`Doc.outerDocWindowRect` returns `[left, top, right, bottom]` for the outer bounds of the document window (the area showing the PDF). PDF.js returns `[0,0,0,0]` because the browser viewer does not expose a discrete document window. Per the Acrobat spec it is read-only; the throwing setter mirrors that and rejects attempts to reshape the non-existent window.","triggerScenarios":"A script writes `doc.outerDocWindowRect = [...];` to resize the document pane. The setter throws on assignment.","commonSituations":"Desktop-Acrobat scripts that reposition the doc window; layout-restore scripts ported to the browser; code copied from SDK examples.","solutions":["Remove the assignment; the property is read-only and returns `[0,0,0,0]` in PDF.js.","Drive viewer sizing through the host page (container CSS, viewer zoom/layout APIs).","Wrap script execution in try/catch to tolerate the unsupported write."],"exampleFix":"// before\ndoc.outerDocWindowRect = [10, 10, 900, 700];\n\n// after\n// (remove) — returns [0,0,0,0] in PDF.js","handlingStrategy":"try-catch","validationCode":"const READ_ONLY_DOC_PROPS = new Set(['outerDocWindowRect','outerAppWindowRect' /* ... */]);\nfunction assertsNoReadOnlyWrite(scriptSrc) {\n  for (const p of READ_ONLY_DOC_PROPS) {\n    if (new RegExp(`\\\\bdoc\\\\.${p}\\\\s*=[^=]`).test(scriptSrc)) {\n      throw new Error(`Script writes read-only property doc.${p}`);\n    }\n  }\n}\nassertsNoReadOnlyWrite(myScript);","typeGuard":"function isReadOnlyDocProp(doc, prop) {\n  const desc = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(doc), prop)\n    || Object.getOwnPropertyDescriptor(doc, prop);\n  return !!desc && !!desc.get && !desc.set;\n}\nisReadOnlyDocProp(doc, 'outerDocWindowRect'); // true","tryCatchPattern":"try {\n  doc.outerDocWindowRect = [0,0,900,700];\n} catch (e) {\n  if (/outerDocWindowRect is read-only/.test(e.message)) console.warn(e.message);\n  else throw e;\n}","preventionTips":["Browser viewers have no discrete document window; avoid scripting window-rect properties.","Control document pane size from the host page CSS.","Wrap legacy window-management scripts in try/catch."],"tags":["scripting","acrobat-js-api","doc-object","read-only","window","unsupported"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}