We wrote a Chrome-extension that, using the onBeforeSendHeaders event, adds a cookie to each web request:
chrome.webRequest.onBeforeSendHeaders.addListener(addCookie, {
urls: ["<all_urls>"]
}, ["blocking", "requestHeaders"]);
function addCookie(details) {
if (details.url.match(/ourWebsite/)) {
details.requestHeaders.forEach(function (requestHeader) {
if (requestHeader.name.toLowerCase() === "cookie") {
//Code that adds a cookie with a value
}
});
return {requestHeaders: details.requestHeaders};
}
}
It works fine on everyone's Chrome but my own. While debugging the extension, I noticed that the details.requestHeaders
array doesn't have the cookie
header (this is always false: requestHeader.name.toLowerCase() === "cookie"
).
My first thought was another extension is messing up with ours, so I tried in incognito (where no other extensions are allowed) but it didn't work.
In the extension's manifest we have both "cookies" and "webRequest" under permissions
.
Any ideas? Thanks in advance!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…