How to disable alert dialogs when errors occur


I’ve been using electron as a way to replace phantomjs on my server (which has no GUI, I’m using xvfb).

I have had an issue where electron seemingly gets stuck and no errors are printed to the console. It turns out that I DID have an error but I couldn’t see it because it was going to an alert popup which was showing up in xfvb, and consequentially locks electron up (at least this is my best guess).

Is there a way to disable alert dialogs when errors occur, or better yet disable ALL dialogs? Dialogs are useless in headless mode (granted electron is not intended to be a headless app) and just get things stuck.

I’m not necessarily looking for a flag ‘disable_dialogs’. Perhaps I could override one method in the main process so that dialogs don’t open, or maybe just that they close instantly?


I didn’t get an official answer so I just tried out changing dialog.showErrorBox.

I just overrode the method to log to the console instead of the default behavior. Works for me.


Can you explain how you override the method to log to the console?

const electron = require('electron');
const dialog = electron.dialog;

// Disable error dialogs by overriding
// FIX:
dialog.showErrorBox = function(title, content) {


What file are you making these changes in?


Tried above code but error dialog still pop up. By the way, I add the code at the very beginning before ready event.


By inputting such script, console.log(alert.toString()), in the console of development tool, I found the following script.

function (message, title) {
    ipcRenderer.sendSync('ELECTRON_BROWSER_WINDOW_ALERT', toString(message), toString(title))

I found that alert from renderer processes is sent through IPC, so what I want to do is to disable the original event listeners and manage the ELECTRON_BROWSER_WINDOW_ALERT event by my event listener.

Here is my solution:

ipcMain.on("ELECTRON_BROWSER_WINDOW_ALERT", (event, message, title)=>{
  console.warn(`[Alert] ** ${title} ** ${message}`)
  event.returnValue = 0 // **IMPORTANT!**

Note that the returnValue is required to make everything works as nothing happens.
I test it in the console of my electron devTool and if there is no returnValue provided, the console will keep waiting for it without handling newly typed scripts, therefore I provide a return value equal to 0 for the synchronized IPC.