'How to log the time when a user closes a flask view?

I am developing a flask Application, now the requirement is to log the time when the user closes a specific flask view (or exits a flask URL). Simple example would be suppose a user is working on '/home' and now closes the browser tab or the browser itself. Then how to record the time for this particular event?

Please help



Solution 1:[1]

This worked for me with similar use case as ajax calls cannot be made anymore so please use navigator.sendBeacon

https://stackoverflow.com/a/20322988/10738743

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1