Bug 293576
Summary: | declarativeNetRequest modifyHeaders doesn't support custom headers | ||
---|---|---|---|
Product: | WebKit | Reporter: | vlkv |
Component: | WebKit Extensions | Assignee: | Nobody <webkit-unassigned> |
Status: | RESOLVED DUPLICATE | ||
Severity: | Major | CC: | timothy, webkit-bug-importer |
Priority: | P2 | Keywords: | InRadar |
Version: | Safari 18 | ||
Hardware: | Mac (Apple Silicon) | ||
OS: | macOS 15 |
vlkv
tl;dr: Safari ignores rules for `modifyHeaders` when making `fetch` request from MV3 extension. However, headers are successfully modified when making `chrome.runtime.sendMessage` request.
I can reproduce this bug in Safari 18.5 and Safari Technology Preview Release 219. This bug can't be reproduced in the latest Chrome or Firefox.
I have following `manifest.json` (MV3 extension):
```
"permissions": ["storage", "declarativeNetRequestWithHostAccess"],
"host_permissions": ["http://localhost/*"],
"declarative_net_request": {
"rule_resources": [
{
"id": "modify-origin",
"enabled": true,
"path": "rules.json"
}
]
},
```
`rules.json`:
```
[
{
"id": 1,
"priority": 1,
"action": {
"type": "modifyHeaders",
"requestHeaders": [
{
"header": "Origin",
"operation": "set",
"value": "http://localhost"
}
]
},
"condition": {
"urlFilter": "http://localhost:11434/*",
"resourceTypes": ["xmlhttprequest"]
}
}
]
```
and `test-script.js`:
```
...
const response = await fetch('http://localhost:11434/api/generate', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: params
});
console.log(response)
const response2 = await new Promise((resolve, reject) => {
chrome.runtime.sendMessage({
type: "ollama-fetch",
url: "http://localhost:11434/api/generate",
body: params
}, (response) => {
if (response && response.success) {
resolve(response.data);
} else {
reject(response ? response.error : "No response");
}
});
});
console.log(response2)
...
```
`fetch` request will end up ignoring `modifyHeaders` rule, but it works in other browsers.
Attachments | ||
---|---|---|
Add attachment proposed patch, testcase, etc. |
Radar WebKit Bug Importer
<rdar://problem/152126602>
Timothy Hatcher
*** This bug has been marked as a duplicate of bug 290922 ***