{"record":{"id":"8013802332e39b63","repo":"eligrey/FileSaver.js","slug":"deprecated-expected-third-argument-to-be-a-object","errorCode":null,"errorMessage":"Deprecated: Expected third argument to be a object","messagePattern":"Deprecated: Expected third argument to be a object","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/FileSaver.js","lineNumber":22,"sourceCode":"*\n* By Eli Grey, http://eligrey.com\n*\n* License : https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md (MIT)\n* source  : http://purl.eligrey.com/github/FileSaver.js\n*/\n\n// The one and only way of getting global scope in all environments\n// https://stackoverflow.com/q/3277182/1008999\nvar _global = typeof window === 'object' && window.window === window\n  ? window : typeof self === 'object' && self.self === self\n  ? self : typeof global === 'object' && global.global === global\n  ? global\n  : this\n\nfunction bom (blob, opts) {\n  if (typeof opts === 'undefined') opts = { autoBom: false }\n  else if (typeof opts !== 'object') {\n    console.warn('Deprecated: Expected third argument to be a object')\n    opts = { autoBom: !opts }\n  }\n\n  // prepend BOM for UTF-8 XML and text/* types (including HTML)\n  // note: your browser will automatically convert UTF-16 U+FEFF to EF BB BF\n  if (opts.autoBom && /^\\s*(?:text\\/\\S*|application\\/xml|\\S*\\/\\S*\\+xml)\\s*;.*charset\\s*=\\s*utf-8/i.test(blob.type)) {\n    return new Blob([String.fromCharCode(0xFEFF), blob], { type: blob.type })\n  }\n  return blob\n}\n\nfunction download (url, name, opts) {\n  var xhr = new XMLHttpRequest()\n  xhr.open('GET', url)\n  xhr.responseType = 'blob'\n  xhr.onload = function () {\n    saveAs(xhr.response, name, opts)\n  }","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/eligrey/FileSaver.js/blob/cea522bc41bfadc364837293d0c4dc585a65ac46/src/FileSaver.js#L4-L40","documentation":"This is a deprecation warning emitted by FileSaver.js's internal `bom` helper (src/FileSaver.js:22), called from `saveAs`. In older versions the third argument to `saveAs(blob, name, useAutoBom)` was a boolean; the library now expects an options object (`{ autoBom: boolean }`). If a non-object (typically a boolean or string) is passed, the warning is printed and the value is coerced to `{ autoBom: !opts }` so old boolean calls keep working, but the API contract is deprecated.","triggerScenarios":"Calling `saveAs(blob, 'name.txt', true)` or `saveAs(blob, 'name.txt', false)` — passing a boolean as the third argument. Also any truthy/falsy non-object third argument (string, number) reaches `typeof opts !== 'object'` and triggers the warning.","commonSituations":"Upgrading FileSaver.js from 1.x (boolean third arg) to 2.x (options object) without updating call sites; copy-pasted legacy tutorials showing `saveAs(data, file, true)`; code that forwards a flag variable as the third argument.","solutions":["Replace the boolean third argument with an options object: `saveAs(blob, name, { autoBom: true })`.","If you did not intend to control BOM behavior, drop the third argument entirely: `saveAs(blob, name)` (defaults to autoBom: false).","Search the codebase for `saveAs(` calls with a third argument and update all call sites, since the warning fires per call."],"exampleFix":"// before\nsaveAs(blob, 'report.xml', true);\n\n// after\nsaveAs(blob, 'report.xml', { autoBom: true });","handlingStrategy":"type-guard","validationCode":"function assertSaveAsOpts(opts) {\n  if (opts !== undefined && (typeof opts !== 'object' || Array.isArray(opts))) {\n    throw new TypeError('saveAs third argument must be an options object: { autoBom: boolean }');\n  }\n}\nassertSaveAsOpts(thirdArg);","typeGuard":"function isSaveAsOptions(v) {\n  return v === undefined || (typeof v === 'object' && v !== null && typeof v.autoBom === 'boolean');\n}","tryCatchPattern":"// The warning is not throw, so wrap calls to intercept/normalize legacy args:\nfunction safeSaveAs(blob, name, opts) {\n  if (typeof opts !== 'object' && typeof opts !== 'undefined') {\n    opts = { autoBom: !!opts };\n  }\n  return saveAs(blob, name, opts);\n}","preventionTips":["Always pass `{ autoBom: true|false }` instead of a bare boolean as saveAs's third argument.","Add an ESLint/CI grep check for `saveAs(` calls with a non-object third argument.","Pin and read the library's changelog when upgrading across major versions (1.x -> 2.x changed this signature).","Wrap saveAs in a small internal helper that normalizes legacy boolean flags before calling the library."],"tags":["deprecation","filesaver","api-change","console-warning"],"backgroundTag":"deprecated-api-signature","analyzedSha":"cea522bc41bfadc364837293d0c4dc585a65ac46","analyzedAt":"2026-09-01T10:08:17.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}