I've exhausted all my research efforts in trying to find a solution that actually works. The problem I am facing is getting two methods from two different services to run when the browser or tab is closed.
I attempted using the fetch API, which worked flawlessly on Chrome but failed to cooperate on Internet Explorer. Another approach I took was implementing a while loop like the one below:
@HostListener('window:beforeunload', ['$event'])
onBeforeUnload(): void {
var sessionEnded = false;
this.userSessionService.EndSession(this.userSessionId).then(res => sessionEnded = res);;
while (sessionEnded == false) {
console.log('session not ended');
}
}
This method was successful on Chrome, however, it didn't quite cut it when trying to close the browser on IE.
Have I missed any other alternative solutions out there?
Could opening a new tab to carry out these functions and then closing upon completion be a feasible option?