parallax/jsPDF · error · Error

Invalid arguments passed to jsPDF.context2d.translate

Error message

Invalid arguments passed to jsPDF.context2d.translate

What it means

translate validates x and y with isNaN before multiplying the translation matrix into the context transform. Omitting either argument or passing non-numeric values throws.

Source

Thrown at src/modules/context2d.js:1486

      0.0,
      0.0
    );
    this.ctx.transform = this.ctx.transform.multiply(matrix);
  };

  /**
   * Remaps the (0,0) position on the canvas
   *
   * @name translate
   * @function
   * @param x {Number} The value to add to horizontal (x) coordinates
   * @param y {Number} The value to add to vertical (y) coordinates
   * @description The translate() method remaps the (0,0) position on the canvas.
   */
  Context2D.prototype.translate = function(x, y) {
    if (isNaN(x) || isNaN(y)) {
      console.error("jsPDF.context2d.translate: Invalid arguments", arguments);
      throw new Error("Invalid arguments passed to jsPDF.context2d.translate");
    }
    var matrix = new Matrix(1.0, 0.0, 0.0, 1.0, x, y);
    this.ctx.transform = this.ctx.transform.multiply(matrix);
  };

  /**
   * Replaces the current transformation matrix for the drawing
   *
   * @name transform
   * @function
   * @param a {Number} Horizontal scaling
   * @param b {Number} Horizontal skewing
   * @param c {Number} Vertical skewing
   * @param d {Number} Vertical scaling
   * @param e {Number} Horizontal moving
   * @param f {Number} Vertical moving
   * @description Each object on the canvas has a current transformation matrix.<br /><br />The transform() method replaces the current transformation matrix. It multiplies the current transformation matrix with the matrix described by:<br /><br /><br /><br />a    c    e<br /><br />b    d    f<br /><br />0    0    1<br /><br />In other words, the transform() method lets you scale, rotate, move, and skew the current context.
   */

View on GitHub (pinned to a3930ce03a)

Solutions

  1. Pass two finite numbers; default missing to 0.
  2. Guard: if (Number.isFinite(+x) && Number.isFinite(+y)) ctx.translate(+x, +y);
  3. Coerce with Number() upstream in your layout pipeline.

Example fix

// before
ctx.translate(origin.x, origin.y); // origin.y undefined -> throws [111]

// after
ctx.translate(+origin.x || 0, +origin.y || 0);
Defensive patterns

Strategy: validation

Validate before calling

function safeTranslate(ctx, x, y) {
  ctx.translate(Number.isFinite(+x) ? +x : 0, Number.isFinite(+y) ? +y : 0);
}

Type guard

function isTranslateArgs(x, y) { return Number.isFinite(+x) && Number.isFinite(+y); }

Try / catch

try { ctx.translate(x, y); }
catch (e) { if (!/context2d.translate/.test(e.message)) throw e; }

Prevention

When it happens

Trigger: ctx.translate(x, y) with either argument undefined, omitted, or non-numeric; reading offsets from an unset origin object.

Common situations: Translating by computed deltas where one component is missing; passing a single argument expecting (x,x); stringified coordinates from config.

Related errors


AI-assisted analysis of parallax/jsPDF@a3930ce03a (2026-08-13). Data as JSON: /api/errors/b53beaf6ebeed825. Report an issue: GitHub.