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