I'm trying to remove a single rule from dynamic rules of declarativeNetRequest of chrome with this code:
const unblockHost = (clickData) => {
chrome.declarativeNetRequest.updateDynamicRules({
removeRuleIds: bannedHosts.map( (h, i) => {
if( new URL(clickData.pageUrl).hostname === h ){
console.log(h, i, i + 1)
return i + 1
}
})
});
}
I have an empty array named bannedHosts that will be filled with all the rules added to chrome using this function
const initRulesList = () => {
chrome.declarativeNetRequest.getDynamicRules( (rules) => {
rules.forEach( (r) => {
bannedHosts.push(r.condition.urlFilter)
})
console.log(bannedHosts)
})
}
When I call the function to remove the a banned host I will get this error message
Error in event handler: TypeError: Error in invocation of declarativeNetRequest.updateDynamicRules(declarativeNetRequest.UpdateRuleOptions options, optional function callback): Error at parameter 'options': Error at property 'removeRuleIds': Error at index 0: Invalid type: expected integer, found undefined.
How I can fix it to be able to add and remove rules dynamically in my extension?
How many dynamic rules I can handle with this chrome api?