@extn/segi-js 0.2.16 → 0.2.18
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/README.md +191 -54
- package/dist/cdn.global.js +37 -37
- package/dist/chunk-USYEDAPQ.js +41 -0
- package/dist/chunk-YOSYA5HJ.mjs +41 -0
- package/dist/index.d.mts +31 -2
- package/dist/index.d.ts +31 -2
- package/dist/index.js +158 -21
- package/dist/index.mjs +146 -9
- package/dist/replay/index.d.mts +10 -2
- package/dist/replay/index.d.ts +10 -2
- package/dist/replay/index.js +48 -14
- package/dist/replay/index.mjs +40 -6
- package/dist/{types-CsgcNSc1.d.mts → types-BU4h40xl.d.mts} +10 -1
- package/dist/{types-CsgcNSc1.d.ts → types-BU4h40xl.d.ts} +10 -1
- package/package.json +3 -2
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import {
|
|
2
|
+
normalizeReplayToken,
|
|
3
|
+
withReplay
|
|
4
|
+
} from "./chunk-YOSYA5HJ.mjs";
|
|
5
|
+
|
|
1
6
|
// src/core.ts
|
|
2
7
|
var DEFAULT_MAX_BREADCRUMBS = 50;
|
|
3
8
|
function createState() {
|
|
@@ -134,6 +139,104 @@ function send(endpoint, projectKey, event) {
|
|
|
134
139
|
}
|
|
135
140
|
}
|
|
136
141
|
|
|
142
|
+
// src/normalize-error.ts
|
|
143
|
+
var MAX_JSON_MESSAGE = 1e3;
|
|
144
|
+
function str(v) {
|
|
145
|
+
return typeof v === "string" && v.trim().length > 0 ? v : null;
|
|
146
|
+
}
|
|
147
|
+
function withMeta(e, o) {
|
|
148
|
+
const name = str(o.name) ?? (typeof o.code === "string" ? o.code : null);
|
|
149
|
+
if (name) {
|
|
150
|
+
try {
|
|
151
|
+
e.name = name;
|
|
152
|
+
} catch {
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const stack = str(o.stack);
|
|
156
|
+
if (stack) {
|
|
157
|
+
try {
|
|
158
|
+
e.stack = stack;
|
|
159
|
+
} catch {
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return e;
|
|
163
|
+
}
|
|
164
|
+
function hasContent(v, depth = 0, seen = /* @__PURE__ */ new Set()) {
|
|
165
|
+
if (v === null || v === void 0) return false;
|
|
166
|
+
switch (typeof v) {
|
|
167
|
+
case "string":
|
|
168
|
+
return v.trim().length > 0;
|
|
169
|
+
case "number":
|
|
170
|
+
case "boolean":
|
|
171
|
+
case "bigint":
|
|
172
|
+
return true;
|
|
173
|
+
case "object":
|
|
174
|
+
break;
|
|
175
|
+
default:
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
if (depth > 4 || seen.has(v)) return false;
|
|
179
|
+
seen.add(v);
|
|
180
|
+
try {
|
|
181
|
+
for (const k of Object.keys(v)) {
|
|
182
|
+
if (hasContent(v[k], depth + 1, seen)) return true;
|
|
183
|
+
}
|
|
184
|
+
} catch {
|
|
185
|
+
}
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
function normalizeError(value) {
|
|
189
|
+
if (value instanceof Error) return value;
|
|
190
|
+
if (value === null || value === void 0) return null;
|
|
191
|
+
switch (typeof value) {
|
|
192
|
+
case "string":
|
|
193
|
+
return str(value) ? new Error(value) : null;
|
|
194
|
+
case "number":
|
|
195
|
+
case "boolean":
|
|
196
|
+
case "bigint":
|
|
197
|
+
return new Error(String(value));
|
|
198
|
+
case "symbol":
|
|
199
|
+
return new Error(value.toString());
|
|
200
|
+
case "function":
|
|
201
|
+
return null;
|
|
202
|
+
case "object":
|
|
203
|
+
break;
|
|
204
|
+
default:
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
const o = value;
|
|
208
|
+
if (o.error !== void 0 && o.error !== value) {
|
|
209
|
+
const inner = normalizeError(o.error);
|
|
210
|
+
if (inner) return inner;
|
|
211
|
+
}
|
|
212
|
+
if (o.reason !== void 0 && o.reason !== value) {
|
|
213
|
+
const inner = normalizeError(o.reason);
|
|
214
|
+
if (inner) return inner;
|
|
215
|
+
}
|
|
216
|
+
const message = str(o.message) ?? str(o.description) ?? str(o.msg);
|
|
217
|
+
if (message) return withMeta(new Error(message), o);
|
|
218
|
+
let json;
|
|
219
|
+
try {
|
|
220
|
+
json = hasContent(value) ? JSON.stringify(value) : void 0;
|
|
221
|
+
} catch {
|
|
222
|
+
json = void 0;
|
|
223
|
+
}
|
|
224
|
+
if (json && json !== "{}" && json !== "[]" && json !== "null") {
|
|
225
|
+
return withMeta(
|
|
226
|
+
new Error(json.length > MAX_JSON_MESSAGE ? `${json.slice(0, MAX_JSON_MESSAGE)}\u2026` : json),
|
|
227
|
+
o
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
try {
|
|
231
|
+
const s = String(value);
|
|
232
|
+
if (s && !/^\[object [A-Za-z]+\]$/.test(s) && s !== "{}") {
|
|
233
|
+
return withMeta(new Error(s), o);
|
|
234
|
+
}
|
|
235
|
+
} catch {
|
|
236
|
+
}
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
|
|
137
240
|
// src/index.ts
|
|
138
241
|
var state = createState();
|
|
139
242
|
function safeStack(err) {
|
|
@@ -180,6 +283,7 @@ function detachListeners() {
|
|
|
180
283
|
}
|
|
181
284
|
var pendingReplayErrors = [];
|
|
182
285
|
var replayEnabled = false;
|
|
286
|
+
var replayRequested = false;
|
|
183
287
|
var replayEpoch = 0;
|
|
184
288
|
var noopReplay = {
|
|
185
289
|
_captureError(signal) {
|
|
@@ -216,12 +320,25 @@ var Segi = {
|
|
|
216
320
|
init(options, opts = {}) {
|
|
217
321
|
try {
|
|
218
322
|
const w = typeof window !== "undefined" ? window : null;
|
|
323
|
+
if (!options || options.enabled === false) {
|
|
324
|
+
if (opts.force && state.initialized) Segi.close();
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
const replay = normalizeReplayToken(options.replay);
|
|
328
|
+
const wantsReplay = !!replay && replay.options.enabled !== false;
|
|
219
329
|
const already = state.initialized || w?.__segiInitialized === true;
|
|
220
330
|
if (already && !opts.force) {
|
|
221
331
|
if (!opts.silent && typeof console !== "undefined") {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
332
|
+
const firstHadReplay = state.initialized ? replayRequested : w?.__segiReplayRequested === true;
|
|
333
|
+
if (wantsReplay && !firstHadReplay) {
|
|
334
|
+
console.warn(
|
|
335
|
+
`[segi] init() was already called WITHOUT session replay (first init wins \u2014 often the CDN auto-init from window.SegiConfig or the script's data-project-key), so the replay option of this call was ignored and nothing is being recorded. Fix: enable replay in that first init (window.SegiConfig = { projectKey, replay: true } or data-replay="true" on the script tag) and drop this call, or call Segi.init({...}, { force: true }) to replace the first init.`
|
|
336
|
+
);
|
|
337
|
+
} else {
|
|
338
|
+
console.warn(
|
|
339
|
+
"[segi] init() called more than once; ignoring. Pass { force: true } to override."
|
|
340
|
+
);
|
|
341
|
+
}
|
|
225
342
|
}
|
|
226
343
|
return;
|
|
227
344
|
}
|
|
@@ -230,13 +347,17 @@ var Segi = {
|
|
|
230
347
|
Segi.replay = noopReplay;
|
|
231
348
|
pendingReplayErrors = [];
|
|
232
349
|
const epoch = ++replayEpoch;
|
|
233
|
-
const { replay, ...core } = options;
|
|
234
|
-
replayEnabled =
|
|
350
|
+
const { replay: _ignored, ...core } = options;
|
|
351
|
+
replayEnabled = wantsReplay;
|
|
352
|
+
replayRequested = wantsReplay;
|
|
235
353
|
state.options = { ...core };
|
|
236
354
|
state.initialized = true;
|
|
237
|
-
if (w)
|
|
355
|
+
if (w) {
|
|
356
|
+
w.__segiInitialized = true;
|
|
357
|
+
w.__segiReplayRequested = wantsReplay;
|
|
358
|
+
}
|
|
238
359
|
attachListeners();
|
|
239
|
-
if (replay
|
|
360
|
+
if (replay && wantsReplay) {
|
|
240
361
|
void import("./replay/index.mjs").then((mod) => {
|
|
241
362
|
if (epoch !== replayEpoch || !state.initialized) return;
|
|
242
363
|
Segi.replay = mod.replayApi;
|
|
@@ -261,6 +382,14 @@ var Segi = {
|
|
|
261
382
|
} catch {
|
|
262
383
|
}
|
|
263
384
|
},
|
|
385
|
+
/**
|
|
386
|
+
* Build the replay activation token for `Segi.init({ replay })`. Same as
|
|
387
|
+
* `withReplay` from `@extn/segi-js/replay`; on the CDN global it defaults
|
|
388
|
+
* `trackRoutes` to true.
|
|
389
|
+
*/
|
|
390
|
+
withReplay(options = {}) {
|
|
391
|
+
return withReplay(options);
|
|
392
|
+
},
|
|
264
393
|
/** True if init() has been called successfully on this bundle. */
|
|
265
394
|
isInitialized() {
|
|
266
395
|
return state.initialized;
|
|
@@ -271,6 +400,7 @@ var Segi = {
|
|
|
271
400
|
detachListeners();
|
|
272
401
|
replayEpoch++;
|
|
273
402
|
replayEnabled = false;
|
|
403
|
+
replayRequested = false;
|
|
274
404
|
Segi.replay._stop();
|
|
275
405
|
Segi.replay = noopReplay;
|
|
276
406
|
pendingReplayErrors = [];
|
|
@@ -281,6 +411,7 @@ var Segi = {
|
|
|
281
411
|
if (typeof window !== "undefined") {
|
|
282
412
|
const w = window;
|
|
283
413
|
w.__segiInitialized = false;
|
|
414
|
+
w.__segiReplayRequested = false;
|
|
284
415
|
}
|
|
285
416
|
} catch {
|
|
286
417
|
}
|
|
@@ -288,7 +419,12 @@ var Segi = {
|
|
|
288
419
|
captureException(error, context = {}) {
|
|
289
420
|
try {
|
|
290
421
|
if (!state.initialized) return;
|
|
291
|
-
|
|
422
|
+
let err = normalizeError(error);
|
|
423
|
+
if (!err) {
|
|
424
|
+
const fallback = typeof context.message === "string" ? context.message.trim() : "";
|
|
425
|
+
if (!fallback) return;
|
|
426
|
+
err = new Error(fallback);
|
|
427
|
+
}
|
|
292
428
|
const evt = buildEvent(state, {
|
|
293
429
|
type: "error",
|
|
294
430
|
level: "error",
|
|
@@ -362,5 +498,6 @@ var Segi = {
|
|
|
362
498
|
var src_default = Segi;
|
|
363
499
|
export {
|
|
364
500
|
Segi,
|
|
365
|
-
src_default as default
|
|
501
|
+
src_default as default,
|
|
502
|
+
normalizeError
|
|
366
503
|
};
|
package/dist/replay/index.d.mts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as ReplayOptions, R as ReplayConfig } from '../types-BU4h40xl.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Replay activation token helpers. Kept separate from ./index so the main
|
|
5
|
+
* entry can build/validate tokens without statically importing the replay
|
|
6
|
+
* runtime (which stays behind a dynamic import).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** Build the replay activation token passed as `Segi.init({ replay })`. */
|
|
10
|
+
declare function withReplay(options?: ReplayOptions): ReplayConfig;
|
|
2
11
|
|
|
3
12
|
/**
|
|
4
13
|
* Replay orchestrator. Exposed at `@extn/segi-js/replay`.
|
|
@@ -29,7 +38,6 @@ import { R as ReplayConfig, a as ReplayOptions } from '../types-CsgcNSc1.mjs';
|
|
|
29
38
|
* in pay zero rrweb bytes. Chunks POST to /api/trace/replay.
|
|
30
39
|
*/
|
|
31
40
|
|
|
32
|
-
declare function withReplay(options?: ReplayOptions): ReplayConfig;
|
|
33
41
|
type ErrorSignal = {
|
|
34
42
|
ts: string;
|
|
35
43
|
url?: string;
|
package/dist/replay/index.d.ts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as ReplayOptions, R as ReplayConfig } from '../types-BU4h40xl.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Replay activation token helpers. Kept separate from ./index so the main
|
|
5
|
+
* entry can build/validate tokens without statically importing the replay
|
|
6
|
+
* runtime (which stays behind a dynamic import).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** Build the replay activation token passed as `Segi.init({ replay })`. */
|
|
10
|
+
declare function withReplay(options?: ReplayOptions): ReplayConfig;
|
|
2
11
|
|
|
3
12
|
/**
|
|
4
13
|
* Replay orchestrator. Exposed at `@extn/segi-js/replay`.
|
|
@@ -29,7 +38,6 @@ import { R as ReplayConfig, a as ReplayOptions } from '../types-CsgcNSc1.js';
|
|
|
29
38
|
* in pay zero rrweb bytes. Chunks POST to /api/trace/replay.
|
|
30
39
|
*/
|
|
31
40
|
|
|
32
|
-
declare function withReplay(options?: ReplayOptions): ReplayConfig;
|
|
33
41
|
type ErrorSignal = {
|
|
34
42
|
ts: string;
|
|
35
43
|
url?: string;
|
package/dist/replay/index.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _chunkUSYEDAPQjs = require('../chunk-USYEDAPQ.js');
|
|
4
|
+
|
|
5
|
+
// src/replay/session.ts
|
|
2
6
|
var UID_KEY = "_bd_session_uid";
|
|
3
7
|
var UID_TS_KEY = "_bd_session_at";
|
|
4
8
|
var ANON_KEY = "_bd_anon";
|
|
@@ -122,9 +126,6 @@ function beaconTrace(cfg, path, body) {
|
|
|
122
126
|
}
|
|
123
127
|
|
|
124
128
|
// src/replay/index.ts
|
|
125
|
-
function withReplay(options = {}) {
|
|
126
|
-
return { __segi_replay: true, options };
|
|
127
|
-
}
|
|
128
129
|
async function gzipString(str) {
|
|
129
130
|
try {
|
|
130
131
|
if (typeof CompressionStream === "undefined") return null;
|
|
@@ -167,6 +168,10 @@ function sendError(signal) {
|
|
|
167
168
|
}] });
|
|
168
169
|
}
|
|
169
170
|
var pendingUser = void 0;
|
|
171
|
+
var lastPageViewUrl = null;
|
|
172
|
+
function pageKey(url) {
|
|
173
|
+
return url.split("#")[0];
|
|
174
|
+
}
|
|
170
175
|
function deviceClass() {
|
|
171
176
|
if (typeof window === "undefined") return "desktop";
|
|
172
177
|
const w = window.innerWidth;
|
|
@@ -213,24 +218,47 @@ async function activateReplay(args) {
|
|
|
213
218
|
const epoch = activationEpoch;
|
|
214
219
|
const suspendExcluded = () => {
|
|
215
220
|
if (active && !pathAllowed()) {
|
|
221
|
+
lastPageViewUrl = null;
|
|
216
222
|
active.routePaused = true;
|
|
217
223
|
active.paused = true;
|
|
218
224
|
_optionalChain([active, 'access', _2 => _2.rrweb, 'optionalAccess', _3 => _3.pause, 'call', _4 => _4()]);
|
|
219
225
|
}
|
|
220
226
|
};
|
|
227
|
+
let routeTimer = null;
|
|
228
|
+
let routeTracking = args.config.options.trackRoutes === true;
|
|
229
|
+
const trackRoute = () => {
|
|
230
|
+
if (!routeTracking) return;
|
|
231
|
+
if (routeTimer) clearTimeout(routeTimer);
|
|
232
|
+
routeTimer = setTimeout(() => {
|
|
233
|
+
routeTimer = null;
|
|
234
|
+
if (!routeTracking) return;
|
|
235
|
+
try {
|
|
236
|
+
replayApi.notifyRouteChange();
|
|
237
|
+
} catch (e12) {
|
|
238
|
+
}
|
|
239
|
+
}, 100);
|
|
240
|
+
};
|
|
241
|
+
cleanup.push(() => {
|
|
242
|
+
routeTracking = false;
|
|
243
|
+
if (routeTimer) clearTimeout(routeTimer);
|
|
244
|
+
});
|
|
245
|
+
const onHistoryChange = () => {
|
|
246
|
+
suspendExcluded();
|
|
247
|
+
trackRoute();
|
|
248
|
+
};
|
|
221
249
|
for (const method of ["pushState", "replaceState"]) {
|
|
222
250
|
const original = history[method];
|
|
223
251
|
const wrapped = function(...params) {
|
|
224
252
|
original.apply(this, params);
|
|
225
|
-
|
|
253
|
+
onHistoryChange();
|
|
226
254
|
};
|
|
227
255
|
history[method] = wrapped;
|
|
228
256
|
cleanup.push(() => {
|
|
229
257
|
if (history[method] === wrapped) history[method] = original;
|
|
230
258
|
});
|
|
231
259
|
}
|
|
232
|
-
window.addEventListener("popstate",
|
|
233
|
-
cleanup.push(() => window.removeEventListener("popstate",
|
|
260
|
+
window.addEventListener("popstate", onHistoryChange);
|
|
261
|
+
cleanup.push(() => window.removeEventListener("popstate", onHistoryChange));
|
|
234
262
|
let inFlight = false;
|
|
235
263
|
const load = async () => {
|
|
236
264
|
if (inFlight || configured || epoch !== activationEpoch) return;
|
|
@@ -244,7 +272,7 @@ async function activateReplay(args) {
|
|
|
244
272
|
if (epoch !== activationEpoch || typeof policy.recordingEnabled !== "boolean" || !Array.isArray(policy.recordingDenyList) || policy.recordingDenyList.some((p) => typeof p !== "string" || !p.startsWith("/"))) return;
|
|
245
273
|
configured = true;
|
|
246
274
|
clearInterval(timer);
|
|
247
|
-
waiting = { ...args, config: withReplay({
|
|
275
|
+
waiting = { ...args, config: _chunkUSYEDAPQjs.withReplay.call(void 0, {
|
|
248
276
|
...args.config.options,
|
|
249
277
|
blockRoutes: [..._nullishCoalesce(args.config.options.blockRoutes, () => ( [])), ...policy.recordingDenyList]
|
|
250
278
|
}) };
|
|
@@ -255,12 +283,12 @@ async function activateReplay(args) {
|
|
|
255
283
|
pendingErrors = pendingErrors.filter((e) => {
|
|
256
284
|
try {
|
|
257
285
|
return !isPathBlocked(waiting.config.options, new URL(_nullishCoalesce(e.url, () => ( location.href)), location.href).pathname);
|
|
258
|
-
} catch (
|
|
286
|
+
} catch (e13) {
|
|
259
287
|
return false;
|
|
260
288
|
}
|
|
261
289
|
});
|
|
262
290
|
await startWhenAllowed();
|
|
263
|
-
} catch (
|
|
291
|
+
} catch (e14) {
|
|
264
292
|
} finally {
|
|
265
293
|
clearTimeout(timeout);
|
|
266
294
|
inFlight = false;
|
|
@@ -325,7 +353,7 @@ async function startReplay(args) {
|
|
|
325
353
|
const body = await res.json().catch(() => ({}));
|
|
326
354
|
recordingEnabled = body.recordingEnabled === true;
|
|
327
355
|
}
|
|
328
|
-
} catch (
|
|
356
|
+
} catch (e15) {
|
|
329
357
|
}
|
|
330
358
|
if (epoch !== activationEpoch) return;
|
|
331
359
|
if (!recordingEnabled) {
|
|
@@ -420,7 +448,7 @@ async function startReplay(args) {
|
|
|
420
448
|
if (typeof navigator !== "undefined" && typeof navigator.sendBeacon === "function") {
|
|
421
449
|
navigator.sendBeacon(url, blob);
|
|
422
450
|
}
|
|
423
|
-
} catch (
|
|
451
|
+
} catch (e16) {
|
|
424
452
|
}
|
|
425
453
|
return;
|
|
426
454
|
}
|
|
@@ -445,7 +473,7 @@ async function startReplay(args) {
|
|
|
445
473
|
active.rrweb = null;
|
|
446
474
|
}
|
|
447
475
|
}
|
|
448
|
-
} catch (
|
|
476
|
+
} catch (e17) {
|
|
449
477
|
}
|
|
450
478
|
}
|
|
451
479
|
}).then(resolve, () => resolve(null));
|
|
@@ -458,6 +486,7 @@ async function startReplay(args) {
|
|
|
458
486
|
} else _optionalChain([handles, 'optionalAccess', _12 => _12.stop, 'call', _13 => _13()]);
|
|
459
487
|
}).catch(() => {
|
|
460
488
|
});
|
|
489
|
+
if (canCollect()) lastPageViewUrl = pageKey(location.href);
|
|
461
490
|
if (canCollect()) void postTrace(transportCfg, "/events", {
|
|
462
491
|
events: [
|
|
463
492
|
{
|
|
@@ -522,6 +551,7 @@ var replayApi = {
|
|
|
522
551
|
active = null;
|
|
523
552
|
pendingErrors = [];
|
|
524
553
|
pendingUser = void 0;
|
|
554
|
+
lastPageViewUrl = null;
|
|
525
555
|
},
|
|
526
556
|
pause() {
|
|
527
557
|
manualPaused = true;
|
|
@@ -580,6 +610,7 @@ var replayApi = {
|
|
|
580
610
|
bumpSessionActivity();
|
|
581
611
|
const nowBlocked = isPathBlocked(active.options, location.pathname);
|
|
582
612
|
if (nowBlocked) {
|
|
613
|
+
lastPageViewUrl = null;
|
|
583
614
|
active.routePaused = true;
|
|
584
615
|
if (!active.paused) {
|
|
585
616
|
_optionalChain([active, 'access', _37 => _37.rrweb, 'optionalAccess', _38 => _38.pause, 'call', _39 => _39()]);
|
|
@@ -594,6 +625,9 @@ var replayApi = {
|
|
|
594
625
|
_optionalChain([active, 'access', _40 => _40.rrweb, 'optionalAccess', _41 => _41.resume, 'call', _42 => _42()]);
|
|
595
626
|
if (pendingUser !== void 0) replayApi.setUser(pendingUser);
|
|
596
627
|
}
|
|
628
|
+
const key = pageKey(_nullishCoalesce(url, () => ( location.href)));
|
|
629
|
+
if (key === lastPageViewUrl) return;
|
|
630
|
+
lastPageViewUrl = key;
|
|
597
631
|
active.pagesVisited += 1;
|
|
598
632
|
saveProgress();
|
|
599
633
|
_optionalChain([active, 'access', _43 => _43.rrweb, 'optionalAccess', _44 => _44.takeFullSnapshot, 'call', _45 => _45()]);
|
|
@@ -619,4 +653,4 @@ var replayApi = {
|
|
|
619
653
|
|
|
620
654
|
|
|
621
655
|
|
|
622
|
-
exports.activateReplay = activateReplay; exports.isPathBlocked = isPathBlocked; exports.replayApi = replayApi; exports.withReplay = withReplay;
|
|
656
|
+
exports.activateReplay = activateReplay; exports.isPathBlocked = isPathBlocked; exports.replayApi = replayApi; exports.withReplay = _chunkUSYEDAPQjs.withReplay;
|
package/dist/replay/index.mjs
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
withReplay
|
|
3
|
+
} from "../chunk-YOSYA5HJ.mjs";
|
|
4
|
+
|
|
1
5
|
// src/replay/session.ts
|
|
2
6
|
var UID_KEY = "_bd_session_uid";
|
|
3
7
|
var UID_TS_KEY = "_bd_session_at";
|
|
@@ -122,9 +126,6 @@ function beaconTrace(cfg, path, body) {
|
|
|
122
126
|
}
|
|
123
127
|
|
|
124
128
|
// src/replay/index.ts
|
|
125
|
-
function withReplay(options = {}) {
|
|
126
|
-
return { __segi_replay: true, options };
|
|
127
|
-
}
|
|
128
129
|
async function gzipString(str) {
|
|
129
130
|
try {
|
|
130
131
|
if (typeof CompressionStream === "undefined") return null;
|
|
@@ -167,6 +168,10 @@ function sendError(signal) {
|
|
|
167
168
|
}] });
|
|
168
169
|
}
|
|
169
170
|
var pendingUser = void 0;
|
|
171
|
+
var lastPageViewUrl = null;
|
|
172
|
+
function pageKey(url) {
|
|
173
|
+
return url.split("#")[0];
|
|
174
|
+
}
|
|
170
175
|
function deviceClass() {
|
|
171
176
|
if (typeof window === "undefined") return "desktop";
|
|
172
177
|
const w = window.innerWidth;
|
|
@@ -213,24 +218,47 @@ async function activateReplay(args) {
|
|
|
213
218
|
const epoch = activationEpoch;
|
|
214
219
|
const suspendExcluded = () => {
|
|
215
220
|
if (active && !pathAllowed()) {
|
|
221
|
+
lastPageViewUrl = null;
|
|
216
222
|
active.routePaused = true;
|
|
217
223
|
active.paused = true;
|
|
218
224
|
active.rrweb?.pause();
|
|
219
225
|
}
|
|
220
226
|
};
|
|
227
|
+
let routeTimer = null;
|
|
228
|
+
let routeTracking = args.config.options.trackRoutes === true;
|
|
229
|
+
const trackRoute = () => {
|
|
230
|
+
if (!routeTracking) return;
|
|
231
|
+
if (routeTimer) clearTimeout(routeTimer);
|
|
232
|
+
routeTimer = setTimeout(() => {
|
|
233
|
+
routeTimer = null;
|
|
234
|
+
if (!routeTracking) return;
|
|
235
|
+
try {
|
|
236
|
+
replayApi.notifyRouteChange();
|
|
237
|
+
} catch {
|
|
238
|
+
}
|
|
239
|
+
}, 100);
|
|
240
|
+
};
|
|
241
|
+
cleanup.push(() => {
|
|
242
|
+
routeTracking = false;
|
|
243
|
+
if (routeTimer) clearTimeout(routeTimer);
|
|
244
|
+
});
|
|
245
|
+
const onHistoryChange = () => {
|
|
246
|
+
suspendExcluded();
|
|
247
|
+
trackRoute();
|
|
248
|
+
};
|
|
221
249
|
for (const method of ["pushState", "replaceState"]) {
|
|
222
250
|
const original = history[method];
|
|
223
251
|
const wrapped = function(...params) {
|
|
224
252
|
original.apply(this, params);
|
|
225
|
-
|
|
253
|
+
onHistoryChange();
|
|
226
254
|
};
|
|
227
255
|
history[method] = wrapped;
|
|
228
256
|
cleanup.push(() => {
|
|
229
257
|
if (history[method] === wrapped) history[method] = original;
|
|
230
258
|
});
|
|
231
259
|
}
|
|
232
|
-
window.addEventListener("popstate",
|
|
233
|
-
cleanup.push(() => window.removeEventListener("popstate",
|
|
260
|
+
window.addEventListener("popstate", onHistoryChange);
|
|
261
|
+
cleanup.push(() => window.removeEventListener("popstate", onHistoryChange));
|
|
234
262
|
let inFlight = false;
|
|
235
263
|
const load = async () => {
|
|
236
264
|
if (inFlight || configured || epoch !== activationEpoch) return;
|
|
@@ -458,6 +486,7 @@ async function startReplay(args) {
|
|
|
458
486
|
} else handles?.stop();
|
|
459
487
|
}).catch(() => {
|
|
460
488
|
});
|
|
489
|
+
if (canCollect()) lastPageViewUrl = pageKey(location.href);
|
|
461
490
|
if (canCollect()) void postTrace(transportCfg, "/events", {
|
|
462
491
|
events: [
|
|
463
492
|
{
|
|
@@ -522,6 +551,7 @@ var replayApi = {
|
|
|
522
551
|
active = null;
|
|
523
552
|
pendingErrors = [];
|
|
524
553
|
pendingUser = void 0;
|
|
554
|
+
lastPageViewUrl = null;
|
|
525
555
|
},
|
|
526
556
|
pause() {
|
|
527
557
|
manualPaused = true;
|
|
@@ -580,6 +610,7 @@ var replayApi = {
|
|
|
580
610
|
bumpSessionActivity();
|
|
581
611
|
const nowBlocked = isPathBlocked(active.options, location.pathname);
|
|
582
612
|
if (nowBlocked) {
|
|
613
|
+
lastPageViewUrl = null;
|
|
583
614
|
active.routePaused = true;
|
|
584
615
|
if (!active.paused) {
|
|
585
616
|
active.rrweb?.pause();
|
|
@@ -594,6 +625,9 @@ var replayApi = {
|
|
|
594
625
|
active.rrweb?.resume();
|
|
595
626
|
if (pendingUser !== void 0) replayApi.setUser(pendingUser);
|
|
596
627
|
}
|
|
628
|
+
const key = pageKey(url ?? location.href);
|
|
629
|
+
if (key === lastPageViewUrl) return;
|
|
630
|
+
lastPageViewUrl = key;
|
|
597
631
|
active.pagesVisited += 1;
|
|
598
632
|
saveProgress();
|
|
599
633
|
active.rrweb?.takeFullSnapshot();
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* server-side /api/trace/heatmap/* endpoints.)
|
|
8
8
|
*/
|
|
9
9
|
interface ReplayOptions {
|
|
10
|
-
/**
|
|
10
|
+
/** Default `true`. `false` keeps replay off (error capture is unaffected). */
|
|
11
11
|
enabled?: boolean;
|
|
12
12
|
/** 0..100 probabilistic gate — only this percent of sessions get recorded. */
|
|
13
13
|
sample?: number;
|
|
@@ -20,6 +20,15 @@ interface ReplayOptions {
|
|
|
20
20
|
};
|
|
21
21
|
/** Override default endpoint base. Defaults to SegiClientOptions.endpoint. */
|
|
22
22
|
endpoint?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Emit a page_view automatically on History API navigation
|
|
25
|
+
* (pushState / replaceState / popstate) when the URL path or query changes.
|
|
26
|
+
* Default: `true` for replay enabled through the CDN bundle
|
|
27
|
+
* (`window.SegiConfig.replay`, `data-replay`, `Segi.withReplay` on the CDN
|
|
28
|
+
* global); `false` for npm imports, where frameworks call
|
|
29
|
+
* `Segi.replay.notifyRouteChange()` (SegiReplayProvider does this).
|
|
30
|
+
*/
|
|
31
|
+
trackRoutes?: boolean;
|
|
23
32
|
}
|
|
24
33
|
interface ReplayConfig {
|
|
25
34
|
/** Internal sentinel — set by withReplay(); main init imports the runtime. */
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* server-side /api/trace/heatmap/* endpoints.)
|
|
8
8
|
*/
|
|
9
9
|
interface ReplayOptions {
|
|
10
|
-
/**
|
|
10
|
+
/** Default `true`. `false` keeps replay off (error capture is unaffected). */
|
|
11
11
|
enabled?: boolean;
|
|
12
12
|
/** 0..100 probabilistic gate — only this percent of sessions get recorded. */
|
|
13
13
|
sample?: number;
|
|
@@ -20,6 +20,15 @@ interface ReplayOptions {
|
|
|
20
20
|
};
|
|
21
21
|
/** Override default endpoint base. Defaults to SegiClientOptions.endpoint. */
|
|
22
22
|
endpoint?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Emit a page_view automatically on History API navigation
|
|
25
|
+
* (pushState / replaceState / popstate) when the URL path or query changes.
|
|
26
|
+
* Default: `true` for replay enabled through the CDN bundle
|
|
27
|
+
* (`window.SegiConfig.replay`, `data-replay`, `Segi.withReplay` on the CDN
|
|
28
|
+
* global); `false` for npm imports, where frameworks call
|
|
29
|
+
* `Segi.replay.notifyRouteChange()` (SegiReplayProvider does this).
|
|
30
|
+
*/
|
|
31
|
+
trackRoutes?: boolean;
|
|
23
32
|
}
|
|
24
33
|
interface ReplayConfig {
|
|
25
34
|
/** Internal sentinel — set by withReplay(); main init imports the runtime. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@extn/segi-js",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.18",
|
|
4
4
|
"description": "Browser JavaScript SDK for the segi error monitoring service",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"rrweb": "2.0.0-alpha.20",
|
|
32
|
-
"@extn/segi-shared": "0.2.
|
|
32
|
+
"@extn/segi-shared": "0.2.1"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"tsup": "^8.3.0",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "tsup",
|
|
40
|
+
"test": "node --test test/normalize-error.test.cjs test/replay-token.test.cjs",
|
|
40
41
|
"test:browser": "node test/browser-runtime.cjs",
|
|
41
42
|
"dev": "tsup --watch",
|
|
42
43
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|