You can listen to the unload or beforeunload events like this:
export class AppComponent {
@HostListener('window:unload', [ '$event' ])
unloadHandler(event) {
// ...
}
@HostListener('window:beforeunload', [ '$event' ])
beforeUnloadHandler(event) {
// ...
}
}
See also
Detect browser or tab closing
https://developer.mozilla.org/de/docs/Web/Events/unload




![Cannot read property ‘toLowerCase’ of undefined [ERROR] An error occurred while running subprocess cordova.](https://blog.rahulbhutani.com/wp-content/uploads/2020/12/ionic-enable-xcode-permissions-banner-100x70.png)












