@sentry/browser 6.13.0 → 6.14.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.
Files changed (43) hide show
  1. package/build/bundle.es6.js +450 -336
  2. package/build/bundle.es6.js.map +1 -1
  3. package/build/bundle.es6.min.js +2 -2
  4. package/build/bundle.es6.min.js.map +1 -1
  5. package/build/bundle.js +451 -338
  6. package/build/bundle.js.map +1 -1
  7. package/build/bundle.min.js +2 -2
  8. package/build/bundle.min.js.map +1 -1
  9. package/dist/eventbuilder.d.ts.map +1 -1
  10. package/dist/eventbuilder.js +1 -4
  11. package/dist/eventbuilder.js.map +1 -1
  12. package/dist/helpers.d.ts.map +1 -1
  13. package/dist/helpers.js +6 -2
  14. package/dist/helpers.js.map +1 -1
  15. package/dist/transports/base.d.ts.map +1 -1
  16. package/dist/transports/base.js +12 -9
  17. package/dist/transports/base.js.map +1 -1
  18. package/dist/transports/fetch.d.ts +1 -2
  19. package/dist/transports/fetch.d.ts.map +1 -1
  20. package/dist/transports/fetch.js +2 -67
  21. package/dist/transports/fetch.js.map +1 -1
  22. package/dist/transports/utils.d.ts +48 -0
  23. package/dist/transports/utils.d.ts.map +1 -0
  24. package/dist/transports/utils.js +99 -0
  25. package/dist/transports/utils.js.map +1 -0
  26. package/esm/eventbuilder.d.ts.map +1 -1
  27. package/esm/eventbuilder.js +1 -4
  28. package/esm/eventbuilder.js.map +1 -1
  29. package/esm/helpers.d.ts.map +1 -1
  30. package/esm/helpers.js +7 -3
  31. package/esm/helpers.js.map +1 -1
  32. package/esm/transports/base.d.ts.map +1 -1
  33. package/esm/transports/base.js +14 -11
  34. package/esm/transports/base.js.map +1 -1
  35. package/esm/transports/fetch.d.ts +1 -2
  36. package/esm/transports/fetch.d.ts.map +1 -1
  37. package/esm/transports/fetch.js +2 -67
  38. package/esm/transports/fetch.js.map +1 -1
  39. package/esm/transports/utils.d.ts +48 -0
  40. package/esm/transports/utils.d.ts.map +1 -0
  41. package/esm/transports/utils.js +96 -0
  42. package/esm/transports/utils.js.map +1 -0
  43. package/package.json +23 -23
@@ -1,4 +1,4 @@
1
- /*! @sentry/browser 6.13.0 (a241a0c) | https://github.com/getsentry/sentry-javascript */
1
+ /*! @sentry/browser 6.14.0 (574741b) | https://github.com/getsentry/sentry-javascript */
2
2
  var Sentry = (function (exports) {
3
3
  /** Console logging verbosity for the SDK. */
4
4
  var LogLevel;
@@ -144,6 +144,62 @@ var Sentry = (function (exports) {
144
144
  Outcome["SampleRate"] = "sample_rate";
145
145
  })(Outcome || (Outcome = {}));
146
146
 
147
+ /**
148
+ * Consumes the promise and logs the error when it rejects.
149
+ * @param promise A promise to forget.
150
+ */
151
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
152
+ function forget(promise) {
153
+ void promise.then(null, e => {
154
+ // TODO: Use a better logging mechanism
155
+ // eslint-disable-next-line no-console
156
+ console.error(e);
157
+ });
158
+ }
159
+
160
+ /**
161
+ * NOTE: In order to avoid circular dependencies, if you add a function to this module and it needs to print something,
162
+ * you must either a) use `console.log` rather than the logger, or b) put your function elsewhere.
163
+ */
164
+ /**
165
+ * Checks whether we're in the Node.js or Browser environment
166
+ *
167
+ * @returns Answer to given question
168
+ */
169
+ function isNodeEnv() {
170
+ return Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
171
+ }
172
+ /**
173
+ * Requires a module which is protected against bundler minification.
174
+ *
175
+ * @param request The module path to resolve
176
+ */
177
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
178
+ function dynamicRequire(mod, request) {
179
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
180
+ return mod.require(request);
181
+ }
182
+
183
+ /**
184
+ * NOTE: In order to avoid circular dependencies, if you add a function to this module and it needs to print something,
185
+ * you must either a) use `console.log` rather than the logger, or b) put your function elsewhere.
186
+ */
187
+ const fallbackGlobalObject = {};
188
+ /**
189
+ * Safely get global scope object
190
+ *
191
+ * @returns Global scope object
192
+ */
193
+ function getGlobalObject() {
194
+ return (isNodeEnv()
195
+ ? global
196
+ : typeof window !== 'undefined' // eslint-disable-line no-restricted-globals
197
+ ? window // eslint-disable-line no-restricted-globals
198
+ : typeof self !== 'undefined'
199
+ ? self
200
+ : fallbackGlobalObject);
201
+ }
202
+
147
203
  /* eslint-disable @typescript-eslint/no-explicit-any */
148
204
  /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
149
205
  /**
@@ -379,6 +435,18 @@ var Sentry = (function (exports) {
379
435
  }
380
436
  }
381
437
  return out.join('');
438
+ }
439
+ /**
440
+ * A safe form of location.href
441
+ */
442
+ function getLocationHref() {
443
+ const global = getGlobalObject();
444
+ try {
445
+ return global.document.location.href;
446
+ }
447
+ catch (oO) {
448
+ return '';
449
+ }
382
450
  }
383
451
 
384
452
  const setPrototypeOf = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array ? setProtoOf : mixinProperties);
@@ -502,174 +570,17 @@ var Sentry = (function (exports) {
502
570
  }
503
571
  }
504
572
 
573
+ // TODO: Implement different loggers for different environments
574
+ const global$1 = getGlobalObject();
575
+ /** Prefix for logging strings */
576
+ const PREFIX = 'Sentry Logger ';
505
577
  /**
506
- * Checks whether we're in the Node.js or Browser environment
507
- *
508
- * @returns Answer to given question
509
- */
510
- function isNodeEnv() {
511
- return Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
512
- }
513
- /**
514
- * Requires a module which is protected against bundler minification.
515
- *
516
- * @param request The module path to resolve
517
- */
518
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
519
- function dynamicRequire(mod, request) {
520
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
521
- return mod.require(request);
522
- }
523
-
524
- /**
525
- * Truncates given string to the maximum characters count
526
- *
527
- * @param str An object that contains serializable values
528
- * @param max Maximum number of characters in truncated string (0 = unlimited)
529
- * @returns string Encoded
530
- */
531
- function truncate(str, max = 0) {
532
- if (typeof str !== 'string' || max === 0) {
533
- return str;
534
- }
535
- return str.length <= max ? str : `${str.substr(0, max)}...`;
536
- }
537
- /**
538
- * Join values in array
539
- * @param input array of values to be joined together
540
- * @param delimiter string to be placed in-between values
541
- * @returns Joined values
542
- */
543
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
544
- function safeJoin(input, delimiter) {
545
- if (!Array.isArray(input)) {
546
- return '';
547
- }
548
- const output = [];
549
- // eslint-disable-next-line @typescript-eslint/prefer-for-of
550
- for (let i = 0; i < input.length; i++) {
551
- const value = input[i];
552
- try {
553
- output.push(String(value));
554
- }
555
- catch (e) {
556
- output.push('[value cannot be serialized]');
557
- }
558
- }
559
- return output.join(delimiter);
560
- }
561
- /**
562
- * Checks if the value matches a regex or includes the string
563
- * @param value The string value to be checked against
564
- * @param pattern Either a regex or a string that must be contained in value
565
- */
566
- function isMatchingPattern(value, pattern) {
567
- if (!isString(value)) {
568
- return false;
569
- }
570
- if (isRegExp(pattern)) {
571
- return pattern.test(value);
572
- }
573
- if (typeof pattern === 'string') {
574
- return value.indexOf(pattern) !== -1;
575
- }
576
- return false;
577
- }
578
-
579
- const fallbackGlobalObject = {};
580
- /**
581
- * Safely get global scope object
578
+ * Temporarily unwrap `console.log` and friends in order to perform the given callback using the original methods.
579
+ * Restores wrapping after the callback completes.
582
580
  *
583
- * @returns Global scope object
581
+ * @param callback The function to run against the original `console` messages
582
+ * @returns The results of the callback
584
583
  */
585
- function getGlobalObject() {
586
- return (isNodeEnv()
587
- ? global
588
- : typeof window !== 'undefined'
589
- ? window
590
- : typeof self !== 'undefined'
591
- ? self
592
- : fallbackGlobalObject);
593
- }
594
- /**
595
- * UUID4 generator
596
- *
597
- * @returns string Generated UUID4.
598
- */
599
- function uuid4() {
600
- const global = getGlobalObject();
601
- const crypto = global.crypto || global.msCrypto;
602
- if (!(crypto === void 0) && crypto.getRandomValues) {
603
- // Use window.crypto API if available
604
- const arr = new Uint16Array(8);
605
- crypto.getRandomValues(arr);
606
- // set 4 in byte 7
607
- // eslint-disable-next-line no-bitwise
608
- arr[3] = (arr[3] & 0xfff) | 0x4000;
609
- // set 2 most significant bits of byte 9 to '10'
610
- // eslint-disable-next-line no-bitwise
611
- arr[4] = (arr[4] & 0x3fff) | 0x8000;
612
- const pad = (num) => {
613
- let v = num.toString(16);
614
- while (v.length < 4) {
615
- v = `0${v}`;
616
- }
617
- return v;
618
- };
619
- return (pad(arr[0]) + pad(arr[1]) + pad(arr[2]) + pad(arr[3]) + pad(arr[4]) + pad(arr[5]) + pad(arr[6]) + pad(arr[7]));
620
- }
621
- // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#2117523
622
- return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, c => {
623
- // eslint-disable-next-line no-bitwise
624
- const r = (Math.random() * 16) | 0;
625
- // eslint-disable-next-line no-bitwise
626
- const v = c === 'x' ? r : (r & 0x3) | 0x8;
627
- return v.toString(16);
628
- });
629
- }
630
- /**
631
- * Parses string form of URL into an object
632
- * // borrowed from https://tools.ietf.org/html/rfc3986#appendix-B
633
- * // intentionally using regex and not <a/> href parsing trick because React Native and other
634
- * // environments where DOM might not be available
635
- * @returns parsed URL object
636
- */
637
- function parseUrl(url) {
638
- if (!url) {
639
- return {};
640
- }
641
- const match = url.match(/^(([^:/?#]+):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/);
642
- if (!match) {
643
- return {};
644
- }
645
- // coerce to undefined values to empty string so we don't get 'undefined'
646
- const query = match[6] || '';
647
- const fragment = match[8] || '';
648
- return {
649
- host: match[4],
650
- path: match[5],
651
- protocol: match[2],
652
- relative: match[5] + query + fragment,
653
- };
654
- }
655
- /**
656
- * Extracts either message or type+value from an event that can be used for user-facing logs
657
- * @returns event's description
658
- */
659
- function getEventDescription(event) {
660
- if (event.message) {
661
- return event.message;
662
- }
663
- if (event.exception && event.exception.values && event.exception.values[0]) {
664
- const exception = event.exception.values[0];
665
- if (exception.type && exception.value) {
666
- return `${exception.type}: ${exception.value}`;
667
- }
668
- return exception.type || exception.value || event.event_id || '<unknown>';
669
- }
670
- return event.event_id || '<unknown>';
671
- }
672
- /** JSDoc */
673
584
  function consoleSandbox(callback) {
674
585
  const global = getGlobalObject();
675
586
  const levels = ['debug', 'info', 'warn', 'error', 'log', 'assert'];
@@ -695,79 +606,6 @@ var Sentry = (function (exports) {
695
606
  });
696
607
  return result;
697
608
  }
698
- /**
699
- * Adds exception values, type and value to an synthetic Exception.
700
- * @param event The event to modify.
701
- * @param value Value of the exception.
702
- * @param type Type of the exception.
703
- * @hidden
704
- */
705
- function addExceptionTypeValue(event, value, type) {
706
- event.exception = event.exception || {};
707
- event.exception.values = event.exception.values || [];
708
- event.exception.values[0] = event.exception.values[0] || {};
709
- event.exception.values[0].value = event.exception.values[0].value || value || '';
710
- event.exception.values[0].type = event.exception.values[0].type || type || 'Error';
711
- }
712
- /**
713
- * Adds exception mechanism to a given event.
714
- * @param event The event to modify.
715
- * @param mechanism Mechanism of the mechanism.
716
- * @hidden
717
- */
718
- function addExceptionMechanism(event, mechanism = {}) {
719
- // TODO: Use real type with `keyof Mechanism` thingy and maybe make it better?
720
- try {
721
- // @ts-ignore Type 'Mechanism | {}' is not assignable to type 'Mechanism | undefined'
722
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
723
- event.exception.values[0].mechanism = event.exception.values[0].mechanism || {};
724
- Object.keys(mechanism).forEach(key => {
725
- // @ts-ignore Mechanism has no index signature
726
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
727
- event.exception.values[0].mechanism[key] = mechanism[key];
728
- });
729
- }
730
- catch (_oO) {
731
- // no-empty
732
- }
733
- }
734
- /**
735
- * A safe form of location.href
736
- */
737
- function getLocationHref() {
738
- try {
739
- return document.location.href;
740
- }
741
- catch (oO) {
742
- return '';
743
- }
744
- }
745
- const defaultRetryAfter = 60 * 1000; // 60 seconds
746
- /**
747
- * Extracts Retry-After value from the request header or returns default value
748
- * @param now current unix timestamp
749
- * @param header string representation of 'Retry-After' header
750
- */
751
- function parseRetryAfterHeader(now, header) {
752
- if (!header) {
753
- return defaultRetryAfter;
754
- }
755
- const headerDelay = parseInt(`${header}`, 10);
756
- if (!isNaN(headerDelay)) {
757
- return headerDelay * 1000;
758
- }
759
- const headerDate = Date.parse(`${header}`);
760
- if (!isNaN(headerDate)) {
761
- return headerDate - now;
762
- }
763
- return defaultRetryAfter;
764
- }
765
-
766
- /* eslint-disable @typescript-eslint/no-explicit-any */
767
- // TODO: Implement different loggers for different environments
768
- const global$1 = getGlobalObject();
769
- /** Prefix for logging strings */
770
- const PREFIX = 'Sentry Logger ';
771
609
  /** JSDoc */
772
610
  class Logger {
773
611
  /** JSDoc */
@@ -884,6 +722,61 @@ var Sentry = (function (exports) {
884
722
  }
885
723
  }
886
724
 
725
+ /**
726
+ * Truncates given string to the maximum characters count
727
+ *
728
+ * @param str An object that contains serializable values
729
+ * @param max Maximum number of characters in truncated string (0 = unlimited)
730
+ * @returns string Encoded
731
+ */
732
+ function truncate(str, max = 0) {
733
+ if (typeof str !== 'string' || max === 0) {
734
+ return str;
735
+ }
736
+ return str.length <= max ? str : `${str.substr(0, max)}...`;
737
+ }
738
+ /**
739
+ * Join values in array
740
+ * @param input array of values to be joined together
741
+ * @param delimiter string to be placed in-between values
742
+ * @returns Joined values
743
+ */
744
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
745
+ function safeJoin(input, delimiter) {
746
+ if (!Array.isArray(input)) {
747
+ return '';
748
+ }
749
+ const output = [];
750
+ // eslint-disable-next-line @typescript-eslint/prefer-for-of
751
+ for (let i = 0; i < input.length; i++) {
752
+ const value = input[i];
753
+ try {
754
+ output.push(String(value));
755
+ }
756
+ catch (e) {
757
+ output.push('[value cannot be serialized]');
758
+ }
759
+ }
760
+ return output.join(delimiter);
761
+ }
762
+ /**
763
+ * Checks if the value matches a regex or includes the string
764
+ * @param value The string value to be checked against
765
+ * @param pattern Either a regex or a string that must be contained in value
766
+ */
767
+ function isMatchingPattern(value, pattern) {
768
+ if (!isString(value)) {
769
+ return false;
770
+ }
771
+ if (isRegExp(pattern)) {
772
+ return pattern.test(value);
773
+ }
774
+ if (typeof pattern === 'string') {
775
+ return value.indexOf(pattern) !== -1;
776
+ }
777
+ return false;
778
+ }
779
+
887
780
  /**
888
781
  * Replace a method in an object with a wrapped version of itself.
889
782
  *
@@ -1051,9 +944,13 @@ var Sentry = (function (exports) {
1051
944
  if (typeof global !== 'undefined' && value === global) {
1052
945
  return '[Global]';
1053
946
  }
947
+ // It's safe to use `window` and `document` here in this manner, as we are asserting using `typeof` first
948
+ // which won't throw if they are not present.
949
+ // eslint-disable-next-line no-restricted-globals
1054
950
  if (typeof window !== 'undefined' && value === window) {
1055
951
  return '[Window]';
1056
952
  }
953
+ // eslint-disable-next-line no-restricted-globals
1057
954
  if (typeof document !== 'undefined' && value === document) {
1058
955
  return '[Document]';
1059
956
  }
@@ -1783,18 +1680,191 @@ var Sentry = (function (exports) {
1783
1680
  return false;
1784
1681
  };
1785
1682
  }
1786
- let _oldOnUnhandledRejectionHandler = null;
1787
- /** JSDoc */
1788
- function instrumentUnhandledRejection() {
1789
- _oldOnUnhandledRejectionHandler = global$2.onunhandledrejection;
1790
- global$2.onunhandledrejection = function (e) {
1791
- triggerHandlers('unhandledrejection', e);
1792
- if (_oldOnUnhandledRejectionHandler) {
1793
- // eslint-disable-next-line prefer-rest-params
1794
- return _oldOnUnhandledRejectionHandler.apply(this, arguments);
1683
+ let _oldOnUnhandledRejectionHandler = null;
1684
+ /** JSDoc */
1685
+ function instrumentUnhandledRejection() {
1686
+ _oldOnUnhandledRejectionHandler = global$2.onunhandledrejection;
1687
+ global$2.onunhandledrejection = function (e) {
1688
+ triggerHandlers('unhandledrejection', e);
1689
+ if (_oldOnUnhandledRejectionHandler) {
1690
+ // eslint-disable-next-line prefer-rest-params
1691
+ return _oldOnUnhandledRejectionHandler.apply(this, arguments);
1692
+ }
1693
+ return true;
1694
+ };
1695
+ }
1696
+
1697
+ /**
1698
+ * UUID4 generator
1699
+ *
1700
+ * @returns string Generated UUID4.
1701
+ */
1702
+ function uuid4() {
1703
+ const global = getGlobalObject();
1704
+ const crypto = global.crypto || global.msCrypto;
1705
+ if (!(crypto === void 0) && crypto.getRandomValues) {
1706
+ // Use window.crypto API if available
1707
+ const arr = new Uint16Array(8);
1708
+ crypto.getRandomValues(arr);
1709
+ // set 4 in byte 7
1710
+ // eslint-disable-next-line no-bitwise
1711
+ arr[3] = (arr[3] & 0xfff) | 0x4000;
1712
+ // set 2 most significant bits of byte 9 to '10'
1713
+ // eslint-disable-next-line no-bitwise
1714
+ arr[4] = (arr[4] & 0x3fff) | 0x8000;
1715
+ const pad = (num) => {
1716
+ let v = num.toString(16);
1717
+ while (v.length < 4) {
1718
+ v = `0${v}`;
1719
+ }
1720
+ return v;
1721
+ };
1722
+ return (pad(arr[0]) + pad(arr[1]) + pad(arr[2]) + pad(arr[3]) + pad(arr[4]) + pad(arr[5]) + pad(arr[6]) + pad(arr[7]));
1723
+ }
1724
+ // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#2117523
1725
+ return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, c => {
1726
+ // eslint-disable-next-line no-bitwise
1727
+ const r = (Math.random() * 16) | 0;
1728
+ // eslint-disable-next-line no-bitwise
1729
+ const v = c === 'x' ? r : (r & 0x3) | 0x8;
1730
+ return v.toString(16);
1731
+ });
1732
+ }
1733
+ /**
1734
+ * Parses string form of URL into an object
1735
+ * // borrowed from https://tools.ietf.org/html/rfc3986#appendix-B
1736
+ * // intentionally using regex and not <a/> href parsing trick because React Native and other
1737
+ * // environments where DOM might not be available
1738
+ * @returns parsed URL object
1739
+ */
1740
+ function parseUrl(url) {
1741
+ if (!url) {
1742
+ return {};
1743
+ }
1744
+ const match = url.match(/^(([^:/?#]+):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/);
1745
+ if (!match) {
1746
+ return {};
1747
+ }
1748
+ // coerce to undefined values to empty string so we don't get 'undefined'
1749
+ const query = match[6] || '';
1750
+ const fragment = match[8] || '';
1751
+ return {
1752
+ host: match[4],
1753
+ path: match[5],
1754
+ protocol: match[2],
1755
+ relative: match[5] + query + fragment,
1756
+ };
1757
+ }
1758
+ /**
1759
+ * Extracts either message or type+value from an event that can be used for user-facing logs
1760
+ * @returns event's description
1761
+ */
1762
+ function getEventDescription(event) {
1763
+ if (event.message) {
1764
+ return event.message;
1765
+ }
1766
+ if (event.exception && event.exception.values && event.exception.values[0]) {
1767
+ const exception = event.exception.values[0];
1768
+ if (exception.type && exception.value) {
1769
+ return `${exception.type}: ${exception.value}`;
1795
1770
  }
1771
+ return exception.type || exception.value || event.event_id || '<unknown>';
1772
+ }
1773
+ return event.event_id || '<unknown>';
1774
+ }
1775
+ /**
1776
+ * Adds exception values, type and value to an synthetic Exception.
1777
+ * @param event The event to modify.
1778
+ * @param value Value of the exception.
1779
+ * @param type Type of the exception.
1780
+ * @hidden
1781
+ */
1782
+ function addExceptionTypeValue(event, value, type) {
1783
+ event.exception = event.exception || {};
1784
+ event.exception.values = event.exception.values || [];
1785
+ event.exception.values[0] = event.exception.values[0] || {};
1786
+ event.exception.values[0].value = event.exception.values[0].value || value || '';
1787
+ event.exception.values[0].type = event.exception.values[0].type || type || 'Error';
1788
+ }
1789
+ /**
1790
+ * Adds exception mechanism data to a given event. Uses defaults if the second parameter is not passed.
1791
+ *
1792
+ * @param event The event to modify.
1793
+ * @param newMechanism Mechanism data to add to the event.
1794
+ * @hidden
1795
+ */
1796
+ function addExceptionMechanism(event, newMechanism) {
1797
+ var _a;
1798
+ if (!event.exception || !event.exception.values) {
1799
+ return;
1800
+ }
1801
+ const exceptionValue0 = event.exception.values[0];
1802
+ const defaultMechanism = { type: 'generic', handled: true };
1803
+ const currentMechanism = exceptionValue0.mechanism;
1804
+ exceptionValue0.mechanism = Object.assign(Object.assign(Object.assign({}, defaultMechanism), currentMechanism), newMechanism);
1805
+ if (newMechanism && 'data' in newMechanism) {
1806
+ const mergedData = Object.assign(Object.assign({}, (_a = currentMechanism) === null || _a === void 0 ? void 0 : _a.data), newMechanism.data);
1807
+ exceptionValue0.mechanism.data = mergedData;
1808
+ }
1809
+ }
1810
+ const defaultRetryAfter = 60 * 1000; // 60 seconds
1811
+ /**
1812
+ * Extracts Retry-After value from the request header or returns default value
1813
+ * @param now current unix timestamp
1814
+ * @param header string representation of 'Retry-After' header
1815
+ */
1816
+ function parseRetryAfterHeader(now, header) {
1817
+ if (!header) {
1818
+ return defaultRetryAfter;
1819
+ }
1820
+ const headerDelay = parseInt(`${header}`, 10);
1821
+ if (!isNaN(headerDelay)) {
1822
+ return headerDelay * 1000;
1823
+ }
1824
+ const headerDate = Date.parse(`${header}`);
1825
+ if (!isNaN(headerDate)) {
1826
+ return headerDate - now;
1827
+ }
1828
+ return defaultRetryAfter;
1829
+ }
1830
+ /**
1831
+ * Checks whether or not we've already captured the given exception (note: not an identical exception - the very object
1832
+ * in question), and marks it captured if not.
1833
+ *
1834
+ * This is useful because it's possible for an error to get captured by more than one mechanism. After we intercept and
1835
+ * record an error, we rethrow it (assuming we've intercepted it before it's reached the top-level global handlers), so
1836
+ * that we don't interfere with whatever effects the error might have had were the SDK not there. At that point, because
1837
+ * the error has been rethrown, it's possible for it to bubble up to some other code we've instrumented. If it's not
1838
+ * caught after that, it will bubble all the way up to the global handlers (which of course we also instrument). This
1839
+ * function helps us ensure that even if we encounter the same error more than once, we only record it the first time we
1840
+ * see it.
1841
+ *
1842
+ * Note: It will ignore primitives (always return `false` and not mark them as seen), as properties can't be set on
1843
+ * them. {@link: Object.objectify} can be used on exceptions to convert any that are primitives into their equivalent
1844
+ * object wrapper forms so that this check will always work. However, because we need to flag the exact object which
1845
+ * will get rethrown, and because that rethrowing happens outside of the event processing pipeline, the objectification
1846
+ * must be done before the exception captured.
1847
+ *
1848
+ * @param A thrown exception to check or flag as having been seen
1849
+ * @returns `true` if the exception has already been captured, `false` if not (with the side effect of marking it seen)
1850
+ */
1851
+ function checkOrSetAlreadyCaught(exception) {
1852
+ var _a;
1853
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
1854
+ if ((_a = exception) === null || _a === void 0 ? void 0 : _a.__sentry_captured__) {
1796
1855
  return true;
1797
- };
1856
+ }
1857
+ try {
1858
+ // set it this way rather than by assignment so that it's not ennumerable and therefore isn't recorded by the
1859
+ // `ExtraErrorData` integration
1860
+ Object.defineProperty(exception, '__sentry_captured__', {
1861
+ value: true,
1862
+ });
1863
+ }
1864
+ catch (err) {
1865
+ // `exception` is a primitive, so we can't mark it seen
1866
+ }
1867
+ return false;
1798
1868
  }
1799
1869
 
1800
1870
  /* eslint-disable @typescript-eslint/explicit-function-return-type */
@@ -3602,6 +3672,7 @@ var Sentry = (function (exports) {
3602
3672
  }
3603
3673
 
3604
3674
  /* eslint-disable max-lines */
3675
+ const ALREADY_SEEN_ERROR = "Not capturing exception because it's already been captured.";
3605
3676
  /**
3606
3677
  * Base implementation for all JavaScript SDK clients.
3607
3678
  *
@@ -3657,6 +3728,11 @@ var Sentry = (function (exports) {
3657
3728
  */
3658
3729
  // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
3659
3730
  captureException(exception, hint, scope) {
3731
+ // ensure we haven't captured this very object before
3732
+ if (checkOrSetAlreadyCaught(exception)) {
3733
+ logger.log(ALREADY_SEEN_ERROR);
3734
+ return;
3735
+ }
3660
3736
  let eventId = hint && hint.event_id;
3661
3737
  this._process(this._getBackend()
3662
3738
  .eventFromException(exception, hint)
@@ -3685,6 +3761,12 @@ var Sentry = (function (exports) {
3685
3761
  * @inheritDoc
3686
3762
  */
3687
3763
  captureEvent(event, hint, scope) {
3764
+ var _a;
3765
+ // ensure we haven't captured this very object before
3766
+ if (((_a = hint) === null || _a === void 0 ? void 0 : _a.originalException) && checkOrSetAlreadyCaught(hint.originalException)) {
3767
+ logger.log(ALREADY_SEEN_ERROR);
3768
+ return;
3769
+ }
3688
3770
  let eventId = hint && hint.event_id;
3689
3771
  this._process(this._captureEvent(event, hint, scope).then(result => {
3690
3772
  eventId = result;
@@ -4280,7 +4362,7 @@ var Sentry = (function (exports) {
4280
4362
  hub.bindClient(client);
4281
4363
  }
4282
4364
 
4283
- const SDK_VERSION = '6.13.0';
4365
+ const SDK_VERSION = '6.14.0';
4284
4366
 
4285
4367
  let originalFunctionToString;
4286
4368
  /** Patch toString calls to return proper name for wrapped functions */
@@ -4851,10 +4933,7 @@ var Sentry = (function (exports) {
4851
4933
  const event = eventFromUnknownInput(exception, syntheticException, {
4852
4934
  attachStacktrace: options.attachStacktrace,
4853
4935
  });
4854
- addExceptionMechanism(event, {
4855
- handled: true,
4856
- type: 'generic',
4857
- });
4936
+ addExceptionMechanism(event); // defaults to { type: 'generic', handled: true }
4858
4937
  event.level = exports.Severity.Error;
4859
4938
  if (hint && hint.event_id) {
4860
4939
  event.event_id = hint.event_id;
@@ -4953,12 +5032,108 @@ var Sentry = (function (exports) {
4953
5032
  return event;
4954
5033
  }
4955
5034
 
5035
+ const global$3 = getGlobalObject();
5036
+ let cachedFetchImpl;
5037
+ /**
5038
+ * A special usecase for incorrectly wrapped Fetch APIs in conjunction with ad-blockers.
5039
+ * Whenever someone wraps the Fetch API and returns the wrong promise chain,
5040
+ * this chain becomes orphaned and there is no possible way to capture it's rejections
5041
+ * other than allowing it bubble up to this very handler. eg.
5042
+ *
5043
+ * const f = window.fetch;
5044
+ * window.fetch = function () {
5045
+ * const p = f.apply(this, arguments);
5046
+ *
5047
+ * p.then(function() {
5048
+ * console.log('hi.');
5049
+ * });
5050
+ *
5051
+ * return p;
5052
+ * }
5053
+ *
5054
+ * `p.then(function () { ... })` is producing a completely separate promise chain,
5055
+ * however, what's returned is `p` - the result of original `fetch` call.
5056
+ *
5057
+ * This mean, that whenever we use the Fetch API to send our own requests, _and_
5058
+ * some ad-blocker blocks it, this orphaned chain will _always_ reject,
5059
+ * effectively causing another event to be captured.
5060
+ * This makes a whole process become an infinite loop, which we need to somehow
5061
+ * deal with, and break it in one way or another.
5062
+ *
5063
+ * To deal with this issue, we are making sure that we _always_ use the real
5064
+ * browser Fetch API, instead of relying on what `window.fetch` exposes.
5065
+ * The only downside to this would be missing our own requests as breadcrumbs,
5066
+ * but because we are already not doing this, it should be just fine.
5067
+ *
5068
+ * Possible failed fetch error messages per-browser:
5069
+ *
5070
+ * Chrome: Failed to fetch
5071
+ * Edge: Failed to Fetch
5072
+ * Firefox: NetworkError when attempting to fetch resource
5073
+ * Safari: resource blocked by content blocker
5074
+ */
5075
+ function getNativeFetchImplementation() {
5076
+ var _a, _b;
5077
+ if (cachedFetchImpl) {
5078
+ return cachedFetchImpl;
5079
+ }
5080
+ /* eslint-disable @typescript-eslint/unbound-method */
5081
+ // Fast path to avoid DOM I/O
5082
+ if (isNativeFetch(global$3.fetch)) {
5083
+ return (cachedFetchImpl = global$3.fetch.bind(global$3));
5084
+ }
5085
+ const document = global$3.document;
5086
+ let fetchImpl = global$3.fetch;
5087
+ // eslint-disable-next-line deprecation/deprecation
5088
+ if (typeof ((_a = document) === null || _a === void 0 ? void 0 : _a.createElement) === `function`) {
5089
+ try {
5090
+ const sandbox = document.createElement('iframe');
5091
+ sandbox.hidden = true;
5092
+ document.head.appendChild(sandbox);
5093
+ if ((_b = sandbox.contentWindow) === null || _b === void 0 ? void 0 : _b.fetch) {
5094
+ fetchImpl = sandbox.contentWindow.fetch;
5095
+ }
5096
+ document.head.removeChild(sandbox);
5097
+ }
5098
+ catch (e) {
5099
+ logger.warn('Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ', e);
5100
+ }
5101
+ }
5102
+ return (cachedFetchImpl = fetchImpl.bind(global$3));
5103
+ /* eslint-enable @typescript-eslint/unbound-method */
5104
+ }
5105
+ /**
5106
+ * Sends sdk client report using sendBeacon or fetch as a fallback if available
5107
+ *
5108
+ * @param url report endpoint
5109
+ * @param body report payload
5110
+ */
5111
+ function sendReport(url, body) {
5112
+ const isRealNavigator = Object.prototype.toString.call(global$3 && global$3.navigator) === '[object Navigator]';
5113
+ const hasSendBeacon = isRealNavigator && typeof global$3.navigator.sendBeacon === 'function';
5114
+ if (hasSendBeacon) {
5115
+ // Prevent illegal invocations - https://xgwang.me/posts/you-may-not-know-beacon/#it-may-throw-error%2C-be-sure-to-catch
5116
+ const sendBeacon = global$3.navigator.sendBeacon.bind(global$3.navigator);
5117
+ return sendBeacon(url, body);
5118
+ }
5119
+ if (supportsFetch()) {
5120
+ const fetch = getNativeFetchImplementation();
5121
+ return forget(fetch(url, {
5122
+ body,
5123
+ method: 'POST',
5124
+ credentials: 'omit',
5125
+ keepalive: true,
5126
+ }));
5127
+ }
5128
+ }
5129
+
4956
5130
  const CATEGORY_MAPPING = {
4957
5131
  event: 'error',
4958
5132
  transaction: 'transaction',
4959
5133
  session: 'session',
4960
5134
  attachment: 'attachment',
4961
5135
  };
5136
+ const global$4 = getGlobalObject();
4962
5137
  /** Base Transport class implementation */
4963
5138
  class BaseTransport {
4964
5139
  constructor(options) {
@@ -4971,9 +5146,9 @@ var Sentry = (function (exports) {
4971
5146
  this._api = new API(options.dsn, options._metadata, options.tunnel);
4972
5147
  // eslint-disable-next-line deprecation/deprecation
4973
5148
  this.url = this._api.getStoreEndpointWithUrlEncodedAuth();
4974
- if (this.options.sendClientReports) {
4975
- document.addEventListener('visibilitychange', () => {
4976
- if (document.visibilityState === 'hidden') {
5149
+ if (this.options.sendClientReports && global$4.document) {
5150
+ global$4.document.addEventListener('visibilitychange', () => {
5151
+ if (global$4.document.visibilityState === 'hidden') {
4977
5152
  this._flushOutcomes();
4978
5153
  }
4979
5154
  });
@@ -5015,10 +5190,6 @@ var Sentry = (function (exports) {
5015
5190
  if (!this.options.sendClientReports) {
5016
5191
  return;
5017
5192
  }
5018
- if (!navigator || typeof navigator.sendBeacon !== 'function') {
5019
- logger.warn('Beacon API not available, skipping sending outcomes.');
5020
- return;
5021
- }
5022
5193
  const outcomes = this._outcomes;
5023
5194
  this._outcomes = {};
5024
5195
  // Nothing to send
@@ -5029,7 +5200,7 @@ var Sentry = (function (exports) {
5029
5200
  logger.log(`Flushing outcomes:\n${JSON.stringify(outcomes, null, 2)}`);
5030
5201
  const url = this._api.getEnvelopeEndpointWithUrlEncodedAuth();
5031
5202
  // Envelope header is required to be at least an empty object
5032
- const envelopeHeader = JSON.stringify({});
5203
+ const envelopeHeader = JSON.stringify(Object.assign({}, (this.options.tunnel && { dsn: this._api.getDsn().toString() })));
5033
5204
  const itemHeaders = JSON.stringify({
5034
5205
  type: 'client_report',
5035
5206
  });
@@ -5045,7 +5216,12 @@ var Sentry = (function (exports) {
5045
5216
  }),
5046
5217
  });
5047
5218
  const envelope = `${envelopeHeader}\n${itemHeaders}\n${item}`;
5048
- navigator.sendBeacon(url, envelope);
5219
+ try {
5220
+ sendReport(url, envelope);
5221
+ }
5222
+ catch (e) {
5223
+ logger.error(e);
5224
+ }
5049
5225
  }
5050
5226
  /**
5051
5227
  * Handle Sentry repsonse for promise-based transports.
@@ -5114,72 +5290,6 @@ var Sentry = (function (exports) {
5114
5290
  }
5115
5291
  }
5116
5292
 
5117
- /**
5118
- * A special usecase for incorrectly wrapped Fetch APIs in conjunction with ad-blockers.
5119
- * Whenever someone wraps the Fetch API and returns the wrong promise chain,
5120
- * this chain becomes orphaned and there is no possible way to capture it's rejections
5121
- * other than allowing it bubble up to this very handler. eg.
5122
- *
5123
- * const f = window.fetch;
5124
- * window.fetch = function () {
5125
- * const p = f.apply(this, arguments);
5126
- *
5127
- * p.then(function() {
5128
- * console.log('hi.');
5129
- * });
5130
- *
5131
- * return p;
5132
- * }
5133
- *
5134
- * `p.then(function () { ... })` is producing a completely separate promise chain,
5135
- * however, what's returned is `p` - the result of original `fetch` call.
5136
- *
5137
- * This mean, that whenever we use the Fetch API to send our own requests, _and_
5138
- * some ad-blocker blocks it, this orphaned chain will _always_ reject,
5139
- * effectively causing another event to be captured.
5140
- * This makes a whole process become an infinite loop, which we need to somehow
5141
- * deal with, and break it in one way or another.
5142
- *
5143
- * To deal with this issue, we are making sure that we _always_ use the real
5144
- * browser Fetch API, instead of relying on what `window.fetch` exposes.
5145
- * The only downside to this would be missing our own requests as breadcrumbs,
5146
- * but because we are already not doing this, it should be just fine.
5147
- *
5148
- * Possible failed fetch error messages per-browser:
5149
- *
5150
- * Chrome: Failed to fetch
5151
- * Edge: Failed to Fetch
5152
- * Firefox: NetworkError when attempting to fetch resource
5153
- * Safari: resource blocked by content blocker
5154
- */
5155
- function getNativeFetchImplementation() {
5156
- /* eslint-disable @typescript-eslint/unbound-method */
5157
- var _a, _b;
5158
- // Fast path to avoid DOM I/O
5159
- const global = getGlobalObject();
5160
- if (isNativeFetch(global.fetch)) {
5161
- return global.fetch.bind(global);
5162
- }
5163
- const document = global.document;
5164
- let fetchImpl = global.fetch;
5165
- // eslint-disable-next-line deprecation/deprecation
5166
- if (typeof ((_a = document) === null || _a === void 0 ? void 0 : _a.createElement) === `function`) {
5167
- try {
5168
- const sandbox = document.createElement('iframe');
5169
- sandbox.hidden = true;
5170
- document.head.appendChild(sandbox);
5171
- if ((_b = sandbox.contentWindow) === null || _b === void 0 ? void 0 : _b.fetch) {
5172
- fetchImpl = sandbox.contentWindow.fetch;
5173
- }
5174
- document.head.removeChild(sandbox);
5175
- }
5176
- catch (e) {
5177
- logger.warn('Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ', e);
5178
- }
5179
- }
5180
- return fetchImpl.bind(global);
5181
- /* eslint-enable @typescript-eslint/unbound-method */
5182
- }
5183
5293
  /** `fetch` based transport */
5184
5294
  class FetchTransport extends BaseTransport {
5185
5295
  constructor(options, fetchImpl = getNativeFetchImplementation()) {
@@ -5364,6 +5474,7 @@ var Sentry = (function (exports) {
5364
5474
  }
5365
5475
  }
5366
5476
 
5477
+ const global$5 = getGlobalObject();
5367
5478
  let ignoreOnError = 0;
5368
5479
  /**
5369
5480
  * @hidden
@@ -5499,6 +5610,9 @@ var Sentry = (function (exports) {
5499
5610
  * @hidden
5500
5611
  */
5501
5612
  function injectReportDialog(options = {}) {
5613
+ if (!global$5.document) {
5614
+ return;
5615
+ }
5502
5616
  if (!options.eventId) {
5503
5617
  logger.error(`Missing eventId option in showReportDialog call`);
5504
5618
  return;
@@ -5507,14 +5621,14 @@ var Sentry = (function (exports) {
5507
5621
  logger.error(`Missing dsn option in showReportDialog call`);
5508
5622
  return;
5509
5623
  }
5510
- const script = document.createElement('script');
5624
+ const script = global$5.document.createElement('script');
5511
5625
  script.async = true;
5512
5626
  script.src = new API(options.dsn).getReportDialogEndpoint(options);
5513
5627
  if (options.onLoad) {
5514
5628
  // eslint-disable-next-line @typescript-eslint/unbound-method
5515
5629
  script.onload = options.onLoad;
5516
5630
  }
5517
- const injectionPoint = document.head || document.body;
5631
+ const injectionPoint = global$5.document.head || global$5.document.body;
5518
5632
  if (injectionPoint) {
5519
5633
  injectionPoint.appendChild(script);
5520
5634
  }
@@ -6224,7 +6338,7 @@ var Sentry = (function (exports) {
6224
6338
  */
6225
6339
  LinkedErrors.id = 'LinkedErrors';
6226
6340
 
6227
- const global$3 = getGlobalObject();
6341
+ const global$6 = getGlobalObject();
6228
6342
  /** UserAgent */
6229
6343
  class UserAgent {
6230
6344
  constructor() {
@@ -6241,13 +6355,13 @@ var Sentry = (function (exports) {
6241
6355
  var _a, _b, _c;
6242
6356
  if (getCurrentHub().getIntegration(UserAgent)) {
6243
6357
  // if none of the information we want exists, don't bother
6244
- if (!global$3.navigator && !global$3.location && !global$3.document) {
6358
+ if (!global$6.navigator && !global$6.location && !global$6.document) {
6245
6359
  return event;
6246
6360
  }
6247
6361
  // grab as much info as exists and add it to the event
6248
- const url = ((_a = event.request) === null || _a === void 0 ? void 0 : _a.url) || ((_b = global$3.location) === null || _b === void 0 ? void 0 : _b.href);
6249
- const { referrer } = global$3.document || {};
6250
- const { userAgent } = global$3.navigator || {};
6362
+ const url = ((_a = event.request) === null || _a === void 0 ? void 0 : _a.url) || ((_b = global$6.location) === null || _b === void 0 ? void 0 : _b.href);
6363
+ const { referrer } = global$6.document || {};
6364
+ const { userAgent } = global$6.navigator || {};
6251
6365
  const headers = Object.assign(Object.assign(Object.assign({}, (_c = event.request) === null || _c === void 0 ? void 0 : _c.headers), (referrer && { Referer: referrer })), (userAgent && { 'User-Agent': userAgent }));
6252
6366
  const request = Object.assign(Object.assign({}, (url && { url })), { headers });
6253
6367
  return Object.assign(Object.assign({}, event), { request });