parallax/jsPDF · error · TypeError
Failed to execute '" + kind + "' on 'FileReader': parameter
Error message
Failed to execute '" + kind + "' on 'FileReader': parameter 1 is not of type 'Blob'.
What it means
Thrown by the Blob.js polyfill's internal _read helper (used by readAsText/readAsArrayBuffer/readAsDataURL/readAsBinaryString) when the first argument is not an instance of Blob. The polyfill type-checks before scheduling the async read to fail fast and match the native DOM TypeError message format.
Source
Thrown at src/libs/Blob.js:332
function FileReader() {
if (!(this instanceof FileReader))
throw new TypeError(
"Failed to construct 'FileReader': Please use the 'new' operator, this DOM object constructor cannot be called as a function."
);
var delegate = document.createDocumentFragment();
this.addEventListener = delegate.addEventListener;
this.dispatchEvent = function(evt) {
var local = this["on" + evt.type];
if (typeof local === "function") local(evt);
delegate.dispatchEvent(evt);
};
this.removeEventListener = delegate.removeEventListener;
}
function _read(fr, blob, kind) {
if (!(blob instanceof Blob))
throw new TypeError(
"Failed to execute '" +
kind +
"' on 'FileReader': parameter 1 is not of type 'Blob'."
);
fr.result = "";
setTimeout(function() {
this.readyState = FileReader.LOADING;
fr.dispatchEvent(new Event("load"));
fr.dispatchEvent(new Event("loadend"));
});
}
FileReader.EMPTY = 0;
FileReader.LOADING = 1;
FileReader.DONE = 2;
FileReader.prototype.error = null;View on GitHub (pinned to a3930ce03a)
Solutions
- Wrap the data in a Blob first: fr.readAsDataURL(new Blob([data])).
- If you already have text, skip FileReader and use the string directly.
- Type-check the argument before calling any read method.
Example fix
// before fr.readAsText(rawString); // after fr.readAsText(new Blob([rawString]));
Defensive patterns
Strategy: type-guard
Validate before calling
function isBlob(v){ return v instanceof Blob; }
if (isBlob(data)) fr.readAsDataURL(data); else fr.readAsDataURL(new Blob([data])); Type guard
function isBlob(v){ return typeof Blob !== 'undefined' && v instanceof Blob; } Try / catch
try { fr.readAsText(data); } catch (e) { if (/is not of type 'Blob'/.test(e.message)) fr.readAsText(new Blob([data])); else throw e; } Prevention
- Wrap raw bytes/strings in a Blob before read methods
- Check instanceof Blob at trust boundaries
When it happens
Trigger: Calling fr.readAsDataURL(stringOrObject) where the argument is a plain string, ArrayBuffer, or object instead of a Blob/File. Passing a base64 string directly; passing the wrong variable; calling read on already-extracted raw bytes.
Common situations: Forgetting to wrap bytes in a Blob before reading; confusing FileReader (which needs a Blob) with a raw byte consumer; legacy code that passed strings to a non-conforming shim.
Related errors
- Failed to construct 'FileReader': Please use the 'new' opera
- Line join style of '" + style + "' is not recognized. See or
- Invalid argument passed to jsPDF.setLineMiterLimit
- Invalid argument passed to jsPDF.addField.
- getTextDimensions expects text-parameter to be of type Strin
AI-assisted analysis of parallax/jsPDF@a3930ce03a (2026-08-13).
Data as JSON: /api/errors/5ab08b81500060d8.
Report an issue: GitHub.