mozilla/pdf.js · error · Error

app.viewerVariation is read-only

Error message

app.viewerVariation is read-only

What it means

app.viewerVariation exposes the compiled VIEWER_VARIATION constant. It is a fixed per-build value and the setter throws to enforce read-only semantics. Assignment is rejected unconditionally.

Source

Thrown at src/scripting_api/app.js:396

  set toolbarVertical(value) {
    /* has been deprecated and it's now equivalent to toolbar */
    this.toolbar = value;
  }

  get viewerType() {
    return VIEWER_TYPE;
  }

  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 */
  }

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Read app.viewerVariation only.
  2. Use the constant for capability detection rather than reassignment.
  3. Build PDF.js from source if a non-default variation is required.

Example fix

// before
app.viewerVariation = 'Pro';
// after
const v = app.viewerVariation; // read-only
Defensive patterns

Strategy: validation

Validate before calling

// app.viewerVariation is a build constant; read only.
const variation = app.viewerVariation;

Type guard

const isNonEmptyString = (v) => typeof v === 'string' && v.length > 0;

Try / catch

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

Prevention

When it happens

Trigger: Any assignment app.viewerVariation = <value> in PDF JavaScript or caller code hits the throw at src/scripting_api/app.js:396.

Common situations: Scripts trying to fake a SKU variation; authors confusing the constant with a configurable option.

Related errors


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