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