首页 > 解决方案 > 无法使用 chrome.declarativeNetRequest.updateDynamicRules() 更新规则

问题描述

这是我的“popup.js”代码,我试图通过按下扩展弹出窗口中的保存按钮来添加动态规则,但 webstorm 指示此规则数组不是 Rule [] 类型。忽略 Webstorm 并尝试使用它我得到这个错误有Unchecked runtime.lastError: Internal error while updating dynamic rules.什么想法吗?

const saveButton = document.getElementById("save")

saveButton.addEventListener('click',() => {
    console.log(document.getElementById('domain').value)
    chrome.declarativeNetRequest.updateDynamicRules(
        {
            addRules: [
                {
                    "id": 1,
                    "priority": 1,
                    "action": {
                        "type": "redirect",
                        "redirect": {
                            "regexSubstitution": document.getElementById('domain').value
                        }
                    },
                    "condition": {
                        "regexFilter": "www.youtube.com",
                        "resourceTypes": [
                            "main_frame"
                        ],
                        "excludedDomains": [document.getElementById('domain').value]
                    }
                }
            ]
         }
    )
})

标签: javascriptgoogle-chrome-extension

解决方案


推荐阅读