@sentry/browser 5.24.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.24.2 (8096d02) | 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.
@@ -962,13 +962,6 @@ var Sentry = (function (exports) {
962
962
  ? self
963
963
  : fallbackGlobalObject);
964
964
  }
965
- /**
966
- * Determines if running in react native
967
- */
968
- function isReactNative() {
969
- var _a;
970
- return ((_a = getGlobalObject().navigator) === null || _a === void 0 ? void 0 : _a.product) === 'ReactNative';
971
- }
972
965
  /**
973
966
  * UUID4 generator
974
967
  *
@@ -1121,73 +1114,6 @@ var Sentry = (function (exports) {
1121
1114
  return '';
1122
1115
  }
1123
1116
  }
1124
- var INITIAL_TIME = Date.now();
1125
- var prevNow = 0;
1126
- var performanceFallback = {
1127
- now: function () {
1128
- var now = Date.now() - INITIAL_TIME;
1129
- if (now < prevNow) {
1130
- now = prevNow;
1131
- }
1132
- prevNow = now;
1133
- return now;
1134
- },
1135
- timeOrigin: INITIAL_TIME,
1136
- };
1137
- /**
1138
- * Performance wrapper for react native as performance.now() has been found to start off with an unusual offset.
1139
- */
1140
- function getReactNativePerformanceWrapper() {
1141
- // Performance only available >= RN 0.63
1142
- var performance = getGlobalObject().performance;
1143
- if (performance && typeof performance.now === 'function') {
1144
- var INITIAL_OFFSET_1 = performance.now();
1145
- return {
1146
- now: function () {
1147
- return performance.now() - INITIAL_OFFSET_1;
1148
- },
1149
- timeOrigin: INITIAL_TIME,
1150
- };
1151
- }
1152
- return performanceFallback;
1153
- }
1154
- var crossPlatformPerformance = (function () {
1155
- // React Native's performance.now() starts with a gigantic offset, so we need to wrap it.
1156
- if (isReactNative()) {
1157
- return getReactNativePerformanceWrapper();
1158
- }
1159
- if (isNodeEnv()) {
1160
- try {
1161
- var perfHooks = dynamicRequire(module, 'perf_hooks');
1162
- return perfHooks.performance;
1163
- }
1164
- catch (_) {
1165
- return performanceFallback;
1166
- }
1167
- }
1168
- var performance = getGlobalObject().performance;
1169
- if (!performance || !performance.now) {
1170
- return performanceFallback;
1171
- }
1172
- // Polyfill for performance.timeOrigin.
1173
- //
1174
- // While performance.timing.navigationStart is deprecated in favor of performance.timeOrigin, performance.timeOrigin
1175
- // is not as widely supported. Namely, performance.timeOrigin is undefined in Safari as of writing.
1176
- if (performance.timeOrigin === undefined) {
1177
- // As of writing, performance.timing is not available in Web Workers in mainstream browsers, so it is not always a
1178
- // valid fallback. In the absence of a initial time provided by the browser, fallback to INITIAL_TIME.
1179
- // @ts-ignore ignored because timeOrigin is a readonly property but we want to override
1180
- // eslint-disable-next-line deprecation/deprecation
1181
- performance.timeOrigin = (performance.timing && performance.timing.navigationStart) || INITIAL_TIME;
1182
- }
1183
- return performance;
1184
- })();
1185
- /**
1186
- * Returns a timestamp in seconds with milliseconds precision since the UNIX epoch calculated with the monotonic clock.
1187
- */
1188
- function timestampWithMs() {
1189
- return (crossPlatformPerformance.timeOrigin + crossPlatformPerformance.now()) / 1000;
1190
- }
1191
1117
  var defaultRetryAfter = 60 * 1000; // 60 seconds
1192
1118
  /**
1193
1119
  * Extracts Retry-After value from the request header or returns default value
@@ -1273,363 +1199,88 @@ var Sentry = (function (exports) {
1273
1199
  global$1.__SENTRY__ = global$1.__SENTRY__ || {};
1274
1200
  var logger = global$1.__SENTRY__.logger || (global$1.__SENTRY__.logger = new Logger());
1275
1201
 
1276
- /* eslint-disable @typescript-eslint/explicit-function-return-type */
1277
- /** SyncPromise internal states */
1278
- var States;
1279
- (function (States) {
1280
- /** Pending */
1281
- States["PENDING"] = "PENDING";
1282
- /** Resolved / OK */
1283
- States["RESOLVED"] = "RESOLVED";
1284
- /** Rejected / Error */
1285
- States["REJECTED"] = "REJECTED";
1286
- })(States || (States = {}));
1287
1202
  /**
1288
- * Thenable class that behaves like a Promise and follows it's interface
1289
- * but is not async internally
1203
+ * Tells whether current environment supports Fetch API
1204
+ * {@link supportsFetch}.
1205
+ *
1206
+ * @returns Answer to the given question.
1290
1207
  */
1291
- var SyncPromise = /** @class */ (function () {
1292
- function SyncPromise(executor) {
1293
- var _this = this;
1294
- this._state = States.PENDING;
1295
- this._handlers = [];
1296
- /** JSDoc */
1297
- this._resolve = function (value) {
1298
- _this._setResult(States.RESOLVED, value);
1299
- };
1300
- /** JSDoc */
1301
- this._reject = function (reason) {
1302
- _this._setResult(States.REJECTED, reason);
1303
- };
1304
- /** JSDoc */
1305
- this._setResult = function (state, value) {
1306
- if (_this._state !== States.PENDING) {
1307
- return;
1308
- }
1309
- if (isThenable(value)) {
1310
- value.then(_this._resolve, _this._reject);
1311
- return;
1312
- }
1313
- _this._state = state;
1314
- _this._value = value;
1315
- _this._executeHandlers();
1316
- };
1317
- // TODO: FIXME
1318
- /** JSDoc */
1319
- this._attachHandler = function (handler) {
1320
- _this._handlers = _this._handlers.concat(handler);
1321
- _this._executeHandlers();
1322
- };
1323
- /** JSDoc */
1324
- this._executeHandlers = function () {
1325
- if (_this._state === States.PENDING) {
1326
- return;
1327
- }
1328
- var cachedHandlers = _this._handlers.slice();
1329
- _this._handlers = [];
1330
- cachedHandlers.forEach(function (handler) {
1331
- if (handler.done) {
1332
- return;
1333
- }
1334
- if (_this._state === States.RESOLVED) {
1335
- if (handler.onfulfilled) {
1336
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
1337
- handler.onfulfilled(_this._value);
1338
- }
1339
- }
1340
- if (_this._state === States.REJECTED) {
1341
- if (handler.onrejected) {
1342
- handler.onrejected(_this._value);
1343
- }
1344
- }
1345
- handler.done = true;
1346
- });
1347
- };
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") {
1348
1251
  try {
1349
- 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);
1350
1260
  }
1351
- catch (e) {
1352
- this._reject(e);
1261
+ catch (err) {
1262
+ logger.warn('Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ', err);
1353
1263
  }
1354
1264
  }
1355
- /** JSDoc */
1356
- SyncPromise.resolve = function (value) {
1357
- return new SyncPromise(function (resolve) {
1358
- resolve(value);
1359
- });
1360
- };
1361
- /** JSDoc */
1362
- SyncPromise.reject = function (reason) {
1363
- return new SyncPromise(function (_, reject) {
1364
- reject(reason);
1365
- });
1366
- };
1367
- /** JSDoc */
1368
- SyncPromise.all = function (collection) {
1369
- return new SyncPromise(function (resolve, reject) {
1370
- if (!Array.isArray(collection)) {
1371
- reject(new TypeError("Promise.all requires an array as input."));
1372
- return;
1373
- }
1374
- if (collection.length === 0) {
1375
- resolve([]);
1376
- return;
1377
- }
1378
- var counter = collection.length;
1379
- var resolvedCollection = [];
1380
- collection.forEach(function (item, index) {
1381
- SyncPromise.resolve(item)
1382
- .then(function (value) {
1383
- resolvedCollection[index] = value;
1384
- counter -= 1;
1385
- if (counter !== 0) {
1386
- return;
1387
- }
1388
- resolve(resolvedCollection);
1389
- })
1390
- .then(null, reject);
1391
- });
1392
- });
1393
- };
1394
- /** JSDoc */
1395
- SyncPromise.prototype.then = function (onfulfilled, onrejected) {
1396
- var _this = this;
1397
- return new SyncPromise(function (resolve, reject) {
1398
- _this._attachHandler({
1399
- done: false,
1400
- onfulfilled: function (result) {
1401
- if (!onfulfilled) {
1402
- // TODO: ¯\_(ツ)_/¯
1403
- // TODO: FIXME
1404
- resolve(result);
1405
- return;
1406
- }
1407
- try {
1408
- resolve(onfulfilled(result));
1409
- return;
1410
- }
1411
- catch (e) {
1412
- reject(e);
1413
- return;
1414
- }
1415
- },
1416
- onrejected: function (reason) {
1417
- if (!onrejected) {
1418
- reject(reason);
1419
- return;
1420
- }
1421
- try {
1422
- resolve(onrejected(reason));
1423
- return;
1424
- }
1425
- catch (e) {
1426
- reject(e);
1427
- return;
1428
- }
1429
- },
1430
- });
1431
- });
1432
- };
1433
- /** JSDoc */
1434
- SyncPromise.prototype.catch = function (onrejected) {
1435
- return this.then(function (val) { return val; }, onrejected);
1436
- };
1437
- /** JSDoc */
1438
- SyncPromise.prototype.finally = function (onfinally) {
1439
- var _this = this;
1440
- return new SyncPromise(function (resolve, reject) {
1441
- var val;
1442
- var isRejected;
1443
- return _this.then(function (value) {
1444
- isRejected = false;
1445
- val = value;
1446
- if (onfinally) {
1447
- onfinally();
1448
- }
1449
- }, function (reason) {
1450
- isRejected = true;
1451
- val = reason;
1452
- if (onfinally) {
1453
- onfinally();
1454
- }
1455
- }).then(function () {
1456
- if (isRejected) {
1457
- reject(val);
1458
- return;
1459
- }
1460
- resolve(val);
1461
- });
1462
- });
1463
- };
1464
- /** JSDoc */
1465
- SyncPromise.prototype.toString = function () {
1466
- return '[object SyncPromise]';
1467
- };
1468
- return SyncPromise;
1469
- }());
1470
-
1471
- /** A simple queue that holds promises. */
1472
- var PromiseBuffer = /** @class */ (function () {
1473
- function PromiseBuffer(_limit) {
1474
- this._limit = _limit;
1475
- /** Internal set of queued Promises */
1476
- this._buffer = [];
1477
- }
1478
- /**
1479
- * Says if the buffer is ready to take more requests
1480
- */
1481
- PromiseBuffer.prototype.isReady = function () {
1482
- return this._limit === undefined || this.length() < this._limit;
1483
- };
1484
- /**
1485
- * Add a promise to the queue.
1486
- *
1487
- * @param task Can be any PromiseLike<T>
1488
- * @returns The original promise.
1489
- */
1490
- PromiseBuffer.prototype.add = function (task) {
1491
- var _this = this;
1492
- if (!this.isReady()) {
1493
- return SyncPromise.reject(new SentryError('Not adding Promise due to buffer limit reached.'));
1494
- }
1495
- if (this._buffer.indexOf(task) === -1) {
1496
- this._buffer.push(task);
1497
- }
1498
- task
1499
- .then(function () { return _this.remove(task); })
1500
- .then(null, function () {
1501
- return _this.remove(task).then(null, function () {
1502
- // We have to add this catch here otherwise we have an unhandledPromiseRejection
1503
- // because it's a new Promise chain.
1504
- });
1505
- });
1506
- return task;
1507
- };
1508
- /**
1509
- * Remove a promise to the queue.
1510
- *
1511
- * @param task Can be any PromiseLike<T>
1512
- * @returns Removed promise.
1513
- */
1514
- PromiseBuffer.prototype.remove = function (task) {
1515
- var removedTask = this._buffer.splice(this._buffer.indexOf(task), 1)[0];
1516
- return removedTask;
1517
- };
1518
- /**
1519
- * This function returns the number of unresolved promises in the queue.
1520
- */
1521
- PromiseBuffer.prototype.length = function () {
1522
- return this._buffer.length;
1523
- };
1524
- /**
1525
- * This will drain the whole queue, returns true if queue is empty or drained.
1526
- * If timeout is provided and the queue takes longer to drain, the promise still resolves but with false.
1527
- *
1528
- * @param timeout Number in ms to wait until it resolves with false.
1529
- */
1530
- PromiseBuffer.prototype.drain = function (timeout) {
1531
- var _this = this;
1532
- return new SyncPromise(function (resolve) {
1533
- var capturedSetTimeout = setTimeout(function () {
1534
- if (timeout && timeout > 0) {
1535
- resolve(false);
1536
- }
1537
- }, timeout);
1538
- SyncPromise.all(_this._buffer)
1539
- .then(function () {
1540
- clearTimeout(capturedSetTimeout);
1541
- resolve(true);
1542
- })
1543
- .then(null, function () {
1544
- resolve(true);
1545
- });
1546
- });
1547
- };
1548
- return PromiseBuffer;
1549
- }());
1550
-
1551
- /**
1552
- * Tells whether current environment supports Fetch API
1553
- * {@link supportsFetch}.
1554
- *
1555
- * @returns Answer to the given question.
1556
- */
1557
- function supportsFetch() {
1558
- if (!('fetch' in getGlobalObject())) {
1559
- return false;
1560
- }
1561
- try {
1562
- new Headers();
1563
- new Request('');
1564
- new Response();
1565
- return true;
1566
- }
1567
- catch (e) {
1568
- return false;
1569
- }
1570
- }
1571
- /**
1572
- * isNativeFetch checks if the given function is a native implementation of fetch()
1573
- */
1574
- // eslint-disable-next-line @typescript-eslint/ban-types
1575
- function isNativeFetch(func) {
1576
- return func && /^function fetch\(\)\s+\{\s+\[native code\]\s+\}$/.test(func.toString());
1577
- }
1578
- /**
1579
- * Tells whether current environment supports Fetch API natively
1580
- * {@link supportsNativeFetch}.
1581
- *
1582
- * @returns true if `window.fetch` is natively implemented, false otherwise
1583
- */
1584
- function supportsNativeFetch() {
1585
- if (!supportsFetch()) {
1586
- return false;
1587
- }
1588
- var global = getGlobalObject();
1589
- // Fast path to avoid DOM I/O
1590
- // eslint-disable-next-line @typescript-eslint/unbound-method
1591
- if (isNativeFetch(global.fetch)) {
1592
- return true;
1593
- }
1594
- // window.fetch is implemented, but is polyfilled or already wrapped (e.g: by a chrome extension)
1595
- // so create a "pure" iframe to see if that has native fetch
1596
- var result = false;
1597
- var doc = global.document;
1598
- // eslint-disable-next-line deprecation/deprecation
1599
- if (doc && typeof doc.createElement === "function") {
1600
- try {
1601
- var sandbox = doc.createElement('iframe');
1602
- sandbox.hidden = true;
1603
- doc.head.appendChild(sandbox);
1604
- if (sandbox.contentWindow && sandbox.contentWindow.fetch) {
1605
- // eslint-disable-next-line @typescript-eslint/unbound-method
1606
- result = isNativeFetch(sandbox.contentWindow.fetch);
1607
- }
1608
- doc.head.removeChild(sandbox);
1609
- }
1610
- catch (err) {
1611
- logger.warn('Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ', err);
1612
- }
1613
- }
1614
- return result;
1615
- }
1616
- /**
1617
- * Tells whether current environment supports Referrer Policy API
1618
- * {@link supportsReferrerPolicy}.
1619
- *
1620
- * @returns Answer to the given question.
1621
- */
1622
- function supportsReferrerPolicy() {
1623
- // Despite all stars in the sky saying that Edge supports old draft syntax, aka 'never', 'always', 'origin' and 'default
1624
- // https://caniuse.com/#feat=referrer-policy
1625
- // It doesn't. And it throw exception instead of ignoring this parameter...
1626
- // REF: https://github.com/getsentry/raven-js/issues/1233
1627
- if (!supportsFetch()) {
1628
- return false;
1629
- }
1630
- try {
1631
- new Request('_', {
1632
- 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',
1633
1284
  });
1634
1285
  return true;
1635
1286
  }
@@ -1775,7 +1426,7 @@ var Sentry = (function (exports) {
1775
1426
  for (var _i = 0; _i < arguments.length; _i++) {
1776
1427
  args[_i] = arguments[_i];
1777
1428
  }
1778
- var commonHandlerData = {
1429
+ var handlerData = {
1779
1430
  args: args,
1780
1431
  fetchData: {
1781
1432
  method: getFetchMethod(args),
@@ -1783,13 +1434,13 @@ var Sentry = (function (exports) {
1783
1434
  },
1784
1435
  startTimestamp: Date.now(),
1785
1436
  };
1786
- triggerHandlers('fetch', __assign({}, commonHandlerData));
1437
+ triggerHandlers('fetch', __assign({}, handlerData));
1787
1438
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
1788
1439
  return originalFetch.apply(global$2, args).then(function (response) {
1789
- triggerHandlers('fetch', __assign(__assign({}, commonHandlerData), { endTimestamp: Date.now(), response: response }));
1440
+ triggerHandlers('fetch', __assign(__assign({}, handlerData), { endTimestamp: Date.now(), response: response }));
1790
1441
  return response;
1791
1442
  }, function (error) {
1792
- triggerHandlers('fetch', __assign(__assign({}, commonHandlerData), { endTimestamp: Date.now(), error: error }));
1443
+ triggerHandlers('fetch', __assign(__assign({}, handlerData), { endTimestamp: Date.now(), error: error }));
1793
1444
  // NOTE: If you are a Sentry user, and you are seeing this stack frame,
1794
1445
  // it means the sentry.javascript SDK caught an error invoking your application code.
1795
1446
  // This is expected behavior and NOT indicative of a bug with sentry.javascript.
@@ -1827,7 +1478,7 @@ var Sentry = (function (exports) {
1827
1478
  if (!('XMLHttpRequest' in global$2)) {
1828
1479
  return;
1829
1480
  }
1830
- // 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.
1831
1482
  var requestKeys = [];
1832
1483
  var requestValues = [];
1833
1484
  var xhrproto = XMLHttpRequest.prototype;
@@ -1865,7 +1516,7 @@ var Sentry = (function (exports) {
1865
1516
  try {
1866
1517
  var requestPos = requestKeys.indexOf(xhr);
1867
1518
  if (requestPos !== -1) {
1868
- // 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.
1869
1520
  requestKeys.splice(requestPos);
1870
1521
  var args_1 = requestValues.splice(requestPos)[0];
1871
1522
  if (xhr.__sentry_xhr__ && args_1[0] !== undefined) {
@@ -2140,51 +1791,431 @@ var Sentry = (function (exports) {
2140
1791
  };
2141
1792
  }
2142
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 = {}));
2143
1805
  /**
2144
- * Holds additional event information. {@link Scope.applyToEvent} will be
2145
- * called by the client before an event will be sent.
1806
+ * Thenable class that behaves like a Promise and follows it's interface
1807
+ * but is not async internally
2146
1808
  */
2147
- var Scope = /** @class */ (function () {
2148
- function Scope() {
2149
- /** Flag if notifiying is happening. */
2150
- this._notifyingListeners = false;
2151
- /** Callback for client to receive scope changes. */
2152
- this._scopeListeners = [];
2153
- /** Callback list that will be called after {@link applyToEvent}. */
2154
- this._eventProcessors = [];
2155
- /** Array of breadcrumbs. */
2156
- this._breadcrumbs = [];
2157
- /** User */
2158
- this._user = {};
2159
- /** Tags */
2160
- this._tags = {};
2161
- /** Extra */
2162
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2163
- this._extra = {};
2164
- /** Contexts */
2165
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2166
- this._contexts = {};
2167
- }
2168
- /**
2169
- * Inherit values from the parent scope.
2170
- * @param scope to clone.
2171
- */
2172
- Scope.clone = function (scope) {
2173
- var newScope = new Scope();
2174
- if (scope) {
2175
- newScope._breadcrumbs = __spread(scope._breadcrumbs);
2176
- newScope._tags = __assign({}, scope._tags);
2177
- newScope._extra = __assign({}, scope._extra);
2178
- newScope._contexts = __assign({}, scope._contexts);
2179
- newScope._user = scope._user;
2180
- newScope._level = scope._level;
2181
- newScope._span = scope._span;
2182
- newScope._transactionName = scope._transactionName;
2183
- newScope._fingerprint = scope._fingerprint;
2184
- newScope._eventProcessors = __spread(scope._eventProcessors);
2185
- }
2186
- return newScope;
2187
- };
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.
2120
+ */
2121
+ function getNodePerformance() {
2122
+ try {
2123
+ var perfHooks = dynamicRequire(module, 'perf_hooks');
2124
+ return perfHooks.performance;
2125
+ }
2126
+ catch (_) {
2127
+ return undefined;
2128
+ }
2129
+ }
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; },
2138
+ };
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
+ })();
2175
+
2176
+ /**
2177
+ * Holds additional event information. {@link Scope.applyToEvent} will be
2178
+ * called by the client before an event will be sent.
2179
+ */
2180
+ var Scope = /** @class */ (function () {
2181
+ function Scope() {
2182
+ /** Flag if notifiying is happening. */
2183
+ this._notifyingListeners = false;
2184
+ /** Callback for client to receive scope changes. */
2185
+ this._scopeListeners = [];
2186
+ /** Callback list that will be called after {@link applyToEvent}. */
2187
+ this._eventProcessors = [];
2188
+ /** Array of breadcrumbs. */
2189
+ this._breadcrumbs = [];
2190
+ /** User */
2191
+ this._user = {};
2192
+ /** Tags */
2193
+ this._tags = {};
2194
+ /** Extra */
2195
+ this._extra = {};
2196
+ /** Contexts */
2197
+ this._contexts = {};
2198
+ }
2199
+ /**
2200
+ * Inherit values from the parent scope.
2201
+ * @param scope to clone.
2202
+ */
2203
+ Scope.clone = function (scope) {
2204
+ var newScope = new Scope();
2205
+ if (scope) {
2206
+ newScope._breadcrumbs = __spread(scope._breadcrumbs);
2207
+ newScope._tags = __assign({}, scope._tags);
2208
+ newScope._extra = __assign({}, scope._extra);
2209
+ newScope._contexts = __assign({}, scope._contexts);
2210
+ newScope._user = scope._user;
2211
+ newScope._level = scope._level;
2212
+ newScope._span = scope._span;
2213
+ newScope._transactionName = scope._transactionName;
2214
+ newScope._fingerprint = scope._fingerprint;
2215
+ newScope._eventProcessors = __spread(scope._eventProcessors);
2216
+ }
2217
+ return newScope;
2218
+ };
2188
2219
  /**
2189
2220
  * Add internal on change listener. Used for sub SDKs that need to store the scope.
2190
2221
  * @hidden
@@ -2275,10 +2306,15 @@ var Sentry = (function (exports) {
2275
2306
  /**
2276
2307
  * @inheritDoc
2277
2308
  */
2278
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2279
2309
  Scope.prototype.setContext = function (key, context) {
2280
2310
  var _a;
2281
- 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
+ }
2282
2318
  this._notifyScopeListeners();
2283
2319
  return this;
2284
2320
  };
@@ -2300,10 +2336,18 @@ var Sentry = (function (exports) {
2300
2336
  * @inheritDoc
2301
2337
  */
2302
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
2303
2341
  var span = this.getSpan();
2304
- 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]) {
2305
2348
  return span.spanRecorder.spans[0];
2306
2349
  }
2350
+ // neither way found a transaction
2307
2351
  return undefined;
2308
2352
  };
2309
2353
  /**
@@ -2369,7 +2413,7 @@ var Sentry = (function (exports) {
2369
2413
  * @inheritDoc
2370
2414
  */
2371
2415
  Scope.prototype.addBreadcrumb = function (breadcrumb, maxBreadcrumbs) {
2372
- var mergedBreadcrumb = __assign({ timestamp: timestampWithMs() }, breadcrumb);
2416
+ var mergedBreadcrumb = __assign({ timestamp: dateTimestampInSeconds() }, breadcrumb);
2373
2417
  this._breadcrumbs =
2374
2418
  maxBreadcrumbs !== undefined && maxBreadcrumbs >= 0
2375
2419
  ? __spread(this._breadcrumbs, [mergedBreadcrumb]).slice(-maxBreadcrumbs)
@@ -2689,7 +2733,7 @@ var Sentry = (function (exports) {
2689
2733
  if (maxBreadcrumbs <= 0) {
2690
2734
  return;
2691
2735
  }
2692
- var timestamp = timestampWithMs();
2736
+ var timestamp = dateTimestampInSeconds();
2693
2737
  var mergedBreadcrumb = __assign({ timestamp: timestamp }, breadcrumb);
2694
2738
  var finalBreadcrumb = beforeBreadcrumb
2695
2739
  ? consoleSandbox(function () { return beforeBreadcrumb(mergedBreadcrumb, hint); })
@@ -3521,7 +3565,7 @@ var Sentry = (function (exports) {
3521
3565
  BaseClient.prototype._prepareEvent = function (event, scope, hint) {
3522
3566
  var _this = this;
3523
3567
  var _a = this.getOptions().normalizeDepth, normalizeDepth = _a === void 0 ? 3 : _a;
3524
- 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() });
3525
3569
  this._applyClientOptions(prepared);
3526
3570
  this._applyIntegrationsMetadata(prepared);
3527
3571
  // If we have scope given to us, use it as the base for further modifications.
@@ -3812,7 +3856,7 @@ var Sentry = (function (exports) {
3812
3856
  event_id: event.event_id,
3813
3857
  // We need to add * 1000 since we divide it by 1000 by default but JS works with ms precision
3814
3858
  // The reason we use timestampWithMs here is that all clocks across the SDK use the same clock
3815
- sent_at: new Date(timestampWithMs() * 1000).toISOString(),
3859
+ sent_at: new Date().toISOString(),
3816
3860
  });
3817
3861
  var itemHeaders = JSON.stringify({
3818
3862
  type: event.type,
@@ -5580,7 +5624,7 @@ var Sentry = (function (exports) {
5580
5624
  });
5581
5625
 
5582
5626
  var SDK_NAME = 'sentry.javascript.browser';
5583
- var SDK_VERSION = '5.24.2';
5627
+ var SDK_VERSION = '5.25.0';
5584
5628
 
5585
5629
  /**
5586
5630
  * The Sentry Browser SDK Client.