question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Code working in Chrome with native fetch, but not Safari with the polyfill.

See original GitHub issue

I have the following code:

fetch('//api.mysite/url', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  }
});

My Access-Control-Request-Headers contains content-type (note case), which works using native fetch in Chrome, but fails in Safari using this polyfill:

Failed to load resource: Request header field Content-Type is not allowed by Access-Control-Allow-Headers.

Initially I thought it was something to do with case, but lowercasing Content-Type didn’t seem to fix it.

Per RFC 7230, headers should be case insensitive anyway: "Each header field consists of a case-insensitive field name followed by a colon (“😊, optional leading whitespace, the field value, and optional trailing whitespace.”

Any ideas what could be causing this? If it’s a bug, happy to contribute a fix.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
cxolterocommented, Jan 25, 2017

try:

{
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  mode: 'cors'
}
1reaction
bradwoodscommented, Mar 20, 2018

I had an issue using the fetch API to get an image from an AWS S3 bucket. I was receiving a CORS issue on some of the images. Adding

headers: {
    'Content-Type': 'application/json'
},

fixed the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Safari not setting CORS cookies using JS Fetch API
The same code works correctly in FF and Chrome (I tested using both native and polyfill fetch ). The request is across domains;;...
Read more >
Fetch API - MDN Web Docs
Fetch provides a generic definition of Request and Response objects (and other things involved with network requests).
Read more >
What are Polyfills? - JavaScript in Plain English
To provide an example, let's say that fetch is not supported on all browsers, and we use it frequently in our application. /*...
Read more >
Polyfill JavaScript Only When You Need To - CSS-Tricks
It is simply a way of triggering your own code when the polyfills have loaded, intended to allow the polyfill service to be...
Read more >
Top 5: Best JavaScript Polyfills for the Fetch API
Chrome ; Firefox; Safari 6.1+; Internet Explorer 10+. On modern browsers such as Chrome, Firefox, Microsoft Edge, and Safari contain native ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found