When I use fetch,it gets the request origin like this: Origin: chrome-extension://hhchkohknefpngiknmlkelgmnhokjnef
I want the request origin like this: Origin: www.xxxxxx.com (the now website page url)
You can do this using the onBeforeSendHeaders
event.
chrome.webRequest.onBeforeSendHeaders.addListener(
function(details) {
for (var i = 0; i < details.requestHeaders.length; ++i) {
if (details.requestHeaders[i].name === 'Origin')
details.requestHeaders[i].value = 'https://www.xxxxxx.com';
}
return {
requestHeaders: details.requestHeaders
};
}, {
urls: ["*://www.xxxxxx.com/*"]
},
["blocking", "requestHeaders", "extraHeaders"]);
extraHeaders
option is required for changing changing Origin
starting chrome 79.
You will need the following permissions in your manifest file:
"permissions": [
"webRequest",
"webRequestBlocking",
"*://www.xxxxxx.com/*"
]
Reference: https://developer.chrome.com/extensions/webRequest#implementation
这篇关于如何在更改原点的 chrome-extension 中使用 fetch?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!