'How can I use fetch in chrome-extension that I change the origin?
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)
Solution 1:[1]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | imlokesh |
