chrome.webRequest.onBeforeSendHeaders.addListener(
function(details){
alert(details.type)
console.log(details)
if(details.type=='xmlhttprequest'){
var exists=false;
for(var i=0;i<details.requestHeaders.length;i++){
if(details.requestHeaders[i].name=="Referer"){
exists=true;
details.requestHeaders[i].value="https://www.baidu.com/";//要修改的referer
break;
}
}
if(!exists){
details.requestHeaders.push({
name:"Referer",
value:"https://www.sogou.com"
})
}
}
return {requestHeaders:details.requestHeaders};
},
{urls:['https://www.abc.com/api*']},//只有访问的网址匹配到这里的请求才修改refer
["blocking","requestHeaders","extraHeaders"]//chrome72以后必须添加 extraHeaders
);