Safely attach a handler to window.onerror.