I am trying to capture browser events like tab-close and refresh in my angular 6 Application. It's working fine in debug mode but its not working if I close debug mode and run the application. below is the piece of code
registerDOMEvents() {
window.addEventListener('unload', () => {
if (this.validNavigation === 0) {
this.endSession();
}
});
document.addEventListener('keydown', (e) => {
const key = e.which || e.keyCode;
if (key === 116) {
this.validNavigation = 1;
}
});
}
endSession() {
this.logout();
localStorage.clear();
}
ngOnInit() {
this.registerDOMEvents();
}
What might me the problem for this issue?