0

I am creating dynamic rules for declarativeNetRequest and passing the below data in updateDynamicRules api, I saw that these rules are only getting applied on doc type of request (refer image) and not on other requests, whereas this should work on all requests and apis. enter image description here

{
    "addRules": [
        {
            "id": 67487208,
            "priority": 1,
            "action": {
                "type": "modifyHeaders",
                "requestHeaders": [
                    {
                        "header": "n",
                        "operation": "set",
                        "value": "true"
                    }
                ]
            },
            "condition": {
                "urlFilter": "|https*",
                "resourceTypes": [
                    "main_frame",
                    "sub_frame"
                ]
            }
        }
    ],
    "removeRuleIds": [
        67487208
    ]
}

this is the Manifest file

{
    "name": "example",
    "description": "example",
    "version": "0.1",
    "manifest_version": 3,
    "action": {
        "default_popup": "index.html"
    },
    "background": {
        "service_worker": "background.js"
    },
    "host_permissions": ["<all_urls>"],
    "permissions": ["storage", "declarativeNetRequest"]
}

markadm
  • 83
  • 3

1 Answers1

0

Inside the addRules json array, in the conditions section, you limit your modifications to "main_frame" and "sub_frame" resource types, which is why only doc type requests are being modified. Adding all these resource types to the rule condition will solve your problem.

"condition": 
{ 
"resourceTypes": 
     ["csp_report", "font", "image", 
      "main_frame", "media", "object", 
      "other", "ping", "script", 
      "stylesheet", "sub_frame", 
      "webbundle", "websocket", 
      "webtransport", "xmlhttprequest"]
}

For more information on these types of resourceTypes, visit ResourceTypes