PixelsCommander / OnlineJS

Reliable, fast and easy to use library to check your internet connection status
http://pixelscommander.com/polygon/onlinejs/
68 stars 17 forks source link

xmlhttp.status sometimes 0 in Firefox #9

Open marcusfritze opened 10 years ago

marcusfritze commented 10 years ago

Hi,

nice tool, but I realized that the xmlhttp.status sometimes is 0 even if the server is available.

You can debug this if you add

console.log("status: " + xmlhttp.status);

between Line 124 / 125.

This seems to be a Firefox bug: https://bugzilla.mozilla.org/show_bug.cgi?id=488605

You can maybe reopen this bug.

This bug causes that the online/offline Handler will be fired very often in Firefox. It seems that Firefox is offline for some milliseconds.

A small workaround for your code would be: add a counter in processXmlhttpStatus or verifyStatus.

Something like:

if(status != 200) counter ++;

if(counter > 2) isOffline();

This should be enough because when counter == 3 then you are definitely offline. Because the Firefox bug send only one status 0 in a row.

Status 200 Status 200 Status 0 Status 200

See image!

bildschirmfoto 2013-11-22 um 15 16 51

Here is my debug code:

bildschirmfoto 2013-11-22 um 15 22 58

Greetings

Marcus

PixelsCommander commented 10 years ago

Hi Marcus

Thank you for submitting this.

Counter solution will work but as I understood will increase reaction time.

marcusfritze commented 10 years ago

Yes, you are right. So I divided my onLineCheckTimeout by 3 ;-)

As I mentioned this is only a quick workaround. Maybe you have a better idea. Or Mozilla would be so kind to fix this almost 5 year old bug.

I have tested your code in Chrome, Safari and IE and have none of these issues.

Thanks anyway!

For your info: here my changed code

var counterFF = 0;

w.onlinejs.verifyStatus = function (status) {
    //return status === 200;
    if(status !== 200)
        counterFF++;
    else
        counterFF = 0;

    return counterFF < 2;
}
marcusfritze commented 10 years ago

ok, I have reported the Firefox bug: https://bugzilla.mozilla.org/show_bug.cgi?id=942942

PixelsCommander commented 10 years ago

Thanks man, appreciate this. What FF version and OS do you use?

marcusfritze commented 10 years ago

Firefox 25.0.1 on OS X 10.9 but this also occurs on other systems (Windows 7 with Firefox 25.0.1), maybe you test my attached URL in the mozilla issue

PixelsCommander commented 10 years ago

Demo works have status 200 in 1350/1350 requests for me. Have I check with more? Testing with FF25 and OS X 10.8.3 Will try to find 10.9

marcusfritze commented 10 years ago

And the number of "status 0"? Actually this is the interesting number. ;-)

As I mentioned in the issue description, status 0 occurs sometimes when Firefox "is almost crashing" or a little bit slow. For example when you have a lot of tabs open or try the Peacekeeper Browser Benchmark.

Maybe you shouldn't test this on your fastest computer. A old slow computer is maybe better. ;-)

I my tests I have my demo page open for an hour. And have almost 6000 "status 200" and sometimes 30 - 300 "status 0".