diff --git a/doc.md b/doc.md index 001b7d7..1b4f09f 100644 --- a/doc.md +++ b/doc.md @@ -256,6 +256,7 @@ w.postMessage('start '+JSON.stringify(params)) * Recommended: `>=1` * __ping_allowPerformanceApi__: toggles use of Performance API to improve accuracy of Ping/Jitter test on browsers that support it. * Default: `true` + * Default override: `false` on Firefox because its performance API implementation is inaccurate * __useMebibits__: use mebibits/s instead of megabits/s for the speeds * Default: `false` * __overheadCompensationFactor__: compensation for HTTP and network overhead. Default value assumes typical MTUs used over the Internet. You might want to change this if you're using this in your internal network with different MTUs, or if you're using IPv6 instead of IPv4. diff --git a/speedtest_worker.js b/speedtest_worker.js index b440e6c..249a7e0 100644 --- a/speedtest_worker.js +++ b/speedtest_worker.js @@ -129,6 +129,10 @@ this.addEventListener("message", function(e) { // ff more precise with 1 upload stream settings.xhr_ulMultistream = 1; } + if (typeof s.xhr_ulMultistream === "undefined") { + // ff performance API sucks + settings.ping_allowPerformanceApi = false; + } } if (/Edge.(\d+\.\d+)/i.test(ua)) { if (typeof s.xhr_dlMultistream === "undefined") { @@ -595,15 +599,17 @@ function pingTest(done) { //try to get accurate performance timing using performance api var p = performance.getEntries(); p = p[p.length - 1]; - var d = p.responseStart - p.requestStart; //best precision: chromium-based - if (d <= 0) d = p.duration; //edge: not so good precision because it also considers the overhead and there is no way to avoid it + var d = p.responseStart - p.requestStart; + if (d <= 0) d = p.duration; if (d > 0 && d < instspd) instspd = d; } catch (e) { //if not possible, keep the estimate - //firefox can't access performance api from worker: worst precision tverb("Performance API not supported, using estimate"); } } + //noticed that some browsers randomly have 0ms ping + if(instspd<1) instspd=prevInstspd; + if(instspd<1) instspd=1; var instjitter = Math.abs(instspd - prevInstspd); if (i === 1) ping = instspd; /* first ping, can't tell jitter yet*/ else { diff --git a/speedtest_worker.min.js b/speedtest_worker.min.js index 7f26384..2143af2 100644 --- a/speedtest_worker.min.js +++ b/speedtest_worker.min.js @@ -1 +1 @@ -var testStatus=-1,dlStatus="",ulStatus="",pingStatus="",jitterStatus="",clientIp="",dlProgress=0,ulProgress=0,pingProgress=0,testId=null,log="";function tlog(s){2<=settings.telemetry_level&&(log+=Date.now()+": "+s+"\n")}function tverb(s){3<=settings.telemetry_level&&(log+=Date.now()+": "+s+"\n")}function twarn(s){2<=settings.telemetry_level&&(log+=Date.now()+" WARN: "+s+"\n"),console.warn(s)}var settings={test_order:"IP_D_U",time_ul_max:15,time_dl_max:15,time_auto:!0,time_ulGraceTime:3,time_dlGraceTime:1.5,count_ping:10,url_dl:"garbage.php",url_ul:"empty.php",url_ping:"empty.php",url_getIp:"getIP.php",getIp_ispInfo:!0,getIp_ispInfo_distance:"km",xhr_dlMultistream:6,xhr_ulMultistream:3,xhr_multistreamDelay:300,xhr_ignoreErrors:1,xhr_dlUseBlob:!1,xhr_ul_blob_megabytes:20,garbagePhp_chunkSize:100,enable_quirks:!0,ping_allowPerformanceApi:!0,overheadCompensationFactor:1.06,useMebibits:!1,telemetry_level:0,url_telemetry:"telemetry/telemetry.php",telemetry_extra:""},xhr=null,interval=null,test_pointer=0;function url_sep(url){return url.match(/\?/)?"&":"?"}function clearRequests(){if(tverb("stopping pending XHRs"),xhr){for(var i=0;i=settings.test_order.length)0settings.time_dl_max||failed)&&((failed||isNaN(dlStatus))&&(dlStatus="Fail"),clearRequests(),clearInterval(interval),dlProgress=1,tlog("dlTest: "+dlStatus+", took "+((new Date).getTime()-startT)+"ms"),done())}else t>1e3*settings.time_dlGraceTime&&(0settings.time_ul_max||failed)&&((failed||isNaN(ulStatus))&&(ulStatus="Fail"),clearRequests(),clearInterval(interval),ulProgress=1,tlog("ulTest: "+ulStatus+", took "+((new Date).getTime()-startT)+"ms"),done())}else t>1e3*settings.time_ulGraceTime&&(0=settings.test_order.length)0settings.time_dl_max||failed)&&((failed||isNaN(dlStatus))&&(dlStatus="Fail"),clearRequests(),clearInterval(interval),dlProgress=1,tlog("dlTest: "+dlStatus+", took "+((new Date).getTime()-startT)+"ms"),done())}else t>1e3*settings.time_dlGraceTime&&(0settings.time_ul_max||failed)&&((failed||isNaN(ulStatus))&&(ulStatus="Fail"),clearRequests(),clearInterval(interval),ulProgress=1,tlog("ulTest: "+ulStatus+", took "+((new Date).getTime()-startT)+"ms"),done())}else t>1e3*settings.time_ulGraceTime&&(0