Why are headers not updated when using Puppeteer page.setRequestInterception(true) on Firefox?
PuppeteerFirefox currently mutates the headers object returned by request.headers() in a way that does not reflect in the response headers. In other words, mutating the copied headers you obtained from request.headers() and then calling request.continue({ headers }) does not guarantee those changes will be visible in response.request().headers(). Chrome has a related fix (PR 14341) to align behavior, but Firefox behaves differently. A reliable pattern is to track the mutated headers on your side and map them to the corresponding request, rather than reading them back from the response. This avoids relying on response.headers() to reflect modifications.
// TypeScript/JavaScript example
const modifiedHeaders = new WeakMap<object, Record<string, string>>();
page.on("request", req => {
const headers = { ...(req.headers() || {}), testung: 'abceded' };
console.log(`[request] ${JSON.stringify(headers)}`);
modifiedHeaders.set(req, headers);
req.continue({ headers });
});
page.on('response', resp => {
const req = resp.request();
const seen = modifiedHeaders.get(req) || {};
console.log(`[response] tracked headers: ${JSON.stringify(seen)}`);
});
What you can rely on is that request.headers() represents the headers before interception, and response.headers() reflects what the server actually sent back. If you need to correlate mutations, maintain your own mapping keyed by the intercepted request.