title: location.hostname of some web pages is not accurate
body: <p>I'm writing a bookmarklet that reads <code>location.hostname</code> of the current page.</p>
  
  <p>On most sites this works fine, i.e. for <a href="https://stackoverflow.com/questions/ask">https://stackoverflow.com/questions/ask</a> it returns <code>http://stackoverflow.com</code>.</p>
  
  <p>But on some sites it does not work. For example, on <a href="http://techslides.com/over-2000-d3-js-examples-and-demos" rel="nofollow noreferrer">http://techslides.com/over-2000-d3-js-examples-and-demos</a> it returns <code>googleads.g.doubleclick.net</code>.</p>
  
  <p>I've figured out that I can get the 'original' hostname <code>http://techslides.com</code> using <code>location.ancestorOrigins[0]</code></p>
  
  <p>Using this, I've written the following attempt to get an accurate hostname on any site:</p>
  
  <pre><code>function getHostname() {
    var previous_hostnames = window.ancestorOrigins;
    if (previous_hostnames) {
      return previous_hostnames[0];
    } else {
      return window.hostname;
    }
  }
  </code></pre>
  
  <p>I'm wondering:</p>
  
  <ol>
  <li>Why is this happening?</li>
  <li>Is my approach adequate?</li>
  </ol>
  
  <p>Can assume I'm just running on Chrome, if it makes things easier. </p>
  
  <p>Chrome build:</p>
  
  <pre><code>Version 52.0.2743.116 (64-bit)
  Platform 8350.68.0 (Official Build) stable-channel orco
  Firmware Google_Orco.5216.362.7
  </code></pre>
  
  <hr>
  
  <p><em>in response to comments</em></p>
  
  <p>neither <code>location.host</code> or <code>location.origin</code> work</p>
  
  <pre><code>location.host
  "googleads.g.doubleclick.net"
  location.origin
  "https://googleads.g.doubleclick.net"
  </code></pre>