parallax/jsPDF · error · Error
Invalid arguments passed to jsPDF.context2d.strokeRect
Error message
Invalid arguments passed to jsPDF.context2d.strokeRect
What it means
strokeRect validates x/y/w/h with isNaN up front and throws before the transparency check or beginPath/rect/stroke pipeline. Even when the stroke style is fully transparent, the guard still fires because validation precedes isStrokeTransparent.
Source
Thrown at src/modules/context2d.js:1119
this.lineJoin = tmp.lineJoin;
}
};
/**
* Draws a rectangle (no fill)
*
* @name strokeRect
* @function
* @param x {Number} The x-coordinate of the upper-left corner of the rectangle
* @param y {Number} The y-coordinate of the upper-left corner of the rectangle
* @param w {Number} The width of the rectangle, in pixels
* @param h {Number} The height of the rectangle, in pixels
* @description The strokeRect() method draws a rectangle (no fill). The default color of the stroke is black.
*/
Context2D.prototype.strokeRect = function strokeRect(x, y, w, h) {
if (isNaN(x) || isNaN(y) || isNaN(w) || isNaN(h)) {
console.error("jsPDF.context2d.strokeRect: Invalid arguments", arguments);
throw new Error("Invalid arguments passed to jsPDF.context2d.strokeRect");
}
if (isStrokeTransparent.call(this)) {
return;
}
this.beginPath();
this.rect(x, y, w, h);
this.stroke();
};
/**
* Clears the specified pixels within a given rectangle
*
* @name clearRect
* @function
* @param x {Number} The x-coordinate of the upper-left corner of the rectangle
* @param y {Number} The y-coordinate of the upper-left corner of the rectangle
* @param w {Number} The width of the rectangle to clear, in pixels
* @param h {Number} The height of the rectangle to clear, in pixelsView on GitHub (pinned to a3930ce03a)
Solutions
- Coerce to finite numbers and guard with Number.isFinite before calling.
- Provide explicit numeric defaults (e.g. 0) for missing dimensions.
- Move dimension validation into a shared helper used by rect/fillRect/strokeRect/clearRect.
Example fix
// before
ctx.strokeRect(o.x, o.y, o.w, o.h);
// after
function safeStrokeRect(ctx, x, y, w, h) {
if (![x, y, w, h].every(v => Number.isFinite(+v))) return;
ctx.strokeRect(+x, +y, +w, +h);
} Defensive patterns
Strategy: validation
Validate before calling
function safeStrokeRect(ctx, x, y, w, h) {
const a = [x, y, w, h].map(Number);
if (!a.every(Number.isFinite)) return;
ctx.strokeRect(...a);
} Type guard
const isFinite4 = (x,y,w,h) => [x,y,w,h].every(v => typeof v === 'number' && Number.isFinite(v));
Try / catch
try { ctx.strokeRect(x, y, w, h); }
catch (e) { if (!/context2d.strokeRect/.test(e.message)) throw e; } Prevention
- Treat border-drawing as optional and skip when dimensions are absent.
- Centralize dimension validation so all four rect-family calls share it.
When it happens
Trigger: ctx.strokeRect(x, y, w, h) where any argument is undefined, omitted, or non-numeric; computing dimensions from null/undefined layout data.
Common situations: Drawing borders around optional panels where dimensions may be absent; passing template-literal numbers; measurement racing producing NaN mid-layout.
Related errors
- Invalid arguments passed to jsPDF.context2d.rect
- Invalid arguments passed to jsPDF.context2d.fillRect
- Invalid arguments passed to jsPDF.context2d.clearRect
- Invalid arguments passed to jsPDF.context2d.fillText
- Invalid arguments passed to jsPDF.context2d.strokeText
AI-assisted analysis of parallax/jsPDF@a3930ce03a (2026-08-13).
Data as JSON: /api/errors/ca9012f0d49fa858.
Report an issue: GitHub.