parallax/jsPDF · error · Error
Invalid arguments passed to jsPDF.context2d.strokeText
Error message
Invalid arguments passed to jsPDF.context2d.strokeText
What it means
strokeText uses the same guard as fillText: isNaN(x) || isNaN(y) || typeof text !== 'string'. It validates before the stroke-transparency check. maxWidth is optional and NaN-safe (coerced to undefined).
Source
Thrown at src/modules/context2d.js:1366
maxWidth: maxWidth
});
};
/**
* Draws text on the canvas (no fill)
*
* @name strokeText
* @function
* @param text {String} Specifies the text that will be written on the canvas
* @param x {Number} The x coordinate where to start painting the text (relative to the canvas)
* @param y {Number} The y coordinate where to start painting the text (relative to the canvas)
* @param maxWidth {Number} Optional. The maximum allowed width of the text, in pixels
* @description The strokeText() method draws text (with no fill) on the canvas. The default color of the text is black.
*/
Context2D.prototype.strokeText = function(text, x, y, maxWidth) {
if (isNaN(x) || isNaN(y) || typeof text !== "string") {
console.error("jsPDF.context2d.strokeText: Invalid arguments", arguments);
throw new Error("Invalid arguments passed to jsPDF.context2d.strokeText");
}
if (isStrokeTransparent.call(this)) {
return;
}
maxWidth = isNaN(maxWidth) ? undefined : maxWidth;
var degs = rad2deg(this.ctx.transform.rotation);
var scale = this.ctx.transform.scaleX;
putText.call(this, {
text: text,
x: x,
y: y,
scale: scale,
renderingMode: "stroke",
angle: degs,
align: this.textAlign,View on GitHub (pinned to a3930ce03a)
Solutions
- Coerce text to String and validate x/y as finite numbers before calling.
- Guard the call site and skip when validation fails.
- Confirm argument order (text, x, y, [maxWidth]).
Example fix
// before
ctx.strokeText(label.value, pos.x, pos.y);
// after
if (typeof label.value === 'string' && Number.isFinite(+pos.x) && Number.isFinite(+pos.y)) {
ctx.strokeText(label.value, +pos.x, +pos.y);
} Defensive patterns
Strategy: validation
Validate before calling
function safeStrokeText(ctx, text, x, y, maxWidth) {
if (typeof text !== 'string') text = String(text);
if (!Number.isFinite(+x) || !Number.isFinite(+y)) return;
ctx.strokeText(text, +x, +y, Number.isFinite(+maxWidth) ? +maxWidth : undefined);
} Type guard
function isStrokeTextArgs(text, x, y) {
return typeof text === 'string' && Number.isFinite(+x) && Number.isFinite(+y);
} Try / catch
try { ctx.strokeText(text, x, y); }
catch (e) { if (!/context2d.strokeText/.test(e.message)) throw e; } Prevention
- Stringify labels before stroking.
- Confirm argument order (text first).
- Validate x/y as finite numbers from your layout source.
When it happens
Trigger: ctx.strokeText(text, x, y) with text not a string, or x/y undefined/NaN/non-numeric; swapping argument order so a number lands in the text slot.
Common situations: Outlining numeric labels without String() coercion; layouts where x/y come from a NaN transform; passing template strings without parsing.
Related errors
- Invalid arguments passed to jsPDF.context2d.fillText
- Invalid arguments passed to jsPDF.context2d.rect
- Invalid arguments passed to jsPDF.context2d.fillRect
- Invalid arguments passed to jsPDF.context2d.strokeRect
- Invalid arguments passed to jsPDF.context2d.clearRect
AI-assisted analysis of parallax/jsPDF@a3930ce03a (2026-08-13).
Data as JSON: /api/errors/501c8e171a95e574.
Report an issue: GitHub.