title: How to use XMLHttpRequest to download an HTML page in the background and extract a text element from it?
body: <p>I want to make a Greasemonkey script that, while you are in URL_1, the script parses the whole HTML web page of URL_2 in the background in order to extract a text element from it.</p>
  
  <p>To be specific, I want to download the whole page's HTML code (a <em>Rotten Tomatoes</em> page) in the background and store it in a variable and then use <code>getElementsByClassName[0]</code> in order to extract the text I want from the element with class name "critic_consensus".  </p>
  
  <p><br/>
  I've found this in MDN: <a href="https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/HTML_in_XMLHttpRequest" rel="nofollow">HTML in XMLHttpRequest</a> so, I ended up in this unfortunately non-working code:</p>
  
  <pre><code>var xhr = new XMLHttpRequest();
  xhr.onload = function() {
    alert(this.responseXML.getElementsByClassName(critic_consensus)[0].innerHTML);
  }
  xhr.open("GET", "http://www.rottentomatoes.com/m/godfather/",true);
  xhr.responseType = "document";
  xhr.send();
  </code></pre>
  
  <p>It shows this error message when I run it in Firefox Scratchpad:</p>
  
  <blockquote>
    <p>Cross-Origin Request Blocked: The Same Origin Policy disallows reading
    the remote resource at <a href="http://www.rottentomatoes.com/m/godfather/" rel="nofollow">http://www.rottentomatoes.com/m/godfather/</a>.
    This can be fixed by moving the resource to the same domain or
    enabling CORS.</p>
  </blockquote>
  
  <p><br/>
  PS. The reason why I don't use the Rotten Tomatoes API is that <a href="http://developer.rottentomatoes.com/forum/read/184496" rel="nofollow">they've removed the critics consensus from it</a>.</p>