Stop Timer API on Window or Tab Close

Hi,we are having a app that logs time automatically for agents when they are inside the ticket based on when they entered and leaves the ticket. In case if the agent closes the tab or window without leaving the ticket i couldn’t stop the timer. i want to trigger stop timer when the user closes the tab or window inside the ticket. Is there anyway to achieve this ?

Hi @arshath.h,

Welcome to the Freshworks developer community :smile:

May I know how are you currently handling the timer stop? I hope you using the App lifecycle events.

To stop the timer whenever the browser tab/browser closes, you can run a setInterval function, keep updating the end timer on the interval. So, if the browser closes you’ll have the end time equal to the last updated time from setInterval function and the time lost will not be > the interval defined in setInterval. You can decide the interval based on the level of accuracy you want.

Hope this helps!

Stay safe :slight_smile:

Hi @velmurugan,

We are currently using Core Api for Stoping and Starting the timer. We trigger the Api call based on visibility change and next or previous ticket navigation events. Are you suggesting us to use setInterval to update timer data ?

@arshath.h

Yes, I am suggesting to use setInterval only to update the stop timer data, you still need to use either the core API or App lifecycle events (if your app location is ticket_background) to start the timer!

Thanks @velmurugan for valuable solution.

This topic was automatically closed after 2 days. New replies are no longer allowed.