jeudi 28 novembre 2019

Reading request headers inside a service worker

I've created a very basic service worker, that logs the request headers on fetch event:

self.addEventListener('fetch', event => {
  console.log("- Fetch -");
  for (const pair of event.request.headers.entries()) {
    console.log(pair[0]+ ': '+ pair[1]);
  }
});

On the main page, I'm fetching the same page like so:

function fetchPage() {
   fetch(location.href);
}

When logging the headers I'm getting just the following 2 headers:

- Fetch -
service-worker.js:12 accept: */*
service-worker.js:12 user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36

Why can't I see any other/custom headers?
Is it a security limitation?




Aucun commentaire:

Enregistrer un commentaire