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

  1. Do not assign to app.media; it is intentionally unsupported and always undefined.
  2. Feature-detect: if (app.media === undefined) skip multimedia paths.
  3. 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

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


AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13). Data as JSON: /api/errors/5e15411ca5f30ef8. Report an issue: GitHub.