Logout the user when browser tab/window is closed but not on refresh

In one of my angular project i’m facing a problem where user is getting logged out when browser is refreshed but i need to logout user only when browser tab/window is closed. Though i’m able to logout the user whenever browser window/tab is closed but same logout api call is made whenever i’m refreshing the browser.

Is there any way to differentiate between the browser refresh and browser close ? Or is there any way to call logout api only when tab/window is closed ?

Any help on this is highly appreciated. Thanks in advance.

I tried native javascript’s beforeunload event to logout the user whenever tab is closed but same logout api is being called whenever i’m refreshing the browser. My expectation is to logout user only when tab/window is closed.