I have a question about making http requests on beforeunload event. The window:beforeunload is a synchronous event, so if I perform an async action within the event listener the event is completed before my async action. That is why my http request is never made. I know that it is possible to use fetch API or navigator.sendBeacon method, but are there any built-in approaches or recommended 'angular' way for this functionality?
Here is an approach using async/await and angular httpClient, which is not working.
@HostListener('window:beforeunload')
async beforeUnload(): Promise<void>{
await this.articleService.setArticlePersistence({});
}