@sprig-technologies/sprig-browser 2.32.2 → 2.32.3

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.
package/dist/replay.js CHANGED
@@ -1,8 +1,8 @@
1
- var xe = Object.defineProperty;
2
- var Be = (e, t, n) => t in e ? xe(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var M = (e, t, n) => (Be(e, typeof t != "symbol" ? t + "" : t, n), n);
4
- import { b as u, s as ie, a as f, v as N, c as Ue, P as de, r as ce, d as Te, e as T, S as O, f as _e } from "./metricsReporter-D0VZ2ZgI.js";
5
- var P = ((e) => (e[e.DomContentLoaded = 0] = "DomContentLoaded", e[e.Load = 1] = "Load", e[e.FullSnapshot = 2] = "FullSnapshot", e[e.IncrementalSnapshot = 3] = "IncrementalSnapshot", e[e.Meta = 4] = "Meta", e[e.Custom = 5] = "Custom", e[e.Plugin = 6] = "Plugin", e))(P || {});
1
+ var Ue = Object.defineProperty;
2
+ var Te = (e, t, n) => t in e ? Ue(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var M = (e, t, n) => (Te(e, typeof t != "symbol" ? t + "" : t, n), n);
4
+ import { b as u, s as ie, a as f, v as N, c as _e, P as de, r as ce, d as Ae, e as T, S as O, f as Ne } from "./metricsReporter-Gimz6xcf.js";
5
+ var R = ((e) => (e[e.DomContentLoaded = 0] = "DomContentLoaded", e[e.Load = 1] = "Load", e[e.FullSnapshot = 2] = "FullSnapshot", e[e.IncrementalSnapshot = 3] = "IncrementalSnapshot", e[e.Meta = 4] = "Meta", e[e.Custom = 5] = "Custom", e[e.Plugin = 6] = "Plugin", e))(R || {});
6
6
  const ue = new class {
7
7
  constructor(e) {
8
8
  M(this, "awaitingResolvers", []);
@@ -52,15 +52,15 @@ let K = { get(e, t, n) {
52
52
  function pe(e) {
53
53
  K = e(K);
54
54
  }
55
- function Ae(e) {
55
+ function Le(e) {
56
56
  return (ee || (ee = [IDBCursor.prototype.advance, IDBCursor.prototype.continue, IDBCursor.prototype.continuePrimaryKey])).includes(e) ? function(...t) {
57
57
  return e.apply(G(this), t), k(this.request);
58
58
  } : function(...t) {
59
59
  return k(e.apply(G(this), t));
60
60
  };
61
61
  }
62
- function Ne(e) {
63
- return typeof e == "function" ? Ae(e) : (e instanceof IDBTransaction && function(t) {
62
+ function Me(e) {
63
+ return typeof e == "function" ? Le(e) : (e instanceof IDBTransaction && function(t) {
64
64
  if (V.has(t))
65
65
  return;
66
66
  const n = new Promise((a, r) => {
@@ -88,7 +88,7 @@ function k(e) {
88
88
  }(e);
89
89
  if (H.has(e))
90
90
  return H.get(e);
91
- const t = Ne(e);
91
+ const t = Me(e);
92
92
  return t !== e && (H.set(e, t), _.set(t, e)), t;
93
93
  }
94
94
  const G = (e) => _.get(e);
@@ -97,14 +97,14 @@ function W(e, { blocked: t } = {}) {
97
97
  return t && (n.onblocked = (a) => t(a.oldVersion, a)), k(n).then(() => {
98
98
  });
99
99
  }
100
- const Le = ["get", "getKey", "getAll", "getAllKeys", "count"], Me = ["put", "add", "delete", "clear"], F = /* @__PURE__ */ new Map();
100
+ const Oe = ["get", "getKey", "getAll", "getAllKeys", "count"], He = ["put", "add", "delete", "clear"], F = /* @__PURE__ */ new Map();
101
101
  function te(e, t) {
102
102
  if (!(e instanceof IDBDatabase) || t in e || typeof t != "string")
103
103
  return;
104
104
  if (F.get(t))
105
105
  return F.get(t);
106
- const n = t.replace(/FromIndex$/, ""), a = t !== n, r = Me.includes(n);
107
- if (!(n in (a ? IDBIndex : IDBObjectStore).prototype) || !r && !Le.includes(n))
106
+ const n = t.replace(/FromIndex$/, ""), a = t !== n, r = He.includes(n);
107
+ if (!(n in (a ? IDBIndex : IDBObjectStore).prototype) || !r && !Oe.includes(n))
108
108
  return;
109
109
  const s = async function(o, ...d) {
110
110
  const i = this.transaction(o, r ? "readwrite" : "readonly");
@@ -114,34 +114,34 @@ function te(e, t) {
114
114
  return F.set(t, s), s;
115
115
  }
116
116
  pe((e) => ({ ...e, get: (t, n, a) => te(t, n) || e.get(t, n, a), has: (t, n) => !!te(t, n) || e.has(t, n) }));
117
- const Oe = ["continue", "continuePrimaryKey", "advance"], ne = {}, $ = /* @__PURE__ */ new WeakMap(), me = /* @__PURE__ */ new WeakMap(), He = { get(e, t) {
118
- if (!Oe.includes(t))
117
+ const Fe = ["continue", "continuePrimaryKey", "advance"], ne = {}, $ = /* @__PURE__ */ new WeakMap(), ge = /* @__PURE__ */ new WeakMap(), je = { get(e, t) {
118
+ if (!Fe.includes(t))
119
119
  return e[t];
120
120
  let n = ne[t];
121
121
  return n || (n = ne[t] = function(...a) {
122
- $.set(this, me.get(this)[t](...a));
122
+ $.set(this, ge.get(this)[t](...a));
123
123
  }), n;
124
124
  } };
125
- async function* Fe(...e) {
125
+ async function* Ve(...e) {
126
126
  let t = this;
127
127
  if (t instanceof IDBCursor || (t = await t.openCursor(...e)), !t)
128
128
  return;
129
- const n = new Proxy(t, He);
130
- for (me.set(n, t), _.set(n, G(t)); t; )
129
+ const n = new Proxy(t, je);
130
+ for (ge.set(n, t), _.set(n, G(t)); t; )
131
131
  yield n, t = await ($.get(n) || t.continue()), $.delete(n);
132
132
  }
133
133
  function ae(e, t) {
134
134
  return t === Symbol.asyncIterator && j(e, [IDBIndex, IDBObjectStore, IDBCursor]) || t === "iterate" && j(e, [IDBIndex, IDBObjectStore]);
135
135
  }
136
- pe((e) => ({ ...e, get: (t, n, a) => ae(t, n) ? Fe : e.get(t, n, a), has: (t, n) => ae(t, n) || e.has(t, n) }));
137
- const je = (e) => {
136
+ pe((e) => ({ ...e, get: (t, n, a) => ae(t, n) ? Ve : e.get(t, n, a), has: (t, n) => ae(t, n) || e.has(t, n) }));
137
+ const Ke = (e) => {
138
138
  if (e instanceof Attr)
139
139
  return null;
140
140
  let t = 1;
141
141
  for (let n = e.previousSibling; n; n = n.previousSibling)
142
142
  n.nodeName === e.nodeName && ++t;
143
143
  return t;
144
- }, ge = (e) => {
144
+ }, me = (e) => {
145
145
  if (e === null)
146
146
  return "";
147
147
  const t = [];
@@ -165,12 +165,12 @@ const je = (e) => {
165
165
  case Node.ELEMENT_NODE:
166
166
  a.name = n.nodeName;
167
167
  }
168
- a.position = je(n);
168
+ a.position = Ke(n);
169
169
  }
170
170
  return "/" + t.reverse().map((n) => n.position !== null ? `/${n.name}[${n.position}]` : `/${n.name}`).join("");
171
- }, S = { capture: !0, passive: !0 }, Ve = ["a", "button", "input", "option", "li", "link"], Ke = ["Escape", "Enter", "Backspace", "F5", "Tab"];
171
+ }, v = { capture: !0, passive: !0 }, Ge = ["a", "button", "input", "option", "li", "link"], We = ["Escape", "Enter", "Backspace", "F5", "Tab"];
172
172
  let A = !1;
173
- const Ge = ["label", "type", "role", "title", "placeholder", "errormessage", "valuetext", "href"], We = "aria-", re = (e) => {
173
+ const $e = ["label", "type", "role", "title", "placeholder", "errormessage", "valuetext", "href"], qe = "aria-", re = (e) => {
174
174
  var a;
175
175
  if (((a = e.tagName) == null ? void 0 : a.toLowerCase()) === "html")
176
176
  return { element: "html" };
@@ -184,24 +184,25 @@ const Ge = ["label", "type", "role", "title", "placeholder", "errormessage", "va
184
184
  for (const r of e.attributes) {
185
185
  let s = r.name;
186
186
  const o = r.value;
187
- s.startsWith(We) && (s = s.substring(5)), Ge.includes(s) && (n[s] = o);
187
+ s.startsWith(qe) && (s = s.substring(5)), $e.includes(s) && (n[s] = o);
188
188
  }
189
189
  return n;
190
- }, $e = (e) => {
190
+ }, ze = (e) => {
191
191
  var a;
192
192
  if (!e)
193
193
  return {};
194
194
  const t = { ...re(e) }, n = e.parentElement;
195
- if (n && Ve.includes((a = n.tagName) == null ? void 0 : a.toLowerCase())) {
195
+ if (n && Ge.includes((a = n.tagName) == null ? void 0 : a.toLowerCase())) {
196
196
  const r = re(n);
197
197
  Object.assign(t, r);
198
198
  }
199
199
  return t;
200
200
  }, we = (e, t) => {
201
- var n;
202
- ze({ x: t.x, y: t.y, type: e, elementAttributes: $e(t.target), windowHeight: window.innerHeight, windowWidth: window.innerWidth, ...t.target instanceof HTMLElement ? { rect: (n = t.target) == null ? void 0 : n.getBoundingClientRect(), xPath: ge(t.target) } : {} });
201
+ var a;
202
+ let n = t.target;
203
+ t.target === ((a = window.document) == null ? void 0 : a.body) && window.Sprig.pointerDownTarget && (n = window.Sprig.pointerDownTarget), Qe({ x: t.x, y: t.y, type: e, elementAttributes: ze(n), windowHeight: window.innerHeight, windowWidth: window.innerWidth, ...n instanceof HTMLElement ? { rect: n == null ? void 0 : n.getBoundingClientRect(), xPath: me(n) } : {} });
203
204
  }, ye = (e) => {
204
- Ke.includes(e.key) && Xe({ key: e.key });
205
+ We.includes(e.key) && Ze({ key: e.key });
205
206
  }, fe = /* @__PURE__ */ ((e, t) => {
206
207
  let n;
207
208
  return (a) => {
@@ -211,13 +212,15 @@ const Ge = ["label", "type", "role", "title", "placeholder", "errormessage", "va
211
212
  if (!(e.target instanceof HTMLElement || e.target instanceof Document))
212
213
  return;
213
214
  let t = e.target;
214
- "scrollTop" in t || (t = t.documentElement), Ye({ xPath: ge(t), x: t.scrollLeft, y: t.scrollTop, elementAttributes: { targetScrollWidth: t.scrollWidth, targetClientWidth: t.clientWidth, targetScrollHeight: t.scrollHeight, targetClientHeight: t.clientHeight } });
215
+ "scrollTop" in t || (t = t.documentElement), et({ xPath: me(t), x: t.scrollLeft, y: t.scrollTop, elementAttributes: { targetScrollWidth: t.scrollWidth, targetClientWidth: t.clientWidth, targetScrollHeight: t.scrollHeight, targetClientHeight: t.clientHeight } });
215
216
  }, 750), Ie = (se = "left_click", (e) => we(se, e));
216
217
  var se;
217
218
  const he = (e) => {
218
219
  e.button === 2 && we("right_click", e);
219
- }, qe = () => {
220
- A || (window.addEventListener("click", Ie, S), window.addEventListener("mousedown", he, S), window.addEventListener("keydown", ye, S), window.addEventListener("scroll", fe, S), A = !0, window.performance.getEntriesByType("navigation").map((e) => e.type).includes("reload") && Je({ url: window.location.href, currentPageTitle: document.title }), window.performance.getEntriesByType("navigation").map((e) => e.type).includes("back_forward") && Qe({ curUrl: window.location.href, fromUrl: document.referrer, currentPageTitle: document.title }));
220
+ }, ve = (e) => {
221
+ window.Sprig && (window.Sprig.pointerDownTarget = e.target);
222
+ }, Je = () => {
223
+ A || (window.addEventListener("click", Ie, v), window.addEventListener("pointerdown", ve, v), window.addEventListener("mousedown", he, v), window.addEventListener("keydown", ye, v), window.addEventListener("scroll", fe, v), A = !0, window.performance.getEntriesByType("navigation").map((e) => e.type).includes("reload") && Xe({ url: window.location.href, currentPageTitle: document.title }), window.performance.getEntriesByType("navigation").map((e) => e.type).includes("back_forward") && Ye({ curUrl: window.location.href, fromUrl: document.referrer, currentPageTitle: document.title }));
221
224
  }, p = { isRecording: !1, scrollEventUuids: {}, stopRecording: () => {
222
225
  } }, y = (() => {
223
226
  const e = f.getItem("sprig.sessionId");
@@ -227,62 +230,62 @@ const he = (e) => {
227
230
  return u.info("GeneratedSessionID", { uuid: t }), t;
228
231
  })(), q = () => {
229
232
  f.setItem("sprig.disableReplayRecording", "disabled");
230
- }, D = () => !!f.getItem("sprig.disableReplayRecording");
233
+ }, b = () => !!f.getItem("sprig.disableReplayRecording");
231
234
  window.addEventListener("beforeunload", () => {
232
235
  u.info("BeforeUnload", { sessionId: y }), f.setItem("sprig.sessionId", y);
233
236
  });
234
- const Y = (e) => e && e.trim().substring(0, 500).replace(/\s\s+/g, " ").replace(/\r?\n|\r/g, " ").substring(0, 250), v = (e, t) => {
237
+ const Y = (e) => e && e.trim().substring(0, 500).replace(/\s\s+/g, " ").replace(/\r?\n|\r/g, " ").substring(0, 250), D = (e, t) => {
235
238
  var n, a;
236
- if (!D() && p.isRecording)
239
+ if (!b() && p.isRecording)
237
240
  try {
238
241
  (a = (n = window.rrwebRecord) == null ? void 0 : n.addCustomEvent) == null || a.call(n, e, t);
239
242
  } catch (r) {
240
243
  L("Error recording custom event", r);
241
244
  }
242
- }, ze = (e) => {
243
- var t;
244
- (t = e == null ? void 0 : e.elementAttributes) != null && t.text && (e.elementAttributes.text = Y(e.elementAttributes.text)), v("Sprig_Click", e);
245
- }, Je = (e) => {
246
- v("Sprig_Refresh", e);
247
245
  }, Qe = (e) => {
248
- e.currentPageTitle && (e.currentPageTitle = Y(e.currentPageTitle)), v("Sprig_BackForward", e);
246
+ var t;
247
+ (t = e == null ? void 0 : e.elementAttributes) != null && t.text && (e.elementAttributes.text = Y(e.elementAttributes.text)), D("Sprig_Click", e);
249
248
  }, Xe = (e) => {
250
- v("Sprig_Keystroke", e);
251
- }, Ye = async (e) => {
249
+ D("Sprig_Refresh", e);
250
+ }, Ye = (e) => {
251
+ e.currentPageTitle && (e.currentPageTitle = Y(e.currentPageTitle)), D("Sprig_BackForward", e);
252
+ }, Ze = (e) => {
253
+ D("Sprig_Keystroke", e);
254
+ }, et = async (e) => {
252
255
  const { x: t, xPath: n, y: a } = e, r = p.scrollEventUuids[n];
253
256
  if (r)
254
- return h(async () => {
257
+ return I(async () => {
255
258
  var d, i, c, w;
256
259
  const s = await l.openDB(), o = await s.get("events", r);
257
260
  if (o != null && o.event) {
258
- const m = JSON.parse(o.event), I = t > ((i = (d = m.data) == null ? void 0 : d.payload) == null ? void 0 : i.x), g = a > ((w = (c = m.data) == null ? void 0 : c.payload) == null ? void 0 : w.y);
259
- if (!I && !g)
261
+ const g = JSON.parse(o.event), h = t > ((i = (d = g.data) == null ? void 0 : d.payload) == null ? void 0 : i.x), m = a > ((w = (c = g.data) == null ? void 0 : c.payload) == null ? void 0 : w.y);
262
+ if (!h && !m)
260
263
  return null;
261
- I && (m.data.payload.x = t), g && (m.data.payload.y = a), m.data.payload.elementAttributes = e.elementAttributes, o.event = JSON.stringify(m), await s.put("events", o);
264
+ h && (g.data.payload.x = t), m && (g.data.payload.y = a), g.data.payload.elementAttributes = e.elementAttributes, o.event = JSON.stringify(g), await s.put("events", o);
262
265
  } else
263
- v("Sprig_Scroll", e);
266
+ D("Sprig_Scroll", e);
264
267
  }, "Error updating scroll event");
265
- v("Sprig_Scroll", e);
266
- }, ve = () => {
268
+ D("Sprig_Scroll", e);
269
+ }, De = () => {
267
270
  p.stopRecording && (p.stopRecording(), p.stopRecording = void 0), p.isRecording = !1, ["cleanupInterval", "inactivityInterval", "pendingCheckInterval"].forEach((e) => {
268
271
  p[e] && (clearInterval(p[e]), p[e] = void 0);
269
- }), A && (window.removeEventListener("click", Ie, S), window.removeEventListener("mousedown", he, S), window.removeEventListener("keydown", ye, S), window.removeEventListener("scroll", fe, S), A = !1);
270
- }, Ze = ["did not allow mutations", "called in an invalid security context"], et = (e, t, { reportError: n = !0, extraInfo: a = {} }) => {
271
- if (!D() && t instanceof Error) {
272
+ }), A && (window.removeEventListener("click", Ie, v), window.removeEventListener("pointerdown", ve, v), window.removeEventListener("mousedown", he, v), window.removeEventListener("keydown", ye, v), window.removeEventListener("scroll", fe, v), A = !1);
273
+ }, tt = ["did not allow mutations", "called in an invalid security context"], nt = (e, t, { reportError: n = !0, extraInfo: a = {} }) => {
274
+ if (!b() && t instanceof Error) {
272
275
  if (q(), t.name === "VersionError")
273
276
  return u.error("VersionErr", { message: e }), l.deleteDB();
274
277
  ((r) => {
275
278
  if (!r)
276
279
  return !0;
277
- for (const s of Ze)
280
+ for (const s of tt)
278
281
  if (r.toLowerCase().includes(s))
279
282
  return !1;
280
283
  return !0;
281
284
  })(t == null ? void 0 : t.message) && (n && window.UserLeap.reportError(e, t, a), l.clearAll());
282
285
  }
283
286
  }, L = (e, t, { reportError: n } = { reportError: !0 }) => {
284
- ve(), u.error("ReplayErr", { code: t.code, name: t.name }), et(e, t, { reportError: n });
285
- }, h = async (e, t) => {
287
+ De(), u.error("ReplayErr", { code: t.code, name: t.name }), nt(e, t, { reportError: n });
288
+ }, I = async (e, t) => {
286
289
  try {
287
290
  await e();
288
291
  } catch (n) {
@@ -366,7 +369,7 @@ const l = new class {
366
369
  return r.getAll(s);
367
370
  }
368
371
  async getPendingCaptures(e = {}) {
369
- return (await (await this.openDB()).getAllFromIndex("pendingCaptures", "sessionId", y)).filter((n) => !e.beforePresent || n.targetTimestamp < Date.now()).filter((n) => !e.isHeatmap || (n.captureParams.isHeatmap ?? !1));
372
+ return (await (await this.openDB()).getAllFromIndex("pendingCaptures", "sessionId", y)).filter((n) => !e.beforePresent || n.targetTimestamp < Date.now()).filter((n) => !e.isBeforeType || n.captureParams.replayParams.replayDurationType === "before").filter((n) => !e.isHeatmap || (n.captureParams.isHeatmap ?? !1));
370
373
  }
371
374
  async markPendingCaptureToCanUpload(e) {
372
375
  const t = (await this.openDB()).transaction("pendingCaptures", "readwrite"), n = t.store.index("sessionId");
@@ -386,7 +389,7 @@ const l = new class {
386
389
  }
387
390
  await n.done;
388
391
  }
389
- }(), De = async (e, t) => {
392
+ }(), be = async (e, t) => {
390
393
  const n = performance.now();
391
394
  let a;
392
395
  try {
@@ -397,7 +400,7 @@ const l = new class {
397
400
  s || (s = ce(t)), s.report(r / 1e3);
398
401
  }
399
402
  return a;
400
- }, be = (e, t) => {
403
+ }, Se = (e, t) => {
401
404
  const n = performance.now();
402
405
  try {
403
406
  e();
@@ -407,8 +410,8 @@ const l = new class {
407
410
  r || (r = ce(t)), r.report(a / 1e3);
408
411
  }
409
412
  };
410
- let Se = 5e3, z = 6e4, J = 0, C, Q = !1, X = [];
411
- const tt = (e) => {
413
+ let ke = 5e3, z = 6e4, J = 0, C, Q = !1, X = [];
414
+ const at = (e) => {
412
415
  var t, n, a, r;
413
416
  if ((t = e.event) != null && t.includes("Sprig_Scroll")) {
414
417
  const s = (r = (a = (n = JSON.parse(e.event)) == null ? void 0 : n.data) == null ? void 0 : a.payload) == null ? void 0 : r.xPath;
@@ -416,39 +419,41 @@ const tt = (e) => {
416
419
  return;
417
420
  p.scrollEventUuids[s] = e.uuid;
418
421
  }
419
- X.push(e), Q || nt();
420
- }, nt = () => {
422
+ X.push(e), Q || rt();
423
+ }, rt = () => {
421
424
  Q = !0, setTimeout(async () => {
422
- if (D())
425
+ if (b())
423
426
  return;
424
427
  const e = X;
425
- X = [], Q = !1, be(async () => {
428
+ X = [], Q = !1, Se(async () => {
426
429
  await (async (t) => {
427
430
  const n = t.map((a) => ({ ...a, sessionId: a.sessionId ?? y }));
428
431
  if (n.length !== 0)
429
- return h(() => l.bulkAdd("events", n), "Error storing replay events");
432
+ return I(() => l.bulkAdd("events", n), "Error storing replay events");
430
433
  })(e);
431
434
  }, "sdk_replay_add_event_batch_seconds");
432
435
  }, 500);
433
- }, at = (e, t, n) => {
436
+ }, st = (e, t, n) => {
434
437
  p.cleanupInterval = window.setInterval(() => {
435
438
  const a = Date.now();
436
- De(() => h(async () => {
437
- D() || await Promise.all([l.deleteRowsBefore("events", a - 1e3 * e, (r) => r.expiredAt === void 0 || r.expiredAt < a - 1e3 * e), l.deleteRowsBefore("chunkUploads", a - 1e3 * t), l.deleteRowsBefore("pendingCaptures", a - 1e3 * n, (r) => !r.canUpload)]);
439
+ be(() => I(async () => {
440
+ b() || await Promise.all([l.deleteRowsBefore("events", a - 1e3 * e, (r) => r.expiredAt === void 0 || r.expiredAt < a - 1e3 * e), l.deleteRowsBefore("chunkUploads", a - 1e3 * t), l.deleteRowsBefore("pendingCaptures", a - 1e3 * n, (r) => !r.canUpload)]);
438
441
  }, "Error deleting table rows"), "sdk_replay_cleanup_seconds"), u.debug("CleanupComplete");
439
442
  }, 3e4);
440
- }, rt = () => {
443
+ }, ot = () => {
441
444
  p.pendingCheckInterval = window.setInterval(async () => {
442
- h(async () => {
443
- const e = parseInt(C ?? "0");
444
- if (e === 0)
445
- return;
446
- const t = await l.getPendingCaptures({ beforePresent: !0 }), n = await l.openDB();
447
- await Promise.all(t.map(async (a) => (await n.delete("pendingCaptures", a.uuid), Ee(a.captureParams, a.canUpload)))), C = (e - t.length).toString(), f.setItem("sprig.pendingCount", C);
445
+ I(async () => {
446
+ await Ce();
448
447
  }, "Error initiating pending captures");
449
448
  }, 5e3);
450
- }, st = async (e, t, n, a, r) => {
451
- const s = Math.min(e + r, n), o = await De(() => l.getEventsBetween(e, s), "sdk_replay_get_events_between_seconds");
449
+ }, Ce = async (e = !1) => {
450
+ const t = parseInt(C ?? "0");
451
+ if (t === 0)
452
+ return;
453
+ const n = await l.getPendingCaptures({ beforePresent: !0, isBeforeType: e }), a = await l.openDB();
454
+ await Promise.all(n.map(async (r) => (await a.delete("pendingCaptures", r.uuid), Re(r.captureParams, r.canUpload)))), C = (t - n.length).toString(), f.setItem("sprig.pendingCount", C);
455
+ }, it = async (e, t, n, a, r) => {
456
+ const s = Math.min(e + r, n), o = await be(() => l.getEventsBetween(e, s), "sdk_replay_get_events_between_seconds");
452
457
  if (!(o != null && o.length))
453
458
  return u.debug("NoEventsFound"), { validStartFound: a, events: [] };
454
459
  if (!a) {
@@ -462,7 +467,7 @@ const tt = (e) => {
462
467
  }), d < 0 ? (u.debug("ValidStartNotFound"), { validStartFound: a, events: [] }) : { validStartFound: !0, events: o == null ? void 0 : o.slice(d) };
463
468
  }
464
469
  return { validStartFound: a, events: o };
465
- }, ke = (e) => Promise.all(e.map(async (t) => {
470
+ }, Ee = (e) => Promise.all(e.map(async (t) => {
466
471
  const n = await (async (a) => ue.execute(async () => {
467
472
  var o;
468
473
  u.info("UploadChunkStart", { chunkIndex: a.chunkIndex, surveyId: a.surveyId });
@@ -474,7 +479,7 @@ const tt = (e) => {
474
479
  return s;
475
480
  }))(t);
476
481
  return await l.updatePartial("chunkUploads", t.uuid, { data: null, etag: n, status: "UploadComplete" }), t.uploadId;
477
- })), Ce = async (e) => {
482
+ })), Pe = async (e) => {
478
483
  const t = await l.getChunkUploadsByStatus({ status: "UploadComplete", uploadId: e });
479
484
  if (!(t != null && t.length))
480
485
  return void u.info("NoChunksForUpload", { uploadId: e });
@@ -482,118 +487,116 @@ const tt = (e) => {
482
487
  n.sort((s, o) => s.chunkIndex - o.chunkIndex);
483
488
  const a = n.map((s) => ({ ETag: s.etag, PartNumber: s.chunkIndex })).filter((s) => s.ETag !== null), r = n[0];
484
489
  await le({ apiUrl: r.apiUrl, surveyId: r.surveyId, uploadId: e, responseGroupUuid: r.responseGroupId, etags: a, headers: r.completeUploadHeaders, replayDuration: r.replayDuration }), await l.deleteChunkUploads("UploadComplete", e);
485
- }, ot = () => {
486
- h(async () => {
490
+ }, dt = () => {
491
+ I(async () => {
487
492
  const e = await l.getChunkUploadsByStatus({ sessionId: y, status: "ReadyForUpload" });
488
493
  if (!(e != null && e.length))
489
494
  return;
490
- const t = await ke(e);
495
+ const t = await Ee(e);
491
496
  t != null && t.length && await Promise.all(t.map((n) => {
492
497
  if (n)
493
- return Ce(n);
498
+ return Pe(n);
494
499
  }));
495
500
  }, "Error uploading unfinished chunks");
496
- }, it = async (e, t) => {
501
+ }, ct = async (e, t) => {
497
502
  const n = t ?? Date.now();
498
503
  return (async (a, r) => {
499
504
  const s = new TextEncoder();
500
505
  let o = null;
501
506
  const d = new CompressionStream("gzip"), i = d.writable.getWriter();
502
- let c = !1, w = !1, [m, I] = [0, 0], g = [];
507
+ let c = !1, w = !1, [g, h] = [0, 0], m = [];
503
508
  for (let E = a - 35e3; E < r; E += z) {
504
- if ({ validStartFound: w, events: g } = await st(E, a, r, w, z), !(g != null && g.length)) {
509
+ if ({ validStartFound: w, events: m } = await it(E, a, r, w, z), !(m != null && m.length)) {
505
510
  u.debug("NoEventsFound");
506
511
  continue;
507
512
  }
508
- m === 0 && (m = g[0].timestamp), I = g[g.length - 1].timestamp;
509
- const x = g.map((R) => R.event);
510
- x.push(`{"timestamp":${r}}`);
511
- const B = `${c ? "," : "["}${x}`, U = s.encode(B);
512
- be(() => {
513
+ g === 0 && (g = m[0].timestamp), h = m[m.length - 1].timestamp;
514
+ const B = m.map((P) => P.event);
515
+ B.push(`{"timestamp":${r}}`);
516
+ const x = `${c ? "," : "["}${B}`, U = s.encode(x);
517
+ Se(() => {
513
518
  i.write(U);
514
519
  }, "sdk_replay_compression_seconds"), c = !0;
515
520
  }
516
- if (I - m < Se)
521
+ if (h - g < ke)
517
522
  return u.debug("ReplayTooShort"), null;
518
- const b = s.encode("]");
519
- return i.write(b), i.close(), o = new Uint8Array(await new Response(d.readable).arrayBuffer()), o;
523
+ const S = s.encode("]");
524
+ return i.write(S), i.close(), o = new Uint8Array(await new Response(d.readable).arrayBuffer()), o;
520
525
  })(n - e, n);
521
526
  }, oe = async (e) => {
522
- const { surveyId: t, responseGroupId: n, visitorId: a, apiUrl: r, completeUploadHeaders: s, replayParams: o, triggerTimestamp: d } = e, i = await it(1e3 * o.replayDurationSeconds, d);
527
+ const { surveyId: t, responseGroupId: n, visitorId: a, apiUrl: r, completeUploadHeaders: s, replayParams: o, triggerTimestamp: d } = e, i = await ct(1e3 * o.replayDurationSeconds, d);
523
528
  if (!(i != null && i.length))
524
529
  return void u.info("FileDataEmpty", { surveyId: t });
525
- const c = ((m, I, g) => {
526
- const b = m.length, E = 1024 * I * 1024, x = Math.ceil(b / g), B = Math.max(E, x), U = [];
527
- let R = 0;
528
- for (; R < b; )
529
- U.push(m.slice(R, R + B)), R += B;
530
+ const c = ((g, h, m) => {
531
+ const S = g.length, E = 1024 * h * 1024, B = Math.ceil(S / m), x = Math.max(E, B), U = [];
532
+ let P = 0;
533
+ for (; P < S; )
534
+ U.push(g.slice(P, P + x)), P += x;
530
535
  return U;
531
- })(i, o.minimumChunkSizeMb, o.signedUrls.length), w = await Promise.all(c.map(async (m, I) => {
532
- const g = N(), b = { apiUrl: r, chunkIndex: I + 1, completeUploadHeaders: s, etag: null, responseGroupId: n, status: "ReadyForUpload", surveyId: t, timestamp: d, totalChunks: c.length, data: m, uploadId: o.uploadId, uploadUrl: o.signedUrls[I].url, uuid: g, visitorId: a };
533
- return await (await l.openDB()).add("chunkUploads", { ...b, sessionId: b.sessionId ?? y }), b;
536
+ })(i, o.minimumChunkSizeMb, o.signedUrls.length), w = await Promise.all(c.map(async (g, h) => {
537
+ const m = N(), S = { apiUrl: r, chunkIndex: h + 1, completeUploadHeaders: s, etag: null, responseGroupId: n, status: "ReadyForUpload", surveyId: t, timestamp: d, totalChunks: c.length, data: g, uploadId: o.uploadId, uploadUrl: o.signedUrls[h].url, uuid: m, visitorId: a };
538
+ return await (await l.openDB()).add("chunkUploads", { ...S, sessionId: S.sessionId ?? y }), S;
534
539
  }));
535
- await (async (m, I) => {
536
- await ke(I), await Promise.all(m.map((g) => Ce(g)));
540
+ await (async (g, h) => {
541
+ await Ee(h), await Promise.all(g.map((m) => Pe(m)));
537
542
  })([o.uploadId], w);
538
- }, Ee = async (e, t) => {
539
- if (D())
543
+ }, Re = async (e, t) => {
544
+ if (b())
540
545
  return u.debug("ReplayDisabled-ScheduleOrCapture");
541
546
  const { isHeatmap: n, isStandalone: a, replayParams: r, triggerTimestamp: s, responseGroupId: o } = e, d = async () => {
542
- setTimeout(() => T.removeListener(O.QuestionAnswered, d), 0), h(async () => {
547
+ setTimeout(() => T.removeListener(O.QuestionAnswered, d), 0), I(async () => {
543
548
  r.replayDurationType === "before" ? await oe(e) : await l.markPendingCaptureToCanUpload(o);
544
549
  }, "Error in schedule/capture callback");
545
550
  };
546
- h(async () => {
551
+ I(async () => {
547
552
  if (r.replayDurationType === "after" || r.replayDurationType === "beforeAndAfter")
548
- return !a && !n && T.on(O.QuestionAnswered, d), void await Pe(e);
553
+ return !a && !n && T.on(O.QuestionAnswered, d), void await xe(e);
549
554
  if (a || n || t)
550
- await oe(e), n && dt();
555
+ await oe(e), n && ut();
551
556
  else {
552
557
  const i = 35 + r.replayDurationSeconds, c = s - 1e3 * i, w = s;
553
558
  await l.updateEventsExpiredAt(c, w, r.expirationTimeLimitMinutes), T.on(O.QuestionAnswered, d);
554
559
  }
555
560
  }, "Error in scheduling/capturing replay");
556
- }, dt = async () => {
557
- parseInt(C ?? "0") || f.removeItem("sprig.isCapturingHeatmap"), f.getItem("sprig.teardownAfterCapture") && (ve(), Re(), f.removeItem("sprig.teardownAfterCapture"));
558
- }, Re = async () => D() ? u.debug("ReplayDisabled-ClearData") : Promise.all([l.deleteBySessionId("events", y), l.deleteBySessionId("pendingCaptures", y)]).catch((e) => {
561
+ }, ut = async () => {
562
+ parseInt(C ?? "0") || f.removeItem("sprig.isCapturingHeatmap"), f.getItem("sprig.teardownAfterCapture") && (De(), Be(), f.removeItem("sprig.teardownAfterCapture"));
563
+ }, Be = async () => b() ? u.debug("ReplayDisabled-ClearData") : Promise.all([l.deleteBySessionId("events", y), l.deleteBySessionId("pendingCaptures", y)]).catch((e) => {
559
564
  L("Error clearing user replay data", e);
560
- }), Pe = async (e) => {
561
- if (D())
565
+ }), xe = async (e) => {
566
+ if (b())
562
567
  return;
563
568
  const { isHeatmap: t, surveyId: n } = e, a = await l.getPendingCaptures(), r = a == null ? void 0 : a.filter((i) => i.captureParams.surveyId === n);
564
569
  if (r != null && r.length)
565
570
  return void u.info("PendingCaptureExists", { surveyId: n });
566
- t && (p.isRecording && h(() => {
571
+ t && (p.isRecording && I(() => {
567
572
  var i, c;
568
573
  return (c = (i = window.rrwebRecord) == null ? void 0 : i.takeFullSnapshot) == null ? void 0 : c.call(i, !0);
569
574
  }, "Error recording full snapshot"), f.setItem("sprig.isCapturingHeatmap", "true"), J = Date.now(), p.inactivityInterval || (p.inactivityInterval = window.setInterval(() => {
570
575
  var i;
571
- i = J, Date.now() - i >= 3e4 && h(() => l.markPendingHeatmapsReady(), "Error in heatmap inactivity");
576
+ i = J, Date.now() - i >= 3e4 && I(() => l.markPendingHeatmapsReady(), "Error in heatmap inactivity");
572
577
  }, 1e3)));
573
578
  const s = { ...e, replayParams: { ...e.replayParams } };
574
579
  e.replayParams.replayDurationType === "beforeAndAfter" && (s.replayParams.replayDurationSeconds *= 2), s.replayParams.replayDurationType = "before";
575
580
  const o = e.triggerTimestamp + 1e3 * e.replayParams.replayDurationSeconds;
576
581
  s.triggerTimestamp = o, C = (parseInt(C ?? "0") + 1).toString(), f.setItem("sprig.pendingCount", C), await (await l.openDB()).add("pendingCaptures", { canUpload: !1, captureParams: s, sessionId: y, targetTimestamp: o, timestamp: Date.now(), uuid: N() });
577
582
  };
578
- _e(Object.freeze(Object.defineProperty({ __proto__: null, RecordEvent: (e) => {
579
- v("Sprig_TrackEvent", e);
583
+ Ne(Object.freeze(Object.defineProperty({ __proto__: null, RecordEvent: (e) => {
584
+ D("Sprig_TrackEvent", e);
580
585
  }, RecordPageView: (e) => {
581
- e.description && (e.description = Y(e.description)), v("Sprig_PageView", e);
586
+ e.description && (e.description = Y(e.description)), D("Sprig_PageView", e);
582
587
  }, RecordSurveyShown: (e) => {
583
- v("Sprig_ShowSurvey", e);
588
+ D("Sprig_ShowSurvey", e);
584
589
  }, _completeSessionReplay: async ({ surveyId: e, responseGroupUuid: t, eventDigest: n, headers: a }) => {
585
590
  if (!e || !t)
586
591
  return !1;
587
592
  const r = window.UserLeap._API_URL, s = await le({ surveyId: e, responseGroupUuid: t, eventDigest: n, apiUrl: r, headers: a }, !0);
588
593
  return !(s != null && s.error);
589
- }, checkPendingHeatmapsUrl: () => D() ? u.debug("ReplayDisabled-PendingHeatmaps") : h(async () => {
590
- const e = (await l.getPendingCaptures({ isHeatmap: !0 })).map((n) => ({ eventId: n.captureParams.eventId, uuid: n.uuid })), t = [];
591
- e.forEach(({ eventId: n, uuid: a }) => {
592
- Ue(n) || t.push(a);
593
- }), t.length && await l.markPendingHeatmapsReady(t);
594
- }, "Error marking pending heatmaps ready"), clearUserReplayData: Re, disableRecording: L, initializeReplay: async ({ maxReplayDurationSeconds: e, maxInflightRequests: t = 2, replaySettings: n, teardownAfter: a = !1 }) => {
594
+ }, checkPendingHeatmapsUrl: () => b() ? u.debug("ReplayDisabled-PendingHeatmaps") : I(async () => {
595
+ const e = (await l.getPendingCaptures({ isHeatmap: !0 })).map((t) => ({ eventId: t.captureParams.eventId, uuid: t.uuid })).filter(({ eventId: t }) => !_e(t)).map(({ uuid: t }) => t);
596
+ u.info("PendingHeatmapsToComplete", { count: e.length }), e.length && (await l.markPendingHeatmapsReady(e), u.info("MarkedPendingHeatmapsReady"));
597
+ }, "Error marking pending heatmaps ready"), clearUserReplayData: Be, disableRecording: L, initializeReplay: async ({ maxReplayDurationSeconds: e, maxInflightRequests: t = 2, replaySettings: n, teardownAfter: a = !1 }) => {
595
598
  if (C = f.getItem("sprig.pendingCount"), !p.isRecording) {
596
- if (a && f.setItem("sprig.teardownAfterCapture", "true"), D())
599
+ if (a && f.setItem("sprig.teardownAfterCapture", "true"), b())
597
600
  return u.debug("ReplayDisabled");
598
601
  if (await (async () => {
599
602
  var r;
@@ -615,11 +618,13 @@ _e(Object.freeze(Object.defineProperty({ __proto__: null, RecordEvent: (e) => {
615
618
  } catch (r) {
616
619
  return u.error("ReplayOpenErr", { name: r.name }), r.name === "VersionError" && l.deleteDB(), q();
617
620
  }
618
- if (!e)
621
+ if (I(async () => {
622
+ await Ce(!0);
623
+ }, "Error uploading ready pending captures"), !e)
619
624
  return u.debug("MissingDuration");
620
- u.debug("ReplayInit"), await h(async () => {
625
+ u.debug("ReplayInit"), await I(async () => {
621
626
  var r;
622
- if (n != null && n.minDuration && (Se = n.minDuration), n != null && n.batchDuration && (z = n.batchDuration), r = t, ue.setLimit(r), ot(), at(e + 35, 1800, e + 35), rt(), !window.rrwebRecord) {
627
+ if (n != null && n.minDuration && (ke = n.minDuration), n != null && n.batchDuration && (z = n.batchDuration), r = t, ue.setLimit(r), dt(), st(e + 35, 1800, e + 35), ot(), !window.rrwebRecord) {
623
628
  const { record: i } = await import(
624
629
  /* webpackIgnore: true */
625
630
  /* @vite-ignore */
@@ -632,20 +637,20 @@ _e(Object.freeze(Object.defineProperty({ __proto__: null, RecordEvent: (e) => {
632
637
  return u.error("RecordScriptFailed");
633
638
  let o = !0, d = 0;
634
639
  p.stopRecording = s({ checkoutEveryNms: 3e4, sampling: { input: "last", scroll: 250, media: 800 }, emit: (i, c) => {
635
- if (i.type === P.Custom && (J = Date.now()), D())
640
+ if (i.type === R.Custom && (J = Date.now()), b())
636
641
  return;
637
- if (c && i.type === P.Meta)
642
+ if (c && i.type === R.Meta)
638
643
  d = performance.now();
639
- else if (c && d && i.type === P.FullSnapshot) {
640
- const m = performance.now() - d;
641
- Te("sdk_replay_snapshot_seconds", m / 1e3);
644
+ else if (c && d && i.type === R.FullSnapshot) {
645
+ const g = performance.now() - d;
646
+ Ae("sdk_replay_snapshot_seconds", g / 1e3);
642
647
  }
643
- const w = o || !!c && i.type === P.Meta;
644
- o = !1, tt({ uuid: N(), event: JSON.stringify(i), isValidStart: w, timestamp: Date.now() });
648
+ const w = o || !!c && i.type === R.Meta;
649
+ o = !1, at({ uuid: N(), event: JSON.stringify(i), isValidStart: w, timestamp: Date.now() });
645
650
  }, ...n }), p.isRecording = !!p.stopRecording, p.isRecording && (T.on("survey.complete", (i) => {
646
651
  var c;
647
- c = { id: i, userAgent: window.navigator.userAgent }, v("Sprig_SubmitSurvey", c);
648
- }), qe());
652
+ c = { id: i, userAgent: window.navigator.userAgent }, D("Sprig_SubmitSurvey", c);
653
+ }), Je());
649
654
  }, "Error initializing replay");
650
655
  }
651
- }, isReplayRecording: () => p.isRecording, scheduleCapture: Pe, scheduleOrCaptureReplay: Ee, tryReplayAction: h }, Symbol.toStringTag, { value: "Module" })));
656
+ }, isReplayRecording: () => p.isRecording, scheduleCapture: xe, scheduleOrCaptureReplay: Re, tryReplayAction: I }, Symbol.toStringTag, { value: "Module" })));