在Chrome Extension服务工作者获取请求中更改了来源
嗨,我正在开发社交媒体营销的Chrome扩展。我正在使用service_worker中的获取来在Facebook上发送请求,但这对我不起作用。
当我将此请求复制为网络请求的提取请求时,然后将其粘贴到Facebook页面上时,它可以很好地工作。
不同之处在于,在服务工人中发送此请求时,原始人头被覆盖,这就是为什么它对我不起作用。
我正在使用此代码来更改标题,但这也对我不起作用。
await chrome.webRequest.onBeforeSendHeaders.addListener(
(details) => {
let { requestHeaders } = details;
const headerList = {};
for (let i = 0; i < requestHeaders.length; i += 1) {
if (requestHeaders[i].name === 'Origin') {
requestHeaders[i].value = 'https://m.facebook.com';
break;
}
}
headerList.requestHeaders = requestHeaders;
return headerList;
}, { urls: ["<all_urls>"] }, ["requestHeaders", "extraHeaders"])
您能否详细说明我应该如何使用webrequest.onbeforesendheaders更改标题。如果我必须使用dectarativenetrequest,我应该如何使用它。
我正在使用Manivest版本3 BTW。
Hi I am developing chrome extension for social media marketing. I am using fetch in service_worker to send a request on facebook but but it is not working for me.
When I copy this request as fetch Request from network requests then paste it on facebook page, it works perfectly.
The difference is that origin-header is overridden in while sending this request in service-worker thats why it doesn't work for me.
I am using this code to change the headers but this is also not working for me.
await chrome.webRequest.onBeforeSendHeaders.addListener(
(details) => {
let { requestHeaders } = details;
const headerList = {};
for (let i = 0; i < requestHeaders.length; i += 1) {
if (requestHeaders[i].name === 'Origin') {
requestHeaders[i].value = 'https://m.facebook.com';
break;
}
}
headerList.requestHeaders = requestHeaders;
return headerList;
}, { urls: ["<all_urls>"] }, ["requestHeaders", "extraHeaders"])
Can you please elaborate how should I use webRequest.onbeforeSendHeaders to change headers. If I have to use declarativeNetRequest, how should I use it.
I am using Manivest Version 3 BTW.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我使用chrome.declarativenetrequest.updatedynamicrules覆盖标题
是代码。
您还必须提供在清单中使用dectarativenetrequest的权限。
I used chrome.declarativeNetRequest.updateDynamicRules to override the headers
Here is the code.
You also have to provide permissions to use declarativeNetRequest in manifest.json