本文介绍了如何在更改原点的 chrome-extension 中使用 fetch?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!
问题描述
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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!
本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!