Open FranklinYu opened 5 years ago
I added this code, and chrome closes and node process exits, but I don't know why.
chrome side:
window.onbeforeunload = exit;
nodejs side:
await app.exposeFunction('exit', () => {
app.exit();
process.exit();
});
Node.js: 10.15.0 Carlo: 0.9.43 Windows 10 1809
@shosatojp Thanks, that works. In addition, following doesn't work:
document.addEventListener('beforeunload', exit)
I have no idea why the event beforeunload
doesn't work with addEventListener
. Isn't addEventListener
preferred?
@FranklinYu I wrote this code, and checked preserve log option on chrome and pressed f5 to reflesh. I thought beforeunload
event of window
emits but document
doesn't emit. addEventListener
is not a cause.
document.addEventListener('beforeunload', function () {
console.log('document beforeunload');
});
window.addEventListener('beforeunload', function () {
console.log('window beforeunload');
});
log:
//F5
window beforeunload
//F5
window beforeunload
FYI, window.addEventListener('beforeunload', exit)
works.
I tried the exact example in https://github.com/GoogleChromeLabs/carlo#usage. After I close the Chrome window, the node process did not exit, so I think the
exit
event is not emitted.Node.js 10.14.2 Carlo 0.9.43 Windows 10, version 1803
Please advise if full
package-lock.json
is needed.