Is there a way to detect, using the REST API or the Spawner API, when a user has closed their browser window?

When a user closes their window, I can see in the logs that the Websocket closes:

[D 2022-04-01 13:12:21.671 ServerApp] Websocket closed d371e9be-6d70-484e-9da3-8817b25b0f11:1703a192-781c-41a7-8aae-783311ddcba6
[D 2022-04-01 13:12:21.672 ServerApp] Websocket closed d371e9be-6d70-484e-9da3-8817b25b0f11:812d4f12-462f-4047-bd93-f660e91a6083
[I 2022-04-01 13:12:21.672 ServerApp] Starting buffering for d371e9be-6d70-484e-9da3-8817b25b0f11:812d4f12-462f-4047-bd93-f660e91a6083
[D 2022-04-01 13:12:21.672 ServerApp] Clearing buffer for d371e9be-6d70-484e-9da3-8817b25b0f11

Is there any way to detect this either from the REST API or the Spawner API or some other programmatic means?

Thank you.

JupyterHub is decoupled from the single-user server, so you can’t get this information through any hub APIs. The closest is probably the idle time which is associated with a user’s servers.

Alternatively you might be able to write a jupyter-server extension that can tell you if a user’s browser is open?

1 Like