title: Alternative to XMLHttpRequest() o DOMParser.parseFromString to make a DOMobject from an external website?
body: <p>I am developing an extension which needs to take the HTML of an external website and looks for all the downloadable links. The code I have written works... but only sometimes, because during the parse process, a lot of the websites makes the parser throw a parseError at some point. There are some webs (which are designed good enough to be able to be parsed without problems) where all the extension works perfectly. In some other websites, the parseerror makes the getElementsByTagName useless. </p>
  
  <p>I guess one option would be to instead of using a DOMobject to find all the links by reading the strings... but that's way more complicated. The point is that using the Downloader extension sample from the chrome extensions dev website, it works perfectly (because instead of using the DOMobject from an external website, it creates the DOMobject from the current active tab). </p>
  
  <p>I thought also of the alternative of opening a new tab with the website temporarily, loading the DOMobject from that tab and then close it and keep going on with the code, but it is a very ugly solution (the user would see a tab opening and closing...).</p>
  
  <p>Edited with current code. Now I receive a document object as response, but when I want to put it in an object to deal with it the result is undefined.</p>
  
  <pre><code>    //Get the HTML of the website
  var xhr = new XMLHttpRequest();
  xhr.open("GET",website.get_URL);
  xhr.responseType = "document";
  xhr.send();
  doc = xhr.responseXML;
  // if(xhr.responseXML !== null){
      // doc = xhr.responseXML;
   // } else {
      // // var parser = new DOMParser();
      // // doc = parser.parseFromString(xhr.response, "text/xml");
   // };
  console.log(xhr);
  console.log(doc);
  // Get all the links in the website and put them in an array (from Download extension from Chrome Extensions Samples)
  var links = [].slice.apply(doc.getElementsByTagName("a"));
  console.log(links);
  links = links.map(function(element){
      var href = element.href;
      var hashIndex = href.indexOf('#');
      if (hashIndex &gt;= 0) {
          href = href.substr(0, hashIndex);
      }       
      return href;
  }); 
  </code></pre>