{"record":{"id":"5ab08b81500060d8","repo":"parallax/jsPDF","slug":"failed-to-execute-kind-on-filereader","errorCode":null,"errorMessage":"Failed to execute '\" + kind + \"' on 'FileReader': parameter 1 is not of type 'Blob'.","messagePattern":"Failed to execute '\" \\+ kind \\+ \"' on 'FileReader': parameter 1 is not of type 'Blob'\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/libs/Blob.js","lineNumber":332,"sourceCode":"  function FileReader() {\n    if (!(this instanceof FileReader))\n      throw new TypeError(\n        \"Failed to construct 'FileReader': Please use the 'new' operator, this DOM object constructor cannot be called as a function.\"\n      );\n\n    var delegate = document.createDocumentFragment();\n    this.addEventListener = delegate.addEventListener;\n    this.dispatchEvent = function(evt) {\n      var local = this[\"on\" + evt.type];\n      if (typeof local === \"function\") local(evt);\n      delegate.dispatchEvent(evt);\n    };\n    this.removeEventListener = delegate.removeEventListener;\n  }\n\n  function _read(fr, blob, kind) {\n    if (!(blob instanceof Blob))\n      throw new TypeError(\n        \"Failed to execute '\" +\n          kind +\n          \"' on 'FileReader': parameter 1 is not of type 'Blob'.\"\n      );\n\n    fr.result = \"\";\n\n    setTimeout(function() {\n      this.readyState = FileReader.LOADING;\n      fr.dispatchEvent(new Event(\"load\"));\n      fr.dispatchEvent(new Event(\"loadend\"));\n    });\n  }\n\n  FileReader.EMPTY = 0;\n  FileReader.LOADING = 1;\n  FileReader.DONE = 2;\n  FileReader.prototype.error = null;","sourceCodeStart":314,"sourceCodeEnd":350,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/libs/Blob.js#L314-L350","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nfr.readAsText(rawString);\n// after\nfr.readAsText(new Blob([rawString]));","handlingStrategy":"type-guard","validationCode":"function isBlob(v){ return v instanceof Blob; }\nif (isBlob(data)) fr.readAsDataURL(data); else fr.readAsDataURL(new Blob([data]));","typeGuard":"function isBlob(v){ return typeof Blob !== 'undefined' && v instanceof Blob; }","tryCatchPattern":"try { fr.readAsText(data); } catch (e) { if (/is not of type 'Blob'/.test(e.message)) fr.readAsText(new Blob([data])); else throw e; }","preventionTips":["Wrap raw bytes/strings in a Blob before read methods","Check instanceof Blob at trust boundaries"],"tags":["blob","filereader","polyfill","type-check","argument"],"backgroundTag":null,"analyzedSha":"a3930ce03a585a26b2c76d12a0f413ce96f6d1a3","analyzedAt":"2026-08-13T05:33:39.648Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}