title: Extract cookie from chrome.webRequest.onBeforeSendHeaders
body: <p>I'm working on a Firefox add-on to intercept HTTP requests and extract the cookie. I was able to extract 'User-agent' from the header but was unable to extract the cookie. The code I used is below. </p>
  
  <pre><code>chrome.webRequest.onBeforeSendHeaders.addListener(function(details){
    var headers = details.requestHeaders,
    blockingResponse = {};
  
    for( var i = 0, l = headers.length; i &lt; l; ++i ) {
      window.alert("Checking headers");
      if( headers[i].name == 'Cookie' ) {
         headers[i].value = 'twid=notsecret';
         window.alert("Cookie Changed");
         console.log(headers[i].value);
         break;
      }
    }
  
    blockingResponse.requestHeaders = headers;
    return blockingResponse;
  },
  {urls: [ "&lt;all_urls&gt;" ]},['requestHeaders','blocking']);
  </code></pre>
  
  <p>Why is this not working and are there alternative methods?</p>