I'm trying to invoke an API call as soon as the tab or browser closes. For this I'm using 'onBeforeUnload' event. Currently, as soon as the browser is closed, the API is not getting called always. It works 2-3 times out of 10 times. Is there a way where I can ensure that the API gets called every time.
Asked
Active
Viewed 401 times
0
-
Why do you think you need this? – CodeCaster Nov 04 '22 at 11:20
1 Answers
0
Can you add more details about your requirement, as I do not recommend this approach you are using. As it is very unsafe to use you cannot ensure it will always run as there are many scenario involved like process termination, power cut of local pc, internet disconnected and many more.
In case you only want to detect user is alive or working on your application you can create a Heartbeat kind of api that will tell the system that user is active and when server did not receive heartbeat for a defined time you can consider that as closing event.
if you can post the what you want to achieve people will defiantly help.

Sunil Soni
- 443
- 3
- 18
-
Requirement is to pass some user related details to a backend system and to let the system know that user has kind of abandoned the application by either closing the browser or tab. – 05_pingpong Nov 04 '22 at 12:19