mozilla/pdf.js · error · Error

Invalid numeric scale.

Error message

Invalid numeric scale.

What it means

Thrown by PDFViewer.currentScale setter when val is NaN (isNaN(val) is true). Scale must be a finite number (percent); a NaN would produce invalid zoom. Note: non-NaN invalid values (0, negative) are not caught here and are handled downstream.

Source

Thrown at web/pdf_viewer.js:609

      console.error(`currentPageLabel: "${val}" is not a valid page.`);
    }
  }

  /**
   * @type {number}
   */
  get currentScale() {
    return this._currentScale !== UNKNOWN_SCALE
      ? this._currentScale
      : DEFAULT_SCALE;
  }

  /**
   * @param {number} val - Scale of the pages in percents.
   */
  set currentScale(val) {
    if (isNaN(val)) {
      throw new Error("Invalid numeric scale.");
    }
    if (!this.pdfDocument) {
      return;
    }
    this.#setScale(val, { noScroll: false });
  }

  /**
   * @type {string}
   */
  get currentScaleValue() {
    return this._currentScaleValue;
  }

  /**
   * @param val - The scale of the pages (in percent or predefined value).
   */
  set currentScaleValue(val) {

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Validate the scale is a finite number before setting: Number.isFinite(val).
  2. Default to a known scale (e.g. DEFAULT_SCALE) when input is missing.
  3. Coerce and bound: const s = Math.min(MAX_SCALE, Math.max(MIN_SCALE, Number(val))).

Example fix

// before
viewer.currentScale = Number(zoomInput.value);

// after
const s = Number(zoomInput.value);
if (Number.isFinite(s) && s > 0) {
  viewer.currentScale = s;
} else {
  viewer.currentScaleValue = 'auto';
}
Defensive patterns

Strategy: validation

Validate before calling

const s = Number(val);
if (Number.isFinite(s) && s > 0) {
  viewer.currentScale = s;
} else {
  viewer.currentScaleValue = 'auto';
}

Type guard

function isFinitePositive(v) {
  return Number.isFinite(v) && v > 0;
}

Prevention

When it happens

Trigger: Setting viewer.currentScale = NaN, or a value that coerces to NaN (e.g. Number(undefined), Number('abc')). Common when scale is derived from a failed parse or undefined UI state.

Common situations: Parsing zoom input from a text field that is empty/non-numeric; scale value from a dropdown that returned undefined; division resulting in NaN.

Related errors


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