【发布时间】:2022-09-30 06:21:06
【问题描述】:
我有一个非常简单的 webRequest 阻塞操作,可以在 MV3 上完美运行,但是通过迁移到 MV3 declarativeNetRequestit 不起作用
对于这个简单的操作,declarativeNetRequest 上的 webRequest 的等价物是什么:
chrome.webRequest.onBeforeRequest.addListener(
function(){ return {cancel: true}; },
{
urls: ["*://*.example.com/mwlite/service-worker.js", "*://*.example.com/mwlite/manifest.json"]
},
["blocking"]
);
在 MV3 上,我有:
chrome.declarativeNetRequest.updateSessionRules(
{addRules:[{
"id": id,
"priority": 1,
"action": { "type": "block"
},
"condition": {"urlFilter": "*://*.example.com/mwlite/service-worker.js", "resourceTypes": ["image",
"media",
"main_frame",
"sub_frame",
"stylesheet",
"script",
"font",
"xmlhttprequest",
"ping",
"websocket",
"other"], "tabIds" : tabMultiId }}
],
removeRuleIds: [id]
},
);
我已经尝试过了,但它根本不起作用! 问候并非常感谢任何试图提供帮助的人。
【问题讨论】:
-
在测试以前的代码时,您可能有旧规则的剩余部分,因此请尝试使用 getSessionRules/getDynamicRules + updateSessionRules/updateDynamicRules 删除它们。另请注意,Chrome 不会取消注册该站点当前注册的 Service Worker。您可以使用 chrome.browsingData API 手动完成。
标签: google-chrome google-chrome-extension firefox-addon