提问人:Sam 提问时间:5/27/2023 更新时间:5/27/2023 访问量:130
如何将“Referer”标头添加到使用清单 V3 进行的扩展中进行的网络调用?
How to add `Referer` header to network calls being made in extensions made using manifest V3?
问:
我使用 manifest v3 开发了一个 chrome 扩展程序。我正在内容脚本中打开一个 iframe,并且从 iframe 中进行了很少的网络调用。我看到这些调用没有标头。为了解决这个问题,我使用了.Referer
declarativeNetRequest
我有这个在我的manifest.json
"permissions": ["scripting", "activeTab", "contextMenus", "storage", "tabs", "declarativeNetRequestWithHostAccess",
"declarativeNetRequestFeedback"]
在我的 中使用这段代码添加标头service worker
Referer
async function addRefererToRequestHeader() {
const ruleId = Math.floor(Math.random() * 1000000); // Generate a random number as the rule ID
const rules = [{
id: ruleId,
action: {
type: 'modifyHeaders',
requestHeaders: [
{
header: 'New-Referer',
operation: 'set',
value: 'https://example.com/*',
},
],
},
condition: {
resourceTypes: ['sub_frame'],
urlFilter: 'https://example.com/*',
},
}];
try {
await browser.declarativeNetRequest.updateDynamicRules({
removeRuleIds: [],
addRules: rules,
});
console.log('Rules added successfully.');
} catch (error) {
console.error('Error adding rules:', error);
}
}
但显然,调用不包含任何标头。
甚至可以添加标题吗?如果是这样,如何?这样做会带来哪些安全隐患?https://example.com/*
Referer
Referer
PS:我正在使用webextension polyyfills浏览器
答: 暂无答案
评论
<all_urls>
host_permissions
New-Referer
Referer
1
chrome://net-export
this-is-a-referer-header
chrome://net-export