How to detect if user goes offline
You need to listen for the window events online
or offline
.
function updateOnlineStatus(event) {
// DO YOUR THING
}
window.addEventListener('online', updateOnlineStatus);
window.addEventListener('offline', updateOnlineStatus);