Google chrome extension 在Chrome扩展中动态添加规则的DeclarativeNet请求路径
如何在manifest json文件中指定动态规则? 目前我有:Google chrome extension 在Chrome扩展中动态添加规则的DeclarativeNet请求路径,google-chrome-extension,Google Chrome Extension,如何在manifest json文件中指定动态规则? 目前我有: "declarative_net_request": { "rule_resources": [{ "id": "ruleset_1", "enabled": true, "path": "rules.json" }] } 在我的b
"declarative_net_request": {
"rule_resources": [{
"id": "ruleset_1",
"enabled": true,
"path": "rules.json"
}] }
在我的background.js
文件中
const blockUrls = ['qwe.com', '123.com'];
blockUrls.forEach((domain, index) => {
let id = index + 1;
chrome.declarativeNetRequest.updateDynamicRules({
addRules: [
{
id: id,
priority: 1,
action: { type: 'block' },
condition: { urlFilter: domain, resourceTypes: ['main_frame'] },
},
],
removeRuleIds: [id],
});
});
在
路径
字段中我应该写什么?动态规则与静态规则无关,因此只需从manifest.json中删除声明性\u net\u请求
。此外,不要为每个URL调用updateDynamicRules,而是生成一个包含所有规则的数组,并在一次updateDynamicRules调用中注册它们一次。