Skip to content
This repository was archived by the owner on Jul 30, 2026. It is now read-only.
This repository was archived by the owner on Jul 30, 2026. It is now read-only.

onBeforeSendHeaders not working in Chromium for certain "extra" headers #229

Description

@p0358

This isn't present in Firefox, but that polyfill doesn't cover it currently. Consider the following example:

function appendReferer(e) {
    e.requestHeaders.push({name: "Referer", value: "https://example.org"});
    return {requestHeaders: e.requestHeaders};
}

browser.webRequest.onBeforeSendHeaders.addListener(appendReferer,
    {urls: ["https://example.com"]},
    ["blocking", "requestHeaders"]
);

Now that will work in Firefox just fine. But apparently in Chromium since some time you need to add extraHeaders to extraInfoSpec in order to be able to retrieve and modify some headers.

So something like this would fix the above example then:

function appendReferer(e) {
    e.requestHeaders.push({name: "Referer", value: "https://example.org"});
    return {requestHeaders: e.requestHeaders};
}

let appendReferer_extraInfoSpec = ["blocking", "requestHeaders"];
if (chrome.webRequest.OnBeforeSendHeadersOptions.hasOwnProperty('EXTRA_HEADERS')) appendReferer_extraInfoSpec.push('extraHeaders');

browser.webRequest.onBeforeSendHeaders.addListener(appendReferer,
    {urls: ["https://example.com"]},
    appendReferer_extraInfoSpec
);

My simple fix proposition:
check the listener of onBeforeSendHeaders, if the resulting requestHeaders contain any of the "extra" headers, do push "extraHeaders" to extraInfoSpec before sending that to chrome

Affected headers include (https://developer.chrome.com/extensions/webRequest):

  • Origin
  • Accept-Language
  • Accept-Encoding
  • Referer
  • Cookie
  • Set-Cookie

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions