One should preserve the previously associated onerror callback as well
<script type="text/javascript">(function() { var errorCallback = window.onerror; window.onerror = function () { // handle error condition errorCallback && errorCallback.apply(this, arguments); };})();</script>