Add-ons

webRequest.onHeadersReceived

Fired when the HTTP response headers associated with a request have been received. You can use this event to modify HTTP response headers.

To have the response headers passed into the listener along with the rest of the request data, pass "responseHeaders" in the extraInfoSpec array.

To modify the headers, pass "blocking" in extraInfoSpec. Then in your event listener, return an object with a property named responseHeaders, whose value is the set of response headers to use. The browser will behave as if the server had sent the modified headers.

From Firefox 52 onwards, instead of returning BlockingResponse, the listener can return a Promise which is resolved with a BlockingResponse. This enables the listener to process the request asynchronously.

If you use "blocking", you must have the "webRequestBlocking" API permission in your manifest.json.

Note that it is possible for extensions to conflict here. If two extensions listen to onHeadersReceived for the same request, then the second listener will see modifications made by the first listener, and will be able to undo any changes made by the first listener. For example, if the first listener adds a Set-Cookie header, and the second listener strips all Set-Cookie headers, then the first listener's modifications will be lost. If you want to see the headers that are actually processed by the system, without the risk that another extension will subsequently alter them, use onResponseStarted, although you can't modify headers on this event.

Document Tags and Contributors

 Contributors to this page: wbamberg, globau, andrewtruongmoz, Makyen, johnadungan
 Last updated by: wbamberg,