其他分享
首页 > 其他分享> > chrome插件修改Referer

chrome插件修改Referer

作者:互联网

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

);

标签:function,插件,chrome,Referer,details,var,type
来源: https://blog.csdn.net/justdoshare/article/details/121729516