Inject header for a specific request for a specific type

127 views
Skip to first unread message

Jordan Cohen

unread,
Jul 9, 2023, 4:05:36 PM7/9/23
to Chromium Extensions
site 1 has image.png
site 2 wants to fetch image.png from site 1

CORs normally blocks this type of request. My ask is simply to add a 

```
Access-Control-Allow-Origin: *
```

...response header when site 2 fetches from site 1. For the life of me there is no combination of configuration I can slap together to get this to work. So far this is what I am doing, any help would be greatly appreciated. The has been the hardest api to understand in all my years of working in technology but some considerable margin.

```
{
    manifest_version: 3,
...
    
    "permissions": [
      "declarativeNetRequest",
      "declarativeNetRequestWithHostAccess",
      "declarativeNetRequestFeedback",
      "scripting",
      "activeTab"
    ],
    "host_permissions": ["https://*.site-1.com/*", "https://*.site-2.com/*"],
    "declarative_net_request": {
      "rule_resources": [
        {
          "id": "ruleset_1",
          "enabled": true,
          "path": "rules.json"
        }
      ]
    },
  }
}
```
 

```
[
  {
    "id" : 1,
    "priority": 1,
    "action": {
      "type": "modifyHeaders",
      "responseHeaders": [
        { "header": "Access-Control-Allow-Origin", "operation": "set", "value": "*" }
      ]
    },
    "condition" : {
      "urlFilter" : "https://*.site-1.com/*",
      "initiatorDomains": ["https://*.site-2.com/*"]
      "resourceTypes" : ["image"]
    }
  }
]
```

Thanks in advanced
 

Jordan Cohen

unread,
Jul 9, 2023, 9:32:57 PM7/9/23
to Chromium Extensions, Jordan Cohen
So it seems declarativeNetRequestWithHostAccess does work when used with requestHeaders but it won't work with responseHeaders? Is this a bug?

Jordan Cohen

unread,
Jul 9, 2023, 9:33:39 PM7/9/23
to Chromium Extensions, Jordan Cohen
bleh i meant to say declarative_net_request not declarativeNetRequestWithHostAccess

Patrick Kettner

unread,
Jul 9, 2023, 9:37:37 PM7/9/23
to Jordan Cohen, Chromium Extensions
Hey Jordan!
I believe you are hitting this bug. The modification is happening, but it is not reflected in the devtools UI

--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/6f93c64c-05ed-4c5e-a7d0-40e89c1dd688n%40chromium.org.

Olga Obasja

unread,
Jul 10, 2023, 12:28:08 AM7/10/23
to Jordan Cohen, Chromium Extensions

пн, 10 июл. 2023 г., 4:33 Jordan Cohen <hype...@gmail.com>:
--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
Reply all
Reply to author
Forward
0 new messages