Try to use navigator.onLine to check connection