我正在编写一个删除请求标题内容的扩展程序" Referer"问题是即使HTTP请求是与" Referer"一起发送的。值为空,一旦加载新页面,document.referrer值就是正确的。无论" Referer"是否在内部获得document.referrer? HTTP请求和响应的价值?
扩展和内容脚本的代码如下......
chrome.webRequest.onBeforeSendHeaders.addListener(
function(details){
if(details.frameId == 0){
var referrer = '';
// traverse the headervalues and delete 'Referer'
for (var i = details.requestHeaders.length - 1; i >= 0; i--) {
if (details.requestHeaders[i].name == 'Referer'){
// save the value in order to compare it in the content script
referrer = details.requestHeaders[i].value;
details.requestHeaders[i].value = '';
};
}
chrome.tabs.sendMessage(details.tabId, { event : "onBeforeSendHeaders", referrer : referrer });
return({ requestHeaders : details.requestHeaders});
}
},
{urls: ["<all_urls>"]},
["blocking", "requestHeaders"]
);
chrome.webNavigation.onDOMContentLoaded.addListener(
function onDOMContentLoaded(details){
if(details.frameId == 0){
chrome.tabs.sendMessage(details.tabId, { event : "onDOMContentLoaded" });
}
}
);
和内容脚本
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse){
switch(request.event){
case "onBeforeSendHeaders" :
console.log("onBeforeSendHeaders:" + request.referrer);
break;
case "onDOMContentLoaded" :
// this should be blank but instead, it has the same value
// of the request.referrer, which holds the value before being deleted
console.log("onDOMContentLoaded:" + document.referrer);
break;
default :
console.log("default");
}
}
);
关于我做错了什么的任何建议?