I've created a very basic service worker, that logs the request headers on fetch
event:
(我创建了一个非常基本的服务工作程序,该事件记录了fetch
事件时的请求头:)
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:
(记录标题时,我只会得到以下2个标题:)
- 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?(这是安全限制吗?)
ask by Shlomi Schwartz translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…