mozilla/pdf.js · error · Error
app.platform is read-only
Error message
app.platform is read-only
What it means
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.
Source
Thrown at src/scripting_api/app.js:298
set numPlugins(_) {
throw new Error("app.numPlugins is read-only");
}
get openInPlace() {
return this._openInPlace;
}
set openInPlace(val) {
this._openInPlace = val;
/* TODO */
}
get platform() {
return this._platform;
}
set platform(_) {
throw new Error("app.platform is read-only");
}
get plugins() {
return [];
}
set plugins(_) {
throw new Error("app.plugins is read-only");
}
get printColorProfiles() {
return [];
}
set printColorProfiles(_) {
throw new Error("app.printColorProfiles is read-only");
}
View on GitHub (pinned to 5903d58d58)
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.
Example fix
// before
app.platform = 'MAC';
// after
if (app.platform === 'MAC') { /* mac code path */ } Defensive patterns
Strategy: validation
Validate before calling
// app.platform is detected at runtime; read only. const isMac = (app) => app.platform === 'MAC';
Type guard
const isKnownPlatform = (v) => ['WIN','MAC','UNIX'].includes(v);
Try / catch
try { /* code that may assign app.platform */ }
catch (e) { if (!/platform is read-only/.test(e.message)) throw e; } Prevention
- Branch on app.platform instead of overriding it.
- For tests, construct the App instance with the desired _platform.
- Avoid spoofing platform from document scripts.
When it happens
Trigger: PDF-embedded JavaScript or caller executes app.platform = 'Win' (or any value); the setter at src/scripting_api/app.js:298 throws unconditionally.
Common situations: Cross-platform scripts trying to spoof platform to force a code path; tests that write instead of mocking the constructor.
Related errors
- app.activeDocs is read-only
- app.constants is read-only
- app.formsVersion is read-only
- app.fromPDFConverters is read-only
- app.language is read-only
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/dc4f969520843b67.
Report an issue: GitHub.