{"record":{"id":"dc4f969520843b67","repo":"mozilla/pdf.js","slug":"app-platform-is-read-only","errorCode":null,"errorMessage":"app.platform is read-only","messagePattern":"app\\.platform is read-only","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/scripting_api/app.js","lineNumber":298,"sourceCode":"  set numPlugins(_) {\n    throw new Error(\"app.numPlugins is read-only\");\n  }\n\n  get openInPlace() {\n    return this._openInPlace;\n  }\n\n  set openInPlace(val) {\n    this._openInPlace = val;\n    /* TODO */\n  }\n\n  get platform() {\n    return this._platform;\n  }\n\n  set platform(_) {\n    throw new Error(\"app.platform is read-only\");\n  }\n\n  get plugins() {\n    return [];\n  }\n\n  set plugins(_) {\n    throw new Error(\"app.plugins is read-only\");\n  }\n\n  get printColorProfiles() {\n    return [];\n  }\n\n  set printColorProfiles(_) {\n    throw new Error(\"app.printColorProfiles is read-only\");\n  }\n","sourceCodeStart":280,"sourceCodeEnd":316,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/scripting_api/app.js#L280-L316","documentation":"app.platform returns the detected platform string (this._platform). It reflects the host environment and is not user-writable, so the setter throws. The throw preserves the platform detection source-of-truth.","triggerScenarios":"PDF-embedded JavaScript or caller executes app.platform = 'Win' (or any value); the setter at src/scripting_api/app.js:298 throws unconditionally.","commonSituations":"Cross-platform scripts trying to spoof platform to force a code path; tests that write instead of mocking the constructor.","solutions":["Read app.platform for platform-specific document behavior.","If you need a different platform value in tests, construct the App with the desired _platform rather than assigning the property.","Do not attempt to mutate app.platform from document JavaScript."],"exampleFix":"// before\napp.platform = 'MAC';\n// after\nif (app.platform === 'MAC') { /* mac code path */ }","handlingStrategy":"validation","validationCode":"// app.platform is detected at runtime; read only.\nconst isMac = (app) => app.platform === 'MAC';","typeGuard":"const isKnownPlatform = (v) => ['WIN','MAC','UNIX'].includes(v);","tryCatchPattern":"try { /* code that may assign app.platform */ }\ncatch (e) { if (!/platform is read-only/.test(e.message)) throw e; }","preventionTips":["Branch on app.platform instead of overriding it.","For tests, construct the App instance with the desired _platform.","Avoid spoofing platform from document scripts."],"tags":["scripting-api","read-only","platform","acrobat-js"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}