I'm trying to detect the internet connection status with this piece of code
console.log('here');
window.addEventListener('offline', function (event) {
console.log('You lost connection.');
});
window.addEventListener('online', function (event) {
console.log('You are back online.');
});
I cut off the internet and nothing happens. No log in the console, only the initial here I'm adding this in a basic block in a blank html page, nothing fancy. It seems the events online and offline do not exist on the window object.
UPDATE: this is very weird because I developed this feature on exactly the same environment: the same laptop, OS: windows, browsers chrome and firefox and it was working. Now it does not work. Also I tested using another pc and it works.