@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
package/build/bundle.js CHANGED
@@ -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
  /*! *****************************************************************************
4
4
  Copyright (c) Microsoft Corporation. All rights reserved.
@@ -228,6 +228,62 @@ var Sentry = (function (exports) {
228
228
  Outcome["SampleRate"] = "sample_rate";
229
229
  })(Outcome || (Outcome = {}));
230
230
 
231
+ /**
232
+ * Consumes the promise and logs the error when it rejects.
233
+ * @param promise A promise to forget.
234
+ */
235
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
236
+ function forget(promise) {
237
+ void promise.then(null, function (e) {
238
+ // TODO: Use a better logging mechanism
239
+ // eslint-disable-next-line no-console
240
+ console.error(e);
241
+ });
242
+ }
243
+
244
+ /**
245
+ * NOTE: In order to avoid circular dependencies, if you add a function to this module and it needs to print something,
246
+ * you must either a) use `console.log` rather than the logger, or b) put your function elsewhere.
247
+ */
248
+ /**
249
+ * Checks whether we're in the Node.js or Browser environment
250
+ *
251
+ * @returns Answer to given question
252
+ */
253
+ function isNodeEnv() {
254
+ return Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
255
+ }
256
+ /**
257
+ * Requires a module which is protected against bundler minification.
258
+ *
259
+ * @param request The module path to resolve
260
+ */
261
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
262
+ function dynamicRequire(mod, request) {
263
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
264
+ return mod.require(request);
265
+ }
266
+
267
+ /**
268
+ * NOTE: In order to avoid circular dependencies, if you add a function to this module and it needs to print something,
269
+ * you must either a) use `console.log` rather than the logger, or b) put your function elsewhere.
270
+ */
271
+ var fallbackGlobalObject = {};
272
+ /**
273
+ * Safely get global scope object
274
+ *
275
+ * @returns Global scope object
276
+ */
277
+ function getGlobalObject() {
278
+ return (isNodeEnv()
279
+ ? global
280
+ : typeof window !== 'undefined' // eslint-disable-line no-restricted-globals
281
+ ? window // eslint-disable-line no-restricted-globals
282
+ : typeof self !== 'undefined'
283
+ ? self
284
+ : fallbackGlobalObject);
285
+ }
286
+
231
287
  /* eslint-disable @typescript-eslint/no-explicit-any */
232
288
  /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
233
289
  /**
@@ -463,6 +519,18 @@ var Sentry = (function (exports) {
463
519
  }
464
520
  }
465
521
  return out.join('');
522
+ }
523
+ /**
524
+ * A safe form of location.href
525
+ */
526
+ function getLocationHref() {
527
+ var global = getGlobalObject();
528
+ try {
529
+ return global.document.location.href;
530
+ }
531
+ catch (oO) {
532
+ return '';
533
+ }
466
534
  }
467
535
 
468
536
  var setPrototypeOf = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array ? setProtoOf : mixinProperties);
@@ -593,175 +661,17 @@ var Sentry = (function (exports) {
593
661
  return Dsn;
594
662
  }());
595
663
 
664
+ // TODO: Implement different loggers for different environments
665
+ var global$1 = getGlobalObject();
666
+ /** Prefix for logging strings */
667
+ var PREFIX = 'Sentry Logger ';
596
668
  /**
597
- * Checks whether we're in the Node.js or Browser environment
598
- *
599
- * @returns Answer to given question
600
- */
601
- function isNodeEnv() {
602
- return Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
603
- }
604
- /**
605
- * Requires a module which is protected against bundler minification.
606
- *
607
- * @param request The module path to resolve
608
- */
609
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
610
- function dynamicRequire(mod, request) {
611
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
612
- return mod.require(request);
613
- }
614
-
615
- /**
616
- * Truncates given string to the maximum characters count
617
- *
618
- * @param str An object that contains serializable values
619
- * @param max Maximum number of characters in truncated string (0 = unlimited)
620
- * @returns string Encoded
621
- */
622
- function truncate(str, max) {
623
- if (max === void 0) { max = 0; }
624
- if (typeof str !== 'string' || max === 0) {
625
- return str;
626
- }
627
- return str.length <= max ? str : str.substr(0, max) + "...";
628
- }
629
- /**
630
- * Join values in array
631
- * @param input array of values to be joined together
632
- * @param delimiter string to be placed in-between values
633
- * @returns Joined values
634
- */
635
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
636
- function safeJoin(input, delimiter) {
637
- if (!Array.isArray(input)) {
638
- return '';
639
- }
640
- var output = [];
641
- // eslint-disable-next-line @typescript-eslint/prefer-for-of
642
- for (var i = 0; i < input.length; i++) {
643
- var value = input[i];
644
- try {
645
- output.push(String(value));
646
- }
647
- catch (e) {
648
- output.push('[value cannot be serialized]');
649
- }
650
- }
651
- return output.join(delimiter);
652
- }
653
- /**
654
- * Checks if the value matches a regex or includes the string
655
- * @param value The string value to be checked against
656
- * @param pattern Either a regex or a string that must be contained in value
657
- */
658
- function isMatchingPattern(value, pattern) {
659
- if (!isString(value)) {
660
- return false;
661
- }
662
- if (isRegExp(pattern)) {
663
- return pattern.test(value);
664
- }
665
- if (typeof pattern === 'string') {
666
- return value.indexOf(pattern) !== -1;
667
- }
668
- return false;
669
- }
670
-
671
- var fallbackGlobalObject = {};
672
- /**
673
- * Safely get global scope object
674
- *
675
- * @returns Global scope object
676
- */
677
- function getGlobalObject() {
678
- return (isNodeEnv()
679
- ? global
680
- : typeof window !== 'undefined'
681
- ? window
682
- : typeof self !== 'undefined'
683
- ? self
684
- : fallbackGlobalObject);
685
- }
686
- /**
687
- * UUID4 generator
669
+ * Temporarily unwrap `console.log` and friends in order to perform the given callback using the original methods.
670
+ * Restores wrapping after the callback completes.
688
671
  *
689
- * @returns string Generated UUID4.
690
- */
691
- function uuid4() {
692
- var global = getGlobalObject();
693
- var crypto = global.crypto || global.msCrypto;
694
- if (!(crypto === void 0) && crypto.getRandomValues) {
695
- // Use window.crypto API if available
696
- var arr = new Uint16Array(8);
697
- crypto.getRandomValues(arr);
698
- // set 4 in byte 7
699
- // eslint-disable-next-line no-bitwise
700
- arr[3] = (arr[3] & 0xfff) | 0x4000;
701
- // set 2 most significant bits of byte 9 to '10'
702
- // eslint-disable-next-line no-bitwise
703
- arr[4] = (arr[4] & 0x3fff) | 0x8000;
704
- var pad = function (num) {
705
- var v = num.toString(16);
706
- while (v.length < 4) {
707
- v = "0" + v;
708
- }
709
- return v;
710
- };
711
- 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]));
712
- }
713
- // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#2117523
714
- return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
715
- // eslint-disable-next-line no-bitwise
716
- var r = (Math.random() * 16) | 0;
717
- // eslint-disable-next-line no-bitwise
718
- var v = c === 'x' ? r : (r & 0x3) | 0x8;
719
- return v.toString(16);
720
- });
721
- }
722
- /**
723
- * Parses string form of URL into an object
724
- * // borrowed from https://tools.ietf.org/html/rfc3986#appendix-B
725
- * // intentionally using regex and not <a/> href parsing trick because React Native and other
726
- * // environments where DOM might not be available
727
- * @returns parsed URL object
728
- */
729
- function parseUrl(url) {
730
- if (!url) {
731
- return {};
732
- }
733
- var match = url.match(/^(([^:/?#]+):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/);
734
- if (!match) {
735
- return {};
736
- }
737
- // coerce to undefined values to empty string so we don't get 'undefined'
738
- var query = match[6] || '';
739
- var fragment = match[8] || '';
740
- return {
741
- host: match[4],
742
- path: match[5],
743
- protocol: match[2],
744
- relative: match[5] + query + fragment,
745
- };
746
- }
747
- /**
748
- * Extracts either message or type+value from an event that can be used for user-facing logs
749
- * @returns event's description
672
+ * @param callback The function to run against the original `console` messages
673
+ * @returns The results of the callback
750
674
  */
751
- function getEventDescription(event) {
752
- if (event.message) {
753
- return event.message;
754
- }
755
- if (event.exception && event.exception.values && event.exception.values[0]) {
756
- var exception = event.exception.values[0];
757
- if (exception.type && exception.value) {
758
- return exception.type + ": " + exception.value;
759
- }
760
- return exception.type || exception.value || event.event_id || '<unknown>';
761
- }
762
- return event.event_id || '<unknown>';
763
- }
764
- /** JSDoc */
765
675
  function consoleSandbox(callback) {
766
676
  var global = getGlobalObject();
767
677
  var levels = ['debug', 'info', 'warn', 'error', 'log', 'assert'];
@@ -787,80 +697,6 @@ var Sentry = (function (exports) {
787
697
  });
788
698
  return result;
789
699
  }
790
- /**
791
- * Adds exception values, type and value to an synthetic Exception.
792
- * @param event The event to modify.
793
- * @param value Value of the exception.
794
- * @param type Type of the exception.
795
- * @hidden
796
- */
797
- function addExceptionTypeValue(event, value, type) {
798
- event.exception = event.exception || {};
799
- event.exception.values = event.exception.values || [];
800
- event.exception.values[0] = event.exception.values[0] || {};
801
- event.exception.values[0].value = event.exception.values[0].value || value || '';
802
- event.exception.values[0].type = event.exception.values[0].type || type || 'Error';
803
- }
804
- /**
805
- * Adds exception mechanism to a given event.
806
- * @param event The event to modify.
807
- * @param mechanism Mechanism of the mechanism.
808
- * @hidden
809
- */
810
- function addExceptionMechanism(event, mechanism) {
811
- if (mechanism === void 0) { mechanism = {}; }
812
- // TODO: Use real type with `keyof Mechanism` thingy and maybe make it better?
813
- try {
814
- // @ts-ignore Type 'Mechanism | {}' is not assignable to type 'Mechanism | undefined'
815
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
816
- event.exception.values[0].mechanism = event.exception.values[0].mechanism || {};
817
- Object.keys(mechanism).forEach(function (key) {
818
- // @ts-ignore Mechanism has no index signature
819
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
820
- event.exception.values[0].mechanism[key] = mechanism[key];
821
- });
822
- }
823
- catch (_oO) {
824
- // no-empty
825
- }
826
- }
827
- /**
828
- * A safe form of location.href
829
- */
830
- function getLocationHref() {
831
- try {
832
- return document.location.href;
833
- }
834
- catch (oO) {
835
- return '';
836
- }
837
- }
838
- var defaultRetryAfter = 60 * 1000; // 60 seconds
839
- /**
840
- * Extracts Retry-After value from the request header or returns default value
841
- * @param now current unix timestamp
842
- * @param header string representation of 'Retry-After' header
843
- */
844
- function parseRetryAfterHeader(now, header) {
845
- if (!header) {
846
- return defaultRetryAfter;
847
- }
848
- var headerDelay = parseInt("" + header, 10);
849
- if (!isNaN(headerDelay)) {
850
- return headerDelay * 1000;
851
- }
852
- var headerDate = Date.parse("" + header);
853
- if (!isNaN(headerDate)) {
854
- return headerDate - now;
855
- }
856
- return defaultRetryAfter;
857
- }
858
-
859
- /* eslint-disable @typescript-eslint/no-explicit-any */
860
- // TODO: Implement different loggers for different environments
861
- var global$1 = getGlobalObject();
862
- /** Prefix for logging strings */
863
- var PREFIX = 'Sentry Logger ';
864
700
  /** JSDoc */
865
701
  var Logger = /** @class */ (function () {
866
702
  /** JSDoc */
@@ -991,6 +827,62 @@ var Sentry = (function (exports) {
991
827
  }
992
828
  }
993
829
 
830
+ /**
831
+ * Truncates given string to the maximum characters count
832
+ *
833
+ * @param str An object that contains serializable values
834
+ * @param max Maximum number of characters in truncated string (0 = unlimited)
835
+ * @returns string Encoded
836
+ */
837
+ function truncate(str, max) {
838
+ if (max === void 0) { max = 0; }
839
+ if (typeof str !== 'string' || max === 0) {
840
+ return str;
841
+ }
842
+ return str.length <= max ? str : str.substr(0, max) + "...";
843
+ }
844
+ /**
845
+ * Join values in array
846
+ * @param input array of values to be joined together
847
+ * @param delimiter string to be placed in-between values
848
+ * @returns Joined values
849
+ */
850
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
851
+ function safeJoin(input, delimiter) {
852
+ if (!Array.isArray(input)) {
853
+ return '';
854
+ }
855
+ var output = [];
856
+ // eslint-disable-next-line @typescript-eslint/prefer-for-of
857
+ for (var i = 0; i < input.length; i++) {
858
+ var value = input[i];
859
+ try {
860
+ output.push(String(value));
861
+ }
862
+ catch (e) {
863
+ output.push('[value cannot be serialized]');
864
+ }
865
+ }
866
+ return output.join(delimiter);
867
+ }
868
+ /**
869
+ * Checks if the value matches a regex or includes the string
870
+ * @param value The string value to be checked against
871
+ * @param pattern Either a regex or a string that must be contained in value
872
+ */
873
+ function isMatchingPattern(value, pattern) {
874
+ if (!isString(value)) {
875
+ return false;
876
+ }
877
+ if (isRegExp(pattern)) {
878
+ return pattern.test(value);
879
+ }
880
+ if (typeof pattern === 'string') {
881
+ return value.indexOf(pattern) !== -1;
882
+ }
883
+ return false;
884
+ }
885
+
994
886
  /**
995
887
  * Replace a method in an object with a wrapped version of itself.
996
888
  *
@@ -1160,9 +1052,13 @@ var Sentry = (function (exports) {
1160
1052
  if (typeof global !== 'undefined' && value === global) {
1161
1053
  return '[Global]';
1162
1054
  }
1055
+ // It's safe to use `window` and `document` here in this manner, as we are asserting using `typeof` first
1056
+ // which won't throw if they are not present.
1057
+ // eslint-disable-next-line no-restricted-globals
1163
1058
  if (typeof window !== 'undefined' && value === window) {
1164
1059
  return '[Window]';
1165
1060
  }
1061
+ // eslint-disable-next-line no-restricted-globals
1166
1062
  if (typeof document !== 'undefined' && value === document) {
1167
1063
  return '[Document]';
1168
1064
  }
@@ -1948,18 +1844,191 @@ var Sentry = (function (exports) {
1948
1844
  return false;
1949
1845
  };
1950
1846
  }
1951
- var _oldOnUnhandledRejectionHandler = null;
1952
- /** JSDoc */
1953
- function instrumentUnhandledRejection() {
1954
- _oldOnUnhandledRejectionHandler = global$2.onunhandledrejection;
1955
- global$2.onunhandledrejection = function (e) {
1956
- triggerHandlers('unhandledrejection', e);
1957
- if (_oldOnUnhandledRejectionHandler) {
1958
- // eslint-disable-next-line prefer-rest-params
1959
- return _oldOnUnhandledRejectionHandler.apply(this, arguments);
1847
+ var _oldOnUnhandledRejectionHandler = null;
1848
+ /** JSDoc */
1849
+ function instrumentUnhandledRejection() {
1850
+ _oldOnUnhandledRejectionHandler = global$2.onunhandledrejection;
1851
+ global$2.onunhandledrejection = function (e) {
1852
+ triggerHandlers('unhandledrejection', e);
1853
+ if (_oldOnUnhandledRejectionHandler) {
1854
+ // eslint-disable-next-line prefer-rest-params
1855
+ return _oldOnUnhandledRejectionHandler.apply(this, arguments);
1856
+ }
1857
+ return true;
1858
+ };
1859
+ }
1860
+
1861
+ /**
1862
+ * UUID4 generator
1863
+ *
1864
+ * @returns string Generated UUID4.
1865
+ */
1866
+ function uuid4() {
1867
+ var global = getGlobalObject();
1868
+ var crypto = global.crypto || global.msCrypto;
1869
+ if (!(crypto === void 0) && crypto.getRandomValues) {
1870
+ // Use window.crypto API if available
1871
+ var arr = new Uint16Array(8);
1872
+ crypto.getRandomValues(arr);
1873
+ // set 4 in byte 7
1874
+ // eslint-disable-next-line no-bitwise
1875
+ arr[3] = (arr[3] & 0xfff) | 0x4000;
1876
+ // set 2 most significant bits of byte 9 to '10'
1877
+ // eslint-disable-next-line no-bitwise
1878
+ arr[4] = (arr[4] & 0x3fff) | 0x8000;
1879
+ var pad = function (num) {
1880
+ var v = num.toString(16);
1881
+ while (v.length < 4) {
1882
+ v = "0" + v;
1883
+ }
1884
+ return v;
1885
+ };
1886
+ 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]));
1887
+ }
1888
+ // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#2117523
1889
+ return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
1890
+ // eslint-disable-next-line no-bitwise
1891
+ var r = (Math.random() * 16) | 0;
1892
+ // eslint-disable-next-line no-bitwise
1893
+ var v = c === 'x' ? r : (r & 0x3) | 0x8;
1894
+ return v.toString(16);
1895
+ });
1896
+ }
1897
+ /**
1898
+ * Parses string form of URL into an object
1899
+ * // borrowed from https://tools.ietf.org/html/rfc3986#appendix-B
1900
+ * // intentionally using regex and not <a/> href parsing trick because React Native and other
1901
+ * // environments where DOM might not be available
1902
+ * @returns parsed URL object
1903
+ */
1904
+ function parseUrl(url) {
1905
+ if (!url) {
1906
+ return {};
1907
+ }
1908
+ var match = url.match(/^(([^:/?#]+):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/);
1909
+ if (!match) {
1910
+ return {};
1911
+ }
1912
+ // coerce to undefined values to empty string so we don't get 'undefined'
1913
+ var query = match[6] || '';
1914
+ var fragment = match[8] || '';
1915
+ return {
1916
+ host: match[4],
1917
+ path: match[5],
1918
+ protocol: match[2],
1919
+ relative: match[5] + query + fragment,
1920
+ };
1921
+ }
1922
+ /**
1923
+ * Extracts either message or type+value from an event that can be used for user-facing logs
1924
+ * @returns event's description
1925
+ */
1926
+ function getEventDescription(event) {
1927
+ if (event.message) {
1928
+ return event.message;
1929
+ }
1930
+ if (event.exception && event.exception.values && event.exception.values[0]) {
1931
+ var exception = event.exception.values[0];
1932
+ if (exception.type && exception.value) {
1933
+ return exception.type + ": " + exception.value;
1960
1934
  }
1935
+ return exception.type || exception.value || event.event_id || '<unknown>';
1936
+ }
1937
+ return event.event_id || '<unknown>';
1938
+ }
1939
+ /**
1940
+ * Adds exception values, type and value to an synthetic Exception.
1941
+ * @param event The event to modify.
1942
+ * @param value Value of the exception.
1943
+ * @param type Type of the exception.
1944
+ * @hidden
1945
+ */
1946
+ function addExceptionTypeValue(event, value, type) {
1947
+ event.exception = event.exception || {};
1948
+ event.exception.values = event.exception.values || [];
1949
+ event.exception.values[0] = event.exception.values[0] || {};
1950
+ event.exception.values[0].value = event.exception.values[0].value || value || '';
1951
+ event.exception.values[0].type = event.exception.values[0].type || type || 'Error';
1952
+ }
1953
+ /**
1954
+ * Adds exception mechanism data to a given event. Uses defaults if the second parameter is not passed.
1955
+ *
1956
+ * @param event The event to modify.
1957
+ * @param newMechanism Mechanism data to add to the event.
1958
+ * @hidden
1959
+ */
1960
+ function addExceptionMechanism(event, newMechanism) {
1961
+ var _a;
1962
+ if (!event.exception || !event.exception.values) {
1963
+ return;
1964
+ }
1965
+ var exceptionValue0 = event.exception.values[0];
1966
+ var defaultMechanism = { type: 'generic', handled: true };
1967
+ var currentMechanism = exceptionValue0.mechanism;
1968
+ exceptionValue0.mechanism = __assign(__assign(__assign({}, defaultMechanism), currentMechanism), newMechanism);
1969
+ if (newMechanism && 'data' in newMechanism) {
1970
+ var mergedData = __assign(__assign({}, (_a = currentMechanism) === null || _a === void 0 ? void 0 : _a.data), newMechanism.data);
1971
+ exceptionValue0.mechanism.data = mergedData;
1972
+ }
1973
+ }
1974
+ var defaultRetryAfter = 60 * 1000; // 60 seconds
1975
+ /**
1976
+ * Extracts Retry-After value from the request header or returns default value
1977
+ * @param now current unix timestamp
1978
+ * @param header string representation of 'Retry-After' header
1979
+ */
1980
+ function parseRetryAfterHeader(now, header) {
1981
+ if (!header) {
1982
+ return defaultRetryAfter;
1983
+ }
1984
+ var headerDelay = parseInt("" + header, 10);
1985
+ if (!isNaN(headerDelay)) {
1986
+ return headerDelay * 1000;
1987
+ }
1988
+ var headerDate = Date.parse("" + header);
1989
+ if (!isNaN(headerDate)) {
1990
+ return headerDate - now;
1991
+ }
1992
+ return defaultRetryAfter;
1993
+ }
1994
+ /**
1995
+ * Checks whether or not we've already captured the given exception (note: not an identical exception - the very object
1996
+ * in question), and marks it captured if not.
1997
+ *
1998
+ * This is useful because it's possible for an error to get captured by more than one mechanism. After we intercept and
1999
+ * record an error, we rethrow it (assuming we've intercepted it before it's reached the top-level global handlers), so
2000
+ * that we don't interfere with whatever effects the error might have had were the SDK not there. At that point, because
2001
+ * the error has been rethrown, it's possible for it to bubble up to some other code we've instrumented. If it's not
2002
+ * caught after that, it will bubble all the way up to the global handlers (which of course we also instrument). This
2003
+ * function helps us ensure that even if we encounter the same error more than once, we only record it the first time we
2004
+ * see it.
2005
+ *
2006
+ * Note: It will ignore primitives (always return `false` and not mark them as seen), as properties can't be set on
2007
+ * them. {@link: Object.objectify} can be used on exceptions to convert any that are primitives into their equivalent
2008
+ * object wrapper forms so that this check will always work. However, because we need to flag the exact object which
2009
+ * will get rethrown, and because that rethrowing happens outside of the event processing pipeline, the objectification
2010
+ * must be done before the exception captured.
2011
+ *
2012
+ * @param A thrown exception to check or flag as having been seen
2013
+ * @returns `true` if the exception has already been captured, `false` if not (with the side effect of marking it seen)
2014
+ */
2015
+ function checkOrSetAlreadyCaught(exception) {
2016
+ var _a;
2017
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
2018
+ if ((_a = exception) === null || _a === void 0 ? void 0 : _a.__sentry_captured__) {
1961
2019
  return true;
1962
- };
2020
+ }
2021
+ try {
2022
+ // set it this way rather than by assignment so that it's not ennumerable and therefore isn't recorded by the
2023
+ // `ExtraErrorData` integration
2024
+ Object.defineProperty(exception, '__sentry_captured__', {
2025
+ value: true,
2026
+ });
2027
+ }
2028
+ catch (err) {
2029
+ // `exception` is a primitive, so we can't mark it seen
2030
+ }
2031
+ return false;
1963
2032
  }
1964
2033
 
1965
2034
  /* eslint-disable @typescript-eslint/explicit-function-return-type */
@@ -3801,6 +3870,7 @@ var Sentry = (function (exports) {
3801
3870
  return integrations;
3802
3871
  }
3803
3872
 
3873
+ var ALREADY_SEEN_ERROR = "Not capturing exception because it's already been captured.";
3804
3874
  /**
3805
3875
  * Base implementation for all JavaScript SDK clients.
3806
3876
  *
@@ -3857,6 +3927,11 @@ var Sentry = (function (exports) {
3857
3927
  // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
3858
3928
  BaseClient.prototype.captureException = function (exception, hint, scope) {
3859
3929
  var _this = this;
3930
+ // ensure we haven't captured this very object before
3931
+ if (checkOrSetAlreadyCaught(exception)) {
3932
+ logger.log(ALREADY_SEEN_ERROR);
3933
+ return;
3934
+ }
3860
3935
  var eventId = hint && hint.event_id;
3861
3936
  this._process(this._getBackend()
3862
3937
  .eventFromException(exception, hint)
@@ -3886,6 +3961,12 @@ var Sentry = (function (exports) {
3886
3961
  * @inheritDoc
3887
3962
  */
3888
3963
  BaseClient.prototype.captureEvent = function (event, hint, scope) {
3964
+ var _a;
3965
+ // ensure we haven't captured this very object before
3966
+ if (((_a = hint) === null || _a === void 0 ? void 0 : _a.originalException) && checkOrSetAlreadyCaught(hint.originalException)) {
3967
+ logger.log(ALREADY_SEEN_ERROR);
3968
+ return;
3969
+ }
3889
3970
  var eventId = hint && hint.event_id;
3890
3971
  this._process(this._captureEvent(event, hint, scope).then(function (result) {
3891
3972
  eventId = result;
@@ -4478,7 +4559,7 @@ var Sentry = (function (exports) {
4478
4559
  hub.bindClient(client);
4479
4560
  }
4480
4561
 
4481
- var SDK_VERSION = '6.13.0';
4562
+ var SDK_VERSION = '6.14.0';
4482
4563
 
4483
4564
  var originalFunctionToString;
4484
4565
  /** Patch toString calls to return proper name for wrapped functions */
@@ -5042,10 +5123,7 @@ var Sentry = (function (exports) {
5042
5123
  var event = eventFromUnknownInput(exception, syntheticException, {
5043
5124
  attachStacktrace: options.attachStacktrace,
5044
5125
  });
5045
- addExceptionMechanism(event, {
5046
- handled: true,
5047
- type: 'generic',
5048
- });
5126
+ addExceptionMechanism(event); // defaults to { type: 'generic', handled: true }
5049
5127
  event.level = exports.Severity.Error;
5050
5128
  if (hint && hint.event_id) {
5051
5129
  event.event_id = hint.event_id;
@@ -5147,12 +5225,108 @@ var Sentry = (function (exports) {
5147
5225
  return event;
5148
5226
  }
5149
5227
 
5228
+ var global$3 = getGlobalObject();
5229
+ var cachedFetchImpl;
5230
+ /**
5231
+ * A special usecase for incorrectly wrapped Fetch APIs in conjunction with ad-blockers.
5232
+ * Whenever someone wraps the Fetch API and returns the wrong promise chain,
5233
+ * this chain becomes orphaned and there is no possible way to capture it's rejections
5234
+ * other than allowing it bubble up to this very handler. eg.
5235
+ *
5236
+ * const f = window.fetch;
5237
+ * window.fetch = function () {
5238
+ * const p = f.apply(this, arguments);
5239
+ *
5240
+ * p.then(function() {
5241
+ * console.log('hi.');
5242
+ * });
5243
+ *
5244
+ * return p;
5245
+ * }
5246
+ *
5247
+ * `p.then(function () { ... })` is producing a completely separate promise chain,
5248
+ * however, what's returned is `p` - the result of original `fetch` call.
5249
+ *
5250
+ * This mean, that whenever we use the Fetch API to send our own requests, _and_
5251
+ * some ad-blocker blocks it, this orphaned chain will _always_ reject,
5252
+ * effectively causing another event to be captured.
5253
+ * This makes a whole process become an infinite loop, which we need to somehow
5254
+ * deal with, and break it in one way or another.
5255
+ *
5256
+ * To deal with this issue, we are making sure that we _always_ use the real
5257
+ * browser Fetch API, instead of relying on what `window.fetch` exposes.
5258
+ * The only downside to this would be missing our own requests as breadcrumbs,
5259
+ * but because we are already not doing this, it should be just fine.
5260
+ *
5261
+ * Possible failed fetch error messages per-browser:
5262
+ *
5263
+ * Chrome: Failed to fetch
5264
+ * Edge: Failed to Fetch
5265
+ * Firefox: NetworkError when attempting to fetch resource
5266
+ * Safari: resource blocked by content blocker
5267
+ */
5268
+ function getNativeFetchImplementation() {
5269
+ var _a, _b;
5270
+ if (cachedFetchImpl) {
5271
+ return cachedFetchImpl;
5272
+ }
5273
+ /* eslint-disable @typescript-eslint/unbound-method */
5274
+ // Fast path to avoid DOM I/O
5275
+ if (isNativeFetch(global$3.fetch)) {
5276
+ return (cachedFetchImpl = global$3.fetch.bind(global$3));
5277
+ }
5278
+ var document = global$3.document;
5279
+ var fetchImpl = global$3.fetch;
5280
+ // eslint-disable-next-line deprecation/deprecation
5281
+ if (typeof ((_a = document) === null || _a === void 0 ? void 0 : _a.createElement) === "function") {
5282
+ try {
5283
+ var sandbox = document.createElement('iframe');
5284
+ sandbox.hidden = true;
5285
+ document.head.appendChild(sandbox);
5286
+ if ((_b = sandbox.contentWindow) === null || _b === void 0 ? void 0 : _b.fetch) {
5287
+ fetchImpl = sandbox.contentWindow.fetch;
5288
+ }
5289
+ document.head.removeChild(sandbox);
5290
+ }
5291
+ catch (e) {
5292
+ logger.warn('Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ', e);
5293
+ }
5294
+ }
5295
+ return (cachedFetchImpl = fetchImpl.bind(global$3));
5296
+ /* eslint-enable @typescript-eslint/unbound-method */
5297
+ }
5298
+ /**
5299
+ * Sends sdk client report using sendBeacon or fetch as a fallback if available
5300
+ *
5301
+ * @param url report endpoint
5302
+ * @param body report payload
5303
+ */
5304
+ function sendReport(url, body) {
5305
+ var isRealNavigator = Object.prototype.toString.call(global$3 && global$3.navigator) === '[object Navigator]';
5306
+ var hasSendBeacon = isRealNavigator && typeof global$3.navigator.sendBeacon === 'function';
5307
+ if (hasSendBeacon) {
5308
+ // Prevent illegal invocations - https://xgwang.me/posts/you-may-not-know-beacon/#it-may-throw-error%2C-be-sure-to-catch
5309
+ var sendBeacon = global$3.navigator.sendBeacon.bind(global$3.navigator);
5310
+ return sendBeacon(url, body);
5311
+ }
5312
+ if (supportsFetch()) {
5313
+ var fetch_1 = getNativeFetchImplementation();
5314
+ return forget(fetch_1(url, {
5315
+ body: body,
5316
+ method: 'POST',
5317
+ credentials: 'omit',
5318
+ keepalive: true,
5319
+ }));
5320
+ }
5321
+ }
5322
+
5150
5323
  var CATEGORY_MAPPING = {
5151
5324
  event: 'error',
5152
5325
  transaction: 'transaction',
5153
5326
  session: 'session',
5154
5327
  attachment: 'attachment',
5155
5328
  };
5329
+ var global$4 = getGlobalObject();
5156
5330
  /** Base Transport class implementation */
5157
5331
  var BaseTransport = /** @class */ (function () {
5158
5332
  function BaseTransport(options) {
@@ -5166,9 +5340,9 @@ var Sentry = (function (exports) {
5166
5340
  this._api = new API(options.dsn, options._metadata, options.tunnel);
5167
5341
  // eslint-disable-next-line deprecation/deprecation
5168
5342
  this.url = this._api.getStoreEndpointWithUrlEncodedAuth();
5169
- if (this.options.sendClientReports) {
5170
- document.addEventListener('visibilitychange', function () {
5171
- if (document.visibilityState === 'hidden') {
5343
+ if (this.options.sendClientReports && global$4.document) {
5344
+ global$4.document.addEventListener('visibilitychange', function () {
5345
+ if (global$4.document.visibilityState === 'hidden') {
5172
5346
  _this._flushOutcomes();
5173
5347
  }
5174
5348
  });
@@ -5210,10 +5384,6 @@ var Sentry = (function (exports) {
5210
5384
  if (!this.options.sendClientReports) {
5211
5385
  return;
5212
5386
  }
5213
- if (!navigator || typeof navigator.sendBeacon !== 'function') {
5214
- logger.warn('Beacon API not available, skipping sending outcomes.');
5215
- return;
5216
- }
5217
5387
  var outcomes = this._outcomes;
5218
5388
  this._outcomes = {};
5219
5389
  // Nothing to send
@@ -5224,7 +5394,7 @@ var Sentry = (function (exports) {
5224
5394
  logger.log("Flushing outcomes:\n" + JSON.stringify(outcomes, null, 2));
5225
5395
  var url = this._api.getEnvelopeEndpointWithUrlEncodedAuth();
5226
5396
  // Envelope header is required to be at least an empty object
5227
- var envelopeHeader = JSON.stringify({});
5397
+ var envelopeHeader = JSON.stringify(__assign({}, (this.options.tunnel && { dsn: this._api.getDsn().toString() })));
5228
5398
  var itemHeaders = JSON.stringify({
5229
5399
  type: 'client_report',
5230
5400
  });
@@ -5240,7 +5410,12 @@ var Sentry = (function (exports) {
5240
5410
  }),
5241
5411
  });
5242
5412
  var envelope = envelopeHeader + "\n" + itemHeaders + "\n" + item;
5243
- navigator.sendBeacon(url, envelope);
5413
+ try {
5414
+ sendReport(url, envelope);
5415
+ }
5416
+ catch (e) {
5417
+ logger.error(e);
5418
+ }
5244
5419
  };
5245
5420
  /**
5246
5421
  * Handle Sentry repsonse for promise-based transports.
@@ -5332,72 +5507,6 @@ var Sentry = (function (exports) {
5332
5507
  return BaseTransport;
5333
5508
  }());
5334
5509
 
5335
- /**
5336
- * A special usecase for incorrectly wrapped Fetch APIs in conjunction with ad-blockers.
5337
- * Whenever someone wraps the Fetch API and returns the wrong promise chain,
5338
- * this chain becomes orphaned and there is no possible way to capture it's rejections
5339
- * other than allowing it bubble up to this very handler. eg.
5340
- *
5341
- * const f = window.fetch;
5342
- * window.fetch = function () {
5343
- * const p = f.apply(this, arguments);
5344
- *
5345
- * p.then(function() {
5346
- * console.log('hi.');
5347
- * });
5348
- *
5349
- * return p;
5350
- * }
5351
- *
5352
- * `p.then(function () { ... })` is producing a completely separate promise chain,
5353
- * however, what's returned is `p` - the result of original `fetch` call.
5354
- *
5355
- * This mean, that whenever we use the Fetch API to send our own requests, _and_
5356
- * some ad-blocker blocks it, this orphaned chain will _always_ reject,
5357
- * effectively causing another event to be captured.
5358
- * This makes a whole process become an infinite loop, which we need to somehow
5359
- * deal with, and break it in one way or another.
5360
- *
5361
- * To deal with this issue, we are making sure that we _always_ use the real
5362
- * browser Fetch API, instead of relying on what `window.fetch` exposes.
5363
- * The only downside to this would be missing our own requests as breadcrumbs,
5364
- * but because we are already not doing this, it should be just fine.
5365
- *
5366
- * Possible failed fetch error messages per-browser:
5367
- *
5368
- * Chrome: Failed to fetch
5369
- * Edge: Failed to Fetch
5370
- * Firefox: NetworkError when attempting to fetch resource
5371
- * Safari: resource blocked by content blocker
5372
- */
5373
- function getNativeFetchImplementation() {
5374
- /* eslint-disable @typescript-eslint/unbound-method */
5375
- var _a, _b;
5376
- // Fast path to avoid DOM I/O
5377
- var global = getGlobalObject();
5378
- if (isNativeFetch(global.fetch)) {
5379
- return global.fetch.bind(global);
5380
- }
5381
- var document = global.document;
5382
- var fetchImpl = global.fetch;
5383
- // eslint-disable-next-line deprecation/deprecation
5384
- if (typeof ((_a = document) === null || _a === void 0 ? void 0 : _a.createElement) === "function") {
5385
- try {
5386
- var sandbox = document.createElement('iframe');
5387
- sandbox.hidden = true;
5388
- document.head.appendChild(sandbox);
5389
- if ((_b = sandbox.contentWindow) === null || _b === void 0 ? void 0 : _b.fetch) {
5390
- fetchImpl = sandbox.contentWindow.fetch;
5391
- }
5392
- document.head.removeChild(sandbox);
5393
- }
5394
- catch (e) {
5395
- logger.warn('Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ', e);
5396
- }
5397
- }
5398
- return fetchImpl.bind(global);
5399
- /* eslint-enable @typescript-eslint/unbound-method */
5400
- }
5401
5510
  /** `fetch` based transport */
5402
5511
  var FetchTransport = /** @class */ (function (_super) {
5403
5512
  __extends(FetchTransport, _super);
@@ -5603,6 +5712,7 @@ var Sentry = (function (exports) {
5603
5712
  return BrowserBackend;
5604
5713
  }(BaseBackend));
5605
5714
 
5715
+ var global$5 = getGlobalObject();
5606
5716
  var ignoreOnError = 0;
5607
5717
  /**
5608
5718
  * @hidden
@@ -5740,6 +5850,9 @@ var Sentry = (function (exports) {
5740
5850
  */
5741
5851
  function injectReportDialog(options) {
5742
5852
  if (options === void 0) { options = {}; }
5853
+ if (!global$5.document) {
5854
+ return;
5855
+ }
5743
5856
  if (!options.eventId) {
5744
5857
  logger.error("Missing eventId option in showReportDialog call");
5745
5858
  return;
@@ -5748,14 +5861,14 @@ var Sentry = (function (exports) {
5748
5861
  logger.error("Missing dsn option in showReportDialog call");
5749
5862
  return;
5750
5863
  }
5751
- var script = document.createElement('script');
5864
+ var script = global$5.document.createElement('script');
5752
5865
  script.async = true;
5753
5866
  script.src = new API(options.dsn).getReportDialogEndpoint(options);
5754
5867
  if (options.onLoad) {
5755
5868
  // eslint-disable-next-line @typescript-eslint/unbound-method
5756
5869
  script.onload = options.onLoad;
5757
5870
  }
5758
- var injectionPoint = document.head || document.body;
5871
+ var injectionPoint = global$5.document.head || global$5.document.body;
5759
5872
  if (injectionPoint) {
5760
5873
  injectionPoint.appendChild(script);
5761
5874
  }
@@ -6500,7 +6613,7 @@ var Sentry = (function (exports) {
6500
6613
  return LinkedErrors;
6501
6614
  }());
6502
6615
 
6503
- var global$3 = getGlobalObject();
6616
+ var global$6 = getGlobalObject();
6504
6617
  /** UserAgent */
6505
6618
  var UserAgent = /** @class */ (function () {
6506
6619
  function UserAgent() {
@@ -6517,13 +6630,13 @@ var Sentry = (function (exports) {
6517
6630
  var _a, _b, _c;
6518
6631
  if (getCurrentHub().getIntegration(UserAgent)) {
6519
6632
  // if none of the information we want exists, don't bother
6520
- if (!global$3.navigator && !global$3.location && !global$3.document) {
6633
+ if (!global$6.navigator && !global$6.location && !global$6.document) {
6521
6634
  return event;
6522
6635
  }
6523
6636
  // grab as much info as exists and add it to the event
6524
- var url = ((_a = event.request) === null || _a === void 0 ? void 0 : _a.url) || ((_b = global$3.location) === null || _b === void 0 ? void 0 : _b.href);
6525
- var referrer = (global$3.document || {}).referrer;
6526
- var userAgent = (global$3.navigator || {}).userAgent;
6637
+ var url = ((_a = event.request) === null || _a === void 0 ? void 0 : _a.url) || ((_b = global$6.location) === null || _b === void 0 ? void 0 : _b.href);
6638
+ var referrer = (global$6.document || {}).referrer;
6639
+ var userAgent = (global$6.navigator || {}).userAgent;
6527
6640
  var headers = __assign(__assign(__assign({}, (_c = event.request) === null || _c === void 0 ? void 0 : _c.headers), (referrer && { Referer: referrer })), (userAgent && { 'User-Agent': userAgent }));
6528
6641
  var request = __assign(__assign({}, (url && { url: url })), { headers: headers });
6529
6642
  return __assign(__assign({}, event), { request: request });