speedtest_worker.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. /*
  2. HTML5 Speedtest v4.3.2
  3. by Federico Dossena
  4. https://github.com/adolfintel/speedtest/
  5. GNU LGPLv3 License
  6. */
  7. // data reported to main thread
  8. var testStatus = 0 // 0=not started, 1=download test, 2=ping+jitter test, 3=upload test, 4=finished, 5=abort/error
  9. var dlStatus = '' // download speed in megabit/s with 2 decimal digits
  10. var ulStatus = '' // upload speed in megabit/s with 2 decimal digits
  11. var pingStatus = '' // ping in milliseconds with 2 decimal digits
  12. var jitterStatus = '' // jitter in milliseconds with 2 decimal digits
  13. var clientIp = '' // client's IP address as reported by getIP.php
  14. var log='' //telemetry log
  15. function tlog(s){log+=Date.now()+': '+s+'\n'}
  16. function twarn(s){log+=Date.now()+' WARN: '+s+'\n'; console.warn(s)}
  17. // test settings. can be overridden by sending specific values with the start command
  18. var settings = {
  19. time_ul: 10, // duration of upload test in seconds
  20. time_dl: 10, // duration of download test in seconds
  21. time_ulGraceTime: 3, //time to wait in seconds before actually measuring ul speed (wait for buffers to fill)
  22. time_dlGraceTime: 1.5, //time to wait in seconds before actually measuring dl speed (wait for TCP window to increase)
  23. count_ping: 35, // number of pings to perform in ping test
  24. url_dl: 'garbage.php', // path to a large file or garbage.php, used for download test. must be relative to this js file
  25. url_ul: 'empty.php', // path to an empty file, used for upload test. must be relative to this js file
  26. url_ping: 'empty.php', // path to an empty file, used for ping test. must be relative to this js file
  27. url_getIp: 'getIP.php', // path to getIP.php relative to this js file, or a similar thing that outputs the client's ip
  28. xhr_dlMultistream: 10, // number of download streams to use (can be different if enable_quirks is active)
  29. xhr_ulMultistream: 3, // number of upload streams to use (can be different if enable_quirks is active)
  30. xhr_ignoreErrors: 1, // 0=fail on errors, 1=attempt to restart a stream if it fails, 2=ignore all errors
  31. xhr_dlUseBlob: false, // if set to true, it reduces ram usage but uses the hard drive (useful with large garbagePhp_chunkSize and/or high xhr_dlMultistream)
  32. garbagePhp_chunkSize: 20, // size of chunks sent by garbage.php (can be different if enable_quirks is active)
  33. enable_quirks: true, // enable quirks for specific browsers. currently it overrides settings to optimize for specific browsers, unless they are already being overridden with the start command
  34. overheadCompensationFactor: 1048576/925000, //compensation for HTTP+TCP+IP+ETH overhead. 925000 is how much data is actually carried over 1048576 (1mb) bytes downloaded/uploaded. This default value assumes HTTP+TCP+IPv4+ETH with typical MTUs over the Internet. You may want to change this if you're going through your local network with a different MTU or if you're going over IPv6 (see doc.md for some other values)
  35. telemetry_level: 2, // 0=disabled, 1=basic (results only), 2=full (results+log)
  36. url_telemetry: 'telemetry.php' // path to the script that adds telemetry data to the database
  37. }
  38. var xhr = null // array of currently active xhr requests
  39. var interval = null // timer used in tests
  40. /*
  41. this function is used on URLs passed in the settings to determine whether we need a ? or an & as a separator
  42. */
  43. function url_sep (url) { return url.match(/\?/) ? '&' : '?'; }
  44. /*
  45. listener for commands from main thread to this worker.
  46. commands:
  47. -status: returns the current status as a string of values spearated by a semicolon (;) in this order: testStatus;dlStatus;ulStatus;pingStatus;clientIp;jitterStatus
  48. -abort: aborts the current test
  49. -start: starts the test. optionally, settings can be passed as JSON.
  50. example: start {"time_ul":"10", "time_dl":"10", "count_ping":"50"}
  51. */
  52. this.addEventListener('message', function (e) {
  53. var params = e.data.split(' ')
  54. if (params[0] === 'status') { // return status
  55. postMessage(testStatus + ';' + dlStatus + ';' + ulStatus + ';' + pingStatus + ';' + clientIp + ';' + jitterStatus)
  56. }
  57. if (params[0] === 'start' && testStatus === 0) { // start new test
  58. testStatus = 1
  59. try {
  60. // parse settings, if present
  61. var s = {}
  62. try{
  63. var ss = e.data.substring(5)
  64. if (ss) s = JSON.parse(ss)
  65. }catch(e){ twarn('Error parsing custom settings JSON. Please check your syntax') }
  66. if (typeof s.url_dl !== 'undefined') settings.url_dl = s.url_dl // download url
  67. if (typeof s.url_ul !== 'undefined') settings.url_ul = s.url_ul // upload url
  68. if (typeof s.url_ping !== 'undefined') settings.url_ping = s.url_ping // ping url
  69. if (typeof s.url_getIp !== 'undefined') settings.url_getIp = s.url_getIp // url to getIP.php
  70. if (typeof s.time_dl !== 'undefined') settings.time_dl = s.time_dl // duration of download test
  71. if (typeof s.time_ul !== 'undefined') settings.time_ul = s.time_ul // duration of upload test
  72. if (typeof s.enable_quirks !== 'undefined') settings.enable_quirks = s.enable_quirks // enable quirks or not
  73. // quirks for specific browsers. more may be added in future releases
  74. if (settings.enable_quirks) {
  75. var ua = navigator.userAgent
  76. if (/Firefox.(\d+\.\d+)/i.test(ua)) {
  77. // ff more precise with 1 upload stream
  78. settings.xhr_ulMultistream = 1
  79. }
  80. if (/Edge.(\d+\.\d+)/i.test(ua)) {
  81. // edge more precise with 3 download streams
  82. settings.xhr_dlMultistream = 3
  83. if (/Edge\/15.(\d+)/i.test(ua)) {
  84. //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
  85. settings.forceIE11Workaround = true
  86. }
  87. }
  88. if (/Chrome.(\d+)/i.test(ua) && (!!self.fetch)) {
  89. // chrome more precise with 5 streams
  90. settings.xhr_dlMultistream = 5
  91. }
  92. }
  93. if (typeof s.count_ping !== 'undefined') settings.count_ping = s.count_ping // number of pings for ping test
  94. if (typeof s.xhr_dlMultistream !== 'undefined') settings.xhr_dlMultistream = s.xhr_dlMultistream // number of download streams
  95. if (typeof s.xhr_ulMultistream !== 'undefined') settings.xhr_ulMultistream = s.xhr_ulMultistream // number of upload streams
  96. if (typeof s.xhr_ignoreErrors !== 'undefined') settings.xhr_ignoreErrors = s.xhr_ignoreErrors // what to do in case of errors during the test
  97. if (typeof s.xhr_dlUseBlob !== 'undefined') settings.xhr_dlUseBlob = s.xhr_dlUseBlob // use blob for download test
  98. if (typeof s.garbagePhp_chunkSize !== 'undefined') settings.garbagePhp_chunkSize = s.garbagePhp_chunkSize // size of garbage.php chunks
  99. if (typeof s.time_dlGraceTime !== 'undefined') settings.time_dlGraceTime = s.time_dlGraceTime // dl test grace time before measuring
  100. if (typeof s.time_ulGraceTime !== 'undefined') settings.time_ulGraceTime = s.time_ulGraceTime // ul test grace time before measuring
  101. if (typeof s.overheadCompensationFactor !== 'undefined') settings.overheadCompensationFactor = s.overheadCompensationFactor //custom overhead compensation factor (default assumes HTTP+TCP+IP+ETH with typical MTUs)
  102. if (typeof s.telemetry_level !== 'undefined') settings.telemetry_level = s.telemetry_level === 'basic' ? 1 : s.telemetry_level === 'full' ? 2 : 0; // telemetry level
  103. if (typeof s.url_telemetry !== 'undefined') settings.url_telemetry = s.url_telemetry // url to telemetry.php
  104. } catch (e) { twarn('Possible error in custom test settings. Some settings may not be applied. Exception: '+e) }
  105. // run the tests
  106. tlog(JSON.stringify(settings))
  107. getIp(function () { dlTest(function () { testStatus = 2; pingTest(function () { testStatus = 3; ulTest(function () { testStatus = 4; sendTelemetry() }) }) }) })
  108. }
  109. if (params[0] === 'abort') { // abort command
  110. tlog('manually aborted')
  111. clearRequests() // stop all xhr activity
  112. if (interval) clearInterval(interval) // clear timer if present
  113. if (settings.telemetry_level > 1) sendTelemetry()
  114. testStatus = 5; dlStatus = ''; ulStatus = ''; pingStatus = ''; jitterStatus = '' // set test as aborted
  115. }
  116. })
  117. // stops all XHR activity, aggressively
  118. function clearRequests () {
  119. tlog('stopping pending XHRs')
  120. if (xhr) {
  121. for (var i = 0; i < xhr.length; i++) {
  122. try { xhr[i].onprogress = null; xhr[i].onload = null; xhr[i].onerror = null } catch (e) { }
  123. try { xhr[i].upload.onprogress = null; xhr[i].upload.onload = null; xhr[i].upload.onerror = null } catch (e) { }
  124. try { xhr[i].abort() } catch (e) { }
  125. try { delete (xhr[i]) } catch (e) { }
  126. }
  127. xhr = null
  128. }
  129. }
  130. // gets client's IP using url_getIp, then calls the done function
  131. function getIp (done) {
  132. tlog('getIp')
  133. if (settings.url_getIp == "-1") {done(); return}
  134. xhr = new XMLHttpRequest()
  135. xhr.onload = function () {
  136. tlog("IP: "+xhr.responseText)
  137. clientIp = xhr.responseText
  138. done()
  139. }
  140. xhr.onerror = function () {
  141. tlog('getIp failed')
  142. done()
  143. }
  144. xhr.open('GET', settings.url_getIp + url_sep(settings.url_getIp) + 'r=' + Math.random(), true)
  145. xhr.send()
  146. }
  147. // download test, calls done function when it's over
  148. var dlCalled = false // used to prevent multiple accidental calls to dlTest
  149. function dlTest (done) {
  150. tlog('dlTest')
  151. if (dlCalled) return; else dlCalled = true // dlTest already called?
  152. if (settings.url_dl === '-1') {done(); return}
  153. var totLoaded = 0.0, // total number of loaded bytes
  154. startT = new Date().getTime(), // timestamp when test was started
  155. graceTimeDone = false, //set to true after the grace time is past
  156. failed = false // set to true if a stream fails
  157. xhr = []
  158. // function to create a download stream. streams are slightly delayed so that they will not end at the same time
  159. var testStream = function (i, delay) {
  160. setTimeout(function () {
  161. if (testStatus !== 1) return // delayed stream ended up starting after the end of the download test
  162. tlog('dl test stream started '+i+' '+delay)
  163. var prevLoaded = 0 // number of bytes loaded last time onprogress was called
  164. var x = new XMLHttpRequest()
  165. xhr[i] = x
  166. xhr[i].onprogress = function (event) {
  167. tlog('dl stream progress event '+i+' '+event.loaded)
  168. if (testStatus !== 1) { try { x.abort() } catch (e) { } } // just in case this XHR is still running after the download test
  169. // progress event, add number of new loaded bytes to totLoaded
  170. var loadDiff = event.loaded <= 0 ? 0 : (event.loaded - prevLoaded)
  171. if (isNaN(loadDiff) || !isFinite(loadDiff) || loadDiff < 0) return // just in case
  172. totLoaded += loadDiff
  173. prevLoaded = event.loaded
  174. }.bind(this)
  175. xhr[i].onload = function () {
  176. // the large file has been loaded entirely, start again
  177. tlog('dl stream finished '+i)
  178. try { xhr[i].abort() } catch (e) { } // reset the stream data to empty ram
  179. testStream(i, 0)
  180. }.bind(this)
  181. xhr[i].onerror = function () {
  182. // error
  183. tlog('dl stream failed '+i)
  184. if (settings.xhr_ignoreErrors === 0) failed=true //abort
  185. try { xhr[i].abort() } catch (e) { }
  186. delete (xhr[i])
  187. if (settings.xhr_ignoreErrors === 1) testStream(i, 100) //restart stream after 100ms
  188. }.bind(this)
  189. // send xhr
  190. try { if (settings.xhr_dlUseBlob) xhr[i].responseType = 'blob'; else xhr[i].responseType = 'arraybuffer' } catch (e) { }
  191. xhr[i].open('GET', settings.url_dl + url_sep(settings.url_dl) + 'r=' + Math.random() + '&ckSize=' + settings.garbagePhp_chunkSize, true) // random string to prevent caching
  192. xhr[i].send()
  193. }.bind(this), 1 + delay)
  194. }.bind(this)
  195. // open streams
  196. for (var i = 0; i < settings.xhr_dlMultistream; i++) {
  197. testStream(i, 100 * i)
  198. }
  199. // every 200ms, update dlStatus
  200. interval = setInterval(function () {
  201. tlog('DL: '+dlStatus+(graceTimeDone?'':' (in grace time)'))
  202. var t = new Date().getTime() - startT
  203. if (t < 200) return
  204. if (!graceTimeDone){
  205. if (t > 1000 * settings.time_dlGraceTime){
  206. if (totLoaded > 0){ // if the connection is so slow that we didn't get a single chunk yet, do not reset
  207. startT = new Date().getTime()
  208. totLoaded = 0.0;
  209. }
  210. graceTimeDone = true;
  211. }
  212. }else{
  213. var speed = totLoaded / (t / 1000.0)
  214. dlStatus = ((speed * 8 * settings.overheadCompensationFactor)/1048576).toFixed(2) // speed is multiplied by 8 to go from bytes to bits, overhead compensation is applied, then everything is divided by 1048576 to go to megabits/s
  215. if (((t / 1000.0) > settings.time_dl && dlStatus > 0) || failed) { // test is over, stop streams and timer
  216. if (failed || isNaN(dlStatus)) dlStatus = 'Fail'
  217. clearRequests()
  218. clearInterval(interval)
  219. tlog('dlTest finished '+dlStatus)
  220. done()
  221. }
  222. }
  223. }.bind(this), 200)
  224. }
  225. // upload test, calls done function whent it's over
  226. // garbage data for upload test
  227. var r = new ArrayBuffer(1048576)
  228. try { r = new Float32Array(r); for (var i = 0; i < r.length; i++)r[i] = Math.random() } catch (e) { }
  229. var req = []
  230. var reqsmall = []
  231. for (var i = 0; i < 20; i++) req.push(r)
  232. req = new Blob(req)
  233. r = new ArrayBuffer(262144)
  234. try { r = new Float32Array(r); for (var i = 0; i < r.length; i++)r[i] = Math.random() } catch (e) { }
  235. reqsmall.push(r)
  236. reqsmall = new Blob(reqsmall)
  237. var ulCalled = false // used to prevent multiple accidental calls to ulTest
  238. function ulTest (done) {
  239. tlog('ulTest')
  240. if (ulCalled) return; else ulCalled = true // ulTest already called?
  241. if (settings.url_ul === '-1') {done(); return}
  242. var totLoaded = 0.0, // total number of transmitted bytes
  243. startT = new Date().getTime(), // timestamp when test was started
  244. graceTimeDone = false, //set to true after the grace time is past
  245. failed = false // set to true if a stream fails
  246. xhr = []
  247. // function to create an upload stream. streams are slightly delayed so that they will not end at the same time
  248. var testStream = function (i, delay) {
  249. setTimeout(function () {
  250. if (testStatus !== 3) return // delayed stream ended up starting after the end of the upload test
  251. tlog('ul test stream started '+i+' '+delay)
  252. var prevLoaded = 0 // number of bytes transmitted last time onprogress was called
  253. var x = new XMLHttpRequest()
  254. xhr[i] = x
  255. var ie11workaround
  256. if (settings.forceIE11Workaround) ie11workaround = true; else {
  257. try {
  258. xhr[i].upload.onprogress
  259. ie11workaround = false
  260. } catch (e) {
  261. ie11workaround = true
  262. }
  263. }
  264. if (ie11workaround) {
  265. // IE11 workarond: xhr.upload does not work properly, therefore we send a bunch of small 256k requests and use the onload event as progress. This is not precise, especially on fast connections
  266. xhr[i].onload = function () {
  267. tlog('ul stream progress event (ie11wa)')
  268. totLoaded += 262144
  269. testStream(i, 0)
  270. }
  271. xhr[i].onerror = function () {
  272. // error, abort
  273. tlog('ul stream failed (ie11wa)')
  274. if (settings.xhr_ignoreErrors === 0) failed = true //abort
  275. try { xhr[i].abort() } catch (e) { }
  276. delete (xhr[i])
  277. if (settings.xhr_ignoreErrors === 1) testStream(i,100); //restart stream after 100ms
  278. }
  279. xhr[i].open('POST', settings.url_ul + url_sep(settings.url_ul) + 'r=' + Math.random(), true) // random string to prevent caching
  280. xhr[i].setRequestHeader('Content-Encoding', 'identity') // disable compression (some browsers may refuse it, but data is incompressible anyway)
  281. xhr[i].send(reqsmall)
  282. } else {
  283. // REGULAR version, no workaround
  284. xhr[i].upload.onprogress = function (event) {
  285. tlog('ul stream progress event '+i+' '+event.loaded)
  286. if (testStatus !== 3) { try { x.abort() } catch (e) { } } // just in case this XHR is still running after the upload test
  287. // progress event, add number of new loaded bytes to totLoaded
  288. var loadDiff = event.loaded <= 0 ? 0 : (event.loaded - prevLoaded)
  289. if (isNaN(loadDiff) || !isFinite(loadDiff) || loadDiff < 0) return // just in case
  290. totLoaded += loadDiff
  291. prevLoaded = event.loaded
  292. }.bind(this)
  293. xhr[i].upload.onload = function () {
  294. // this stream sent all the garbage data, start again
  295. tlog('ul stream finished '+i)
  296. testStream(i, 0)
  297. }.bind(this)
  298. xhr[i].upload.onerror = function () {
  299. tlog('ul stream failed '+i)
  300. if (settings.xhr_ignoreErrors === 0) failed=true //abort
  301. try { xhr[i].abort() } catch (e) { }
  302. delete (xhr[i])
  303. if (settings.xhr_ignoreErrors === 1) testStream(i, 100) //restart stream after 100ms
  304. }.bind(this)
  305. // send xhr
  306. xhr[i].open('POST', settings.url_ul + url_sep(settings.url_ul) + 'r=' + Math.random(), true) // random string to prevent caching
  307. xhr[i].setRequestHeader('Content-Encoding', 'identity') // disable compression (some browsers may refuse it, but data is incompressible anyway)
  308. xhr[i].send(req)
  309. }
  310. }.bind(this), 1)
  311. }.bind(this)
  312. // open streams
  313. for (var i = 0; i < settings.xhr_ulMultistream; i++) {
  314. testStream(i, 100 * i)
  315. }
  316. // every 200ms, update ulStatus
  317. interval = setInterval(function () {
  318. tlog('UL: '+ulStatus+(graceTimeDone?'':' (in grace time)'))
  319. var t = new Date().getTime() - startT
  320. if (t < 200) return
  321. if (!graceTimeDone){
  322. if (t > 1000 * settings.time_ulGraceTime){
  323. if (totLoaded > 0){ // if the connection is so slow that we didn't get a single chunk yet, do not reset
  324. startT = new Date().getTime()
  325. totLoaded = 0.0;
  326. }
  327. graceTimeDone = true;
  328. }
  329. }else{
  330. var speed = totLoaded / (t / 1000.0)
  331. ulStatus = ((speed * 8 * settings.overheadCompensationFactor)/1048576).toFixed(2) // speed is multiplied by 8 to go from bytes to bits, overhead compensation is applied, then everything is divided by 1048576 to go to megabits/s
  332. if (((t / 1000.0) > settings.time_ul && ulStatus > 0) || failed) { // test is over, stop streams and timer
  333. if (failed || isNaN(ulStatus)) ulStatus = 'Fail'
  334. clearRequests()
  335. clearInterval(interval)
  336. tlog('ulTest finished '+ulStatus)
  337. done()
  338. }
  339. }
  340. }.bind(this), 200)
  341. }
  342. // ping+jitter test, function done is called when it's over
  343. var ptCalled = false // used to prevent multiple accidental calls to pingTest
  344. function pingTest (done) {
  345. tlog('pingTest')
  346. if (ptCalled) return; else ptCalled = true // pingTest already called?
  347. if (settings.url_ping === '-1') {done(); return}
  348. var prevT = null // last time a pong was received
  349. var ping = 0.0 // current ping value
  350. var jitter = 0.0 // current jitter value
  351. var i = 0 // counter of pongs received
  352. var prevInstspd = 0 // last ping time, used for jitter calculation
  353. xhr = []
  354. // ping function
  355. var doPing = function () {
  356. tlog('ping')
  357. prevT = new Date().getTime()
  358. xhr[0] = new XMLHttpRequest()
  359. xhr[0].onload = function () {
  360. // pong
  361. tlog('pong')
  362. if (i === 0) {
  363. prevT = new Date().getTime() // first pong
  364. } else {
  365. var instspd = (new Date().getTime() - prevT)
  366. var instjitter = Math.abs(instspd - prevInstspd)
  367. if (i === 1) ping = instspd; /* first ping, can't tell jitter yet*/ else {
  368. ping = ping * 0.9 + instspd * 0.1 // ping, weighted average
  369. jitter = instjitter > jitter ? (jitter * 0.2 + instjitter * 0.8) : (jitter * 0.9 + instjitter * 0.1) // update jitter, weighted average. spikes in ping values are given more weight.
  370. }
  371. prevInstspd = instspd
  372. }
  373. pingStatus = ping.toFixed(2)
  374. jitterStatus = jitter.toFixed(2)
  375. i++
  376. tlog('PING: '+pingStatus+' JITTER: '+jitterStatus)
  377. if (i < settings.count_ping) doPing(); else done() // more pings to do?
  378. }.bind(this)
  379. xhr[0].onerror = function () {
  380. // a ping failed, cancel test
  381. tlog('ping failed')
  382. if (settings.xhr_ignoreErrors === 0) { //abort
  383. pingStatus = 'Fail'
  384. jitterStatus = 'Fail'
  385. clearRequests()
  386. done()
  387. }
  388. if (settings.xhr_ignoreErrors === 1) doPing() //retry ping
  389. if (settings.xhr_ignoreErrors === 2){ //ignore failed ping
  390. i++
  391. if (i < settings.count_ping) doPing(); else done() // more pings to do?
  392. }
  393. }.bind(this)
  394. // sent xhr
  395. xhr[0].open('GET', settings.url_ping + url_sep(settings.url_ping) + 'r=' + Math.random(), true) // random string to prevent caching
  396. xhr[0].send()
  397. }.bind(this)
  398. doPing() // start first ping
  399. }
  400. // telemetry
  401. function sendTelemetry(){
  402. if (settings.telemetry_level < 1) return
  403. xhr = new XMLHttpRequest()
  404. xhr.onload = function () { console.log('TELEMETRY OL '+xhr.responseText) }
  405. xhr.onerror = function () { console.log('TELEMETRY ERROR '+xhr) }
  406. xhr.open('POST', settings.url_telemetry+"?r="+Math.random(), true);
  407. try{
  408. var fd = new FormData()
  409. fd.append('dl', dlStatus)
  410. fd.append('ul', ulStatus)
  411. fd.append('ping', pingStatus)
  412. fd.append('jitter', jitterStatus)
  413. fd.append('log', settings.telemetry_level>1?log:"")
  414. xhr.send(fd)
  415. }catch(ex){
  416. var postData = 'dl='+encodeURIComponent(dlStatus)+'&ul='+encodeURIComponent(ulStatus)+'&ping='+encodeURIComponent(pingStatus)+'&jitter='+encodeURIComponent(jitterStatus)+'&log='+encodeURIComponent(settings.telemetry_level>1?log:'')
  417. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
  418. xhr.send(postData)
  419. }
  420. }