Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

113
Views
Firefox & Safari doesn't send custom http headers in Service Worker requests

In firefox and safari, custom headers doesn't send on fetch requests inside a service worker. But chrome works. (I added my custom header in Access-Control-Allow-Headers )

Code inside service worker:

fetch(Request, {
    headers: {
      'my-custom-header': 'a value'
    }
  });

My OPTIONS returns 204, and request mode is 'cors'. Also it is same origin request.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

(For same-origin requests, CORS doesn't come into play.)

I'm not able to reproduce the problem you describe; here's a live deployment of a site with a service worker that makes a request to the https://httpbin.org/#/Request_inspection/get_headers endpoint when it starts up, and logs the response back, indicating what request headers were received:

fetch('https://httpbin.org/headers', {
  headers: {'my-custom-header': 'a value'},
})
.then((response) => response.json())
.then((data) => console.log(data.headers));

In Chrome, Firefox, and Safari, I see the custom header returned along with the other headers that are sent by default by the browser.

You can play around with this and test out different scenarios by remixing https://glitch.com/edit/#!/valuable-nonchalant-pet?path=sw.js%3A3%3A81

about 4 years ago · Juan Pablo Isaza Report

0

I figured out my mistake. I was passing Request object instead of URL. So I should have done this like below:

const request = new Request(event.request); 
request.headers.append('my-custom-header', 'a value'); 
return fetch(request);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!