Speed Test randomly fails
I am using SpeedTest on a normal front-end web app. Every now and then it randomly gives me errors. Those errors do not happen all the time. I keep getting them if I try to re-run the tests during the same browser session. If I refresh the page, the errors are gone and only happen again after a while. I tried to create a new instance of SpeetTest to mitigate that behavior, but the errors keep popping up.
Those include:
Error fetching https://speed.clousflare.com/__down?bytes=0:
TypeError: Cannot read properties of undefined (reading 'transferSize')
// Or
Error in network meter Connection error while measuring download:
Connection failed to https://speed.cloudflare.com/__down?bytes=100000. Gave up after 20 retries.
I inspected the network tab, and all requests were responded with status 200, so I suppose it is not a problem with the network.
Then I tried to debug the issue, and it looks like performance.getEntriesByName(url) returns an empty array. I found a PR that attempted to fix a similar problem but for node.js: https://github.com/cloudflare/speedtest/pull/24
In that issue you mentioned it is a problem with the fetch implementation, but I am using native fetch, since I am on the browser and window.fetch returns native code, and not some polyfill.
Here are the settings I am using:
function createTestObject() {
return new SpeedTest({
autoStart: false,
bandwidthFinishRequestDuration: 800,
measureDownloadLoadedLatency: false,
measurements: [
{ type: 'latency', numPackets: 1 }, // initial latency estimation
{ type: 'download', bytes: 1e5, count: 1, bypassMinDuration: true }, // initial download estimation
{ type: 'latency', numPackets: 3 },
{ type: 'download', bytes: 1e5, count: 1 },
{ type: 'download', bytes: 1e6, count: 1 },
{ type: 'upload', bytes: 1e5, count: 1 },
{ type: 'upload', bytes: 1e6, count: 1 },
{ type: 'download', bytes: 1e7, count: 1 },
{ type: 'upload', bytes: 1e7, count: 4 },
{ type: 'download', bytes: 2.5e7, count: 4 },
{ type: 'upload', bytes: 2.5e7, count: 4 },
{ type: 'download', bytes: 1e8, count: 7 },
{ type: 'latency', numPackets: 2 },
{ type: 'upload', bytes: 5e7, count: 7 },
{ type: 'download', bytes: 2.5e8, count: 9 },
{ type: 'upload', bytes: 5e8, count: 9 }
]
})
}
This is a problem because the speed test does not work until the user refreshes the page. More info about the environment were the tests were run:
| Google Chrome | 125.0.6422.114 (Official Build) (arm64) |
|---|---|
| Revision | 457d70149965cebad452f7e37e8b5ec5b6dde5b4-refs/branch-heads/6422_76@{#5} |
| OS | macOS Version 14.4.1 (Build 23E224) |
| JavaScript | V8 12.5.227.9 |
All tests were run using chrome with the device toolbar set to iPhone 12 Pro. I would guess that it doesn't affect the Performance API, but I figured it could be a good idea to mention
I am also running into this error. I cannot make rhyme nor reason for when this bug appears. I have reduced the config to a bare minimum in order more effectively test it:
const measurements = [
{ type: 'download', bytes: 1e5, count: 1, bypassMinDuration: true }, // initial download estimation
];
I am using Firefox 127.0.2 on MacOS Sonoma 14.5 but have also run into the same error on Chrome.
As can be seen in the following screenshot, the initial speedtest works (my app logs the results to console currently), but the second one fails with the same errors as @trickstival (the message being different is just because I'm using firefox - my log messages are the same as theirs on Chrome).
Edit: hmm it looks like we're running into the same issue as #17
Not exactly sure what's going on, but I'm getting exactly the same error from time to time
TypeError: Cannot read properties of undefined (reading 'transferSize')
Linux with Chrome 109.0.5414.120
I am not able to reproduce this error to debug the issue. If you have a steps to reproduce that would be helpful. For the meanwhile i will close this ticket and please feel free to reopen it if the issue still persist. Thanks
I'm also experiencing the same exact issue, also on macOS. Most of the time it works, but sometimes this happens and then all following tests have the same issue until I refresh the page. It seems very random so sadly I have no idea how to reproduce...
We are also encountering this issue -- intermittently -- using the 1.4.1 version of the @cloudflare/speedtest node package. We've seen it occur when a browser session is left around overnight and the speed test is re-executed the next day. A hard refresh consistently yields successful execution, although we can find no evidence of any stray/uncleaned-up resources that would explain why.
Calling window.performance.clearResourceTimings() before launching the test MIGHT be the remedy.