@honeybadger-io/js 4.7.1 → 4.8.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.
@@ -204,7 +204,7 @@
204
204
  __setModuleDefault(result, mod);
205
205
  return result;
206
206
  };
207
- var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
207
+ var __awaiter$1 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
208
208
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
209
209
  return new (P || (P = Promise))(function (resolve, reject) {
210
210
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -213,7 +213,7 @@
213
213
  step((generator = generator.apply(thisArg, _arguments || [])).next());
214
214
  });
215
215
  };
216
- var __generator = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
216
+ var __generator$1 = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
217
217
  var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
218
218
  return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
219
219
  function verb(n) { return function (v) { return step([n, v]); }; }
@@ -317,9 +317,9 @@
317
317
  }
318
318
  util$1.getCauses = getCauses;
319
319
  function getSourceForBacktrace(backtrace, getSourceFileHandler) {
320
- return __awaiter(this, void 0, void 0, function () {
320
+ return __awaiter$1(this, void 0, void 0, function () {
321
321
  var result, index, trace, fileContent;
322
- return __generator(this, function (_a) {
322
+ return __generator$1(this, function (_a) {
323
323
  switch (_a.label) {
324
324
  case 0:
325
325
  result = [];
@@ -689,7 +689,7 @@
689
689
 
690
690
  Object.defineProperty(store, "__esModule", { value: true });
691
691
  store.GlobalStore = void 0;
692
- var util_1$2 = util$1;
692
+ var util_1$7 = util$1;
693
693
  var GlobalStore = /** @class */ (function () {
694
694
  function GlobalStore(contents, breadcrumbsLimit) {
695
695
  this.contents = contents;
@@ -706,7 +706,7 @@
706
706
  return JSON.parse(JSON.stringify(value));
707
707
  };
708
708
  GlobalStore.prototype.setContext = function (context) {
709
- this.contents.context = (0, util_1$2.merge)(this.contents.context, context || {});
709
+ this.contents.context = (0, util_1$7.merge)(this.contents.context, context || {});
710
710
  };
711
711
  GlobalStore.prototype.addBreadcrumb = function (breadcrumb) {
712
712
  if (this.contents.breadcrumbs.length == this.breadcrumbsLimit) {
@@ -738,12 +738,12 @@
738
738
  };
739
739
  Object.defineProperty(client, "__esModule", { value: true });
740
740
  client.Client = void 0;
741
- var util_1$1 = util$1;
741
+ var util_1$6 = util$1;
742
742
  var store_1 = store;
743
743
  var notifier = {
744
744
  name: 'honeybadger-js',
745
745
  url: 'https://github.com/honeybadger-io/honeybadger-js',
746
- version: '4.7.1'
746
+ version: '4.8.0'
747
747
  };
748
748
  // Split at commas and spaces
749
749
  var TAG_SEPARATOR = /,|\s+/;
@@ -759,7 +759,7 @@
759
759
  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);
760
760
  this.__initStore();
761
761
  this.__transport = transport;
762
- this.logger = (0, util_1$1.logger)(this);
762
+ this.logger = (0, util_1$6.logger)(this);
763
763
  }
764
764
  Client.prototype.getVersion = function () {
765
765
  return notifier.version;
@@ -829,14 +829,14 @@
829
829
  }
830
830
  // we need to have the source file data before the beforeNotifyHandlers,
831
831
  // in case they modify them
832
- var sourceCodeData = notice && notice.backtrace ? notice.backtrace.map(function (trace) { return (0, util_1$1.shallowClone)(trace); }) : null;
833
- var beforeNotifyResult = (0, util_1$1.runBeforeNotifyHandlers)(notice, this.__beforeNotifyHandlers);
832
+ var sourceCodeData = notice && notice.backtrace ? notice.backtrace.map(function (trace) { return (0, util_1$6.shallowClone)(trace); }) : null;
833
+ var beforeNotifyResult = (0, util_1$6.runBeforeNotifyHandlers)(notice, this.__beforeNotifyHandlers);
834
834
  if (!preConditionError && !beforeNotifyResult) {
835
835
  this.logger.debug('skipping error report: beforeNotify handlers returned false', notice);
836
836
  preConditionError = new Error('beforeNotify handlers returned false');
837
837
  }
838
838
  if (preConditionError) {
839
- (0, util_1$1.runAfterNotifyHandlers)(notice, this.__afterNotifyHandlers, preConditionError);
839
+ (0, util_1$6.runAfterNotifyHandlers)(notice, this.__afterNotifyHandlers, preConditionError);
840
840
  return false;
841
841
  }
842
842
  this.addBreadcrumb('Honeybadger Notice', {
@@ -849,7 +849,7 @@
849
849
  });
850
850
  var breadcrumbs = this.__store.getContents('breadcrumbs');
851
851
  notice.__breadcrumbs = this.config.breadcrumbsEnabled ? breadcrumbs : [];
852
- (0, util_1$1.getSourceForBacktrace)(sourceCodeData, this.__getSourceFileHandler)
852
+ (0, util_1$6.getSourceForBacktrace)(sourceCodeData, this.__getSourceFileHandler)
853
853
  .then(function (sourcePerTrace) {
854
854
  sourcePerTrace.forEach(function (source, index) {
855
855
  notice.backtrace[index].source = source;
@@ -863,26 +863,25 @@
863
863
  'Accept': 'text/json, application/json'
864
864
  },
865
865
  method: 'POST',
866
- endpoint: (0, util_1$1.endpoint)(_this.config.endpoint, '/v1/notices/js'),
866
+ endpoint: (0, util_1$6.endpoint)(_this.config.endpoint, '/v1/notices/js'),
867
867
  maxObjectDepth: _this.config.maxObjectDepth,
868
868
  logger: _this.logger,
869
- async: (0, util_1$1.isBrowserConfig)(_this.config) ? _this.config.async : undefined,
870
869
  }, payload)
871
870
  .then(function (res) {
872
871
  if (res.statusCode !== 201) {
873
- (0, util_1$1.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, new Error("Bad HTTP response: ".concat(res.statusCode)));
872
+ (0, util_1$6.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, new Error("Bad HTTP response: ".concat(res.statusCode)));
874
873
  _this.logger.warn("Error report failed: unknown response from server. code=".concat(res.statusCode));
875
874
  return;
876
875
  }
877
876
  var uuid = JSON.parse(res.body).id;
878
- (0, util_1$1.runAfterNotifyHandlers)((0, util_1$1.merge)(notice, {
877
+ (0, util_1$6.runAfterNotifyHandlers)((0, util_1$6.merge)(notice, {
879
878
  id: uuid
880
879
  }), _this.__afterNotifyHandlers);
881
880
  _this.logger.info("Error report sent \u26A1 https://app.honeybadger.io/notice/".concat(uuid));
882
881
  })
883
882
  .catch(function (err) {
884
883
  _this.logger.error('Error report failed: an unknown error occurred.', "message=".concat(err.message));
885
- (0, util_1$1.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, err);
884
+ (0, util_1$6.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, err);
886
885
  });
887
886
  });
888
887
  return true;
@@ -935,18 +934,18 @@
935
934
  Client.prototype.makeNotice = function (noticeable, name, extra) {
936
935
  if (name === void 0) { name = undefined; }
937
936
  if (extra === void 0) { extra = undefined; }
938
- var notice = (0, util_1$1.makeNotice)(noticeable);
937
+ var notice = (0, util_1$6.makeNotice)(noticeable);
939
938
  if (name && !(typeof name === 'object')) {
940
939
  var n = String(name);
941
940
  name = { name: n };
942
941
  }
943
942
  if (name) {
944
- notice = (0, util_1$1.mergeNotice)(notice, name);
943
+ notice = (0, util_1$6.mergeNotice)(notice, name);
945
944
  }
946
945
  if (typeof extra === 'object' && extra !== null) {
947
- notice = (0, util_1$1.mergeNotice)(notice, extra);
946
+ notice = (0, util_1$6.mergeNotice)(notice, extra);
948
947
  }
949
- if ((0, util_1$1.objectIsEmpty)(notice)) {
948
+ if ((0, util_1$6.objectIsEmpty)(notice)) {
950
949
  return null;
951
950
  }
952
951
  var context = this.__store.getContents('context');
@@ -956,9 +955,9 @@
956
955
  // Turning into a Set will remove duplicates
957
956
  var tags = noticeTags.concat(contextTags).concat(configTags);
958
957
  var uniqueTags = tags.filter(function (item, index) { return tags.indexOf(item) === index; });
959
- notice = (0, util_1$1.merge)(notice, {
958
+ notice = (0, util_1$6.merge)(notice, {
960
959
  name: notice.name || 'Error',
961
- context: (0, util_1$1.merge)(context, notice.context),
960
+ context: (0, util_1$6.merge)(context, notice.context),
962
961
  projectRoot: notice.projectRoot || this.config.projectRoot,
963
962
  environment: notice.environment || this.config.environment,
964
963
  component: notice.component || this.config.component,
@@ -968,10 +967,10 @@
968
967
  });
969
968
  var backtraceShift = 0;
970
969
  if (typeof notice.stack !== 'string' || !notice.stack.trim()) {
971
- notice.stack = (0, util_1$1.generateStackTrace)();
970
+ notice.stack = (0, util_1$6.generateStackTrace)();
972
971
  backtraceShift = 2;
973
972
  }
974
- notice.backtrace = (0, util_1$1.makeBacktrace)(notice.stack, backtraceShift);
973
+ notice.backtrace = (0, util_1$6.makeBacktrace)(notice.stack, backtraceShift);
975
974
  return notice;
976
975
  };
977
976
  Client.prototype.addBreadcrumb = function (message, opts) {
@@ -979,7 +978,7 @@
979
978
  return;
980
979
  }
981
980
  opts = opts || {};
982
- var metadata = (0, util_1$1.shallowClone)(opts.metadata);
981
+ var metadata = (0, util_1$6.shallowClone)(opts.metadata);
983
982
  var category = opts.category || 'custom';
984
983
  var timestamp = new Date().toISOString();
985
984
  this.__store.addBreadcrumb({
@@ -1003,8 +1002,8 @@
1003
1002
  return (this.config.environment && this.config.developmentEnvironments.includes(this.config.environment));
1004
1003
  };
1005
1004
  Client.prototype.__buildPayload = function (notice) {
1006
- var headers = (0, util_1$1.filter)(notice.headers, this.config.filters) || {};
1007
- var cgiData = (0, util_1$1.filter)(__assign(__assign({}, notice.cgiData), (0, util_1$1.formatCGIData)(headers, 'HTTP_')), this.config.filters);
1005
+ var headers = (0, util_1$6.filter)(notice.headers, this.config.filters) || {};
1006
+ var cgiData = (0, util_1$6.filter)(__assign(__assign({}, notice.cgiData), (0, util_1$6.formatCGIData)(headers, 'HTTP_')), this.config.filters);
1008
1007
  return {
1009
1008
  notifier: notifier,
1010
1009
  breadcrumbs: {
@@ -1017,16 +1016,16 @@
1017
1016
  backtrace: notice.backtrace,
1018
1017
  fingerprint: notice.fingerprint,
1019
1018
  tags: notice.tags,
1020
- causes: (0, util_1$1.getCauses)(notice),
1019
+ causes: (0, util_1$6.getCauses)(notice),
1021
1020
  },
1022
1021
  request: {
1023
- url: (0, util_1$1.filterUrl)(notice.url, this.config.filters),
1022
+ url: (0, util_1$6.filterUrl)(notice.url, this.config.filters),
1024
1023
  component: notice.component,
1025
1024
  action: notice.action,
1026
1025
  context: notice.context,
1027
1026
  cgi_data: cgiData,
1028
- params: (0, util_1$1.filter)(notice.params, this.config.filters) || {},
1029
- session: (0, util_1$1.filter)(notice.session, this.config.filters) || {}
1027
+ params: (0, util_1$6.filter)(notice.params, this.config.filters) || {},
1028
+ session: (0, util_1$6.filter)(notice.session, this.config.filters) || {}
1030
1029
  },
1031
1030
  server: {
1032
1031
  project_root: notice.projectRoot,
@@ -1086,12 +1085,13 @@
1086
1085
  __exportStar(store, exports);
1087
1086
  exports.Types = __importStar(types);
1088
1087
  exports.Util = __importStar(util$1);
1088
+
1089
1089
  } (src));
1090
1090
 
1091
1091
  var util = {};
1092
1092
 
1093
1093
  Object.defineProperty(util, "__esModule", { value: true });
1094
- util.preferCatch = util.encodeCookie = util.decodeCookie = util.localURLPathname = util.parseURL = util.nativeFetch = util.stringTextOfElement = util.stringSelectorOfElement = util.stringNameOfElement = void 0;
1094
+ util.globalThisOrWindow = util.preferCatch = util.encodeCookie = util.decodeCookie = util.localURLPathname = util.parseURL = util.nativeFetch = util.stringTextOfElement = util.stringSelectorOfElement = util.stringNameOfElement = void 0;
1095
1095
  /**
1096
1096
  * Converts an HTMLElement into a human-readable string.
1097
1097
  * @param {!HTMLElement} element
@@ -1148,10 +1148,11 @@
1148
1148
  }
1149
1149
  util.stringTextOfElement = stringTextOfElement;
1150
1150
  function nativeFetch() {
1151
- if (!window.fetch) {
1151
+ var global = globalThisOrWindow();
1152
+ if (!global.fetch) {
1152
1153
  return false;
1153
1154
  }
1154
- if (isNative(window.fetch)) {
1155
+ if (isNative(global.fetch)) {
1155
1156
  return true;
1156
1157
  }
1157
1158
  // If fetch isn't native, it may be wrapped by someone else. Try to get
@@ -1247,6 +1248,9 @@
1247
1248
  // will provide more information in modern browsers.
1248
1249
  util.preferCatch = (function () {
1249
1250
  var preferCatch = true;
1251
+ // In case we're in an environment without access to "window", lets make sure theres a window.
1252
+ if (typeof window === 'undefined')
1253
+ return preferCatch;
1250
1254
  // IE < 10
1251
1255
  if (!window.atob) {
1252
1256
  preferCatch = false;
@@ -1264,6 +1268,19 @@
1264
1268
  }
1265
1269
  return preferCatch;
1266
1270
  })();
1271
+ /** globalThis has fairly good support. But just in case, lets check its defined.
1272
+ * @see {https://caniuse.com/?search=globalThis}
1273
+ */
1274
+ function globalThisOrWindow() {
1275
+ if (typeof globalThis !== 'undefined') {
1276
+ return globalThis;
1277
+ }
1278
+ if (typeof self !== 'undefined') {
1279
+ return self;
1280
+ }
1281
+ return window;
1282
+ }
1283
+ util.globalThisOrWindow = globalThisOrWindow;
1267
1284
 
1268
1285
  var onerror = {};
1269
1286
 
@@ -1271,6 +1288,7 @@
1271
1288
  onerror.onError = onerror.ignoreNextOnError = void 0;
1272
1289
  /* eslint-disable prefer-rest-params */
1273
1290
  var core_1$5 = src;
1291
+ var util_1$5 = util;
1274
1292
  var instrument$4 = core_1$5.Util.instrument, makeNotice = core_1$5.Util.makeNotice;
1275
1293
  var ignoreOnError = 0;
1276
1294
  var currentTimeout;
@@ -1284,7 +1302,7 @@
1284
1302
  onerror.ignoreNextOnError = ignoreNextOnError;
1285
1303
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1286
1304
  function onError(_window) {
1287
- if (_window === void 0) { _window = window; }
1305
+ if (_window === void 0) { _window = (0, util_1$5.globalThisOrWindow)(); }
1288
1306
  return {
1289
1307
  load: function (client) {
1290
1308
  instrument$4(_window, 'onerror', function (original) {
@@ -1329,7 +1347,7 @@
1329
1347
  return function (msg, url, line, col, err) {
1330
1348
  onerror(msg, url, line, col, err);
1331
1349
  if (typeof original === 'function') {
1332
- return original.apply(window, arguments);
1350
+ return original.apply(_window, arguments);
1333
1351
  }
1334
1352
  return false;
1335
1353
  };
@@ -1344,10 +1362,11 @@
1344
1362
  Object.defineProperty(onunhandledrejection, "__esModule", { value: true });
1345
1363
  /* eslint-disable prefer-rest-params */
1346
1364
  var core_1$4 = src;
1365
+ var util_1$4 = util;
1347
1366
  var instrument$3 = core_1$4.Util.instrument;
1348
1367
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1349
1368
  function default_1$3(_window) {
1350
- if (_window === void 0) { _window = window; }
1369
+ if (_window === void 0) { _window = (0, util_1$4.globalThisOrWindow)(); }
1351
1370
  return {
1352
1371
  load: function (client) {
1353
1372
  if (!client.config.enableUnhandledRejection) {
@@ -1405,10 +1424,10 @@
1405
1424
  Object.defineProperty(breadcrumbs, "__esModule", { value: true });
1406
1425
  /* eslint-disable prefer-rest-params */
1407
1426
  var core_1$3 = src;
1408
- var util_1 = util;
1427
+ var util_1$3 = util;
1409
1428
  var sanitize$1 = core_1$3.Util.sanitize, instrument$2 = core_1$3.Util.instrument;
1410
1429
  function default_1$2(_window) {
1411
- if (_window === void 0) { _window = window; }
1430
+ if (_window === void 0) { _window = (0, util_1$3.globalThisOrWindow)(); }
1412
1431
  return {
1413
1432
  load: function (client) {
1414
1433
  function breadcrumbsEnabled(type) {
@@ -1466,9 +1485,9 @@
1466
1485
  _window.addEventListener('click', function (event) {
1467
1486
  var message, selector, text;
1468
1487
  try {
1469
- message = (0, util_1.stringNameOfElement)(event.target);
1470
- selector = (0, util_1.stringSelectorOfElement)(event.target);
1471
- text = (0, util_1.stringTextOfElement)(event.target);
1488
+ message = (0, util_1$3.stringNameOfElement)(event.target);
1489
+ selector = (0, util_1$3.stringSelectorOfElement)(event.target);
1490
+ text = (0, util_1$3.stringTextOfElement)(event.target);
1472
1491
  }
1473
1492
  catch (e) {
1474
1493
  message = 'UI Click';
@@ -1487,13 +1506,16 @@
1487
1506
  event: event
1488
1507
  }
1489
1508
  });
1490
- }, true);
1509
+ }, _window.location ? true : false); // In CloudFlare workers useCapture must be false. window.locaiton is a hacky way to detect it.
1491
1510
  })();
1492
1511
  // Breadcrumbs: instrument XMLHttpRequest
1493
1512
  (function () {
1494
1513
  if (!breadcrumbsEnabled('network')) {
1495
1514
  return;
1496
1515
  }
1516
+ // Some environments may not support XMLHttpRequest.
1517
+ if (typeof XMLHttpRequest === 'undefined')
1518
+ return;
1497
1519
  // -- On xhr.open: capture initial metadata
1498
1520
  instrument$2(XMLHttpRequest.prototype, 'open', function (original) {
1499
1521
  return function () {
@@ -1501,7 +1523,7 @@
1501
1523
  var xhr = this;
1502
1524
  var url = arguments[1];
1503
1525
  var method = typeof arguments[0] === 'string' ? arguments[0].toUpperCase() : arguments[0];
1504
- var message = "".concat(method, " ").concat((0, util_1.localURLPathname)(url));
1526
+ var message = "".concat(method, " ").concat((0, util_1$3.localURLPathname)(url));
1505
1527
  this.__hb_xhr = {
1506
1528
  type: 'xhr',
1507
1529
  method: method,
@@ -1558,7 +1580,7 @@
1558
1580
  if (!breadcrumbsEnabled('network')) {
1559
1581
  return;
1560
1582
  }
1561
- if (!(0, util_1.nativeFetch)()) {
1583
+ if (!(0, util_1$3.nativeFetch)()) {
1562
1584
  // Polyfills use XHR.
1563
1585
  return;
1564
1586
  }
@@ -1586,7 +1608,8 @@
1586
1608
  if (typeof method === 'string') {
1587
1609
  method = method.toUpperCase();
1588
1610
  }
1589
- var message = "".concat(method, " ").concat((0, util_1.localURLPathname)(url));
1611
+ // localURLPathname cant be constructed for CF workers due to reliance on "document".
1612
+ var message = "".concat(method, " ").concat(typeof document === 'undefined' ? url : (0, util_1$3.localURLPathname)(url));
1590
1613
  var metadata = {
1591
1614
  type: 'fetch',
1592
1615
  method: method,
@@ -1617,6 +1640,10 @@
1617
1640
  if (!breadcrumbsEnabled('navigation')) {
1618
1641
  return;
1619
1642
  }
1643
+ if (_window.location == null) {
1644
+ // Most likely in a CF worker, we should be listening to fetch requests instead.
1645
+ return;
1646
+ }
1620
1647
  // The last known href of the current page
1621
1648
  var lastHref = _window.location.href;
1622
1649
  function recordUrlChange(from, to) {
@@ -1662,9 +1689,10 @@
1662
1689
  Object.defineProperty(timers, "__esModule", { value: true });
1663
1690
  /* eslint-disable prefer-rest-params */
1664
1691
  var core_1$2 = src;
1692
+ var util_1$2 = util;
1665
1693
  var instrument$1 = core_1$2.Util.instrument;
1666
1694
  function default_1$1(_window) {
1667
- if (_window === void 0) { _window = window; }
1695
+ if (_window === void 0) { _window = (0, util_1$2.globalThisOrWindow)(); }
1668
1696
  return {
1669
1697
  load: function (client) {
1670
1698
  // Wrap timers
@@ -1698,9 +1726,10 @@
1698
1726
 
1699
1727
  Object.defineProperty(event_listeners, "__esModule", { value: true });
1700
1728
  var core_1$1 = src;
1729
+ var util_1$1 = util;
1701
1730
  var instrument = core_1$1.Util.instrument;
1702
1731
  function default_1(_window) {
1703
- if (_window === void 0) { _window = window; }
1732
+ if (_window === void 0) { _window = (0, util_1$1.globalThisOrWindow)(); }
1704
1733
  return {
1705
1734
  load: function (client) {
1706
1735
  // Wrap event listeners
@@ -1741,31 +1770,88 @@
1741
1770
 
1742
1771
  var transport = {};
1743
1772
 
1773
+ var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
1774
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1775
+ return new (P || (P = Promise))(function (resolve, reject) {
1776
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
1777
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
1778
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
1779
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
1780
+ });
1781
+ };
1782
+ var __generator = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
1783
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
1784
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
1785
+ function verb(n) { return function (v) { return step([n, v]); }; }
1786
+ function step(op) {
1787
+ if (f) throw new TypeError("Generator is already executing.");
1788
+ while (_) try {
1789
+ 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;
1790
+ if (y = 0, t) op = [op[0] & 2, t.value];
1791
+ switch (op[0]) {
1792
+ case 0: case 1: t = op; break;
1793
+ case 4: _.label++; return { value: op[1], done: false };
1794
+ case 5: _.label++; y = op[1]; op = [0]; continue;
1795
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
1796
+ default:
1797
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
1798
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
1799
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
1800
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
1801
+ if (t[2]) _.ops.pop();
1802
+ _.trys.pop(); continue;
1803
+ }
1804
+ op = body.call(thisArg, _);
1805
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
1806
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
1807
+ }
1808
+ };
1744
1809
  Object.defineProperty(transport, "__esModule", { value: true });
1745
1810
  transport.BrowserTransport = void 0;
1746
1811
  var core_1 = src;
1812
+ var util_1 = util;
1747
1813
  var sanitize = core_1.Util.sanitize;
1814
+ /**
1815
+ * Helper function to get typesafe Object.entries()
1816
+ * https://twitter.com/mattpocockuk/status/1502264005251018754?lang=en
1817
+ */
1818
+ function objectEntries(obj) {
1819
+ return Object.entries(obj);
1820
+ }
1748
1821
  var BrowserTransport = /** @class */ (function () {
1749
1822
  function BrowserTransport() {
1750
1823
  }
1751
1824
  BrowserTransport.prototype.send = function (options, payload) {
1752
- return new Promise(function (resolve, reject) {
1753
- try {
1754
- var x_1 = new XMLHttpRequest();
1755
- x_1.open(options.method, options.endpoint, options.async);
1756
- if (Object.keys(options.headers || []).length) {
1757
- for (var i in options.headers) {
1758
- if (typeof options.headers[i] !== 'undefined') {
1759
- x_1.setRequestHeader(i, String(options.headers[i]));
1825
+ return __awaiter(this, void 0, void 0, function () {
1826
+ var headerArray, headers, requestInit, response, body;
1827
+ return __generator(this, function (_a) {
1828
+ switch (_a.label) {
1829
+ case 0:
1830
+ headerArray = options.headers ? objectEntries(options.headers) : [];
1831
+ headers = {};
1832
+ headerArray.forEach(function (_a) {
1833
+ var key = _a[0], value = _a[1];
1834
+ if (key != null && value != null) {
1835
+ headers[String(key)] = String(value);
1836
+ }
1837
+ });
1838
+ requestInit = {
1839
+ method: options.method,
1840
+ headers: headers
1841
+ };
1842
+ // GET methods cannot have a body.
1843
+ if (options.method === 'POST') {
1844
+ requestInit.body = payload ? JSON.stringify(sanitize(payload, options.maxObjectDepth)) : undefined;
1760
1845
  }
1761
- }
1846
+ return [4 /*yield*/, (0, util_1.globalThisOrWindow)().fetch(options.endpoint, requestInit)];
1847
+ case 1:
1848
+ response = _a.sent();
1849
+ return [4 /*yield*/, response.text()];
1850
+ case 2:
1851
+ body = _a.sent();
1852
+ return [2 /*return*/, Promise.resolve({ statusCode: response.status, body: body })];
1762
1853
  }
1763
- x_1.send(payload ? JSON.stringify(sanitize(payload, options.maxObjectDepth)) : undefined);
1764
- x_1.onload = function () { return resolve({ statusCode: x_1.status, body: x_1.response }); };
1765
- }
1766
- catch (err) {
1767
- reject(err);
1768
- }
1854
+ });
1769
1855
  });
1770
1856
  };
1771
1857
  return BrowserTransport;
@@ -1817,7 +1903,14 @@
1817
1903
  __extends(Honeybadger, _super);
1818
1904
  function Honeybadger(opts) {
1819
1905
  if (opts === void 0) { opts = {}; }
1820
- var _this = _super.call(this, __assign({ async: true, maxErrors: null, projectRoot: window.location.protocol + '//' + window.location.host }, opts), new transport_1.BrowserTransport()) || this;
1906
+ var _this = this;
1907
+ var global = (0, util_1.globalThisOrWindow)();
1908
+ var projectRoot = '';
1909
+ // Cloudflare workers do not have access to location API.
1910
+ if (global.location != null) {
1911
+ projectRoot = global.location.protocol + '//' + global.location.host;
1912
+ }
1913
+ _this = _super.call(this, __assign({ async: true, maxErrors: null, projectRoot: projectRoot }, opts), new transport_1.BrowserTransport()) || this;
1821
1914
  /** @internal */
1822
1915
  _this.__errorsSent = 0;
1823
1916
  /** @internal */
@@ -1829,7 +1922,7 @@
1829
1922
  _this.logger.debug('Dropping notice: max errors exceeded', notice);
1830
1923
  return false;
1831
1924
  }
1832
- if (notice && !notice.url) {
1925
+ if (notice && !notice.url && typeof document !== 'undefined') {
1833
1926
  notice.url = document.URL;
1834
1927
  }
1835
1928
  _this.__incrementErrorsCount();
@@ -1860,7 +1953,7 @@
1860
1953
  HTTP_COOKIE: undefined
1861
1954
  };
1862
1955
  cgiData.HTTP_USER_AGENT = navigator.userAgent;
1863
- if (document.referrer.match(/\S/)) {
1956
+ if (typeof document !== 'undefined' && document.referrer.match(/\S/)) {
1864
1957
  cgiData.HTTP_REFERER = document.referrer;
1865
1958
  }
1866
1959
  var cookiesObject;
@@ -1958,6 +2051,7 @@
1958
2051
  (0, breadcrumbs_1.default)()
1959
2052
  ]
1960
2053
  });
2054
+
1961
2055
  } (browser$1));
1962
2056
 
1963
2057
  var browser = /*@__PURE__*/getDefaultExportFromCjs(browser$1);