无法在Chrome扩展程序(Chrome 72+)中设置Referer(或Cookie)标头

时间:2019-02-03 21:54:42

标签: google-chrome google-chrome-extension

在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"}); 
// ...

1 个答案:

答案 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);