mozilla/pdf.js · error · Error
app.language is read-only
Error message
app.language is read-only
What it means
app.language returns the viewer's resolved language string (this._language). It reflects the host locale and is not user-writable, so the setter throws. The throw guards the locale source-of-truth held by the viewer.
Source
Thrown at src/scripting_api/app.js:257
}
get fs() {
return (this._fs ??= new Proxy(
new FullScreen({ send: this._send }),
this._proxyHandler
));
}
set fs(_) {
throw new Error("app.fs is read-only");
}
get language() {
return this._language;
}
set language(_) {
throw new Error("app.language is read-only");
}
get media() {
return undefined;
}
set media(_) {
throw new Error("app.media is read-only");
}
get monitors() {
return [];
}
set monitors(_) {
throw new Error("app.monitors is read-only");
}
View on GitHub (pinned to 5903d58d58)
Solutions
- Set the desired locale at the viewer/host level (e.g., PDF.js locale init), not via app.language.
- Read app.language to branch document behavior per locale.
- Pass language preferences through viewer configuration before document load.
Example fix
// before
app.language = 'FRA';
// after
// configure pdf.js with the fr locale at startup; then:
if (app.language === 'FRA') { /* ... */ } Defensive patterns
Strategy: validation
Validate before calling
// app.language reflects host locale; configure via viewer init.
function pickLabel(app, dict) { return dict[app.language] ?? dict.default; } Type guard
const isLanguageString = (v) => typeof v === 'string' && /^[A-Z]{3}$/.test(v); Try / catch
try { /* code that may assign app.language */ }
catch (e) { if (!/language is read-only/.test(e.message)) throw e; } Prevention
- Set locale at viewer startup, not from document JS.
- Branch on app.language rather than trying to change it.
- Pass desired locale through pdf.js configuration.
When it happens
Trigger: PDF-embedded JavaScript or caller executes app.language = 'FRA' (or any value); the setter at src/scripting_api/app.js:257 throws unconditionally.
Common situations: Scripts trying to force a UI language from within the document; localization tests that mistakenly write instead of configuring the viewer.
Related errors
- app.activeDocs is read-only
- app.constants is read-only
- app.formsVersion is read-only
- app.fromPDFConverters is read-only
- app.monitors is read-only
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/2e57ddb60555e206.
Report an issue: GitHub.