在Chrome 72+中,设置任何标题均可:
chrome.webRequest.onBeforeSendHeaders.addListener(function(details){
details.requestHeaders.push({name:"Anything", value:"https://google.com"});
// ...
但是设置引荐来源网址不
chrome.webRequest.onBeforeSendHeaders.addListener(function(details){
details.requestHeaders.push({name:"Referer", value:"https://google.com"});
// ...
答案 0 :(得分:3)
从Chrome 72 according to this post开始,如果要修改“接受语言”,“接受编码”,“ Cookie”或“引荐来源网址”,则必须将extraHeaders
添加到extraInfoSpec
数组中。
为了向后兼容(Chrome 71及更低版本),请检查属性EXTRA_HEADERS
。
var extraInfoSpec = ['blocking', 'requestHeaders'];
if (chrome.webRequest.OnBeforeSendHeadersOptions.hasOwnProperty('EXTRA_HEADERS')) extraInfoSpec.push('extraHeaders');
chrome.webRequest.onBeforeSendHeaders.addListener(function(details){
// ...
}, {
urls:[urls]
}, extraInfoSpec);