@sentry/replay 0.6.14-6 → 7.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (340) hide show
  1. package/README.md +114 -30
  2. package/cjs/constants.js +39 -0
  3. package/cjs/constants.js.map +1 -0
  4. package/cjs/coreHandlers/breadcrumbHandler.js +15 -0
  5. package/cjs/coreHandlers/breadcrumbHandler.js.map +1 -0
  6. package/cjs/coreHandlers/handleDom.js +49 -0
  7. package/cjs/coreHandlers/handleDom.js.map +1 -0
  8. package/cjs/coreHandlers/handleFetch.js +30 -0
  9. package/cjs/coreHandlers/handleFetch.js.map +1 -0
  10. package/cjs/coreHandlers/handleHistory.js +20 -0
  11. package/cjs/coreHandlers/handleHistory.js.map +1 -0
  12. package/cjs/coreHandlers/handleScope.js +38 -0
  13. package/cjs/coreHandlers/handleScope.js.map +1 -0
  14. package/cjs/coreHandlers/handleXhr.js +49 -0
  15. package/cjs/coreHandlers/handleXhr.js.map +1 -0
  16. package/cjs/coreHandlers/spanHandler.js +20 -0
  17. package/cjs/coreHandlers/spanHandler.js.map +1 -0
  18. package/cjs/createPerformanceEntry.js +147 -0
  19. package/cjs/createPerformanceEntry.js.map +1 -0
  20. package/cjs/eventBuffer.js +189 -0
  21. package/cjs/eventBuffer.js.map +1 -0
  22. package/cjs/index.js +191 -0
  23. package/cjs/index.js.map +1 -0
  24. package/cjs/node_modules/rrweb/es/rrweb/ext/@xstate/fsm/es/index.js +22 -0
  25. package/cjs/node_modules/rrweb/es/rrweb/ext/@xstate/fsm/es/index.js.map +1 -0
  26. package/cjs/node_modules/rrweb/es/rrweb/ext/base64-arraybuffer/dist/base64-arraybuffer.es5.js +53 -0
  27. package/cjs/node_modules/rrweb/es/rrweb/ext/base64-arraybuffer/dist/base64-arraybuffer.es5.js.map +1 -0
  28. package/cjs/node_modules/rrweb/es/rrweb/ext/fflate/esm/browser.js +783 -0
  29. package/cjs/node_modules/rrweb/es/rrweb/ext/fflate/esm/browser.js.map +1 -0
  30. package/cjs/node_modules/rrweb/es/rrweb/ext/mitt/dist/mitt.es.js +59 -0
  31. package/cjs/node_modules/rrweb/es/rrweb/ext/mitt/dist/mitt.es.js.map +1 -0
  32. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/ext/tslib/tslib.es6.js +84 -0
  33. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/ext/tslib/tslib.es6.js.map +1 -0
  34. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/entries/all.js +45 -0
  35. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/entries/all.js.map +1 -0
  36. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/index.js +36 -0
  37. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/index.js.map +1 -0
  38. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/packer/base.js +6 -0
  39. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/packer/base.js.map +1 -0
  40. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/packer/pack.js +13 -0
  41. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/packer/pack.js.map +1 -0
  42. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/packer/unpack.js +32 -0
  43. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/packer/unpack.js.map +1 -0
  44. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/plugins/console/record/error-stack-parser.js +183 -0
  45. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/plugins/console/record/error-stack-parser.js.map +1 -0
  46. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/plugins/console/record/index.js +138 -0
  47. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/plugins/console/record/index.js.map +1 -0
  48. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/plugins/console/record/stringify.js +144 -0
  49. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/plugins/console/record/stringify.js.map +1 -0
  50. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/plugins/console/replay/index.js +114 -0
  51. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/plugins/console/replay/index.js.map +1 -0
  52. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/iframe-manager.js +35 -0
  53. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/iframe-manager.js.map +1 -0
  54. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/index.js +385 -0
  55. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/index.js.map +1 -0
  56. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/mutation.js +519 -0
  57. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/mutation.js.map +1 -0
  58. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/observer.js +671 -0
  59. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/observer.js.map +1 -0
  60. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/observers/canvas/2d.js +81 -0
  61. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/observers/canvas/2d.js.map +1 -0
  62. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/observers/canvas/canvas-manager.js +96 -0
  63. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/observers/canvas/canvas-manager.js.map +1 -0
  64. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/observers/canvas/canvas.js +33 -0
  65. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/observers/canvas/canvas.js.map +1 -0
  66. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/observers/canvas/serialize-args.js +123 -0
  67. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/observers/canvas/serialize-args.js.map +1 -0
  68. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/observers/canvas/webgl.js +81 -0
  69. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/observers/canvas/webgl.js.map +1 -0
  70. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/shadow-dom-manager.js +48 -0
  71. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/shadow-dom-manager.js.map +1 -0
  72. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/replay/canvas/2d.js +28 -0
  73. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/replay/canvas/2d.js.map +1 -0
  74. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/replay/canvas/index.js +38 -0
  75. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/replay/canvas/index.js.map +1 -0
  76. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/replay/canvas/webgl.js +128 -0
  77. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/replay/canvas/webgl.js.map +1 -0
  78. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/replay/index.js +1716 -0
  79. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/replay/index.js.map +1 -0
  80. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/replay/machine.js +279 -0
  81. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/replay/machine.js.map +1 -0
  82. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/replay/smoothscroll.js +224 -0
  83. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/replay/smoothscroll.js.map +1 -0
  84. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/replay/styles/inject-style.js +9 -0
  85. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/replay/styles/inject-style.js.map +1 -0
  86. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/replay/timer.js +94 -0
  87. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/replay/timer.js.map +1 -0
  88. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/replay/virtual-styles.js +127 -0
  89. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/replay/virtual-styles.js.map +1 -0
  90. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/types.js +76 -0
  91. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/types.js.map +1 -0
  92. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/utils.js +518 -0
  93. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb/src/utils.js.map +1 -0
  94. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb-snapshot/es/rrweb-snapshot.js +1648 -0
  95. package/cjs/node_modules/rrweb/es/rrweb/packages/rrweb-snapshot/es/rrweb-snapshot.js.map +1 -0
  96. package/cjs/replay.js +1269 -0
  97. package/cjs/replay.js.map +1 -0
  98. package/cjs/session/Session.js +36 -0
  99. package/cjs/session/Session.js.map +1 -0
  100. package/cjs/session/createSession.js +28 -0
  101. package/cjs/session/createSession.js.map +1 -0
  102. package/cjs/session/deleteSession.js +23 -0
  103. package/cjs/session/deleteSession.js.map +1 -0
  104. package/cjs/session/fetchSession.js +33 -0
  105. package/cjs/session/fetchSession.js.map +1 -0
  106. package/cjs/session/getSession.js +45 -0
  107. package/cjs/session/getSession.js.map +1 -0
  108. package/cjs/session/saveSession.js +19 -0
  109. package/cjs/session/saveSession.js.map +1 -0
  110. package/cjs/util/addInternalBreadcrumb.js +25 -0
  111. package/cjs/util/addInternalBreadcrumb.js.map +1 -0
  112. package/cjs/util/captureInternalException.js +18 -0
  113. package/cjs/util/captureInternalException.js.map +1 -0
  114. package/cjs/util/createBreadcrumb.js +14 -0
  115. package/cjs/util/createBreadcrumb.js.map +1 -0
  116. package/cjs/util/createPayload.js +31 -0
  117. package/cjs/util/createPayload.js.map +1 -0
  118. package/cjs/util/dedupePerformanceEntries.js +95 -0
  119. package/cjs/util/dedupePerformanceEntries.js.map +1 -0
  120. package/cjs/util/isBrowser.js +11 -0
  121. package/cjs/util/isBrowser.js.map +1 -0
  122. package/cjs/util/isExpired.js +26 -0
  123. package/cjs/util/isExpired.js.map +1 -0
  124. package/cjs/util/isIngestHost.js +26 -0
  125. package/cjs/util/isIngestHost.js.map +1 -0
  126. package/cjs/util/isInternal.js +15 -0
  127. package/cjs/util/isInternal.js.map +1 -0
  128. package/cjs/util/isSampled.js +19 -0
  129. package/cjs/util/isSampled.js.map +1 -0
  130. package/cjs/util/isSessionExpired.js +24 -0
  131. package/cjs/util/isSessionExpired.js.map +1 -0
  132. package/cjs/worker/worker.js +7 -0
  133. package/cjs/worker/worker.js.map +1 -0
  134. package/esm/constants.js +29 -0
  135. package/esm/constants.js.map +1 -0
  136. package/esm/coreHandlers/breadcrumbHandler.js +13 -0
  137. package/esm/coreHandlers/breadcrumbHandler.js.map +1 -0
  138. package/esm/coreHandlers/handleDom.js +47 -0
  139. package/esm/coreHandlers/handleDom.js.map +1 -0
  140. package/esm/coreHandlers/handleFetch.js +28 -0
  141. package/esm/coreHandlers/handleFetch.js.map +1 -0
  142. package/esm/coreHandlers/handleHistory.js +18 -0
  143. package/esm/coreHandlers/handleHistory.js.map +1 -0
  144. package/esm/coreHandlers/handleScope.js +33 -0
  145. package/esm/coreHandlers/handleScope.js.map +1 -0
  146. package/esm/coreHandlers/handleXhr.js +44 -0
  147. package/esm/coreHandlers/handleXhr.js.map +1 -0
  148. package/esm/coreHandlers/spanHandler.js +18 -0
  149. package/esm/coreHandlers/spanHandler.js.map +1 -0
  150. package/esm/createPerformanceEntry.js +144 -0
  151. package/esm/createPerformanceEntry.js.map +1 -0
  152. package/esm/eventBuffer.js +183 -0
  153. package/esm/eventBuffer.js.map +1 -0
  154. package/esm/index.js +189 -0
  155. package/esm/index.js.map +1 -0
  156. package/esm/node_modules/rrweb/es/rrweb/ext/@xstate/fsm/es/index.js +18 -0
  157. package/esm/node_modules/rrweb/es/rrweb/ext/@xstate/fsm/es/index.js.map +1 -0
  158. package/esm/node_modules/rrweb/es/rrweb/ext/base64-arraybuffer/dist/base64-arraybuffer.es5.js +50 -0
  159. package/esm/node_modules/rrweb/es/rrweb/ext/base64-arraybuffer/dist/base64-arraybuffer.es5.js.map +1 -0
  160. package/esm/node_modules/rrweb/es/rrweb/ext/fflate/esm/browser.js +778 -0
  161. package/esm/node_modules/rrweb/es/rrweb/ext/fflate/esm/browser.js.map +1 -0
  162. package/esm/node_modules/rrweb/es/rrweb/ext/mitt/dist/mitt.es.js +57 -0
  163. package/esm/node_modules/rrweb/es/rrweb/ext/mitt/dist/mitt.es.js.map +1 -0
  164. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/ext/tslib/tslib.es6.js +79 -0
  165. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/ext/tslib/tslib.es6.js.map +1 -0
  166. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/entries/all.js +12 -0
  167. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/entries/all.js.map +1 -0
  168. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/index.js +13 -0
  169. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/index.js.map +1 -0
  170. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/packer/base.js +4 -0
  171. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/packer/base.js.map +1 -0
  172. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/packer/pack.js +11 -0
  173. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/packer/pack.js.map +1 -0
  174. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/packer/unpack.js +30 -0
  175. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/packer/unpack.js.map +1 -0
  176. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/plugins/console/record/error-stack-parser.js +180 -0
  177. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/plugins/console/record/error-stack-parser.js.map +1 -0
  178. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/plugins/console/record/index.js +135 -0
  179. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/plugins/console/record/index.js.map +1 -0
  180. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/plugins/console/record/stringify.js +142 -0
  181. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/plugins/console/record/stringify.js.map +1 -0
  182. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/plugins/console/replay/index.js +112 -0
  183. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/plugins/console/replay/index.js.map +1 -0
  184. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/iframe-manager.js +33 -0
  185. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/iframe-manager.js.map +1 -0
  186. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/index.js +383 -0
  187. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/index.js.map +1 -0
  188. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/mutation.js +517 -0
  189. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/mutation.js.map +1 -0
  190. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/observer.js +665 -0
  191. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/observer.js.map +1 -0
  192. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/observers/canvas/2d.js +79 -0
  193. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/observers/canvas/2d.js.map +1 -0
  194. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/observers/canvas/canvas-manager.js +94 -0
  195. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/observers/canvas/canvas-manager.js.map +1 -0
  196. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/observers/canvas/canvas.js +31 -0
  197. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/observers/canvas/canvas.js.map +1 -0
  198. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/observers/canvas/serialize-args.js +117 -0
  199. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/observers/canvas/serialize-args.js.map +1 -0
  200. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/observers/canvas/webgl.js +79 -0
  201. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/observers/canvas/webgl.js.map +1 -0
  202. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/shadow-dom-manager.js +46 -0
  203. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/record/shadow-dom-manager.js.map +1 -0
  204. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/replay/canvas/2d.js +26 -0
  205. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/replay/canvas/2d.js.map +1 -0
  206. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/replay/canvas/index.js +36 -0
  207. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/replay/canvas/index.js.map +1 -0
  208. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/replay/canvas/webgl.js +124 -0
  209. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/replay/canvas/webgl.js.map +1 -0
  210. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/replay/index.js +1715 -0
  211. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/replay/index.js.map +1 -0
  212. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/replay/machine.js +275 -0
  213. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/replay/machine.js.map +1 -0
  214. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/replay/smoothscroll.js +222 -0
  215. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/replay/smoothscroll.js.map +1 -0
  216. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/replay/styles/inject-style.js +7 -0
  217. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/replay/styles/inject-style.js.map +1 -0
  218. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/replay/timer.js +91 -0
  219. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/replay/timer.js.map +1 -0
  220. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/replay/virtual-styles.js +122 -0
  221. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/replay/virtual-styles.js.map +1 -0
  222. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/types.js +76 -0
  223. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/types.js.map +1 -0
  224. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/utils.js +499 -0
  225. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb/src/utils.js.map +1 -0
  226. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb-snapshot/es/rrweb-snapshot.js +1634 -0
  227. package/esm/node_modules/rrweb/es/rrweb/packages/rrweb-snapshot/es/rrweb-snapshot.js.map +1 -0
  228. package/esm/replay.js +1264 -0
  229. package/esm/replay.js.map +1 -0
  230. package/esm/session/Session.js +33 -0
  231. package/esm/session/Session.js.map +1 -0
  232. package/esm/session/createSession.js +26 -0
  233. package/esm/session/createSession.js.map +1 -0
  234. package/esm/session/deleteSession.js +21 -0
  235. package/esm/session/deleteSession.js.map +1 -0
  236. package/esm/session/fetchSession.js +31 -0
  237. package/esm/session/fetchSession.js.map +1 -0
  238. package/esm/session/getSession.js +43 -0
  239. package/esm/session/getSession.js.map +1 -0
  240. package/esm/session/saveSession.js +17 -0
  241. package/esm/session/saveSession.js.map +1 -0
  242. package/esm/util/addInternalBreadcrumb.js +23 -0
  243. package/esm/util/addInternalBreadcrumb.js.map +1 -0
  244. package/esm/util/captureInternalException.js +16 -0
  245. package/esm/util/captureInternalException.js.map +1 -0
  246. package/esm/util/createBreadcrumb.js +12 -0
  247. package/esm/util/createBreadcrumb.js.map +1 -0
  248. package/esm/util/createPayload.js +29 -0
  249. package/esm/util/createPayload.js.map +1 -0
  250. package/esm/util/dedupePerformanceEntries.js +93 -0
  251. package/esm/util/dedupePerformanceEntries.js.map +1 -0
  252. package/esm/util/isBrowser.js +9 -0
  253. package/esm/util/isBrowser.js.map +1 -0
  254. package/esm/util/isExpired.js +24 -0
  255. package/esm/util/isExpired.js.map +1 -0
  256. package/esm/util/isIngestHost.js +21 -0
  257. package/esm/util/isIngestHost.js.map +1 -0
  258. package/esm/util/isInternal.js +13 -0
  259. package/esm/util/isInternal.js.map +1 -0
  260. package/esm/util/isSampled.js +17 -0
  261. package/esm/util/isSampled.js.map +1 -0
  262. package/esm/util/isSessionExpired.js +19 -0
  263. package/esm/util/isSessionExpired.js.map +1 -0
  264. package/esm/worker/worker.js +5 -0
  265. package/esm/worker/worker.js.map +1 -0
  266. package/package.json +16 -64
  267. package/{dist/types/src/session → types}/constants.d.ts +2 -0
  268. package/types/constants.d.ts.map +1 -0
  269. package/types/coreHandlers/breadcrumbHandler.d.ts +4 -0
  270. package/types/coreHandlers/breadcrumbHandler.d.ts.map +1 -0
  271. package/types/coreHandlers/handleDom.d.ts +9 -0
  272. package/types/coreHandlers/handleDom.d.ts.map +1 -0
  273. package/{dist/types/src → types}/coreHandlers/handleFetch.d.ts +2 -2
  274. package/types/coreHandlers/handleFetch.d.ts.map +1 -0
  275. package/{dist/types/src → types}/coreHandlers/handleHistory.d.ts +2 -2
  276. package/types/coreHandlers/handleHistory.d.ts.map +1 -0
  277. package/{dist/types/src → types}/coreHandlers/handleScope.d.ts +1 -0
  278. package/types/coreHandlers/handleScope.d.ts.map +1 -0
  279. package/{dist/types/src → types}/coreHandlers/handleXhr.d.ts +3 -2
  280. package/types/coreHandlers/handleXhr.d.ts.map +1 -0
  281. package/types/coreHandlers/spanHandler.d.ts +4 -0
  282. package/types/coreHandlers/spanHandler.d.ts.map +1 -0
  283. package/{dist/types/src → types}/createPerformanceEntry.d.ts +4 -10
  284. package/types/createPerformanceEntry.d.ts.map +1 -0
  285. package/types/eventBuffer.d.ts +34 -0
  286. package/types/eventBuffer.d.ts.map +1 -0
  287. package/types/index.d.ts +48 -0
  288. package/types/index.d.ts.map +1 -0
  289. package/{dist/types/src/index.d.ts → types/replay.d.ts} +49 -53
  290. package/types/replay.d.ts.map +1 -0
  291. package/types/session/Session.d.ts +37 -0
  292. package/types/session/Session.d.ts.map +1 -0
  293. package/{dist/types/src → types}/session/createSession.d.ts +2 -1
  294. package/types/session/createSession.d.ts.map +1 -0
  295. package/{dist/types/src → types}/session/deleteSession.d.ts +1 -0
  296. package/types/session/deleteSession.d.ts.map +1 -0
  297. package/types/session/fetchSession.d.ts +6 -0
  298. package/types/session/fetchSession.d.ts.map +1 -0
  299. package/{dist/types/src → types}/session/getSession.d.ts +2 -1
  300. package/types/session/getSession.d.ts.map +1 -0
  301. package/types/session/index.d.ts +2 -0
  302. package/types/session/index.d.ts.map +1 -0
  303. package/{dist/types/src → types}/session/saveSession.d.ts +1 -0
  304. package/types/session/saveSession.d.ts.map +1 -0
  305. package/{dist/types/src → types}/types.d.ts +8 -15
  306. package/types/types.d.ts.map +1 -0
  307. package/{dist/types/src → types}/util/addInternalBreadcrumb.d.ts +1 -0
  308. package/types/util/addInternalBreadcrumb.d.ts.map +1 -0
  309. package/{dist/types/src → types}/util/captureInternalException.d.ts +1 -0
  310. package/types/util/captureInternalException.d.ts.map +1 -0
  311. package/{dist/types/src → types}/util/createBreadcrumb.d.ts +1 -0
  312. package/types/util/createBreadcrumb.d.ts.map +1 -0
  313. package/{dist/types/src → types}/util/createPayload.d.ts +2 -1
  314. package/types/util/createPayload.d.ts.map +1 -0
  315. package/{dist/types/src → types}/util/dedupePerformanceEntries.d.ts +2 -1
  316. package/types/util/dedupePerformanceEntries.d.ts.map +1 -0
  317. package/types/util/isBrowser.d.ts +2 -0
  318. package/types/util/isBrowser.d.ts.map +1 -0
  319. package/{dist/types/src → types}/util/isExpired.d.ts +1 -0
  320. package/types/util/isExpired.d.ts.map +1 -0
  321. package/{dist/types/src → types}/util/isIngestHost.d.ts +1 -0
  322. package/types/util/isIngestHost.d.ts.map +1 -0
  323. package/{dist/types/src → types}/util/isInternal.d.ts +1 -0
  324. package/types/util/isInternal.d.ts.map +1 -0
  325. package/{dist/types/src → types}/util/isSampled.d.ts +1 -0
  326. package/types/util/isSampled.d.ts.map +1 -0
  327. package/{dist/types/src → types}/util/isSessionExpired.d.ts +1 -0
  328. package/types/util/isSessionExpired.d.ts.map +1 -0
  329. package/dist/index.es.js +0 -2085
  330. package/dist/index.js +0 -2094
  331. package/dist/index.js.map +0 -1
  332. package/dist/types/src/coreHandlers/getBreadcrumbHandler.d.ts +0 -3
  333. package/dist/types/src/coreHandlers/getSpanHandler.d.ts +0 -5
  334. package/dist/types/src/coreHandlers/handleDom.d.ts +0 -1
  335. package/dist/types/src/eventBuffer.d.ts +0 -45
  336. package/dist/types/src/flags.d.ts +0 -2
  337. package/dist/types/src/session/Session.d.ts +0 -63
  338. package/dist/types/src/session/fetchSession.d.ts +0 -6
  339. package/dist/types/src/session/index.d.ts +0 -1
  340. package/dist/types/src/util/logger.d.ts +0 -12
package/esm/replay.js ADDED
@@ -0,0 +1,1264 @@
1
+ import { _optionalChain } from '@sentry/utils/esm/buildPolyfills';
2
+ import { getCurrentHub, addGlobalEventProcessor, setContext } from '@sentry/core';
3
+ import { logger, addInstrumentationHandler, createEnvelope } from '@sentry/utils';
4
+ import debounce from 'lodash.debounce';
5
+ import './node_modules/rrweb/es/rrweb/packages/rrweb/src/entries/all.js';
6
+ import { SESSION_IDLE_DURATION, WINDOW, REPLAY_EVENT_NAME, VISIBILITY_CHANGE_TIMEOUT, MAX_SESSION_LIFE } from './constants.js';
7
+ import { breadcrumbHandler } from './coreHandlers/breadcrumbHandler.js';
8
+ import { spanHandler } from './coreHandlers/spanHandler.js';
9
+ import { createPerformanceEntries, createMemoryEntry } from './createPerformanceEntry.js';
10
+ import { createEventBuffer } from './eventBuffer.js';
11
+ import { deleteSession } from './session/deleteSession.js';
12
+ import { getSession } from './session/getSession.js';
13
+ import { saveSession } from './session/saveSession.js';
14
+ import { addInternalBreadcrumb } from './util/addInternalBreadcrumb.js';
15
+ import { captureInternalException } from './util/captureInternalException.js';
16
+ import { createBreadcrumb } from './util/createBreadcrumb.js';
17
+ import { createPayload } from './util/createPayload.js';
18
+ import { dedupePerformanceEntries } from './util/dedupePerformanceEntries.js';
19
+ import { isExpired } from './util/isExpired.js';
20
+ import { isSessionExpired } from './util/isSessionExpired.js';
21
+ import record from './node_modules/rrweb/es/rrweb/packages/rrweb/src/record/index.js';
22
+ import { EventType } from './node_modules/rrweb/es/rrweb/packages/rrweb/src/types.js';
23
+
24
+ /* eslint-disable max-lines */ // TODO: We might want to split this file up
25
+
26
+ /**
27
+ * Returns true to return control to calling function, otherwise continue with normal batching
28
+ */
29
+
30
+ const BASE_RETRY_INTERVAL = 5000;
31
+ const MAX_RETRY_COUNT = 3;
32
+ const UNABLE_TO_SEND_REPLAY = 'Unable to send Replay';
33
+
34
+ class ReplayContainer {
35
+ __init() {this.eventBuffer = null;}
36
+
37
+ /**
38
+ * List of PerformanceEntry from PerformanceObserver
39
+ */
40
+ __init2() {this.performanceEvents = [];}
41
+
42
+ /**
43
+ * Options to pass to `rrweb.record()`
44
+ */
45
+
46
+ __init3() {this._performanceObserver = null;}
47
+
48
+ __init4() {this._retryCount = 0;}
49
+ __init5() {this._retryInterval = BASE_RETRY_INTERVAL;}
50
+
51
+ __init6() {this._flushLock = null;}
52
+
53
+ /**
54
+ * Timestamp of the last user activity. This lives across sessions.
55
+ */
56
+ __init7() {this._lastActivity = new Date().getTime();}
57
+
58
+ /**
59
+ * Is the integration currently active?
60
+ */
61
+ __init8() {this._isEnabled = false;}
62
+
63
+ /**
64
+ * Paused is a state where:
65
+ * - DOM Recording is not listening at all
66
+ * - Nothing will be added to event buffer (e.g. core SDK events)
67
+ */
68
+ __init9() {this._isPaused = false;}
69
+
70
+ /**
71
+ * Integration will wait until an error occurs before creating and sending a
72
+ * replay.
73
+ */
74
+ __init10() {this._waitForError = false;}
75
+
76
+ /**
77
+ * Have we attached listeners to the core SDK?
78
+ * Note we have to track this as there is no way to remove instrumentation handlers.
79
+ */
80
+ __init11() {this._hasInitializedCoreListeners = false;}
81
+
82
+ /**
83
+ * Function to stop recording
84
+ */
85
+ __init12() {this._stopRecording = null;}
86
+
87
+ /**
88
+ * We overwrite `client.recordDroppedEvent`, but store the original method here so we can restore it.
89
+ */
90
+
91
+ __init13() {this._context = {
92
+ errorIds: new Set(),
93
+ traceIds: new Set(),
94
+ urls: [],
95
+ earliestEvent: null,
96
+ initialTimestamp: new Date().getTime(),
97
+ initialUrl: '',
98
+ };}
99
+
100
+ constructor({ options, recordingOptions }) {;ReplayContainer.prototype.__init.call(this);ReplayContainer.prototype.__init2.call(this);ReplayContainer.prototype.__init3.call(this);ReplayContainer.prototype.__init4.call(this);ReplayContainer.prototype.__init5.call(this);ReplayContainer.prototype.__init6.call(this);ReplayContainer.prototype.__init7.call(this);ReplayContainer.prototype.__init8.call(this);ReplayContainer.prototype.__init9.call(this);ReplayContainer.prototype.__init10.call(this);ReplayContainer.prototype.__init11.call(this);ReplayContainer.prototype.__init12.call(this);ReplayContainer.prototype.__init13.call(this);ReplayContainer.prototype.__init14.call(this);ReplayContainer.prototype.__init15.call(this);ReplayContainer.prototype.__init16.call(this);ReplayContainer.prototype.__init17.call(this);ReplayContainer.prototype.__init18.call(this);ReplayContainer.prototype.__init19.call(this);ReplayContainer.prototype.__init20.call(this);ReplayContainer.prototype.__init21.call(this);ReplayContainer.prototype.__init22.call(this);
101
+ this.recordingOptions = recordingOptions;
102
+ this.options = options;
103
+
104
+ this._debouncedFlush = debounce(() => this.flush(), this.options.flushMinDelay, {
105
+ maxWait: this.options.flushMaxDelay,
106
+ });
107
+ }
108
+
109
+ /**
110
+ * Initializes the plugin.
111
+ *
112
+ * Creates or loads a session, attaches listeners to varying events (DOM,
113
+ * _performanceObserver, Recording, Sentry SDK, etc)
114
+ */
115
+ start() {
116
+ this.setInitialState();
117
+
118
+ this.loadSession({ expiry: SESSION_IDLE_DURATION });
119
+
120
+ // If there is no session, then something bad has happened - can't continue
121
+ if (!this.session) {
122
+ captureInternalException(new Error('Invalid session'));
123
+ return;
124
+ }
125
+
126
+ if (!this.session.sampled) {
127
+ // If session was not sampled, then we do not initialize the integration at all.
128
+ return;
129
+ }
130
+
131
+ // Modify recording options to checkoutEveryNthSecond if
132
+ // sampling for error replay. This is because we don't know
133
+ // when an error will occur, so we need to keep a buffer of
134
+ // replay events.
135
+ if (this.session.sampled === 'error') {
136
+ // Checkout every minute, meaning we only get up-to one minute of events before the error happens
137
+ this.recordingOptions.checkoutEveryNms = 60000;
138
+ this._waitForError = true;
139
+ }
140
+
141
+ // setup() is generally called on page load or manually - in both cases we
142
+ // should treat it as an activity
143
+ this.updateSessionActivity();
144
+
145
+ this.eventBuffer = createEventBuffer({
146
+ useCompression: Boolean(this.options.useCompression),
147
+ });
148
+
149
+ this.addListeners();
150
+
151
+ this.startRecording();
152
+
153
+ this._isEnabled = true;
154
+ }
155
+
156
+ /**
157
+ * Start recording.
158
+ *
159
+ * Note that this will cause a new DOM checkout
160
+ */
161
+ startRecording() {
162
+ try {
163
+ this._stopRecording = record({
164
+ ...this.recordingOptions,
165
+ emit: this.handleRecordingEmit,
166
+ });
167
+ } catch (err) {
168
+ (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.error('[Replay]', err);
169
+ captureInternalException(err);
170
+ }
171
+ }
172
+
173
+ /**
174
+ * Currently, this needs to be manually called (e.g. for tests). Sentry SDK
175
+ * does not support a teardown
176
+ */
177
+ stop() {
178
+ try {
179
+ (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.log('[Replay] Stopping Replays');
180
+ this._isEnabled = false;
181
+ this.removeListeners();
182
+ _optionalChain([this, 'access', _21 => _21._stopRecording, 'optionalCall', _22 => _22()]);
183
+ _optionalChain([this, 'access', _23 => _23.eventBuffer, 'optionalAccess', _24 => _24.destroy, 'call', _25 => _25()]);
184
+ this.eventBuffer = null;
185
+ } catch (err) {
186
+ (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.error('[Replay]', err);
187
+ captureInternalException(err);
188
+ }
189
+ }
190
+
191
+ /**
192
+ * Pause some replay functionality. See comments for `_isPaused`.
193
+ * This differs from stop as this only stops DOM recording, it is
194
+ * not as thorough of a shutdown as `stop()`.
195
+ */
196
+ pause() {
197
+ this._isPaused = true;
198
+ try {
199
+ if (this._stopRecording) {
200
+ this._stopRecording();
201
+ this._stopRecording = undefined;
202
+ }
203
+ } catch (err) {
204
+ (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.error('[Replay]', err);
205
+ captureInternalException(err);
206
+ }
207
+ }
208
+
209
+ /**
210
+ * Resumes recording, see notes for `pause().
211
+ *
212
+ * Note that calling `startRecording()` here will cause a
213
+ * new DOM checkout.`
214
+ */
215
+ resume() {
216
+ this._isPaused = false;
217
+ this.startRecording();
218
+ }
219
+
220
+ /** for tests only */
221
+ clearSession() {
222
+ try {
223
+ deleteSession();
224
+ this.session = undefined;
225
+ } catch (err) {
226
+ (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.error('[Replay]', err);
227
+ captureInternalException(err);
228
+ }
229
+ }
230
+
231
+ /**
232
+ * Loads a session from storage, or creates a new one if it does not exist or
233
+ * is expired.
234
+ */
235
+ loadSession({ expiry }) {
236
+ const { type, session } = getSession({
237
+ expiry,
238
+ stickySession: Boolean(this.options.stickySession),
239
+ currentSession: this.session,
240
+ sessionSampleRate: this.options.sessionSampleRate,
241
+ errorSampleRate: this.options.errorSampleRate,
242
+ });
243
+
244
+ // If session was newly created (i.e. was not loaded from storage), then
245
+ // enable flag to create the root replay
246
+ if (type === 'new') {
247
+ this.setInitialState();
248
+ }
249
+
250
+ if (session.id !== _optionalChain([this, 'access', _26 => _26.session, 'optionalAccess', _27 => _27.id])) {
251
+ session.previousSessionId = _optionalChain([this, 'access', _28 => _28.session, 'optionalAccess', _29 => _29.id]);
252
+ }
253
+
254
+ this.session = session;
255
+ }
256
+
257
+ /**
258
+ * Capture some initial state that can change throughout the lifespan of the
259
+ * replay. This is required because otherwise they would be captured at the
260
+ * first flush.
261
+ */
262
+ setInitialState() {
263
+ const urlPath = `${WINDOW.location.pathname}${WINDOW.location.hash}${WINDOW.location.search}`;
264
+ const url = `${WINDOW.location.origin}${urlPath}`;
265
+
266
+ this.performanceEvents = [];
267
+
268
+ // Reset _context as well
269
+ this.clearContext();
270
+
271
+ this._context.initialUrl = url;
272
+ this._context.initialTimestamp = new Date().getTime();
273
+ this._context.urls.push(url);
274
+ }
275
+
276
+ /**
277
+ * Adds listeners to record events for the replay
278
+ */
279
+ addListeners() {
280
+ try {
281
+ WINDOW.document.addEventListener('visibilitychange', this.handleVisibilityChange);
282
+ WINDOW.addEventListener('blur', this.handleWindowBlur);
283
+ WINDOW.addEventListener('focus', this.handleWindowFocus);
284
+
285
+ // We need to filter out dropped events captured by `addGlobalEventProcessor(this.handleGlobalEvent)` below
286
+ this._overwriteRecordDroppedEvent();
287
+
288
+ // There is no way to remove these listeners, so ensure they are only added once
289
+ if (!this._hasInitializedCoreListeners) {
290
+ // Listeners from core SDK //
291
+ const scope = getCurrentHub().getScope();
292
+ _optionalChain([scope, 'optionalAccess', _30 => _30.addScopeListener, 'call', _31 => _31(this.handleCoreBreadcrumbListener('scope'))]);
293
+ addInstrumentationHandler('dom', this.handleCoreBreadcrumbListener('dom'));
294
+ addInstrumentationHandler('fetch', this.handleCoreSpanListener('fetch'));
295
+ addInstrumentationHandler('xhr', this.handleCoreSpanListener('xhr'));
296
+ addInstrumentationHandler('history', this.handleCoreSpanListener('history'));
297
+
298
+ // Tag all (non replay) events that get sent to Sentry with the current
299
+ // replay ID so that we can reference them later in the UI
300
+ addGlobalEventProcessor(this.handleGlobalEvent);
301
+
302
+ this._hasInitializedCoreListeners = true;
303
+ }
304
+ } catch (err) {
305
+ (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.error('[Replay]', err);
306
+ captureInternalException(err);
307
+ }
308
+
309
+ // _performanceObserver //
310
+ if (!('_performanceObserver' in WINDOW)) {
311
+ return;
312
+ }
313
+
314
+ this._performanceObserver = new PerformanceObserver(this.handle_performanceObserver);
315
+
316
+ // Observe almost everything for now (no mark/measure)
317
+ [
318
+ 'element',
319
+ 'event',
320
+ 'first-input',
321
+ 'largest-contentful-paint',
322
+ 'layout-shift',
323
+ 'longtask',
324
+ 'navigation',
325
+ 'paint',
326
+ 'resource',
327
+ ].forEach(type => {
328
+ try {
329
+ _optionalChain([this, 'access', _32 => _32._performanceObserver, 'optionalAccess', _33 => _33.observe, 'call', _34 => _34({
330
+ type,
331
+ buffered: true,
332
+ })]);
333
+ } catch (e) {
334
+ // This can throw if an entry type is not supported in the browser.
335
+ // Ignore these errors.
336
+ }
337
+ });
338
+ }
339
+
340
+ /**
341
+ * Cleans up listeners that were created in `addListeners`
342
+ */
343
+ removeListeners() {
344
+ try {
345
+ WINDOW.document.removeEventListener('visibilitychange', this.handleVisibilityChange);
346
+
347
+ WINDOW.removeEventListener('blur', this.handleWindowBlur);
348
+ WINDOW.removeEventListener('focus', this.handleWindowFocus);
349
+
350
+ this._restoreRecordDroppedEvent();
351
+
352
+ if (this._performanceObserver) {
353
+ this._performanceObserver.disconnect();
354
+ this._performanceObserver = null;
355
+ }
356
+ } catch (err) {
357
+ (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.error('[Replay]', err);
358
+ captureInternalException(err);
359
+ }
360
+ }
361
+
362
+ /**
363
+ * We want to batch uploads of replay events. Save events only if
364
+ * `<flushMinDelay>` milliseconds have elapsed since the last event
365
+ * *OR* if `<flushMaxDelay>` milliseconds have elapsed.
366
+ *
367
+ * Accepts a callback to perform side-effects and returns true to stop batch
368
+ * processing and hand back control to caller.
369
+ */
370
+ addUpdate(cb) {
371
+ // We need to always run `cb` (e.g. in the case of `this._waitForError == true`)
372
+ const cbResult = _optionalChain([cb, 'optionalCall', _35 => _35()]);
373
+
374
+ // If this option is turned on then we will only want to call `flush`
375
+ // explicitly
376
+ if (this._waitForError) {
377
+ return;
378
+ }
379
+
380
+ // If callback is true, we do not want to continue with flushing -- the
381
+ // caller will need to handle it.
382
+ if (cbResult === true) {
383
+ return;
384
+ }
385
+
386
+ // addUpdate is called quite frequently - use _debouncedFlush so that it
387
+ // respects the flush delays and does not flush immediately
388
+ this._debouncedFlush();
389
+ }
390
+
391
+ /**
392
+ * Core Sentry SDK global event handler. Attaches `replayId` to all [non-replay]
393
+ * events as a tag. Also handles the case where we only want to capture a reply
394
+ * when an error occurs.
395
+ **/
396
+ __init14() {this.handleGlobalEvent = (event) => {
397
+ // Do not apply replayId to the root event
398
+ if (
399
+ // @ts-ignore new event type
400
+ event.type === REPLAY_EVENT_NAME
401
+ ) {
402
+ // Replays have separate set of breadcrumbs, do not include breadcrumbs
403
+ // from core SDK
404
+ delete event.breadcrumbs;
405
+ return event;
406
+ }
407
+
408
+ // Only tag transactions with replayId if not waiting for an error
409
+ if (event.type !== 'transaction' || !this._waitForError) {
410
+ event.tags = { ...event.tags, replayId: _optionalChain([this, 'access', _36 => _36.session, 'optionalAccess', _37 => _37.id]) };
411
+ }
412
+
413
+ // Collect traceIds in _context regardless of `_waitForError` - if it's true,
414
+ // _context gets cleared on every checkout
415
+ if (event.type === 'transaction') {
416
+ this._context.traceIds.add(String(_optionalChain([event, 'access', _38 => _38.contexts, 'optionalAccess', _39 => _39.trace, 'optionalAccess', _40 => _40.trace_id]) || ''));
417
+ return event;
418
+ }
419
+
420
+ // XXX: Is it safe to assume that all other events are error events?
421
+ // @ts-ignore: Type 'undefined' is not assignable to type 'string'.ts(2345)
422
+ this._context.errorIds.add(event.event_id);
423
+
424
+ const exc = _optionalChain([event, 'access', _41 => _41.exception, 'optionalAccess', _42 => _42.values, 'optionalAccess', _43 => _43[0]]);
425
+ addInternalBreadcrumb({
426
+ message: `Tagging event (${event.event_id}) - ${event.message} - ${_optionalChain([exc, 'optionalAccess', _44 => _44.type]) || 'Unknown'}: ${
427
+ _optionalChain([exc, 'optionalAccess', _45 => _45.value]) || 'n/a'
428
+ }`,
429
+ });
430
+
431
+ // Need to be very careful that this does not cause an infinite loop
432
+ if (
433
+ this._waitForError &&
434
+ event.exception &&
435
+ event.message !== UNABLE_TO_SEND_REPLAY // ignore this error because otherwise we could loop indefinitely with trying to capture replay and failing
436
+ ) {
437
+ setTimeout(async () => {
438
+ // Allow flush to complete before resuming as a session recording, otherwise
439
+ // the checkout from `startRecording` may be included in the payload.
440
+ // Prefer to keep the error replay as a separate (and smaller) segment
441
+ // than the session replay.
442
+ await this.flushImmediate();
443
+
444
+ if (this._stopRecording) {
445
+ this._stopRecording();
446
+ // Reset all "capture on error" configuration before
447
+ // starting a new recording
448
+ delete this.recordingOptions.checkoutEveryNms;
449
+ this._waitForError = false;
450
+ this.startRecording();
451
+ }
452
+ });
453
+ }
454
+
455
+ return event;
456
+ };}
457
+
458
+ /**
459
+ * Handler for recording events.
460
+ *
461
+ * Adds to event buffer, and has varying flushing behaviors if the event was a checkout.
462
+ */
463
+ __init15() {this.handleRecordingEmit = (
464
+ event,
465
+ isCheckout,
466
+ ) => {
467
+ // If this is false, it means session is expired, create and a new session and wait for checkout
468
+ if (!this.checkAndHandleExpiredSession()) {
469
+ (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.error('[Replay] Received replay event after session expired.');
470
+
471
+ return;
472
+ }
473
+
474
+ this.addUpdate(() => {
475
+ // The session is always started immediately on pageload/init, but for
476
+ // error-only replays, it should reflect the most recent checkout
477
+ // when an error occurs. Clear any state that happens before this current
478
+ // checkout. This needs to happen before `addEvent()` which updates state
479
+ // dependent on this reset.
480
+ if (this._waitForError && event.type === 2) {
481
+ this.setInitialState();
482
+ }
483
+
484
+ // We need to clear existing events on a checkout, otherwise they are
485
+ // incremental event updates and should be appended
486
+ this.addEvent(event, isCheckout);
487
+
488
+ // Different behavior for full snapshots (type=2), ignore other event types
489
+ // See https://github.com/rrweb-io/rrweb/blob/d8f9290ca496712aa1e7d472549480c4e7876594/packages/rrweb/src/types.ts#L16
490
+ if (event.type !== 2) {
491
+ return false;
492
+ }
493
+
494
+ // If there is a previousSessionId after a full snapshot occurs, then
495
+ // the replay session was started due to session expiration. The new session
496
+ // is started before triggering a new checkout and contains the id
497
+ // of the previous session. Do not immediately flush in this case
498
+ // to avoid capturing only the checkout and instead the replay will
499
+ // be captured if they perform any follow-up actions.
500
+ if (_optionalChain([this, 'access', _46 => _46.session, 'optionalAccess', _47 => _47.previousSessionId])) {
501
+ return true;
502
+ }
503
+
504
+ // See note above re: session start needs to reflect the most recent
505
+ // checkout.
506
+ if (this._waitForError && this.session && this._context.earliestEvent) {
507
+ this.session.started = this._context.earliestEvent;
508
+ this._maybeSaveSession();
509
+ }
510
+
511
+ // If the full snapshot is due to an initial load, we will not have
512
+ // a previous session ID. In this case, we want to buffer events
513
+ // for a set amount of time before flushing. This can help avoid
514
+ // capturing replays of users that immediately close the window.
515
+ setTimeout(() => this.conditionalFlush(), this.options.initialFlushDelay);
516
+
517
+ // Cancel any previously debounced flushes to ensure there are no [near]
518
+ // simultaneous flushes happening. The latter request should be
519
+ // insignificant in this case, so wait for additional user interaction to
520
+ // trigger a new flush.
521
+ //
522
+ // This can happen because there's no guarantee that a recording event
523
+ // happens first. e.g. a mouse click can happen and trigger a debounced
524
+ // flush before the checkout.
525
+ _optionalChain([this, 'access', _48 => _48._debouncedFlush, 'optionalAccess', _49 => _49.cancel, 'call', _50 => _50()]);
526
+
527
+ return true;
528
+ });
529
+ };}
530
+
531
+ /**
532
+ * Handle when visibility of the page content changes. Opening a new tab will
533
+ * cause the state to change to hidden because of content of current page will
534
+ * be hidden. Likewise, moving a different window to cover the contents of the
535
+ * page will also trigger a change to a hidden state.
536
+ */
537
+ __init16() {this.handleVisibilityChange = () => {
538
+ if (WINDOW.document.visibilityState === 'visible') {
539
+ this.doChangeToForegroundTasks();
540
+ } else {
541
+ this.doChangeToBackgroundTasks();
542
+ }
543
+ };}
544
+
545
+ /**
546
+ * Handle when page is blurred
547
+ */
548
+ __init17() {this.handleWindowBlur = () => {
549
+ const breadcrumb = createBreadcrumb({
550
+ category: 'ui.blur',
551
+ });
552
+
553
+ // Do not count blur as a user action -- it's part of the process of them
554
+ // leaving the page
555
+ this.doChangeToBackgroundTasks(breadcrumb);
556
+ };}
557
+
558
+ /**
559
+ * Handle when page is focused
560
+ */
561
+ __init18() {this.handleWindowFocus = () => {
562
+ const breadcrumb = createBreadcrumb({
563
+ category: 'ui.focus',
564
+ });
565
+
566
+ // Do not count focus as a user action -- instead wait until they focus and
567
+ // interactive with page
568
+ this.doChangeToForegroundTasks(breadcrumb);
569
+ };}
570
+
571
+ /**
572
+ * Handler for Sentry Core SDK events.
573
+ *
574
+ * These specific events will create span-like objects in the recording.
575
+ */
576
+ __init19() {this.handleCoreSpanListener =
577
+ (type) =>
578
+ (handlerData) => {
579
+ if (!this._isEnabled) {
580
+ return;
581
+ }
582
+
583
+ const result = spanHandler(type, handlerData);
584
+
585
+ if (result === null) {
586
+ return;
587
+ }
588
+
589
+ if (type === 'history') {
590
+ // Need to collect visited URLs
591
+ this._context.urls.push(result.name);
592
+ this.triggerUserActivity();
593
+ }
594
+
595
+ this.addUpdate(() => {
596
+ void this.createPerformanceSpans([result ]);
597
+ // Returning true will cause `addUpdate` to not flush
598
+ // We do not want network requests to cause a flush. This will prevent
599
+ // recurring/polling requests from keeping the replay session alive.
600
+ return ['xhr', 'fetch'].includes(type);
601
+ });
602
+ };}
603
+
604
+ /**
605
+ * Handler for Sentry Core SDK events.
606
+ *
607
+ * These events will create breadcrumb-like objects in the recording.
608
+ */
609
+ __init20() {this.handleCoreBreadcrumbListener =
610
+ (type) =>
611
+ (handlerData) => {
612
+ if (!this._isEnabled) {
613
+ return;
614
+ }
615
+
616
+ const result = breadcrumbHandler(type, handlerData);
617
+
618
+ if (result === null) {
619
+ return;
620
+ }
621
+
622
+ if (result.category === 'sentry.transaction') {
623
+ return;
624
+ }
625
+
626
+ if (result.category === 'ui.click') {
627
+ this.triggerUserActivity();
628
+ } else {
629
+ this.checkAndHandleExpiredSession();
630
+ }
631
+
632
+ this.addUpdate(() => {
633
+ this.addEvent({
634
+ type: EventType.Custom,
635
+ // TODO: We were converting from ms to seconds for breadcrumbs, spans,
636
+ // but maybe we should just keep them as milliseconds
637
+ timestamp: (result.timestamp || 0) * 1000,
638
+ data: {
639
+ tag: 'breadcrumb',
640
+ payload: result,
641
+ },
642
+ });
643
+
644
+ // Do not flush after console log messages
645
+ return result.category === 'console';
646
+ });
647
+ };}
648
+
649
+ /**
650
+ * Keep a list of performance entries that will be sent with a replay
651
+ */
652
+ __init21() {this.handle_performanceObserver = (list) => {
653
+ // For whatever reason the observer was returning duplicate navigation
654
+ // entries (the other entry types were not duplicated).
655
+ const newPerformanceEntries = dedupePerformanceEntries(
656
+ this.performanceEvents,
657
+ list.getEntries() ,
658
+ );
659
+ this.performanceEvents = newPerformanceEntries;
660
+ };}
661
+
662
+ /**
663
+ * Tasks to run when we consider a page to be hidden (via blurring and/or visibility)
664
+ */
665
+ doChangeToBackgroundTasks(breadcrumb) {
666
+ if (!this.session) {
667
+ return;
668
+ }
669
+
670
+ const expired = isSessionExpired(this.session, VISIBILITY_CHANGE_TIMEOUT);
671
+
672
+ if (breadcrumb && !expired) {
673
+ this.createCustomBreadcrumb(breadcrumb);
674
+ }
675
+
676
+ // Send replay when the page/tab becomes hidden. There is no reason to send
677
+ // replay if it becomes visible, since no actions we care about were done
678
+ // while it was hidden
679
+ this.conditionalFlush();
680
+ }
681
+
682
+ /**
683
+ * Tasks to run when we consider a page to be visible (via focus and/or visibility)
684
+ */
685
+ doChangeToForegroundTasks(breadcrumb) {
686
+ if (!this.session) {
687
+ return;
688
+ }
689
+
690
+ const isSessionActive = this.checkAndHandleExpiredSession({
691
+ expiry: VISIBILITY_CHANGE_TIMEOUT,
692
+ });
693
+
694
+ if (!isSessionActive) {
695
+ // If the user has come back to the page within VISIBILITY_CHANGE_TIMEOUT
696
+ // ms, we will re-use the existing session, otherwise create a new
697
+ // session
698
+ (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.log('[Replay] Document has become active, but session has expired');
699
+ return;
700
+ }
701
+
702
+ if (breadcrumb) {
703
+ this.createCustomBreadcrumb(breadcrumb);
704
+ }
705
+ }
706
+
707
+ /**
708
+ * Trigger rrweb to take a full snapshot which will cause this plugin to
709
+ * create a new Replay event.
710
+ */
711
+ triggerFullSnapshot() {
712
+ (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.log('[Replay] Taking full rrweb snapshot');
713
+ record.takeFullSnapshot(true);
714
+ }
715
+
716
+ /**
717
+ * Add an event to the event buffer
718
+ */
719
+ addEvent(event, isCheckout) {
720
+ if (!this.eventBuffer) {
721
+ // This implies that `_isEnabled` is false
722
+ return;
723
+ }
724
+
725
+ if (this._isPaused) {
726
+ // Do not add to event buffer when recording is paused
727
+ return;
728
+ }
729
+
730
+ // TODO: sadness -- we will want to normalize timestamps to be in ms -
731
+ // requires coordination with frontend
732
+ const isMs = event.timestamp > 9999999999;
733
+ const timestampInMs = isMs ? event.timestamp : event.timestamp * 1000;
734
+
735
+ // Throw out events that happen more than 5 minutes ago. This can happen if
736
+ // page has been left open and idle for a long period of time and user
737
+ // comes back to trigger a new session. The performance entries rely on
738
+ // `performance.timeOrigin`, which is when the page first opened.
739
+ if (timestampInMs + SESSION_IDLE_DURATION < new Date().getTime()) {
740
+ return;
741
+ }
742
+
743
+ // Only record earliest event if a new session was created, otherwise it
744
+ // shouldn't be relevant
745
+ if (
746
+ _optionalChain([this, 'access', _51 => _51.session, 'optionalAccess', _52 => _52.segmentId]) === 0 &&
747
+ (!this._context.earliestEvent || timestampInMs < this._context.earliestEvent)
748
+ ) {
749
+ this._context.earliestEvent = timestampInMs;
750
+ }
751
+
752
+ this.eventBuffer.addEvent(event, isCheckout);
753
+ }
754
+
755
+ /**
756
+ * Update user activity (across session lifespans)
757
+ */
758
+ updateUserActivity(_lastActivity = new Date().getTime()) {
759
+ this._lastActivity = _lastActivity;
760
+ }
761
+
762
+ /**
763
+ * Updates the session's last activity timestamp
764
+ */
765
+ updateSessionActivity(_lastActivity = new Date().getTime()) {
766
+ if (this.session) {
767
+ this.session.lastActivity = _lastActivity;
768
+ this._maybeSaveSession();
769
+ }
770
+ }
771
+
772
+ /**
773
+ * Updates the user activity timestamp and resumes recording. This should be
774
+ * called in an event handler for a user action that we consider as the user
775
+ * being "active" (e.g. a mouse click).
776
+ */
777
+ triggerUserActivity() {
778
+ this.updateUserActivity();
779
+
780
+ // This case means that recording was once stopped due to inactivity.
781
+ // Ensure that recording is resumed.
782
+ if (!this._stopRecording) {
783
+ // Create a new session, otherwise when the user action is flushed, it
784
+ // will get rejected due to an expired session.
785
+ this.loadSession({ expiry: SESSION_IDLE_DURATION });
786
+
787
+ // Note: This will cause a new DOM checkout
788
+ this.resume();
789
+ return;
790
+ }
791
+
792
+ // Otherwise... recording was never suspended, continue as normalish
793
+ this.checkAndHandleExpiredSession();
794
+
795
+ this.updateSessionActivity();
796
+ }
797
+
798
+ /**
799
+ * Helper to create (and buffer) a replay breadcrumb from a core SDK breadcrumb
800
+ */
801
+ createCustomBreadcrumb(breadcrumb) {
802
+ this.addUpdate(() => {
803
+ this.addEvent({
804
+ type: EventType.Custom,
805
+ timestamp: breadcrumb.timestamp || 0,
806
+ data: {
807
+ tag: 'breadcrumb',
808
+ payload: breadcrumb,
809
+ },
810
+ });
811
+ });
812
+ }
813
+
814
+ /**
815
+ * Create a "span" for each performance entry. The parent transaction is `this.replayEvent`.
816
+ */
817
+ createPerformanceSpans(entries) {
818
+ return Promise.all(
819
+ entries.map(({ type, start, end, name, data }) =>
820
+ this.addEvent({
821
+ type: EventType.Custom,
822
+ timestamp: start,
823
+ data: {
824
+ tag: 'performanceSpan',
825
+ payload: {
826
+ op: type,
827
+ description: name,
828
+ startTimestamp: start,
829
+ endTimestamp: end,
830
+ data,
831
+ },
832
+ },
833
+ }),
834
+ ),
835
+ );
836
+ }
837
+
838
+ /**
839
+ * Observed performance events are added to `this.performanceEvents`. These
840
+ * are included in the replay event before it is finished and sent to Sentry.
841
+ */
842
+ addPerformanceEntries() {
843
+ // Copy and reset entries before processing
844
+ const entries = [...this.performanceEvents];
845
+ this.performanceEvents = [];
846
+
847
+ return this.createPerformanceSpans(createPerformanceEntries(entries));
848
+ }
849
+
850
+ /**
851
+ * Create a "span" for the total amount of memory being used by JS objects
852
+ * (including v8 internal objects).
853
+ */
854
+ addMemoryEntry() {
855
+ // window.performance.memory is a non-standard API and doesn't work on all browsers
856
+ // so we check before creating the event.
857
+ if (!('memory' in WINDOW.performance)) {
858
+ return;
859
+ }
860
+
861
+ return this.createPerformanceSpans([
862
+ // @ts-ignore memory doesn't exist on type Performance as the API is non-standard (we check that it exists above)
863
+ createMemoryEntry(WINDOW.performance.memory),
864
+ ]);
865
+ }
866
+
867
+ /**
868
+ * Checks if recording should be stopped due to user inactivity. Otherwise
869
+ * check if session is expired and create a new session if so. Triggers a new
870
+ * full snapshot on new session.
871
+ *
872
+ * Returns true if session is not expired, false otherwise.
873
+ */
874
+ checkAndHandleExpiredSession({ expiry = SESSION_IDLE_DURATION } = {}) {
875
+ const oldSessionId = _optionalChain([this, 'access', _53 => _53.session, 'optionalAccess', _54 => _54.id]);
876
+
877
+ // Prevent starting a new session if the last user activity is older than
878
+ // MAX_SESSION_LIFE. Otherwise non-user activity can trigger a new
879
+ // session+recording. This creates noisy replays that do not have much
880
+ // content in them.
881
+ if (this._lastActivity && isExpired(this._lastActivity, MAX_SESSION_LIFE)) {
882
+ // Pause recording
883
+ this.pause();
884
+ return;
885
+ }
886
+
887
+ // --- There is recent user activity --- //
888
+ // This will create a new session if expired, based on expiry length
889
+ this.loadSession({ expiry });
890
+
891
+ // Session was expired if session ids do not match
892
+ const expired = oldSessionId !== _optionalChain([this, 'access', _55 => _55.session, 'optionalAccess', _56 => _56.id]);
893
+
894
+ if (!expired) {
895
+ return true;
896
+ }
897
+
898
+ // Session is expired, trigger a full snapshot (which will create a new session)
899
+ this.triggerFullSnapshot();
900
+
901
+ return false;
902
+ }
903
+
904
+ /**
905
+ * Only flush if `this._waitForError` is false.
906
+ */
907
+ conditionalFlush() {
908
+ if (this._waitForError) {
909
+ return;
910
+ }
911
+
912
+ void this.flushImmediate();
913
+ }
914
+
915
+ /**
916
+ * Clear _context
917
+ */
918
+ clearContext() {
919
+ // XXX: `initialTimestamp` and `initialUrl` do not get cleared
920
+ this._context.errorIds.clear();
921
+ this._context.traceIds.clear();
922
+ this._context.urls = [];
923
+ this._context.earliestEvent = null;
924
+ }
925
+
926
+ /**
927
+ * Return and clear _context
928
+ */
929
+ popEventContext() {
930
+ if (this._context.earliestEvent && this._context.earliestEvent < this._context.initialTimestamp) {
931
+ this._context.initialTimestamp = this._context.earliestEvent;
932
+ }
933
+
934
+ const _context = {
935
+ initialTimestamp: this._context.initialTimestamp,
936
+ initialUrl: this._context.initialUrl,
937
+ errorIds: Array.from(this._context.errorIds).filter(Boolean),
938
+ traceIds: Array.from(this._context.traceIds).filter(Boolean),
939
+ urls: this._context.urls,
940
+ };
941
+
942
+ this.clearContext();
943
+
944
+ return _context;
945
+ }
946
+
947
+ /**
948
+ * Flushes replay event buffer to Sentry.
949
+ *
950
+ * Performance events are only added right before flushing - this is
951
+ * due to the buffered performance observer events.
952
+ *
953
+ * Should never be called directly, only by `flush`
954
+ */
955
+ async runFlush() {
956
+ if (!this.session) {
957
+ (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.error('[Replay] No session found to flush.');
958
+ return;
959
+ }
960
+
961
+ await this.addPerformanceEntries();
962
+
963
+ if (!_optionalChain([this, 'access', _57 => _57.eventBuffer, 'optionalAccess', _58 => _58.length])) {
964
+ return;
965
+ }
966
+
967
+ // Only attach memory event if eventBuffer is not empty
968
+ await this.addMemoryEntry();
969
+
970
+ try {
971
+ // Note this empties the event buffer regardless of outcome of sending replay
972
+ const recordingData = await this.eventBuffer.finish();
973
+
974
+ // NOTE: Copy values from instance members, as it's possible they could
975
+ // change before the flush finishes.
976
+ const replayId = this.session.id;
977
+ const eventContext = this.popEventContext();
978
+ // Always increment segmentId regardless of outcome of sending replay
979
+ const segmentId = this.session.segmentId++;
980
+ this._maybeSaveSession();
981
+
982
+ await this.sendReplay({
983
+ replayId,
984
+ events: recordingData,
985
+ segmentId,
986
+ includeReplayStartTimestamp: segmentId === 0,
987
+ eventContext,
988
+ });
989
+ } catch (err) {
990
+ (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.error(err);
991
+ captureInternalException(err);
992
+ }
993
+ }
994
+
995
+ /**
996
+ * Flush recording data to Sentry. Creates a lock so that only a single flush
997
+ * can be active at a time. Do not call this directly.
998
+ */
999
+ __init22() {this.flush = async () => {
1000
+ if (!this._isEnabled) {
1001
+ // This is just a precaution, there should be no listeners that would
1002
+ // cause a flush.
1003
+ return;
1004
+ }
1005
+
1006
+ if (!this.checkAndHandleExpiredSession()) {
1007
+ (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.error('[Replay] Attempting to finish replay event after session expired.');
1008
+ return;
1009
+ }
1010
+
1011
+ if (!_optionalChain([this, 'access', _59 => _59.session, 'optionalAccess', _60 => _60.id])) {
1012
+ (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.error('[Replay] No session found to flush.');
1013
+ return;
1014
+ }
1015
+
1016
+ // A flush is about to happen, cancel any queued flushes
1017
+ _optionalChain([this, 'access', _61 => _61._debouncedFlush, 'optionalAccess', _62 => _62.cancel, 'call', _63 => _63()]);
1018
+
1019
+ // No existing flush in progress, proceed with flushing.
1020
+ // this._flushLock acts as a lock so that future calls to `flush()`
1021
+ // will be blocked until this promise resolves
1022
+ if (!this._flushLock) {
1023
+ this._flushLock = this.runFlush();
1024
+ await this._flushLock;
1025
+ this._flushLock = null;
1026
+ return;
1027
+ }
1028
+
1029
+ // Wait for previous flush to finish, then call the debounced `flush()`.
1030
+ // It's possible there are other flush requests queued and waiting for it
1031
+ // to resolve. We want to reduce all outstanding requests (as well as any
1032
+ // new flush requests that occur within a second of the locked flush
1033
+ // completing) into a single flush.
1034
+
1035
+ try {
1036
+ await this._flushLock;
1037
+ } catch (err) {
1038
+ (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.error(err);
1039
+ } finally {
1040
+ this._debouncedFlush();
1041
+ }
1042
+ };}
1043
+
1044
+ /**
1045
+ *
1046
+ * Always flush via `_debouncedFlush` so that we do not have flushes triggered
1047
+ * from calling both `flush` and `_debouncedFlush`. Otherwise, there could be
1048
+ * cases of mulitple flushes happening closely together.
1049
+ */
1050
+ flushImmediate() {
1051
+ this._debouncedFlush();
1052
+ // `.flush` is provided by lodash.debounce
1053
+ return this._debouncedFlush.flush();
1054
+ }
1055
+
1056
+ /**
1057
+ * Send replay attachment using `fetch()`
1058
+ */
1059
+ async sendReplayRequest({
1060
+ events,
1061
+ replayId: event_id,
1062
+ segmentId: segment_id,
1063
+ includeReplayStartTimestamp,
1064
+ eventContext,
1065
+ }) {
1066
+ const payloadWithSequence = createPayload({
1067
+ events,
1068
+ headers: {
1069
+ segment_id,
1070
+ },
1071
+ });
1072
+
1073
+ const { urls, errorIds, traceIds, initialTimestamp } = eventContext;
1074
+
1075
+ const currentTimestamp = new Date().getTime();
1076
+
1077
+ const sdkInfo = {
1078
+ name: 'sentry.javascript.integration.replay',
1079
+ version: "7.24.0",
1080
+ };
1081
+
1082
+ const replayEvent = await new Promise(resolve => {
1083
+ _optionalChain([getCurrentHub, 'call', _64 => _64()
1084
+
1085
+ , 'optionalAccess', _65 => _65._withClient, 'call', _66 => _66(async (client, scope) => {
1086
+ // XXX: This event does not trigger `beforeSend` in SDK
1087
+ // @ts-ignore private api
1088
+ const preparedEvent = await client._prepareEvent(
1089
+ {
1090
+ type: REPLAY_EVENT_NAME,
1091
+ ...(includeReplayStartTimestamp ? { replay_start_timestamp: initialTimestamp / 1000 } : {}),
1092
+ timestamp: currentTimestamp / 1000,
1093
+ error_ids: errorIds,
1094
+ trace_ids: traceIds,
1095
+ urls,
1096
+ replay_id: event_id,
1097
+ segment_id,
1098
+ },
1099
+ { event_id },
1100
+ scope,
1101
+ );
1102
+ const session = scope && scope.getSession();
1103
+ if (session) {
1104
+ // @ts-ignore private api
1105
+ client._updateSessionFromEvent(session, preparedEvent);
1106
+ }
1107
+
1108
+ preparedEvent.sdk = {
1109
+ ...preparedEvent.sdk,
1110
+ ...sdkInfo,
1111
+ };
1112
+
1113
+ preparedEvent.tags = {
1114
+ ...preparedEvent.tags,
1115
+ sessionSampleRate: this.options.sessionSampleRate,
1116
+ errorSampleRate: this.options.errorSampleRate,
1117
+ replayType: _optionalChain([this, 'access', _67 => _67.session, 'optionalAccess', _68 => _68.sampled]),
1118
+ };
1119
+
1120
+ resolve(preparedEvent);
1121
+ })]);
1122
+ });
1123
+
1124
+ const envelope = createEnvelope(
1125
+ {
1126
+ event_id,
1127
+ sent_at: new Date().toISOString(),
1128
+ sdk: sdkInfo,
1129
+ },
1130
+ [
1131
+ // @ts-ignore New types
1132
+ [{ type: 'replay_event' }, replayEvent],
1133
+ [
1134
+ {
1135
+ // @ts-ignore setting envelope
1136
+ type: 'replay_recording',
1137
+ length: payloadWithSequence.length,
1138
+ },
1139
+ // @ts-ignore: Type 'string' is not assignable to type 'ClientReport'.ts(2322)
1140
+ payloadWithSequence,
1141
+ ],
1142
+ ],
1143
+ );
1144
+
1145
+ const client = getCurrentHub().getClient();
1146
+ try {
1147
+ return _optionalChain([client, 'optionalAccess', _69 => _69.getTransport, 'call', _70 => _70(), 'optionalAccess', _71 => _71.send, 'call', _72 => _72(envelope)]);
1148
+ } catch (e2) {
1149
+ throw new Error(UNABLE_TO_SEND_REPLAY);
1150
+ }
1151
+ }
1152
+
1153
+ resetRetries() {
1154
+ this._retryCount = 0;
1155
+ this._retryInterval = BASE_RETRY_INTERVAL;
1156
+ }
1157
+
1158
+ /**
1159
+ * Finalize and send the current replay event to Sentry
1160
+ */
1161
+ async sendReplay({
1162
+ replayId,
1163
+ events,
1164
+ segmentId,
1165
+ includeReplayStartTimestamp,
1166
+ eventContext,
1167
+ }) {
1168
+ // short circuit if there's no events to upload (this shouldn't happen as runFlush makes this check)
1169
+ if (!events.length) {
1170
+ return;
1171
+ }
1172
+
1173
+ try {
1174
+ await this.sendReplayRequest({
1175
+ events,
1176
+ replayId,
1177
+ segmentId,
1178
+ includeReplayStartTimestamp,
1179
+ eventContext,
1180
+ });
1181
+ this.resetRetries();
1182
+ return true;
1183
+ } catch (err) {
1184
+ (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.error(err);
1185
+ // Capture error for every failed replay
1186
+ setContext('Replays', {
1187
+ _retryCount: this._retryCount,
1188
+ });
1189
+ captureInternalException(err);
1190
+
1191
+ // If an error happened here, it's likely that uploading the attachment
1192
+ // failed, we'll can retry with the same events payload
1193
+ if (this._retryCount >= MAX_RETRY_COUNT) {
1194
+ throw new Error(`${UNABLE_TO_SEND_REPLAY} - max retries exceeded`);
1195
+ }
1196
+
1197
+ this._retryCount = this._retryCount + 1;
1198
+ // will retry in intervals of 5, 10, 30
1199
+ this._retryInterval = this._retryCount * this._retryInterval;
1200
+
1201
+ return await new Promise((resolve, reject) => {
1202
+ setTimeout(async () => {
1203
+ try {
1204
+ await this.sendReplay({
1205
+ replayId,
1206
+ events,
1207
+ segmentId,
1208
+ includeReplayStartTimestamp,
1209
+ eventContext,
1210
+ });
1211
+ resolve(true);
1212
+ } catch (err) {
1213
+ reject(err);
1214
+ }
1215
+ }, this._retryInterval);
1216
+ });
1217
+ }
1218
+ }
1219
+
1220
+ /** Save the session, if it is sticky */
1221
+ _maybeSaveSession() {
1222
+ if (this.session && this.options.stickySession) {
1223
+ saveSession(this.session);
1224
+ }
1225
+ }
1226
+
1227
+ _overwriteRecordDroppedEvent() {
1228
+ const client = getCurrentHub().getClient();
1229
+
1230
+ if (!client) {
1231
+ return;
1232
+ }
1233
+
1234
+ const _originalCallback = client.recordDroppedEvent.bind(client);
1235
+
1236
+ const recordDroppedEvent = (
1237
+ reason,
1238
+ category,
1239
+ event,
1240
+ ) => {
1241
+ if (event && event.event_id) {
1242
+ this._context.errorIds.delete(event.event_id);
1243
+ }
1244
+
1245
+ return _originalCallback(reason, category, event);
1246
+ };
1247
+
1248
+ client.recordDroppedEvent = recordDroppedEvent;
1249
+ this._originalRecordDroppedEvent = _originalCallback;
1250
+ }
1251
+
1252
+ _restoreRecordDroppedEvent() {
1253
+ const client = getCurrentHub().getClient();
1254
+
1255
+ if (!client || !this._originalRecordDroppedEvent) {
1256
+ return;
1257
+ }
1258
+
1259
+ client.recordDroppedEvent = this._originalRecordDroppedEvent;
1260
+ }
1261
+ }
1262
+
1263
+ export { ReplayContainer };
1264
+ //# sourceMappingURL=replay.js.map