1

I'm building a chrome extension that relies on accessing a csv file. Currently, I'm hosting the csv file remotely on Github. I'm using fetch() to get the url, then using .text() on the response object to get it into a usable format. The problem is, my code is returning the entire HTML of the github webpage, when all I want is the contents of the file. Here is my code:

function fetchCSV(){
    var corsProxy = "https://cors-anywhere.herokuapp.com/"; //having CORS issues so using a cors proxy currently
    var url = "https://github.com/path/to/file/data.csv";
    return fetch(corsProxy + url)  
       .then((responseObj)=>{
          return responseObj.text();
       });
    return true;  // Will respond asynchronously.
}

console.log(fetchCSV()); //returns a promise object with resolve value that contains entire github webpage html

So, how do I get just the contents of the CSV file, and not the entire webpage?

MRB
  • 221
  • 2
  • 12
  • 3
    Try `https://raw.githubusercontent.com/user/repo/branch/file` ([example](https://raw.githubusercontent.com/mrb/mrb.github.com/master/feed.xml) for [this file](https://github.com/mrb/mrb.github.com/blob/master/feed.xml)) – blex Sep 13 '20 at 16:14

0 Answers0