@sentry/browser 7.0.0-beta.0 → 7.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. package/README.md +2 -3
  2. package/cjs/client.js +125 -102
  3. package/cjs/client.js.map +1 -1
  4. package/cjs/eventbuilder.js +225 -165
  5. package/cjs/eventbuilder.js.map +1 -1
  6. package/cjs/exports.js +55 -59
  7. package/cjs/exports.js.map +1 -1
  8. package/cjs/flags.js +7 -3
  9. package/cjs/flags.js.map +1 -1
  10. package/cjs/helpers.js +123 -96
  11. package/cjs/helpers.js.map +1 -1
  12. package/cjs/index.js +77 -10
  13. package/cjs/index.js.map +1 -1
  14. package/cjs/integrations/breadcrumbs.js +222 -174
  15. package/cjs/integrations/breadcrumbs.js.map +1 -1
  16. package/cjs/integrations/dedupe.js +184 -142
  17. package/cjs/integrations/dedupe.js.map +1 -1
  18. package/cjs/integrations/globalhandlers.js +211 -170
  19. package/cjs/integrations/globalhandlers.js.map +1 -1
  20. package/cjs/integrations/httpcontext.js +51 -0
  21. package/cjs/integrations/httpcontext.js.map +1 -0
  22. package/cjs/integrations/index.js +18 -14
  23. package/cjs/integrations/index.js.map +1 -1
  24. package/cjs/integrations/linkederrors.js +81 -50
  25. package/cjs/integrations/linkederrors.js.map +1 -1
  26. package/cjs/integrations/trycatch.js +247 -208
  27. package/cjs/integrations/trycatch.js.map +1 -1
  28. package/cjs/sdk.js +166 -125
  29. package/cjs/sdk.js.map +1 -1
  30. package/cjs/stack-parsers.js +143 -93
  31. package/cjs/stack-parsers.js.map +1 -1
  32. package/cjs/transports/fetch.js +30 -15
  33. package/cjs/transports/fetch.js.map +1 -1
  34. package/cjs/transports/index.js +10 -6
  35. package/cjs/transports/index.js.map +1 -1
  36. package/cjs/transports/utils.js +56 -51
  37. package/cjs/transports/utils.js.map +1 -1
  38. package/cjs/transports/xhr.js +40 -30
  39. package/cjs/transports/xhr.js.map +1 -1
  40. package/esm/client.js +124 -101
  41. package/esm/client.js.map +1 -1
  42. package/esm/eventbuilder.js +218 -158
  43. package/esm/eventbuilder.js.map +1 -1
  44. package/esm/exports.js +12 -8
  45. package/esm/exports.js.map +1 -1
  46. package/esm/flags.js +5 -2
  47. package/esm/flags.js.map +1 -1
  48. package/esm/helpers.js +122 -95
  49. package/esm/helpers.js.map +1 -1
  50. package/esm/index.js +27 -7
  51. package/esm/index.js.map +1 -1
  52. package/esm/integrations/breadcrumbs.js +218 -171
  53. package/esm/integrations/breadcrumbs.js.map +1 -1
  54. package/esm/integrations/dedupe.js +181 -139
  55. package/esm/integrations/dedupe.js.map +1 -1
  56. package/esm/integrations/globalhandlers.js +208 -167
  57. package/esm/integrations/globalhandlers.js.map +1 -1
  58. package/esm/integrations/httpcontext.js +49 -0
  59. package/esm/integrations/httpcontext.js.map +1 -0
  60. package/esm/integrations/index.js +7 -7
  61. package/esm/integrations/index.js.map +1 -1
  62. package/esm/integrations/linkederrors.js +77 -46
  63. package/esm/integrations/linkederrors.js.map +1 -1
  64. package/esm/integrations/trycatch.js +244 -205
  65. package/esm/integrations/trycatch.js.map +1 -1
  66. package/esm/sdk.js +163 -123
  67. package/esm/sdk.js.map +1 -1
  68. package/esm/stack-parsers.js +134 -91
  69. package/esm/stack-parsers.js.map +1 -1
  70. package/esm/transports/fetch.js +28 -13
  71. package/esm/transports/fetch.js.map +1 -1
  72. package/esm/transports/index.js +3 -3
  73. package/esm/transports/index.js.map +1 -1
  74. package/esm/transports/utils.js +55 -50
  75. package/esm/transports/utils.js.map +1 -1
  76. package/esm/transports/xhr.js +38 -28
  77. package/esm/transports/xhr.js.map +1 -1
  78. package/package.json +4 -4
  79. package/types/client.d.ts +3 -2
  80. package/types/client.d.ts.map +1 -1
  81. package/types/exports.d.ts +3 -4
  82. package/types/exports.d.ts.map +1 -1
  83. package/types/index.d.ts +1 -1
  84. package/types/integrations/{useragent.d.ts → httpcontext.d.ts} +3 -3
  85. package/types/integrations/httpcontext.d.ts.map +1 -0
  86. package/types/integrations/index.d.ts +1 -1
  87. package/types/integrations/index.d.ts.map +1 -1
  88. package/types/sdk.d.ts +2 -2
  89. package/types/sdk.d.ts.map +1 -1
  90. package/types/transports/fetch.d.ts +3 -5
  91. package/types/transports/fetch.d.ts.map +1 -1
  92. package/types/transports/types.d.ts +10 -0
  93. package/types/transports/types.d.ts.map +1 -0
  94. package/types/transports/xhr.d.ts +3 -7
  95. package/types/transports/xhr.d.ts.map +1 -1
  96. package/cjs/client.d.ts +0 -63
  97. package/cjs/client.d.ts.map +0 -1
  98. package/cjs/eventbuilder.d.ts +0 -37
  99. package/cjs/eventbuilder.d.ts.map +0 -1
  100. package/cjs/exports.d.ts +0 -11
  101. package/cjs/exports.d.ts.map +0 -1
  102. package/cjs/flags.d.ts +0 -3
  103. package/cjs/flags.d.ts.map +0 -1
  104. package/cjs/helpers.d.ts +0 -47
  105. package/cjs/helpers.d.ts.map +0 -1
  106. package/cjs/index.d.ts +0 -15
  107. package/cjs/index.d.ts.map +0 -1
  108. package/cjs/integrations/breadcrumbs.d.ts +0 -46
  109. package/cjs/integrations/breadcrumbs.d.ts.map +0 -1
  110. package/cjs/integrations/dedupe.d.ts +0 -21
  111. package/cjs/integrations/dedupe.d.ts.map +0 -1
  112. package/cjs/integrations/globalhandlers.d.ts +0 -30
  113. package/cjs/integrations/globalhandlers.d.ts.map +0 -1
  114. package/cjs/integrations/index.d.ts +0 -7
  115. package/cjs/integrations/index.d.ts.map +0 -1
  116. package/cjs/integrations/linkederrors.d.ts +0 -42
  117. package/cjs/integrations/linkederrors.d.ts.map +0 -1
  118. package/cjs/integrations/trycatch.d.ts +0 -33
  119. package/cjs/integrations/trycatch.d.ts.map +0 -1
  120. package/cjs/integrations/useragent.d.ts +0 -17
  121. package/cjs/integrations/useragent.d.ts.map +0 -1
  122. package/cjs/integrations/useragent.js +0 -40
  123. package/cjs/integrations/useragent.js.map +0 -1
  124. package/cjs/sdk.d.ts +0 -112
  125. package/cjs/sdk.d.ts.map +0 -1
  126. package/cjs/stack-parsers.d.ts +0 -9
  127. package/cjs/stack-parsers.d.ts.map +0 -1
  128. package/cjs/transports/fetch.d.ts +0 -10
  129. package/cjs/transports/fetch.d.ts.map +0 -1
  130. package/cjs/transports/index.d.ts +0 -3
  131. package/cjs/transports/index.d.ts.map +0 -1
  132. package/cjs/transports/utils.d.ts +0 -48
  133. package/cjs/transports/utils.d.ts.map +0 -1
  134. package/cjs/transports/xhr.d.ts +0 -11
  135. package/cjs/transports/xhr.d.ts.map +0 -1
  136. package/cjs/version.d.ts +0 -2
  137. package/cjs/version.d.ts.map +0 -1
  138. package/cjs/version.js +0 -4
  139. package/cjs/version.js.map +0 -1
  140. package/esm/client.d.ts +0 -63
  141. package/esm/client.d.ts.map +0 -1
  142. package/esm/eventbuilder.d.ts +0 -37
  143. package/esm/eventbuilder.d.ts.map +0 -1
  144. package/esm/exports.d.ts +0 -11
  145. package/esm/exports.d.ts.map +0 -1
  146. package/esm/flags.d.ts +0 -3
  147. package/esm/flags.d.ts.map +0 -1
  148. package/esm/helpers.d.ts +0 -47
  149. package/esm/helpers.d.ts.map +0 -1
  150. package/esm/index.d.ts +0 -15
  151. package/esm/index.d.ts.map +0 -1
  152. package/esm/integrations/breadcrumbs.d.ts +0 -46
  153. package/esm/integrations/breadcrumbs.d.ts.map +0 -1
  154. package/esm/integrations/dedupe.d.ts +0 -21
  155. package/esm/integrations/dedupe.d.ts.map +0 -1
  156. package/esm/integrations/globalhandlers.d.ts +0 -30
  157. package/esm/integrations/globalhandlers.d.ts.map +0 -1
  158. package/esm/integrations/index.d.ts +0 -7
  159. package/esm/integrations/index.d.ts.map +0 -1
  160. package/esm/integrations/linkederrors.d.ts +0 -42
  161. package/esm/integrations/linkederrors.d.ts.map +0 -1
  162. package/esm/integrations/trycatch.d.ts +0 -33
  163. package/esm/integrations/trycatch.d.ts.map +0 -1
  164. package/esm/integrations/useragent.d.ts +0 -17
  165. package/esm/integrations/useragent.d.ts.map +0 -1
  166. package/esm/integrations/useragent.js +0 -38
  167. package/esm/integrations/useragent.js.map +0 -1
  168. package/esm/sdk.d.ts +0 -112
  169. package/esm/sdk.d.ts.map +0 -1
  170. package/esm/stack-parsers.d.ts +0 -9
  171. package/esm/stack-parsers.d.ts.map +0 -1
  172. package/esm/transports/fetch.d.ts +0 -10
  173. package/esm/transports/fetch.d.ts.map +0 -1
  174. package/esm/transports/index.d.ts +0 -3
  175. package/esm/transports/index.d.ts.map +0 -1
  176. package/esm/transports/utils.d.ts +0 -48
  177. package/esm/transports/utils.d.ts.map +0 -1
  178. package/esm/transports/xhr.d.ts +0 -11
  179. package/esm/transports/xhr.d.ts.map +0 -1
  180. package/esm/version.d.ts +0 -2
  181. package/esm/version.d.ts.map +0 -1
  182. package/esm/version.js +0 -3
  183. package/esm/version.js.map +0 -1
  184. package/types/integrations/useragent.d.ts.map +0 -1
  185. package/types/version.d.ts +0 -2
  186. package/types/version.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"trycatch.js","sourceRoot":"","sources":["../../../../src/integrations/trycatch.ts"],"names":[],"mappings":";AACA,yCAA4F;AAE5F,wCAAkC;AAElC,MAAM,oBAAoB,GAAG;IAC3B,aAAa;IACb,QAAQ;IACR,MAAM;IACN,kBAAkB;IAClB,gBAAgB;IAChB,mBAAmB;IACnB,iBAAiB;IACjB,aAAa;IACb,YAAY;IACZ,oBAAoB;IACpB,aAAa;IACb,YAAY;IACZ,gBAAgB;IAChB,cAAc;IACd,iBAAiB;IACjB,aAAa;IACb,aAAa;IACb,cAAc;IACd,oBAAoB;IACpB,QAAQ;IACR,WAAW;IACX,cAAc;IACd,eAAe;IACf,WAAW;IACX,iBAAiB;IACjB,QAAQ;IACR,gBAAgB;IAChB,2BAA2B;IAC3B,sBAAsB;CACvB,CAAC;AAaF,0FAA0F;AAC1F,MAAa,QAAQ;IAcnB;;OAEG;IACH,YAAmB,OAAkC;QAXrD;;WAEG;QACI,SAAI,GAAW,QAAQ,CAAC,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,CACF,CAAC;AACJ,CAAC","sourcesContent":["import { Integration, WrappedFunction } from '@sentry/types';\nimport { fill, getFunctionName, getGlobalObject, getOriginalFunction } from '@sentry/utils';\n\nimport { wrap } from '../helpers';\n\nconst DEFAULT_EVENT_TARGET = [\n 'EventTarget',\n 'Window',\n 'Node',\n 'ApplicationCache',\n 'AudioTrackList',\n 'ChannelMergerNode',\n 'CryptoOperation',\n 'EventSource',\n 'FileReader',\n 'HTMLUnknownElement',\n 'IDBDatabase',\n 'IDBRequest',\n 'IDBTransaction',\n 'KeyOperation',\n 'MediaController',\n 'MessagePort',\n 'ModalWindow',\n 'Notification',\n 'SVGElementInstance',\n 'Screen',\n 'TextTrack',\n 'TextTrackCue',\n 'TextTrackList',\n 'WebSocket',\n 'WebSocketWorker',\n 'Worker',\n 'XMLHttpRequest',\n 'XMLHttpRequestEventTarget',\n 'XMLHttpRequestUpload',\n];\n\ntype XMLHttpRequestProp = 'onload' | 'onerror' | 'onprogress' | 'onreadystatechange';\n\n/** JSDoc */\ninterface TryCatchOptions {\n setTimeout: boolean;\n setInterval: boolean;\n requestAnimationFrame: boolean;\n XMLHttpRequest: boolean;\n eventTarget: boolean | string[];\n}\n\n/** Wrap timer functions and event targets to catch errors and provide better meta data */\nexport class TryCatch implements Integration {\n /**\n * @inheritDoc\n */\n public static id: string = 'TryCatch';\n\n /**\n * @inheritDoc\n */\n public name: string = TryCatch.id;\n\n /** JSDoc */\n private readonly _options: TryCatchOptions;\n\n /**\n * @inheritDoc\n */\n public constructor(options?: Partial<TryCatchOptions>) {\n this._options = {\n XMLHttpRequest: true,\n eventTarget: true,\n requestAnimationFrame: true,\n setInterval: true,\n setTimeout: true,\n ...options,\n };\n }\n\n /**\n * Wrap timer functions and event targets to catch errors\n * and provide better metadata.\n */\n public setupOnce(): void {\n const global = getGlobalObject();\n\n if (this._options.setTimeout) {\n fill(global, 'setTimeout', _wrapTimeFunction);\n }\n\n if (this._options.setInterval) {\n fill(global, 'setInterval', _wrapTimeFunction);\n }\n\n if (this._options.requestAnimationFrame) {\n fill(global, 'requestAnimationFrame', _wrapRAF);\n }\n\n if (this._options.XMLHttpRequest && 'XMLHttpRequest' in global) {\n fill(XMLHttpRequest.prototype, 'send', _wrapXHR);\n }\n\n const eventTargetOption = this._options.eventTarget;\n if (eventTargetOption) {\n const eventTarget = Array.isArray(eventTargetOption) ? eventTargetOption : DEFAULT_EVENT_TARGET;\n eventTarget.forEach(_wrapEventTarget);\n }\n }\n}\n\n/** JSDoc */\nfunction _wrapTimeFunction(original: () => void): () => number {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return function (this: any, ...args: any[]): number {\n const originalCallback = args[0];\n args[0] = wrap(originalCallback, {\n mechanism: {\n data: { function: getFunctionName(original) },\n handled: true,\n type: 'instrument',\n },\n });\n return original.apply(this, args);\n };\n}\n\n/** JSDoc */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction _wrapRAF(original: any): (callback: () => void) => any {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return function (this: any, callback: () => void): () => void {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return original.apply(this, [\n wrap(callback, {\n mechanism: {\n data: {\n function: 'requestAnimationFrame',\n handler: getFunctionName(original),\n },\n handled: true,\n type: 'instrument',\n },\n }),\n ]);\n };\n}\n\n/** JSDoc */\nfunction _wrapXHR(originalSend: () => void): () => void {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return function (this: XMLHttpRequest, ...args: any[]): void {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const xhr = this;\n const xmlHttpRequestProps: XMLHttpRequestProp[] = ['onload', 'onerror', 'onprogress', 'onreadystatechange'];\n\n xmlHttpRequestProps.forEach(prop => {\n if (prop in xhr && typeof xhr[prop] === 'function') {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n fill(xhr, prop, function (original: WrappedFunction): () => any {\n const wrapOptions = {\n mechanism: {\n data: {\n function: prop,\n handler: getFunctionName(original),\n },\n handled: true,\n type: 'instrument',\n },\n };\n\n // If Instrument integration has been called before TryCatch, get the name of original function\n const originalFunction = getOriginalFunction(original);\n if (originalFunction) {\n wrapOptions.mechanism.data.handler = getFunctionName(originalFunction);\n }\n\n // Otherwise wrap directly\n return wrap(original, wrapOptions);\n });\n }\n });\n\n return originalSend.apply(this, args);\n };\n}\n\n/** JSDoc */\nfunction _wrapEventTarget(target: string): void {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const global = getGlobalObject() as { [key: string]: any };\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const proto = global[target] && global[target].prototype;\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, no-prototype-builtins\n if (!proto || !proto.hasOwnProperty || !proto.hasOwnProperty('addEventListener')) {\n return;\n }\n\n fill(proto, 'addEventListener', function (original: () => void): (\n eventName: string,\n fn: EventListenerObject,\n options?: boolean | AddEventListenerOptions,\n ) => void {\n return function (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this: any,\n eventName: string,\n fn: EventListenerObject,\n options?: boolean | AddEventListenerOptions,\n ): (eventName: string, fn: EventListenerObject, capture?: boolean, secure?: boolean) => void {\n try {\n if (typeof fn.handleEvent === 'function') {\n fn.handleEvent = wrap(fn.handleEvent.bind(fn), {\n mechanism: {\n data: {\n function: 'handleEvent',\n handler: getFunctionName(fn),\n target,\n },\n handled: true,\n type: 'instrument',\n },\n });\n }\n } catch (err) {\n // can sometimes get 'Permission denied to access property \"handle Event'\n }\n\n return original.apply(this, [\n eventName,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n wrap(fn as any as WrappedFunction, {\n mechanism: {\n data: {\n function: 'addEventListener',\n handler: getFunctionName(fn),\n target,\n },\n handled: true,\n type: 'instrument',\n },\n }),\n options,\n ]);\n };\n });\n\n fill(\n proto,\n 'removeEventListener',\n function (\n originalRemoveEventListener: () => void,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ): (this: any, eventName: string, fn: EventListenerObject, options?: boolean | EventListenerOptions) => () => void {\n return function (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this: any,\n eventName: string,\n fn: EventListenerObject,\n options?: boolean | EventListenerOptions,\n ): () => void {\n /**\n * There are 2 possible scenarios here:\n *\n * 1. Someone passes a callback, which was attached prior to Sentry initialization, or by using unmodified\n * method, eg. `document.addEventListener.call(el, name, handler). In this case, we treat this function\n * as a pass-through, and call original `removeEventListener` with it.\n *\n * 2. Someone passes a callback, which was attached after Sentry was initialized, which means that it was using\n * our wrapped version of `addEventListener`, which internally calls `wrap` helper.\n * This helper \"wraps\" whole callback inside a try/catch statement, and attached appropriate metadata to it,\n * in order for us to make a distinction between wrapped/non-wrapped functions possible.\n * If a function was wrapped, it has additional property of `__sentry_wrapped__`, holding the handler.\n *\n * When someone adds a handler prior to initialization, and then do it again, but after,\n * then we have to detach both of them. Otherwise, if we'd detach only wrapped one, it'd be impossible\n * to get rid of the initial handler and it'd stick there forever.\n */\n const wrappedEventHandler = fn as unknown as WrappedFunction;\n try {\n const originalEventHandler = wrappedEventHandler && wrappedEventHandler.__sentry_wrapped__;\n if (originalEventHandler) {\n originalRemoveEventListener.call(this, eventName, originalEventHandler, options);\n }\n } catch (e) {\n // ignore, accessing __sentry_wrapped__ will throw in some Selenium environments\n }\n return originalRemoveEventListener.call(this, eventName, wrappedEventHandler, options);\n };\n },\n );\n}\n"]}
1
+ {"version":3,"file":"trycatch.js","sources":["../../../../src/integrations/trycatch.ts"],"sourcesContent":["import { Integration, WrappedFunction } from '@sentry/types';\nimport { fill, getFunctionName, getGlobalObject, getOriginalFunction } from '@sentry/utils';\n\nimport { wrap } from '../helpers';\n\nconst DEFAULT_EVENT_TARGET = [\n 'EventTarget',\n 'Window',\n 'Node',\n 'ApplicationCache',\n 'AudioTrackList',\n 'ChannelMergerNode',\n 'CryptoOperation',\n 'EventSource',\n 'FileReader',\n 'HTMLUnknownElement',\n 'IDBDatabase',\n 'IDBRequest',\n 'IDBTransaction',\n 'KeyOperation',\n 'MediaController',\n 'MessagePort',\n 'ModalWindow',\n 'Notification',\n 'SVGElementInstance',\n 'Screen',\n 'TextTrack',\n 'TextTrackCue',\n 'TextTrackList',\n 'WebSocket',\n 'WebSocketWorker',\n 'Worker',\n 'XMLHttpRequest',\n 'XMLHttpRequestEventTarget',\n 'XMLHttpRequestUpload',\n];\n\ntype XMLHttpRequestProp = 'onload' | 'onerror' | 'onprogress' | 'onreadystatechange';\n\n/** JSDoc */\ninterface TryCatchOptions {\n setTimeout: boolean;\n setInterval: boolean;\n requestAnimationFrame: boolean;\n XMLHttpRequest: boolean;\n eventTarget: boolean | string[];\n}\n\n/** Wrap timer functions and event targets to catch errors and provide better meta data */\nexport class TryCatch implements Integration {\n /**\n * @inheritDoc\n */\n public static id: string = 'TryCatch';\n\n /**\n * @inheritDoc\n */\n public name: string = TryCatch.id;\n\n /** JSDoc */\n private readonly _options: TryCatchOptions;\n\n /**\n * @inheritDoc\n */\n public constructor(options?: Partial<TryCatchOptions>) {\n this._options = {\n XMLHttpRequest: true,\n eventTarget: true,\n requestAnimationFrame: true,\n setInterval: true,\n setTimeout: true,\n ...options,\n };\n }\n\n /**\n * Wrap timer functions and event targets to catch errors\n * and provide better metadata.\n */\n public setupOnce(): void {\n const global = getGlobalObject();\n\n if (this._options.setTimeout) {\n fill(global, 'setTimeout', _wrapTimeFunction);\n }\n\n if (this._options.setInterval) {\n fill(global, 'setInterval', _wrapTimeFunction);\n }\n\n if (this._options.requestAnimationFrame) {\n fill(global, 'requestAnimationFrame', _wrapRAF);\n }\n\n if (this._options.XMLHttpRequest && 'XMLHttpRequest' in global) {\n fill(XMLHttpRequest.prototype, 'send', _wrapXHR);\n }\n\n const eventTargetOption = this._options.eventTarget;\n if (eventTargetOption) {\n const eventTarget = Array.isArray(eventTargetOption) ? eventTargetOption : DEFAULT_EVENT_TARGET;\n eventTarget.forEach(_wrapEventTarget);\n }\n }\n}\n\n/** JSDoc */\nfunction _wrapTimeFunction(original: () => void): () => number {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return function (this: any, ...args: any[]): number {\n const originalCallback = args[0];\n args[0] = wrap(originalCallback, {\n mechanism: {\n data: { function: getFunctionName(original) },\n handled: true,\n type: 'instrument',\n },\n });\n return original.apply(this, args);\n };\n}\n\n/** JSDoc */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction _wrapRAF(original: any): (callback: () => void) => any {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return function (this: any, callback: () => void): () => void {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return original.apply(this, [\n wrap(callback, {\n mechanism: {\n data: {\n function: 'requestAnimationFrame',\n handler: getFunctionName(original),\n },\n handled: true,\n type: 'instrument',\n },\n }),\n ]);\n };\n}\n\n/** JSDoc */\nfunction _wrapXHR(originalSend: () => void): () => void {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return function (this: XMLHttpRequest, ...args: any[]): void {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const xhr = this;\n const xmlHttpRequestProps: XMLHttpRequestProp[] = ['onload', 'onerror', 'onprogress', 'onreadystatechange'];\n\n xmlHttpRequestProps.forEach(prop => {\n if (prop in xhr && typeof xhr[prop] === 'function') {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n fill(xhr, prop, function (original: WrappedFunction): () => any {\n const wrapOptions = {\n mechanism: {\n data: {\n function: prop,\n handler: getFunctionName(original),\n },\n handled: true,\n type: 'instrument',\n },\n };\n\n // If Instrument integration has been called before TryCatch, get the name of original function\n const originalFunction = getOriginalFunction(original);\n if (originalFunction) {\n wrapOptions.mechanism.data.handler = getFunctionName(originalFunction);\n }\n\n // Otherwise wrap directly\n return wrap(original, wrapOptions);\n });\n }\n });\n\n return originalSend.apply(this, args);\n };\n}\n\n/** JSDoc */\nfunction _wrapEventTarget(target: string): void {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const global = getGlobalObject() as { [key: string]: any };\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const proto = global[target] && global[target].prototype;\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, no-prototype-builtins\n if (!proto || !proto.hasOwnProperty || !proto.hasOwnProperty('addEventListener')) {\n return;\n }\n\n fill(proto, 'addEventListener', function (original: () => void): (\n eventName: string,\n fn: EventListenerObject,\n options?: boolean | AddEventListenerOptions,\n ) => void {\n return function (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this: any,\n eventName: string,\n fn: EventListenerObject,\n options?: boolean | AddEventListenerOptions,\n ): (eventName: string, fn: EventListenerObject, capture?: boolean, secure?: boolean) => void {\n try {\n if (typeof fn.handleEvent === 'function') {\n fn.handleEvent = wrap(fn.handleEvent.bind(fn), {\n mechanism: {\n data: {\n function: 'handleEvent',\n handler: getFunctionName(fn),\n target,\n },\n handled: true,\n type: 'instrument',\n },\n });\n }\n } catch (err) {\n // can sometimes get 'Permission denied to access property \"handle Event'\n }\n\n return original.apply(this, [\n eventName,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n wrap(fn as any as WrappedFunction, {\n mechanism: {\n data: {\n function: 'addEventListener',\n handler: getFunctionName(fn),\n target,\n },\n handled: true,\n type: 'instrument',\n },\n }),\n options,\n ]);\n };\n });\n\n fill(\n proto,\n 'removeEventListener',\n function (\n originalRemoveEventListener: () => void,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ): (this: any, eventName: string, fn: EventListenerObject, options?: boolean | EventListenerOptions) => () => void {\n return function (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this: any,\n eventName: string,\n fn: EventListenerObject,\n options?: boolean | EventListenerOptions,\n ): () => void {\n /**\n * There are 2 possible scenarios here:\n *\n * 1. Someone passes a callback, which was attached prior to Sentry initialization, or by using unmodified\n * method, eg. `document.addEventListener.call(el, name, handler). In this case, we treat this function\n * as a pass-through, and call original `removeEventListener` with it.\n *\n * 2. Someone passes a callback, which was attached after Sentry was initialized, which means that it was using\n * our wrapped version of `addEventListener`, which internally calls `wrap` helper.\n * This helper \"wraps\" whole callback inside a try/catch statement, and attached appropriate metadata to it,\n * in order for us to make a distinction between wrapped/non-wrapped functions possible.\n * If a function was wrapped, it has additional property of `__sentry_wrapped__`, holding the handler.\n *\n * When someone adds a handler prior to initialization, and then do it again, but after,\n * then we have to detach both of them. Otherwise, if we'd detach only wrapped one, it'd be impossible\n * to get rid of the initial handler and it'd stick there forever.\n */\n const wrappedEventHandler = fn as unknown as WrappedFunction;\n try {\n const originalEventHandler = wrappedEventHandler && wrappedEventHandler.__sentry_wrapped__;\n if (originalEventHandler) {\n originalRemoveEventListener.call(this, eventName, originalEventHandler, options);\n }\n } catch (e) {\n // ignore, accessing __sentry_wrapped__ will throw in some Selenium environments\n }\n return originalRemoveEventListener.call(this, eventName, wrappedEventHandler, options);\n };\n },\n );\n}\n"],"names":[],"mappings":";;;;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAaA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAEA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAEA;AACA;AAEA;AACA;AACA;AACA;;AAIA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;"}
package/cjs/sdk.js CHANGED
@@ -1,22 +1,33 @@
1
- Object.defineProperty(exports, "__esModule", { value: true });
2
- const core_1 = require("@sentry/core");
3
- const utils_1 = require("@sentry/utils");
4
- const client_1 = require("./client");
5
- const flags_1 = require("./flags");
6
- const helpers_1 = require("./helpers");
7
- const integrations_1 = require("./integrations");
8
- const stack_parsers_1 = require("./stack-parsers");
9
- const transports_1 = require("./transports");
10
- exports.defaultIntegrations = [
11
- new core_1.Integrations.InboundFilters(),
12
- new core_1.Integrations.FunctionToString(),
13
- new integrations_1.TryCatch(),
14
- new integrations_1.Breadcrumbs(),
15
- new integrations_1.GlobalHandlers(),
16
- new integrations_1.LinkedErrors(),
17
- new integrations_1.Dedupe(),
18
- new integrations_1.UserAgent(),
1
+ Object.defineProperty(exports, '__esModule', { value: true });
2
+
3
+ var core = require('@sentry/core');
4
+ var utils = require('@sentry/utils');
5
+ var client = require('./client.js');
6
+ var flags = require('./flags.js');
7
+ var helpers = require('./helpers.js');
8
+ require('./integrations/index.js');
9
+ var stackParsers = require('./stack-parsers.js');
10
+ require('./transports/index.js');
11
+ var trycatch = require('./integrations/trycatch.js');
12
+ var breadcrumbs = require('./integrations/breadcrumbs.js');
13
+ var globalhandlers = require('./integrations/globalhandlers.js');
14
+ var linkederrors = require('./integrations/linkederrors.js');
15
+ var dedupe = require('./integrations/dedupe.js');
16
+ var httpcontext = require('./integrations/httpcontext.js');
17
+ var fetch = require('./transports/fetch.js');
18
+ var xhr = require('./transports/xhr.js');
19
+
20
+ var defaultIntegrations = [
21
+ new core.Integrations.InboundFilters(),
22
+ new core.Integrations.FunctionToString(),
23
+ new trycatch.TryCatch(),
24
+ new breadcrumbs.Breadcrumbs(),
25
+ new globalhandlers.GlobalHandlers(),
26
+ new linkederrors.LinkedErrors(),
27
+ new dedupe.Dedupe(),
28
+ new httpcontext.HttpContext(),
19
29
  ];
30
+
20
31
  /**
21
32
  * The Sentry Browser SDK Client.
22
33
  *
@@ -75,94 +86,109 @@ exports.defaultIntegrations = [
75
86
  * @see {@link BrowserOptions} for documentation on configuration options.
76
87
  */
77
88
  function init(options = {}) {
78
- if (options.defaultIntegrations === undefined) {
79
- options.defaultIntegrations = exports.defaultIntegrations;
80
- }
81
- if (options.release === undefined) {
82
- const window = utils_1.getGlobalObject();
83
- // This supports the variable that sentry-webpack-plugin injects
84
- if (window.SENTRY_RELEASE && window.SENTRY_RELEASE.id) {
85
- options.release = window.SENTRY_RELEASE.id;
86
- }
87
- }
88
- if (options.autoSessionTracking === undefined) {
89
- options.autoSessionTracking = true;
90
- }
91
- if (options.sendClientReports === undefined) {
92
- options.sendClientReports = true;
93
- }
94
- const clientOptions = Object.assign(Object.assign({}, options), { stackParser: utils_1.stackParserFromStackParserOptions(options.stackParser || stack_parsers_1.defaultStackParser), integrations: core_1.getIntegrationsToSetup(options), transport: options.transport || (utils_1.supportsFetch() ? transports_1.makeFetchTransport : transports_1.makeXHRTransport) });
95
- core_1.initAndBind(client_1.BrowserClient, clientOptions);
96
- if (options.autoSessionTracking) {
97
- startSessionTracking();
89
+ if (options.defaultIntegrations === undefined) {
90
+ options.defaultIntegrations = defaultIntegrations;
91
+ }
92
+ if (options.release === undefined) {
93
+ var window = utils.getGlobalObject();
94
+ // This supports the variable that sentry-webpack-plugin injects
95
+ if (window.SENTRY_RELEASE && window.SENTRY_RELEASE.id) {
96
+ options.release = window.SENTRY_RELEASE.id;
98
97
  }
98
+ }
99
+ if (options.autoSessionTracking === undefined) {
100
+ options.autoSessionTracking = true;
101
+ }
102
+ if (options.sendClientReports === undefined) {
103
+ options.sendClientReports = true;
104
+ }
105
+
106
+ var clientOptions = {
107
+ ...options,
108
+ stackParser: utils.stackParserFromStackParserOptions(options.stackParser || stackParsers.defaultStackParser),
109
+ integrations: core.getIntegrationsToSetup(options),
110
+ transport: options.transport || (utils.supportsFetch() ? fetch.makeFetchTransport : xhr.makeXHRTransport),
111
+ };
112
+
113
+ core.initAndBind(client.BrowserClient, clientOptions);
114
+
115
+ if (options.autoSessionTracking) {
116
+ startSessionTracking();
117
+ }
99
118
  }
100
- exports.init = init;
119
+
101
120
  /**
102
121
  * Present the user with a report dialog.
103
122
  *
104
123
  * @param options Everything is optional, we try to fetch all info need from the global scope.
105
124
  */
106
- function showReportDialog(options = {}, hub = core_1.getCurrentHub()) {
107
- // doesn't work without a document (React Native)
108
- const global = utils_1.getGlobalObject();
109
- if (!global.document) {
110
- flags_1.IS_DEBUG_BUILD && utils_1.logger.error('Global document not defined in showReportDialog call');
111
- return;
112
- }
113
- const { client, scope } = hub.getStackTop();
114
- const dsn = options.dsn || (client && client.getDsn());
115
- if (!dsn) {
116
- flags_1.IS_DEBUG_BUILD && utils_1.logger.error('DSN not configured for showReportDialog call');
117
- return;
118
- }
119
- if (scope) {
120
- options.user = Object.assign(Object.assign({}, scope.getUser()), options.user);
121
- }
122
- if (!options.eventId) {
123
- options.eventId = hub.lastEventId();
124
- }
125
- const script = global.document.createElement('script');
126
- script.async = true;
127
- script.src = core_1.getReportDialogEndpoint(dsn, options);
128
- if (options.onLoad) {
129
- // eslint-disable-next-line @typescript-eslint/unbound-method
125
+ function showReportDialog(options = {}, hub = core.getCurrentHub()) {
126
+ // doesn't work without a document (React Native)
127
+ var global = utils.getGlobalObject();
128
+ if (!global.document) {
129
+ flags.IS_DEBUG_BUILD && utils.logger.error('Global document not defined in showReportDialog call');
130
+ return;
131
+ }
132
+
133
+ const { client, scope } = hub.getStackTop();
134
+ var dsn = options.dsn || (client && client.getDsn());
135
+ if (!dsn) {
136
+ flags.IS_DEBUG_BUILD && utils.logger.error('DSN not configured for showReportDialog call');
137
+ return;
138
+ }
139
+
140
+ if (scope) {
141
+ options.user = {
142
+ ...scope.getUser(),
143
+ ...options.user,
144
+ };
145
+ }
146
+
147
+ if (!options.eventId) {
148
+ options.eventId = hub.lastEventId();
149
+ }
150
+
151
+ var script = global.document.createElement('script');
152
+ script.async = true;
153
+ script.src = core.getReportDialogEndpoint(dsn, options);
154
+
155
+ if (options.onLoad) {
130
156
  script.onload = options.onLoad;
131
- }
132
- const injectionPoint = global.document.head || global.document.body;
133
- if (injectionPoint) {
134
- injectionPoint.appendChild(script);
135
- }
136
- else {
137
- flags_1.IS_DEBUG_BUILD && utils_1.logger.error('Not injecting report dialog. No injection point found in HTML');
138
- }
157
+ }
158
+
159
+ var injectionPoint = global.document.head || global.document.body;
160
+ if (injectionPoint) {
161
+ injectionPoint.appendChild(script);
162
+ } else {
163
+ flags.IS_DEBUG_BUILD && utils.logger.error('Not injecting report dialog. No injection point found in HTML');
164
+ }
139
165
  }
140
- exports.showReportDialog = showReportDialog;
166
+
141
167
  /**
142
168
  * This is the getter for lastEventId.
143
169
  *
144
170
  * @returns The last event id of a captured event.
145
171
  */
146
172
  function lastEventId() {
147
- return core_1.getCurrentHub().lastEventId();
173
+ return core.getCurrentHub().lastEventId();
148
174
  }
149
- exports.lastEventId = lastEventId;
175
+
150
176
  /**
151
177
  * This function is here to be API compatible with the loader.
152
178
  * @hidden
153
179
  */
154
180
  function forceLoad() {
155
- // Noop
181
+ // Noop
156
182
  }
157
- exports.forceLoad = forceLoad;
183
+
158
184
  /**
159
185
  * This function is here to be API compatible with the loader.
160
186
  * @hidden
161
187
  */
162
188
  function onLoad(callback) {
163
- callback();
189
+ callback();
164
190
  }
165
- exports.onLoad = onLoad;
191
+
166
192
  /**
167
193
  * Call `flush()` on the current client, if there is one. See {@link Client.flush}.
168
194
  *
@@ -172,14 +198,14 @@ exports.onLoad = onLoad;
172
198
  * doesn't (or if there's no client defined).
173
199
  */
174
200
  function flush(timeout) {
175
- const client = core_1.getCurrentHub().getClient();
176
- if (client) {
177
- return client.flush(timeout);
178
- }
179
- flags_1.IS_DEBUG_BUILD && utils_1.logger.warn('Cannot flush events. No client defined.');
180
- return utils_1.resolvedSyncPromise(false);
201
+ var client = core.getCurrentHub().getClient();
202
+ if (client) {
203
+ return client.flush(timeout);
204
+ }
205
+ flags.IS_DEBUG_BUILD && utils.logger.warn('Cannot flush events. No client defined.');
206
+ return utils.resolvedSyncPromise(false);
181
207
  }
182
- exports.flush = flush;
208
+
183
209
  /**
184
210
  * Call `close()` on the current client, if there is one. See {@link Client.close}.
185
211
  *
@@ -189,14 +215,14 @@ exports.flush = flush;
189
215
  * doesn't (or if there's no client defined).
190
216
  */
191
217
  function close(timeout) {
192
- const client = core_1.getCurrentHub().getClient();
193
- if (client) {
194
- return client.close(timeout);
195
- }
196
- flags_1.IS_DEBUG_BUILD && utils_1.logger.warn('Cannot flush events and disable SDK. No client defined.');
197
- return utils_1.resolvedSyncPromise(false);
218
+ var client = core.getCurrentHub().getClient();
219
+ if (client) {
220
+ return client.close(timeout);
221
+ }
222
+ flags.IS_DEBUG_BUILD && utils.logger.warn('Cannot flush events and disable SDK. No client defined.');
223
+ return utils.resolvedSyncPromise(false);
198
224
  }
199
- exports.close = close;
225
+
200
226
  /**
201
227
  * Wrap code within a try/catch block so the SDK is able to capture errors.
202
228
  *
@@ -204,46 +230,61 @@ exports.close = close;
204
230
  *
205
231
  * @returns The result of wrapped function call.
206
232
  */
207
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
208
233
  function wrap(fn) {
209
- return helpers_1.wrap(fn)();
234
+ return helpers.wrap(fn)();
210
235
  }
211
- exports.wrap = wrap;
236
+
212
237
  function startSessionOnHub(hub) {
213
- hub.startSession({ ignoreDuration: true });
214
- hub.captureSession();
238
+ hub.startSession({ ignoreDuration: true });
239
+ hub.captureSession();
215
240
  }
241
+
216
242
  /**
217
243
  * Enable automatic Session Tracking for the initial page load.
218
244
  */
219
245
  function startSessionTracking() {
220
- const window = utils_1.getGlobalObject();
221
- const document = window.document;
222
- if (typeof document === 'undefined') {
223
- flags_1.IS_DEBUG_BUILD && utils_1.logger.warn('Session tracking in non-browser environment with @sentry/browser is not supported.');
224
- return;
246
+ var window = utils.getGlobalObject();
247
+ var document = window.document;
248
+
249
+ if (typeof document === 'undefined') {
250
+ flags.IS_DEBUG_BUILD && utils.logger.warn('Session tracking in non-browser environment with @sentry/browser is not supported.');
251
+ return;
252
+ }
253
+
254
+ var hub = core.getCurrentHub();
255
+
256
+ // The only way for this to be false is for there to be a version mismatch between @sentry/browser (>= 6.0.0) and
257
+ // @sentry/hub (< 5.27.0). In the simple case, there won't ever be such a mismatch, because the two packages are
258
+ // pinned at the same version in package.json, but there are edge cases where it's possible. See
259
+ // https://github.com/getsentry/sentry-javascript/issues/3207 and
260
+ // https://github.com/getsentry/sentry-javascript/issues/3234 and
261
+ // https://github.com/getsentry/sentry-javascript/issues/3278.
262
+ if (!hub.captureSession) {
263
+ return;
264
+ }
265
+
266
+ // The session duration for browser sessions does not track a meaningful
267
+ // concept that can be used as a metric.
268
+ // Automatically captured sessions are akin to page views, and thus we
269
+ // discard their duration.
270
+ startSessionOnHub(hub);
271
+
272
+ // We want to create a session for every navigation as well
273
+ utils.addInstrumentationHandler('history', ({ from, to }) => {
274
+ // Don't create an additional session for the initial route or if the location did not change
275
+ if (!(from === undefined || from === to)) {
276
+ startSessionOnHub(core.getCurrentHub());
225
277
  }
226
- const hub = core_1.getCurrentHub();
227
- // The only way for this to be false is for there to be a version mismatch between @sentry/browser (>= 6.0.0) and
228
- // @sentry/hub (< 5.27.0). In the simple case, there won't ever be such a mismatch, because the two packages are
229
- // pinned at the same version in package.json, but there are edge cases where it's possible. See
230
- // https://github.com/getsentry/sentry-javascript/issues/3207 and
231
- // https://github.com/getsentry/sentry-javascript/issues/3234 and
232
- // https://github.com/getsentry/sentry-javascript/issues/3278.
233
- if (!hub.captureSession) {
234
- return;
235
- }
236
- // The session duration for browser sessions does not track a meaningful
237
- // concept that can be used as a metric.
238
- // Automatically captured sessions are akin to page views, and thus we
239
- // discard their duration.
240
- startSessionOnHub(hub);
241
- // We want to create a session for every navigation as well
242
- utils_1.addInstrumentationHandler('history', ({ from, to }) => {
243
- // Don't create an additional session for the initial route or if the location did not change
244
- if (!(from === undefined || from === to)) {
245
- startSessionOnHub(core_1.getCurrentHub());
246
- }
247
- });
278
+ });
248
279
  }
249
- //# sourceMappingURL=sdk.js.map
280
+
281
+ exports.close = close;
282
+ exports.defaultIntegrations = defaultIntegrations;
283
+ exports.flush = flush;
284
+ exports.forceLoad = forceLoad;
285
+ exports.init = init;
286
+ exports.lastEventId = lastEventId;
287
+ exports.onLoad = onLoad;
288
+ exports.showReportDialog = showReportDialog;
289
+ exports.wrap = wrap;
290
+ //# sourceMappingURL=sdk.js.map
package/cjs/sdk.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"sdk.js","sourceRoot":"","sources":["../../../src/sdk.ts"],"names":[],"mappings":";AAAA,uCAOsB;AACtB,yCAOuB;AAEvB,qCAA+E;AAC/E,mCAAyC;AACzC,uCAAsE;AACtE,iDAAwG;AACxG,mDAAqD;AACrD,6CAAoE;AAEvD,QAAA,mBAAmB,GAAG;IACjC,IAAI,mBAAgB,CAAC,cAAc,EAAE;IACrC,IAAI,mBAAgB,CAAC,gBAAgB,EAAE;IACvC,IAAI,uBAAQ,EAAE;IACd,IAAI,0BAAW,EAAE;IACjB,IAAI,6BAAc,EAAE;IACpB,IA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,IAAI,EAAE,CAAC,CAAC;IAC3C,GAAG,CAAC,cAAc,EAAE,CAAC;AACvB,CAAC;AAED;;GAEG;AACH,SAAS,oBAAoB;IAC3B,MAAM,MAAM,GAAG,uBAAe,EAAU,CAAC;IACzC,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;IAEjC,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE;QACnC,sBAAc,IAAI,cAAM,CAAC,IAAI,CAAC,oFAAoF,CAAC,CAAC;QACpH,OAAO;KACR;IAED,MAAM,GAAG,GAAG,oBAAa,EAAE,CAAC;IAE5B,iHAAiH;IACjH,gHAAgH;IAChH,gGAAgG;IAChG,iEAAiE;IACjE,iEAAiE;IACjE,8DAA8D;IAC9D,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE;QACvB,OAAO;KACR;IAED,wEAAwE;IACxE,wCAAwC;IACxC,sEAAsE;IACtE,0BAA0B;IAC1B,iBAAiB,CAAC,GAAG,CAAC,CAAC;IAEvB,2DAA2D;IAC3D,iCAAyB,CAAC,SAAS,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,EAAE;QACpD,6FAA6F;QAC7F,IAAI,CAAC,CAAC,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,EAAE,CAAC,EAAE;YACxC,iBAAiB,CAAC,oBAAa,EAAE,CAAC,CAAC;SACpC;IACH,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n getCurrentHub,\n getIntegrationsToSetup,\n getReportDialogEndpoint,\n Hub,\n initAndBind,\n Integrations as CoreIntegrations,\n} from '@sentry/core';\nimport {\n addInstrumentationHandler,\n getGlobalObject,\n logger,\n resolvedSyncPromise,\n stackParserFromStackParserOptions,\n supportsFetch,\n} from '@sentry/utils';\n\nimport { BrowserClient, BrowserClientOptions, BrowserOptions } from './client';\nimport { IS_DEBUG_BUILD } from './flags';\nimport { ReportDialogOptions, wrap as internalWrap } from './helpers';\nimport { Breadcrumbs, Dedupe, GlobalHandlers, LinkedErrors, TryCatch, UserAgent } from './integrations';\nimport { defaultStackParser } from './stack-parsers';\nimport { makeFetchTransport, makeXHRTransport } from './transports';\n\nexport const defaultIntegrations = [\n new CoreIntegrations.InboundFilters(),\n new CoreIntegrations.FunctionToString(),\n new TryCatch(),\n new Breadcrumbs(),\n new GlobalHandlers(),\n new LinkedErrors(),\n new Dedupe(),\n new UserAgent(),\n];\n\n/**\n * The Sentry Browser SDK Client.\n *\n * To use this SDK, call the {@link init} function as early as possible when\n * loading the web page. To set context information or send manual events, use\n * the provided methods.\n *\n * @example\n *\n * ```\n *\n * import { init } from '@sentry/browser';\n *\n * init({\n * dsn: '__DSN__',\n * // ...\n * });\n * ```\n *\n * @example\n * ```\n *\n * import { configureScope } from '@sentry/browser';\n * configureScope((scope: Scope) => {\n * scope.setExtra({ battery: 0.7 });\n * scope.setTag({ user_mode: 'admin' });\n * scope.setUser({ id: '4711' });\n * });\n * ```\n *\n * @example\n * ```\n *\n * import { addBreadcrumb } from '@sentry/browser';\n * addBreadcrumb({\n * message: 'My Breadcrumb',\n * // ...\n * });\n * ```\n *\n * @example\n *\n * ```\n *\n * import * as Sentry from '@sentry/browser';\n * Sentry.captureMessage('Hello, world!');\n * Sentry.captureException(new Error('Good bye'));\n * Sentry.captureEvent({\n * message: 'Manual',\n * stacktrace: [\n * // ...\n * ],\n * });\n * ```\n *\n * @see {@link BrowserOptions} for documentation on configuration options.\n */\nexport function init(options: BrowserOptions = {}): void {\n if (options.defaultIntegrations === undefined) {\n options.defaultIntegrations = defaultIntegrations;\n }\n if (options.release === undefined) {\n const window = getGlobalObject<Window>();\n // This supports the variable that sentry-webpack-plugin injects\n if (window.SENTRY_RELEASE && window.SENTRY_RELEASE.id) {\n options.release = window.SENTRY_RELEASE.id;\n }\n }\n if (options.autoSessionTracking === undefined) {\n options.autoSessionTracking = true;\n }\n if (options.sendClientReports === undefined) {\n options.sendClientReports = true;\n }\n\n const clientOptions: BrowserClientOptions = {\n ...options,\n stackParser: stackParserFromStackParserOptions(options.stackParser || defaultStackParser),\n integrations: getIntegrationsToSetup(options),\n transport: options.transport || (supportsFetch() ? makeFetchTransport : makeXHRTransport),\n };\n\n initAndBind(BrowserClient, clientOptions);\n\n if (options.autoSessionTracking) {\n startSessionTracking();\n }\n}\n\n/**\n * Present the user with a report dialog.\n *\n * @param options Everything is optional, we try to fetch all info need from the global scope.\n */\nexport function showReportDialog(options: ReportDialogOptions = {}, hub: Hub = getCurrentHub()): void {\n // doesn't work without a document (React Native)\n const global = getGlobalObject<Window>();\n if (!global.document) {\n IS_DEBUG_BUILD && logger.error('Global document not defined in showReportDialog call');\n return;\n }\n\n const { client, scope } = hub.getStackTop();\n const dsn = options.dsn || (client && client.getDsn());\n if (!dsn) {\n IS_DEBUG_BUILD && logger.error('DSN not configured for showReportDialog call');\n return;\n }\n\n if (scope) {\n options.user = {\n ...scope.getUser(),\n ...options.user,\n };\n }\n\n if (!options.eventId) {\n options.eventId = hub.lastEventId();\n }\n\n const script = global.document.createElement('script');\n script.async = true;\n script.src = getReportDialogEndpoint(dsn, options);\n\n if (options.onLoad) {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n script.onload = options.onLoad;\n }\n\n const injectionPoint = global.document.head || global.document.body;\n if (injectionPoint) {\n injectionPoint.appendChild(script);\n } else {\n IS_DEBUG_BUILD && logger.error('Not injecting report dialog. No injection point found in HTML');\n }\n}\n\n/**\n * This is the getter for lastEventId.\n *\n * @returns The last event id of a captured event.\n */\nexport function lastEventId(): string | undefined {\n return getCurrentHub().lastEventId();\n}\n\n/**\n * This function is here to be API compatible with the loader.\n * @hidden\n */\nexport function forceLoad(): void {\n // Noop\n}\n\n/**\n * This function is here to be API compatible with the loader.\n * @hidden\n */\nexport function onLoad(callback: () => void): void {\n callback();\n}\n\n/**\n * Call `flush()` on the current client, if there is one. See {@link Client.flush}.\n *\n * @param timeout Maximum time in ms the client should wait to flush its event queue. Omitting this parameter will cause\n * the client to wait until all events are sent before resolving the promise.\n * @returns A promise which resolves to `true` if the queue successfully drains before the timeout, or `false` if it\n * doesn't (or if there's no client defined).\n */\nexport function flush(timeout?: number): PromiseLike<boolean> {\n const client = getCurrentHub().getClient<BrowserClient>();\n if (client) {\n return client.flush(timeout);\n }\n IS_DEBUG_BUILD && logger.warn('Cannot flush events. No client defined.');\n return resolvedSyncPromise(false);\n}\n\n/**\n * Call `close()` on the current client, if there is one. See {@link Client.close}.\n *\n * @param timeout Maximum time in ms the client should wait to flush its event queue before shutting down. Omitting this\n * parameter will cause the client to wait until all events are sent before disabling itself.\n * @returns A promise which resolves to `true` if the queue successfully drains before the timeout, or `false` if it\n * doesn't (or if there's no client defined).\n */\nexport function close(timeout?: number): PromiseLike<boolean> {\n const client = getCurrentHub().getClient<BrowserClient>();\n if (client) {\n return client.close(timeout);\n }\n IS_DEBUG_BUILD && logger.warn('Cannot flush events and disable SDK. No client defined.');\n return resolvedSyncPromise(false);\n}\n\n/**\n * Wrap code within a try/catch block so the SDK is able to capture errors.\n *\n * @param fn A function to wrap.\n *\n * @returns The result of wrapped function call.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function wrap(fn: (...args: any) => any): any {\n return internalWrap(fn)();\n}\n\nfunction startSessionOnHub(hub: Hub): void {\n hub.startSession({ ignoreDuration: true });\n hub.captureSession();\n}\n\n/**\n * Enable automatic Session Tracking for the initial page load.\n */\nfunction startSessionTracking(): void {\n const window = getGlobalObject<Window>();\n const document = window.document;\n\n if (typeof document === 'undefined') {\n IS_DEBUG_BUILD && logger.warn('Session tracking in non-browser environment with @sentry/browser is not supported.');\n return;\n }\n\n const hub = getCurrentHub();\n\n // The only way for this to be false is for there to be a version mismatch between @sentry/browser (>= 6.0.0) and\n // @sentry/hub (< 5.27.0). In the simple case, there won't ever be such a mismatch, because the two packages are\n // pinned at the same version in package.json, but there are edge cases where it's possible. See\n // https://github.com/getsentry/sentry-javascript/issues/3207 and\n // https://github.com/getsentry/sentry-javascript/issues/3234 and\n // https://github.com/getsentry/sentry-javascript/issues/3278.\n if (!hub.captureSession) {\n return;\n }\n\n // The session duration for browser sessions does not track a meaningful\n // concept that can be used as a metric.\n // Automatically captured sessions are akin to page views, and thus we\n // discard their duration.\n startSessionOnHub(hub);\n\n // We want to create a session for every navigation as well\n addInstrumentationHandler('history', ({ from, to }) => {\n // Don't create an additional session for the initial route or if the location did not change\n if (!(from === undefined || from === to)) {\n startSessionOnHub(getCurrentHub());\n }\n });\n}\n"]}
1
+ {"version":3,"file":"sdk.js","sources":["../../../src/sdk.ts"],"sourcesContent":["import {\n getCurrentHub,\n getIntegrationsToSetup,\n getReportDialogEndpoint,\n Hub,\n initAndBind,\n Integrations as CoreIntegrations,\n} from '@sentry/core';\nimport {\n addInstrumentationHandler,\n getGlobalObject,\n logger,\n resolvedSyncPromise,\n stackParserFromStackParserOptions,\n supportsFetch,\n} from '@sentry/utils';\n\nimport { BrowserClient, BrowserClientOptions, BrowserOptions } from './client';\nimport { IS_DEBUG_BUILD } from './flags';\nimport { ReportDialogOptions, wrap as internalWrap } from './helpers';\nimport { Breadcrumbs, Dedupe, GlobalHandlers, HttpContext, LinkedErrors, TryCatch } from './integrations';\nimport { defaultStackParser } from './stack-parsers';\nimport { makeFetchTransport, makeXHRTransport } from './transports';\n\nexport const defaultIntegrations = [\n new CoreIntegrations.InboundFilters(),\n new CoreIntegrations.FunctionToString(),\n new TryCatch(),\n new Breadcrumbs(),\n new GlobalHandlers(),\n new LinkedErrors(),\n new Dedupe(),\n new HttpContext(),\n];\n\n/**\n * The Sentry Browser SDK Client.\n *\n * To use this SDK, call the {@link init} function as early as possible when\n * loading the web page. To set context information or send manual events, use\n * the provided methods.\n *\n * @example\n *\n * ```\n *\n * import { init } from '@sentry/browser';\n *\n * init({\n * dsn: '__DSN__',\n * // ...\n * });\n * ```\n *\n * @example\n * ```\n *\n * import { configureScope } from '@sentry/browser';\n * configureScope((scope: Scope) => {\n * scope.setExtra({ battery: 0.7 });\n * scope.setTag({ user_mode: 'admin' });\n * scope.setUser({ id: '4711' });\n * });\n * ```\n *\n * @example\n * ```\n *\n * import { addBreadcrumb } from '@sentry/browser';\n * addBreadcrumb({\n * message: 'My Breadcrumb',\n * // ...\n * });\n * ```\n *\n * @example\n *\n * ```\n *\n * import * as Sentry from '@sentry/browser';\n * Sentry.captureMessage('Hello, world!');\n * Sentry.captureException(new Error('Good bye'));\n * Sentry.captureEvent({\n * message: 'Manual',\n * stacktrace: [\n * // ...\n * ],\n * });\n * ```\n *\n * @see {@link BrowserOptions} for documentation on configuration options.\n */\nexport function init(options: BrowserOptions = {}): void {\n if (options.defaultIntegrations === undefined) {\n options.defaultIntegrations = defaultIntegrations;\n }\n if (options.release === undefined) {\n const window = getGlobalObject<Window>();\n // This supports the variable that sentry-webpack-plugin injects\n if (window.SENTRY_RELEASE && window.SENTRY_RELEASE.id) {\n options.release = window.SENTRY_RELEASE.id;\n }\n }\n if (options.autoSessionTracking === undefined) {\n options.autoSessionTracking = true;\n }\n if (options.sendClientReports === undefined) {\n options.sendClientReports = true;\n }\n\n const clientOptions: BrowserClientOptions = {\n ...options,\n stackParser: stackParserFromStackParserOptions(options.stackParser || defaultStackParser),\n integrations: getIntegrationsToSetup(options),\n transport: options.transport || (supportsFetch() ? makeFetchTransport : makeXHRTransport),\n };\n\n initAndBind(BrowserClient, clientOptions);\n\n if (options.autoSessionTracking) {\n startSessionTracking();\n }\n}\n\n/**\n * Present the user with a report dialog.\n *\n * @param options Everything is optional, we try to fetch all info need from the global scope.\n */\nexport function showReportDialog(options: ReportDialogOptions = {}, hub: Hub = getCurrentHub()): void {\n // doesn't work without a document (React Native)\n const global = getGlobalObject<Window>();\n if (!global.document) {\n IS_DEBUG_BUILD && logger.error('Global document not defined in showReportDialog call');\n return;\n }\n\n const { client, scope } = hub.getStackTop();\n const dsn = options.dsn || (client && client.getDsn());\n if (!dsn) {\n IS_DEBUG_BUILD && logger.error('DSN not configured for showReportDialog call');\n return;\n }\n\n if (scope) {\n options.user = {\n ...scope.getUser(),\n ...options.user,\n };\n }\n\n if (!options.eventId) {\n options.eventId = hub.lastEventId();\n }\n\n const script = global.document.createElement('script');\n script.async = true;\n script.src = getReportDialogEndpoint(dsn, options);\n\n if (options.onLoad) {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n script.onload = options.onLoad;\n }\n\n const injectionPoint = global.document.head || global.document.body;\n if (injectionPoint) {\n injectionPoint.appendChild(script);\n } else {\n IS_DEBUG_BUILD && logger.error('Not injecting report dialog. No injection point found in HTML');\n }\n}\n\n/**\n * This is the getter for lastEventId.\n *\n * @returns The last event id of a captured event.\n */\nexport function lastEventId(): string | undefined {\n return getCurrentHub().lastEventId();\n}\n\n/**\n * This function is here to be API compatible with the loader.\n * @hidden\n */\nexport function forceLoad(): void {\n // Noop\n}\n\n/**\n * This function is here to be API compatible with the loader.\n * @hidden\n */\nexport function onLoad(callback: () => void): void {\n callback();\n}\n\n/**\n * Call `flush()` on the current client, if there is one. See {@link Client.flush}.\n *\n * @param timeout Maximum time in ms the client should wait to flush its event queue. Omitting this parameter will cause\n * the client to wait until all events are sent before resolving the promise.\n * @returns A promise which resolves to `true` if the queue successfully drains before the timeout, or `false` if it\n * doesn't (or if there's no client defined).\n */\nexport function flush(timeout?: number): PromiseLike<boolean> {\n const client = getCurrentHub().getClient<BrowserClient>();\n if (client) {\n return client.flush(timeout);\n }\n IS_DEBUG_BUILD && logger.warn('Cannot flush events. No client defined.');\n return resolvedSyncPromise(false);\n}\n\n/**\n * Call `close()` on the current client, if there is one. See {@link Client.close}.\n *\n * @param timeout Maximum time in ms the client should wait to flush its event queue before shutting down. Omitting this\n * parameter will cause the client to wait until all events are sent before disabling itself.\n * @returns A promise which resolves to `true` if the queue successfully drains before the timeout, or `false` if it\n * doesn't (or if there's no client defined).\n */\nexport function close(timeout?: number): PromiseLike<boolean> {\n const client = getCurrentHub().getClient<BrowserClient>();\n if (client) {\n return client.close(timeout);\n }\n IS_DEBUG_BUILD && logger.warn('Cannot flush events and disable SDK. No client defined.');\n return resolvedSyncPromise(false);\n}\n\n/**\n * Wrap code within a try/catch block so the SDK is able to capture errors.\n *\n * @param fn A function to wrap.\n *\n * @returns The result of wrapped function call.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function wrap(fn: (...args: any) => any): any {\n return internalWrap(fn)();\n}\n\nfunction startSessionOnHub(hub: Hub): void {\n hub.startSession({ ignoreDuration: true });\n hub.captureSession();\n}\n\n/**\n * Enable automatic Session Tracking for the initial page load.\n */\nfunction startSessionTracking(): void {\n const window = getGlobalObject<Window>();\n const document = window.document;\n\n if (typeof document === 'undefined') {\n IS_DEBUG_BUILD && logger.warn('Session tracking in non-browser environment with @sentry/browser is not supported.');\n return;\n }\n\n const hub = getCurrentHub();\n\n // The only way for this to be false is for there to be a version mismatch between @sentry/browser (>= 6.0.0) and\n // @sentry/hub (< 5.27.0). In the simple case, there won't ever be such a mismatch, because the two packages are\n // pinned at the same version in package.json, but there are edge cases where it's possible. See\n // https://github.com/getsentry/sentry-javascript/issues/3207 and\n // https://github.com/getsentry/sentry-javascript/issues/3234 and\n // https://github.com/getsentry/sentry-javascript/issues/3278.\n if (!hub.captureSession) {\n return;\n }\n\n // The session duration for browser sessions does not track a meaningful\n // concept that can be used as a metric.\n // Automatically captured sessions are akin to page views, and thus we\n // discard their duration.\n startSessionOnHub(hub);\n\n // We want to create a session for every navigation as well\n addInstrumentationHandler('history', ({ from, to }) => {\n // Don't create an additional session for the initial route or if the location did not change\n if (!(from === undefined || from === to)) {\n startSessionOnHub(getCurrentHub());\n }\n });\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAyBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;"}