Yes, the behavior can be overridden using the File System Access API. The API exposes some methods that will override the browser's behavior.
Simply running window.showOpenFilePicker()
in the Chrome Browser console will launch the file picker prompt.
To override the download destination prompt behavior, you can make use of the window.showSaveFilePicker()
method.
// ...
const blob = new Blob(/*...*/);
// Use File System Access API
saveFileToDisk(blob, 'Some-File.txt')
async saveFileToDisk({blob, fileName}){
try {
const fileHandle = await self.showSaveFilePicker({
suggestedName: fileName,
types: [
{
description: "File",
// ...
},
],
});
const writeFile = async (fileHandle, contents) => {
// Create a FileSystemWritableFileStream to write to.
const writable = await fileHandle.createWritable();
// Write the contents of the file to the stream.
await writable.write(contents);
// Close the file and write the contents to disk.
await writable.close();
};
// write file
writeFile(fileHandle, blob).then(() => console.log("FILE DOWNLOADED!!!"));
} catch (error) {
console.log(error);
}
}
For more details, check out the documentation https://web.dev/file-system-access/ and https://web.dev/browser-fs-access/