Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

120
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda