Is there a way to update a flag in the database using a service call (Delete method) when the user closes the browser? I have tried detecting browser close actions using the onbeforeunload
and onunload
events, but asynchronous calls do not consistently work for me. Sometimes it works fine in debugging mode, but on higher environments it fails.
After attempting synchronous requests, I discovered that Chrome now prevents synchronous XHR during page dismissal or when the page is being closed by the user. More information can be found at this link:
I have experimented with using new approaches like XMLHttpRequest()
as synchronous, fetch api, and Navigator.sendBeacon()
, but unfortunately none of these options seem to work for me.
If anyone has suggestions for a working solution, please share because despite searching through various posts, I haven't found anything that works for my situation.
Thank you in advance.