cloudflare / speedtest

Component to perform network speed tests against Cloudflare's edge network
https://speed.cloudflare.com
MIT License
459 stars 34 forks source link

`packetLoss` endpoint has CORS set to `speed.cloudflare.com` #39

Closed 96imranahmed closed 2 months ago

96imranahmed commented 2 months ago

Hi there, the default config is failing because the packetLoss test queries https://speed.cloudflare.com/turn-creds

However, the CORS policy for this page is set to only accept cloudflare domains (e.g., access-control-allow-origin: speed.cloudflare.com)

A workaround is to remove packetLoss calculations from the test, but I'd love to be able to also use packetLoss stats in the reporting on my app!

PrasanthGondi commented 2 months ago

+1

Running the code below in react gives Cors error:

import SpeedTest from '@cloudflare/speedtest';

new SpeedTest().onFinish = results => console.log(results.getSummary());

Access to fetch at '[https://speed.cloudflare.com/turn-creds](vscode-file://vscode-app/Applications/Visual%20Studio%20Code.app/Contents/Resources/app/out/vs/code/electron-sandbox/workbench/workbench.html)' from origin '[http://localhost:3000](vscode-file://vscode-app/Applications/Visual%20Studio%20Code.app/Contents/Resources/app/out/vs/code/electron-sandbox/workbench/workbench.html)' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header contains the invalid value 'speed.cloudflare.com'.

animencoding commented 2 months ago

+1 having issues with the turn-creds CORS

dragonslair1027 commented 2 months ago

@96imranahmed how did you do the workaround for packetLoss??

96imranahmed commented 2 months ago

Sorry I wasn't clear - I don't have a solution for getting a packetLoss metric. I just ignore the test entirely by removing it from the list of default measurements that are run when you make a test.

    { type: 'latency', numPackets: 1 }, // initial ttfb estimation
    { type: 'download', bytes: 1e5, count: 1, bypassMinDuration: true }, // initial download estimation
    { type: 'latency', numPackets: 20 },
    { type: 'download', bytes: 1e5, count: 9 },
    { type: 'download', bytes: 1e6, count: 8 },
    { type: 'upload', bytes: 1e5, count: 8 },
    { // Remove this line
      type: 'packetLoss',
      numPackets: 1e3,
      batchSize: 10,
      batchWaitTime: 10, // ms (in between batches)
      responsesWaitTime: 3000 // ms (silent time after last sent msg)
    },
    { type: 'upload', bytes: 1e6, count: 6 },
    { type: 'download', bytes: 1e7, count: 6 },
    { 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: 3 },
    { type: 'upload', bytes: 5e7, count: 3 },
    { type: 'download', bytes: 2.5e8, count: 2 }
joao-reis commented 2 months ago

We will apply a fix in the next days.

dragonslair1027 commented 2 months ago

@joao-reis Please let me know when fix is released :D

joao-reis commented 2 months ago

Fixed 👍

96imranahmed commented 2 months ago

Works perfectly - thanks for the quick turnaround! Let me close this!