I'm using the fetch
API in React, and I'm pulling down some data from a JSON endpoint.
As part of my requests, I want to send a custom User-Agent
string. Currently, when I inspect my requests, the UA string is:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
Since I'm pasing in headers with every request, I figured I'd just append User-Agent
to the headers object, like it says in various places online:
fetch(url, {
Accept: 'application/json',
'Content-Type': 'application/json',
'User-Agent': 'MY-UA-STRING' // <---
})
But this doesn't work. I have a feeling it's becuase of a bug in the fetch api, as reported here and here and here.
Anyone have a work around on how to pass UA as part of the headers
using fetch
?