{"record":{"id":"c5c25f5a78360213","repo":"parallax/jsPDF","slug":"failed-to-construct-filereader-please-use-the","errorCode":null,"errorMessage":"Failed to construct 'FileReader': Please use the 'new' operator, this DOM object constructor cannot be called as a function.","messagePattern":"Failed to construct 'FileReader': Please use the 'new' operator, this DOM object constructor cannot be called as a function\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/libs/Blob.js","lineNumber":316,"sourceCode":"  File.prototype.constructor = File;\n\n  if (Object.setPrototypeOf) Object.setPrototypeOf(File, Blob);\n  else {\n    try {\n      File.__proto__ = Blob;\n    } catch (e) {}\n  }\n\n  File.prototype.toString = function() {\n    return \"[object File]\";\n  };\n\n  /********************************************************/\n  /*                FileReader constructor                */\n  /********************************************************/\n  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 +","sourceCodeStart":298,"sourceCodeEnd":334,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/libs/Blob.js#L298-L334","documentation":"Thrown by the Blob.js FileReader polyfill constructor when invoked as a plain function (FileReader()) rather than with `new`. The polyfill checks `this instanceof FileReader`; without `new`, `this` is the global/undefined and the check fails, mirroring native DOM behavior which requires construction with new.","triggerScenarios":"Calling var fr = FileReader(); instead of var fr = new FileReader();. Passing FileReader as a callback that drops the new operator; code written against an older non-class shim that allowed function-style invocation.","commonSituations":"Migrating from a shim that permitted function calls; copy-paste code missing the new keyword; minifiers/transforms that drop new in certain patterns.","solutions":["Always construct with new: var fr = new FileReader();.","If you have a factory wrapper, ensure it uses new internally or uses Reflect.construct.","Lint with a rule that flags missing new on known constructors."],"exampleFix":"// before\nvar fr = FileReader();\n// after\nvar fr = new FileReader();","handlingStrategy":"validation","validationCode":"var fr = new FileReader();","typeGuard":null,"tryCatchPattern":"try { var fr = new FileReader(); } catch (e) { if (/new operator/.test(e.message)) { fr = new FileReader(); } else throw e; }","preventionTips":["Always use new with FileReader","Lint for missing new on constructors"],"tags":["blob","filereader","polyfill","constructor","new-operator"],"backgroundTag":null,"analyzedSha":"a3930ce03a585a26b2c76d12a0f413ce96f6d1a3","analyzedAt":"2026-08-13T05:33:39.648Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}