I am trying to check whether there is an internet connection from within a chrome plugin. While there is API call available that suggests to do check that, it only checks if there is internet connection possible, theoretically. To get this information, I try to load an Image
checkConnection() {
var newImg = new Image;
newImg.src = url;
newImg.onload = function() { ... }
newImg.onerror = function() { ... }
}
I do use the Image object to avoid all these problems with Same-Origin-Policies that occur when using get request with JavaScript (I am using the code from within a plugin, so there is no address that has the same origin as my code :/ ). In principle, my code from above works. I have a setTimeout that calls checkConnection every other time. However, when the image was loaded successfully once (per plugin reload) it is stored in the cache and is loaded from there when the connection fails.
Do you have an idea how to bypass this problem? Or do you know of a smart way to check the internet connection from within a Chrome plugin without setting up a server that might tolerate the origin of my request?