3000 explained code solutions for 75 technologies

chrome-extensionHow to modify requests headers

chrome.webRequest.onBeforeSendHeaders.addListener( function(e) {
    for ( let header of e.requestHeaders ) {
      if ( header.name.toLowerCase() === 'user-agent' ) {
        header.value = 'some other value';
    return {requestHeaders: e.requestHeaders};
  }, {urls: ['<all_urls>']}, ['blocking', 'requestHeaders']
);ctrl + c

let's listen to an event right before chrome is going to send requests to the server


iterate through all request headers


name of the header we want to modify


set new value for the header we want