@honeybadger-io/js 6.12.3 → 6.15.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.
@@ -559,7 +559,7 @@
559
559
  }
560
560
  else if (isErrorObject(thing)) {
561
561
  var e = thing;
562
- notice = merge(thing, { name: e.name, message: e.message, stack: e.stack, cause: e.cause });
562
+ notice = merge(thing, { name: e.name, message: e.message, stack: e.stack, cause: e.cause, originalError: e });
563
563
  }
564
564
  else if (typeof thing === 'object') {
565
565
  notice = shallowClone(thing);
@@ -939,7 +939,7 @@
939
939
  var defaults = {};
940
940
 
941
941
  Object.defineProperty(defaults, "__esModule", { value: true });
942
- defaults.CONFIG = void 0;
942
+ defaults.BREADCRUMBS_SELECTOR_ATTRIBUTES = defaults.CONFIG = void 0;
943
943
  defaults.CONFIG = {
944
944
  apiKey: null,
945
945
  endpoint: 'https://api.honeybadger.io',
@@ -966,6 +966,8 @@
966
966
  filters: ['creditcard', 'password'],
967
967
  __plugins: [],
968
968
  };
969
+ // Browser-only, so it lives outside CONFIG (which is shared with Node).
970
+ defaults.BREADCRUMBS_SELECTOR_ATTRIBUTES = ['data-hb-name'];
969
971
 
970
972
  var __assign$2 = (commonjsGlobal && commonjsGlobal.__assign) || function () {
971
973
  __assign$2 = Object.assign || function(t) {
@@ -1198,7 +1200,7 @@
1198
1200
  this.__notifier = {
1199
1201
  name: '@honeybadger-io/core',
1200
1202
  url: 'https://github.com/honeybadger-io/honeybadger-js/tree/master/packages/core',
1201
- version: '6.12.3'
1203
+ version: '6.15.0'
1202
1204
  };
1203
1205
  this.config = __assign$1(__assign$1({}, defaults_1.CONFIG), opts);
1204
1206
  this.__initStore();
@@ -1633,12 +1635,34 @@
1633
1635
  util.preferCatch = util.encodeCookie = util.decodeCookie = util.localURLPathname = util.parseURL = util.nativeFetch = util.stringTextOfElement = util.stringSelectorOfElement = util.stringNameOfElement = void 0;
1634
1636
  var core_1$7 = src;
1635
1637
  var globalThisOrWindow$7 = core_1$7.Util.globalThisOrWindow;
1638
+ var BREADCRUMBS_SELECTOR_ATTRIBUTES = core_1$7.Defaults.BREADCRUMBS_SELECTOR_ATTRIBUTES;
1636
1639
  /**
1637
1640
  * Converts an HTMLElement into a human-readable string.
1638
1641
  * @param {!HTMLElement} element
1639
1642
  * @return {string}
1640
1643
  */
1641
- function stringNameOfElement(element) {
1644
+ function cleanNameOfElement(element, attributes) {
1645
+ if (!Array.isArray(attributes)) {
1646
+ return undefined;
1647
+ }
1648
+ if (!element || typeof element.getAttribute !== 'function') {
1649
+ return undefined;
1650
+ }
1651
+ for (var _i = 0, attributes_1 = attributes; _i < attributes_1.length; _i++) {
1652
+ var attr = attributes_1[_i];
1653
+ if (typeof attr !== 'string' || attr.length === 0) {
1654
+ continue;
1655
+ }
1656
+ var value = element.getAttribute(attr);
1657
+ if (value && value.trim()) {
1658
+ var normalized = value.trim().replace(/\s+/g, ' ');
1659
+ return truncate(normalized, 100);
1660
+ }
1661
+ }
1662
+ return undefined;
1663
+ }
1664
+ function stringNameOfElement(element, attributes) {
1665
+ if (attributes === void 0) { attributes = BREADCRUMBS_SELECTOR_ATTRIBUTES; }
1642
1666
  if (!element || !element.tagName) {
1643
1667
  return '';
1644
1668
  }
@@ -1647,6 +1671,10 @@
1647
1671
  if (name === 'html') {
1648
1672
  return '';
1649
1673
  }
1674
+ var cleanName = cleanNameOfElement(element, attributes);
1675
+ if (cleanName) {
1676
+ return cleanName;
1677
+ }
1650
1678
  if (element.id) {
1651
1679
  name += "#".concat(element.id);
1652
1680
  }
@@ -1669,10 +1697,15 @@
1669
1697
  return name;
1670
1698
  }
1671
1699
  util.stringNameOfElement = stringNameOfElement;
1672
- function stringSelectorOfElement(element) {
1673
- var name = stringNameOfElement(element);
1700
+ function stringSelectorOfElement(element, attributes) {
1701
+ if (attributes === void 0) { attributes = BREADCRUMBS_SELECTOR_ATTRIBUTES; }
1702
+ var name = stringNameOfElement(element, attributes);
1703
+ // A named element anchors the selector: stop walking up.
1704
+ if (name && cleanNameOfElement(element, attributes)) {
1705
+ return name;
1706
+ }
1674
1707
  if (element.parentNode && element.parentNode.tagName) {
1675
- var parentName = stringSelectorOfElement(element.parentNode);
1708
+ var parentName = stringSelectorOfElement(element.parentNode, attributes);
1676
1709
  if (parentName.length > 0) {
1677
1710
  return "".concat(parentName, " > ").concat(name);
1678
1711
  }
@@ -1819,7 +1852,7 @@
1819
1852
  onerror.onError = onerror.ignoreNextOnError = void 0;
1820
1853
  /* eslint-disable prefer-rest-params */
1821
1854
  var core_1$6 = src;
1822
- var instrument$4 = core_1$6.Util.instrument, makeNotice = core_1$6.Util.makeNotice, globalThisOrWindow$6 = core_1$6.Util.globalThisOrWindow;
1855
+ var instrument$4 = core_1$6.Util.instrument, makeNotice$1 = core_1$6.Util.makeNotice, globalThisOrWindow$6 = core_1$6.Util.globalThisOrWindow;
1823
1856
  var ignoreOnError = 0;
1824
1857
  var currentTimeout;
1825
1858
  function ignoreNextOnError() {
@@ -1851,7 +1884,7 @@
1851
1884
  }
1852
1885
  return;
1853
1886
  }
1854
- var notice = makeNotice(err);
1887
+ var notice = makeNotice$1(err);
1855
1888
  if (!notice.name) {
1856
1889
  notice.name = 'window.onerror';
1857
1890
  }
@@ -1892,7 +1925,7 @@
1892
1925
  Object.defineProperty(onunhandledrejection, "__esModule", { value: true });
1893
1926
  /* eslint-disable prefer-rest-params */
1894
1927
  var core_1$5 = src;
1895
- var instrument$3 = core_1$5.Util.instrument, globalThisOrWindow$5 = core_1$5.Util.globalThisOrWindow;
1928
+ var instrument$3 = core_1$5.Util.instrument, makeNotice = core_1$5.Util.makeNotice, globalThisOrWindow$5 = core_1$5.Util.globalThisOrWindow;
1896
1929
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1897
1930
  function default_1$3(_window) {
1898
1931
  if (_window === void 0) { _window = globalThisOrWindow$5(); }
@@ -1911,23 +1944,16 @@
1911
1944
  }
1912
1945
  var reason = promiseRejectionEvent.reason;
1913
1946
  if (reason instanceof Error) {
1914
- // simulate v8 stack
1915
- // const fileName = reason.fileName || 'unknown'
1916
- // const lineNumber = reason.lineNumber || 0
1917
- var fileName = 'unknown';
1918
- var lineNumber = 0;
1919
- var stackFallback = "".concat(reason.message, "\n at ? (").concat(fileName, ":").concat(lineNumber, ")");
1920
- var stack = reason.stack || stackFallback;
1921
- var err = {
1922
- name: reason.name,
1923
- message: "UnhandledPromiseRejectionWarning: ".concat(reason),
1924
- stack: stack
1925
- };
1926
- client.addBreadcrumb("window.onunhandledrejection: ".concat(err.name), {
1947
+ var notice = makeNotice(reason);
1948
+ if (!notice.stack) {
1949
+ notice.stack = "".concat(reason.message, "\n at ? (unknown:0)");
1950
+ }
1951
+ notice.message = "UnhandledPromiseRejectionWarning: ".concat(reason);
1952
+ client.addBreadcrumb("window.onunhandledrejection: ".concat(notice.name), {
1927
1953
  category: 'error',
1928
- metadata: err
1954
+ metadata: { name: notice.name, message: notice.message, stack: notice.stack }
1929
1955
  });
1930
- client.notify(err);
1956
+ client.notify(notice);
1931
1957
  return;
1932
1958
  }
1933
1959
  var message = typeof reason === 'string' ? reason : ((_a = JSON.stringify(reason)) !== null && _a !== void 0 ? _a : 'Unspecified reason');
@@ -2009,8 +2035,9 @@
2009
2035
  _window.addEventListener('click', function (event) {
2010
2036
  var message, selector, text;
2011
2037
  try {
2012
- message = (0, util_1.stringNameOfElement)(event.target);
2013
- selector = (0, util_1.stringSelectorOfElement)(event.target);
2038
+ var attributes = client.config.breadcrumbsSelectorAttributes;
2039
+ message = (0, util_1.stringNameOfElement)(event.target, attributes);
2040
+ selector = (0, util_1.stringSelectorOfElement)(event.target, attributes);
2014
2041
  text = (0, util_1.stringTextOfElement)(event.target);
2015
2042
  }
2016
2043
  catch (e) {
@@ -2559,7 +2586,7 @@
2559
2586
  __extends(Honeybadger, _super);
2560
2587
  function Honeybadger(opts) {
2561
2588
  if (opts === void 0) { opts = {}; }
2562
- var _this = _super.call(this, __assign({ userFeedbackEndpoint: 'https://api.honeybadger.io/v2/feedback', async: true, maxErrors: null, projectRoot: getProjectRoot() }, opts), new transport_1.BrowserTransport({
2589
+ var _this = _super.call(this, __assign({ userFeedbackEndpoint: 'https://api.honeybadger.io/v2/feedback', async: true, maxErrors: null, ignoreBrowserExtensionErrors: false, breadcrumbsSelectorAttributes: core_1.Defaults.BREADCRUMBS_SELECTOR_ATTRIBUTES, projectRoot: getProjectRoot() }, opts), new transport_1.BrowserTransport({
2563
2590
  'User-Agent': userAgent(),
2564
2591
  })) || this;
2565
2592
  /** @internal */
@@ -2571,6 +2598,18 @@
2571
2598
  /** @internal */
2572
2599
  _this.__beforeNotifyHandlers = [
2573
2600
  function (notice) {
2601
+ if (_this.config.ignoreBrowserExtensionErrors &&
2602
+ notice && notice.backtrace && notice.backtrace.length) {
2603
+ var topFrame = notice.backtrace[0];
2604
+ if (topFrame && typeof topFrame.file === 'string' &&
2605
+ (topFrame.file.startsWith('chrome-extension://') ||
2606
+ topFrame.file.startsWith('moz-extension://') ||
2607
+ topFrame.file.startsWith('safari-extension://') ||
2608
+ topFrame.file.startsWith('safari-web-extension://'))) {
2609
+ _this.logger.debug('Dropping notice: browser extension error', notice);
2610
+ return false;
2611
+ }
2612
+ }
2574
2613
  if (_this.__exceedsMaxErrors()) {
2575
2614
  _this.logger.debug('Dropping notice: max errors exceeded', notice);
2576
2615
  return false;
@@ -2721,7 +2760,7 @@
2721
2760
  var NOTIFIER = {
2722
2761
  name: '@honeybadger-io/js',
2723
2762
  url: 'https://github.com/honeybadger-io/honeybadger-js/tree/master/packages/js',
2724
- version: '6.12.3'
2763
+ version: '6.15.0'
2725
2764
  };
2726
2765
  var userAgent = function () {
2727
2766
  if (typeof navigator !== 'undefined') {