electron / electron/electron

[webRequest.onHeadersReceived] Not all requests show modified headers

Open
#45,168 15 comments 0 reactions 0 assignees View on GitHub
33-x-y 34-x-y bug :beetle: component/webRequest has-repro-gist platform/windows stale
Dominant language
C++
Stars
123k
Forks
17.5k
Avg merge
14h 28m
Merged PRs (30d)
870

Description

### Preflight Checklist

- [x] I have read the [Contributing Guidelines](https://github.com/electron/electron/blob/main/CONTRIBUTING.md) for this project.
- [x] I agree to follow the [Code of Conduct](https://github.com/electron/electron/blob/main/CODE_OF_CONDUCT.md) that this project adheres to.
- [x] I have searched the [issue tracker](https://www.github.com/electron/electron/issues) for a bug report that matches the one I want to file, without success.

### Electron Version

34.0.0

### What operating system(s) are you using?

Windows

### Operating System Version

Windows 10

### What arch are you using?

x64

### Last Known Working Electron version

14.2.9

### Expected Behavior

All requests that are handled with `onHeadersReceived` should show modified headers (if they are being modified in the handler)

### Actual Behavior

Some requests do not show the modified headers.
Example:
```
electron.session.defaultSession.webRequest.onHeadersReceived((details, callback) => {
console.log(details.url, details.responseHeaders);
if (details.responseHeaders) {
details.responseHeaders["test"] = ["1"];
}
callback({cancel: false, responseHeaders: details.responseHeaders});
});
```
I am setting a "test" header to each request
Navigating to google.com does not show the header in the first request:
![Image](https://github.com/user-attachments/assets/98b6b77e-31a5-468e-b94e-c3ea14180977)
It does appear in the second request though

### Testcase Gist URL

https://gist.github.com/t57ser/b97184b3c8772a8ccf7cb600ceac1202

### Additional Information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.