I have an electron app that loads the URL of the web version of the app. However I cannot close the application by clicking in the X button and I dont have access to the webapp. I have tried this:
let count = BrowserWindow.getAllWindows().length;
///returns 1, so there is only 1 window)
window.onbeforeunload=function(e){
e.returnValue=undefined;
return undefined;
}
window.close();
app.quit();
Nothing happens.
app.exit(0)
works, but I dont want to use it. Is there a way I can close the app with window.close
and app.quit
?
EDIT:
The problem are those global beforeunload events. If i click remove in the devtools I am able to close the app.
Also this let names= window.eventNames();
returns an array that does not have any beforeunload events
You need to save the BrowserWindow object reference. Then listen for a 'closed' event and dereference it:
After dereference, it's all simple, just listen for 'window-all-closed' event on app: