title: Overridden error handler inside iframe catches errors outside it (?!?)
body: <p>The JavaScript single-page application I am maintaining opens most of the times in <strong>iframes created inside pages of our customers' sites</strong>.</p>
  
  <p>Our SPA features a brutal override of <code>window.onerror</code>, as I want to be notified on my server of all JS errors happening during the execution of my code.</p>
  
  <pre><code>window.onerror = my_global_error_handler;
  </code></pre>
  
  <p>When JS code fails I record the domain where it came from. I'd expect that all errors be generated from code coming from my company's domain.
  However, <strong>in some cases I get errors generated from JS code loaded from other domains</strong>. I wonder how this is possible, as I expect that my error handler be unable to catch errors outside the iframe where my code is executing.</p>
  
  <p>Since most of the "foreign" domains mentioned in my logs are various viral e-marketing companies, I wonder whether some smart kid is managing to inject code in my iframe.</p>
  
  <p>Another hypothesis is that <strong>some browsers may be overriding the top window's error handler</strong> when I override the one of the inner iframe window.</p>
  
  <p>What could be happening?</p>