Try to use navigator.onLine to check for connection