eligrey/FileSaver.js · warning
Deprecated: Expected third argument to be a object
Error message
Deprecated: Expected third argument to be a object
What it means
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.
Source
Thrown at src/FileSaver.js:22
*
* By Eli Grey, http://eligrey.com
*
* License : https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md (MIT)
* source : http://purl.eligrey.com/github/FileSaver.js
*/
// The one and only way of getting global scope in all environments
// https://stackoverflow.com/q/3277182/1008999
var _global = typeof window === 'object' && window.window === window
? window : typeof self === 'object' && self.self === self
? self : typeof global === 'object' && global.global === global
? global
: this
function bom (blob, opts) {
if (typeof opts === 'undefined') opts = { autoBom: false }
else if (typeof opts !== 'object') {
console.warn('Deprecated: Expected third argument to be a object')
opts = { autoBom: !opts }
}
// prepend BOM for UTF-8 XML and text/* types (including HTML)
// note: your browser will automatically convert UTF-16 U+FEFF to EF BB BF
if (opts.autoBom && /^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(blob.type)) {
return new Blob([String.fromCharCode(0xFEFF), blob], { type: blob.type })
}
return blob
}
function download (url, name, opts) {
var xhr = new XMLHttpRequest()
xhr.open('GET', url)
xhr.responseType = 'blob'
xhr.onload = function () {
saveAs(xhr.response, name, opts)
}View on GitHub (pinned to cea522bc41)
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.
Example fix
// before
saveAs(blob, 'report.xml', true);
// after
saveAs(blob, 'report.xml', { autoBom: true }); Defensive patterns
Strategy: type-guard
Validate before calling
function assertSaveAsOpts(opts) {
if (opts !== undefined && (typeof opts !== 'object' || Array.isArray(opts))) {
throw new TypeError('saveAs third argument must be an options object: { autoBom: boolean }');
}
}
assertSaveAsOpts(thirdArg); Type guard
function isSaveAsOptions(v) {
return v === undefined || (typeof v === 'object' && v !== null && typeof v.autoBom === 'boolean');
} Try / catch
// The warning is not throw, so wrap calls to intercept/normalize legacy args:
function safeSaveAs(blob, name, opts) {
if (typeof opts !== 'object' && typeof opts !== 'undefined') {
opts = { autoBom: !!opts };
}
return saveAs(blob, name, opts);
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
AI-assisted analysis of eligrey/FileSaver.js@cea522bc41 (2026-09-01).
Data as JSON: /api/errors/8013802332e39b63.
Report an issue: GitHub.