How does Electron intercept page download events?

the default download event of Electron does not support downloading at breakpoints. I want to call my own download function after intercepting it. The download function has been written. Now the main problem is to intercept the download event of the page (the html page is not written by myself). Is there any God who understands it

Mar.23,2021

The

problem is solved. When the page performs the download operation, the webContents.downloadURL (url) of Electron will be called automatically, and the will-download event of session will be triggered. Just listen to the will-download event of session, then call event.preventDefault () to prevent the default download of the calling system, and then call your own download function. Thank you
mainWindow.webContents.session.on ('will-download', (event,item,webContents) = > {

).
    event.preventDefault();
    //console.log('will-download'+item.getURL());
    //
    MyDownLoad(item.getURL());
});

I just wrote about electron download some time ago. What is a normal electron implementation download like?
first, let's talk about the ipc communication of electron. ipcMain , ipcRenderer
the main process and the rendering process in electron are
main process (main.js) that communicates through ipc. Define the monitoring function

.
ipcMain.on('download', (evt, args) => {
    let url = JSON.parse(args);
    downloadUrl = url.downloadUrl;
    saveUrl = url.saveUrl;
    mainWindow.webContents.downloadURL(downloadUrl);
});

rendering process (page) calls ipcRenderer to trigger

ipcRenderer.send('download', JSON.stringify({
    downloadUrl: `${ipURL()}${url}`,
    saveUrl: result[0]
}));

in this way, you can trigger the download action of the main process. As for what the download action is, I won't write about it. Officially, there are
if you want to stop electron, just put the

in main.js.
ipcMain.on('download', (evt, args) => {
    let url = JSON.parse(args);
    downloadUrl = url.downloadUrl;
    saveUrl = url.saveUrl;
    //mainWindow.webContents.downloadURL(downloadUrl);
});

just comment out

of course, everyone may write differently, but they are all sent from the rendering process to the main process through ipc. Find the actions that start downloading in the main process, and turn it off


File download is an action of the browser, and this part does not interact with js

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b39c5c-40749.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b39c5c-40749.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?