Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

showSaveFilePicker not in Firefox - what can I use instead?

With great surprise I found out that FF does not support window.showSaveFilePicker.

caniuse-showSaveFilePicker

What could I use in FF to allow saving a file from the browser programmatically?

Maybe can someone explain what reasons has FF for not supporting this feature?

like image 923
Marco Faustinelli Avatar asked Jan 29 '26 20:01

Marco Faustinelli


2 Answers

Assuming you're working with blobs under ~2GB you can always use a classic:

async function downloadBlob(inputblob) {
  const downloadelem = document.createElement("a");
  const url = URL.createObjectURL(inputblob);
  document.body.appendChild(downloadelem);
  downloadelem.href = url;
  downloadelem.click();
  downloadelem.remove();
  window.URL.revokeObjectURL(url);
}
downloadBlob(yourblob);
This will invoke the user's preference of whether to download the file directly to a folder or to select a place in which to put it. As far as I'm aware there is no other method to invoke a file picker if the user has it left at the default which in most cases is to download without confirmation.

Answering your question regarding why Firefox doesn't support it, Mozilla doesn't believe that the File System Access specification, which this endpoint is a part of, is a good addition to the web. You can read more here.

EDIT February 17, 2025: Fix the .src which should've been .href as pointed out by @josh.

like image 97
SpaceSaver2000 Avatar answered Feb 03 '26 08:02

SpaceSaver2000


@SpaceSaver2000's answer almost worked for me. After some more poking around, I got this to work:

async function downloadBlob(inputblob) {
  const downloadelem = document.createElement("a");
  const url = URL.createObjectURL(inputblob);
  document.body.appendChild(downloadelem);
  downloadelem.href = url;
  downloadelem.download = 'filename.txt';
  downloadelem.click();
  downloadelem.remove();
  window.URL.revokeObjectURL(url);
}
downloadBlob(yourblob);

Mostly from here: https://stackoverflow.com/a/35488280/423384

like image 20
Josh Avatar answered Feb 03 '26 07:02

Josh