Electron Will-[work] Download -
: If you want to use your own styled UI for choosing a folder, you can call event.preventDefault() to stop the default behavior, then use Electron's dialog module to get a path before calling item.setSavePath() .
: Be aware that will-download might fire multiple times if your app has multiple windows sharing the same session. Use checks to ensure you only handle downloads relevant to the current user context.
const { session } = require('electron'); session.defaultSession.on('will-download', (event, item, webContents) => { // 1. Set the save path (this bypasses the native save dialog) item.setSavePath('/path/to/save/file.ext'); // 2. Monitor progress item.on('updated', (event, state) => { if (state === 'progressing') { if (item.isPaused()) { console.log('Download is paused'); } else { console.log(`Received bytes: ${item.getReceivedBytes()}`); } } else if (state === 'interrupted') { console.log('Download was interrupted'); } }); // 3. Handle completion item.once('done', (event, state) => { if (state === 'completed') { console.log('Download successfully finished'); } else { console.log(`Download failed: ${state}`); } }); }); Use code with caution. Key Methods of the DownloadItem Class electron will-download
will-download is fired for every window when downloading a file
: If your app needs to download updates or assets in the background, use setSavePath immediately within the will-download listener to prevent interrupting the user. : If you want to use your own
The DownloadItem provides several methods to manage the lifecycle of a download:
: Defines where the file will be saved. If this is called, Electron will not prompt the user with a Save As dialog. const { session } = require('electron'); session
: Ensure you are listening to the correct session. If your BrowserWindow uses a custom partition, you must attach the listener to that specific partition's session.



