@sentry/browser 6.13.1 → 6.14.1

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 (51) hide show
  1. package/build/bundle.es6.js +453 -340
  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 +454 -342
  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/integrations/trycatch.js +1 -1
  16. package/dist/integrations/trycatch.js.map +1 -1
  17. package/dist/transports/base.d.ts.map +1 -1
  18. package/dist/transports/base.js +12 -9
  19. package/dist/transports/base.js.map +1 -1
  20. package/dist/transports/fetch.d.ts +1 -2
  21. package/dist/transports/fetch.d.ts.map +1 -1
  22. package/dist/transports/fetch.js +2 -67
  23. package/dist/transports/fetch.js.map +1 -1
  24. package/dist/transports/utils.d.ts +48 -0
  25. package/dist/transports/utils.d.ts.map +1 -0
  26. package/dist/transports/utils.js +99 -0
  27. package/dist/transports/utils.js.map +1 -0
  28. package/dist/transports/xhr.js +1 -1
  29. package/dist/transports/xhr.js.map +1 -1
  30. package/esm/eventbuilder.d.ts.map +1 -1
  31. package/esm/eventbuilder.js +1 -4
  32. package/esm/eventbuilder.js.map +1 -1
  33. package/esm/helpers.d.ts.map +1 -1
  34. package/esm/helpers.js +7 -3
  35. package/esm/helpers.js.map +1 -1
  36. package/esm/integrations/trycatch.js +1 -1
  37. package/esm/integrations/trycatch.js.map +1 -1
  38. package/esm/transports/base.d.ts.map +1 -1
  39. package/esm/transports/base.js +14 -11
  40. package/esm/transports/base.js.map +1 -1
  41. package/esm/transports/fetch.d.ts +1 -2
  42. package/esm/transports/fetch.d.ts.map +1 -1
  43. package/esm/transports/fetch.js +2 -67
  44. package/esm/transports/fetch.js.map +1 -1
  45. package/esm/transports/utils.d.ts +48 -0
  46. package/esm/transports/utils.d.ts.map +1 -0
  47. package/esm/transports/utils.js +96 -0
  48. package/esm/transports/utils.js.map +1 -0
  49. package/esm/transports/xhr.js +1 -1
  50. package/esm/transports/xhr.js.map +1 -1
  51. package/package.json +23 -23
package/build/bundle.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @sentry/browser 6.13.1 (fdf519b) | https://github.com/getsentry/sentry-javascript */
1
+ /*! @sentry/browser 6.14.1 (687b6c4) | 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);
@@ -481,8 +549,7 @@ var Sentry = (function (exports) {
481
549
  // eslint-disable-next-line @typescript-eslint/ban-types
482
550
  function mixinProperties(obj, proto) {
483
551
  for (var prop in proto) {
484
- // eslint-disable-next-line no-prototype-builtins
485
- if (!obj.hasOwnProperty(prop)) {
552
+ if (!Object.prototype.hasOwnProperty.call(obj, prop)) {
486
553
  // @ts-ignore typescript complains about indexing so we remove
487
554
  obj[prop] = proto[prop];
488
555
  }
@@ -593,175 +660,17 @@ var Sentry = (function (exports) {
593
660
  return Dsn;
594
661
  }());
595
662
 
663
+ // TODO: Implement different loggers for different environments
664
+ var global$1 = getGlobalObject();
665
+ /** Prefix for logging strings */
666
+ var PREFIX = 'Sentry Logger ';
596
667
  /**
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
668
+ * Temporarily unwrap `console.log` and friends in order to perform the given callback using the original methods.
669
+ * Restores wrapping after the callback completes.
688
670
  *
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
671
+ * @param callback The function to run against the original `console` messages
672
+ * @returns The results of the callback
750
673
  */
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
674
  function consoleSandbox(callback) {
766
675
  var global = getGlobalObject();
767
676
  var levels = ['debug', 'info', 'warn', 'error', 'log', 'assert'];
@@ -787,80 +696,6 @@ var Sentry = (function (exports) {
787
696
  });
788
697
  return result;
789
698
  }
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
699
  /** JSDoc */
865
700
  var Logger = /** @class */ (function () {
866
701
  /** JSDoc */
@@ -991,6 +826,62 @@ var Sentry = (function (exports) {
991
826
  }
992
827
  }
993
828
 
829
+ /**
830
+ * Truncates given string to the maximum characters count
831
+ *
832
+ * @param str An object that contains serializable values
833
+ * @param max Maximum number of characters in truncated string (0 = unlimited)
834
+ * @returns string Encoded
835
+ */
836
+ function truncate(str, max) {
837
+ if (max === void 0) { max = 0; }
838
+ if (typeof str !== 'string' || max === 0) {
839
+ return str;
840
+ }
841
+ return str.length <= max ? str : str.substr(0, max) + "...";
842
+ }
843
+ /**
844
+ * Join values in array
845
+ * @param input array of values to be joined together
846
+ * @param delimiter string to be placed in-between values
847
+ * @returns Joined values
848
+ */
849
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
850
+ function safeJoin(input, delimiter) {
851
+ if (!Array.isArray(input)) {
852
+ return '';
853
+ }
854
+ var output = [];
855
+ // eslint-disable-next-line @typescript-eslint/prefer-for-of
856
+ for (var i = 0; i < input.length; i++) {
857
+ var value = input[i];
858
+ try {
859
+ output.push(String(value));
860
+ }
861
+ catch (e) {
862
+ output.push('[value cannot be serialized]');
863
+ }
864
+ }
865
+ return output.join(delimiter);
866
+ }
867
+ /**
868
+ * Checks if the value matches a regex or includes the string
869
+ * @param value The string value to be checked against
870
+ * @param pattern Either a regex or a string that must be contained in value
871
+ */
872
+ function isMatchingPattern(value, pattern) {
873
+ if (!isString(value)) {
874
+ return false;
875
+ }
876
+ if (isRegExp(pattern)) {
877
+ return pattern.test(value);
878
+ }
879
+ if (typeof pattern === 'string') {
880
+ return value.indexOf(pattern) !== -1;
881
+ }
882
+ return false;
883
+ }
884
+
994
885
  /**
995
886
  * Replace a method in an object with a wrapped version of itself.
996
887
  *
@@ -1160,9 +1051,13 @@ var Sentry = (function (exports) {
1160
1051
  if (typeof global !== 'undefined' && value === global) {
1161
1052
  return '[Global]';
1162
1053
  }
1054
+ // It's safe to use `window` and `document` here in this manner, as we are asserting using `typeof` first
1055
+ // which won't throw if they are not present.
1056
+ // eslint-disable-next-line no-restricted-globals
1163
1057
  if (typeof window !== 'undefined' && value === window) {
1164
1058
  return '[Window]';
1165
1059
  }
1060
+ // eslint-disable-next-line no-restricted-globals
1166
1061
  if (typeof document !== 'undefined' && value === document) {
1167
1062
  return '[Document]';
1168
1063
  }
@@ -1948,18 +1843,191 @@ var Sentry = (function (exports) {
1948
1843
  return false;
1949
1844
  };
1950
1845
  }
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);
1846
+ var _oldOnUnhandledRejectionHandler = null;
1847
+ /** JSDoc */
1848
+ function instrumentUnhandledRejection() {
1849
+ _oldOnUnhandledRejectionHandler = global$2.onunhandledrejection;
1850
+ global$2.onunhandledrejection = function (e) {
1851
+ triggerHandlers('unhandledrejection', e);
1852
+ if (_oldOnUnhandledRejectionHandler) {
1853
+ // eslint-disable-next-line prefer-rest-params
1854
+ return _oldOnUnhandledRejectionHandler.apply(this, arguments);
1855
+ }
1856
+ return true;
1857
+ };
1858
+ }
1859
+
1860
+ /**
1861
+ * UUID4 generator
1862
+ *
1863
+ * @returns string Generated UUID4.
1864
+ */
1865
+ function uuid4() {
1866
+ var global = getGlobalObject();
1867
+ var crypto = global.crypto || global.msCrypto;
1868
+ if (!(crypto === void 0) && crypto.getRandomValues) {
1869
+ // Use window.crypto API if available
1870
+ var arr = new Uint16Array(8);
1871
+ crypto.getRandomValues(arr);
1872
+ // set 4 in byte 7
1873
+ // eslint-disable-next-line no-bitwise
1874
+ arr[3] = (arr[3] & 0xfff) | 0x4000;
1875
+ // set 2 most significant bits of byte 9 to '10'
1876
+ // eslint-disable-next-line no-bitwise
1877
+ arr[4] = (arr[4] & 0x3fff) | 0x8000;
1878
+ var pad = function (num) {
1879
+ var v = num.toString(16);
1880
+ while (v.length < 4) {
1881
+ v = "0" + v;
1882
+ }
1883
+ return v;
1884
+ };
1885
+ 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]));
1886
+ }
1887
+ // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#2117523
1888
+ return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
1889
+ // eslint-disable-next-line no-bitwise
1890
+ var r = (Math.random() * 16) | 0;
1891
+ // eslint-disable-next-line no-bitwise
1892
+ var v = c === 'x' ? r : (r & 0x3) | 0x8;
1893
+ return v.toString(16);
1894
+ });
1895
+ }
1896
+ /**
1897
+ * Parses string form of URL into an object
1898
+ * // borrowed from https://tools.ietf.org/html/rfc3986#appendix-B
1899
+ * // intentionally using regex and not <a/> href parsing trick because React Native and other
1900
+ * // environments where DOM might not be available
1901
+ * @returns parsed URL object
1902
+ */
1903
+ function parseUrl(url) {
1904
+ if (!url) {
1905
+ return {};
1906
+ }
1907
+ var match = url.match(/^(([^:/?#]+):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/);
1908
+ if (!match) {
1909
+ return {};
1910
+ }
1911
+ // coerce to undefined values to empty string so we don't get 'undefined'
1912
+ var query = match[6] || '';
1913
+ var fragment = match[8] || '';
1914
+ return {
1915
+ host: match[4],
1916
+ path: match[5],
1917
+ protocol: match[2],
1918
+ relative: match[5] + query + fragment,
1919
+ };
1920
+ }
1921
+ /**
1922
+ * Extracts either message or type+value from an event that can be used for user-facing logs
1923
+ * @returns event's description
1924
+ */
1925
+ function getEventDescription(event) {
1926
+ if (event.message) {
1927
+ return event.message;
1928
+ }
1929
+ if (event.exception && event.exception.values && event.exception.values[0]) {
1930
+ var exception = event.exception.values[0];
1931
+ if (exception.type && exception.value) {
1932
+ return exception.type + ": " + exception.value;
1960
1933
  }
1934
+ return exception.type || exception.value || event.event_id || '<unknown>';
1935
+ }
1936
+ return event.event_id || '<unknown>';
1937
+ }
1938
+ /**
1939
+ * Adds exception values, type and value to an synthetic Exception.
1940
+ * @param event The event to modify.
1941
+ * @param value Value of the exception.
1942
+ * @param type Type of the exception.
1943
+ * @hidden
1944
+ */
1945
+ function addExceptionTypeValue(event, value, type) {
1946
+ event.exception = event.exception || {};
1947
+ event.exception.values = event.exception.values || [];
1948
+ event.exception.values[0] = event.exception.values[0] || {};
1949
+ event.exception.values[0].value = event.exception.values[0].value || value || '';
1950
+ event.exception.values[0].type = event.exception.values[0].type || type || 'Error';
1951
+ }
1952
+ /**
1953
+ * Adds exception mechanism data to a given event. Uses defaults if the second parameter is not passed.
1954
+ *
1955
+ * @param event The event to modify.
1956
+ * @param newMechanism Mechanism data to add to the event.
1957
+ * @hidden
1958
+ */
1959
+ function addExceptionMechanism(event, newMechanism) {
1960
+ var _a;
1961
+ if (!event.exception || !event.exception.values) {
1962
+ return;
1963
+ }
1964
+ var exceptionValue0 = event.exception.values[0];
1965
+ var defaultMechanism = { type: 'generic', handled: true };
1966
+ var currentMechanism = exceptionValue0.mechanism;
1967
+ exceptionValue0.mechanism = __assign(__assign(__assign({}, defaultMechanism), currentMechanism), newMechanism);
1968
+ if (newMechanism && 'data' in newMechanism) {
1969
+ var mergedData = __assign(__assign({}, (_a = currentMechanism) === null || _a === void 0 ? void 0 : _a.data), newMechanism.data);
1970
+ exceptionValue0.mechanism.data = mergedData;
1971
+ }
1972
+ }
1973
+ var defaultRetryAfter = 60 * 1000; // 60 seconds
1974
+ /**
1975
+ * Extracts Retry-After value from the request header or returns default value
1976
+ * @param now current unix timestamp
1977
+ * @param header string representation of 'Retry-After' header
1978
+ */
1979
+ function parseRetryAfterHeader(now, header) {
1980
+ if (!header) {
1981
+ return defaultRetryAfter;
1982
+ }
1983
+ var headerDelay = parseInt("" + header, 10);
1984
+ if (!isNaN(headerDelay)) {
1985
+ return headerDelay * 1000;
1986
+ }
1987
+ var headerDate = Date.parse("" + header);
1988
+ if (!isNaN(headerDate)) {
1989
+ return headerDate - now;
1990
+ }
1991
+ return defaultRetryAfter;
1992
+ }
1993
+ /**
1994
+ * Checks whether or not we've already captured the given exception (note: not an identical exception - the very object
1995
+ * in question), and marks it captured if not.
1996
+ *
1997
+ * This is useful because it's possible for an error to get captured by more than one mechanism. After we intercept and
1998
+ * record an error, we rethrow it (assuming we've intercepted it before it's reached the top-level global handlers), so
1999
+ * that we don't interfere with whatever effects the error might have had were the SDK not there. At that point, because
2000
+ * the error has been rethrown, it's possible for it to bubble up to some other code we've instrumented. If it's not
2001
+ * caught after that, it will bubble all the way up to the global handlers (which of course we also instrument). This
2002
+ * function helps us ensure that even if we encounter the same error more than once, we only record it the first time we
2003
+ * see it.
2004
+ *
2005
+ * Note: It will ignore primitives (always return `false` and not mark them as seen), as properties can't be set on
2006
+ * them. {@link: Object.objectify} can be used on exceptions to convert any that are primitives into their equivalent
2007
+ * object wrapper forms so that this check will always work. However, because we need to flag the exact object which
2008
+ * will get rethrown, and because that rethrowing happens outside of the event processing pipeline, the objectification
2009
+ * must be done before the exception captured.
2010
+ *
2011
+ * @param A thrown exception to check or flag as having been seen
2012
+ * @returns `true` if the exception has already been captured, `false` if not (with the side effect of marking it seen)
2013
+ */
2014
+ function checkOrSetAlreadyCaught(exception) {
2015
+ var _a;
2016
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
2017
+ if ((_a = exception) === null || _a === void 0 ? void 0 : _a.__sentry_captured__) {
1961
2018
  return true;
1962
- };
2019
+ }
2020
+ try {
2021
+ // set it this way rather than by assignment so that it's not ennumerable and therefore isn't recorded by the
2022
+ // `ExtraErrorData` integration
2023
+ Object.defineProperty(exception, '__sentry_captured__', {
2024
+ value: true,
2025
+ });
2026
+ }
2027
+ catch (err) {
2028
+ // `exception` is a primitive, so we can't mark it seen
2029
+ }
2030
+ return false;
1963
2031
  }
1964
2032
 
1965
2033
  /* eslint-disable @typescript-eslint/explicit-function-return-type */
@@ -3801,6 +3869,7 @@ var Sentry = (function (exports) {
3801
3869
  return integrations;
3802
3870
  }
3803
3871
 
3872
+ var ALREADY_SEEN_ERROR = "Not capturing exception because it's already been captured.";
3804
3873
  /**
3805
3874
  * Base implementation for all JavaScript SDK clients.
3806
3875
  *
@@ -3857,6 +3926,11 @@ var Sentry = (function (exports) {
3857
3926
  // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
3858
3927
  BaseClient.prototype.captureException = function (exception, hint, scope) {
3859
3928
  var _this = this;
3929
+ // ensure we haven't captured this very object before
3930
+ if (checkOrSetAlreadyCaught(exception)) {
3931
+ logger.log(ALREADY_SEEN_ERROR);
3932
+ return;
3933
+ }
3860
3934
  var eventId = hint && hint.event_id;
3861
3935
  this._process(this._getBackend()
3862
3936
  .eventFromException(exception, hint)
@@ -3886,6 +3960,12 @@ var Sentry = (function (exports) {
3886
3960
  * @inheritDoc
3887
3961
  */
3888
3962
  BaseClient.prototype.captureEvent = function (event, hint, scope) {
3963
+ var _a;
3964
+ // ensure we haven't captured this very object before
3965
+ if (((_a = hint) === null || _a === void 0 ? void 0 : _a.originalException) && checkOrSetAlreadyCaught(hint.originalException)) {
3966
+ logger.log(ALREADY_SEEN_ERROR);
3967
+ return;
3968
+ }
3889
3969
  var eventId = hint && hint.event_id;
3890
3970
  this._process(this._captureEvent(event, hint, scope).then(function (result) {
3891
3971
  eventId = result;
@@ -4478,7 +4558,7 @@ var Sentry = (function (exports) {
4478
4558
  hub.bindClient(client);
4479
4559
  }
4480
4560
 
4481
- var SDK_VERSION = '6.13.1';
4561
+ var SDK_VERSION = '6.14.1';
4482
4562
 
4483
4563
  var originalFunctionToString;
4484
4564
  /** Patch toString calls to return proper name for wrapped functions */
@@ -5042,10 +5122,7 @@ var Sentry = (function (exports) {
5042
5122
  var event = eventFromUnknownInput(exception, syntheticException, {
5043
5123
  attachStacktrace: options.attachStacktrace,
5044
5124
  });
5045
- addExceptionMechanism(event, {
5046
- handled: true,
5047
- type: 'generic',
5048
- });
5125
+ addExceptionMechanism(event); // defaults to { type: 'generic', handled: true }
5049
5126
  event.level = exports.Severity.Error;
5050
5127
  if (hint && hint.event_id) {
5051
5128
  event.event_id = hint.event_id;
@@ -5147,12 +5224,108 @@ var Sentry = (function (exports) {
5147
5224
  return event;
5148
5225
  }
5149
5226
 
5227
+ var global$3 = getGlobalObject();
5228
+ var cachedFetchImpl;
5229
+ /**
5230
+ * A special usecase for incorrectly wrapped Fetch APIs in conjunction with ad-blockers.
5231
+ * Whenever someone wraps the Fetch API and returns the wrong promise chain,
5232
+ * this chain becomes orphaned and there is no possible way to capture it's rejections
5233
+ * other than allowing it bubble up to this very handler. eg.
5234
+ *
5235
+ * const f = window.fetch;
5236
+ * window.fetch = function () {
5237
+ * const p = f.apply(this, arguments);
5238
+ *
5239
+ * p.then(function() {
5240
+ * console.log('hi.');
5241
+ * });
5242
+ *
5243
+ * return p;
5244
+ * }
5245
+ *
5246
+ * `p.then(function () { ... })` is producing a completely separate promise chain,
5247
+ * however, what's returned is `p` - the result of original `fetch` call.
5248
+ *
5249
+ * This mean, that whenever we use the Fetch API to send our own requests, _and_
5250
+ * some ad-blocker blocks it, this orphaned chain will _always_ reject,
5251
+ * effectively causing another event to be captured.
5252
+ * This makes a whole process become an infinite loop, which we need to somehow
5253
+ * deal with, and break it in one way or another.
5254
+ *
5255
+ * To deal with this issue, we are making sure that we _always_ use the real
5256
+ * browser Fetch API, instead of relying on what `window.fetch` exposes.
5257
+ * The only downside to this would be missing our own requests as breadcrumbs,
5258
+ * but because we are already not doing this, it should be just fine.
5259
+ *
5260
+ * Possible failed fetch error messages per-browser:
5261
+ *
5262
+ * Chrome: Failed to fetch
5263
+ * Edge: Failed to Fetch
5264
+ * Firefox: NetworkError when attempting to fetch resource
5265
+ * Safari: resource blocked by content blocker
5266
+ */
5267
+ function getNativeFetchImplementation() {
5268
+ var _a, _b;
5269
+ if (cachedFetchImpl) {
5270
+ return cachedFetchImpl;
5271
+ }
5272
+ /* eslint-disable @typescript-eslint/unbound-method */
5273
+ // Fast path to avoid DOM I/O
5274
+ if (isNativeFetch(global$3.fetch)) {
5275
+ return (cachedFetchImpl = global$3.fetch.bind(global$3));
5276
+ }
5277
+ var document = global$3.document;
5278
+ var fetchImpl = global$3.fetch;
5279
+ // eslint-disable-next-line deprecation/deprecation
5280
+ if (typeof ((_a = document) === null || _a === void 0 ? void 0 : _a.createElement) === "function") {
5281
+ try {
5282
+ var sandbox = document.createElement('iframe');
5283
+ sandbox.hidden = true;
5284
+ document.head.appendChild(sandbox);
5285
+ if ((_b = sandbox.contentWindow) === null || _b === void 0 ? void 0 : _b.fetch) {
5286
+ fetchImpl = sandbox.contentWindow.fetch;
5287
+ }
5288
+ document.head.removeChild(sandbox);
5289
+ }
5290
+ catch (e) {
5291
+ logger.warn('Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ', e);
5292
+ }
5293
+ }
5294
+ return (cachedFetchImpl = fetchImpl.bind(global$3));
5295
+ /* eslint-enable @typescript-eslint/unbound-method */
5296
+ }
5297
+ /**
5298
+ * Sends sdk client report using sendBeacon or fetch as a fallback if available
5299
+ *
5300
+ * @param url report endpoint
5301
+ * @param body report payload
5302
+ */
5303
+ function sendReport(url, body) {
5304
+ var isRealNavigator = Object.prototype.toString.call(global$3 && global$3.navigator) === '[object Navigator]';
5305
+ var hasSendBeacon = isRealNavigator && typeof global$3.navigator.sendBeacon === 'function';
5306
+ if (hasSendBeacon) {
5307
+ // Prevent illegal invocations - https://xgwang.me/posts/you-may-not-know-beacon/#it-may-throw-error%2C-be-sure-to-catch
5308
+ var sendBeacon = global$3.navigator.sendBeacon.bind(global$3.navigator);
5309
+ return sendBeacon(url, body);
5310
+ }
5311
+ if (supportsFetch()) {
5312
+ var fetch_1 = getNativeFetchImplementation();
5313
+ return forget(fetch_1(url, {
5314
+ body: body,
5315
+ method: 'POST',
5316
+ credentials: 'omit',
5317
+ keepalive: true,
5318
+ }));
5319
+ }
5320
+ }
5321
+
5150
5322
  var CATEGORY_MAPPING = {
5151
5323
  event: 'error',
5152
5324
  transaction: 'transaction',
5153
5325
  session: 'session',
5154
5326
  attachment: 'attachment',
5155
5327
  };
5328
+ var global$4 = getGlobalObject();
5156
5329
  /** Base Transport class implementation */
5157
5330
  var BaseTransport = /** @class */ (function () {
5158
5331
  function BaseTransport(options) {
@@ -5166,9 +5339,9 @@ var Sentry = (function (exports) {
5166
5339
  this._api = new API(options.dsn, options._metadata, options.tunnel);
5167
5340
  // eslint-disable-next-line deprecation/deprecation
5168
5341
  this.url = this._api.getStoreEndpointWithUrlEncodedAuth();
5169
- if (this.options.sendClientReports && document) {
5170
- document.addEventListener('visibilitychange', function () {
5171
- if (document.visibilityState === 'hidden') {
5342
+ if (this.options.sendClientReports && global$4.document) {
5343
+ global$4.document.addEventListener('visibilitychange', function () {
5344
+ if (global$4.document.visibilityState === 'hidden') {
5172
5345
  _this._flushOutcomes();
5173
5346
  }
5174
5347
  });
@@ -5210,10 +5383,6 @@ var Sentry = (function (exports) {
5210
5383
  if (!this.options.sendClientReports) {
5211
5384
  return;
5212
5385
  }
5213
- if (!navigator || typeof navigator.sendBeacon !== 'function') {
5214
- logger.warn('Beacon API not available, skipping sending outcomes.');
5215
- return;
5216
- }
5217
5386
  var outcomes = this._outcomes;
5218
5387
  this._outcomes = {};
5219
5388
  // Nothing to send
@@ -5224,7 +5393,7 @@ var Sentry = (function (exports) {
5224
5393
  logger.log("Flushing outcomes:\n" + JSON.stringify(outcomes, null, 2));
5225
5394
  var url = this._api.getEnvelopeEndpointWithUrlEncodedAuth();
5226
5395
  // Envelope header is required to be at least an empty object
5227
- var envelopeHeader = JSON.stringify({});
5396
+ var envelopeHeader = JSON.stringify(__assign({}, (this.options.tunnel && { dsn: this._api.getDsn().toString() })));
5228
5397
  var itemHeaders = JSON.stringify({
5229
5398
  type: 'client_report',
5230
5399
  });
@@ -5240,7 +5409,12 @@ var Sentry = (function (exports) {
5240
5409
  }),
5241
5410
  });
5242
5411
  var envelope = envelopeHeader + "\n" + itemHeaders + "\n" + item;
5243
- navigator.sendBeacon(url, envelope);
5412
+ try {
5413
+ sendReport(url, envelope);
5414
+ }
5415
+ catch (e) {
5416
+ logger.error(e);
5417
+ }
5244
5418
  };
5245
5419
  /**
5246
5420
  * Handle Sentry repsonse for promise-based transports.
@@ -5332,72 +5506,6 @@ var Sentry = (function (exports) {
5332
5506
  return BaseTransport;
5333
5507
  }());
5334
5508
 
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
5509
  /** `fetch` based transport */
5402
5510
  var FetchTransport = /** @class */ (function (_super) {
5403
5511
  __extends(FetchTransport, _super);
@@ -5531,7 +5639,7 @@ var Sentry = (function (exports) {
5531
5639
  };
5532
5640
  request.open('POST', sentryRequest.url);
5533
5641
  for (var header in _this.options.headers) {
5534
- if (_this.options.headers.hasOwnProperty(header)) {
5642
+ if (Object.prototype.hasOwnProperty.call(_this.options.headers, header)) {
5535
5643
  request.setRequestHeader(header, _this.options.headers[header]);
5536
5644
  }
5537
5645
  }
@@ -5603,6 +5711,7 @@ var Sentry = (function (exports) {
5603
5711
  return BrowserBackend;
5604
5712
  }(BaseBackend));
5605
5713
 
5714
+ var global$5 = getGlobalObject();
5606
5715
  var ignoreOnError = 0;
5607
5716
  /**
5608
5717
  * @hidden
@@ -5740,6 +5849,9 @@ var Sentry = (function (exports) {
5740
5849
  */
5741
5850
  function injectReportDialog(options) {
5742
5851
  if (options === void 0) { options = {}; }
5852
+ if (!global$5.document) {
5853
+ return;
5854
+ }
5743
5855
  if (!options.eventId) {
5744
5856
  logger.error("Missing eventId option in showReportDialog call");
5745
5857
  return;
@@ -5748,14 +5860,14 @@ var Sentry = (function (exports) {
5748
5860
  logger.error("Missing dsn option in showReportDialog call");
5749
5861
  return;
5750
5862
  }
5751
- var script = document.createElement('script');
5863
+ var script = global$5.document.createElement('script');
5752
5864
  script.async = true;
5753
5865
  script.src = new API(options.dsn).getReportDialogEndpoint(options);
5754
5866
  if (options.onLoad) {
5755
5867
  // eslint-disable-next-line @typescript-eslint/unbound-method
5756
5868
  script.onload = options.onLoad;
5757
5869
  }
5758
- var injectionPoint = document.head || document.body;
5870
+ var injectionPoint = global$5.document.head || global$5.document.body;
5759
5871
  if (injectionPoint) {
5760
5872
  injectionPoint.appendChild(script);
5761
5873
  }
@@ -6063,7 +6175,7 @@ var Sentry = (function (exports) {
6063
6175
  var global = getGlobalObject();
6064
6176
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
6065
6177
  var proto = global[target] && global[target].prototype;
6066
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
6178
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, no-prototype-builtins
6067
6179
  if (!proto || !proto.hasOwnProperty || !proto.hasOwnProperty('addEventListener')) {
6068
6180
  return;
6069
6181
  }
@@ -6500,7 +6612,7 @@ var Sentry = (function (exports) {
6500
6612
  return LinkedErrors;
6501
6613
  }());
6502
6614
 
6503
- var global$3 = getGlobalObject();
6615
+ var global$6 = getGlobalObject();
6504
6616
  /** UserAgent */
6505
6617
  var UserAgent = /** @class */ (function () {
6506
6618
  function UserAgent() {
@@ -6517,13 +6629,13 @@ var Sentry = (function (exports) {
6517
6629
  var _a, _b, _c;
6518
6630
  if (getCurrentHub().getIntegration(UserAgent)) {
6519
6631
  // if none of the information we want exists, don't bother
6520
- if (!global$3.navigator && !global$3.location && !global$3.document) {
6632
+ if (!global$6.navigator && !global$6.location && !global$6.document) {
6521
6633
  return event;
6522
6634
  }
6523
6635
  // 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;
6636
+ 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);
6637
+ var referrer = (global$6.document || {}).referrer;
6638
+ var userAgent = (global$6.navigator || {}).userAgent;
6527
6639
  var headers = __assign(__assign(__assign({}, (_c = event.request) === null || _c === void 0 ? void 0 : _c.headers), (referrer && { Referer: referrer })), (userAgent && { 'User-Agent': userAgent }));
6528
6640
  var request = __assign(__assign({}, (url && { url: url })), { headers: headers });
6529
6641
  return __assign(__assign({}, event), { request: request });