var isBrowser = require('./isBrowser'); var listeners = []; var isOn = false; exports = { start: function() { isOn = true; }, stop: function() { isOn = false; }, addListener: function(fn) { listeners.push(fn); }, rmListener: function(fn) { var idx = listeners.indexOf(fn); if (idx > -1) { listeners.splice(idx, 1); } }, rmAllListeners: function() { listeners = []; } }; if (isBrowser) { window.addEventListener('error', function(event) { callListeners(event.error); }); window.addEventListener('unhandledrejection', function(e) { callListeners(e.reason); }); } else { process.on('uncaughtException', callListeners); process.on('unhandledRejection', callListeners); } function callListeners(err) { if (!isOn) return; for (var i = 0, len = listeners.length; i < len; i++) { listeners[i](err); } } module.exports = exports;