Skip to content

Commit

Permalink
Rewritten settings parser; Added new quirk for Firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
adolfintel committed Oct 14, 2017
1 parent 60c707d commit 5ea9a56
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
1 change: 1 addition & 0 deletions doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ w.postMessage('start {"param1": "value1", "param2": "value2", ...}')
* `P`: ping + jitter test
* `_`: delay 1 second
* Default test order: `ID_U_P`
* Default override: `ID_P_U` on Firefox if enable_quirks is true because Firefox does not stop upload XHRs right away, it takes 2-3 seconds.
* __Important:__ Tests can only be run once
* __enable_quirks__: enables browser-specific optimizations. These optimizations override some of the default settings. They do not override settings that are explicitly set.
* Default: `true`
Expand Down
53 changes: 26 additions & 27 deletions speedtest_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,45 +72,44 @@ this.addEventListener('message', function (e) {
var ss = e.data.substring(5)
if (ss) s = JSON.parse(ss)
}catch(e){ twarn('Error parsing custom settings JSON. Please check your syntax') }
if (typeof s.test_order !== 'undefined') settings.test_order = s.test_order.toUpperCase() // test order
if (typeof s.url_dl !== 'undefined') settings.url_dl = s.url_dl // download url
if (typeof s.url_ul !== 'undefined') settings.url_ul = s.url_ul // upload url
if (typeof s.url_ping !== 'undefined') settings.url_ping = s.url_ping // ping url
if (typeof s.url_getIp !== 'undefined') settings.url_getIp = s.url_getIp // url to getIP.php
if (typeof s.time_dl !== 'undefined') settings.time_dl = s.time_dl // duration of download test
if (typeof s.time_ul !== 'undefined') settings.time_ul = s.time_ul // duration of upload test
if (typeof s.enable_quirks !== 'undefined') settings.enable_quirks = s.enable_quirks // enable quirks or not
// quirks for specific browsers. more may be added in future releases
if (settings.enable_quirks) {
//copy custom settings
for(var key in s){
if(typeof settings[key] !== 'undefined') settings[key]=s[key]; else twarn("Unknown setting ignored: "+key);
}
// quirks for specific browsers. apply only if not overridden. more may be added in future releases
if (settings.enable_quirks||(typeof s.enable_quirks !== 'undefined' && s.enable_quirks)) {
var ua = navigator.userAgent
if (/Firefox.(\d+\.\d+)/i.test(ua)) {
// ff more precise with 1 upload stream
settings.xhr_ulMultistream = 1
if(typeof s.xhr_ulMultistream === 'undefined'){
// ff more precise with 1 upload stream
settings.xhr_ulMultistream = 1
}
if(typeof s.test_order === 'undefined'){
// ff more precise if upload test is performed after ping because upload XHRs are not interrupted immediately
settings.test_order= 'ID_P_U'
}
}
if (/Edge.(\d+\.\d+)/i.test(ua)) {
// edge more precise with 3 download streams
settings.xhr_dlMultistream = 3
if(typeof s.xhr_dlMultistream === 'undefined'){
// edge more precise with 3 download streams
settings.xhr_dlMultistream = 3
}
if (/Edge\/15.(\d+)/i.test(ua) || /Edge\/16.(\d+)/i.test(ua)) {
//Edge 15 introduced a bug that causes onprogress events to not get fired, so for Edge 15, we have to use the "small chunks" workaround that reduces accuracy
settings.forceIE11Workaround = true
}
}
if (/Chrome.(\d+)/i.test(ua) && (!!self.fetch)) {
// chrome more precise with 5 streams
settings.xhr_dlMultistream = 5
if(typeof s.xhr_dlMultistream === 'undefined'){
// chrome more precise with 5 streams
settings.xhr_dlMultistream = 5
}
}
}
if (typeof s.count_ping !== 'undefined') settings.count_ping = s.count_ping // number of pings for ping test
if (typeof s.xhr_dlMultistream !== 'undefined') settings.xhr_dlMultistream = s.xhr_dlMultistream // number of download streams
if (typeof s.xhr_ulMultistream !== 'undefined') settings.xhr_ulMultistream = s.xhr_ulMultistream // number of upload streams
if (typeof s.xhr_ignoreErrors !== 'undefined') settings.xhr_ignoreErrors = s.xhr_ignoreErrors // what to do in case of errors during the test
if (typeof s.xhr_dlUseBlob !== 'undefined') settings.xhr_dlUseBlob = s.xhr_dlUseBlob // use blob for download test
if (typeof s.garbagePhp_chunkSize !== 'undefined') settings.garbagePhp_chunkSize = s.garbagePhp_chunkSize // size of garbage.php chunks
if (typeof s.time_dlGraceTime !== 'undefined') settings.time_dlGraceTime = s.time_dlGraceTime // dl test grace time before measuring
if (typeof s.time_ulGraceTime !== 'undefined') settings.time_ulGraceTime = s.time_ulGraceTime // ul test grace time before measuring
if (typeof s.overheadCompensationFactor !== 'undefined') settings.overheadCompensationFactor = s.overheadCompensationFactor //custom overhead compensation factor (default assumes HTTP+TCP+IP+ETH with typical MTUs)
if (typeof s.telemetry_level !== 'undefined') settings.telemetry_level = s.telemetry_level === 'basic' ? 1 : s.telemetry_level === 'full' ? 2 : 0; // telemetry level
if (typeof s.url_telemetry !== 'undefined') settings.url_telemetry = s.url_telemetry // url to telemetry.php
//telemetry_level has to be parsed and not just copied
if(typeof s.telemetry_level !== 'undefined') settings.telemetry_level = s.telemetry_level === 'basic' ? 1 : s.telemetry_level === 'full' ? 2 : 0; // telemetry level
//transform test_order to uppercase, just in case
settings.test_order=settings.test_order.toUpperCase();
} catch (e) { twarn('Possible error in custom test settings. Some settings may not be applied. Exception: '+e) }
// run the tests
tlog(JSON.stringify(settings))
Expand Down
Loading

0 comments on commit 5ea9a56

Please sign in to comment.