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

146
Views
JavaScript: Fetch Headers: Object literal does not add custom header, new Header() obj does

On MDN Fetch

Theres this example:

const myInit = {
  method: 'GET',
  headers: {
    'Accept': 'image/jpeg'
  },
  mode: 'cors',
  cache: 'default'
};

let myRequest = new Request('flowers.jpg', myInit);

You can see the headers object is just a normal object literal, but when I try, this code does not add the custom header:

        const PWA_FETCH_BYPASS = "X-PWA-Fetch-Bypass"
        let init = {
            headers: {
                PWA_FETCH_BYPASS: 'true'
            },
        }
        let response = await fetch(url, init)

But this code does add the custom header:

        const PWA_FETCH_BYPASS = "X-PWA-Fetch-Bypass"
        let myHeaders = new Headers();
        myHeaders.append(PWA_FETCH_BYPASS, 'true')
        const init = {
            headers: myHeaders
        }

        let response = await fetch(url, init)

Why does object literal version not add the custom header?

about 4 years ago · Juan Pablo Isaza
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!