helpers.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import * as BreadcrumbFrameData from './replayBreadcrumbFrameData';
  2. import * as ReplayFrameEvents from './replayFrameEvents';
  3. import * as ReplaySpanFrameData from './replaySpanFrameData';
  4. export function ConsoleEvent({timestamp, message}: {timestamp: Date; message?: string}) {
  5. return ReplayFrameEvents.BreadcrumbFrameEvent({
  6. timestamp,
  7. data: {
  8. payload: BreadcrumbFrameData.ConsoleFrame({
  9. timestamp,
  10. message: message ?? 'Hello World',
  11. }),
  12. },
  13. });
  14. }
  15. export function ClickEvent({timestamp}: {timestamp: Date}) {
  16. return ReplayFrameEvents.BreadcrumbFrameEvent({
  17. timestamp,
  18. data: {
  19. payload: BreadcrumbFrameData.ClickFrame({
  20. timestamp,
  21. message: 'nav[aria-label="Primary Navigation"] > div > a#sidebar-item-projects',
  22. data: {
  23. nodeId: 42,
  24. },
  25. }),
  26. },
  27. });
  28. }
  29. export function DeadClickEvent({timestamp}: {timestamp: Date}) {
  30. return ReplayFrameEvents.BreadcrumbFrameEvent({
  31. timestamp,
  32. data: {
  33. payload: BreadcrumbFrameData.SlowClickFrame({
  34. timestamp,
  35. message: 'nav[aria-label="Primary Navigation"] > div > a#sidebar-item-projects',
  36. data: {
  37. nodeId: 42,
  38. url: '',
  39. timeAfterClickMs: 7000,
  40. endReason: 'timeout',
  41. },
  42. }),
  43. },
  44. });
  45. }
  46. export function NavigateEvent({
  47. startTimestamp,
  48. endTimestamp,
  49. }: {
  50. endTimestamp: Date;
  51. startTimestamp: Date;
  52. }) {
  53. const duration = endTimestamp.getTime() - startTimestamp.getTime(); // in MS
  54. return ReplayFrameEvents.SpanFrameEvent({
  55. timestamp: startTimestamp,
  56. data: {
  57. payload: ReplaySpanFrameData.NavigationFrame({
  58. op: 'navigation.navigate',
  59. startTimestamp,
  60. endTimestamp,
  61. description: '',
  62. data: {
  63. size: 1149,
  64. decodedBodySize: 1712,
  65. encodedBodySize: 849,
  66. duration,
  67. domInteractive: duration - 200,
  68. domContentLoadedEventStart: duration - 50,
  69. domContentLoadedEventEnd: duration - 48,
  70. loadEventStart: duration, // real value would be approx the same
  71. loadEventEnd: duration, // real value would be approx the same
  72. domComplete: duration, // real value would be approx the same
  73. redirectCount: 0,
  74. },
  75. }),
  76. },
  77. });
  78. }
  79. export function MemoryEvent({
  80. startTimestamp,
  81. endTimestamp,
  82. }: {
  83. endTimestamp: Date;
  84. startTimestamp: Date;
  85. }) {
  86. return ReplayFrameEvents.SpanFrameEvent({
  87. timestamp: startTimestamp,
  88. data: {
  89. payload: ReplaySpanFrameData.MemoryFrame({
  90. op: 'memory',
  91. startTimestamp,
  92. endTimestamp,
  93. description: '',
  94. }),
  95. },
  96. });
  97. }