Get offline notification


Is there a way to get a callback in a Theia extension when Theia goes offline ?


[original thread by Julien Eluard]

@jeluard from a theia extension you can listen to the onStatusChange event:

[Julien Eluard]


[Julien Eluard]

It looks like onStatusChange is triggered when a tab browser is not active after a couple seconds. At least on chrome/osx. Select a different tab, select another app, wait 5 seconds and OFFLINE is sent.

Is that the expected behaviour?

@jeluard I’ve noticed the same thing when quickly testing. I believe it is because we have a timer (idle) which causes us to fire the status change event:

this.timer = this.setTimeout(() => {
  console.log(`No activity for ${this.options.offlineTimeout} ms. We are offline.`);
}, this.options.offlineTimeout);

I see the following log:

root INFO No activity for 5000 ms. We are offline.

Perhaps there is an improvement to be made in this area, thank you for reporting the behavior.

Or it means that chromes suspends activities of the background tab and does not send messages over WS anymore or setTimeout behaves differently for such tabs.

[Julien Eluard]

Right it looks like setTimeout slows down when in an inactive tab. WebSockets apparently still work as expected.


Does it make sense to change the pings logic so inactive tab doesn’t send those pings at all?

I am not sure, if there is not ping, a user can loose all debugging sessions and so on. So probably no.


@anton-kosyakov what is the expectation for debug sessions, I once opened for them being lost on brief disconnections. This means that already today they are lost when chrome tab is not active as according to the above there are disconnects.

I cannot say anything according to the above. There still can be a ping, but the status reported bogusly since timeout behaves differently.

the debug sessions is only an example, we will have to consider how it affects other services as well.


what about if we need to disconnect sessions after some time of inactivity. do you see this as a contribution or should we rebind FrontendConnectionStatusService in our extension?

I don’t know. I will need to debug it to learn more first. I don’t like that ping rely on timing of setTimeout, maybe there is a way to rework it first without relying on such timings. But I don’t think we need to stop sending ping if the tab is not active.


@anton-kosyakov We are looking for a way to identify if incoming message is a ping response or not, so we can identify user inactivity.
Do you see any issue with adding message content to onIncomingMessageActivity event? Or maybe do you have some other proposal?

AbstractConnectionStatusService.onStatusChange should fire with ONLINE when ping is responded

Why do you want to know it?


We want stop sending ping messages to backend when user is inactive after some predefined time. In order to detect user inactivity I thought about reading incoming traffic and exclude ping responses somehow.
Other direction can be to detect user inactivity by listening to mousemove and keypress events, but then I’m not sure how to listen to webviews events. Maybe do you have other idea?

All webview keys are delivered to main window:

I wonder what would happen when a user left a terminal to run some important task, but connection times out because there was not any interactions.