mozilla/pdf.js · error · Error

app.viewerVersion is read-only

Error message

app.viewerVersion is read-only

What it means

app.viewerVersion exposes the compiled VIEWER_VERSION numeric constant. It is fixed per PDF.js build and the setter throws. The throw prevents scripts from spoofing the viewer version to unlock version-gated features.

Source

Thrown at src/scripting_api/app.js:404

  set viewerType(_) {
    throw new Error("app.viewerType is read-only");
  }

  get viewerVariation() {
    return VIEWER_VARIATION;
  }

  set viewerVariation(_) {
    throw new Error("app.viewerVariation is read-only");
  }

  get viewerVersion() {
    return VIEWER_VERSION;
  }

  set viewerVersion(_) {
    throw new Error("app.viewerVersion is read-only");
  }

  addMenuItem() {
    /* Not implemented */
  }

  addSubMenu() {
    /* Not implemented */
  }

  addToolButton() {
    /* Not implemented */
  }

  alert(
    cMsg,
    nIcon = 0,
    nType = 0,

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Read app.viewerVersion for feature gating by numeric comparison.
  2. If you need a different version, rebuild PDF.js from the corresponding source.
  3. Do not assign to the property from document JavaScript.

Example fix

// before
app.viewerVersion = 11;
// after
if (app.viewerVersion >= REQUIRED_VERSION) { /* ... */ }
Defensive patterns

Strategy: validation

Validate before calling

// app.viewerVersion is a build constant; read only.
const meetsMin = (app, min) => app.viewerVersion >= min;

Type guard

const isVersionNumber = (v) => typeof v === 'number' && Number.isFinite(v);

Try / catch

try { /* code that may assign app.viewerVersion */ }
catch (e) { if (!/viewerVersion is read-only/.test(e.message)) throw e; }

Prevention

When it happens

Trigger: Any assignment app.viewerVersion = N in PDF JavaScript or caller code hits the throw at src/scripting_api/app.js:404.

Common situations: Scripts trying to fake a higher version to bypass feature checks; tests that write instead of constructing App with a different constant.

Related errors


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