globalError.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. Object.defineProperty(exports, '__esModule', { value: true });
  2. const worldwide = require('../worldwide.js');
  3. const _handlers = require('./_handlers.js');
  4. let _oldOnErrorHandler = null;
  5. /**
  6. * Add an instrumentation handler for when an error is captured by the global error handler.
  7. *
  8. * Use at your own risk, this might break without changelog notice, only used internally.
  9. * @hidden
  10. */
  11. function addGlobalErrorInstrumentationHandler(handler) {
  12. const type = 'error';
  13. _handlers.addHandler(type, handler);
  14. _handlers.maybeInstrument(type, instrumentError);
  15. }
  16. function instrumentError() {
  17. _oldOnErrorHandler = worldwide.GLOBAL_OBJ.onerror;
  18. worldwide.GLOBAL_OBJ.onerror = function (
  19. msg,
  20. url,
  21. line,
  22. column,
  23. error,
  24. ) {
  25. const handlerData = {
  26. column,
  27. error,
  28. line,
  29. msg,
  30. url,
  31. };
  32. _handlers.triggerHandlers('error', handlerData);
  33. if (_oldOnErrorHandler && !_oldOnErrorHandler.__SENTRY_LOADER__) {
  34. // eslint-disable-next-line prefer-rest-params
  35. return _oldOnErrorHandler.apply(this, arguments);
  36. }
  37. return false;
  38. };
  39. worldwide.GLOBAL_OBJ.onerror.__SENTRY_INSTRUMENTED__ = true;
  40. }
  41. exports.addGlobalErrorInstrumentationHandler = addGlobalErrorInstrumentationHandler;
  42. //# sourceMappingURL=globalError.js.map