mozilla/pdf.js · error · Error

app.formsVersion is read-only

Error message

app.formsVersion is read-only

What it means

app.formsVersion exposes the compiled FORMS_VERSION constant of the viewer. It is informational and fixed per PDF.js build, so the setter always throws. The throw indicates an attempt to spoof or override the reported forms engine version.

Source

Thrown at src/scripting_api/app.js:230

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

  get focusRect() {
    return this._focusRect;
  }

  set focusRect(val) {
    /* TODO or not */
    this._focusRect = val;
  }

  get formsVersion() {
    return FORMS_VERSION;
  }

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

  get fromPDFConverters() {
    return [];
  }

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

  get fs() {
    return (this._fs ??= new Proxy(
      new FullScreen({ send: this._send }),
      this._proxyHandler
    ));
  }

  set fs(_) {

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Read app.formsVersion only (e.g. for feature gating by comparison).
  2. Gate features on your own capability flags rather than rewriting the version.
  3. If you need a different forms version, build PDF.js from the matching source tag.

Example fix

// before
app.formsVersion = 999;
// after
if (app.formsVersion >= FORMS_VERSION) { /* supported */ }
Defensive patterns

Strategy: validation

Validate before calling

// formsVersion is a build constant; read only.
const supported = (app) => typeof app.formsVersion === 'number';

Type guard

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

Try / catch

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

Prevention

When it happens

Trigger: Any assignment app.formsVersion = <value> in PDF-embedded JS or scripting-API test code hits the unconditional throw at src/scripting_api/app.js:230.

Common situations: Scripts trying to fake a higher forms-version to unlock features; conditional logic that mistakenly writes instead of reads the property.

Related errors


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