清单 V3 的更新
我想出了一个办法来做到这一点。但要格外小心您的 url 过滤和其他保护措施。
从 Manifest v3 开始,您可以设置修改呼入和呼出的规则。在清单的一个名为"host_permissions"
. 您可以在此处查看如何在清单中实施规则:
https ://developer.chrome.com/docs/extensions/reference/declarativeNetRequest/#manifest
有一个称为"allowAllRequests"
使用此规则的规则操作允许您进行跨域请求,绕过预检检查。您可以在此处阅读有关规则的更多信息:
https ://developer.chrome.com/docs/extensions/reference/declarativeNetRequest/#type-RuleActionType
要使用此规则,您需要包含"resourceTypes"
key in"condition"
和"main_frame"
or的值"sub_frame"
还要确保完全卸载您的扩展并重新安装以使这些更改生效。
来自谷歌的示例清单:
{
"name": "My extension",
...
"declarative_net_request" : {
"rule_resources" : [{
"id": "ruleset_1",
"enabled": true,
"path": "rules_1.json"
}, {
"id": "ruleset_2",
"enabled": false,
"path": "rules_2.json"
}]
},
"permissions": [
"declarativeNetRequest",
"declarativeNetRequestFeedback",
"*://example.com/*"
],
"host_permissions": [
"http://www.blogger.com/",
"*://*/*"
],
...
}
示例 Rule.json:
[
{
"id": 1,
"priority": 1,
"action": { "type": "allowAllRequests" },
"condition": {
"urlFilter": "again make sure you are very specific with this.",
"resourceTypes": ["main_frame"]
}
}
]