mozilla/pdf.js · error · Error
app.media is read-only
Error message
app.media is read-only
What it means
app.media always returns undefined because PDF.js does not implement the Acrobat multimedia API. The setter still throws to preserve the read-only contract of the property. Any assignment is rejected.
Source
Thrown at src/scripting_api/app.js:265
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");
}
get numPlugins() {
return 0;
}
set numPlugins(_) {
throw new Error("app.numPlugins is read-only");
}
View on GitHub (pinned to 5903d58d58)
Solutions
- Do not assign to app.media; it is intentionally unsupported and always undefined.
- Feature-detect: if (app.media === undefined) skip multimedia paths.
- Render any media outside the PDF.js scripting API (e.g., host page).
Example fix
// before
app.media = myPlayer;
// after
if (app.media === undefined) { /* multimedia not supported */ } Defensive patterns
Strategy: type-guard
Validate before calling
// app.media is intentionally undefined in pdf.js. const hasMedia = (app) => app.media !== undefined;
Type guard
const isMediaSupported = (app) => app.media != null;
Try / catch
try { /* code that may assign app.media */ }
catch (e) { if (!/media is read-only/.test(e.message)) throw e; } Prevention
- Treat undefined stubs as permanently unsupported.
- Feature-detect before any multimedia code path.
- Render media via the host page, not the scripting API.
When it happens
Trigger: PDF JavaScript or test code runs app.media = {...}; the setter at src/scripting_api/app.js:265 throws regardless of value.
Common situations: Legacy multimedia-heavy PDFs trying to install a media player object; authors assuming undefined means assignable.
Related errors
- app.activeDocs is read-only
- app.constants is read-only
- app.formsVersion is read-only
- app.fromPDFConverters is read-only
- app.fs is read-only
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/5e15411ca5f30ef8.
Report an issue: GitHub.