@sentry/browser 5.25.0-beta.2 → 5.25.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.
package/build/bundle.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @sentry/browser 5.25.0-beta.2 (84e835c) | https://github.com/getsentry/sentry-javascript */
1
+ /*! @sentry/browser 5.25.0 (bca2c59) | https://github.com/getsentry/sentry-javascript */
2
2
  var Sentry = (function (exports) {
3
3
  /*! *****************************************************************************
4
4
  Copyright (c) Microsoft Corporation. All rights reserved.
@@ -87,21 +87,6 @@ var Sentry = (function (exports) {
87
87
  LogLevel[LogLevel["Verbose"] = 3] = "Verbose";
88
88
  })(LogLevel || (LogLevel = {}));
89
89
 
90
- /**
91
- * Session Status
92
- */
93
- var SessionStatus;
94
- (function (SessionStatus) {
95
- /** JSDoc */
96
- SessionStatus["Ok"] = "ok";
97
- /** JSDoc */
98
- SessionStatus["Exited"] = "exited";
99
- /** JSDoc */
100
- SessionStatus["Crashed"] = "crashed";
101
- /** JSDoc */
102
- SessionStatus["Abnormal"] = "abnormal";
103
- })(SessionStatus || (SessionStatus = {}));
104
-
105
90
  /** JSDoc */
106
91
  (function (Severity) {
107
92
  /** JSDoc */
@@ -941,37 +926,6 @@ var Sentry = (function (exports) {
941
926
  return truncate(serialized, maxLength);
942
927
  }
943
928
  return '';
944
- }
945
- /**
946
- * Given any object, return the new object with removed keys that value was `undefined`.
947
- * Works recursively on objects and arrays.
948
- */
949
- function dropUndefinedKeys(val) {
950
- var e_1, _a;
951
- if (isPlainObject(val)) {
952
- var obj = val;
953
- var rv = {};
954
- try {
955
- for (var _b = __values(Object.keys(obj)), _c = _b.next(); !_c.done; _c = _b.next()) {
956
- var key = _c.value;
957
- if (typeof obj[key] !== 'undefined') {
958
- rv[key] = dropUndefinedKeys(obj[key]);
959
- }
960
- }
961
- }
962
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
963
- finally {
964
- try {
965
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
966
- }
967
- finally { if (e_1) throw e_1.error; }
968
- }
969
- return rv;
970
- }
971
- if (Array.isArray(val)) {
972
- return val.map(dropUndefinedKeys);
973
- }
974
- return val;
975
929
  }
976
930
 
977
931
  /**
@@ -1008,13 +962,6 @@ var Sentry = (function (exports) {
1008
962
  ? self
1009
963
  : fallbackGlobalObject);
1010
964
  }
1011
- /**
1012
- * Determines if running in react native
1013
- */
1014
- function isReactNative() {
1015
- var _a;
1016
- return ((_a = getGlobalObject().navigator) === null || _a === void 0 ? void 0 : _a.product) === 'ReactNative';
1017
- }
1018
965
  /**
1019
966
  * UUID4 generator
1020
967
  *
@@ -1167,73 +1114,6 @@ var Sentry = (function (exports) {
1167
1114
  return '';
1168
1115
  }
1169
1116
  }
1170
- var INITIAL_TIME = Date.now();
1171
- var prevNow = 0;
1172
- var performanceFallback = {
1173
- now: function () {
1174
- var now = Date.now() - INITIAL_TIME;
1175
- if (now < prevNow) {
1176
- now = prevNow;
1177
- }
1178
- prevNow = now;
1179
- return now;
1180
- },
1181
- timeOrigin: INITIAL_TIME,
1182
- };
1183
- /**
1184
- * Performance wrapper for react native as performance.now() has been found to start off with an unusual offset.
1185
- */
1186
- function getReactNativePerformanceWrapper() {
1187
- // Performance only available >= RN 0.63
1188
- var performance = getGlobalObject().performance;
1189
- if (performance && typeof performance.now === 'function') {
1190
- var INITIAL_OFFSET_1 = performance.now();
1191
- return {
1192
- now: function () {
1193
- return performance.now() - INITIAL_OFFSET_1;
1194
- },
1195
- timeOrigin: INITIAL_TIME,
1196
- };
1197
- }
1198
- return performanceFallback;
1199
- }
1200
- var crossPlatformPerformance = (function () {
1201
- // React Native's performance.now() starts with a gigantic offset, so we need to wrap it.
1202
- if (isReactNative()) {
1203
- return getReactNativePerformanceWrapper();
1204
- }
1205
- if (isNodeEnv()) {
1206
- try {
1207
- var perfHooks = dynamicRequire(module, 'perf_hooks');
1208
- return perfHooks.performance;
1209
- }
1210
- catch (_) {
1211
- return performanceFallback;
1212
- }
1213
- }
1214
- var performance = getGlobalObject().performance;
1215
- if (!performance || !performance.now) {
1216
- return performanceFallback;
1217
- }
1218
- // Polyfill for performance.timeOrigin.
1219
- //
1220
- // While performance.timing.navigationStart is deprecated in favor of performance.timeOrigin, performance.timeOrigin
1221
- // is not as widely supported. Namely, performance.timeOrigin is undefined in Safari as of writing.
1222
- if (performance.timeOrigin === undefined) {
1223
- // As of writing, performance.timing is not available in Web Workers in mainstream browsers, so it is not always a
1224
- // valid fallback. In the absence of a initial time provided by the browser, fallback to INITIAL_TIME.
1225
- // @ts-ignore ignored because timeOrigin is a readonly property but we want to override
1226
- // eslint-disable-next-line deprecation/deprecation
1227
- performance.timeOrigin = (performance.timing && performance.timing.navigationStart) || INITIAL_TIME;
1228
- }
1229
- return performance;
1230
- })();
1231
- /**
1232
- * Returns a timestamp in seconds with milliseconds precision since the UNIX epoch calculated with the monotonic clock.
1233
- */
1234
- function timestampWithMs() {
1235
- return (crossPlatformPerformance.timeOrigin + crossPlatformPerformance.now()) / 1000;
1236
- }
1237
1117
  var defaultRetryAfter = 60 * 1000; // 60 seconds
1238
1118
  /**
1239
1119
  * Extracts Retry-After value from the request header or returns default value
@@ -1319,363 +1199,88 @@ var Sentry = (function (exports) {
1319
1199
  global$1.__SENTRY__ = global$1.__SENTRY__ || {};
1320
1200
  var logger = global$1.__SENTRY__.logger || (global$1.__SENTRY__.logger = new Logger());
1321
1201
 
1322
- /* eslint-disable @typescript-eslint/explicit-function-return-type */
1323
- /** SyncPromise internal states */
1324
- var States;
1325
- (function (States) {
1326
- /** Pending */
1327
- States["PENDING"] = "PENDING";
1328
- /** Resolved / OK */
1329
- States["RESOLVED"] = "RESOLVED";
1330
- /** Rejected / Error */
1331
- States["REJECTED"] = "REJECTED";
1332
- })(States || (States = {}));
1333
1202
  /**
1334
- * Thenable class that behaves like a Promise and follows it's interface
1335
- * but is not async internally
1203
+ * Tells whether current environment supports Fetch API
1204
+ * {@link supportsFetch}.
1205
+ *
1206
+ * @returns Answer to the given question.
1336
1207
  */
1337
- var SyncPromise = /** @class */ (function () {
1338
- function SyncPromise(executor) {
1339
- var _this = this;
1340
- this._state = States.PENDING;
1341
- this._handlers = [];
1342
- /** JSDoc */
1343
- this._resolve = function (value) {
1344
- _this._setResult(States.RESOLVED, value);
1345
- };
1346
- /** JSDoc */
1347
- this._reject = function (reason) {
1348
- _this._setResult(States.REJECTED, reason);
1349
- };
1350
- /** JSDoc */
1351
- this._setResult = function (state, value) {
1352
- if (_this._state !== States.PENDING) {
1353
- return;
1354
- }
1355
- if (isThenable(value)) {
1356
- value.then(_this._resolve, _this._reject);
1357
- return;
1358
- }
1359
- _this._state = state;
1360
- _this._value = value;
1361
- _this._executeHandlers();
1362
- };
1363
- // TODO: FIXME
1364
- /** JSDoc */
1365
- this._attachHandler = function (handler) {
1366
- _this._handlers = _this._handlers.concat(handler);
1367
- _this._executeHandlers();
1368
- };
1369
- /** JSDoc */
1370
- this._executeHandlers = function () {
1371
- if (_this._state === States.PENDING) {
1372
- return;
1373
- }
1374
- var cachedHandlers = _this._handlers.slice();
1375
- _this._handlers = [];
1376
- cachedHandlers.forEach(function (handler) {
1377
- if (handler.done) {
1378
- return;
1379
- }
1380
- if (_this._state === States.RESOLVED) {
1381
- if (handler.onfulfilled) {
1382
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
1383
- handler.onfulfilled(_this._value);
1384
- }
1385
- }
1386
- if (_this._state === States.REJECTED) {
1387
- if (handler.onrejected) {
1388
- handler.onrejected(_this._value);
1389
- }
1390
- }
1391
- handler.done = true;
1392
- });
1393
- };
1208
+ function supportsFetch() {
1209
+ if (!('fetch' in getGlobalObject())) {
1210
+ return false;
1211
+ }
1212
+ try {
1213
+ new Headers();
1214
+ new Request('');
1215
+ new Response();
1216
+ return true;
1217
+ }
1218
+ catch (e) {
1219
+ return false;
1220
+ }
1221
+ }
1222
+ /**
1223
+ * isNativeFetch checks if the given function is a native implementation of fetch()
1224
+ */
1225
+ // eslint-disable-next-line @typescript-eslint/ban-types
1226
+ function isNativeFetch(func) {
1227
+ return func && /^function fetch\(\)\s+\{\s+\[native code\]\s+\}$/.test(func.toString());
1228
+ }
1229
+ /**
1230
+ * Tells whether current environment supports Fetch API natively
1231
+ * {@link supportsNativeFetch}.
1232
+ *
1233
+ * @returns true if `window.fetch` is natively implemented, false otherwise
1234
+ */
1235
+ function supportsNativeFetch() {
1236
+ if (!supportsFetch()) {
1237
+ return false;
1238
+ }
1239
+ var global = getGlobalObject();
1240
+ // Fast path to avoid DOM I/O
1241
+ // eslint-disable-next-line @typescript-eslint/unbound-method
1242
+ if (isNativeFetch(global.fetch)) {
1243
+ return true;
1244
+ }
1245
+ // window.fetch is implemented, but is polyfilled or already wrapped (e.g: by a chrome extension)
1246
+ // so create a "pure" iframe to see if that has native fetch
1247
+ var result = false;
1248
+ var doc = global.document;
1249
+ // eslint-disable-next-line deprecation/deprecation
1250
+ if (doc && typeof doc.createElement === "function") {
1394
1251
  try {
1395
- executor(this._resolve, this._reject);
1252
+ var sandbox = doc.createElement('iframe');
1253
+ sandbox.hidden = true;
1254
+ doc.head.appendChild(sandbox);
1255
+ if (sandbox.contentWindow && sandbox.contentWindow.fetch) {
1256
+ // eslint-disable-next-line @typescript-eslint/unbound-method
1257
+ result = isNativeFetch(sandbox.contentWindow.fetch);
1258
+ }
1259
+ doc.head.removeChild(sandbox);
1396
1260
  }
1397
- catch (e) {
1398
- this._reject(e);
1261
+ catch (err) {
1262
+ logger.warn('Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ', err);
1399
1263
  }
1400
1264
  }
1401
- /** JSDoc */
1402
- SyncPromise.resolve = function (value) {
1403
- return new SyncPromise(function (resolve) {
1404
- resolve(value);
1405
- });
1406
- };
1407
- /** JSDoc */
1408
- SyncPromise.reject = function (reason) {
1409
- return new SyncPromise(function (_, reject) {
1410
- reject(reason);
1411
- });
1412
- };
1413
- /** JSDoc */
1414
- SyncPromise.all = function (collection) {
1415
- return new SyncPromise(function (resolve, reject) {
1416
- if (!Array.isArray(collection)) {
1417
- reject(new TypeError("Promise.all requires an array as input."));
1418
- return;
1419
- }
1420
- if (collection.length === 0) {
1421
- resolve([]);
1422
- return;
1423
- }
1424
- var counter = collection.length;
1425
- var resolvedCollection = [];
1426
- collection.forEach(function (item, index) {
1427
- SyncPromise.resolve(item)
1428
- .then(function (value) {
1429
- resolvedCollection[index] = value;
1430
- counter -= 1;
1431
- if (counter !== 0) {
1432
- return;
1433
- }
1434
- resolve(resolvedCollection);
1435
- })
1436
- .then(null, reject);
1437
- });
1438
- });
1439
- };
1440
- /** JSDoc */
1441
- SyncPromise.prototype.then = function (onfulfilled, onrejected) {
1442
- var _this = this;
1443
- return new SyncPromise(function (resolve, reject) {
1444
- _this._attachHandler({
1445
- done: false,
1446
- onfulfilled: function (result) {
1447
- if (!onfulfilled) {
1448
- // TODO: ¯\_(ツ)_/¯
1449
- // TODO: FIXME
1450
- resolve(result);
1451
- return;
1452
- }
1453
- try {
1454
- resolve(onfulfilled(result));
1455
- return;
1456
- }
1457
- catch (e) {
1458
- reject(e);
1459
- return;
1460
- }
1461
- },
1462
- onrejected: function (reason) {
1463
- if (!onrejected) {
1464
- reject(reason);
1465
- return;
1466
- }
1467
- try {
1468
- resolve(onrejected(reason));
1469
- return;
1470
- }
1471
- catch (e) {
1472
- reject(e);
1473
- return;
1474
- }
1475
- },
1476
- });
1477
- });
1478
- };
1479
- /** JSDoc */
1480
- SyncPromise.prototype.catch = function (onrejected) {
1481
- return this.then(function (val) { return val; }, onrejected);
1482
- };
1483
- /** JSDoc */
1484
- SyncPromise.prototype.finally = function (onfinally) {
1485
- var _this = this;
1486
- return new SyncPromise(function (resolve, reject) {
1487
- var val;
1488
- var isRejected;
1489
- return _this.then(function (value) {
1490
- isRejected = false;
1491
- val = value;
1492
- if (onfinally) {
1493
- onfinally();
1494
- }
1495
- }, function (reason) {
1496
- isRejected = true;
1497
- val = reason;
1498
- if (onfinally) {
1499
- onfinally();
1500
- }
1501
- }).then(function () {
1502
- if (isRejected) {
1503
- reject(val);
1504
- return;
1505
- }
1506
- resolve(val);
1507
- });
1508
- });
1509
- };
1510
- /** JSDoc */
1511
- SyncPromise.prototype.toString = function () {
1512
- return '[object SyncPromise]';
1513
- };
1514
- return SyncPromise;
1515
- }());
1516
-
1517
- /** A simple queue that holds promises. */
1518
- var PromiseBuffer = /** @class */ (function () {
1519
- function PromiseBuffer(_limit) {
1520
- this._limit = _limit;
1521
- /** Internal set of queued Promises */
1522
- this._buffer = [];
1523
- }
1524
- /**
1525
- * Says if the buffer is ready to take more requests
1526
- */
1527
- PromiseBuffer.prototype.isReady = function () {
1528
- return this._limit === undefined || this.length() < this._limit;
1529
- };
1530
- /**
1531
- * Add a promise to the queue.
1532
- *
1533
- * @param task Can be any PromiseLike<T>
1534
- * @returns The original promise.
1535
- */
1536
- PromiseBuffer.prototype.add = function (task) {
1537
- var _this = this;
1538
- if (!this.isReady()) {
1539
- return SyncPromise.reject(new SentryError('Not adding Promise due to buffer limit reached.'));
1540
- }
1541
- if (this._buffer.indexOf(task) === -1) {
1542
- this._buffer.push(task);
1543
- }
1544
- task
1545
- .then(function () { return _this.remove(task); })
1546
- .then(null, function () {
1547
- return _this.remove(task).then(null, function () {
1548
- // We have to add this catch here otherwise we have an unhandledPromiseRejection
1549
- // because it's a new Promise chain.
1550
- });
1551
- });
1552
- return task;
1553
- };
1554
- /**
1555
- * Remove a promise to the queue.
1556
- *
1557
- * @param task Can be any PromiseLike<T>
1558
- * @returns Removed promise.
1559
- */
1560
- PromiseBuffer.prototype.remove = function (task) {
1561
- var removedTask = this._buffer.splice(this._buffer.indexOf(task), 1)[0];
1562
- return removedTask;
1563
- };
1564
- /**
1565
- * This function returns the number of unresolved promises in the queue.
1566
- */
1567
- PromiseBuffer.prototype.length = function () {
1568
- return this._buffer.length;
1569
- };
1570
- /**
1571
- * This will drain the whole queue, returns true if queue is empty or drained.
1572
- * If timeout is provided and the queue takes longer to drain, the promise still resolves but with false.
1573
- *
1574
- * @param timeout Number in ms to wait until it resolves with false.
1575
- */
1576
- PromiseBuffer.prototype.drain = function (timeout) {
1577
- var _this = this;
1578
- return new SyncPromise(function (resolve) {
1579
- var capturedSetTimeout = setTimeout(function () {
1580
- if (timeout && timeout > 0) {
1581
- resolve(false);
1582
- }
1583
- }, timeout);
1584
- SyncPromise.all(_this._buffer)
1585
- .then(function () {
1586
- clearTimeout(capturedSetTimeout);
1587
- resolve(true);
1588
- })
1589
- .then(null, function () {
1590
- resolve(true);
1591
- });
1592
- });
1593
- };
1594
- return PromiseBuffer;
1595
- }());
1596
-
1597
- /**
1598
- * Tells whether current environment supports Fetch API
1599
- * {@link supportsFetch}.
1600
- *
1601
- * @returns Answer to the given question.
1602
- */
1603
- function supportsFetch() {
1604
- if (!('fetch' in getGlobalObject())) {
1605
- return false;
1606
- }
1607
- try {
1608
- new Headers();
1609
- new Request('');
1610
- new Response();
1611
- return true;
1612
- }
1613
- catch (e) {
1614
- return false;
1615
- }
1616
- }
1617
- /**
1618
- * isNativeFetch checks if the given function is a native implementation of fetch()
1619
- */
1620
- // eslint-disable-next-line @typescript-eslint/ban-types
1621
- function isNativeFetch(func) {
1622
- return func && /^function fetch\(\)\s+\{\s+\[native code\]\s+\}$/.test(func.toString());
1623
- }
1624
- /**
1625
- * Tells whether current environment supports Fetch API natively
1626
- * {@link supportsNativeFetch}.
1627
- *
1628
- * @returns true if `window.fetch` is natively implemented, false otherwise
1629
- */
1630
- function supportsNativeFetch() {
1631
- if (!supportsFetch()) {
1632
- return false;
1633
- }
1634
- var global = getGlobalObject();
1635
- // Fast path to avoid DOM I/O
1636
- // eslint-disable-next-line @typescript-eslint/unbound-method
1637
- if (isNativeFetch(global.fetch)) {
1638
- return true;
1639
- }
1640
- // window.fetch is implemented, but is polyfilled or already wrapped (e.g: by a chrome extension)
1641
- // so create a "pure" iframe to see if that has native fetch
1642
- var result = false;
1643
- var doc = global.document;
1644
- // eslint-disable-next-line deprecation/deprecation
1645
- if (doc && typeof doc.createElement === "function") {
1646
- try {
1647
- var sandbox = doc.createElement('iframe');
1648
- sandbox.hidden = true;
1649
- doc.head.appendChild(sandbox);
1650
- if (sandbox.contentWindow && sandbox.contentWindow.fetch) {
1651
- // eslint-disable-next-line @typescript-eslint/unbound-method
1652
- result = isNativeFetch(sandbox.contentWindow.fetch);
1653
- }
1654
- doc.head.removeChild(sandbox);
1655
- }
1656
- catch (err) {
1657
- logger.warn('Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ', err);
1658
- }
1659
- }
1660
- return result;
1661
- }
1662
- /**
1663
- * Tells whether current environment supports Referrer Policy API
1664
- * {@link supportsReferrerPolicy}.
1665
- *
1666
- * @returns Answer to the given question.
1667
- */
1668
- function supportsReferrerPolicy() {
1669
- // Despite all stars in the sky saying that Edge supports old draft syntax, aka 'never', 'always', 'origin' and 'default
1670
- // https://caniuse.com/#feat=referrer-policy
1671
- // It doesn't. And it throw exception instead of ignoring this parameter...
1672
- // REF: https://github.com/getsentry/raven-js/issues/1233
1673
- if (!supportsFetch()) {
1674
- return false;
1675
- }
1676
- try {
1677
- new Request('_', {
1678
- referrerPolicy: 'origin',
1265
+ return result;
1266
+ }
1267
+ /**
1268
+ * Tells whether current environment supports Referrer Policy API
1269
+ * {@link supportsReferrerPolicy}.
1270
+ *
1271
+ * @returns Answer to the given question.
1272
+ */
1273
+ function supportsReferrerPolicy() {
1274
+ // Despite all stars in the sky saying that Edge supports old draft syntax, aka 'never', 'always', 'origin' and 'default
1275
+ // https://caniuse.com/#feat=referrer-policy
1276
+ // It doesn't. And it throw exception instead of ignoring this parameter...
1277
+ // REF: https://github.com/getsentry/raven-js/issues/1233
1278
+ if (!supportsFetch()) {
1279
+ return false;
1280
+ }
1281
+ try {
1282
+ new Request('_', {
1283
+ referrerPolicy: 'origin',
1679
1284
  });
1680
1285
  return true;
1681
1286
  }
@@ -1821,7 +1426,7 @@ var Sentry = (function (exports) {
1821
1426
  for (var _i = 0; _i < arguments.length; _i++) {
1822
1427
  args[_i] = arguments[_i];
1823
1428
  }
1824
- var commonHandlerData = {
1429
+ var handlerData = {
1825
1430
  args: args,
1826
1431
  fetchData: {
1827
1432
  method: getFetchMethod(args),
@@ -1829,13 +1434,13 @@ var Sentry = (function (exports) {
1829
1434
  },
1830
1435
  startTimestamp: Date.now(),
1831
1436
  };
1832
- triggerHandlers('fetch', __assign({}, commonHandlerData));
1437
+ triggerHandlers('fetch', __assign({}, handlerData));
1833
1438
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
1834
1439
  return originalFetch.apply(global$2, args).then(function (response) {
1835
- triggerHandlers('fetch', __assign(__assign({}, commonHandlerData), { endTimestamp: Date.now(), response: response }));
1440
+ triggerHandlers('fetch', __assign(__assign({}, handlerData), { endTimestamp: Date.now(), response: response }));
1836
1441
  return response;
1837
1442
  }, function (error) {
1838
- triggerHandlers('fetch', __assign(__assign({}, commonHandlerData), { endTimestamp: Date.now(), error: error }));
1443
+ triggerHandlers('fetch', __assign(__assign({}, handlerData), { endTimestamp: Date.now(), error: error }));
1839
1444
  // NOTE: If you are a Sentry user, and you are seeing this stack frame,
1840
1445
  // it means the sentry.javascript SDK caught an error invoking your application code.
1841
1446
  // This is expected behavior and NOT indicative of a bug with sentry.javascript.
@@ -1873,7 +1478,7 @@ var Sentry = (function (exports) {
1873
1478
  if (!('XMLHttpRequest' in global$2)) {
1874
1479
  return;
1875
1480
  }
1876
- // Poor man implementation of ES6 `Map` by tracking and keeping in sync key and value separately.
1481
+ // Poor man's implementation of ES6 `Map`, tracking and keeping in sync key and value separately.
1877
1482
  var requestKeys = [];
1878
1483
  var requestValues = [];
1879
1484
  var xhrproto = XMLHttpRequest.prototype;
@@ -1911,7 +1516,7 @@ var Sentry = (function (exports) {
1911
1516
  try {
1912
1517
  var requestPos = requestKeys.indexOf(xhr);
1913
1518
  if (requestPos !== -1) {
1914
- // Make sure to pop both, key and value to keep it in sync.
1519
+ // Make sure to pop both key and value to keep it in sync.
1915
1520
  requestKeys.splice(requestPos);
1916
1521
  var args_1 = requestValues.splice(requestPos)[0];
1917
1522
  if (xhr.__sentry_xhr__ && args_1[0] !== undefined) {
@@ -2116,75 +1721,457 @@ var Sentry = (function (exports) {
2116
1721
  };
2117
1722
  }
2118
1723
  /**
2119
- * Wraps addEventListener to capture keypress UI events
2120
- * @param handler function that will be triggered
2121
- * @returns wrapped keypress events handler
2122
- * @hidden
1724
+ * Wraps addEventListener to capture keypress UI events
1725
+ * @param handler function that will be triggered
1726
+ * @returns wrapped keypress events handler
1727
+ * @hidden
1728
+ */
1729
+ function keypressEventHandler(handler) {
1730
+ // TODO: if somehow user switches keypress target before
1731
+ // debounce timeout is triggered, we will only capture
1732
+ // a single breadcrumb from the FIRST target (acceptable?)
1733
+ return function (event) {
1734
+ var target;
1735
+ try {
1736
+ target = event.target;
1737
+ }
1738
+ catch (e) {
1739
+ // just accessing event properties can throw an exception in some rare circumstances
1740
+ // see: https://github.com/getsentry/raven-js/issues/838
1741
+ return;
1742
+ }
1743
+ var tagName = target && target.tagName;
1744
+ // only consider keypress events on actual input elements
1745
+ // this will disregard keypresses targeting body (e.g. tabbing
1746
+ // through elements, hotkeys, etc)
1747
+ if (!tagName || (tagName !== 'INPUT' && tagName !== 'TEXTAREA' && !target.isContentEditable)) {
1748
+ return;
1749
+ }
1750
+ // record first keypress in a series, but ignore subsequent
1751
+ // keypresses until debounce clears
1752
+ if (!keypressTimeout) {
1753
+ domEventHandler('input', handler)(event);
1754
+ }
1755
+ clearTimeout(keypressTimeout);
1756
+ keypressTimeout = setTimeout(function () {
1757
+ keypressTimeout = undefined;
1758
+ }, debounceDuration);
1759
+ };
1760
+ }
1761
+ var _oldOnErrorHandler = null;
1762
+ /** JSDoc */
1763
+ function instrumentError() {
1764
+ _oldOnErrorHandler = global$2.onerror;
1765
+ global$2.onerror = function (msg, url, line, column, error) {
1766
+ triggerHandlers('error', {
1767
+ column: column,
1768
+ error: error,
1769
+ line: line,
1770
+ msg: msg,
1771
+ url: url,
1772
+ });
1773
+ if (_oldOnErrorHandler) {
1774
+ // eslint-disable-next-line prefer-rest-params
1775
+ return _oldOnErrorHandler.apply(this, arguments);
1776
+ }
1777
+ return false;
1778
+ };
1779
+ }
1780
+ var _oldOnUnhandledRejectionHandler = null;
1781
+ /** JSDoc */
1782
+ function instrumentUnhandledRejection() {
1783
+ _oldOnUnhandledRejectionHandler = global$2.onunhandledrejection;
1784
+ global$2.onunhandledrejection = function (e) {
1785
+ triggerHandlers('unhandledrejection', e);
1786
+ if (_oldOnUnhandledRejectionHandler) {
1787
+ // eslint-disable-next-line prefer-rest-params
1788
+ return _oldOnUnhandledRejectionHandler.apply(this, arguments);
1789
+ }
1790
+ return true;
1791
+ };
1792
+ }
1793
+
1794
+ /* eslint-disable @typescript-eslint/explicit-function-return-type */
1795
+ /** SyncPromise internal states */
1796
+ var States;
1797
+ (function (States) {
1798
+ /** Pending */
1799
+ States["PENDING"] = "PENDING";
1800
+ /** Resolved / OK */
1801
+ States["RESOLVED"] = "RESOLVED";
1802
+ /** Rejected / Error */
1803
+ States["REJECTED"] = "REJECTED";
1804
+ })(States || (States = {}));
1805
+ /**
1806
+ * Thenable class that behaves like a Promise and follows it's interface
1807
+ * but is not async internally
1808
+ */
1809
+ var SyncPromise = /** @class */ (function () {
1810
+ function SyncPromise(executor) {
1811
+ var _this = this;
1812
+ this._state = States.PENDING;
1813
+ this._handlers = [];
1814
+ /** JSDoc */
1815
+ this._resolve = function (value) {
1816
+ _this._setResult(States.RESOLVED, value);
1817
+ };
1818
+ /** JSDoc */
1819
+ this._reject = function (reason) {
1820
+ _this._setResult(States.REJECTED, reason);
1821
+ };
1822
+ /** JSDoc */
1823
+ this._setResult = function (state, value) {
1824
+ if (_this._state !== States.PENDING) {
1825
+ return;
1826
+ }
1827
+ if (isThenable(value)) {
1828
+ value.then(_this._resolve, _this._reject);
1829
+ return;
1830
+ }
1831
+ _this._state = state;
1832
+ _this._value = value;
1833
+ _this._executeHandlers();
1834
+ };
1835
+ // TODO: FIXME
1836
+ /** JSDoc */
1837
+ this._attachHandler = function (handler) {
1838
+ _this._handlers = _this._handlers.concat(handler);
1839
+ _this._executeHandlers();
1840
+ };
1841
+ /** JSDoc */
1842
+ this._executeHandlers = function () {
1843
+ if (_this._state === States.PENDING) {
1844
+ return;
1845
+ }
1846
+ var cachedHandlers = _this._handlers.slice();
1847
+ _this._handlers = [];
1848
+ cachedHandlers.forEach(function (handler) {
1849
+ if (handler.done) {
1850
+ return;
1851
+ }
1852
+ if (_this._state === States.RESOLVED) {
1853
+ if (handler.onfulfilled) {
1854
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
1855
+ handler.onfulfilled(_this._value);
1856
+ }
1857
+ }
1858
+ if (_this._state === States.REJECTED) {
1859
+ if (handler.onrejected) {
1860
+ handler.onrejected(_this._value);
1861
+ }
1862
+ }
1863
+ handler.done = true;
1864
+ });
1865
+ };
1866
+ try {
1867
+ executor(this._resolve, this._reject);
1868
+ }
1869
+ catch (e) {
1870
+ this._reject(e);
1871
+ }
1872
+ }
1873
+ /** JSDoc */
1874
+ SyncPromise.resolve = function (value) {
1875
+ return new SyncPromise(function (resolve) {
1876
+ resolve(value);
1877
+ });
1878
+ };
1879
+ /** JSDoc */
1880
+ SyncPromise.reject = function (reason) {
1881
+ return new SyncPromise(function (_, reject) {
1882
+ reject(reason);
1883
+ });
1884
+ };
1885
+ /** JSDoc */
1886
+ SyncPromise.all = function (collection) {
1887
+ return new SyncPromise(function (resolve, reject) {
1888
+ if (!Array.isArray(collection)) {
1889
+ reject(new TypeError("Promise.all requires an array as input."));
1890
+ return;
1891
+ }
1892
+ if (collection.length === 0) {
1893
+ resolve([]);
1894
+ return;
1895
+ }
1896
+ var counter = collection.length;
1897
+ var resolvedCollection = [];
1898
+ collection.forEach(function (item, index) {
1899
+ SyncPromise.resolve(item)
1900
+ .then(function (value) {
1901
+ resolvedCollection[index] = value;
1902
+ counter -= 1;
1903
+ if (counter !== 0) {
1904
+ return;
1905
+ }
1906
+ resolve(resolvedCollection);
1907
+ })
1908
+ .then(null, reject);
1909
+ });
1910
+ });
1911
+ };
1912
+ /** JSDoc */
1913
+ SyncPromise.prototype.then = function (onfulfilled, onrejected) {
1914
+ var _this = this;
1915
+ return new SyncPromise(function (resolve, reject) {
1916
+ _this._attachHandler({
1917
+ done: false,
1918
+ onfulfilled: function (result) {
1919
+ if (!onfulfilled) {
1920
+ // TODO: ¯\_(ツ)_/¯
1921
+ // TODO: FIXME
1922
+ resolve(result);
1923
+ return;
1924
+ }
1925
+ try {
1926
+ resolve(onfulfilled(result));
1927
+ return;
1928
+ }
1929
+ catch (e) {
1930
+ reject(e);
1931
+ return;
1932
+ }
1933
+ },
1934
+ onrejected: function (reason) {
1935
+ if (!onrejected) {
1936
+ reject(reason);
1937
+ return;
1938
+ }
1939
+ try {
1940
+ resolve(onrejected(reason));
1941
+ return;
1942
+ }
1943
+ catch (e) {
1944
+ reject(e);
1945
+ return;
1946
+ }
1947
+ },
1948
+ });
1949
+ });
1950
+ };
1951
+ /** JSDoc */
1952
+ SyncPromise.prototype.catch = function (onrejected) {
1953
+ return this.then(function (val) { return val; }, onrejected);
1954
+ };
1955
+ /** JSDoc */
1956
+ SyncPromise.prototype.finally = function (onfinally) {
1957
+ var _this = this;
1958
+ return new SyncPromise(function (resolve, reject) {
1959
+ var val;
1960
+ var isRejected;
1961
+ return _this.then(function (value) {
1962
+ isRejected = false;
1963
+ val = value;
1964
+ if (onfinally) {
1965
+ onfinally();
1966
+ }
1967
+ }, function (reason) {
1968
+ isRejected = true;
1969
+ val = reason;
1970
+ if (onfinally) {
1971
+ onfinally();
1972
+ }
1973
+ }).then(function () {
1974
+ if (isRejected) {
1975
+ reject(val);
1976
+ return;
1977
+ }
1978
+ resolve(val);
1979
+ });
1980
+ });
1981
+ };
1982
+ /** JSDoc */
1983
+ SyncPromise.prototype.toString = function () {
1984
+ return '[object SyncPromise]';
1985
+ };
1986
+ return SyncPromise;
1987
+ }());
1988
+
1989
+ /** A simple queue that holds promises. */
1990
+ var PromiseBuffer = /** @class */ (function () {
1991
+ function PromiseBuffer(_limit) {
1992
+ this._limit = _limit;
1993
+ /** Internal set of queued Promises */
1994
+ this._buffer = [];
1995
+ }
1996
+ /**
1997
+ * Says if the buffer is ready to take more requests
1998
+ */
1999
+ PromiseBuffer.prototype.isReady = function () {
2000
+ return this._limit === undefined || this.length() < this._limit;
2001
+ };
2002
+ /**
2003
+ * Add a promise to the queue.
2004
+ *
2005
+ * @param task Can be any PromiseLike<T>
2006
+ * @returns The original promise.
2007
+ */
2008
+ PromiseBuffer.prototype.add = function (task) {
2009
+ var _this = this;
2010
+ if (!this.isReady()) {
2011
+ return SyncPromise.reject(new SentryError('Not adding Promise due to buffer limit reached.'));
2012
+ }
2013
+ if (this._buffer.indexOf(task) === -1) {
2014
+ this._buffer.push(task);
2015
+ }
2016
+ task
2017
+ .then(function () { return _this.remove(task); })
2018
+ .then(null, function () {
2019
+ return _this.remove(task).then(null, function () {
2020
+ // We have to add this catch here otherwise we have an unhandledPromiseRejection
2021
+ // because it's a new Promise chain.
2022
+ });
2023
+ });
2024
+ return task;
2025
+ };
2026
+ /**
2027
+ * Remove a promise to the queue.
2028
+ *
2029
+ * @param task Can be any PromiseLike<T>
2030
+ * @returns Removed promise.
2031
+ */
2032
+ PromiseBuffer.prototype.remove = function (task) {
2033
+ var removedTask = this._buffer.splice(this._buffer.indexOf(task), 1)[0];
2034
+ return removedTask;
2035
+ };
2036
+ /**
2037
+ * This function returns the number of unresolved promises in the queue.
2038
+ */
2039
+ PromiseBuffer.prototype.length = function () {
2040
+ return this._buffer.length;
2041
+ };
2042
+ /**
2043
+ * This will drain the whole queue, returns true if queue is empty or drained.
2044
+ * If timeout is provided and the queue takes longer to drain, the promise still resolves but with false.
2045
+ *
2046
+ * @param timeout Number in ms to wait until it resolves with false.
2047
+ */
2048
+ PromiseBuffer.prototype.drain = function (timeout) {
2049
+ var _this = this;
2050
+ return new SyncPromise(function (resolve) {
2051
+ var capturedSetTimeout = setTimeout(function () {
2052
+ if (timeout && timeout > 0) {
2053
+ resolve(false);
2054
+ }
2055
+ }, timeout);
2056
+ SyncPromise.all(_this._buffer)
2057
+ .then(function () {
2058
+ clearTimeout(capturedSetTimeout);
2059
+ resolve(true);
2060
+ })
2061
+ .then(null, function () {
2062
+ resolve(true);
2063
+ });
2064
+ });
2065
+ };
2066
+ return PromiseBuffer;
2067
+ }());
2068
+
2069
+ /**
2070
+ * A TimestampSource implementation for environments that do not support the Performance Web API natively.
2071
+ *
2072
+ * Note that this TimestampSource does not use a monotonic clock. A call to `nowSeconds` may return a timestamp earlier
2073
+ * than a previously returned value. We do not try to emulate a monotonic behavior in order to facilitate debugging. It
2074
+ * is more obvious to explain "why does my span have negative duration" than "why my spans have zero duration".
2075
+ */
2076
+ var dateTimestampSource = {
2077
+ nowSeconds: function () { return Date.now() / 1000; },
2078
+ };
2079
+ /**
2080
+ * Returns a wrapper around the native Performance API browser implementation, or undefined for browsers that do not
2081
+ * support the API.
2082
+ *
2083
+ * Wrapping the native API works around differences in behavior from different browsers.
2084
+ */
2085
+ function getBrowserPerformance() {
2086
+ var performance = getGlobalObject().performance;
2087
+ if (!performance || !performance.now) {
2088
+ return undefined;
2089
+ }
2090
+ // Replace performance.timeOrigin with our own timeOrigin based on Date.now().
2091
+ //
2092
+ // This is a partial workaround for browsers reporting performance.timeOrigin such that performance.timeOrigin +
2093
+ // performance.now() gives a date arbitrarily in the past.
2094
+ //
2095
+ // Additionally, computing timeOrigin in this way fills the gap for browsers where performance.timeOrigin is
2096
+ // undefined.
2097
+ //
2098
+ // The assumption that performance.timeOrigin + performance.now() ~= Date.now() is flawed, but we depend on it to
2099
+ // interact with data coming out of performance entries.
2100
+ //
2101
+ // Note that despite recommendations against it in the spec, browsers implement the Performance API with a clock that
2102
+ // might stop when the computer is asleep (and perhaps under other circumstances). Such behavior causes
2103
+ // performance.timeOrigin + performance.now() to have an arbitrary skew over Date.now(). In laptop computers, we have
2104
+ // observed skews that can be as long as days, weeks or months.
2105
+ //
2106
+ // See https://github.com/getsentry/sentry-javascript/issues/2590.
2107
+ //
2108
+ // BUG: despite our best intentions, this workaround has its limitations. It mostly addresses timings of pageload
2109
+ // transactions, but ignores the skew built up over time that can aversely affect timestamps of navigation
2110
+ // transactions of long-lived web pages.
2111
+ var timeOrigin = Date.now() - performance.now();
2112
+ return {
2113
+ now: function () { return performance.now(); },
2114
+ timeOrigin: timeOrigin,
2115
+ };
2116
+ }
2117
+ /**
2118
+ * Returns the native Performance API implementation from Node.js. Returns undefined in old Node.js versions that don't
2119
+ * implement the API.
2123
2120
  */
2124
- function keypressEventHandler(handler) {
2125
- // TODO: if somehow user switches keypress target before
2126
- // debounce timeout is triggered, we will only capture
2127
- // a single breadcrumb from the FIRST target (acceptable?)
2128
- return function (event) {
2129
- var target;
2130
- try {
2131
- target = event.target;
2132
- }
2133
- catch (e) {
2134
- // just accessing event properties can throw an exception in some rare circumstances
2135
- // see: https://github.com/getsentry/raven-js/issues/838
2136
- return;
2137
- }
2138
- var tagName = target && target.tagName;
2139
- // only consider keypress events on actual input elements
2140
- // this will disregard keypresses targeting body (e.g. tabbing
2141
- // through elements, hotkeys, etc)
2142
- if (!tagName || (tagName !== 'INPUT' && tagName !== 'TEXTAREA' && !target.isContentEditable)) {
2143
- return;
2144
- }
2145
- // record first keypress in a series, but ignore subsequent
2146
- // keypresses until debounce clears
2147
- if (!keypressTimeout) {
2148
- domEventHandler('input', handler)(event);
2149
- }
2150
- clearTimeout(keypressTimeout);
2151
- keypressTimeout = setTimeout(function () {
2152
- keypressTimeout = undefined;
2153
- }, debounceDuration);
2154
- };
2155
- }
2156
- var _oldOnErrorHandler = null;
2157
- /** JSDoc */
2158
- function instrumentError() {
2159
- _oldOnErrorHandler = global$2.onerror;
2160
- global$2.onerror = function (msg, url, line, column, error) {
2161
- triggerHandlers('error', {
2162
- column: column,
2163
- error: error,
2164
- line: line,
2165
- msg: msg,
2166
- url: url,
2167
- });
2168
- if (_oldOnErrorHandler) {
2169
- // eslint-disable-next-line prefer-rest-params
2170
- return _oldOnErrorHandler.apply(this, arguments);
2171
- }
2172
- return false;
2173
- };
2121
+ function getNodePerformance() {
2122
+ try {
2123
+ var perfHooks = dynamicRequire(module, 'perf_hooks');
2124
+ return perfHooks.performance;
2125
+ }
2126
+ catch (_) {
2127
+ return undefined;
2128
+ }
2174
2129
  }
2175
- var _oldOnUnhandledRejectionHandler = null;
2176
- /** JSDoc */
2177
- function instrumentUnhandledRejection() {
2178
- _oldOnUnhandledRejectionHandler = global$2.onunhandledrejection;
2179
- global$2.onunhandledrejection = function (e) {
2180
- triggerHandlers('unhandledrejection', e);
2181
- if (_oldOnUnhandledRejectionHandler) {
2182
- // eslint-disable-next-line prefer-rest-params
2183
- return _oldOnUnhandledRejectionHandler.apply(this, arguments);
2184
- }
2185
- return true;
2130
+ /**
2131
+ * The Performance API implementation for the current platform, if available.
2132
+ */
2133
+ var platformPerformance = isNodeEnv() ? getNodePerformance() : getBrowserPerformance();
2134
+ var timestampSource = platformPerformance === undefined
2135
+ ? dateTimestampSource
2136
+ : {
2137
+ nowSeconds: function () { return (platformPerformance.timeOrigin + platformPerformance.now()) / 1000; },
2186
2138
  };
2187
- }
2139
+ /**
2140
+ * Returns a timestamp in seconds since the UNIX epoch using the Date API.
2141
+ */
2142
+ var dateTimestampInSeconds = dateTimestampSource.nowSeconds.bind(dateTimestampSource);
2143
+ /**
2144
+ * Returns a timestamp in seconds since the UNIX epoch using either the Performance or Date APIs, depending on the
2145
+ * availability of the Performance API.
2146
+ *
2147
+ * See `usingPerformanceAPI` to test whether the Performance API is used.
2148
+ *
2149
+ * BUG: Note that because of how browsers implement the Performance API, the clock might stop when the computer is
2150
+ * asleep. This creates a skew between `dateTimestampInSeconds` and `timestampInSeconds`. The
2151
+ * skew can grow to arbitrary amounts like days, weeks or months.
2152
+ * See https://github.com/getsentry/sentry-javascript/issues/2590.
2153
+ */
2154
+ var timestampInSeconds = timestampSource.nowSeconds.bind(timestampSource);
2155
+ /**
2156
+ * The number of milliseconds since the UNIX epoch. This value is only usable in a browser, and only when the
2157
+ * performance API is available.
2158
+ */
2159
+ var browserPerformanceTimeOrigin = (function () {
2160
+ var performance = getGlobalObject().performance;
2161
+ if (!performance) {
2162
+ return undefined;
2163
+ }
2164
+ if (performance.timeOrigin) {
2165
+ return performance.timeOrigin;
2166
+ }
2167
+ // While performance.timing.navigationStart is deprecated in favor of performance.timeOrigin, performance.timeOrigin
2168
+ // is not as widely supported. Namely, performance.timeOrigin is undefined in Safari as of writing.
2169
+ // Also as of writing, performance.timing is not available in Web Workers in mainstream browsers, so it is not always
2170
+ // a valid fallback. In the absence of an initial time provided by the browser, fallback to the current time from the
2171
+ // Date API.
2172
+ // eslint-disable-next-line deprecation/deprecation
2173
+ return (performance.timing && performance.timing.navigationStart) || Date.now();
2174
+ })();
2188
2175
 
2189
2176
  /**
2190
2177
  * Holds additional event information. {@link Scope.applyToEvent} will be
@@ -2205,10 +2192,8 @@ var Sentry = (function (exports) {
2205
2192
  /** Tags */
2206
2193
  this._tags = {};
2207
2194
  /** Extra */
2208
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2209
2195
  this._extra = {};
2210
2196
  /** Contexts */
2211
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2212
2197
  this._contexts = {};
2213
2198
  }
2214
2199
  /**
@@ -2225,7 +2210,6 @@ var Sentry = (function (exports) {
2225
2210
  newScope._user = scope._user;
2226
2211
  newScope._level = scope._level;
2227
2212
  newScope._span = scope._span;
2228
- newScope._session = scope._session;
2229
2213
  newScope._transactionName = scope._transactionName;
2230
2214
  newScope._fingerprint = scope._fingerprint;
2231
2215
  newScope._eventProcessors = __spread(scope._eventProcessors);
@@ -2251,18 +2235,9 @@ var Sentry = (function (exports) {
2251
2235
  */
2252
2236
  Scope.prototype.setUser = function (user) {
2253
2237
  this._user = user || {};
2254
- if (this._session) {
2255
- this._session.update({ user: user });
2256
- }
2257
2238
  this._notifyScopeListeners();
2258
2239
  return this;
2259
2240
  };
2260
- /**
2261
- * @inheritDoc
2262
- */
2263
- Scope.prototype.getUser = function () {
2264
- return this._user;
2265
- };
2266
2241
  /**
2267
2242
  * @inheritDoc
2268
2243
  */
@@ -2331,10 +2306,15 @@ var Sentry = (function (exports) {
2331
2306
  /**
2332
2307
  * @inheritDoc
2333
2308
  */
2334
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2335
2309
  Scope.prototype.setContext = function (key, context) {
2336
2310
  var _a;
2337
- this._contexts = __assign(__assign({}, this._contexts), (_a = {}, _a[key] = context, _a));
2311
+ if (context === null) {
2312
+ // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
2313
+ delete this._contexts[key];
2314
+ }
2315
+ else {
2316
+ this._contexts = __assign(__assign({}, this._contexts), (_a = {}, _a[key] = context, _a));
2317
+ }
2338
2318
  this._notifyScopeListeners();
2339
2319
  return this;
2340
2320
  };
@@ -2356,31 +2336,20 @@ var Sentry = (function (exports) {
2356
2336
  * @inheritDoc
2357
2337
  */
2358
2338
  Scope.prototype.getTransaction = function () {
2339
+ var _a, _b, _c, _d;
2340
+ // often, this span will be a transaction, but it's not guaranteed to be
2359
2341
  var span = this.getSpan();
2360
- if (span && span.spanRecorder && span.spanRecorder.spans[0]) {
2342
+ // try it the new way first
2343
+ if ((_a = span) === null || _a === void 0 ? void 0 : _a.transaction) {
2344
+ return (_b = span) === null || _b === void 0 ? void 0 : _b.transaction;
2345
+ }
2346
+ // fallback to the old way (known bug: this only finds transactions with sampled = true)
2347
+ if ((_d = (_c = span) === null || _c === void 0 ? void 0 : _c.spanRecorder) === null || _d === void 0 ? void 0 : _d.spans[0]) {
2361
2348
  return span.spanRecorder.spans[0];
2362
2349
  }
2350
+ // neither way found a transaction
2363
2351
  return undefined;
2364
2352
  };
2365
- /**
2366
- * @inheritDoc
2367
- */
2368
- Scope.prototype.setSession = function (session) {
2369
- if (!session) {
2370
- delete this._session;
2371
- }
2372
- else {
2373
- this._session = session;
2374
- }
2375
- this._notifyScopeListeners();
2376
- return this;
2377
- };
2378
- /**
2379
- * @inheritDoc
2380
- */
2381
- Scope.prototype.getSession = function () {
2382
- return this._session;
2383
- };
2384
2353
  /**
2385
2354
  * @inheritDoc
2386
2355
  */
@@ -2437,7 +2406,6 @@ var Sentry = (function (exports) {
2437
2406
  this._transactionName = undefined;
2438
2407
  this._fingerprint = undefined;
2439
2408
  this._span = undefined;
2440
- this._session = undefined;
2441
2409
  this._notifyScopeListeners();
2442
2410
  return this;
2443
2411
  };
@@ -2445,7 +2413,7 @@ var Sentry = (function (exports) {
2445
2413
  * @inheritDoc
2446
2414
  */
2447
2415
  Scope.prototype.addBreadcrumb = function (breadcrumb, maxBreadcrumbs) {
2448
- var mergedBreadcrumb = __assign({ timestamp: timestampWithMs() }, breadcrumb);
2416
+ var mergedBreadcrumb = __assign({ timestamp: dateTimestampInSeconds() }, breadcrumb);
2449
2417
  this._breadcrumbs =
2450
2418
  maxBreadcrumbs !== undefined && maxBreadcrumbs >= 0
2451
2419
  ? __spread(this._breadcrumbs, [mergedBreadcrumb]).slice(-maxBreadcrumbs)
@@ -2579,96 +2547,6 @@ var Sentry = (function (exports) {
2579
2547
  getGlobalEventProcessors().push(callback);
2580
2548
  }
2581
2549
 
2582
- /**
2583
- * @inheritdoc
2584
- */
2585
- var Session = /** @class */ (function () {
2586
- function Session(context) {
2587
- this.errors = 0;
2588
- this.sid = uuid4();
2589
- this.timestamp = Date.now();
2590
- this.started = Date.now();
2591
- this.status = SessionStatus.Ok;
2592
- console.log('new session constructed'); // eslint-disable-line no-console
2593
- if (context) {
2594
- this.update(context);
2595
- }
2596
- }
2597
- /** JSDoc */
2598
- // eslint-disable-next-line complexity
2599
- Session.prototype.update = function (context) {
2600
- if (context.user) {
2601
- if (context.user.ip_address) {
2602
- this.ip_address = context.user.ip_address;
2603
- }
2604
- if (!context.did) {
2605
- this.did = context.user.id || context.user.email || context.user.username;
2606
- }
2607
- }
2608
- this.timestamp = context.timestamp || Date.now();
2609
- if (context.sid) {
2610
- // Good enough uuid validation for now
2611
- this.sid = context.sid.length === 32 ? context.sid : uuid4();
2612
- }
2613
- if (context.did) {
2614
- this.did = "" + context.did;
2615
- }
2616
- if (typeof context.started === 'number') {
2617
- this.started = context.started;
2618
- }
2619
- if (typeof context.duration === 'number') {
2620
- this.duration = context.duration;
2621
- }
2622
- if (context.release) {
2623
- this.release = context.release;
2624
- }
2625
- if (context.environment) {
2626
- this.environment = context.environment;
2627
- }
2628
- if (context.ip_address) {
2629
- this.ip_address = context.ip_address;
2630
- }
2631
- if (context.user_agent) {
2632
- this.user_agent = context.user_agent;
2633
- }
2634
- if (typeof context.errors === 'number') {
2635
- this.errors = context.errors;
2636
- }
2637
- if (context.status) {
2638
- this.status = context.status;
2639
- }
2640
- };
2641
- /** JSDoc */
2642
- Session.prototype.close = function (status) {
2643
- if (status) {
2644
- this.update({ status: status });
2645
- }
2646
- else if (this.status === SessionStatus.Ok) {
2647
- this.update({ status: SessionStatus.Exited });
2648
- }
2649
- };
2650
- /** JSDoc */
2651
- Session.prototype.toJSON = function () {
2652
- return dropUndefinedKeys({
2653
- sid: "" + this.sid,
2654
- init: true,
2655
- started: new Date(this.started).toISOString(),
2656
- timestamp: new Date(this.timestamp).toISOString(),
2657
- status: this.status,
2658
- errors: this.errors,
2659
- did: typeof this.did === 'number' || typeof this.did === 'string' ? "" + this.did : undefined,
2660
- duration: this.duration,
2661
- attrs: dropUndefinedKeys({
2662
- release: this.release,
2663
- environment: this.environment,
2664
- ip_address: this.ip_address,
2665
- user_agent: this.user_agent,
2666
- }),
2667
- });
2668
- };
2669
- return Session;
2670
- }());
2671
-
2672
2550
  /**
2673
2551
  * API compatibility version of this hub.
2674
2552
  *
@@ -2855,7 +2733,7 @@ var Sentry = (function (exports) {
2855
2733
  if (maxBreadcrumbs <= 0) {
2856
2734
  return;
2857
2735
  }
2858
- var timestamp = timestampWithMs();
2736
+ var timestamp = dateTimestampInSeconds();
2859
2737
  var mergedBreadcrumb = __assign({ timestamp: timestamp }, breadcrumb);
2860
2738
  var finalBreadcrumb = beforeBreadcrumb
2861
2739
  ? consoleSandbox(function () { return beforeBreadcrumb(mergedBreadcrumb, hint); })
@@ -2981,41 +2859,6 @@ var Sentry = (function (exports) {
2981
2859
  Hub.prototype.traceHeaders = function () {
2982
2860
  return this._callExtensionMethod('traceHeaders');
2983
2861
  };
2984
- /**
2985
- * @inheritDoc
2986
- */
2987
- Hub.prototype.startSession = function () {
2988
- var top = this.getStackTop();
2989
- if (!top.scope) {
2990
- return;
2991
- }
2992
- var client = top.client;
2993
- var _a = (client && client.getOptions()) || {}, release = _a.release, environment = _a.environment;
2994
- // End existing session if there's one
2995
- this.endSession();
2996
- top.scope.setSession(new Session({
2997
- release: release,
2998
- environment: environment,
2999
- user: top.scope.getUser(),
3000
- }));
3001
- };
3002
- /**
3003
- * @inheritDoc
3004
- */
3005
- Hub.prototype.endSession = function () {
3006
- var top = this.getStackTop();
3007
- if (!top.scope) {
3008
- return;
3009
- }
3010
- var session = top.scope.getSession();
3011
- if (session) {
3012
- session.close();
3013
- if (top.client) {
3014
- top.client.captureSession(session);
3015
- }
3016
- }
3017
- top.scope.setSession(undefined);
3018
- };
3019
2862
  /**
3020
2863
  * Internal helper function to call a method on the top client if it exists.
3021
2864
  *
@@ -3615,17 +3458,6 @@ var Sentry = (function (exports) {
3615
3458
  });
3616
3459
  return eventId;
3617
3460
  };
3618
- /**
3619
- * @inheritDoc
3620
- */
3621
- BaseClient.prototype.captureSession = function (session) {
3622
- if (!session.release) {
3623
- logger.warn('Discarded session update because of missing release');
3624
- }
3625
- else {
3626
- this._sendSession(session);
3627
- }
3628
- };
3629
3461
  /**
3630
3462
  * @inheritDoc
3631
3463
  */
@@ -3681,49 +3513,6 @@ var Sentry = (function (exports) {
3681
3513
  return null;
3682
3514
  }
3683
3515
  };
3684
- /** Updates existing session based on the provided event */
3685
- BaseClient.prototype._updateSessionFromEvent = function (session, event) {
3686
- var e_1, _a;
3687
- var crashed = false;
3688
- var errored = false;
3689
- var user_agent;
3690
- var exceptions = event.exception && event.exception.values;
3691
- if (exceptions) {
3692
- errored = true;
3693
- try {
3694
- for (var exceptions_1 = __values(exceptions), exceptions_1_1 = exceptions_1.next(); !exceptions_1_1.done; exceptions_1_1 = exceptions_1.next()) {
3695
- var ex = exceptions_1_1.value;
3696
- var mechanism = ex.mechanism;
3697
- if (mechanism && mechanism.handled === false) {
3698
- crashed = true;
3699
- break;
3700
- }
3701
- }
3702
- }
3703
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
3704
- finally {
3705
- try {
3706
- if (exceptions_1_1 && !exceptions_1_1.done && (_a = exceptions_1.return)) _a.call(exceptions_1);
3707
- }
3708
- finally { if (e_1) throw e_1.error; }
3709
- }
3710
- }
3711
- var user = event.user;
3712
- if (!session.user_agent) {
3713
- var headers = event.request ? event.request.headers : {};
3714
- for (var key in headers) {
3715
- if (key.toLowerCase() === 'user-agent') {
3716
- user_agent = headers[key];
3717
- break;
3718
- }
3719
- }
3720
- }
3721
- session.update(__assign(__assign({}, (crashed && { status: SessionStatus.Crashed })), { user: user, user_agent: user_agent, errors: session.errors + Number(errored || crashed) }));
3722
- };
3723
- /** Deliver captured session to Sentry */
3724
- BaseClient.prototype._sendSession = function (session) {
3725
- this._getBackend().sendSession(session);
3726
- };
3727
3516
  /** Waits for the client to be done with processing. */
3728
3517
  BaseClient.prototype._isClientProcessing = function (timeout) {
3729
3518
  var _this = this;
@@ -3776,7 +3565,7 @@ var Sentry = (function (exports) {
3776
3565
  BaseClient.prototype._prepareEvent = function (event, scope, hint) {
3777
3566
  var _this = this;
3778
3567
  var _a = this.getOptions().normalizeDepth, normalizeDepth = _a === void 0 ? 3 : _a;
3779
- var prepared = __assign(__assign({}, event), { event_id: event.event_id || (hint && hint.event_id ? hint.event_id : uuid4()), timestamp: event.timestamp || timestampWithMs() });
3568
+ var prepared = __assign(__assign({}, event), { event_id: event.event_id || (hint && hint.event_id ? hint.event_id : uuid4()), timestamp: event.timestamp || dateTimestampInSeconds() });
3780
3569
  this._applyClientOptions(prepared);
3781
3570
  this._applyIntegrationsMetadata(prepared);
3782
3571
  // If we have scope given to us, use it as the base for further modifications.
@@ -3923,12 +3712,6 @@ var Sentry = (function (exports) {
3923
3712
  var isInternalException = hint && hint.data && hint.data.__sentry__ === true;
3924
3713
  // We skip beforeSend in case of transactions
3925
3714
  if (isInternalException || !beforeSend || isTransaction) {
3926
- if (!isTransaction) {
3927
- var session = scope && scope.getSession();
3928
- if (session) {
3929
- _this._updateSessionFromEvent(session, finalEvent);
3930
- }
3931
- }
3932
3715
  _this._sendEvent(finalEvent);
3933
3716
  resolve(finalEvent);
3934
3717
  return;
@@ -3947,10 +3730,6 @@ var Sentry = (function (exports) {
3947
3730
  resolve(null);
3948
3731
  return;
3949
3732
  }
3950
- var session = scope && scope.getSession();
3951
- if (session) {
3952
- _this._updateSessionFromEvent(session, finalEvent);
3953
- }
3954
3733
  // From here on we are really async
3955
3734
  _this._sendEvent(finalEvent);
3956
3735
  resolve(finalEvent);
@@ -4045,18 +3824,6 @@ var Sentry = (function (exports) {
4045
3824
  logger.error("Error while sending event: " + reason);
4046
3825
  });
4047
3826
  };
4048
- /**
4049
- * @inheritDoc
4050
- */
4051
- BaseBackend.prototype.sendSession = function (session) {
4052
- if (!this._transport.sendSession) {
4053
- logger.warn('sendSession not implemented for a transport used');
4054
- return;
4055
- }
4056
- this._transport.sendSession(session).then(null, function (reason) {
4057
- logger.error("Error while sending session: " + reason);
4058
- });
4059
- };
4060
3827
  /**
4061
3828
  * @inheritDoc
4062
3829
  */
@@ -4072,19 +3839,6 @@ var Sentry = (function (exports) {
4072
3839
  return BaseBackend;
4073
3840
  }());
4074
3841
 
4075
- /** Creates a SentryRequest from an event. */
4076
- function sessionToSentryRequest(session, api) {
4077
- var envelopeHeaders = JSON.stringify({
4078
- sent_at: new Date(timestampWithMs() * 1000).toISOString(),
4079
- });
4080
- var itemHeaders = JSON.stringify({
4081
- type: 'session',
4082
- });
4083
- return {
4084
- body: envelopeHeaders + "\n" + itemHeaders + "\n" + JSON.stringify(session),
4085
- url: api.getEnvelopeEndpointWithUrlEncodedAuth(),
4086
- };
4087
- }
4088
3842
  /** Creates a SentryRequest from an event. */
4089
3843
  function eventToSentryRequest(event, api) {
4090
3844
  var useEnvelope = event.type === 'transaction';
@@ -4102,7 +3856,7 @@ var Sentry = (function (exports) {
4102
3856
  event_id: event.event_id,
4103
3857
  // We need to add * 1000 since we divide it by 1000 by default but JS works with ms precision
4104
3858
  // The reason we use timestampWithMs here is that all clocks across the SDK use the same clock
4105
- sent_at: new Date(timestampWithMs() * 1000).toISOString(),
3859
+ sent_at: new Date().toISOString(),
4106
3860
  });
4107
3861
  var itemHeaders = JSON.stringify({
4108
3862
  type: event.type,
@@ -4827,40 +4581,6 @@ var Sentry = (function (exports) {
4827
4581
  .catch(reject);
4828
4582
  }));
4829
4583
  };
4830
- /**
4831
- * @inheritDoc
4832
- */
4833
- FetchTransport.prototype.sendSession = function (session) {
4834
- var sentryReq = sessionToSentryRequest(session, this._api);
4835
- var options = {
4836
- body: sentryReq.body,
4837
- method: 'POST',
4838
- // Despite all stars in the sky saying that Edge supports old draft syntax, aka 'never', 'always', 'origin' and 'default
4839
- // https://caniuse.com/#feat=referrer-policy
4840
- // It doesn't. And it throw exception instead of ignoring this parameter...
4841
- // REF: https://github.com/getsentry/raven-js/issues/1233
4842
- referrerPolicy: (supportsReferrerPolicy() ? 'origin' : ''),
4843
- };
4844
- if (this.options.fetchParameters !== undefined) {
4845
- Object.assign(options, this.options.fetchParameters);
4846
- }
4847
- if (this.options.headers !== undefined) {
4848
- options.headers = this.options.headers;
4849
- }
4850
- return new SyncPromise(function (resolve, reject) {
4851
- global$3
4852
- .fetch(sentryReq.url, options)
4853
- .then(function (response) {
4854
- var status = exports.Status.fromHttpCode(response.status);
4855
- if (status === exports.Status.Success) {
4856
- resolve({ status: status });
4857
- return;
4858
- }
4859
- reject(response);
4860
- })
4861
- .catch(reject);
4862
- });
4863
- };
4864
4584
  return FetchTransport;
4865
4585
  }(BaseTransport));
4866
4586
 
@@ -4918,34 +4638,6 @@ var Sentry = (function (exports) {
4918
4638
  request.send(sentryReq.body);
4919
4639
  }));
4920
4640
  };
4921
- /**
4922
- * @inheritDoc
4923
- */
4924
- XHRTransport.prototype.sendSession = function (session) {
4925
- var _this = this;
4926
- var sentryReq = sessionToSentryRequest(session, this._api);
4927
- return new SyncPromise(function (resolve, reject) {
4928
- var request = new XMLHttpRequest();
4929
- request.onreadystatechange = function () {
4930
- if (request.readyState !== 4) {
4931
- return;
4932
- }
4933
- var status = exports.Status.fromHttpCode(request.status);
4934
- if (status === exports.Status.Success) {
4935
- resolve({ status: status });
4936
- return;
4937
- }
4938
- reject(request);
4939
- };
4940
- request.open('POST', sentryReq.url);
4941
- for (var header in _this.options.headers) {
4942
- if (_this.options.headers.hasOwnProperty(header)) {
4943
- request.setRequestHeader(header, _this.options.headers[header]);
4944
- }
4945
- }
4946
- request.send(sentryReq.body);
4947
- });
4948
- };
4949
4641
  return XHRTransport;
4950
4642
  }(BaseTransport));
4951
4643
 
@@ -5932,7 +5624,7 @@ var Sentry = (function (exports) {
5932
5624
  });
5933
5625
 
5934
5626
  var SDK_NAME = 'sentry.javascript.browser';
5935
- var SDK_VERSION = '5.25.0-beta.2';
5627
+ var SDK_VERSION = '5.25.0';
5936
5628
 
5937
5629
  /**
5938
5630
  * The Sentry Browser SDK Client.