4

The app I'm building, when I compile it for distribution packing it with electron-builder, every now and then, dies, showing a blank screen and a disconnected devtools:

enter image description here

Any ideas what's going on or how to start figuring out what's happening here?

Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622

2 Answers2

2

Listen for the uncaughtException event and log any error that you get. This will give you insight into what is happening. Then perform any cleanup if necessary and relaunch the app if desired. This allows your app to "recover" from crashes if it is intended to be long-running.

//handle crashes and kill events
process.on('uncaughtException', function(err) {
  //log the message and stack trace
  fs.writeFileSync('crash.log', err + "\n" + err.stack);

  //do any cleanup like shutting down servers, etc

  //relaunch the app (if you want)
  app.relaunch({args: []});
  app.exit(0);
});

You can also listen to the SIGTERM event to see if your application is being killed off, and also gracefully shutdown servers, restart, etc.

process.on('SIGTERM', function() {
  fs.writeFileSync('shutdown.log', "Received SIGTERM signal");

  //do any cleanup like shutting down servers, etc

  //relaunch the app (if you want)
  app.relaunch({args: []});
  app.exit(0);
});
AlienHoboken
  • 2,750
  • 20
  • 23
1

This can be caused by several different serious faults in the renderer process (out of memory, for example). To fix it, you really have to get your hands on the error.

See https://www.electronjs.org/docs/tutorial/application-debugging#v8-crashes for more details. Specifically, I would recommend settings the ELECTRON_ENABLE_LOGGING environment variable to true before launching the electron process, this should result in the error showing up in the console from which you launch the main process (NOT the chrome devtools console).

RocketMan
  • 441
  • 4
  • 15