Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting "Error 106 net::ERR_INTERNET_DISCONNECTED)"

Is there anyway to detect in a background extension when Chrome shows the page "Error 106 (net::ERR_INTERNET_DISCONNECTED): The Internet connection has been lost." ? I have tried registering a listener with both chrome.webRequest.onErrorOccurred.addListener and chrome.webNavigation.onErrorOccurred.addListener but neither listener is called when a "Error 106" occurs. My listeners are being called correctly for other errors such as "net::ERR_NAME_NOT_RESOLVED".

I'm targeting Chrome 22.0.1229.94 in a Window 7 environment. The larger goal is to provide custom messaging (in a separate tab) when Internet connectivity is lost.

like image 336
trauble Avatar asked Mar 15 '13 13:03

trauble


1 Answers

I personally ended up testing for response == "" and status == 0.

        var req = new XMLHttpRequest();
        req.open("post", VALIDATE_URL, true);
        req.onreadystatechange = function receiveResponse() {

            if (this.readyState == 4) {
                if (this.status == 200) {
                    console.log("We go a response : " + this.response);
                } else if (!isValid(this.response) && this.status == 0) {
                    console.log("The computer appears to be offline.");
                }
            }
        };
        req.send(payload);
        req = null;
like image 124
Francois Dermu Avatar answered Sep 23 '22 00:09

Francois Dermu