{"record":{"id":"ab9dc673dfbe68ee","repo":"mozilla/pdf.js","slug":"app-viewerversion-is-read-only","errorCode":null,"errorMessage":"app.viewerVersion is read-only","messagePattern":"app\\.viewerVersion is read-only","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/scripting_api/app.js","lineNumber":404,"sourceCode":"\n  set viewerType(_) {\n    throw new Error(\"app.viewerType is read-only\");\n  }\n\n  get viewerVariation() {\n    return VIEWER_VARIATION;\n  }\n\n  set viewerVariation(_) {\n    throw new Error(\"app.viewerVariation is read-only\");\n  }\n\n  get viewerVersion() {\n    return VIEWER_VERSION;\n  }\n\n  set viewerVersion(_) {\n    throw new Error(\"app.viewerVersion is read-only\");\n  }\n\n  addMenuItem() {\n    /* Not implemented */\n  }\n\n  addSubMenu() {\n    /* Not implemented */\n  }\n\n  addToolButton() {\n    /* Not implemented */\n  }\n\n  alert(\n    cMsg,\n    nIcon = 0,\n    nType = 0,","sourceCodeStart":386,"sourceCodeEnd":422,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/scripting_api/app.js#L386-L422","documentation":"app.viewerVersion exposes the compiled VIEWER_VERSION numeric constant. It is fixed per PDF.js build and the setter throws. The throw prevents scripts from spoofing the viewer version to unlock version-gated features.","triggerScenarios":"Any assignment app.viewerVersion = N in PDF JavaScript or caller code hits the throw at src/scripting_api/app.js:404.","commonSituations":"Scripts trying to fake a higher version to bypass feature checks; tests that write instead of constructing App with a different constant.","solutions":["Read app.viewerVersion for feature gating by numeric comparison.","If you need a different version, rebuild PDF.js from the corresponding source.","Do not assign to the property from document JavaScript."],"exampleFix":"// before\napp.viewerVersion = 11;\n// after\nif (app.viewerVersion >= REQUIRED_VERSION) { /* ... */ }","handlingStrategy":"validation","validationCode":"// app.viewerVersion is a build constant; read only.\nconst meetsMin = (app, min) => app.viewerVersion >= min;","typeGuard":"const isVersionNumber = (v) => typeof v === 'number' && Number.isFinite(v);","tryCatchPattern":"try { /* code that may assign app.viewerVersion */ }\ncatch (e) { if (!/viewerVersion is read-only/.test(e.message)) throw e; }","preventionTips":["Compare app.viewerVersion numerically for feature gating.","Pin your PDF.js build to know the expected version.","Never spoof the version from document JS."],"tags":["scripting-api","read-only","version","acrobat-js"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}