@honeybadger-io/js 4.7.4 → 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.4'
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,
@@ -1092,7 +1091,7 @@
1092
1091
  var util = {};
1093
1092
 
1094
1093
  Object.defineProperty(util, "__esModule", { value: true });
1095
- 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;
1096
1095
  /**
1097
1096
  * Converts an HTMLElement into a human-readable string.
1098
1097
  * @param {!HTMLElement} element
@@ -1149,10 +1148,11 @@
1149
1148
  }
1150
1149
  util.stringTextOfElement = stringTextOfElement;
1151
1150
  function nativeFetch() {
1152
- if (!window.fetch) {
1151
+ var global = globalThisOrWindow();
1152
+ if (!global.fetch) {
1153
1153
  return false;
1154
1154
  }
1155
- if (isNative(window.fetch)) {
1155
+ if (isNative(global.fetch)) {
1156
1156
  return true;
1157
1157
  }
1158
1158
  // If fetch isn't native, it may be wrapped by someone else. Try to get
@@ -1248,6 +1248,9 @@
1248
1248
  // will provide more information in modern browsers.
1249
1249
  util.preferCatch = (function () {
1250
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;
1251
1254
  // IE < 10
1252
1255
  if (!window.atob) {
1253
1256
  preferCatch = false;
@@ -1265,6 +1268,19 @@
1265
1268
  }
1266
1269
  return preferCatch;
1267
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;
1268
1284
 
1269
1285
  var onerror = {};
1270
1286
 
@@ -1272,6 +1288,7 @@
1272
1288
  onerror.onError = onerror.ignoreNextOnError = void 0;
1273
1289
  /* eslint-disable prefer-rest-params */
1274
1290
  var core_1$5 = src;
1291
+ var util_1$5 = util;
1275
1292
  var instrument$4 = core_1$5.Util.instrument, makeNotice = core_1$5.Util.makeNotice;
1276
1293
  var ignoreOnError = 0;
1277
1294
  var currentTimeout;
@@ -1285,7 +1302,7 @@
1285
1302
  onerror.ignoreNextOnError = ignoreNextOnError;
1286
1303
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1287
1304
  function onError(_window) {
1288
- if (_window === void 0) { _window = window; }
1305
+ if (_window === void 0) { _window = (0, util_1$5.globalThisOrWindow)(); }
1289
1306
  return {
1290
1307
  load: function (client) {
1291
1308
  instrument$4(_window, 'onerror', function (original) {
@@ -1330,7 +1347,7 @@
1330
1347
  return function (msg, url, line, col, err) {
1331
1348
  onerror(msg, url, line, col, err);
1332
1349
  if (typeof original === 'function') {
1333
- return original.apply(window, arguments);
1350
+ return original.apply(_window, arguments);
1334
1351
  }
1335
1352
  return false;
1336
1353
  };
@@ -1345,10 +1362,11 @@
1345
1362
  Object.defineProperty(onunhandledrejection, "__esModule", { value: true });
1346
1363
  /* eslint-disable prefer-rest-params */
1347
1364
  var core_1$4 = src;
1365
+ var util_1$4 = util;
1348
1366
  var instrument$3 = core_1$4.Util.instrument;
1349
1367
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1350
1368
  function default_1$3(_window) {
1351
- if (_window === void 0) { _window = window; }
1369
+ if (_window === void 0) { _window = (0, util_1$4.globalThisOrWindow)(); }
1352
1370
  return {
1353
1371
  load: function (client) {
1354
1372
  if (!client.config.enableUnhandledRejection) {
@@ -1406,10 +1424,10 @@
1406
1424
  Object.defineProperty(breadcrumbs, "__esModule", { value: true });
1407
1425
  /* eslint-disable prefer-rest-params */
1408
1426
  var core_1$3 = src;
1409
- var util_1 = util;
1427
+ var util_1$3 = util;
1410
1428
  var sanitize$1 = core_1$3.Util.sanitize, instrument$2 = core_1$3.Util.instrument;
1411
1429
  function default_1$2(_window) {
1412
- if (_window === void 0) { _window = window; }
1430
+ if (_window === void 0) { _window = (0, util_1$3.globalThisOrWindow)(); }
1413
1431
  return {
1414
1432
  load: function (client) {
1415
1433
  function breadcrumbsEnabled(type) {
@@ -1467,9 +1485,9 @@
1467
1485
  _window.addEventListener('click', function (event) {
1468
1486
  var message, selector, text;
1469
1487
  try {
1470
- message = (0, util_1.stringNameOfElement)(event.target);
1471
- selector = (0, util_1.stringSelectorOfElement)(event.target);
1472
- 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);
1473
1491
  }
1474
1492
  catch (e) {
1475
1493
  message = 'UI Click';
@@ -1488,13 +1506,16 @@
1488
1506
  event: event
1489
1507
  }
1490
1508
  });
1491
- }, true);
1509
+ }, _window.location ? true : false); // In CloudFlare workers useCapture must be false. window.locaiton is a hacky way to detect it.
1492
1510
  })();
1493
1511
  // Breadcrumbs: instrument XMLHttpRequest
1494
1512
  (function () {
1495
1513
  if (!breadcrumbsEnabled('network')) {
1496
1514
  return;
1497
1515
  }
1516
+ // Some environments may not support XMLHttpRequest.
1517
+ if (typeof XMLHttpRequest === 'undefined')
1518
+ return;
1498
1519
  // -- On xhr.open: capture initial metadata
1499
1520
  instrument$2(XMLHttpRequest.prototype, 'open', function (original) {
1500
1521
  return function () {
@@ -1502,7 +1523,7 @@
1502
1523
  var xhr = this;
1503
1524
  var url = arguments[1];
1504
1525
  var method = typeof arguments[0] === 'string' ? arguments[0].toUpperCase() : arguments[0];
1505
- var message = "".concat(method, " ").concat((0, util_1.localURLPathname)(url));
1526
+ var message = "".concat(method, " ").concat((0, util_1$3.localURLPathname)(url));
1506
1527
  this.__hb_xhr = {
1507
1528
  type: 'xhr',
1508
1529
  method: method,
@@ -1559,7 +1580,7 @@
1559
1580
  if (!breadcrumbsEnabled('network')) {
1560
1581
  return;
1561
1582
  }
1562
- if (!(0, util_1.nativeFetch)()) {
1583
+ if (!(0, util_1$3.nativeFetch)()) {
1563
1584
  // Polyfills use XHR.
1564
1585
  return;
1565
1586
  }
@@ -1587,7 +1608,8 @@
1587
1608
  if (typeof method === 'string') {
1588
1609
  method = method.toUpperCase();
1589
1610
  }
1590
- 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));
1591
1613
  var metadata = {
1592
1614
  type: 'fetch',
1593
1615
  method: method,
@@ -1618,6 +1640,10 @@
1618
1640
  if (!breadcrumbsEnabled('navigation')) {
1619
1641
  return;
1620
1642
  }
1643
+ if (_window.location == null) {
1644
+ // Most likely in a CF worker, we should be listening to fetch requests instead.
1645
+ return;
1646
+ }
1621
1647
  // The last known href of the current page
1622
1648
  var lastHref = _window.location.href;
1623
1649
  function recordUrlChange(from, to) {
@@ -1663,9 +1689,10 @@
1663
1689
  Object.defineProperty(timers, "__esModule", { value: true });
1664
1690
  /* eslint-disable prefer-rest-params */
1665
1691
  var core_1$2 = src;
1692
+ var util_1$2 = util;
1666
1693
  var instrument$1 = core_1$2.Util.instrument;
1667
1694
  function default_1$1(_window) {
1668
- if (_window === void 0) { _window = window; }
1695
+ if (_window === void 0) { _window = (0, util_1$2.globalThisOrWindow)(); }
1669
1696
  return {
1670
1697
  load: function (client) {
1671
1698
  // Wrap timers
@@ -1699,9 +1726,10 @@
1699
1726
 
1700
1727
  Object.defineProperty(event_listeners, "__esModule", { value: true });
1701
1728
  var core_1$1 = src;
1729
+ var util_1$1 = util;
1702
1730
  var instrument = core_1$1.Util.instrument;
1703
1731
  function default_1(_window) {
1704
- if (_window === void 0) { _window = window; }
1732
+ if (_window === void 0) { _window = (0, util_1$1.globalThisOrWindow)(); }
1705
1733
  return {
1706
1734
  load: function (client) {
1707
1735
  // Wrap event listeners
@@ -1742,31 +1770,88 @@
1742
1770
 
1743
1771
  var transport = {};
1744
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
+ };
1745
1809
  Object.defineProperty(transport, "__esModule", { value: true });
1746
1810
  transport.BrowserTransport = void 0;
1747
1811
  var core_1 = src;
1812
+ var util_1 = util;
1748
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
+ }
1749
1821
  var BrowserTransport = /** @class */ (function () {
1750
1822
  function BrowserTransport() {
1751
1823
  }
1752
1824
  BrowserTransport.prototype.send = function (options, payload) {
1753
- return new Promise(function (resolve, reject) {
1754
- try {
1755
- var x_1 = new XMLHttpRequest();
1756
- x_1.open(options.method, options.endpoint, options.async);
1757
- if (Object.keys(options.headers || []).length) {
1758
- for (var i in options.headers) {
1759
- if (typeof options.headers[i] !== 'undefined') {
1760
- 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;
1761
1845
  }
1762
- }
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 })];
1763
1853
  }
1764
- x_1.send(payload ? JSON.stringify(sanitize(payload, options.maxObjectDepth)) : undefined);
1765
- x_1.onload = function () { return resolve({ statusCode: x_1.status, body: x_1.response }); };
1766
- }
1767
- catch (err) {
1768
- reject(err);
1769
- }
1854
+ });
1770
1855
  });
1771
1856
  };
1772
1857
  return BrowserTransport;
@@ -1818,7 +1903,14 @@
1818
1903
  __extends(Honeybadger, _super);
1819
1904
  function Honeybadger(opts) {
1820
1905
  if (opts === void 0) { opts = {}; }
1821
- 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;
1822
1914
  /** @internal */
1823
1915
  _this.__errorsSent = 0;
1824
1916
  /** @internal */
@@ -1830,7 +1922,7 @@
1830
1922
  _this.logger.debug('Dropping notice: max errors exceeded', notice);
1831
1923
  return false;
1832
1924
  }
1833
- if (notice && !notice.url) {
1925
+ if (notice && !notice.url && typeof document !== 'undefined') {
1834
1926
  notice.url = document.URL;
1835
1927
  }
1836
1928
  _this.__incrementErrorsCount();
@@ -1861,7 +1953,7 @@
1861
1953
  HTTP_COOKIE: undefined
1862
1954
  };
1863
1955
  cgiData.HTTP_USER_AGENT = navigator.userAgent;
1864
- if (document.referrer.match(/\S/)) {
1956
+ if (typeof document !== 'undefined' && document.referrer.match(/\S/)) {
1865
1957
  cgiData.HTTP_REFERER = document.referrer;
1866
1958
  }
1867
1959
  var cookiesObject;