{"record":{"id":"35518e74456c0c2f","repo":"mozilla/pdf.js","slug":"doc-pagewindowrect-is-read-only","errorCode":null,"errorMessage":"doc.pageWindowRect is read-only","messagePattern":"doc\\.pageWindowRect is read-only","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/scripting_api/doc.js","lineNumber":583,"sourceCode":"  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  }\n\n  get pageWindowRect() {\n    return [0, 0, 0, 0];\n  }\n\n  set pageWindowRect(_) {\n    throw new Error(\"doc.pageWindowRect is read-only\");\n  }\n\n  get path() {\n    return \"\";\n  }\n\n  set path(_) {\n    throw new Error(\"doc.path is read-only\");\n  }\n\n  get permStatusReady() {\n    return true;\n  }\n\n  set permStatusReady(_) {\n    throw new Error(\"doc.permStatusReady is read-only\");\n  }\n","sourceCodeStart":565,"sourceCodeEnd":601,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/scripting_api/doc.js#L565-L601","documentation":"`Doc.pageWindowRect` returns `[left, top, right, bottom]` describing the page window rectangle. PDF.js returns `[0,0,0,0]` (browser viewer has no such windowing concept). It is read-only by the Acrobat spec, and the throwing setter rejects scripts that try to set it.","triggerScenarios":"A script assigns to `doc.pageWindowRect` (e.g. `doc.pageWindowRect = [0,0,500,500];`). The setter throws at that line.","commonSituations":"Scripts targeting desktop Acrobat windowing; layout/snapshot scripts; code blindly probing all properties.","solutions":["Drop the assignment — the value is read-only and constant `[0,0,0,0]` in PDF.js.","Use viewer-level zoom/layout controls to affect page display instead.","Run untrusted scripts through a try/catch boundary."],"exampleFix":"// before\ndoc.pageWindowRect = [0, 0, 612, 792];\n\n// after\n// (remove) — read-only; returns [0,0,0,0] in PDF.js","handlingStrategy":"try-catch","validationCode":"const READ_ONLY_DOC_PROPS = new Set(['pageWindowRect','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, 'pageWindowRect'); // true","tryCatchPattern":"try {\n  doc.pageWindowRect = [0,0,612,792];\n} catch (e) {\n  if (/pageWindowRect is read-only/.test(e.message)) console.warn(e.message);\n  else throw e;\n}","preventionTips":["Page-window geometry is not exposed in the browser viewer; do not write it.","Use viewer zoom/layout APIs to affect page display.","Guard legacy scripts with try/catch at the dispatch boundary."],"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"}