@sprig-technologies/sprig-browser 2.32.11 → 2.33.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/replay.js CHANGED
@@ -1,147 +1,147 @@
1
- var Te = Object.defineProperty;
2
- var _e = (e, t, n) => t in e ? Te(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var M = (e, t, n) => (_e(e, typeof t != "symbol" ? t + "" : t, n), n);
4
- import { b as u, s as de, a as f, v as N, c as Ae, P as ce, r as ue, d as Ne, e as T, S as O, f as Le } from "./metricsReporter-DNUK7N1y.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
- const le = new class {
7
- constructor(e) {
8
- M(this, "awaitingResolvers", []);
9
- M(this, "activeCount", 0);
10
- this.capacity = e;
11
- }
12
- async acquire() {
13
- if (!(this.activeCount < this.capacity))
14
- return new Promise((e) => {
15
- this.awaitingResolvers.push(e);
16
- });
17
- this.activeCount++;
18
- }
19
- release() {
20
- const e = this.awaitingResolvers.shift();
21
- e && this.activeCount <= this.capacity ? e() : this.activeCount--;
22
- }
23
- async execute(e) {
24
- try {
25
- return await this.acquire(), await e();
26
- } finally {
27
- this.release();
28
- }
29
- }
30
- setLimit(e) {
31
- this.capacity = e;
32
- }
33
- }(2), pe = async ({ apiUrl: e, surveyId: t, uploadId: n, etags: a, headers: r, responseGroupUuid: s, replayDuration: o, eventDigest: d }, i = !1) => {
34
- var w;
35
- if (!i && !n && !a)
36
- return void u.error("UploadErr", { isMobile: i, uploadId: n, etags: a });
37
- u.info("MarkUploadComplete", { surveyId: t });
38
- const c = await de(`${e}/sdk/1/completeSessionReplay`, { method: "POST", body: JSON.stringify({ etags: a, uploadId: n, responseGroupUuid: s, surveyId: t, replayDuration: o, eventDigest: d, userAgent: (w = window == null ? void 0 : window.navigator) == null ? void 0 : w.userAgent }), headers: r, shouldRetryRequest: !0 });
39
- return u.info("MarkUploadDone", { surveyId: t }), c;
40
- }, j = (e, t) => t.some((n) => e instanceof n);
41
- let ee, te;
42
- const V = /* @__PURE__ */ new WeakMap(), H = /* @__PURE__ */ new WeakMap(), _ = /* @__PURE__ */ new WeakMap();
43
- let K = { get(e, t, n) {
1
+ var tt = Object.defineProperty;
2
+ var nt = (e, t, n) => t in e ? tt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var z = (e, t, n) => (nt(e, typeof t != "symbol" ? t + "" : t, n), n);
4
+ import { b as d, s as K, a as f, v as W, c as at, g as rt, P as be, r as Ee, d as ot, e as F, S as q, f as st } from "./metricsReporter-Dsn4xUH7.js";
5
+ var U = ((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))(U || {}), E = ((e) => (e[e.Mutation = 0] = "Mutation", e[e.MouseMove = 1] = "MouseMove", e[e.MouseInteraction = 2] = "MouseInteraction", e[e.Scroll = 3] = "Scroll", e[e.ViewportResize = 4] = "ViewportResize", e[e.Input = 5] = "Input", e[e.TouchMove = 6] = "TouchMove", e[e.MediaInteraction = 7] = "MediaInteraction", e[e.StyleSheetRule = 8] = "StyleSheetRule", e[e.CanvasMutation = 9] = "CanvasMutation", e[e.Font = 10] = "Font", e[e.Log = 11] = "Log", e[e.Drag = 12] = "Drag", e[e.StyleDeclaration = 13] = "StyleDeclaration", e[e.Selection = 14] = "Selection", e[e.AdoptedStyleSheet = 15] = "AdoptedStyleSheet", e[e.CustomElement = 16] = "CustomElement", e))(E || {});
6
+ const ee = (e, t) => t.some((n) => e instanceof n);
7
+ let we, ye;
8
+ const te = /* @__PURE__ */ new WeakMap(), Q = /* @__PURE__ */ new WeakMap(), V = /* @__PURE__ */ new WeakMap();
9
+ let ne = { get(e, t, n) {
44
10
  if (e instanceof IDBTransaction) {
45
11
  if (t === "done")
46
- return V.get(e);
12
+ return te.get(e);
47
13
  if (t === "store")
48
14
  return n.objectStoreNames[1] ? void 0 : n.objectStore(n.objectStoreNames[0]);
49
15
  }
50
- return C(e[t]);
16
+ return x(e[t]);
51
17
  }, set: (e, t, n) => (e[t] = n, !0), has: (e, t) => e instanceof IDBTransaction && (t === "done" || t === "store") || t in e };
52
- function ge(e) {
53
- K = e(K);
18
+ function Ce(e) {
19
+ ne = e(ne);
54
20
  }
55
- function Me(e) {
56
- return (te || (te = [IDBCursor.prototype.advance, IDBCursor.prototype.continue, IDBCursor.prototype.continuePrimaryKey])).includes(e) ? function(...t) {
57
- return e.apply(G(this), t), C(this.request);
21
+ function it(e) {
22
+ return (ye || (ye = [IDBCursor.prototype.advance, IDBCursor.prototype.continue, IDBCursor.prototype.continuePrimaryKey])).includes(e) ? function(...t) {
23
+ return e.apply(ae(this), t), x(this.request);
58
24
  } : function(...t) {
59
- return C(e.apply(G(this), t));
25
+ return x(e.apply(ae(this), t));
60
26
  };
61
27
  }
62
- function Oe(e) {
63
- return typeof e == "function" ? Me(e) : (e instanceof IDBTransaction && function(t) {
64
- if (V.has(t))
28
+ function dt(e) {
29
+ return typeof e == "function" ? it(e) : (e instanceof IDBTransaction && function(t) {
30
+ if (te.has(t))
65
31
  return;
66
32
  const n = new Promise((a, r) => {
67
- const s = () => {
33
+ const o = () => {
68
34
  r(t.error || new DOMException("AbortError", "AbortError"));
69
35
  };
70
36
  t.oncomplete = () => {
71
37
  a();
72
- }, t.onerror = s, t.onabort = s;
38
+ }, t.onerror = o, t.onabort = o;
73
39
  });
74
- V.set(t, n);
75
- }(e), j(e, ee || (ee = [IDBDatabase, IDBObjectStore, IDBIndex, IDBCursor, IDBTransaction])) ? new Proxy(e, K) : e);
40
+ te.set(t, n);
41
+ }(e), ee(e, we || (we = [IDBDatabase, IDBObjectStore, IDBIndex, IDBCursor, IDBTransaction])) ? new Proxy(e, ne) : e);
76
42
  }
77
- function C(e) {
43
+ function x(e) {
78
44
  if (e instanceof IDBRequest)
79
45
  return function(n) {
80
- const a = new Promise((r, s) => {
46
+ const a = new Promise((r, o) => {
81
47
  n.onsuccess = () => {
82
- r(C(n.result));
48
+ r(x(n.result));
83
49
  }, n.onerror = () => {
84
- s(n.error);
50
+ o(n.error);
85
51
  };
86
52
  });
87
- return _.set(a, n), a;
53
+ return V.set(a, n), a;
88
54
  }(e);
89
- if (H.has(e))
90
- return H.get(e);
91
- const t = Oe(e);
92
- return t !== e && (H.set(e, t), _.set(t, e)), t;
55
+ if (Q.has(e))
56
+ return Q.get(e);
57
+ const t = dt(e);
58
+ return t !== e && (Q.set(e, t), V.set(t, e)), t;
93
59
  }
94
- const G = (e) => _.get(e);
95
- function W(e, { blocked: t } = {}) {
60
+ const ae = (e) => V.get(e);
61
+ function re(e, { blocked: t } = {}) {
96
62
  const n = indexedDB.deleteDatabase(e);
97
- return t && (n.onblocked = (a) => t(a.oldVersion, a)), C(n).then(() => {
63
+ return t && (n.onblocked = (a) => t(a.oldVersion, a)), x(n).then(() => {
98
64
  });
99
65
  }
100
- const He = ["get", "getKey", "getAll", "getAllKeys", "count"], Fe = ["put", "add", "delete", "clear"], F = /* @__PURE__ */ new Map();
101
- function ne(e, t) {
66
+ const ct = ["get", "getKey", "getAll", "getAllKeys", "count"], lt = ["put", "add", "delete", "clear"], X = /* @__PURE__ */ new Map();
67
+ function fe(e, t) {
102
68
  if (!(e instanceof IDBDatabase) || t in e || typeof t != "string")
103
69
  return;
104
- if (F.get(t))
105
- return F.get(t);
106
- const n = t.replace(/FromIndex$/, ""), a = t !== n, r = Fe.includes(n);
107
- if (!(n in (a ? IDBIndex : IDBObjectStore).prototype) || !r && !He.includes(n))
70
+ if (X.get(t))
71
+ return X.get(t);
72
+ const n = t.replace(/FromIndex$/, ""), a = t !== n, r = lt.includes(n);
73
+ if (!(n in (a ? IDBIndex : IDBObjectStore).prototype) || !r && !ct.includes(n))
108
74
  return;
109
- const s = async function(o, ...d) {
110
- const i = this.transaction(o, r ? "readwrite" : "readonly");
111
- let c = i.store;
112
- return a && (c = c.index(d.shift())), (await Promise.all([c[n](...d), r && i.done]))[0];
75
+ const o = async function(s, ...c) {
76
+ const i = this.transaction(s, r ? "readwrite" : "readonly");
77
+ let l = i.store;
78
+ return a && (l = l.index(c.shift())), (await Promise.all([l[n](...c), r && i.done]))[0];
113
79
  };
114
- return F.set(t, s), s;
80
+ return X.set(t, o), o;
115
81
  }
116
- ge((e) => ({ ...e, get: (t, n, a) => ne(t, n) || e.get(t, n, a), has: (t, n) => !!ne(t, n) || e.has(t, n) }));
117
- const je = ["continue", "continuePrimaryKey", "advance"], ae = {}, $ = /* @__PURE__ */ new WeakMap(), me = /* @__PURE__ */ new WeakMap(), Ve = { get(e, t) {
118
- if (!je.includes(t))
82
+ Ce((e) => ({ ...e, get: (t, n, a) => fe(t, n) || e.get(t, n, a), has: (t, n) => !!fe(t, n) || e.has(t, n) }));
83
+ const ut = ["continue", "continuePrimaryKey", "advance"], he = {}, oe = /* @__PURE__ */ new WeakMap(), ke = /* @__PURE__ */ new WeakMap(), pt = { get(e, t) {
84
+ if (!ut.includes(t))
119
85
  return e[t];
120
- let n = ae[t];
121
- return n || (n = ae[t] = function(...a) {
122
- $.set(this, me.get(this)[t](...a));
86
+ let n = he[t];
87
+ return n || (n = he[t] = function(...a) {
88
+ oe.set(this, ke.get(this)[t](...a));
123
89
  }), n;
124
90
  } };
125
- async function* Ke(...e) {
91
+ async function* gt(...e) {
126
92
  let t = this;
127
93
  if (t instanceof IDBCursor || (t = await t.openCursor(...e)), !t)
128
94
  return;
129
- const n = new Proxy(t, Ve);
130
- for (me.set(n, t), _.set(n, G(t)); t; )
131
- yield n, t = await ($.get(n) || t.continue()), $.delete(n);
95
+ const n = new Proxy(t, pt);
96
+ for (ke.set(n, t), V.set(n, ae(t)); t; )
97
+ yield n, t = await (oe.get(n) || t.continue()), oe.delete(n);
132
98
  }
133
- function re(e, t) {
134
- return t === Symbol.asyncIterator && j(e, [IDBIndex, IDBObjectStore, IDBCursor]) || t === "iterate" && j(e, [IDBIndex, IDBObjectStore]);
99
+ function Ie(e, t) {
100
+ return t === Symbol.asyncIterator && ee(e, [IDBIndex, IDBObjectStore, IDBCursor]) || t === "iterate" && ee(e, [IDBIndex, IDBObjectStore]);
135
101
  }
136
- ge((e) => ({ ...e, get: (t, n, a) => re(t, n) ? Ke : e.get(t, n, a), has: (t, n) => re(t, n) || e.has(t, n) }));
137
- const Ge = (e) => {
102
+ Ce((e) => ({ ...e, get: (t, n, a) => Ie(t, n) ? gt : e.get(t, n, a), has: (t, n) => Ie(t, n) || e.has(t, n) }));
103
+ const Ue = new class {
104
+ constructor(e) {
105
+ z(this, "awaitingResolvers", []);
106
+ z(this, "activeCount", 0);
107
+ this.capacity = e;
108
+ }
109
+ async acquire() {
110
+ if (!(this.activeCount < this.capacity))
111
+ return new Promise((e) => {
112
+ this.awaitingResolvers.push(e);
113
+ });
114
+ this.activeCount++;
115
+ }
116
+ release() {
117
+ const e = this.awaitingResolvers.shift();
118
+ e && this.activeCount <= this.capacity ? e() : this.activeCount--;
119
+ }
120
+ async execute(e) {
121
+ try {
122
+ return await this.acquire(), await e();
123
+ } finally {
124
+ this.release();
125
+ }
126
+ }
127
+ setLimit(e) {
128
+ this.capacity = e;
129
+ }
130
+ }(2), xe = async ({ apiUrl: e, surveyId: t, uploadId: n, etags: a, headers: r, responseGroupUuid: o, replayDuration: s, eventDigest: c }, i = !1) => {
131
+ var y;
132
+ if (!i && !n && !a)
133
+ return void d.error("UploadErr", { isMobile: i, uploadId: n, etags: a });
134
+ d.info("MarkUploadComplete", { surveyId: t });
135
+ const l = await K(`${e}/sdk/1/completeSessionReplay`, { method: "POST", body: JSON.stringify({ etags: a, uploadId: n, responseGroupUuid: o, surveyId: t, replayDuration: s, eventDigest: c, userAgent: (y = window == null ? void 0 : window.navigator) == null ? void 0 : y.userAgent }), headers: r, shouldRetryRequest: !0 });
136
+ return d.info("MarkUploadDone", { surveyId: t }), l;
137
+ }, mt = (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
- }, we = (e) => {
144
+ }, Pe = (e) => {
145
145
  if (e === null)
146
146
  return "";
147
147
  const t = [];
@@ -165,12 +165,12 @@ const Ge = (e) => {
165
165
  case Node.ELEMENT_NODE:
166
166
  a.name = n.nodeName;
167
167
  }
168
- a.position = Ge(n);
168
+ a.position = mt(n);
169
169
  }
170
170
  return "/" + t.reverse().map((n) => n.position !== null ? `/${n.name}[${n.position}]` : `/${n.name}`).join("");
171
- }, v = { capture: !0, passive: !0 }, We = ["a", "button", "input", "option", "li", "link"], $e = ["Escape", "Enter", "Backspace", "F5", "Tab"];
172
- let A = !1;
173
- const qe = ["label", "type", "role", "title", "placeholder", "errormessage", "valuetext", "href"], ze = "aria-", se = (e) => {
171
+ }, S = { capture: !0, passive: !0 }, wt = ["a", "button", "input", "option", "li", "link"], yt = ["Escape", "Enter", "Backspace", "F5", "Tab"];
172
+ let G = !1;
173
+ const ft = ["label", "type", "role", "title", "placeholder", "errormessage", "valuetext", "href"], ht = "aria-", ve = (e) => {
174
174
  var a;
175
175
  if (((a = e.tagName) == null ? void 0 : a.toLowerCase()) === "html")
176
176
  return { element: "html" };
@@ -178,32 +178,32 @@ const qe = ["label", "type", "role", "title", "placeholder", "errormessage", "va
178
178
  n.element = ((r) => {
179
179
  if (!r.tagName)
180
180
  return "No tagName";
181
- const s = r.getAttribute("type");
182
- return s ? `${s} ${r.tagName.toLowerCase()}` : r.tagName.toLowerCase();
181
+ const o = r.getAttribute("type");
182
+ return o ? `${o} ${r.tagName.toLowerCase()}` : r.tagName.toLowerCase();
183
183
  })(e);
184
184
  for (const r of e.attributes) {
185
- let s = r.name;
186
- const o = r.value;
187
- s.startsWith(ze) && (s = s.substring(5)), qe.includes(s) && (n[s] = o);
185
+ let o = r.name;
186
+ const s = r.value;
187
+ o.startsWith(ht) && (o = o.substring(5)), ft.includes(o) && (n[o] = s);
188
188
  }
189
189
  return n;
190
- }, Je = (e) => {
190
+ }, It = (e) => {
191
191
  var a;
192
192
  if (!e)
193
193
  return {};
194
- const t = { ...se(e) }, n = e.parentElement;
195
- if (n && We.includes((a = n.tagName) == null ? void 0 : a.toLowerCase())) {
196
- const r = se(n);
194
+ const t = { ...ve(e) }, n = e.parentElement;
195
+ if (n && wt.includes((a = n.tagName) == null ? void 0 : a.toLowerCase())) {
196
+ const r = ve(n);
197
197
  Object.assign(t, r);
198
198
  }
199
199
  return t;
200
- }, ye = (e, t) => {
200
+ }, Re = (e, t) => {
201
201
  var a;
202
202
  let n = t.target;
203
- t.target === ((a = window.document) == null ? void 0 : a.body) && window.Sprig.pointerDownTarget && (n = window.Sprig.pointerDownTarget), Xe({ x: t.x, y: t.y, type: e, elementAttributes: Je(n), windowHeight: window.innerHeight, windowWidth: window.innerWidth, ...n instanceof HTMLElement ? { rect: n == null ? void 0 : n.getBoundingClientRect(), xPath: we(n) } : {} });
204
- }, fe = (e) => {
205
- $e.includes(e.key) && et({ key: e.key });
206
- }, Ie = /* @__PURE__ */ ((e, t) => {
203
+ t.target === ((a = window.document) == null ? void 0 : a.body) && window.Sprig.pointerDownTarget && (n = window.Sprig.pointerDownTarget), St({ x: t.x, y: t.y, type: e, elementAttributes: It(n), windowHeight: window.innerHeight, windowWidth: window.innerWidth, ...n instanceof HTMLElement ? { rect: n == null ? void 0 : n.getBoundingClientRect(), xPath: Pe(n) } : {} });
204
+ }, Be = (e) => {
205
+ yt.includes(e.key) && Et({ key: e.key });
206
+ }, Te = /* @__PURE__ */ ((e, t) => {
207
207
  let n;
208
208
  return (a) => {
209
209
  clearTimeout(n), n = window.setTimeout(() => e(a), t);
@@ -212,97 +212,97 @@ const qe = ["label", "type", "role", "title", "placeholder", "errormessage", "va
212
212
  if (!(e.target instanceof HTMLElement || e.target instanceof Document))
213
213
  return;
214
214
  let t = e.target;
215
- "scrollTop" in t || (t = t.documentElement), tt({ xPath: we(t), x: t.scrollLeft, y: t.scrollTop, elementAttributes: { targetScrollWidth: t.scrollWidth, targetClientWidth: t.clientWidth, targetScrollHeight: t.scrollHeight, targetClientHeight: t.clientHeight } });
216
- }, 750), he = (oe = "left_click", (e) => ye(oe, e));
217
- var oe;
218
- const ve = (e) => {
219
- e.button === 2 && ye("right_click", e);
220
- }, De = (e) => {
215
+ "scrollTop" in t || (t = t.documentElement), Ct({ xPath: Pe(t), x: t.scrollLeft, y: t.scrollTop, elementAttributes: { targetScrollWidth: t.scrollWidth, targetClientWidth: t.clientWidth, targetScrollHeight: t.scrollHeight, targetClientHeight: t.clientHeight } });
216
+ }, 750), Me = (Se = "left_click", (e) => Re(Se, e));
217
+ var Se;
218
+ const Ae = (e) => {
219
+ e.button === 2 && Re("right_click", e);
220
+ }, _e = (e) => {
221
221
  window.Sprig && (window.Sprig.pointerDownTarget = e.target);
222
- }, Qe = () => {
223
- A || (window.addEventListener("click", he, v), window.addEventListener("pointerdown", De, v), window.addEventListener("mousedown", ve, v), window.addEventListener("keydown", fe, v), window.addEventListener("scroll", Ie, v), A = !0, window.performance.getEntriesByType("navigation").map((e) => e.type).includes("reload") && Ye({ url: window.location.href, currentPageTitle: document.title }), window.performance.getEntriesByType("navigation").map((e) => e.type).includes("back_forward") && Ze({ curUrl: window.location.href, fromUrl: document.referrer, currentPageTitle: document.title }));
224
- }, p = { isRecording: !1, scrollEventUuids: {}, stopRecording: () => {
225
- } }, be = () => window.indexedDB && window.IDBKeyRange && window.CompressionStream, y = (() => {
222
+ }, vt = () => {
223
+ G || (window.addEventListener("click", Me, S), window.addEventListener("pointerdown", _e, S), window.addEventListener("mousedown", Ae, S), window.addEventListener("keydown", Be, S), window.addEventListener("scroll", Te, S), G = !0, window.performance.getEntriesByType("navigation").map((e) => e.type).includes("reload") && Dt({ url: window.location.href, currentPageTitle: document.title }), window.performance.getEntriesByType("navigation").map((e) => e.type).includes("back_forward") && bt({ curUrl: window.location.href, fromUrl: document.referrer, currentPageTitle: document.title }));
224
+ }, w = { isRecording: !1, scrollEventUuids: {}, stopRecording: () => {
225
+ } }, Ne = () => window.indexedDB && window.IDBKeyRange && window.CompressionStream, h = (() => {
226
226
  const e = f.getItem("sprig.sessionId");
227
227
  if (e)
228
- return u.info("SessionIDFound", { savedSessionId: e }), f.removeItem("sprig.sessionId"), e;
229
- const t = N();
230
- return u.info("GeneratedSessionID", { uuid: t }), t;
231
- })(), q = () => {
228
+ return d.info("SessionIDFound", { savedSessionId: e }), f.removeItem("sprig.sessionId"), e;
229
+ const t = W();
230
+ return d.info("GeneratedSessionID", { uuid: t }), t;
231
+ })(), se = () => {
232
232
  f.setItem("sprig.disableReplayRecording", "disabled");
233
233
  }, b = () => !!f.getItem("sprig.disableReplayRecording");
234
234
  window.addEventListener("beforeunload", () => {
235
- u.info("BeforeUnload", { sessionId: y }), f.setItem("sprig.sessionId", y);
235
+ d.info("BeforeUnload", { sessionId: h }), f.setItem("sprig.sessionId", h);
236
236
  });
237
- const Z = (e) => e && e.trim().substring(0, 500).replace(/\s\s+/g, " ").replace(/\r?\n|\r/g, " ").substring(0, 250), D = (e, t) => {
237
+ const pe = (e) => e && e.trim().substring(0, 500).replace(/\s\s+/g, " ").replace(/\r?\n|\r/g, " ").substring(0, 250), D = (e, t) => {
238
238
  var n, a;
239
- if (!b() && p.isRecording)
239
+ if (!b() && w.isRecording)
240
240
  try {
241
241
  (a = (n = window.rrwebRecord) == null ? void 0 : n.addCustomEvent) == null || a.call(n, e, t);
242
242
  } catch (r) {
243
- L("Error recording custom event", r);
243
+ J("Error recording custom event", r);
244
244
  }
245
- }, Xe = (e) => {
245
+ }, St = (e) => {
246
246
  var t;
247
- (t = e == null ? void 0 : e.elementAttributes) != null && t.text && (e.elementAttributes.text = Z(e.elementAttributes.text)), D("Sprig_Click", e);
248
- }, Ye = (e) => {
247
+ (t = e == null ? void 0 : e.elementAttributes) != null && t.text && (e.elementAttributes.text = pe(e.elementAttributes.text)), D("Sprig_Click", e);
248
+ }, Dt = (e) => {
249
249
  D("Sprig_Refresh", e);
250
- }, Ze = (e) => {
251
- e.currentPageTitle && (e.currentPageTitle = Z(e.currentPageTitle)), D("Sprig_BackForward", e);
252
- }, et = (e) => {
250
+ }, bt = (e) => {
251
+ e.currentPageTitle && (e.currentPageTitle = pe(e.currentPageTitle)), D("Sprig_BackForward", e);
252
+ }, Et = (e) => {
253
253
  D("Sprig_Keystroke", e);
254
- }, tt = async (e) => {
255
- const { x: t, xPath: n, y: a } = e, r = p.scrollEventUuids[n];
254
+ }, Ct = async (e) => {
255
+ const { x: t, xPath: n, y: a } = e, r = w.scrollEventUuids[n];
256
256
  if (r)
257
257
  return I(async () => {
258
- var d, i, c, w;
259
- const s = await l.openDB(), o = await s.get("events", r);
260
- if (o != null && o.event) {
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)
258
+ var c, i, l, y;
259
+ const o = await u.openDB(), s = await o.get("events", r);
260
+ if (s != null && s.event) {
261
+ const p = JSON.parse(s.event), m = t > ((i = (c = p.data) == null ? void 0 : c.payload) == null ? void 0 : i.x), g = a > ((y = (l = p.data) == null ? void 0 : l.payload) == null ? void 0 : y.y);
262
+ if (!m && !g)
263
263
  return null;
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);
264
+ m && (p.data.payload.x = t), g && (p.data.payload.y = a), p.data.payload.elementAttributes = e.elementAttributes, s.event = JSON.stringify(p), await o.put("events", s);
265
265
  } else
266
266
  D("Sprig_Scroll", e);
267
267
  }, "Error updating scroll event");
268
268
  D("Sprig_Scroll", e);
269
- }, Se = () => {
270
- p.stopRecording && (p.stopRecording(), p.stopRecording = void 0), p.isRecording = !1, ["cleanupInterval", "inactivityInterval", "pendingCheckInterval"].forEach((e) => {
271
- p[e] && (clearInterval(p[e]), p[e] = void 0);
272
- }), A && (window.removeEventListener("click", he, v), window.removeEventListener("pointerdown", De, v), window.removeEventListener("mousedown", ve, v), window.removeEventListener("keydown", fe, v), window.removeEventListener("scroll", Ie, v), A = !1);
273
- }, nt = ["did not allow mutations", "called in an invalid security context"], at = (e, t, { reportError: n = !0, extraInfo: a = {} }) => {
269
+ }, Le = () => {
270
+ w.stopRecording && (w.stopRecording(), w.stopRecording = void 0), w.isRecording = !1, ["cleanupInterval", "inactivityInterval", "pendingCheckInterval"].forEach((e) => {
271
+ w[e] && (clearInterval(w[e]), w[e] = void 0);
272
+ }), G && (window.removeEventListener("click", Me, S), window.removeEventListener("pointerdown", _e, S), window.removeEventListener("mousedown", Ae, S), window.removeEventListener("keydown", Be, S), window.removeEventListener("scroll", Te, S), G = !1);
273
+ }, kt = ["did not allow mutations", "called in an invalid security context"], Ut = (e, t, { reportError: n = !0, extraInfo: a = {} }) => {
274
274
  if (!b() && t instanceof Error) {
275
- if (q(), t.name === "VersionError")
276
- return u.error("VersionErr", { message: e }), l.deleteDB();
275
+ if (se(), t.name === "VersionError")
276
+ return d.error("VersionErr", { message: e }), u.deleteDB();
277
277
  ((r) => {
278
278
  if (!r)
279
279
  return !0;
280
- for (const s of nt)
281
- if (r.toLowerCase().includes(s))
280
+ for (const o of kt)
281
+ if (r.toLowerCase().includes(o))
282
282
  return !1;
283
283
  return !0;
284
- })(t == null ? void 0 : t.message) && (n && window.UserLeap.reportError(e, t, a), l.clearAll());
284
+ })(t == null ? void 0 : t.message) && (n && window.UserLeap.reportError(e, t, a), u.clearAll());
285
285
  }
286
- }, L = (e, t, { reportError: n } = { reportError: !0 }) => {
287
- Se(), u.error("ReplayErr", { code: t.code, name: t.name }), at(e, t, { reportError: n });
286
+ }, J = (e, t, { reportError: n } = { reportError: !0 }) => {
287
+ Le(), d.error("ReplayErr", { code: t.code, name: t.name }), Ut(e, t, { reportError: n });
288
288
  }, I = async (e, t) => {
289
289
  try {
290
290
  return await e();
291
291
  } catch (n) {
292
- L(t, n);
292
+ J(t, n);
293
293
  }
294
294
  };
295
- be() && (W("replayStorage").catch(console.error), W("sprig.replay").catch(console.error));
296
- const l = new class {
295
+ Ne() && (re("replayStorage").catch(console.error), re("sprig.replay").catch(console.error));
296
+ const u = new class {
297
297
  openDB() {
298
- return function(e, t, { blocked: n, upgrade: a, blocking: r, terminated: s } = {}) {
299
- const o = indexedDB.open(e, t), d = C(o);
300
- return a && (o.onupgradeneeded = (i) => {
301
- a(C(o.result), i.oldVersion, i.newVersion, C(o.transaction), i);
302
- }), n && (o.onblocked = (i) => n(i.oldVersion, i.newVersion, i)), d.then((i) => {
303
- s && (i.onclose = () => s()), r && (i.onversionchange = (c) => r(c.oldVersion, c.newVersion, c));
298
+ return function(e, t, { blocked: n, upgrade: a, blocking: r, terminated: o } = {}) {
299
+ const s = indexedDB.open(e, t), c = x(s);
300
+ return a && (s.onupgradeneeded = (i) => {
301
+ a(x(s.result), i.oldVersion, i.newVersion, x(s.transaction), i);
302
+ }), n && (s.onblocked = (i) => n(i.oldVersion, i.newVersion, i)), c.then((i) => {
303
+ o && (i.onclose = () => o()), r && (i.onversionchange = (l) => r(l.oldVersion, l.newVersion, l));
304
304
  }).catch(() => {
305
- }), d;
305
+ }), c;
306
306
  }("sprigReplay", 1, { upgrade: (e, t, n) => {
307
307
  if (n === 0 && f.setItem("sprig.pendingCount", "0"), !e.objectStoreNames.contains("events")) {
308
308
  const a = e.createObjectStore("events", { keyPath: "uuid" });
@@ -319,7 +319,7 @@ const l = new class {
319
319
  } });
320
320
  }
321
321
  deleteDB() {
322
- return W("sprigReplay").catch(console.error);
322
+ return re("sprigReplay").catch(console.error);
323
323
  }
324
324
  async bulkAdd(e, t) {
325
325
  const n = (await this.openDB()).transaction(e, "readwrite");
@@ -331,8 +331,8 @@ const l = new class {
331
331
  }
332
332
  async deleteBySessionId(e, t) {
333
333
  const n = IDBKeyRange.only(t), a = (await this.openDB()).transaction(e, "readwrite"), r = a.store.index("sessionId");
334
- for await (const s of r.iterate(n))
335
- await s.delete();
334
+ for await (const o of r.iterate(n))
335
+ await o.delete();
336
336
  await a.done;
337
337
  }
338
338
  async updatePartial(e, t, n) {
@@ -340,40 +340,40 @@ const l = new class {
340
340
  r && await a.store.put({ ...r, ...n }), await a.done;
341
341
  }
342
342
  async deleteRowsBefore(e, t, n = () => !0) {
343
- const a = IDBKeyRange.upperBound(t, !0), r = (await this.openDB()).transaction(e, "readwrite"), s = r.store.index("timestamp");
344
- for await (const o of s.iterate(a))
345
- n(o.value) && await o.delete();
343
+ const a = IDBKeyRange.upperBound(t, !0), r = (await this.openDB()).transaction(e, "readwrite"), o = r.store.index("timestamp");
344
+ for await (const s of o.iterate(a))
345
+ n(s.value) && await s.delete();
346
346
  await r.done;
347
347
  }
348
348
  async getEventsBetween(e, t = Date.now()) {
349
349
  if (e >= t)
350
350
  return Promise.resolve([]);
351
- const n = IDBKeyRange.bound([y, e], [y, t], !1, !0);
351
+ const n = IDBKeyRange.bound([h, e], [h, t], !1, !0);
352
352
  return (await this.openDB()).getAllFromIndex("events", "[sessionId+timestamp]", n);
353
353
  }
354
354
  async updateEventsExpiredAt(e, t, n = 30) {
355
- const a = /* @__PURE__ */ new Date(), r = a.setMinutes(a.getMinutes() + (n ?? 30)), s = (await this.openDB()).transaction("events", "readwrite"), o = s.store.index("[sessionId+timestamp]"), d = IDBKeyRange.bound([y, e], [y, t], !1, !0);
356
- for await (const i of o.iterate(d))
355
+ const a = /* @__PURE__ */ new Date(), r = a.setMinutes(a.getMinutes() + (n ?? 30)), o = (await this.openDB()).transaction("events", "readwrite"), s = o.store.index("[sessionId+timestamp]"), c = IDBKeyRange.bound([h, e], [h, t], !1, !0);
356
+ for await (const i of s.iterate(c))
357
357
  await i.update({ ...i.value, expiredAt: r });
358
- await s.done;
358
+ await o.done;
359
359
  }
360
360
  async deleteChunkUploads(e, t) {
361
361
  const n = IDBKeyRange.only([t, e]), a = (await this.openDB()).transaction("chunkUploads", "readwrite");
362
- let s = await a.store.index("[uploadId+status]").openCursor(n);
363
- for (; s; )
364
- s.delete(), s = await s.continue();
362
+ let o = await a.store.index("[uploadId+status]").openCursor(n);
363
+ for (; o; )
364
+ o.delete(), o = await o.continue();
365
365
  await a.done;
366
366
  }
367
367
  async getChunkUploadsByStatus({ sessionId: e, status: t, uploadId: n }) {
368
- const a = (await this.openDB()).transaction("chunkUploads", "readonly"), r = n ? a.store.index("[uploadId+status]") : a.store.index("[sessionId+status]"), s = n ? IDBKeyRange.only([n, t]) : IDBKeyRange.only([e, t]);
369
- return r.getAll(s);
368
+ const a = (await this.openDB()).transaction("chunkUploads", "readonly"), r = n ? a.store.index("[uploadId+status]") : a.store.index("[sessionId+status]"), o = n ? IDBKeyRange.only([n, t]) : IDBKeyRange.only([e, t]);
369
+ return r.getAll(o);
370
370
  }
371
371
  async getPendingCaptures(e = {}) {
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));
372
+ return (await (await this.openDB()).getAllFromIndex("pendingCaptures", "sessionId", h)).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));
373
373
  }
374
374
  async markPendingCaptureToCanUpload(e) {
375
375
  const t = (await this.openDB()).transaction("pendingCaptures", "readwrite"), n = t.store.index("sessionId");
376
- for await (const a of n.iterate(y)) {
376
+ for await (const a of n.iterate(h)) {
377
377
  const r = a.value;
378
378
  r.captureParams.responseGroupId === e && await a.update({ ...r, canUpload: !0 });
379
379
  }
@@ -383,274 +383,377 @@ const l = new class {
383
383
  if (parseInt(f.getItem("sprig.pendingCount") ?? "0") === 0)
384
384
  return null;
385
385
  const t = Date.now(), n = (await this.openDB()).transaction("pendingCaptures", "readwrite"), a = n.store.index("sessionId");
386
- for await (const r of a.iterate(y)) {
387
- const s = r.value;
388
- !s.captureParams.isHeatmap || e && !e.includes(s.uuid) || await r.update({ ...s, targetTimestamp: t, captureParams: { ...s.captureParams, triggerTimestamp: t, replayParams: { ...s.captureParams.replayParams, replayDurationSeconds: Math.floor((t - s.timestamp) / 1e3) } } });
386
+ for await (const r of a.iterate(h)) {
387
+ const o = r.value;
388
+ !o.captureParams.isHeatmap || e && !e.includes(o.uuid) || await r.update({ ...o, targetTimestamp: t, captureParams: { ...o.captureParams, triggerTimestamp: t, replayParams: { ...o.captureParams.replayParams, replayDurationSeconds: Math.floor((t - o.timestamp) / 1e3) } } });
389
389
  }
390
390
  await n.done;
391
391
  }
392
- }(), Ce = async (e, t) => {
392
+ }(), C = [];
393
+ let _, Oe, $, Fe, H, He, R = [], M = !1, T = 0, j = !1, je = !1, ge = [], Y = !1;
394
+ const A = () => j && !M && Date.now() <= $, xt = ({ apiUrl: e, config: t, triggerSnapshot: n, forceInit: a = !1 }) => {
395
+ j && !a || (f.isStorageAvailable ? (R = [], ge.splice(0), C.splice(0), T = 0, H = n, Oe = e, _ = { responseGroupUuid: t.responseGroupUuid, surveyId: t.surveyId, userAgent: t.userAgent, sdkVersion: t.sdkVersion }, Fe = t.maxDurationSeconds, Tt(), j || (He = window.setInterval(Bt, 500)), j = !0) : M = !0);
396
+ }, Pt = [E.Drag, E.Input, E.MediaInteraction, E.MouseInteraction, E.MouseMove, E.Scroll, E.Selection, E.TouchMove], Rt = (e) => e.type === U.Custom || e.type === U.IncrementalSnapshot && Pt.includes(e.data.source), me = (e) => e.some(Rt), Bt = async () => {
397
+ if (!A())
398
+ return void window.clearInterval(He);
399
+ if (Ve(), !me(C))
400
+ return;
401
+ const e = C[0].timestamp;
402
+ Date.now() - e > 35e3 && (H == null || H());
403
+ }, Ve = async () => {
404
+ if (R.length || Y)
405
+ return;
406
+ Y = !0;
407
+ const e = await At();
408
+ if (!e)
409
+ return void (M = !0);
410
+ ge.splice(0, e.length).forEach((t) => t(e.shift())), e.forEach((t) => R.push(t)), Y = !1;
411
+ }, Tt = () => {
412
+ const e = f.getItem("sprig.alwayson.info");
413
+ if (e) {
414
+ d.info("Read stored session state", e);
415
+ const t = JSON.parse(e);
416
+ M = t.disabled, _ = t.metadata, R = t.uploadUrls, T = t.currentIndex, $ = t.expirationTimestamp, t.pendingEventTimestamp && (d.info(`Uploading with pending timestamp: ${t.pendingEventTimestamp}`), Mt(t.pendingEventTimestamp));
417
+ } else
418
+ $ = 1e3 * Fe + Date.now();
419
+ }, Mt = async (e) => {
420
+ const t = Date.now(), n = (await u.getEventsBetween(e, t)).map((r) => JSON.parse(r.event));
421
+ if (!me(n))
422
+ return;
423
+ We(n);
424
+ const a = await Ke();
425
+ a && await $e(a, n);
426
+ }, Ge = async (e, t) => {
427
+ try {
428
+ const n = await e();
429
+ if (!n.ok)
430
+ throw new Error(`Error ${t}`);
431
+ return n;
432
+ } catch {
433
+ M = !0;
434
+ }
435
+ }, $e = async (e, t) => {
436
+ if (!A() || !e)
437
+ return;
438
+ const n = await (async (a) => {
439
+ const r = new TextEncoder(), o = new CompressionStream("gzip"), s = o.writable.getWriter(), c = r.encode(JSON.stringify(a));
440
+ return s.write(c), s.close(), new Uint8Array(await new Response(o.readable).arrayBuffer());
441
+ })(t);
442
+ d.info("Uploading always-on events with presigned url"), await Ge(() => K(e, { body: n, method: "PUT" }), "uploading always-on with presigned url");
443
+ }, At = async () => {
444
+ if (!A())
445
+ return;
446
+ const { surveyId: e, responseGroupUuid: t } = _, n = { responseGroupUuid: t, surveyId: e, index: T + 1 };
447
+ d.info("Fetching always-on upload urls", n);
448
+ const a = await Ge(() => K(`${Oe}/sdk/1/replayUrls`, { method: "POST", body: JSON.stringify(n), headers: rt(window.UserLeap) }), "fetching always-on signed urls");
449
+ if (!a)
450
+ return;
451
+ const r = a.json.signedUrls;
452
+ return d.info("Fetched more always-on upload urls", { body: n, urls: r }), r;
453
+ }, Ke = async () => {
454
+ if (R.length)
455
+ return R.shift();
456
+ const e = new Promise((t) => {
457
+ ge.push(t);
458
+ });
459
+ return Ve(), e;
460
+ }, We = (e) => {
461
+ var r, o, s;
462
+ const t = e.length ? e[e.length - 1].timestamp : Date.now(), n = T, a = ((o = (r = window.UserLeap) == null ? void 0 : r.config) == null ? void 0 : o.customMetadata) ?? ((s = window.__cfg) == null ? void 0 : s.customMetadata);
463
+ T++, e.push({ timestamp: t, type: U.Custom, data: { tag: "Sprig_Meta", payload: { ..._, index: n, visitorId: window.UserLeap.visitorId ?? "", timestamp: t, customMetadata: a } } });
464
+ }, _t = (e, t) => {
465
+ A() && !je && (e || C.length) && (e && C.length && (async () => {
466
+ const n = C.splice(0);
467
+ if (!me(n))
468
+ return;
469
+ d.info("Capturing always-on event array to upload"), We(n);
470
+ const a = await Ke();
471
+ a && await $e(a, n);
472
+ })(), C.push(t));
473
+ };
474
+ window.addEventListener("beforeunload", async () => {
475
+ je = !0, A() && (d.info("Always On handle page unload"), (() => {
476
+ let e;
477
+ C.length && (e = C[0].timestamp);
478
+ const t = { disabled: M, metadata: _, uploadUrls: R, currentIndex: T, pendingEventTimestamp: e, expirationTimestamp: $ };
479
+ d.info("Storing session state on unload", t), f.setItem("sprig.alwayson.info", JSON.stringify(t));
480
+ })());
481
+ });
482
+ const Je = async (e, t) => {
393
483
  const n = performance.now();
394
484
  let a;
395
485
  try {
396
486
  a = await e();
397
487
  } finally {
398
488
  const r = performance.now() - n;
399
- let s = ce[t];
400
- s || (s = ue(t)), s.report(r / 1e3);
489
+ let o = be[t];
490
+ o || (o = Ee(t)), o.report(r / 1e3);
401
491
  }
402
492
  return a;
403
- }, ke = (e, t) => {
493
+ }, ze = (e, t) => {
404
494
  const n = performance.now();
405
495
  try {
406
496
  e();
407
497
  } finally {
408
498
  const a = performance.now() - n;
409
- let r = ce[t];
410
- r || (r = ue(t)), r.report(a / 1e3);
499
+ let r = be[t];
500
+ r || (r = Ee(t)), r.report(a / 1e3);
411
501
  }
412
502
  };
413
- let Ee = 5e3, z = 6e4, J = 0, k, Q = !1, X = [];
414
- const rt = (e) => {
503
+ let qe = 5e3, ie = 6e4, de = 0, P, ce = !1, le = [];
504
+ const Nt = (e) => {
415
505
  var t, n, a, r;
416
506
  if ((t = e.event) != null && t.includes("Sprig_Scroll")) {
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;
418
- if (!s)
507
+ const o = (r = (a = (n = JSON.parse(e.event)) == null ? void 0 : n.data) == null ? void 0 : a.payload) == null ? void 0 : r.xPath;
508
+ if (!o)
419
509
  return;
420
- p.scrollEventUuids[s] = e.uuid;
510
+ w.scrollEventUuids[o] = e.uuid;
421
511
  }
422
- X.push(e), Q || st();
423
- }, st = () => {
424
- Q = !0, setTimeout(async () => {
512
+ le.push(e), ce || Lt();
513
+ }, Lt = () => {
514
+ ce = !0, setTimeout(async () => {
425
515
  if (b())
426
516
  return;
427
- const e = X;
428
- X = [], Q = !1, ke(async () => {
517
+ const e = le;
518
+ le = [], ce = !1, ze(async () => {
429
519
  await (async (t) => {
430
- const n = t.map((a) => ({ ...a, sessionId: a.sessionId ?? y }));
520
+ const n = t.map((a) => ({ ...a, sessionId: a.sessionId ?? h }));
431
521
  if (n.length !== 0)
432
- return I(() => l.bulkAdd("events", n), "Error storing replay events");
522
+ return I(() => u.bulkAdd("events", n), "Error storing replay events");
433
523
  })(e);
434
524
  }, "sdk_replay_add_event_batch_seconds");
435
525
  }, 500);
436
- }, ot = (e, t, n) => {
437
- p.cleanupInterval = window.setInterval(() => {
526
+ }, Ot = (e, t, n) => {
527
+ w.cleanupInterval = window.setInterval(() => {
438
528
  const a = Date.now();
439
- Ce(() => 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)]);
441
- }, "Error deleting table rows"), "sdk_replay_cleanup_seconds"), u.debug("CleanupComplete");
529
+ Je(() => I(async () => {
530
+ b() || await Promise.all([u.deleteRowsBefore("events", a - 1e3 * e, (r) => r.expiredAt === void 0 || r.expiredAt < a - 1e3 * e), u.deleteRowsBefore("chunkUploads", a - 1e3 * t), u.deleteRowsBefore("pendingCaptures", a - 1e3 * n, (r) => !r.canUpload)]);
531
+ }, "Error deleting table rows"), "sdk_replay_cleanup_seconds"), d.debug("CleanupComplete");
442
532
  }, 3e4);
443
- }, it = () => {
444
- p.pendingCheckInterval = window.setInterval(async () => {
533
+ }, Ft = () => {
534
+ w.pendingCheckInterval = window.setInterval(async () => {
445
535
  I(async () => {
446
- await Y();
536
+ await ue();
447
537
  }, "Error initiating pending captures");
448
538
  }, 5e3);
449
- }, Y = async (e = !1) => {
450
- const t = parseInt(k ?? "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), Be(r.captureParams, r.canUpload)))), k = (t - n.length).toString(), f.setItem("sprig.pendingCount", k);
455
- }, dt = async (e, t, n, a, r) => {
456
- const s = Math.min(e + r, n), o = await Ce(() => l.getEventsBetween(e, s), "sdk_replay_get_events_between_seconds");
457
- if (!(o != null && o.length))
458
- return u.debug("NoEventsFound"), { validStartFound: a, events: [] };
539
+ };
540
+ let Z = !1;
541
+ const ue = async (e = !1) => {
542
+ if (!Z)
543
+ try {
544
+ Z = !0;
545
+ const t = parseInt(P ?? "0");
546
+ if (t === 0)
547
+ return;
548
+ const n = await u.getPendingCaptures({ beforePresent: !0, isBeforeType: e }), a = await u.openDB();
549
+ await Promise.all(n.map(async (r) => (await a.delete("pendingCaptures", r.uuid), Ye(r.captureParams, r.canUpload)))), P = (t - n.length).toString(), f.setItem("sprig.pendingCount", P);
550
+ } finally {
551
+ Z = !1;
552
+ }
553
+ }, Ht = async (e, t, n, a, r) => {
554
+ const o = Math.min(e + r, n), s = await Je(() => u.getEventsBetween(e, o), "sdk_replay_get_events_between_seconds");
555
+ if (!(s != null && s.length))
556
+ return d.debug("NoEventsFound"), { validStartFound: a, events: [] };
459
557
  if (!a) {
460
- u.debug("ValidStartSearch");
461
- let d = -1;
462
- return o == null || o.forEach((i, c) => {
558
+ d.debug("ValidStartSearch");
559
+ let c = -1;
560
+ return s == null || s.forEach((i, l) => {
463
561
  if (!i.isValidStart)
464
562
  return;
465
- const w = i.timestamp <= t;
466
- (d < 0 || w) && (d = c);
467
- }), d < 0 ? (u.debug("ValidStartNotFound"), { validStartFound: a, events: [] }) : { validStartFound: !0, events: o == null ? void 0 : o.slice(d) };
563
+ const y = i.timestamp <= t;
564
+ (c < 0 || y) && (c = l);
565
+ }), c < 0 ? (d.debug("ValidStartNotFound"), { validStartFound: a, events: [] }) : { validStartFound: !0, events: s == null ? void 0 : s.slice(c) };
468
566
  }
469
- return { validStartFound: a, events: o };
470
- }, Pe = (e) => Promise.all(e.map(async (t) => {
471
- const n = await (async (a) => le.execute(async () => {
472
- var o;
473
- u.info("UploadChunkStart", { chunkIndex: a.chunkIndex, surveyId: a.surveyId });
474
- const r = await de(a.uploadUrl, { body: a.data, method: "PUT" });
475
- u.http("UploadChunkEnd", { url: a.uploadUrl, method: "PUT", status_code: r.status, reason: r.statusText ?? "OK", chunkIndex: a.chunkIndex, surveyId: a.surveyId });
476
- const s = (o = r.headers) == null ? void 0 : o.get("ETag");
477
- if (!s)
567
+ return { validStartFound: a, events: s };
568
+ }, Qe = (e) => Promise.all(e.map(async (t) => {
569
+ const n = await (async (a) => Ue.execute(async () => {
570
+ var s;
571
+ d.info("UploadChunkStart", { chunkIndex: a.chunkIndex, surveyId: a.surveyId });
572
+ const r = await K(a.uploadUrl, { body: a.data, method: "PUT" });
573
+ d.http("UploadChunkEnd", { url: a.uploadUrl, method: "PUT", status_code: r.status, reason: r.statusText ?? "OK", chunkIndex: a.chunkIndex, surveyId: a.surveyId });
574
+ const o = (s = r.headers) == null ? void 0 : s.get("ETag");
575
+ if (!o)
478
576
  throw new Error(`Upload response did not include etag for upload ${a.uploadId}, part ${a.chunkIndex}`);
479
- return s;
577
+ return o;
480
578
  }))(t);
481
- return await l.updatePartial("chunkUploads", t.uuid, { data: null, etag: n, status: "UploadComplete" }), t.uploadId;
482
- })), Re = async (e) => {
483
- const t = await l.getChunkUploadsByStatus({ status: "UploadComplete", uploadId: e });
579
+ return await u.updatePartial("chunkUploads", t.uuid, { data: null, etag: n, status: "UploadComplete" }), t.uploadId;
580
+ })), Xe = async (e) => {
581
+ const t = await u.getChunkUploadsByStatus({ status: "UploadComplete", uploadId: e });
484
582
  if (!(t != null && t.length))
485
- return void u.info("NoChunksForUpload", { uploadId: e });
486
- const n = t.reduce((s, o) => (s.find((d) => d.chunkIndex === o.chunkIndex) || s.push(o), s), []);
487
- n.sort((s, o) => s.chunkIndex - o.chunkIndex);
488
- const a = n.map((s) => ({ ETag: s.etag, PartNumber: s.chunkIndex })).filter((s) => s.ETag !== null), r = n[0];
489
- await pe({ apiUrl: r.apiUrl, surveyId: r.surveyId, uploadId: e, responseGroupUuid: r.responseGroupId, etags: a, headers: r.completeUploadHeaders, replayDuration: r.replayDuration }), await l.deleteChunkUploads("UploadComplete", e);
490
- }, ct = () => {
583
+ return void d.info("NoChunksForUpload", { uploadId: e });
584
+ const n = t.reduce((o, s) => (o.find((c) => c.chunkIndex === s.chunkIndex) || o.push(s), o), []);
585
+ n.sort((o, s) => o.chunkIndex - s.chunkIndex);
586
+ const a = n.map((o) => ({ ETag: o.etag, PartNumber: o.chunkIndex })).filter((o) => o.ETag !== null), r = n[0];
587
+ await xe({ apiUrl: r.apiUrl, surveyId: r.surveyId, uploadId: e, responseGroupUuid: r.responseGroupId, etags: a, headers: r.completeUploadHeaders, replayDuration: r.replayDuration }), await u.deleteChunkUploads("UploadComplete", e);
588
+ }, jt = () => {
491
589
  I(async () => {
492
- const e = await l.getChunkUploadsByStatus({ sessionId: y, status: "ReadyForUpload" });
590
+ const e = await u.getChunkUploadsByStatus({ sessionId: h, status: "ReadyForUpload" });
493
591
  if (!(e != null && e.length))
494
592
  return;
495
- const t = await Pe(e);
593
+ const t = await Qe(e);
496
594
  t != null && t.length && await Promise.all(t.map((n) => {
497
595
  if (n)
498
- return Re(n);
596
+ return Xe(n);
499
597
  }));
500
598
  }, "Error uploading unfinished chunks");
501
- }, ut = async (e, t) => {
599
+ }, Vt = async (e, t) => {
502
600
  const n = t ?? Date.now();
503
601
  return (async (a, r) => {
504
- const s = new TextEncoder();
505
- let o = null;
506
- const d = new CompressionStream("gzip"), i = d.writable.getWriter();
507
- let c = !1, w = !1, [g, h] = [0, 0], m = [];
508
- for (let E = a - 35e3; E < r; E += z) {
509
- if ({ validStartFound: w, events: m } = await dt(E, a, r, w, z), !(m != null && m.length)) {
510
- u.debug("NoEventsFound");
602
+ const o = new TextEncoder();
603
+ let s = null;
604
+ const c = new CompressionStream("gzip"), i = c.writable.getWriter();
605
+ let l = !1, y = !1, [p, m] = [0, 0], g = [];
606
+ for (let k = a - 35e3; k < r; k += ie) {
607
+ if ({ validStartFound: y, events: g } = await Ht(k, a, r, y, ie), !(g != null && g.length)) {
608
+ d.debug("NoEventsFound");
511
609
  continue;
512
610
  }
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
- ke(() => {
518
- i.write(U);
519
- }, "sdk_replay_compression_seconds"), c = !0;
611
+ p === 0 && (p = g[0].timestamp), m = g[g.length - 1].timestamp;
612
+ const N = g.map((B) => B.event);
613
+ N.push(`{"timestamp":${r}}`);
614
+ const L = `${l ? "," : "["}${N}`, O = o.encode(L);
615
+ ze(() => {
616
+ i.write(O);
617
+ }, "sdk_replay_compression_seconds"), l = !0;
520
618
  }
521
- if (h - g < Ee)
522
- return u.debug("ReplayTooShort"), null;
523
- const S = s.encode("]");
524
- return i.write(S), i.close(), o = new Uint8Array(await new Response(d.readable).arrayBuffer()), o;
619
+ if (m - p < qe)
620
+ return d.debug("ReplayTooShort"), null;
621
+ const v = o.encode("]");
622
+ return i.write(v), i.close(), s = new Uint8Array(await new Response(c.readable).arrayBuffer()), s;
525
623
  })(n - e, n);
526
- }, ie = async (e) => {
527
- const { surveyId: t, responseGroupId: n, visitorId: a, apiUrl: r, completeUploadHeaders: s, replayParams: o, triggerTimestamp: d } = e, i = await ut(1e3 * o.replayDurationSeconds, d);
624
+ }, De = async (e) => {
625
+ const { surveyId: t, responseGroupId: n, visitorId: a, apiUrl: r, completeUploadHeaders: o, replayParams: s, triggerTimestamp: c } = e, i = await Vt(1e3 * s.replayDurationSeconds, c);
528
626
  if (!(i != null && i.length))
529
- return void u.info("FileDataEmpty", { surveyId: t });
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;
535
- return U;
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;
627
+ return void d.info("FileDataEmpty", { surveyId: t });
628
+ const l = ((p, m, g) => {
629
+ const v = p.length, k = 1024 * m * 1024, N = Math.ceil(v / g), L = Math.max(k, N), O = [];
630
+ let B = 0;
631
+ for (; B < v; )
632
+ O.push(p.slice(B, B + L)), B += L;
633
+ return O;
634
+ })(i, s.minimumChunkSizeMb, s.signedUrls.length), y = await Promise.all(l.map(async (p, m) => {
635
+ const g = W(), v = { apiUrl: r, chunkIndex: m + 1, completeUploadHeaders: o, etag: null, responseGroupId: n, status: "ReadyForUpload", surveyId: t, timestamp: c, totalChunks: l.length, data: p, uploadId: s.uploadId, uploadUrl: s.signedUrls[m].url, uuid: g, visitorId: a };
636
+ return await (await u.openDB()).add("chunkUploads", { ...v, sessionId: v.sessionId ?? h }), v;
539
637
  }));
540
- await (async (g, h) => {
541
- await Pe(h), await Promise.all(g.map((m) => Re(m)));
542
- })([o.uploadId], w);
543
- }, Be = async (e, t) => {
638
+ await (async (p, m) => {
639
+ await Qe(m), await Promise.all(p.map((g) => Xe(g)));
640
+ })([s.uploadId], y);
641
+ }, Ye = async (e, t) => {
544
642
  if (b())
545
- return u.debug("ReplayDisabled-ScheduleOrCapture");
546
- const { isHeatmap: n, isStandalone: a, replayParams: r, triggerTimestamp: s, responseGroupId: o } = e, d = async () => {
547
- setTimeout(() => T.removeListener(O.QuestionAnswered, d), 0), I(async () => {
548
- r.replayDurationType === "before" ? await ie(e) : await l.markPendingCaptureToCanUpload(o);
643
+ return d.debug("ReplayDisabled-ScheduleOrCapture");
644
+ const { isHeatmap: n, isStandalone: a, replayParams: r, triggerTimestamp: o, responseGroupId: s } = e, c = async () => {
645
+ setTimeout(() => F.removeListener(q.QuestionAnswered, c), 0), I(async () => {
646
+ r.replayDurationType === "before" ? await De(e) : await u.markPendingCaptureToCanUpload(s);
549
647
  }, "Error in schedule/capture callback");
550
648
  };
551
649
  I(async () => {
552
650
  if (r.replayDurationType === "after" || r.replayDurationType === "beforeAndAfter")
553
- return !a && !n && T.on(O.QuestionAnswered, d), void await Ue(e);
651
+ return !a && !n && F.on(q.QuestionAnswered, c), void await et(e);
554
652
  if (a || n || t)
555
- await ie(e), n && lt();
653
+ await De(e), n && Gt();
556
654
  else {
557
- const i = 35 + r.replayDurationSeconds, c = s - 1e3 * i, w = s;
558
- await l.updateEventsExpiredAt(c, w, r.expirationTimeLimitMinutes), T.on(O.QuestionAnswered, d);
655
+ const i = 35 + r.replayDurationSeconds, l = o - 1e3 * i, y = o;
656
+ await u.updateEventsExpiredAt(l, y, r.expirationTimeLimitMinutes), F.on(q.QuestionAnswered, c);
559
657
  }
560
658
  }, "Error in scheduling/capturing replay");
561
- }, lt = async () => {
562
- parseInt(k ?? "0") || f.removeItem("sprig.isCapturingHeatmap"), f.getItem("sprig.teardownAfterCapture") && (Se(), xe(), f.removeItem("sprig.teardownAfterCapture"));
563
- }, xe = async () => b() ? u.debug("ReplayDisabled-ClearData") : Promise.all([l.deleteBySessionId("events", y), l.deleteBySessionId("pendingCaptures", y)]).catch((e) => {
564
- L("Error clearing user replay data", e);
565
- }), Ue = async (e) => {
659
+ }, Gt = async () => {
660
+ parseInt(P ?? "0") || f.removeItem("sprig.isCapturingHeatmap"), f.getItem("sprig.teardownAfterCapture") && (Le(), Ze(), f.removeItem("sprig.teardownAfterCapture"));
661
+ }, Ze = async () => b() ? d.debug("ReplayDisabled-ClearData") : Promise.all([u.deleteBySessionId("events", h), u.deleteBySessionId("pendingCaptures", h)]).catch((e) => {
662
+ J("Error clearing user replay data", e);
663
+ }), et = async (e) => {
566
664
  if (b())
567
665
  return;
568
- const { isHeatmap: t, surveyId: n } = e, a = await l.getPendingCaptures(), r = a == null ? void 0 : a.filter((i) => i.captureParams.surveyId === n);
666
+ const { isHeatmap: t, surveyId: n } = e, a = await u.getPendingCaptures(), r = a == null ? void 0 : a.filter((i) => i.captureParams.surveyId === n);
569
667
  if (r != null && r.length)
570
- return void u.info("PendingCaptureExists", { surveyId: n });
571
- t && (p.isRecording && I(() => {
572
- var i, c;
573
- return (c = (i = window.rrwebRecord) == null ? void 0 : i.takeFullSnapshot) == null ? void 0 : c.call(i, !0);
574
- }, "Error recording full snapshot"), f.setItem("sprig.isCapturingHeatmap", "true"), J = Date.now(), p.inactivityInterval || (p.inactivityInterval = window.setInterval(() => {
668
+ return void d.info("PendingCaptureExists", { surveyId: n });
669
+ t && (w.isRecording && I(() => {
670
+ var i, l;
671
+ return (l = (i = window.rrwebRecord) == null ? void 0 : i.takeFullSnapshot) == null ? void 0 : l.call(i, !0);
672
+ }, "Error recording full snapshot"), f.setItem("sprig.isCapturingHeatmap", "true"), de = Date.now(), w.inactivityInterval || (w.inactivityInterval = window.setInterval(() => {
575
673
  var i;
576
- i = J, Date.now() - i >= 3e4 && I(() => l.markPendingHeatmapsReady(), "Error in heatmap inactivity");
674
+ i = de, Date.now() - i >= 3e4 && I(() => u.markPendingHeatmapsReady(), "Error in heatmap inactivity");
577
675
  }, 1e3)));
578
- const s = { ...e, replayParams: { ...e.replayParams } };
579
- e.replayParams.replayDurationType === "beforeAndAfter" && (s.replayParams.replayDurationSeconds *= 2), s.replayParams.replayDurationType = "before";
580
- const o = e.triggerTimestamp + 1e3 * e.replayParams.replayDurationSeconds;
581
- s.triggerTimestamp = o, k = (parseInt(k ?? "0") + 1).toString(), f.setItem("sprig.pendingCount", k), await (await l.openDB()).add("pendingCaptures", { canUpload: !1, captureParams: s, sessionId: y, targetTimestamp: o, timestamp: Date.now(), uuid: N() });
582
- };
583
- Le(Object.freeze(Object.defineProperty({ __proto__: null, RecordEvent: (e) => {
676
+ const o = { ...e, replayParams: { ...e.replayParams } };
677
+ e.replayParams.replayDurationType === "beforeAndAfter" && (o.replayParams.replayDurationSeconds *= 2), o.replayParams.replayDurationType = "before";
678
+ const s = e.triggerTimestamp + 1e3 * e.replayParams.replayDurationSeconds;
679
+ o.triggerTimestamp = s, P = (parseInt(P ?? "0") + 1).toString(), f.setItem("sprig.pendingCount", P), await (await u.openDB()).add("pendingCaptures", { canUpload: !1, captureParams: o, sessionId: h, targetTimestamp: s, timestamp: Date.now(), uuid: W() });
680
+ }, $t = Object.freeze(Object.defineProperty({ __proto__: null, RecordEvent: (e) => {
584
681
  D("Sprig_TrackEvent", e);
585
682
  }, RecordPageView: (e) => {
586
- e.description && (e.description = Z(e.description)), D("Sprig_PageView", e);
683
+ e.description && (e.description = pe(e.description)), D("Sprig_PageView", e);
587
684
  }, RecordSurveyShown: (e) => {
588
685
  D("Sprig_ShowSurvey", e);
589
686
  }, _completeSessionReplay: async ({ surveyId: e, responseGroupUuid: t, eventDigest: n, headers: a }) => {
590
687
  if (!e || !t)
591
688
  return !1;
592
- const r = window.UserLeap._API_URL, s = await pe({ surveyId: e, responseGroupUuid: t, eventDigest: n, apiUrl: r, headers: a }, !0);
593
- return !(s != null && s.error);
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 }) => !Ae(t)).map(({ uuid: t }) => t);
596
- return u.info("PendingHeatmapsToComplete", { count: e.length }), e.length && (await l.markPendingHeatmapsReady(e), u.info("MarkedPendingHeatmapsReady")), e.length;
597
- }, "Error marking pending heatmaps ready"), clearUserReplayData: xe, disableRecording: L, initializeReplay: async ({ maxReplayDurationSeconds: e, maxInflightRequests: t = 2, replaySettings: n, teardownAfter: a = !1 }) => {
598
- if (k = f.getItem("sprig.pendingCount"), !p.isRecording) {
599
- if (a && f.setItem("sprig.teardownAfterCapture", "true"), b())
600
- return u.debug("ReplayDisabled");
601
- if (await (async () => {
602
- var r;
603
- if (!be())
689
+ const r = window.UserLeap._API_URL, o = await xe({ surveyId: e, responseGroupUuid: t, eventDigest: n, apiUrl: r, headers: a }, !0);
690
+ return !(o != null && o.error);
691
+ }, checkPendingHeatmapsUrl: () => b() ? d.debug("ReplayDisabled-PendingHeatmaps") : I(async () => {
692
+ const e = (await u.getPendingCaptures({ isHeatmap: !0 })).map((t) => ({ eventId: t.captureParams.eventId, uuid: t.uuid })).filter(({ eventId: t }) => !at(t)).map(({ uuid: t }) => t);
693
+ return d.info("PendingHeatmapsToComplete", { count: e.length }), e.length && (await u.markPendingHeatmapsReady(e), d.info("MarkedPendingHeatmapsReady")), e.length;
694
+ }, "Error marking pending heatmaps ready"), clearUserReplayData: Ze, disableRecording: J, initializeReplay: async ({ maxReplayDurationSeconds: e, maxInflightRequests: t = 2, replaySettings: n, teardownAfter: a = !1, apiUrl: r, alwaysOnConfig: o }) => {
695
+ if (o && xt({ apiUrl: r, config: o, triggerSnapshot: () => {
696
+ var i;
697
+ return (i = window.rrwebRecord) == null ? void 0 : i.takeFullSnapshot(!0);
698
+ } }), P = f.getItem("sprig.pendingCount"), w.isRecording)
699
+ return;
700
+ if (a && f.setItem("sprig.teardownAfterCapture", "true"), b())
701
+ return d.debug("ReplayDisabled");
702
+ if (await (async () => {
703
+ var i;
704
+ if (!Ne())
705
+ return !0;
706
+ if ((i = window.navigator.storage) != null && i.estimate)
707
+ try {
708
+ const { quota: l = 0, usage: y = 0 } = await window.navigator.storage.estimate(), p = (l - y) / 1024 ** 3;
709
+ return d.info("Storage", { availableGb: p }), p < 0.5;
710
+ } catch {
604
711
  return !0;
605
- if ((r = window.navigator.storage) != null && r.estimate)
606
- try {
607
- const { quota: s = 0, usage: o = 0 } = await window.navigator.storage.estimate(), d = (s - o) / 1024 ** 3;
608
- return u.info("Storage", { availableGb: d }), d < 0.5;
609
- } catch {
610
- return !0;
611
- }
612
- return !1;
613
- })())
614
- return u.debug("IDBNotSupported"), q();
615
- try {
616
- const r = await l.openDB();
617
- u.info("DBVersion", { version: r.version });
618
- } catch (r) {
619
- return u.error("ReplayOpenErr", { name: r.name }), r.name === "VersionError" && l.deleteDB(), q();
620
- }
621
- if (I(async () => {
622
- await Y(!0);
623
- }, "Error uploading ready pending captures"), !e)
624
- return u.debug("MissingDuration");
625
- u.debug("ReplayInit"), await I(async () => {
626
- var r;
627
- if (n != null && n.minDuration && (Ee = n.minDuration), n != null && n.batchDuration && (z = n.batchDuration), r = t, le.setLimit(r), ct(), ot(e + 35, 1800, e + 35), it(), !window.rrwebRecord) {
628
- const { record: i } = await import(
629
- /* webpackIgnore: true */
630
- /* @vite-ignore */
631
- window.UserLeap.replayLibraryURL ?? "https://cdn.sprig.com/dependencies/record-2.0.0-alpha.17.min.js"
632
- );
633
- window.rrwebRecord = i;
634
712
  }
635
- const s = window.rrwebRecord;
636
- if (!s)
637
- return u.error("RecordScriptFailed");
638
- let o = !0, d = 0;
639
- p.stopRecording = s({ checkoutEveryNms: 3e4, sampling: { input: "last", scroll: 250, media: 800 }, emit: (i, c) => {
640
- if (i.type === R.Custom && (J = Date.now()), b())
641
- return;
642
- if (c && i.type === R.Meta)
643
- d = performance.now();
644
- else if (c && d && i.type === R.FullSnapshot) {
645
- const g = performance.now() - d;
646
- Ne("sdk_replay_snapshot_seconds", g / 1e3);
647
- }
648
- const w = o || !!c && i.type === R.Meta;
649
- o = !1, rt({ uuid: N(), event: JSON.stringify(i), isValidStart: w, timestamp: Date.now() });
650
- }, ...n }), p.isRecording = !!p.stopRecording, p.isRecording && (T.on("survey.complete", (i) => {
651
- var c;
652
- c = { id: i, userAgent: window.navigator.userAgent }, D("Sprig_SubmitSurvey", c);
653
- }), Qe());
654
- }, "Error initializing replay");
713
+ return !1;
714
+ })())
715
+ return d.debug("IDBNotSupported"), se();
716
+ try {
717
+ const i = await u.openDB();
718
+ d.info("DBVersion", { version: i.version });
719
+ } catch (i) {
720
+ return d.error("ReplayOpenErr", { name: i.name }), i.name === "VersionError" && u.deleteDB(), se();
655
721
  }
656
- }, isReplayRecording: () => p.isRecording, scheduleCapture: Ue, scheduleOrCaptureReplay: Be, tryReplayAction: I, uploadReadyPendingCaptures: Y }, Symbol.toStringTag, { value: "Module" })));
722
+ I(async () => {
723
+ await ue(!0);
724
+ }, "Error uploading ready pending captures");
725
+ const s = A() ? 30 : 0, c = Math.max(e ?? 0, s);
726
+ if (!c)
727
+ return d.debug("MissingDuration");
728
+ d.debug("ReplayInit"), await I(async () => {
729
+ var i;
730
+ if (n != null && n.minDuration && (qe = n.minDuration), n != null && n.batchDuration && (ie = n.batchDuration), i = t, Ue.setLimit(i), jt(), Ot(c + 35, 1800, c + 35), Ft(), !window.rrwebRecord) {
731
+ const { record: m } = await import(
732
+ /* webpackIgnore: true */
733
+ /* @vite-ignore */
734
+ window.UserLeap.replayLibraryURL ?? "https://cdn.sprig.com/dependencies/record-2.0.0-alpha.17.min.js"
735
+ );
736
+ window.rrwebRecord = m;
737
+ }
738
+ const l = window.rrwebRecord;
739
+ if (!l)
740
+ return d.error("RecordScriptFailed");
741
+ let y = !0, p = 0;
742
+ w.stopRecording = l({ checkoutEveryNms: 3e4, sampling: { input: "last", scroll: 250, media: 800 }, emit: (m, g) => {
743
+ if (m.type === U.Custom && (de = Date.now()), b())
744
+ return;
745
+ if (g && m.type === U.Meta)
746
+ p = performance.now();
747
+ else if (g && p && m.type === U.FullSnapshot) {
748
+ const k = performance.now() - p;
749
+ ot("sdk_replay_snapshot_seconds", k / 1e3);
750
+ }
751
+ const v = y || !!g && m.type === U.Meta;
752
+ y = !1, _t(v, m), Nt({ uuid: W(), event: JSON.stringify(m), isValidStart: v, timestamp: Date.now() });
753
+ }, ...n }), w.isRecording = !!w.stopRecording, w.isRecording && (F.on("survey.complete", (m) => {
754
+ var g;
755
+ g = { id: m, userAgent: window.navigator.userAgent }, D("Sprig_SubmitSurvey", g);
756
+ }), vt());
757
+ }, "Error initializing replay");
758
+ }, isReplayRecording: () => w.isRecording, scheduleCapture: et, scheduleOrCaptureReplay: Ye, tryReplayAction: I, uploadReadyPendingCaptures: ue }, Symbol.toStringTag, { value: "Module" }));
759
+ st($t);