Logout when closing the browser

Enonic version: 7.2.2
OS: Linux

Hello, is there a way to logoff the user after closing a tab or browser? With or without an idprovider app.

Maybe you can listen to the beforeunload event, and either do an ajax-call there to log out, or delete the cookie?

Here is a slightly hackish solution to figure out if user is closing browser, or just navigating on the page.

Someone also suggested opening a websocket. If the browser doesn’t answer a ping, log them out.