How to prevent download prompts from appearing?


#1

Is there a way to disable the “Save as” prompts globally? I don’t want my electron app to have these dialogs since it pauses a timer script whenever it shows up. My app loads other users’ websites in a webview and since I do not have control over their content, the guests’ content can force download prompts which is undesirable (same goes for dialogs).

I think “will-download” has something to do with disabling it but I don’t know exactly how to go about doing this. Any help would be highly appreciated, thanks!


#2

There is an option to save the content automatically without even asking about the location to user.

Do you want to disable the pop up/dialogues check this thread
https://github.com/electron/electron/issues/10588

Please explain clearly if your question is different


#3

Hi @myfrndjk1, thanks for your help. I actually don’t want them to download any items with Electron app, so completely disable the “save as” dialog. I think the “save as” dialog is unrelated to the alert/confirm/prompt dialogs because when I added “alert = confirm = prompt = function () {};”, the alert/confirm/prompt will not occur but “save as” dialog will still occur.


#4

Below code may help you. Shamelessly stolen from https://github.com/electron/electron/issues/5024

// main.js
let webviewSession = session.fromPartition(partitionName);
webviewSession.on('will-download', function(e, item, webContents) {
    if (item.getMimeType() === "application/pdf") {
        e.preventDefault()
        // logic
    }
})

#5

Thanks! It is working now :slight_smile: