I have to detect closing browser event so I close the user's connection. I have tried the following method:
@HostListener('window:beforeunload', ['$event'])
beforeUnloadHandler(event) {
/**
* Post a single object to the server
* Send Beacon API to keep request after browser windowunload event
*/
navigator.sendBeacon(`${this.appConfigService.appConfig.apiUrl}/Account/LogoutDirectly/`);
}
on my app.component.ts. I tried this on both Chrome and Firefox. But it doesn't trigger anything.
Ressources where following:
Angular 8 HostListener 'window:unload' how to make API call before unload