chrome.webRequest API header access changes

1,293 views
Skip to first unread message

cdu...@chromium.org

unread,
Nov 28, 2018, 2:29:16 PM11/28/18
to Chromium Extensions

Starting from Chrome 72, certain request and response headers will not be available by default in webRequest listeners which specify ‘requestHeaders’ or ‘responseHeaders’ in the extraInfoSpec. To view, modify, or delete these headers, the listener will need to also specify ‘extraHeaders’ in the extraInfoSpec. The affected headers are:


Request headers:

  • Accept-Language

  • Accept-Encoding

  • Cookie

  • Referer


Response headers:

  • Set-Cookie


Note: using ‘extraHeaders’ in a listener can impact performance for all matching requests, so only use this when absolutely necessary.


Thanks!

cdu...@chromium.org

unread,
Nov 28, 2018, 4:16:05 PM11/28/18
to Chromium Extensions
One other note, before Chrome 72, an error will be thrown if 'extraHeaders' is added to extraInfoSpec. To make sure 'extraHeaders' is supported, you will want to check the corresponding options object for your listener, and only add 'extraHeaders' if it is available. For example, for onBeforeSendHeaders, you could do something like:

var extraInfoSpec = ['blocking', 'requestHeaders'];
if (chrome.webRequest.OnBeforeSendHeadersOptions.hasOwnProperty('EXTRA_HEADERS'))
  extraInfoSpec.push('extraHeaders');

And similar for other listeners.

Thanks!

Hlawuleka Maswanganyi

unread,
Feb 11, 2019, 3:34:26 AM2/11/19
to Chromium Extensions
Is it possible to be more clear around what exactly one needs to do to resolve the "accept-language" issue?

Hlawuleka Maswanganyi

unread,
Feb 11, 2019, 4:18:26 AM2/11/19
to Chromium Extensions
Never mind. Resolved.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages