Welcome to the Ranch.
Please
SearchFirst. You will find that this issue has been discussed dozens of times, and that the conclusion is always that you cannot detect when the browser is closing, and you must rely on the session timeout to allow the session to invalidate itself when the timeout expires.