sbtpr
sbtpr

Reputation: 561

Why does a legitimate cors request that works on Chrome fail on FireFox?

I'm trying to process a csv file obtained from a server that is different from the one serving the script:

fetch("https://raw.githubusercontent.com/webflo/countries/master/countries.csv").then(response=>{
    console.log(response.body)
})

This works on Chrome, response.body is a ReadableStream from which I can read the content.

However on FireFox the response does not have a body, so it is undefined.

What is the reason for this and how can I modify the script so that it works on FireFox as well?

Upvotes: 1

Views: 80

Answers (1)

charlietfl
charlietfl

Reputation: 171700

Using native fetch and response.text() the following works fine for me in Firefox

fetch("https://raw.githubusercontent.com/webflo/countries/master/countries.csv")
  .then(response => response.text())
  .then(data => {
    console.log('Data length =', data.length)
    let arr = data.split('\n').map(line => line.replace(/\"/g, '').split(','));
    console.log(arr);
  })

Upvotes: 1

Related Questions