@extn/segi-js 0.2.3 → 0.2.5
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/index.js
CHANGED
|
@@ -367,7 +367,7 @@ async function activateReplay(args) {
|
|
|
367
367
|
setTimeout(onIdle, 5e3);
|
|
368
368
|
}
|
|
369
369
|
};
|
|
370
|
-
void Promise.resolve().then(() => _interopRequireWildcard(require("../rrweb-
|
|
370
|
+
void Promise.resolve().then(() => _interopRequireWildcard(require("../rrweb-KAUSOLTH.js"))).then(
|
|
371
371
|
({ startRrweb }) => new Promise((resolve) => {
|
|
372
372
|
scheduleRrwebStart(() => {
|
|
373
373
|
startRrweb({
|
|
@@ -375,19 +375,52 @@ async function activateReplay(args) {
|
|
|
375
375
|
options,
|
|
376
376
|
sendChunk: async (chunk, useBeacon) => {
|
|
377
377
|
if (!active || active.replayBlocked) return;
|
|
378
|
+
const bodyStr = `{"sessionUid":${JSON.stringify(sessionUid)},"chunk":[${chunk.join(",")}]}`;
|
|
379
|
+
const base = (transportCfg.endpoint || "https://segiapi.extn.ai").replace(/\/+$/, "").replace(/\/api\/ingest\/events$/, "").replace(/\/api\/ingest$/, "").replace(/\/api$/, "");
|
|
378
380
|
if (useBeacon) {
|
|
379
|
-
|
|
381
|
+
try {
|
|
382
|
+
const url = `${base}/api/trace/replay?pk=${encodeURIComponent(transportCfg.projectKey)}`;
|
|
383
|
+
const blob = new Blob([bodyStr], {
|
|
384
|
+
type: "application/json"
|
|
385
|
+
});
|
|
386
|
+
if (typeof navigator !== "undefined" && typeof navigator.sendBeacon === "function") {
|
|
387
|
+
navigator.sendBeacon(url, blob);
|
|
388
|
+
}
|
|
389
|
+
} catch (e12) {
|
|
390
|
+
}
|
|
380
391
|
return;
|
|
381
392
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
393
|
+
try {
|
|
394
|
+
const res = await fetch(`${base}/api/trace/replay`, {
|
|
395
|
+
method: "POST",
|
|
396
|
+
headers: {
|
|
397
|
+
"Content-Type": "application/json",
|
|
398
|
+
"X-Segi-Project-Key": transportCfg.projectKey
|
|
399
|
+
},
|
|
400
|
+
body: bodyStr,
|
|
401
|
+
keepalive: true
|
|
402
|
+
});
|
|
403
|
+
if (typeof console !== "undefined") {
|
|
404
|
+
console.log(
|
|
405
|
+
"[segi.replay] /replay POST",
|
|
406
|
+
res.status,
|
|
407
|
+
bodyStr.length,
|
|
408
|
+
"bytes"
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
if (res.status === 429) {
|
|
412
|
+
if (active) {
|
|
413
|
+
active.replayBlocked = true;
|
|
414
|
+
_optionalChain([active, 'access', _28 => _28.rrweb, 'optionalAccess', _29 => _29.stop, 'call', _30 => _30()]);
|
|
415
|
+
active.rrweb = null;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
} catch (err) {
|
|
419
|
+
if (typeof console !== "undefined") {
|
|
420
|
+
console.log(
|
|
421
|
+
"[segi.replay] /replay POST FETCH FAILED:",
|
|
422
|
+
err.message
|
|
423
|
+
);
|
|
391
424
|
}
|
|
392
425
|
}
|
|
393
426
|
}
|
package/dist/replay/index.mjs
CHANGED
|
@@ -367,7 +367,7 @@ async function activateReplay(args) {
|
|
|
367
367
|
setTimeout(onIdle, 5e3);
|
|
368
368
|
}
|
|
369
369
|
};
|
|
370
|
-
void import("../rrweb-
|
|
370
|
+
void import("../rrweb-DCBIDQEX.mjs").then(
|
|
371
371
|
({ startRrweb }) => new Promise((resolve) => {
|
|
372
372
|
scheduleRrwebStart(() => {
|
|
373
373
|
startRrweb({
|
|
@@ -375,19 +375,52 @@ async function activateReplay(args) {
|
|
|
375
375
|
options,
|
|
376
376
|
sendChunk: async (chunk, useBeacon) => {
|
|
377
377
|
if (!active || active.replayBlocked) return;
|
|
378
|
+
const bodyStr = `{"sessionUid":${JSON.stringify(sessionUid)},"chunk":[${chunk.join(",")}]}`;
|
|
379
|
+
const base = (transportCfg.endpoint || "https://segiapi.extn.ai").replace(/\/+$/, "").replace(/\/api\/ingest\/events$/, "").replace(/\/api\/ingest$/, "").replace(/\/api$/, "");
|
|
378
380
|
if (useBeacon) {
|
|
379
|
-
|
|
381
|
+
try {
|
|
382
|
+
const url = `${base}/api/trace/replay?pk=${encodeURIComponent(transportCfg.projectKey)}`;
|
|
383
|
+
const blob = new Blob([bodyStr], {
|
|
384
|
+
type: "application/json"
|
|
385
|
+
});
|
|
386
|
+
if (typeof navigator !== "undefined" && typeof navigator.sendBeacon === "function") {
|
|
387
|
+
navigator.sendBeacon(url, blob);
|
|
388
|
+
}
|
|
389
|
+
} catch {
|
|
390
|
+
}
|
|
380
391
|
return;
|
|
381
392
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
393
|
+
try {
|
|
394
|
+
const res = await fetch(`${base}/api/trace/replay`, {
|
|
395
|
+
method: "POST",
|
|
396
|
+
headers: {
|
|
397
|
+
"Content-Type": "application/json",
|
|
398
|
+
"X-Segi-Project-Key": transportCfg.projectKey
|
|
399
|
+
},
|
|
400
|
+
body: bodyStr,
|
|
401
|
+
keepalive: true
|
|
402
|
+
});
|
|
403
|
+
if (typeof console !== "undefined") {
|
|
404
|
+
console.log(
|
|
405
|
+
"[segi.replay] /replay POST",
|
|
406
|
+
res.status,
|
|
407
|
+
bodyStr.length,
|
|
408
|
+
"bytes"
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
if (res.status === 429) {
|
|
412
|
+
if (active) {
|
|
413
|
+
active.replayBlocked = true;
|
|
414
|
+
active.rrweb?.stop();
|
|
415
|
+
active.rrweb = null;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
} catch (err) {
|
|
419
|
+
if (typeof console !== "undefined") {
|
|
420
|
+
console.log(
|
|
421
|
+
"[segi.replay] /replay POST FETCH FAILED:",
|
|
422
|
+
err.message
|
|
423
|
+
);
|
|
391
424
|
}
|
|
392
425
|
}
|
|
393
426
|
}
|
|
@@ -48,14 +48,41 @@ async function startRrweb(args) {
|
|
|
48
48
|
}, IDLE_CHECK_MS);
|
|
49
49
|
function startRecorder() {
|
|
50
50
|
if (stopFn) return;
|
|
51
|
+
let emitCount = 0;
|
|
52
|
+
const log = (...args2) => {
|
|
53
|
+
if (typeof console !== "undefined") {
|
|
54
|
+
console.log("[segi.replay]", ...args2);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
log("startRecorder() called, rrweb keys:", Object.keys(rrweb).slice(0, 12));
|
|
51
58
|
const stop = rrweb.record({
|
|
52
59
|
emit(event) {
|
|
60
|
+
emitCount++;
|
|
61
|
+
const e = event;
|
|
53
62
|
if (paused || stopped) return;
|
|
54
|
-
|
|
63
|
+
let serialized;
|
|
55
64
|
try {
|
|
56
|
-
|
|
57
|
-
} catch {
|
|
65
|
+
serialized = JSON.stringify(event);
|
|
66
|
+
} catch (err) {
|
|
67
|
+
log(
|
|
68
|
+
`emit #${emitCount} type:${e.type} source:${e.data?.source} STRINGIFY_FAILED:`,
|
|
69
|
+
err.message
|
|
70
|
+
);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (emitCount <= 10) {
|
|
74
|
+
log(
|
|
75
|
+
`emit #${emitCount}`,
|
|
76
|
+
"type:",
|
|
77
|
+
e.type,
|
|
78
|
+
"source:",
|
|
79
|
+
e.data?.source,
|
|
80
|
+
"size:",
|
|
81
|
+
serialized.length
|
|
82
|
+
);
|
|
58
83
|
}
|
|
84
|
+
buffer.push(serialized);
|
|
85
|
+
bufferBytes += serialized.length;
|
|
59
86
|
if (bufferBytes >= FLUSH_BYTES) flush();
|
|
60
87
|
},
|
|
61
88
|
// `input: "last"` emits only the final value of each keystroke
|
|
@@ -69,23 +96,42 @@ async function startRrweb(args) {
|
|
|
69
96
|
maskTextClass: maskClass,
|
|
70
97
|
recordCanvas: false,
|
|
71
98
|
collectFonts: false,
|
|
72
|
-
checkoutEveryNms: CHECKOUT_EVERY_MS
|
|
73
|
-
//
|
|
74
|
-
//
|
|
75
|
-
//
|
|
76
|
-
//
|
|
77
|
-
//
|
|
78
|
-
inlineStylesheet: true
|
|
99
|
+
checkoutEveryNms: CHECKOUT_EVERY_MS
|
|
100
|
+
// inlineStylesheet intentionally NOT set explicitly; in
|
|
101
|
+
// 2.0.0-alpha.20 the default is `true` but setting it explicitly
|
|
102
|
+
// appears to defer the initial FullSnapshot until all stylesheet
|
|
103
|
+
// fetches complete (or fail). Leaving the default makes rrweb
|
|
104
|
+
// emit the FullSnapshot immediately and inline async-best-effort.
|
|
79
105
|
});
|
|
80
106
|
stopFn = typeof stop === "function" ? stop : null;
|
|
81
|
-
|
|
107
|
+
log(
|
|
108
|
+
"record() returned, stopFn:",
|
|
109
|
+
typeof stop,
|
|
110
|
+
"rrweb.record.takeFullSnapshot:",
|
|
111
|
+
typeof rrweb.record.takeFullSnapshot,
|
|
112
|
+
"rrweb.takeFullSnapshot:",
|
|
113
|
+
typeof rrweb.takeFullSnapshot
|
|
114
|
+
);
|
|
115
|
+
const forceSnapshot = (label) => {
|
|
82
116
|
if (stopped || paused) return;
|
|
83
117
|
try {
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
118
|
+
const rrwebMod = rrweb;
|
|
119
|
+
if (typeof rrwebMod.record.takeFullSnapshot === "function") {
|
|
120
|
+
log(`forceSnapshot[${label}] via record.takeFullSnapshot`);
|
|
121
|
+
rrwebMod.record.takeFullSnapshot(true);
|
|
122
|
+
} else if (typeof rrwebMod.takeFullSnapshot === "function") {
|
|
123
|
+
log(`forceSnapshot[${label}] via top-level takeFullSnapshot`);
|
|
124
|
+
rrwebMod.takeFullSnapshot(true);
|
|
125
|
+
} else {
|
|
126
|
+
log(`forceSnapshot[${label}] no takeFullSnapshot found`);
|
|
127
|
+
}
|
|
128
|
+
} catch (err) {
|
|
129
|
+
log(`forceSnapshot[${label}] threw:`, err);
|
|
87
130
|
}
|
|
88
|
-
}
|
|
131
|
+
};
|
|
132
|
+
setTimeout(() => forceSnapshot("100ms"), 100);
|
|
133
|
+
setTimeout(() => forceSnapshot("500ms"), 500);
|
|
134
|
+
setTimeout(() => forceSnapshot("2000ms"), 2e3);
|
|
89
135
|
}
|
|
90
136
|
function stopRrwebOnly() {
|
|
91
137
|
try {
|
|
@@ -100,6 +146,25 @@ async function startRrweb(args) {
|
|
|
100
146
|
const chunk = buffer;
|
|
101
147
|
buffer = [];
|
|
102
148
|
bufferBytes = 0;
|
|
149
|
+
if (typeof console !== "undefined") {
|
|
150
|
+
const totalSize = chunk.reduce((a, s) => a + s.length, 0);
|
|
151
|
+
const types = {};
|
|
152
|
+
for (const s of chunk) {
|
|
153
|
+
const m = s.match(/^\{"type":(\d+)/);
|
|
154
|
+
const t = m ? m[1] : "?";
|
|
155
|
+
types[t] = (types[t] ?? 0) + 1;
|
|
156
|
+
}
|
|
157
|
+
console.log(
|
|
158
|
+
"[segi.replay] flush:",
|
|
159
|
+
chunk.length,
|
|
160
|
+
"events,",
|
|
161
|
+
totalSize,
|
|
162
|
+
"bytes, types:",
|
|
163
|
+
types,
|
|
164
|
+
"useBeacon:",
|
|
165
|
+
useBeacon
|
|
166
|
+
);
|
|
167
|
+
}
|
|
103
168
|
try {
|
|
104
169
|
args.sendChunk(chunk, useBeacon);
|
|
105
170
|
} catch {
|
|
@@ -17,7 +17,7 @@ async function startRrweb(args) {
|
|
|
17
17
|
let rrweb;
|
|
18
18
|
try {
|
|
19
19
|
rrweb = await Promise.resolve().then(() => _interopRequireWildcard(require("rrweb")));
|
|
20
|
-
} catch (
|
|
20
|
+
} catch (e2) {
|
|
21
21
|
return null;
|
|
22
22
|
}
|
|
23
23
|
const maskClass = _nullishCoalesce(_optionalChain([args, 'access', _ => _.options, 'access', _2 => _2.mask, 'optionalAccess', _3 => _3.class]), () => ( "segi-mask"));
|
|
@@ -48,14 +48,41 @@ async function startRrweb(args) {
|
|
|
48
48
|
}, IDLE_CHECK_MS);
|
|
49
49
|
function startRecorder() {
|
|
50
50
|
if (stopFn) return;
|
|
51
|
+
let emitCount = 0;
|
|
52
|
+
const log = (...args2) => {
|
|
53
|
+
if (typeof console !== "undefined") {
|
|
54
|
+
console.log("[segi.replay]", ...args2);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
log("startRecorder() called, rrweb keys:", Object.keys(rrweb).slice(0, 12));
|
|
51
58
|
const stop = rrweb.record({
|
|
52
59
|
emit(event) {
|
|
60
|
+
emitCount++;
|
|
61
|
+
const e = event;
|
|
53
62
|
if (paused || stopped) return;
|
|
54
|
-
|
|
63
|
+
let serialized;
|
|
55
64
|
try {
|
|
56
|
-
|
|
57
|
-
} catch (
|
|
65
|
+
serialized = JSON.stringify(event);
|
|
66
|
+
} catch (err) {
|
|
67
|
+
log(
|
|
68
|
+
`emit #${emitCount} type:${e.type} source:${_optionalChain([e, 'access', _7 => _7.data, 'optionalAccess', _8 => _8.source])} STRINGIFY_FAILED:`,
|
|
69
|
+
err.message
|
|
70
|
+
);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (emitCount <= 10) {
|
|
74
|
+
log(
|
|
75
|
+
`emit #${emitCount}`,
|
|
76
|
+
"type:",
|
|
77
|
+
e.type,
|
|
78
|
+
"source:",
|
|
79
|
+
_optionalChain([e, 'access', _9 => _9.data, 'optionalAccess', _10 => _10.source]),
|
|
80
|
+
"size:",
|
|
81
|
+
serialized.length
|
|
82
|
+
);
|
|
58
83
|
}
|
|
84
|
+
buffer.push(serialized);
|
|
85
|
+
bufferBytes += serialized.length;
|
|
59
86
|
if (bufferBytes >= FLUSH_BYTES) flush();
|
|
60
87
|
},
|
|
61
88
|
// `input: "last"` emits only the final value of each keystroke
|
|
@@ -69,27 +96,46 @@ async function startRrweb(args) {
|
|
|
69
96
|
maskTextClass: maskClass,
|
|
70
97
|
recordCanvas: false,
|
|
71
98
|
collectFonts: false,
|
|
72
|
-
checkoutEveryNms: CHECKOUT_EVERY_MS
|
|
73
|
-
//
|
|
74
|
-
//
|
|
75
|
-
//
|
|
76
|
-
//
|
|
77
|
-
//
|
|
78
|
-
inlineStylesheet: true
|
|
99
|
+
checkoutEveryNms: CHECKOUT_EVERY_MS
|
|
100
|
+
// inlineStylesheet intentionally NOT set explicitly; in
|
|
101
|
+
// 2.0.0-alpha.20 the default is `true` but setting it explicitly
|
|
102
|
+
// appears to defer the initial FullSnapshot until all stylesheet
|
|
103
|
+
// fetches complete (or fail). Leaving the default makes rrweb
|
|
104
|
+
// emit the FullSnapshot immediately and inline async-best-effort.
|
|
79
105
|
});
|
|
80
106
|
stopFn = typeof stop === "function" ? stop : null;
|
|
81
|
-
|
|
107
|
+
log(
|
|
108
|
+
"record() returned, stopFn:",
|
|
109
|
+
typeof stop,
|
|
110
|
+
"rrweb.record.takeFullSnapshot:",
|
|
111
|
+
typeof rrweb.record.takeFullSnapshot,
|
|
112
|
+
"rrweb.takeFullSnapshot:",
|
|
113
|
+
typeof rrweb.takeFullSnapshot
|
|
114
|
+
);
|
|
115
|
+
const forceSnapshot = (label) => {
|
|
82
116
|
if (stopped || paused) return;
|
|
83
117
|
try {
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
118
|
+
const rrwebMod = rrweb;
|
|
119
|
+
if (typeof rrwebMod.record.takeFullSnapshot === "function") {
|
|
120
|
+
log(`forceSnapshot[${label}] via record.takeFullSnapshot`);
|
|
121
|
+
rrwebMod.record.takeFullSnapshot(true);
|
|
122
|
+
} else if (typeof rrwebMod.takeFullSnapshot === "function") {
|
|
123
|
+
log(`forceSnapshot[${label}] via top-level takeFullSnapshot`);
|
|
124
|
+
rrwebMod.takeFullSnapshot(true);
|
|
125
|
+
} else {
|
|
126
|
+
log(`forceSnapshot[${label}] no takeFullSnapshot found`);
|
|
127
|
+
}
|
|
128
|
+
} catch (err) {
|
|
129
|
+
log(`forceSnapshot[${label}] threw:`, err);
|
|
87
130
|
}
|
|
88
|
-
}
|
|
131
|
+
};
|
|
132
|
+
setTimeout(() => forceSnapshot("100ms"), 100);
|
|
133
|
+
setTimeout(() => forceSnapshot("500ms"), 500);
|
|
134
|
+
setTimeout(() => forceSnapshot("2000ms"), 2e3);
|
|
89
135
|
}
|
|
90
136
|
function stopRrwebOnly() {
|
|
91
137
|
try {
|
|
92
|
-
_optionalChain([stopFn, 'optionalCall',
|
|
138
|
+
_optionalChain([stopFn, 'optionalCall', _11 => _11()]);
|
|
93
139
|
} finally {
|
|
94
140
|
stopFn = null;
|
|
95
141
|
}
|
|
@@ -100,9 +146,28 @@ async function startRrweb(args) {
|
|
|
100
146
|
const chunk = buffer;
|
|
101
147
|
buffer = [];
|
|
102
148
|
bufferBytes = 0;
|
|
149
|
+
if (typeof console !== "undefined") {
|
|
150
|
+
const totalSize = chunk.reduce((a, s) => a + s.length, 0);
|
|
151
|
+
const types = {};
|
|
152
|
+
for (const s of chunk) {
|
|
153
|
+
const m = s.match(/^\{"type":(\d+)/);
|
|
154
|
+
const t = m ? m[1] : "?";
|
|
155
|
+
types[t] = (_nullishCoalesce(types[t], () => ( 0))) + 1;
|
|
156
|
+
}
|
|
157
|
+
console.log(
|
|
158
|
+
"[segi.replay] flush:",
|
|
159
|
+
chunk.length,
|
|
160
|
+
"events,",
|
|
161
|
+
totalSize,
|
|
162
|
+
"bytes, types:",
|
|
163
|
+
types,
|
|
164
|
+
"useBeacon:",
|
|
165
|
+
useBeacon
|
|
166
|
+
);
|
|
167
|
+
}
|
|
103
168
|
try {
|
|
104
169
|
args.sendChunk(chunk, useBeacon);
|
|
105
|
-
} catch (
|
|
170
|
+
} catch (e3) {
|
|
106
171
|
}
|
|
107
172
|
}
|
|
108
173
|
function onActivity() {
|
|
@@ -151,8 +216,8 @@ async function startRrweb(args) {
|
|
|
151
216
|
if (stopped || paused) return;
|
|
152
217
|
try {
|
|
153
218
|
const rec = rrweb.record;
|
|
154
|
-
_optionalChain([rec, 'access',
|
|
155
|
-
} catch (
|
|
219
|
+
_optionalChain([rec, 'access', _12 => _12.takeFullSnapshot, 'optionalCall', _13 => _13()]);
|
|
220
|
+
} catch (e4) {
|
|
156
221
|
}
|
|
157
222
|
}
|
|
158
223
|
};
|