如何在declarativeNetRequest规则中排除无发起者的请求?
问题:无法排除无发起者的declarativeNetRequest请求
我正在创建declarativeNetRequest规则,当前无法排除无发起者的请求(使用Chrome版本112.0.5615.139 (Official Build) (64-bit))。例如用户直接在地址栏手动输入URL时,规则不应拦截该请求。
我尝试排除以下值但未成功:
excludedInitiatorDomains: ["", "null", "newtab", "localhost", "about:blank", "chrome://"]
我知道chrome.runtime.id可用于排除扩展发起的请求,但不确定如何排除用户或浏览器发起的请求,恳请帮助!
最小可复现示例(MCVE)
manifest.json
{ "name": "Chrome Extension Initiator Domain MCVE", "version": "1.0", "manifest_version": 3, "declarative_net_request": { "rule_resources": [ { "id": "ruleset_1", "enabled": true, "path": "rules.json" } ] }, "permissions": [ "declarativeNetRequest", "declarativeNetRequestFeedback" ], "host_permissions": [ "*://*.google.com/*" ], "background": { "service_worker": "background.js" } }
rules.json
[ { "id": 1, "action": { "type": "block" }, "condition": { "urlFilter": "google.com", "resourceTypes": ["main_frame"], "excludedInitiatorDomains": ["google.com", "", "null", "newtab", "localhost", "about:blank", "chrome://"] } } ]
background.js
chrome.declarativeNetRequest.onRuleMatchedDebug.addListener(info => console.log(info) )
测试日志
当打开新标签页并直接导航至google.com时,日志输出如下:
{ "request": { "documentLifecycle": "active", "frameId": 0, "frameType": "outermost_frame", "method": "GET", "parentFrameId": -1, "requestId": "72065", "tabId": 852200437, "type": "main_frame", "url": "https://www.google.com/" }, "rule": { "ruleId": 1, "rulesetId": "ruleset_1" } }
内容的提问来源于stack exchange,提问作者Efraim Bart
相关产品推荐
相关产品推荐

