无法编辑回复标题
chrome.webRequest.onHeadersReceived.addListener(function (details) {
for(i=0;i<details.responseHeaders.length;i++)
{
if(details.responseHeaders[i].name.toLocaleLowerCase()=='content-type')
{
alert(details.responseHeaders[i].name); //it works
details.responseHeaders[i].value='text/plain; charset=utf-8';
}
}
return {responseHeaders: details.responseHeaders};
}, {urls: ["<all_urls>"]}, ['responseHeaders']);
它会警告Content-Type但不能编辑值?
答案 0 :(得分:2)
刚刚做到了
chrome.webRequest.onHeadersReceived.addListener(function (details) {
var yeniheaderlar =
[{
name : "Content-Security-Policy",
value : "sil"
}, {
name : "Content-Security-Policy-Report-Only",
value : "sil"
}, {
name : "X-Content-Security-Policy",
value : "sil"
}, {
name : "X-WebKit-CSP",
value : "sil"
}, {
name : "X-Frame-Options",
value : "sil"
}, {
name : "X-XSS-Protection",
value : "sil"
}, {
name : "Access-Control-Allow-Origin",
value : "*"
}, {
name : "Access-Control-Allow-Methods",
value : "POST, GET, OPTIONS, DELETE, PUT"
}, {
name : "Access-Control-Allow-Headers",
value : "*"
}
];
for (z = 0; z < yeniheaderlar.length; z++) {
var zamazingo = false;
for (i = 0; i < details.responseHeaders.length; i++) {
if (details.responseHeaders[i].name.toLowerCase() == yeniheaderlar[z].name.toLowerCase()) {
if (yeniheaderlar[z].value == "sil") {
details.responseHeaders.splice(i, 1);
} else {
details.responseHeaders[i].value = yeniheaderlar[z].value; ;
}
zamazingo = true;
}
}
if (!zamazingo && (yeniheaderlar[z].value != 'sil')) {
details.responseHeaders.push(yeniheaderlar[z]);
}
}
return {
responseHeaders : details.responseHeaders
};
}, {
urls : ["<all_urls>"],
types : ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", "other"]
},
["blocking", "responseHeaders"]);
答案 1 :(得分:0)
你试过details.responseHeaders[i].name = 'text/plain; charset=utf-8';
吗?