title: Cookies not present after using XMLHttpRequest
body: <p><strong>Update: It looks like after receiving a 403 response, the xmlhttprequest just hangs there, and so the document.location code is never executed, any ideas on how to get around this?</strong></p>
  
  <p>I'm trying to make a bookmarklet to download videos off of YouTube, but I've come across a little problem.</p>
  
  <p>To detect the highest quality video available, I use a sort of brute force method, in which I make requests using the XMLHttpRequest object until a 404 isn't returned (I can't do it until a 200 ok is returned because YouTube redirects to a different server if the video is available, and the cross-domain policy won't allow me to access any of that data).</p>
  
  <p>Once a working URL is found, I simply set window.location to the URL and the download should start, right? Wrong. A request is made, but for reasons unknown to me, the cookies are stripped and YouTube returns a 403 access denied. This does not happen if the XML requests aren't made before it, i.e. if I just set window.location to the URL, everything works fine, it's when I do the XMLHttpRequest that the cookies aren't sent.</p>
  
  <p>It's hard to explain so here's the script:</p>
  
  <pre><code>var formats = ["37", "22", "35", "34", "18", ""];
  var url = "/get_video?video_id=" + yt.getConfig('SWF_ARGS')['video_id'] + "&amp;t=" + (unescape(yt.getConfig('SWF_ARGS')['t'])) + "&amp;fmt=";
  for (var i = 0; i &lt; formats.length; i++) {
      xmlhttp = new XMLHttpRequest;
   xmlhttp.open("HEAD", url + formats[i], false);
      xmlhttp.send(null);
      if (xmlhttp.status != 404) {
          document.location = url + formats[i];
          break
      }
  }
  </code></pre>
  
  <p>That script does not send the cookies after setting the document.location and thus does not work. However, simply doing this:</p>
  
  <pre>
  <code>
  document.location = "/get_video?video_id=" + yt.getConfig('SWF_ARGS')['video_id'] + "&t=" + (unescape(yt.getConfig('SWF_ARGS')['t']))
  </code>
  </pre>
  
  <p>DOES send the cookies along with the request, and does work. The only downside is I can't automatically detect the highest quality, I just have to try every "fmt" parameter manually until I get it right.</p>
  
  <p>So my question is: why is the XMLHttpRequest object removing cookies from subsequent requests?</p>
  
  <p>This is the first time I've ever done anything in JS by the way, so please, go easy on me. ;)</p>
  
  <p><strong>Update: It looks like after receiving a 403 response, the xmlhttprequest just hangs there, and so the document.location code is never executed, any ideas on how to get around this?</strong></p>