@honeybadger-io/js 6.6.0 → 6.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -179,7 +179,7 @@
179
179
  parse: parse
180
180
  });
181
181
 
182
- var require$$0 = /*@__PURE__*/getAugmentedNamespace(stackTraceParser_esm);
182
+ var require$$0$1 = /*@__PURE__*/getAugmentedNamespace(stackTraceParser_esm);
183
183
 
184
184
  (function (exports) {
185
185
  var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
@@ -242,8 +242,9 @@
242
242
  }
243
243
  };
244
244
  Object.defineProperty(exports, "__esModule", { value: true });
245
- exports.isBrowserConfig = exports.clone = exports.formatCGIData = exports.filterUrl = exports.filter = exports.generateStackTrace = exports.endpoint = exports.instrument = exports.isErrorObject = exports.makeNotice = exports.logger = exports.sanitize = exports.shallowClone = exports.runAfterNotifyHandlers = exports.runBeforeNotifyHandlers = exports.getSourceForBacktrace = exports.getCauses = exports.calculateBacktraceShift = exports.DEFAULT_BACKTRACE_SHIFT = exports.makeBacktrace = exports.objectIsExtensible = exports.objectIsEmpty = exports.mergeNotice = exports.merge = void 0;
246
- var stackTraceParser = __importStar(require$$0);
245
+ exports.isBrowserConfig = exports.clone = exports.formatCGIData = exports.filterUrl = exports.filter = exports.generateStackTrace = exports.endpoint = exports.instrumentConsole = exports.instrument = exports.isErrorObject = exports.makeNotice = exports.logger = exports.sanitize = exports.shallowClone = exports.runAfterNotifyHandlers = exports.runBeforeNotifyHandlers = exports.getSourceForBacktrace = exports.getCauses = exports.calculateBacktraceShift = exports.DEFAULT_BACKTRACE_SHIFT = exports.makeBacktrace = exports.objectIsExtensible = exports.objectIsEmpty = exports.mergeNotice = exports.merge = void 0;
246
+ /* eslint-disable prefer-rest-params */
247
+ var stackTraceParser = __importStar(require$$0$1);
247
248
  function merge(obj1, obj2) {
248
249
  var result = {};
249
250
  for (var k in obj1) {
@@ -603,6 +604,39 @@
603
604
  }
604
605
  }
605
606
  exports.instrument = instrument;
607
+ var _consoleAlreadyInstrumented = false;
608
+ var listeners = [];
609
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
610
+ function instrumentConsole(_window, handler) {
611
+ if (!_window || !_window.console || !handler) {
612
+ return;
613
+ }
614
+ listeners.push(handler);
615
+ if (_consoleAlreadyInstrumented) {
616
+ return;
617
+ }
618
+ _consoleAlreadyInstrumented = true;
619
+ ['debug', 'info', 'warn', 'error', 'log'].forEach(function (level) {
620
+ instrument(_window.console, level, function hbLogger(original) {
621
+ return function () {
622
+ var args = Array.prototype.slice.call(arguments);
623
+ listeners.forEach(function (listener) {
624
+ try {
625
+ listener(level, args);
626
+ }
627
+ catch (_e) {
628
+ // ignore
629
+ // should never reach here because instrument method already wraps with try/catch block
630
+ }
631
+ });
632
+ if (typeof original === 'function') {
633
+ Function.prototype.apply.call(original, _window.console, arguments);
634
+ }
635
+ };
636
+ });
637
+ });
638
+ }
639
+ exports.instrumentConsole = instrumentConsole;
606
640
  function endpoint(base, path) {
607
641
  var endpoint = base.trim().replace(/\/$/, '');
608
642
  path = path.trim().replace(/(^\/|\/$)/g, '');
@@ -756,7 +790,7 @@
756
790
 
757
791
  Object.defineProperty(store, "__esModule", { value: true });
758
792
  store.GlobalStore = void 0;
759
- var util_1$7 = util$1;
793
+ var util_1$9 = util$1;
760
794
  var GlobalStore = /** @class */ (function () {
761
795
  function GlobalStore(contents, breadcrumbsLimit) {
762
796
  this.contents = contents;
@@ -773,7 +807,7 @@
773
807
  return JSON.parse(JSON.stringify(value));
774
808
  };
775
809
  GlobalStore.prototype.setContext = function (context) {
776
- this.contents.context = (0, util_1$7.merge)(this.contents.context, context || {});
810
+ this.contents.context = (0, util_1$9.merge)(this.contents.context, context || {});
777
811
  };
778
812
  GlobalStore.prototype.addBreadcrumb = function (breadcrumb) {
779
813
  if (this.contents.breadcrumbs.length == this.breadcrumbsLimit) {
@@ -792,6 +826,195 @@
792
826
  }());
793
827
  store.GlobalStore = GlobalStore;
794
828
 
829
+ var throttled_events_logger = {};
830
+
831
+ class NdJson {
832
+ static parse(data) {
833
+ const lines = data.trim().split('\n');
834
+ return lines.map(line => JSON.parse(line));
835
+ }
836
+ static stringify(data) {
837
+ return data.map(item => JSON.stringify(item)).join('\n');
838
+ }
839
+ }
840
+
841
+ var module = /*#__PURE__*/Object.freeze({
842
+ __proto__: null,
843
+ NdJson: NdJson
844
+ });
845
+
846
+ var require$$0 = /*@__PURE__*/getAugmentedNamespace(module);
847
+
848
+ var defaults = {};
849
+
850
+ Object.defineProperty(defaults, "__esModule", { value: true });
851
+ defaults.CONFIG = void 0;
852
+ defaults.CONFIG = {
853
+ apiKey: null,
854
+ endpoint: 'https://api.honeybadger.io',
855
+ environment: null,
856
+ hostname: null,
857
+ projectRoot: null,
858
+ component: null,
859
+ action: null,
860
+ revision: null,
861
+ reportData: null,
862
+ breadcrumbsEnabled: true,
863
+ eventsEnabled: false,
864
+ maxBreadcrumbs: 40,
865
+ maxObjectDepth: 8,
866
+ logger: console,
867
+ developmentEnvironments: ['dev', 'development', 'test'],
868
+ debug: false,
869
+ tags: null,
870
+ enableUncaught: true,
871
+ enableUnhandledRejection: true,
872
+ afterUncaught: function () { return true; },
873
+ filters: ['creditcard', 'password'],
874
+ __plugins: [],
875
+ };
876
+
877
+ var __assign$1 = (commonjsGlobal && commonjsGlobal.__assign) || function () {
878
+ __assign$1 = Object.assign || function(t) {
879
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
880
+ s = arguments[i];
881
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
882
+ t[p] = s[p];
883
+ }
884
+ return t;
885
+ };
886
+ return __assign$1.apply(this, arguments);
887
+ };
888
+ var __awaiter$2 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
889
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
890
+ return new (P || (P = Promise))(function (resolve, reject) {
891
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
892
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
893
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
894
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
895
+ });
896
+ };
897
+ var __generator$2 = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
898
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
899
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
900
+ function verb(n) { return function (v) { return step([n, v]); }; }
901
+ function step(op) {
902
+ if (f) throw new TypeError("Generator is already executing.");
903
+ while (_) try {
904
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
905
+ if (y = 0, t) op = [op[0] & 2, t.value];
906
+ switch (op[0]) {
907
+ case 0: case 1: t = op; break;
908
+ case 4: _.label++; return { value: op[1], done: false };
909
+ case 5: _.label++; y = op[1]; op = [0]; continue;
910
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
911
+ default:
912
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
913
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
914
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
915
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
916
+ if (t[2]) _.ops.pop();
917
+ _.trys.pop(); continue;
918
+ }
919
+ op = body.call(thisArg, _);
920
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
921
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
922
+ }
923
+ };
924
+ Object.defineProperty(throttled_events_logger, "__esModule", { value: true });
925
+ throttled_events_logger.ThrottledEventsLogger = void 0;
926
+ var json_nd_1 = require$$0;
927
+ var util_1$8 = util$1;
928
+ var defaults_1$1 = defaults;
929
+ var ThrottledEventsLogger = /** @class */ (function () {
930
+ function ThrottledEventsLogger(config, transport) {
931
+ this.config = config;
932
+ this.transport = transport;
933
+ this.queue = [];
934
+ this.isProcessing = false;
935
+ this.config = __assign$1(__assign$1({}, defaults_1$1.CONFIG), config);
936
+ this.logger = this.originalLogger();
937
+ }
938
+ ThrottledEventsLogger.prototype.logEvent = function (data) {
939
+ this.queue.push(data);
940
+ if (!this.isProcessing) {
941
+ this.processQueue();
942
+ }
943
+ };
944
+ ThrottledEventsLogger.prototype.processQueue = function () {
945
+ var _this = this;
946
+ if (this.queue.length === 0 || this.isProcessing) {
947
+ return;
948
+ }
949
+ this.isProcessing = true;
950
+ var eventsData = this.queue.slice();
951
+ this.queue = [];
952
+ var data = json_nd_1.NdJson.stringify(eventsData);
953
+ this.makeHttpRequest(data)
954
+ .then(function () {
955
+ setTimeout(function () {
956
+ _this.isProcessing = false;
957
+ _this.processQueue();
958
+ }, 50);
959
+ })
960
+ .catch(function (error) {
961
+ _this.logger.error('[Honeybadger] Error making HTTP request:', error);
962
+ // Continue processing the queue even if there's an error
963
+ setTimeout(function () {
964
+ _this.isProcessing = false;
965
+ _this.processQueue();
966
+ }, 50);
967
+ });
968
+ };
969
+ ThrottledEventsLogger.prototype.makeHttpRequest = function (data) {
970
+ return __awaiter$2(this, void 0, void 0, function () {
971
+ var _this = this;
972
+ return __generator$2(this, function (_a) {
973
+ return [2 /*return*/, this.transport
974
+ .send({
975
+ headers: {
976
+ 'X-API-Key': this.config.apiKey,
977
+ 'Content-Type': 'application/json',
978
+ },
979
+ method: 'POST',
980
+ endpoint: (0, util_1$8.endpoint)(this.config.endpoint, '/v1/events'),
981
+ maxObjectDepth: this.config.maxObjectDepth,
982
+ logger: this.logger,
983
+ }, data)
984
+ .then(function () {
985
+ if (_this.config.debug) {
986
+ _this.logger.debug('[Honeybadger] Events sent successfully');
987
+ }
988
+ })
989
+ .catch(function (err) {
990
+ _this.logger.error("[Honeybadger] Error sending events: ".concat(err.message));
991
+ })];
992
+ });
993
+ });
994
+ };
995
+ /**
996
+ * The EventsLogger overrides the console methods
997
+ * so if we want to log something we need to use the original methods
998
+ */
999
+ ThrottledEventsLogger.prototype.originalLogger = function () {
1000
+ var _a, _b, _c, _d, _e;
1001
+ return {
1002
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1003
+ log: (_a = console.log.__hb_original) !== null && _a !== void 0 ? _a : console.log,
1004
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1005
+ info: (_b = console.info.__hb_original) !== null && _b !== void 0 ? _b : console.info,
1006
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1007
+ debug: (_c = console.debug.__hb_original) !== null && _c !== void 0 ? _c : console.debug,
1008
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1009
+ warn: (_d = console.warn.__hb_original) !== null && _d !== void 0 ? _d : console.warn,
1010
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1011
+ error: (_e = console.error.__hb_original) !== null && _e !== void 0 ? _e : console.error,
1012
+ };
1013
+ };
1014
+ return ThrottledEventsLogger;
1015
+ }());
1016
+ throttled_events_logger.ThrottledEventsLogger = ThrottledEventsLogger;
1017
+
795
1018
  var __assign = (commonjsGlobal && commonjsGlobal.__assign) || function () {
796
1019
  __assign = Object.assign || function(t) {
797
1020
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -841,8 +1064,10 @@
841
1064
  };
842
1065
  Object.defineProperty(client, "__esModule", { value: true });
843
1066
  client.Client = void 0;
844
- var util_1$6 = util$1;
1067
+ var util_1$7 = util$1;
845
1068
  var store_1 = store;
1069
+ var throttled_events_logger_1 = throttled_events_logger;
1070
+ var defaults_1 = defaults;
846
1071
  // Split at commas and spaces
847
1072
  var TAG_SEPARATOR = /,|\s+/;
848
1073
  // Checks for non-blank characters
@@ -857,12 +1082,13 @@
857
1082
  this.__notifier = {
858
1083
  name: '@honeybadger-io/core',
859
1084
  url: 'https://github.com/honeybadger-io/honeybadger-js/tree/master/packages/core',
860
- version: '6.6.0'
1085
+ version: '6.7.0'
861
1086
  };
862
- this.config = __assign({ apiKey: null, endpoint: 'https://api.honeybadger.io', environment: null, hostname: null, projectRoot: null, component: null, action: null, revision: null, reportData: null, breadcrumbsEnabled: true, maxBreadcrumbs: 40, maxObjectDepth: 8, logger: console, developmentEnvironments: ['dev', 'development', 'test'], debug: false, tags: null, enableUncaught: true, enableUnhandledRejection: true, afterUncaught: function () { return true; }, filters: ['creditcard', 'password'], __plugins: [] }, opts);
1087
+ this.config = __assign(__assign({}, defaults_1.CONFIG), opts);
863
1088
  this.__initStore();
864
1089
  this.__transport = transport;
865
- this.logger = (0, util_1$6.logger)(this);
1090
+ this.__eventsLogger = new throttled_events_logger_1.ThrottledEventsLogger(this.config, this.__transport);
1091
+ this.logger = (0, util_1$7.logger)(this);
866
1092
  }
867
1093
  Client.prototype.getVersion = function () {
868
1094
  return this.__notifier.version;
@@ -932,16 +1158,16 @@
932
1158
  var notice = this.makeNotice(noticeable, name, extra);
933
1159
  // we need to have the source file data before the beforeNotifyHandlers,
934
1160
  // in case they modify them
935
- var sourceCodeData = notice && notice.backtrace ? notice.backtrace.map(function (trace) { return (0, util_1$6.shallowClone)(trace); }) : null;
1161
+ var sourceCodeData = notice && notice.backtrace ? notice.backtrace.map(function (trace) { return (0, util_1$7.shallowClone)(trace); }) : null;
936
1162
  var preConditionsResult = this.__runPreconditions(notice);
937
1163
  if (preConditionsResult instanceof Error) {
938
- (0, util_1$6.runAfterNotifyHandlers)(notice, this.__afterNotifyHandlers, preConditionsResult);
1164
+ (0, util_1$7.runAfterNotifyHandlers)(notice, this.__afterNotifyHandlers, preConditionsResult);
939
1165
  return false;
940
1166
  }
941
1167
  if (preConditionsResult instanceof Promise) {
942
1168
  preConditionsResult.then(function (result) {
943
1169
  if (result instanceof Error) {
944
- (0, util_1$6.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, result);
1170
+ (0, util_1$7.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, result);
945
1171
  return false;
946
1172
  }
947
1173
  return _this.__send(notice, sourceCodeData);
@@ -999,18 +1225,18 @@
999
1225
  Client.prototype.makeNotice = function (noticeable, name, extra) {
1000
1226
  if (name === void 0) { name = undefined; }
1001
1227
  if (extra === void 0) { extra = undefined; }
1002
- var notice = (0, util_1$6.makeNotice)(noticeable);
1228
+ var notice = (0, util_1$7.makeNotice)(noticeable);
1003
1229
  if (name && !(typeof name === 'object')) {
1004
1230
  var n = String(name);
1005
1231
  name = { name: n };
1006
1232
  }
1007
1233
  if (name) {
1008
- notice = (0, util_1$6.mergeNotice)(notice, name);
1234
+ notice = (0, util_1$7.mergeNotice)(notice, name);
1009
1235
  }
1010
1236
  if (typeof extra === 'object' && extra !== null) {
1011
- notice = (0, util_1$6.mergeNotice)(notice, extra);
1237
+ notice = (0, util_1$7.mergeNotice)(notice, extra);
1012
1238
  }
1013
- if ((0, util_1$6.objectIsEmpty)(notice)) {
1239
+ if ((0, util_1$7.objectIsEmpty)(notice)) {
1014
1240
  return null;
1015
1241
  }
1016
1242
  var context = this.__store.getContents('context');
@@ -1020,9 +1246,9 @@
1020
1246
  // Turning into a Set will remove duplicates
1021
1247
  var tags = noticeTags.concat(contextTags).concat(configTags);
1022
1248
  var uniqueTags = tags.filter(function (item, index) { return tags.indexOf(item) === index; });
1023
- notice = (0, util_1$6.merge)(notice, {
1249
+ notice = (0, util_1$7.merge)(notice, {
1024
1250
  name: notice.name || 'Error',
1025
- context: (0, util_1$6.merge)(context, notice.context),
1251
+ context: (0, util_1$7.merge)(context, notice.context),
1026
1252
  projectRoot: notice.projectRoot || this.config.projectRoot,
1027
1253
  environment: notice.environment || this.config.environment,
1028
1254
  component: notice.component || this.config.component,
@@ -1034,11 +1260,11 @@
1034
1260
  // Otherwise we make one.
1035
1261
  if (!Array.isArray(notice.backtrace) || !notice.backtrace.length) {
1036
1262
  if (typeof notice.stack !== 'string' || !notice.stack.trim()) {
1037
- notice.stack = (0, util_1$6.generateStackTrace)();
1038
- notice.backtrace = (0, util_1$6.makeBacktrace)(notice.stack, true, this.logger);
1263
+ notice.stack = (0, util_1$7.generateStackTrace)();
1264
+ notice.backtrace = (0, util_1$7.makeBacktrace)(notice.stack, true, this.logger);
1039
1265
  }
1040
1266
  else {
1041
- notice.backtrace = (0, util_1$6.makeBacktrace)(notice.stack, false, this.logger);
1267
+ notice.backtrace = (0, util_1$7.makeBacktrace)(notice.stack, false, this.logger);
1042
1268
  }
1043
1269
  }
1044
1270
  return notice;
@@ -1048,7 +1274,7 @@
1048
1274
  return;
1049
1275
  }
1050
1276
  opts = opts || {};
1051
- var metadata = (0, util_1$6.shallowClone)(opts.metadata);
1277
+ var metadata = (0, util_1$7.shallowClone)(opts.metadata);
1052
1278
  var category = opts.category || 'custom';
1053
1279
  var timestamp = new Date().toISOString();
1054
1280
  this.__store.addBreadcrumb({
@@ -1059,6 +1285,9 @@
1059
1285
  });
1060
1286
  return this;
1061
1287
  };
1288
+ Client.prototype.logEvent = function (data) {
1289
+ this.__eventsLogger.logEvent(data);
1290
+ };
1062
1291
  Client.prototype.__getBreadcrumbs = function () {
1063
1292
  return this.__store.getContents('breadcrumbs').slice();
1064
1293
  };
@@ -1072,8 +1301,8 @@
1072
1301
  return (this.config.environment && this.config.developmentEnvironments.includes(this.config.environment));
1073
1302
  };
1074
1303
  Client.prototype.__buildPayload = function (notice) {
1075
- var headers = (0, util_1$6.filter)(notice.headers, this.config.filters) || {};
1076
- var cgiData = (0, util_1$6.filter)(__assign(__assign({}, notice.cgiData), (0, util_1$6.formatCGIData)(headers, 'HTTP_')), this.config.filters);
1304
+ var headers = (0, util_1$7.filter)(notice.headers, this.config.filters) || {};
1305
+ var cgiData = (0, util_1$7.filter)(__assign(__assign({}, notice.cgiData), (0, util_1$7.formatCGIData)(headers, 'HTTP_')), this.config.filters);
1077
1306
  return {
1078
1307
  notifier: this.__notifier,
1079
1308
  breadcrumbs: {
@@ -1086,16 +1315,16 @@
1086
1315
  backtrace: notice.backtrace,
1087
1316
  fingerprint: notice.fingerprint,
1088
1317
  tags: notice.tags,
1089
- causes: (0, util_1$6.getCauses)(notice, this.logger),
1318
+ causes: (0, util_1$7.getCauses)(notice, this.logger),
1090
1319
  },
1091
1320
  request: {
1092
- url: (0, util_1$6.filterUrl)(notice.url, this.config.filters),
1321
+ url: (0, util_1$7.filterUrl)(notice.url, this.config.filters),
1093
1322
  component: notice.component,
1094
1323
  action: notice.action,
1095
1324
  context: notice.context,
1096
1325
  cgi_data: cgiData,
1097
- params: (0, util_1$6.filter)(notice.params, this.config.filters) || {},
1098
- session: (0, util_1$6.filter)(notice.session, this.config.filters) || {}
1326
+ params: (0, util_1$7.filter)(notice.params, this.config.filters) || {},
1327
+ session: (0, util_1$7.filter)(notice.session, this.config.filters) || {}
1099
1328
  },
1100
1329
  server: {
1101
1330
  project_root: notice.projectRoot,
@@ -1132,7 +1361,7 @@
1132
1361
  this.logger.warn('could not send error report: no API key has been configured', notice);
1133
1362
  preConditionError = new Error('missing API key');
1134
1363
  }
1135
- var beforeNotifyResult = (0, util_1$6.runBeforeNotifyHandlers)(notice, this.__beforeNotifyHandlers);
1364
+ var beforeNotifyResult = (0, util_1$7.runBeforeNotifyHandlers)(notice, this.__beforeNotifyHandlers);
1136
1365
  if (!preConditionError && !beforeNotifyResult.result) {
1137
1366
  this.logger.debug('skipping error report: one or more beforeNotify handlers returned false', notice);
1138
1367
  preConditionError = new Error('beforeNotify handlers returned false');
@@ -1167,7 +1396,7 @@
1167
1396
  else {
1168
1397
  notice.__breadcrumbs = [];
1169
1398
  }
1170
- return (0, util_1$6.getSourceForBacktrace)(originalBacktrace, this.__getSourceFileHandler)
1399
+ return (0, util_1$7.getSourceForBacktrace)(originalBacktrace, this.__getSourceFileHandler)
1171
1400
  .then(function (sourcePerTrace) { return __awaiter$1(_this, void 0, void 0, function () {
1172
1401
  var payload;
1173
1402
  return __generator$1(this, function (_a) {
@@ -1183,7 +1412,7 @@
1183
1412
  'Accept': 'text/json, application/json'
1184
1413
  },
1185
1414
  method: 'POST',
1186
- endpoint: (0, util_1$6.endpoint)(this.config.endpoint, '/v1/notices/js'),
1415
+ endpoint: (0, util_1$7.endpoint)(this.config.endpoint, '/v1/notices/js'),
1187
1416
  maxObjectDepth: this.config.maxObjectDepth,
1188
1417
  logger: this.logger,
1189
1418
  }, payload)];
@@ -1191,12 +1420,12 @@
1191
1420
  }); })
1192
1421
  .then(function (res) {
1193
1422
  if (res.statusCode !== 201) {
1194
- (0, util_1$6.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, new Error("Bad HTTP response: ".concat(res.statusCode)));
1423
+ (0, util_1$7.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, new Error("Bad HTTP response: ".concat(res.statusCode)));
1195
1424
  _this.logger.warn("Error report failed: unknown response from server. code=".concat(res.statusCode));
1196
1425
  return false;
1197
1426
  }
1198
1427
  var uuid = JSON.parse(res.body).id;
1199
- (0, util_1$6.runAfterNotifyHandlers)((0, util_1$6.merge)(notice, {
1428
+ (0, util_1$7.runAfterNotifyHandlers)((0, util_1$7.merge)(notice, {
1200
1429
  id: uuid
1201
1430
  }), _this.__afterNotifyHandlers);
1202
1431
  _this.logger.info("Error report sent \u26A1 https://app.honeybadger.io/notice/".concat(uuid));
@@ -1204,7 +1433,7 @@
1204
1433
  })
1205
1434
  .catch(function (err) {
1206
1435
  _this.logger.error('Error report failed: an unknown error occurred.', "message=".concat(err.message));
1207
- (0, util_1$6.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, err);
1436
+ (0, util_1$7.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, err);
1208
1437
  return false;
1209
1438
  });
1210
1439
  };
@@ -1455,9 +1684,9 @@
1455
1684
  Object.defineProperty(onerror, "__esModule", { value: true });
1456
1685
  onerror.onError = onerror.ignoreNextOnError = void 0;
1457
1686
  /* eslint-disable prefer-rest-params */
1458
- var core_1$5 = src;
1459
- var util_1$5 = util;
1460
- var instrument$4 = core_1$5.Util.instrument, makeNotice = core_1$5.Util.makeNotice;
1687
+ var core_1$6 = src;
1688
+ var util_1$6 = util;
1689
+ var instrument$4 = core_1$6.Util.instrument, makeNotice = core_1$6.Util.makeNotice;
1461
1690
  var ignoreOnError = 0;
1462
1691
  var currentTimeout;
1463
1692
  function ignoreNextOnError() {
@@ -1470,7 +1699,7 @@
1470
1699
  onerror.ignoreNextOnError = ignoreNextOnError;
1471
1700
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1472
1701
  function onError(_window) {
1473
- if (_window === void 0) { _window = (0, util_1$5.globalThisOrWindow)(); }
1702
+ if (_window === void 0) { _window = (0, util_1$6.globalThisOrWindow)(); }
1474
1703
  return {
1475
1704
  load: function (client) {
1476
1705
  instrument$4(_window, 'onerror', function (original) {
@@ -1529,12 +1758,12 @@
1529
1758
 
1530
1759
  Object.defineProperty(onunhandledrejection, "__esModule", { value: true });
1531
1760
  /* eslint-disable prefer-rest-params */
1532
- var core_1$4 = src;
1533
- var util_1$4 = util;
1534
- var instrument$3 = core_1$4.Util.instrument;
1761
+ var core_1$5 = src;
1762
+ var util_1$5 = util;
1763
+ var instrument$3 = core_1$5.Util.instrument;
1535
1764
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1536
- function default_1$3(_window) {
1537
- if (_window === void 0) { _window = (0, util_1$4.globalThisOrWindow)(); }
1765
+ function default_1$4(_window) {
1766
+ if (_window === void 0) { _window = (0, util_1$5.globalThisOrWindow)(); }
1538
1767
  return {
1539
1768
  load: function (client) {
1540
1769
  if (!client.config.enableUnhandledRejection) {
@@ -1585,17 +1814,17 @@
1585
1814
  }
1586
1815
  };
1587
1816
  }
1588
- onunhandledrejection.default = default_1$3;
1817
+ onunhandledrejection.default = default_1$4;
1589
1818
 
1590
1819
  var breadcrumbs = {};
1591
1820
 
1592
1821
  Object.defineProperty(breadcrumbs, "__esModule", { value: true });
1593
1822
  /* eslint-disable prefer-rest-params */
1594
- var core_1$3 = src;
1595
- var util_1$3 = util;
1596
- var sanitize$1 = core_1$3.Util.sanitize, instrument$2 = core_1$3.Util.instrument;
1597
- function default_1$2(_window) {
1598
- if (_window === void 0) { _window = (0, util_1$3.globalThisOrWindow)(); }
1823
+ var core_1$4 = src;
1824
+ var util_1$4 = util;
1825
+ var sanitize$1 = core_1$4.Util.sanitize, instrument$2 = core_1$4.Util.instrument, instrumentConsole$1 = core_1$4.Util.instrumentConsole;
1826
+ function default_1$3(_window) {
1827
+ if (_window === void 0) { _window = (0, util_1$4.globalThisOrWindow)(); }
1599
1828
  return {
1600
1829
  load: function (client) {
1601
1830
  function breadcrumbsEnabled(type) {
@@ -1625,24 +1854,16 @@
1625
1854
  }
1626
1855
  }).join(' ');
1627
1856
  }
1628
- ['debug', 'info', 'warn', 'error', 'log'].forEach(function (level) {
1629
- instrument$2(_window.console, level, function (original) {
1630
- return function () {
1631
- var args = Array.prototype.slice.call(arguments);
1632
- var message = inspectArray(args);
1633
- var opts = {
1634
- category: 'log',
1635
- metadata: {
1636
- level: level,
1637
- arguments: sanitize$1(args, 3)
1638
- }
1639
- };
1640
- client.addBreadcrumb(message, opts);
1641
- if (typeof original === 'function') {
1642
- Function.prototype.apply.call(original, _window.console, arguments);
1643
- }
1644
- };
1645
- });
1857
+ instrumentConsole$1(_window, function (level, args) {
1858
+ var message = inspectArray(args);
1859
+ var opts = {
1860
+ category: 'log',
1861
+ metadata: {
1862
+ level: level,
1863
+ arguments: sanitize$1(args, 3)
1864
+ }
1865
+ };
1866
+ client.addBreadcrumb(message, opts);
1646
1867
  });
1647
1868
  })();
1648
1869
  // Breadcrumbs: instrument click events
@@ -1656,9 +1877,9 @@
1656
1877
  _window.addEventListener('click', function (event) {
1657
1878
  var message, selector, text;
1658
1879
  try {
1659
- message = (0, util_1$3.stringNameOfElement)(event.target);
1660
- selector = (0, util_1$3.stringSelectorOfElement)(event.target);
1661
- text = (0, util_1$3.stringTextOfElement)(event.target);
1880
+ message = (0, util_1$4.stringNameOfElement)(event.target);
1881
+ selector = (0, util_1$4.stringSelectorOfElement)(event.target);
1882
+ text = (0, util_1$4.stringTextOfElement)(event.target);
1662
1883
  }
1663
1884
  catch (e) {
1664
1885
  message = 'UI Click';
@@ -1697,7 +1918,7 @@
1697
1918
  // in case of url being URL object (which is valid input) we need to stringify it
1698
1919
  var url = typeof rawUrl === 'string' ? rawUrl : String(rawUrl);
1699
1920
  var method = typeof arguments[0] === 'string' ? arguments[0].toUpperCase() : arguments[0];
1700
- var message = "".concat(method, " ").concat((0, util_1$3.localURLPathname)(url));
1921
+ var message = "".concat(method, " ").concat((0, util_1$4.localURLPathname)(url));
1701
1922
  this.__hb_xhr = {
1702
1923
  type: 'xhr',
1703
1924
  method: method,
@@ -1754,7 +1975,7 @@
1754
1975
  if (!breadcrumbsEnabled('network')) {
1755
1976
  return;
1756
1977
  }
1757
- if (!(0, util_1$3.nativeFetch)()) {
1978
+ if (!(0, util_1$4.nativeFetch)()) {
1758
1979
  // Polyfills use XHR.
1759
1980
  return;
1760
1981
  }
@@ -1783,7 +2004,7 @@
1783
2004
  method = method.toUpperCase();
1784
2005
  }
1785
2006
  // localURLPathname cant be constructed for CF workers due to reliance on "document".
1786
- var message = "".concat(method, " ").concat(typeof document === 'undefined' ? url : (0, util_1$3.localURLPathname)(url));
2007
+ var message = "".concat(method, " ").concat(typeof document === 'undefined' ? url : (0, util_1$4.localURLPathname)(url));
1787
2008
  var metadata = {
1788
2009
  type: 'fetch',
1789
2010
  method: method,
@@ -1855,7 +2076,40 @@
1855
2076
  }
1856
2077
  };
1857
2078
  }
1858
- breadcrumbs.default = default_1$2;
2079
+ breadcrumbs.default = default_1$3;
2080
+
2081
+ var events = {};
2082
+
2083
+ Object.defineProperty(events, "__esModule", { value: true });
2084
+ /* eslint-disable prefer-rest-params */
2085
+ var core_1$3 = src;
2086
+ var util_1$3 = util;
2087
+ var instrumentConsole = core_1$3.Util.instrumentConsole;
2088
+ function default_1$2(_window) {
2089
+ if (_window === void 0) { _window = (0, util_1$3.globalThisOrWindow)(); }
2090
+ return {
2091
+ shouldReloadOnConfigure: false,
2092
+ load: function (client) {
2093
+ function sendEventsToInsights() {
2094
+ return client.config.eventsEnabled;
2095
+ }
2096
+ if (!sendEventsToInsights()) {
2097
+ return;
2098
+ }
2099
+ instrumentConsole(_window, function (level, args) {
2100
+ if (!sendEventsToInsights()) {
2101
+ return;
2102
+ }
2103
+ // todo: send browser info
2104
+ client.logEvent({
2105
+ level: level,
2106
+ args: args
2107
+ });
2108
+ });
2109
+ }
2110
+ };
2111
+ }
2112
+ events.default = default_1$2;
1859
2113
 
1860
2114
  var timers = {};
1861
2115
 
@@ -2019,8 +2273,8 @@
2019
2273
  headers: headers
2020
2274
  };
2021
2275
  // GET methods cannot have a body.
2022
- if (options.method === 'POST') {
2023
- requestInit.body = payload ? JSON.stringify(sanitize(payload, options.maxObjectDepth)) : undefined;
2276
+ if (options.method === 'POST' && payload) {
2277
+ requestInit.body = typeof payload === 'string' ? payload : JSON.stringify(sanitize(payload, options.maxObjectDepth));
2024
2278
  }
2025
2279
  return [4 /*yield*/, (0, util_1.globalThisOrWindow)().fetch(options.endpoint, requestInit)];
2026
2280
  case 1:
@@ -2110,6 +2364,7 @@
2110
2364
  var onerror_1 = onerror;
2111
2365
  var onunhandledrejection_1 = __importDefault(onunhandledrejection);
2112
2366
  var breadcrumbs_1 = __importDefault(breadcrumbs);
2367
+ var events_1 = __importDefault(events);
2113
2368
  var timers_1 = __importDefault(timers);
2114
2369
  var event_listeners_1 = __importDefault(event_listeners);
2115
2370
  var transport_1 = transport;
@@ -2132,7 +2387,9 @@
2132
2387
  __extends(Honeybadger, _super);
2133
2388
  function Honeybadger(opts) {
2134
2389
  if (opts === void 0) { opts = {}; }
2135
- var _this = _super.call(this, __assign({ userFeedbackEndpoint: 'https://api.honeybadger.io/v2/feedback', async: true, maxErrors: null, projectRoot: getProjectRoot() }, opts), new transport_1.BrowserTransport()) || this;
2390
+ var _this = _super.call(this, __assign({ userFeedbackEndpoint: 'https://api.honeybadger.io/v2/feedback', async: true, maxErrors: null, projectRoot: getProjectRoot() }, opts), new transport_1.BrowserTransport({
2391
+ 'User-Agent': userAgent(),
2392
+ })) || this;
2136
2393
  /** @internal */
2137
2394
  _this.__errorsSent = 0;
2138
2395
  /** @internal */
@@ -2327,20 +2584,27 @@
2327
2584
  };
2328
2585
  return Honeybadger;
2329
2586
  }(core_1.Client));
2587
+ var NOTIFIER = {
2588
+ name: '@honeybadger-io/js',
2589
+ url: 'https://github.com/honeybadger-io/honeybadger-js/tree/master/packages/js',
2590
+ version: '6.7.0'
2591
+ };
2592
+ var userAgent = function () {
2593
+ if (typeof navigator !== undefined) {
2594
+ return "Honeybadger JS Browser Client ".concat(NOTIFIER.version, "; ").concat(navigator.userAgent);
2595
+ }
2596
+ return "Honeybadger JS Browser Client ".concat(NOTIFIER.version, "; n/a; n/a");
2597
+ };
2330
2598
  var singleton = new Honeybadger({
2331
2599
  __plugins: [
2332
2600
  (0, onerror_1.onError)(),
2333
2601
  (0, onunhandledrejection_1.default)(),
2334
2602
  (0, timers_1.default)(),
2335
2603
  (0, event_listeners_1.default)(),
2336
- (0, breadcrumbs_1.default)()
2604
+ (0, breadcrumbs_1.default)(),
2605
+ (0, events_1.default)(),
2337
2606
  ]
2338
2607
  });
2339
- var NOTIFIER = {
2340
- name: '@honeybadger-io/js',
2341
- url: 'https://github.com/honeybadger-io/honeybadger-js/tree/master/packages/js',
2342
- version: '6.6.0'
2343
- };
2344
2608
  singleton.setNotifier(NOTIFIER);
2345
2609
  var core_2 = src;
2346
2610
  Object.defineProperty(exports, "Types", { enumerable: true, get: function () { return core_2.Types; } });