<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>293576</bug_id>
          
          <creation_ts>2025-05-26 02:40:03 -0700</creation_ts>
          <short_desc>declarativeNetRequest modifyHeaders doesn&apos;t support custom headers</short_desc>
          <delta_ts>2025-06-13 12:02:51 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebKit Extensions</component>
          <version>Safari 18</version>
          <rep_platform>Mac (Apple Silicon)</rep_platform>
          <op_sys>macOS 15</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>290922</dup_id>
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Major</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>vlkv</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>timothy</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2119676</commentid>
    <comment_count>0</comment_count>
    <who name="">vlkv</who>
    <bug_when>2025-05-26 02:40:03 -0700</bug_when>
    <thetext>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&apos;t be reproduced in the latest Chrome or Firefox. 



I have following `manifest.json` (MV3 extension):
```
&quot;permissions&quot;: [&quot;storage&quot;, &quot;declarativeNetRequestWithHostAccess&quot;],
  &quot;host_permissions&quot;: [&quot;http://localhost/*&quot;],
  &quot;declarative_net_request&quot;: {
    &quot;rule_resources&quot;: [
      {
        &quot;id&quot;: &quot;modify-origin&quot;,
        &quot;enabled&quot;: true,
        &quot;path&quot;: &quot;rules.json&quot;
      }
    ]
  },

```

`rules.json`:
```
[
    {
      &quot;id&quot;: 1,
      &quot;priority&quot;: 1,
      &quot;action&quot;: {
        &quot;type&quot;: &quot;modifyHeaders&quot;,
        &quot;requestHeaders&quot;: [
          {
            &quot;header&quot;: &quot;Origin&quot;,
            &quot;operation&quot;: &quot;set&quot;,
            &quot;value&quot;: &quot;http://localhost&quot;
          }
        ]
      },
      &quot;condition&quot;: {
        &quot;urlFilter&quot;: &quot;http://localhost:11434/*&quot;,
        &quot;resourceTypes&quot;: [&quot;xmlhttprequest&quot;]
      }
    }
  ]
  


```

and `test-script.js`:
```
...
const response = await fetch(&apos;http://localhost:11434/api/generate&apos;, {
        method: &apos;POST&apos;,
        headers: { &apos;Content-Type&apos;: &apos;application/json&apos; },
        body: params
    });
    console.log(response)

    const response2 = await new Promise((resolve, reject) =&gt; {
        chrome.runtime.sendMessage({
            type: &quot;ollama-fetch&quot;,
            url: &quot;http://localhost:11434/api/generate&quot;,
            body: params
        }, (response) =&gt; {
            if (response &amp;&amp; response.success) {
                resolve(response.data);
            } else {
                reject(response ? response.error : &quot;No response&quot;);
            }
        });
    });
    console.log(response2)
...

```

`fetch` request will end up ignoring `modifyHeaders` rule, but it works in other browsers.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2120034</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2025-05-27 19:25:35 -0700</bug_when>
    <thetext>&lt;rdar://problem/152126602&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2123547</commentid>
    <comment_count>2</comment_count>
    <who name="Timothy Hatcher">timothy</who>
    <bug_when>2025-06-13 12:02:51 -0700</bug_when>
    <thetext>

*** This bug has been marked as a duplicate of bug 290922 ***</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>