FileSaver.js
FileSaver.js copied to clipboard
Add stripped down / Modern version
i found this lib via stackoverflow but i luckely dont need to support ancient browsers of times from the dinosaurs so i was able to strip it down to the most important parts ;) works in chrome and firefox ^^
// stripped down version of https://github.com/eligrey/FileSaver.js/blob/master/src/FileSaver.js#L81-L108
/**
* @param {Blob} blob
* @param {string} name
*/
export const saveAs = (blob, name) => {
// Namespace is used to prevent conflict w/ Chrome Poper Blocker extension (Issue https://github.com/eligrey/FileSaver.js/issues/561)
const a = document.createElementNS('http://www.w3.org/1999/xhtml', 'a')
a.download = name
a.rel = 'noopener'
a.href = URL.createObjectURL(blob)
setTimeout(() => URL.revokeObjectURL(a.href), 40 /* sec */ * 1000)
setTimeout(() => a.click(), 0)
}
Maybe add this to the readme - so one can decide to use this 8 liner by copy pasta ^^
Thank you! REALLY helpful 😘
Indeed, this helped us avoid the "This file cannot be downloaded securely" error which where caused by the Chrome 119.0.6045.105 update: https://chromereleases.googleblog.com/2023/10/stable-channel-update-for-desktop_31.html