Detecting inactive users

Hello,
in my understanding if a user leaves a tab with a panel app open, even if they are never interacting with it again, the session will not expire because the ws connection is kept active by the browser. Is that correct?
If this is the case, is there any way to detect such situations and close the session?
I could imagine that a possibility is monitoring the active status of the tab and/or the last user interaction with the page via js and close the session if no activity is registered for a certain time.
But I was wondering if there is already a solution provided by panel, before reinventing the wheel.

No I think it’ll expire due to serve — Bokeh 3.9.1 Documentation

You can block expiration though Re-connecting to a Session — Panel v1.9.3

Hi @ahuang11,
I originally thought so too but I got the impression that, for a session to become unused, the user must have closed the tab in the browser.

I made the following test file:

# app.py
import panel as pn
pn.FlexBox('test').servable()

and served it via

panel serve app.py --admin --check-unused-sessions 1000 --unused-session-lifetime 3000 

I then opened the webapp at localhost:5006/app ad checked via localhost:5006/admin when the session becomes unactive. I observed that, until the tab with the app is opened (even if not selected) the session remains active. Once I close the tab, the session becomes unactive within the chosen lifetime.

In my understadig it makes sense, since the browser keeps the websockect open even if there is no user interaction.
That means though that if a user chages tab and forget about it, the session might remain active for a long time, consuming resources.
Or maybe I got this wrong? I tested it for 10 minutes or so.

Ideally I wanted the session to expire if the user didn’t interact with the webapp for some time.