I'm building an electron app that must reload the render process window if a crash happens.
Currently I can restart the app from the main process
app.relaunch();
app.quit();
But I cannot detect the window crashing. I tried using the
win.on('unresponsive', () => { ... } );
But the event is not getting generated when I crash the process.
To crash the process I tried:
process.crash()
Both ways successfully crash the process but again, I cannot find a way to detect it.
I tried also using, from the render process, the window.onerror(...)
and sending via IPC to the main process a message when the crash is detected, but this seems not to work as well.
You should be looking for the 'crashed' event in webContents. Check https://electronjs.org/docs/api/web-contents#event-crashed
For example put something like this in main process:
win.webContents.on('crashed', (e) => {
app.relaunch();
app.quit()
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With