I am attempting to add dynamic DNR redirects to a MV3 web extension running in Firefox 123. When the script in charge of adding dynamic redirects runs, it throws the error TypeError: can't access property "updateDynamicRules", browser.declarativeNetRequest is undefined. However, if I add a static redirect via the declarative_net_request property in the extension's manifest.json, it redirects the network requests exactly as expected.
The extension has the necessary permissions and host permissions needed to use the declaritiveNetRequest API, and attempts to add dynamic rules via the declarativeNetRequest.updateDynamicRules() method in a content script.
manifest.json
"permissions": [ "storage", "declarativeNetRequestWithHostAccess" ],
"host_permissions": ["*://*.example.com/"],
content script
await browser.declarativeNetRequest.updateDynamicRules({
removeRuleIds: oldIds,
addRules: newRules,
});