This API is too unstable and usually you don't want to use it in production, because online in terms of user's browser may not be the same as online in terms of the user themselves.
There are better ways to detect offline:
Long-pooling request to the server.
Periodical check for a dummy image/resource without caching.
Showing such a status only when the user's request fails due to unstable network.
Relying on navigator.onLine only you may scare your user. So, please do not.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This API is too unstable and usually you don't want to use it in production, because
online
in terms of user's browser may not be the same asonline
in terms of the user themselves.There are better ways to detect offline:
Relying on
navigator.onLine
only you may scare your user. So, please do not.