4

While playing with XHR requests I found interesting thing in making XHR requests from 2 major browsers - Google's Chrome and Mozilla's Firefox. Request was simple HEAD request to www.google.ba:

var xhr = new XMLHttpRequest();
xhr.open('HEAD' , 'www.google.ba', true);

xhr.onreadystatechange = function (aEvt){
  if (xhr.readyState == 4) {
    if (xhr.status >= 200 && xhr.status < 304) {
      console.log('Connected');
    } else {
      console.log('No net');
    }
  }
};

xhr.send();

After trying to make XHR request while there was no connection I would get readyState 4 and status 0 on both browsers. After i reconnected - making XHR request from both browsers were successful.

But here is the thing, after I disconnected again and made request, Chrome returned readyState 4 and status 0 after 9 milliseconds, but Firefox stayed in some kind of pending state and waited to net to return. When I reconnected after 13 seconds, request was successfully processed. I didn't get status 0 on Firefox even after 13 seconds. Is there anyone who could explained these huge differences and how to possibly prevent this behavior on Firefox?

Screenshot from Chrome:

enter image description here

Screenshot from Firefox:

enter image description here

EDIT:

It seems like that Firefox can't detect offline mode, only when I select work offline in browser i get the same result as in Chrome. Is there any way to get same result as in Chrome?

Community
  • 1
  • 1
Ivan Pandžić
  • 598
  • 5
  • 20
  • 1
    @xmashallax - Is there anyone who could explained these huge differences and how to possibly prevent this behavior on Firefox? – Ivan Pandžić Jul 21 '15 at 13:18
  • Does it really matter if the result is the same? How does this behavior negatively effect any scripts you have wrote? – glend Jul 21 '15 at 15:19
  • 1
    @doveyg actually it does, if there is no connection user could impatiently run same action multiple times unaware of lost connection and after reconnect all that actions would be processed. Just a possible scenario. – Ivan Pandžić Jul 21 '15 at 17:55

0 Answers0