@sentry/browser 6.18.0 → 6.18.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/build/bundle.es6.js +158 -123
  2. package/build/bundle.es6.js.map +1 -1
  3. package/build/bundle.es6.min.js +2 -2
  4. package/build/bundle.es6.min.js.map +1 -1
  5. package/build/bundle.js +168 -130
  6. package/build/bundle.js.map +1 -1
  7. package/build/bundle.min.js +2 -2
  8. package/build/bundle.min.js.map +1 -1
  9. package/dist/backend.js +2 -2
  10. package/dist/backend.js.map +1 -1
  11. package/dist/eventbuilder.d.ts +24 -10
  12. package/dist/eventbuilder.d.ts.map +1 -1
  13. package/dist/eventbuilder.js +119 -23
  14. package/dist/eventbuilder.js.map +1 -1
  15. package/dist/helpers.js +2 -2
  16. package/dist/helpers.js.map +1 -1
  17. package/dist/integrations/dedupe.js +1 -1
  18. package/dist/integrations/dedupe.js.map +1 -1
  19. package/dist/integrations/globalhandlers.js +2 -8
  20. package/dist/integrations/globalhandlers.js.map +1 -1
  21. package/dist/integrations/linkederrors.js +2 -2
  22. package/dist/integrations/linkederrors.js.map +1 -1
  23. package/dist/stack-parsers.d.ts +5 -5
  24. package/dist/stack-parsers.d.ts.map +1 -1
  25. package/dist/stack-parsers.js +16 -6
  26. package/dist/stack-parsers.js.map +1 -1
  27. package/dist/transports/base.d.ts.map +1 -1
  28. package/dist/transports/base.js +11 -18
  29. package/dist/transports/base.js.map +1 -1
  30. package/dist/transports/utils.js +1 -1
  31. package/dist/transports/utils.js.map +1 -1
  32. package/esm/backend.js +2 -2
  33. package/esm/backend.js.map +1 -1
  34. package/esm/eventbuilder.d.ts +24 -10
  35. package/esm/eventbuilder.d.ts.map +1 -1
  36. package/esm/eventbuilder.js +113 -21
  37. package/esm/eventbuilder.js.map +1 -1
  38. package/esm/helpers.js +2 -2
  39. package/esm/helpers.js.map +1 -1
  40. package/esm/integrations/dedupe.js +1 -1
  41. package/esm/integrations/dedupe.js.map +1 -1
  42. package/esm/integrations/globalhandlers.js +2 -8
  43. package/esm/integrations/globalhandlers.js.map +1 -1
  44. package/esm/integrations/linkederrors.js +1 -1
  45. package/esm/integrations/linkederrors.js.map +1 -1
  46. package/esm/stack-parsers.d.ts +5 -5
  47. package/esm/stack-parsers.d.ts.map +1 -1
  48. package/esm/stack-parsers.js +16 -6
  49. package/esm/stack-parsers.js.map +1 -1
  50. package/esm/transports/base.d.ts.map +1 -1
  51. package/esm/transports/base.js +13 -20
  52. package/esm/transports/base.js.map +1 -1
  53. package/esm/transports/utils.js +1 -1
  54. package/esm/transports/utils.js.map +1 -1
  55. package/package.json +5 -5
  56. package/dist/parsers.d.ts +0 -21
  57. package/dist/parsers.d.ts.map +0 -1
  58. package/dist/parsers.js +0 -108
  59. package/dist/parsers.js.map +0 -1
  60. package/esm/parsers.d.ts +0 -21
  61. package/esm/parsers.d.ts.map +0 -1
  62. package/esm/parsers.js +0 -103
  63. package/esm/parsers.js.map +0 -1
@@ -1,4 +1,4 @@
1
- /*! @sentry/browser 6.18.0 (70c1d77) | https://github.com/getsentry/sentry-javascript */
1
+ /*! @sentry/browser 6.18.2 (22f518e) | https://github.com/getsentry/sentry-javascript */
2
2
  var Sentry = (function (exports) {
3
3
 
4
4
  /**
@@ -501,7 +501,7 @@ var Sentry = (function (exports) {
501
501
  return;
502
502
  }
503
503
  consoleSandbox(() => {
504
- global$6.console.log(`${PREFIX}[Log]: ${args.join(' ')}`);
504
+ global$6.console.log(`${PREFIX}[Log]:`, ...args);
505
505
  });
506
506
  }
507
507
  /** JSDoc */
@@ -510,7 +510,7 @@ var Sentry = (function (exports) {
510
510
  return;
511
511
  }
512
512
  consoleSandbox(() => {
513
- global$6.console.warn(`${PREFIX}[Warn]: ${args.join(' ')}`);
513
+ global$6.console.warn(`${PREFIX}[Warn]:`, ...args);
514
514
  });
515
515
  }
516
516
  /** JSDoc */
@@ -519,7 +519,7 @@ var Sentry = (function (exports) {
519
519
  return;
520
520
  }
521
521
  consoleSandbox(() => {
522
- global$6.console.error(`${PREFIX}[Error]: ${args.join(' ')}`);
522
+ global$6.console.error(`${PREFIX}[Error]:`, ...args);
523
523
  });
524
524
  }
525
525
  }
@@ -576,12 +576,13 @@ var Sentry = (function (exports) {
576
576
  * StackFrames are returned in the correct order for Sentry Exception
577
577
  * frames and with Sentry SDK internal frames removed from the top and bottom
578
578
  *
579
- * */
579
+ */
580
580
  function createStackParser(...parsers) {
581
+ const sortedParsers = parsers.sort((a, b) => a[0] - b[0]).map(p => p[1]);
581
582
  return (stack, skipFirst = 0) => {
582
583
  const frames = [];
583
584
  for (const line of stack.split('\n').slice(skipFirst)) {
584
- for (const parser of parsers) {
585
+ for (const parser of sortedParsers) {
585
586
  const frame = parser(line);
586
587
  if (frame) {
587
588
  frames.push(frame);
@@ -865,19 +866,19 @@ var Sentry = (function (exports) {
865
866
  if (type === '[object Array]') {
866
867
  return '[Array]';
867
868
  }
868
- const normalized = normalizeValue(value);
869
- return isPrimitive(normalized) ? normalized : type;
869
+ // `makeSerializable` provides a string representation of certain non-serializable values. For all others, it's a
870
+ // pass-through.
871
+ const serializable = makeSerializable(value);
872
+ return isPrimitive(serializable) ? serializable : type;
870
873
  }
871
874
  /**
872
- * normalizeValue()
875
+ * makeSerializable()
873
876
  *
874
- * Takes unserializable input and make it serializable friendly
877
+ * Takes unserializable input and make it serializer-friendly.
875
878
  *
876
- * - translates undefined/NaN values to "[undefined]"/"[NaN]" respectively,
877
- * - serializes Error objects
878
- * - filter global objects
879
+ * Handles globals, functions, `undefined`, `NaN`, and other non-serializable values.
879
880
  */
880
- function normalizeValue(value, key) {
881
+ function makeSerializable(value, key) {
881
882
  if (key === 'domain' && value && typeof value === 'object' && value._events) {
882
883
  return '[Domain]';
883
884
  }
@@ -929,6 +930,7 @@ var Sentry = (function (exports) {
929
930
  */
930
931
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
931
932
  function walk(key, value, depth = +Infinity, memo = memoBuilder()) {
933
+ const [memoize, unmemoize] = memo;
932
934
  // If we reach the maximum depth, serialize whatever is left
933
935
  if (depth === 0) {
934
936
  return serializeValue(value);
@@ -939,10 +941,12 @@ var Sentry = (function (exports) {
939
941
  return value.toJSON();
940
942
  }
941
943
  /* eslint-enable @typescript-eslint/no-unsafe-member-access */
942
- // If normalized value is a primitive, there are no branches left to walk, so bail out
943
- const normalized = normalizeValue(value, key);
944
- if (isPrimitive(normalized)) {
945
- return normalized;
944
+ // `makeSerializable` provides a string representation of certain non-serializable values. For all others, it's a
945
+ // pass-through. If what comes back is a primitive (either because it's been stringified or because it was primitive
946
+ // all along), we're done.
947
+ const serializable = makeSerializable(value, key);
948
+ if (isPrimitive(serializable)) {
949
+ return serializable;
946
950
  }
947
951
  // Create source that we will use for the next iteration. It will either be an objectified error object (`Error` type
948
952
  // with extracted key:value pairs) or the input itself.
@@ -950,7 +954,7 @@ var Sentry = (function (exports) {
950
954
  // Create an accumulator that will act as a parent for all future itterations of that branch
951
955
  const acc = Array.isArray(value) ? [] : {};
952
956
  // If we already walked that branch, bail out, as it's circular reference
953
- if (memo[0](value)) {
957
+ if (memoize(value)) {
954
958
  return '[Circular ~]';
955
959
  }
956
960
  // Walk all keys of the source
@@ -960,10 +964,11 @@ var Sentry = (function (exports) {
960
964
  continue;
961
965
  }
962
966
  // Recursively walk through all the child nodes
963
- acc[innerKey] = walk(innerKey, source[innerKey], depth - 1, memo);
967
+ const innerValue = source[innerKey];
968
+ acc[innerKey] = walk(innerKey, innerValue, depth - 1, memo);
964
969
  }
965
970
  // Once walked through all the branches, remove the parent from memo storage
966
- memo[1](value);
971
+ unmemoize(value);
967
972
  // Return accumulated values
968
973
  return acc;
969
974
  }
@@ -982,7 +987,8 @@ var Sentry = (function (exports) {
982
987
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
983
988
  function normalize(input, depth) {
984
989
  try {
985
- return JSON.parse(JSON.stringify(input, (key, value) => walk(key, value, depth)));
990
+ // since we're at the outermost level, there is no key
991
+ return walk('', input, depth);
986
992
  }
987
993
  catch (_oO) {
988
994
  return '**non-serializable**';
@@ -1084,7 +1090,7 @@ var Sentry = (function (exports) {
1084
1090
  let result = false;
1085
1091
  const doc = global.document;
1086
1092
  // eslint-disable-next-line deprecation/deprecation
1087
- if (doc && typeof doc.createElement === `function`) {
1093
+ if (doc && typeof doc.createElement === 'function') {
1088
1094
  try {
1089
1095
  const sandbox = doc.createElement('iframe');
1090
1096
  sandbox.hidden = true;
@@ -1213,7 +1219,7 @@ var Sentry = (function (exports) {
1213
1219
  }
1214
1220
  catch (e) {
1215
1221
  if (isDebugBuild()) {
1216
- logger.error(`Error while triggering instrumentation handler.\nType: ${type}\nName: ${getFunctionName(handler)}\nError: ${e}`);
1222
+ logger.error(`Error while triggering instrumentation handler.\nType: ${type}\nName: ${getFunctionName(handler)}\nError:`, e);
1217
1223
  }
1218
1224
  }
1219
1225
  }
@@ -1741,26 +1747,6 @@ var Sentry = (function (exports) {
1741
1747
  firstException.mechanism.data = mergedData;
1742
1748
  }
1743
1749
  }
1744
- const defaultRetryAfter = 60 * 1000; // 60 seconds
1745
- /**
1746
- * Extracts Retry-After value from the request header or returns default value
1747
- * @param now current unix timestamp
1748
- * @param header string representation of 'Retry-After' header
1749
- */
1750
- function parseRetryAfterHeader(now, header) {
1751
- if (!header) {
1752
- return defaultRetryAfter;
1753
- }
1754
- const headerDelay = parseInt(`${header}`, 10);
1755
- if (!isNaN(headerDelay)) {
1756
- return headerDelay * 1000;
1757
- }
1758
- const headerDate = Date.parse(`${header}`);
1759
- if (!isNaN(headerDate)) {
1760
- return headerDate - now;
1761
- }
1762
- return defaultRetryAfter;
1763
- }
1764
1750
  /**
1765
1751
  * Checks whether or not we've already captured the given exception (note: not an identical exception - the very object
1766
1752
  * in question), and marks it captured if not.
@@ -2190,6 +2176,68 @@ var Sentry = (function (exports) {
2190
2176
  return dateNow;
2191
2177
  })();
2192
2178
 
2179
+ /**
2180
+ * Creates an envelope.
2181
+ * Make sure to always explicitly provide the generic to this function
2182
+ * so that the envelope types resolve correctly.
2183
+ */
2184
+ function createEnvelope(headers, items = []) {
2185
+ return [headers, items];
2186
+ }
2187
+ /**
2188
+ * Serializes an envelope into a string.
2189
+ */
2190
+ function serializeEnvelope(envelope) {
2191
+ const [headers, items] = envelope;
2192
+ const serializedHeaders = JSON.stringify(headers);
2193
+ // Have to cast items to any here since Envelope is a union type
2194
+ // Fixed in Typescript 4.2
2195
+ // TODO: Remove any[] cast when we upgrade to TS 4.2
2196
+ // https://github.com/microsoft/TypeScript/issues/36390
2197
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2198
+ return items.reduce((acc, item) => {
2199
+ const [itemHeaders, payload] = item;
2200
+ // We do not serialize payloads that are primitives
2201
+ const serializedPayload = isPrimitive(payload) ? String(payload) : JSON.stringify(payload);
2202
+ return `${acc}\n${JSON.stringify(itemHeaders)}\n${serializedPayload}`;
2203
+ }, serializedHeaders);
2204
+ }
2205
+
2206
+ /**
2207
+ * Creates client report envelope
2208
+ * @param discarded_events An array of discard events
2209
+ * @param dsn A DSN that can be set on the header. Optional.
2210
+ */
2211
+ function createClientReportEnvelope(discarded_events, dsn, timestamp) {
2212
+ const clientReportItem = [
2213
+ { type: 'client_report' },
2214
+ {
2215
+ timestamp: timestamp || dateTimestampInSeconds(),
2216
+ discarded_events,
2217
+ },
2218
+ ];
2219
+ return createEnvelope(dsn ? { dsn } : {}, [clientReportItem]);
2220
+ }
2221
+
2222
+ const DEFAULT_RETRY_AFTER = 60 * 1000; // 60 seconds
2223
+ /**
2224
+ * Extracts Retry-After value from the request header or returns default value
2225
+ * @param header string representation of 'Retry-After' header
2226
+ * @param now current unix timestamp
2227
+ *
2228
+ */
2229
+ function parseRetryAfterHeader(header, now = Date.now()) {
2230
+ const headerDelay = parseInt(`${header}`, 10);
2231
+ if (!isNaN(headerDelay)) {
2232
+ return headerDelay * 1000;
2233
+ }
2234
+ const headerDate = Date.parse(`${header}`);
2235
+ if (!isNaN(headerDate)) {
2236
+ return headerDate - now;
2237
+ }
2238
+ return DEFAULT_RETRY_AFTER;
2239
+ }
2240
+
2193
2241
  /**
2194
2242
  * Absolute maximum number of breadcrumbs added to an event.
2195
2243
  * The `maxBreadcrumbs` option cannot be higher than this value.
@@ -4018,7 +4066,7 @@ var Sentry = (function (exports) {
4018
4066
  */
4019
4067
  sendEvent(_) {
4020
4068
  return resolvedSyncPromise({
4021
- reason: `NoopTransport: Event has been skipped because no Dsn is configured.`,
4069
+ reason: 'NoopTransport: Event has been skipped because no Dsn is configured.',
4022
4070
  status: 'skipped',
4023
4071
  });
4024
4072
  }
@@ -4062,7 +4110,7 @@ var Sentry = (function (exports) {
4062
4110
  sendEvent(event) {
4063
4111
  void this._transport.sendEvent(event).then(null, reason => {
4064
4112
  if (isDebugBuild()) {
4065
- logger.error(`Error while sending event: ${reason}`);
4113
+ logger.error('Error while sending event:', reason);
4066
4114
  }
4067
4115
  });
4068
4116
  }
@@ -4078,7 +4126,7 @@ var Sentry = (function (exports) {
4078
4126
  }
4079
4127
  void this._transport.sendSession(session).then(null, reason => {
4080
4128
  if (isDebugBuild()) {
4081
- logger.error(`Error while sending session: ${reason}`);
4129
+ logger.error('Error while sending session:', reason);
4082
4130
  }
4083
4131
  });
4084
4132
  }
@@ -4122,14 +4170,14 @@ var Sentry = (function (exports) {
4122
4170
  /** Creates a SentryRequest from a Session. */
4123
4171
  function sessionToSentryRequest(session, api) {
4124
4172
  const sdkInfo = getSdkMetadataForEnvelopeHeader(api);
4125
- const envelopeHeaders = JSON.stringify(Object.assign(Object.assign({ sent_at: new Date().toISOString() }, (sdkInfo && { sdk: sdkInfo })), (!!api.tunnel && { dsn: dsnToString(api.dsn) })));
4126
- // I know this is hacky but we don't want to add `session` to request type since it's never rate limited
4173
+ const envelopeHeaders = Object.assign(Object.assign({ sent_at: new Date().toISOString() }, (sdkInfo && { sdk: sdkInfo })), (!!api.tunnel && { dsn: dsnToString(api.dsn) }));
4174
+ // I know this is hacky but we don't want to add `sessions` to request type since it's never rate limited
4127
4175
  const type = 'aggregates' in session ? 'sessions' : 'session';
4128
- const itemHeaders = JSON.stringify({
4129
- type,
4130
- });
4176
+ // TODO (v7) Have to cast type because envelope items do not accept a `SentryRequestType`
4177
+ const envelopeItem = [{ type }, session];
4178
+ const envelope = createEnvelope(envelopeHeaders, [envelopeItem]);
4131
4179
  return {
4132
- body: `${envelopeHeaders}\n${itemHeaders}\n${JSON.stringify(session)}`,
4180
+ body: serializeEnvelope(envelope),
4133
4181
  type,
4134
4182
  url: getEnvelopeEndpointWithUrlEncodedAuth(api.dsn, api.tunnel),
4135
4183
  };
@@ -4207,19 +4255,16 @@ var Sentry = (function (exports) {
4207
4255
  // deserialization. Instead, we only implement a minimal subset of the spec to
4208
4256
  // serialize events inline here.
4209
4257
  if (useEnvelope) {
4210
- const envelopeHeaders = JSON.stringify(Object.assign(Object.assign({ event_id: event.event_id, sent_at: new Date().toISOString() }, (sdkInfo && { sdk: sdkInfo })), (!!api.tunnel && { dsn: dsnToString(api.dsn) })));
4211
- const itemHeaders = JSON.stringify({
4212
- type: eventType,
4213
- // TODO: Right now, sampleRate may or may not be defined (it won't be in the cases of inheritance and
4214
- // explicitly-set sampling decisions). Are we good with that?
4215
- sample_rates: [{ id: samplingMethod, rate: sampleRate }],
4216
- });
4217
- // The trailing newline is optional. We intentionally don't send it to avoid
4218
- // sending unnecessary bytes.
4219
- //
4220
- // const envelope = `${envelopeHeaders}\n${itemHeaders}\n${req.body}\n`;
4221
- const envelope = `${envelopeHeaders}\n${itemHeaders}\n${req.body}`;
4222
- req.body = envelope;
4258
+ const envelopeHeaders = Object.assign(Object.assign({ event_id: event.event_id, sent_at: new Date().toISOString() }, (sdkInfo && { sdk: sdkInfo })), (!!api.tunnel && { dsn: dsnToString(api.dsn) }));
4259
+ const eventItem = [
4260
+ {
4261
+ type: eventType,
4262
+ sample_rates: [{ id: samplingMethod, rate: sampleRate }],
4263
+ },
4264
+ req.body,
4265
+ ];
4266
+ const envelope = createEnvelope(envelopeHeaders, [eventItem]);
4267
+ req.body = serializeEnvelope(envelope);
4223
4268
  }
4224
4269
  return req;
4225
4270
  }
@@ -4244,7 +4289,7 @@ var Sentry = (function (exports) {
4244
4289
  hub.bindClient(client);
4245
4290
  }
4246
4291
 
4247
- const SDK_VERSION = '6.18.0';
4292
+ const SDK_VERSION = '6.18.2';
4248
4293
 
4249
4294
  let originalFunctionToString;
4250
4295
  /** Patch toString calls to return proper name for wrapped functions */
@@ -4475,6 +4520,11 @@ var Sentry = (function (exports) {
4475
4520
 
4476
4521
  // global reference to slice
4477
4522
  const UNKNOWN_FUNCTION = '?';
4523
+ const OPERA10_PRIORITY = 10;
4524
+ const OPERA11_PRIORITY = 20;
4525
+ const CHROME_PRIORITY = 30;
4526
+ const WINJS_PRIORITY = 40;
4527
+ const GECKO_PRIORITY = 50;
4478
4528
  function createFrame(filename, func, lineno, colno) {
4479
4529
  const frame = {
4480
4530
  filename,
@@ -4513,6 +4563,7 @@ var Sentry = (function (exports) {
4513
4563
  }
4514
4564
  return;
4515
4565
  };
4566
+ const chromeStackParser = [CHROME_PRIORITY, chrome];
4516
4567
  // gecko regex: `(?:bundle|\d+\.js)`: `bundle` is for react native, `\d+\.js` also but specifically for ram bundles because it
4517
4568
  // generates filenames without a prefix like `file://` the filenames in the stacktrace are just 42.js
4518
4569
  // We need this specific case for now because we want no other regex to match.
@@ -4526,7 +4577,7 @@ var Sentry = (function (exports) {
4526
4577
  const subMatch = geckoEvalRegex.exec(parts[3]);
4527
4578
  if (subMatch) {
4528
4579
  // throw out eval line/column and use top-most line number
4529
- parts[1] = parts[1] || `eval`;
4580
+ parts[1] = parts[1] || 'eval';
4530
4581
  parts[3] = subMatch[1];
4531
4582
  parts[4] = subMatch[2];
4532
4583
  parts[5] = ''; // no column when eval
@@ -4539,6 +4590,7 @@ var Sentry = (function (exports) {
4539
4590
  }
4540
4591
  return;
4541
4592
  };
4593
+ const geckoStackParser = [GECKO_PRIORITY, gecko];
4542
4594
  const winjsRegex = /^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx|https?|webpack|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i;
4543
4595
  const winjs = line => {
4544
4596
  const parts = winjsRegex.exec(line);
@@ -4546,16 +4598,19 @@ var Sentry = (function (exports) {
4546
4598
  ? createFrame(parts[2], parts[1] || UNKNOWN_FUNCTION, +parts[3], parts[4] ? +parts[4] : undefined)
4547
4599
  : undefined;
4548
4600
  };
4601
+ const winjsStackParser = [WINJS_PRIORITY, winjs];
4549
4602
  const opera10Regex = / line (\d+).*script (?:in )?(\S+)(?:: in function (\S+))?$/i;
4550
4603
  const opera10 = line => {
4551
4604
  const parts = opera10Regex.exec(line);
4552
4605
  return parts ? createFrame(parts[2], parts[3] || UNKNOWN_FUNCTION, +parts[1]) : undefined;
4553
4606
  };
4607
+ const opera10StackParser = [OPERA10_PRIORITY, opera10];
4554
4608
  const opera11Regex = / line (\d+), column (\d+)\s*(?:in (?:<anonymous function: ([^>]+)>|([^)]+))\(.*\))? in (.*):\s*$/i;
4555
4609
  const opera11 = line => {
4556
4610
  const parts = opera11Regex.exec(line);
4557
4611
  return parts ? createFrame(parts[5], parts[3] || parts[4] || UNKNOWN_FUNCTION, +parts[1], +parts[2]) : undefined;
4558
4612
  };
4613
+ const opera11StackParser = [OPERA11_PRIORITY, opera11];
4559
4614
  /**
4560
4615
  * Safari web extensions, starting version unknown, can produce "frames-only" stacktraces.
4561
4616
  * What it means, is that instead of format like:
@@ -4599,7 +4654,7 @@ var Sentry = (function (exports) {
4599
4654
  type: ex && ex.name,
4600
4655
  value: extractMessage(ex),
4601
4656
  };
4602
- if (frames && frames.length) {
4657
+ if (frames.length) {
4603
4658
  exception.stacktrace = { frames };
4604
4659
  }
4605
4660
  if (exception.type === undefined && exception.value === '') {
@@ -4610,13 +4665,13 @@ var Sentry = (function (exports) {
4610
4665
  /**
4611
4666
  * @hidden
4612
4667
  */
4613
- function eventFromPlainObject(exception, syntheticException, rejection) {
4668
+ function eventFromPlainObject(exception, syntheticException, isUnhandledRejection) {
4614
4669
  const event = {
4615
4670
  exception: {
4616
4671
  values: [
4617
4672
  {
4618
- type: isEvent(exception) ? exception.constructor.name : rejection ? 'UnhandledRejection' : 'Error',
4619
- value: `Non-Error ${rejection ? 'promise rejection' : 'exception'} captured with keys: ${extractExceptionKeysForMessage(exception)}`,
4673
+ type: isEvent(exception) ? exception.constructor.name : isUnhandledRejection ? 'UnhandledRejection' : 'Error',
4674
+ value: `Non-Error ${isUnhandledRejection ? 'promise rejection' : 'exception'} captured with keys: ${extractExceptionKeysForMessage(exception)}`,
4620
4675
  },
4621
4676
  ],
4622
4677
  },
@@ -4650,8 +4705,7 @@ var Sentry = (function (exports) {
4650
4705
  const stacktrace = ex.stacktrace || ex.stack || '';
4651
4706
  const popSize = getPopSize(ex);
4652
4707
  try {
4653
- // The order of the parsers in important
4654
- return createStackParser(opera10, opera11, chrome, winjs, gecko)(stacktrace, popSize);
4708
+ return createStackParser(opera10StackParser, opera11StackParser, chromeStackParser, winjsStackParser, geckoStackParser)(stacktrace, popSize);
4655
4709
  }
4656
4710
  catch (e) {
4657
4711
  // no-empty
@@ -4676,7 +4730,6 @@ var Sentry = (function (exports) {
4676
4730
  * https://github.com/getsentry/sentry-javascript/issues/1949
4677
4731
  * In this specific case we try to extract stacktrace.message.error.message
4678
4732
  */
4679
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4680
4733
  function extractMessage(ex) {
4681
4734
  const message = ex && ex.message;
4682
4735
  if (!message) {
@@ -4686,17 +4739,14 @@ var Sentry = (function (exports) {
4686
4739
  return message.error.message;
4687
4740
  }
4688
4741
  return message;
4689
- }
4690
-
4742
+ }
4691
4743
  /**
4692
4744
  * Creates an {@link Event} from all inputs to `captureException` and non-primitive inputs to `captureMessage`.
4693
4745
  * @hidden
4694
4746
  */
4695
- function eventFromException(options, exception, hint) {
4747
+ function eventFromException(exception, hint, attachStacktrace) {
4696
4748
  const syntheticException = (hint && hint.syntheticException) || undefined;
4697
- const event = eventFromUnknownInput(exception, syntheticException, {
4698
- attachStacktrace: options.attachStacktrace,
4699
- });
4749
+ const event = eventFromUnknownInput(exception, syntheticException, attachStacktrace);
4700
4750
  addExceptionMechanism(event); // defaults to { type: 'generic', handled: true }
4701
4751
  event.level = exports.Severity.Error;
4702
4752
  if (hint && hint.event_id) {
@@ -4708,11 +4758,9 @@ var Sentry = (function (exports) {
4708
4758
  * Builds and Event from a Message
4709
4759
  * @hidden
4710
4760
  */
4711
- function eventFromMessage(options, message, level = exports.Severity.Info, hint) {
4761
+ function eventFromMessage(message, level = exports.Severity.Info, hint, attachStacktrace) {
4712
4762
  const syntheticException = (hint && hint.syntheticException) || undefined;
4713
- const event = eventFromString(message, syntheticException, {
4714
- attachStacktrace: options.attachStacktrace,
4715
- });
4763
+ const event = eventFromString(message, syntheticException, attachStacktrace);
4716
4764
  event.level = level;
4717
4765
  if (hint && hint.event_id) {
4718
4766
  event.event_id = hint.event_id;
@@ -4722,7 +4770,7 @@ var Sentry = (function (exports) {
4722
4770
  /**
4723
4771
  * @hidden
4724
4772
  */
4725
- function eventFromUnknownInput(exception, syntheticException, options = {}) {
4773
+ function eventFromUnknownInput(exception, syntheticException, attachStacktrace, isUnhandledRejection) {
4726
4774
  let event;
4727
4775
  if (isErrorEvent(exception) && exception.error) {
4728
4776
  // If it is an ErrorEvent with `error` property, extract it to get actual Error
@@ -4744,7 +4792,7 @@ var Sentry = (function (exports) {
4744
4792
  else {
4745
4793
  const name = domException.name || (isDOMError(domException) ? 'DOMError' : 'DOMException');
4746
4794
  const message = domException.message ? `${name}: ${domException.message}` : name;
4747
- event = eventFromString(message, syntheticException, options);
4795
+ event = eventFromString(message, syntheticException, attachStacktrace);
4748
4796
  addExceptionTypeValue(event, message);
4749
4797
  }
4750
4798
  if ('code' in domException) {
@@ -4761,7 +4809,7 @@ var Sentry = (function (exports) {
4761
4809
  // it manually. This will allow us to group events based on top-level keys which is much better than creating a new
4762
4810
  // group on any key/value change.
4763
4811
  const objectException = exception;
4764
- event = eventFromPlainObject(objectException, syntheticException, options.isRejection);
4812
+ event = eventFromPlainObject(objectException, syntheticException, isUnhandledRejection);
4765
4813
  addExceptionMechanism(event, {
4766
4814
  synthetic: true,
4767
4815
  });
@@ -4776,7 +4824,7 @@ var Sentry = (function (exports) {
4776
4824
  // - a plain Object
4777
4825
  //
4778
4826
  // So bail out and capture it as a simple message:
4779
- event = eventFromString(exception, syntheticException, options);
4827
+ event = eventFromString(exception, syntheticException, attachStacktrace);
4780
4828
  addExceptionTypeValue(event, `${exception}`, undefined);
4781
4829
  addExceptionMechanism(event, {
4782
4830
  synthetic: true,
@@ -4786,11 +4834,11 @@ var Sentry = (function (exports) {
4786
4834
  /**
4787
4835
  * @hidden
4788
4836
  */
4789
- function eventFromString(input, syntheticException, options = {}) {
4837
+ function eventFromString(input, syntheticException, attachStacktrace) {
4790
4838
  const event = {
4791
4839
  message: input,
4792
4840
  };
4793
- if (options.attachStacktrace && syntheticException) {
4841
+ if (attachStacktrace && syntheticException) {
4794
4842
  const frames = parseStackFrames(syntheticException);
4795
4843
  if (frames.length) {
4796
4844
  event.stacktrace = { frames };
@@ -4851,7 +4899,7 @@ var Sentry = (function (exports) {
4851
4899
  const document = global$4.document;
4852
4900
  let fetchImpl = global$4.fetch;
4853
4901
  // eslint-disable-next-line deprecation/deprecation
4854
- if (document && typeof document.createElement === `function`) {
4902
+ if (document && typeof document.createElement === 'function') {
4855
4903
  try {
4856
4904
  const sandbox = document.createElement('iframe');
4857
4905
  sandbox.hidden = true;
@@ -4972,25 +5020,18 @@ var Sentry = (function (exports) {
4972
5020
  }
4973
5021
  logger.log(`Flushing outcomes:\n${JSON.stringify(outcomes, null, 2)}`);
4974
5022
  const url = getEnvelopeEndpointWithUrlEncodedAuth(this._api.dsn, this._api.tunnel);
4975
- // Envelope header is required to be at least an empty object
4976
- const envelopeHeader = JSON.stringify(Object.assign({}, (this._api.tunnel && { dsn: dsnToString(this._api.dsn) })));
4977
- const itemHeaders = JSON.stringify({
4978
- type: 'client_report',
4979
- });
4980
- const item = JSON.stringify({
4981
- timestamp: dateTimestampInSeconds(),
4982
- discarded_events: Object.keys(outcomes).map(key => {
4983
- const [category, reason] = key.split(':');
4984
- return {
4985
- reason,
4986
- category,
4987
- quantity: outcomes[key],
4988
- };
4989
- }),
5023
+ const discardedEvents = Object.keys(outcomes).map(key => {
5024
+ const [category, reason] = key.split(':');
5025
+ return {
5026
+ reason,
5027
+ category,
5028
+ quantity: outcomes[key],
5029
+ };
5030
+ // TODO: Improve types on discarded_events to get rid of cast
4990
5031
  });
4991
- const envelope = `${envelopeHeader}\n${itemHeaders}\n${item}`;
5032
+ const envelope = createClientReportEnvelope(discardedEvents, this._api.tunnel && dsnToString(this._api.dsn));
4992
5033
  try {
4993
- sendReport(url, envelope);
5034
+ sendReport(url, serializeEnvelope(envelope));
4994
5035
  }
4995
5036
  catch (e) {
4996
5037
  logger.error(e);
@@ -5057,7 +5098,7 @@ var Sentry = (function (exports) {
5057
5098
  return true;
5058
5099
  }
5059
5100
  else if (raHeader) {
5060
- this._rateLimits.all = new Date(now + parseRetryAfterHeader(now, raHeader));
5101
+ this._rateLimits.all = new Date(now + parseRetryAfterHeader(raHeader, now));
5061
5102
  return true;
5062
5103
  }
5063
5104
  return false;
@@ -5195,13 +5236,13 @@ var Sentry = (function (exports) {
5195
5236
  * @inheritDoc
5196
5237
  */
5197
5238
  eventFromException(exception, hint) {
5198
- return eventFromException(this._options, exception, hint);
5239
+ return eventFromException(exception, hint, this._options.attachStacktrace);
5199
5240
  }
5200
5241
  /**
5201
5242
  * @inheritDoc
5202
5243
  */
5203
5244
  eventFromMessage(message, level = exports.Severity.Info, hint) {
5204
- return eventFromMessage(this._options, message, level, hint);
5245
+ return eventFromMessage(message, level, hint, this._options.attachStacktrace);
5205
5246
  }
5206
5247
  /**
5207
5248
  * @inheritDoc
@@ -5348,13 +5389,13 @@ var Sentry = (function (exports) {
5348
5389
  }
5349
5390
  if (!options.eventId) {
5350
5391
  if (isDebugBuild()) {
5351
- logger.error(`Missing eventId option in showReportDialog call`);
5392
+ logger.error('Missing eventId option in showReportDialog call');
5352
5393
  }
5353
5394
  return;
5354
5395
  }
5355
5396
  if (!options.dsn) {
5356
5397
  if (isDebugBuild()) {
5357
- logger.error(`Missing dsn option in showReportDialog call`);
5398
+ logger.error('Missing dsn option in showReportDialog call');
5358
5399
  }
5359
5400
  return;
5360
5401
  }
@@ -5428,10 +5469,7 @@ var Sentry = (function (exports) {
5428
5469
  }
5429
5470
  const event = error === undefined && isString(msg)
5430
5471
  ? _eventFromIncompleteOnError(msg, url, line, column)
5431
- : _enhanceEventWithInitialFrame(eventFromUnknownInput(error || msg, undefined, {
5432
- attachStacktrace,
5433
- isRejection: false,
5434
- }), url, line, column);
5472
+ : _enhanceEventWithInitialFrame(eventFromUnknownInput(error || msg, undefined, attachStacktrace, false), url, line, column);
5435
5473
  event.level = exports.Severity.Error;
5436
5474
  addMechanismAndCapture(hub, error, event, 'onerror');
5437
5475
  });
@@ -5470,10 +5508,7 @@ var Sentry = (function (exports) {
5470
5508
  }
5471
5509
  const event = isPrimitive(error)
5472
5510
  ? _eventFromRejectionWithPrimitive(error)
5473
- : eventFromUnknownInput(error, undefined, {
5474
- attachStacktrace,
5475
- isRejection: true,
5476
- });
5511
+ : eventFromUnknownInput(error, undefined, attachStacktrace, true);
5477
5512
  event.level = exports.Severity.Error;
5478
5513
  addMechanismAndCapture(hub, error, event, 'onunhandledrejection');
5479
5514
  return;
@@ -6116,7 +6151,7 @@ var Sentry = (function (exports) {
6116
6151
  // Juuust in case something goes wrong
6117
6152
  try {
6118
6153
  if (_shouldDropEvent(currentEvent, self._previousEvent)) {
6119
- logger.warn(`Event dropped due to being a duplicate of previously captured event.`);
6154
+ logger.warn('Event dropped due to being a duplicate of previously captured event.');
6120
6155
  return null;
6121
6156
  }
6122
6157
  }