@extn/segi-js 0.2.4 → 0.2.6

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.
@@ -221,9 +221,12 @@ async function postTrace(cfg, path, body) {
221
221
  "Content-Type": "application/json",
222
222
  "X-Segi-Project-Key": cfg.projectKey
223
223
  },
224
- body: JSON.stringify(body),
225
- // Keep the request alive past page unload (best-effort flush).
226
- keepalive: true
224
+ body: JSON.stringify(body)
225
+ // No `keepalive: true` — Chrome caps keepalive request bodies at
226
+ // 64 KB and rejects larger ones synchronously with "Failed to
227
+ // fetch", which silently nukes uploads (FullSnapshots routinely
228
+ // exceed 64 KB). Unload-path flushing goes through sendBeacon
229
+ // instead (separate API, no throw).
227
230
  });
228
231
  return res;
229
232
  } catch (e8) {
@@ -367,7 +370,7 @@ async function activateReplay(args) {
367
370
  setTimeout(onIdle, 5e3);
368
371
  }
369
372
  };
370
- void Promise.resolve().then(() => _interopRequireWildcard(require("../rrweb-5RF4GJUU.js"))).then(
373
+ void Promise.resolve().then(() => _interopRequireWildcard(require("../rrweb-KAUSOLTH.js"))).then(
371
374
  ({ startRrweb }) => new Promise((resolve) => {
372
375
  scheduleRrwebStart(() => {
373
376
  startRrweb({
@@ -375,19 +378,51 @@ async function activateReplay(args) {
375
378
  options,
376
379
  sendChunk: async (chunk, useBeacon) => {
377
380
  if (!active || active.replayBlocked) return;
381
+ const bodyStr = `{"sessionUid":${JSON.stringify(sessionUid)},"chunk":[${chunk.join(",")}]}`;
382
+ const base = (transportCfg.endpoint || "https://segiapi.extn.ai").replace(/\/+$/, "").replace(/\/api\/ingest\/events$/, "").replace(/\/api\/ingest$/, "").replace(/\/api$/, "");
378
383
  if (useBeacon) {
379
- beaconTrace(transportCfg, "/replay", { sessionUid, chunk });
384
+ try {
385
+ const url = `${base}/api/trace/replay?pk=${encodeURIComponent(transportCfg.projectKey)}`;
386
+ const blob = new Blob([bodyStr], {
387
+ type: "application/json"
388
+ });
389
+ if (typeof navigator !== "undefined" && typeof navigator.sendBeacon === "function") {
390
+ navigator.sendBeacon(url, blob);
391
+ }
392
+ } catch (e12) {
393
+ }
380
394
  return;
381
395
  }
382
- const res = await postTrace(transportCfg, "/replay", {
383
- sessionUid,
384
- chunk
385
- });
386
- if (res && res.status === 429) {
387
- if (active) {
388
- active.replayBlocked = true;
389
- _optionalChain([active, 'access', _28 => _28.rrweb, 'optionalAccess', _29 => _29.stop, 'call', _30 => _30()]);
390
- active.rrweb = null;
396
+ try {
397
+ const res = await fetch(`${base}/api/trace/replay`, {
398
+ method: "POST",
399
+ headers: {
400
+ "Content-Type": "application/json",
401
+ "X-Segi-Project-Key": transportCfg.projectKey
402
+ },
403
+ body: bodyStr
404
+ });
405
+ if (typeof console !== "undefined") {
406
+ console.log(
407
+ "[segi.replay] /replay POST",
408
+ res.status,
409
+ bodyStr.length,
410
+ "bytes"
411
+ );
412
+ }
413
+ if (res.status === 429) {
414
+ if (active) {
415
+ active.replayBlocked = true;
416
+ _optionalChain([active, 'access', _28 => _28.rrweb, 'optionalAccess', _29 => _29.stop, 'call', _30 => _30()]);
417
+ active.rrweb = null;
418
+ }
419
+ }
420
+ } catch (err) {
421
+ if (typeof console !== "undefined") {
422
+ console.log(
423
+ "[segi.replay] /replay POST FETCH FAILED:",
424
+ err.message
425
+ );
391
426
  }
392
427
  }
393
428
  }
@@ -221,9 +221,12 @@ async function postTrace(cfg, path, body) {
221
221
  "Content-Type": "application/json",
222
222
  "X-Segi-Project-Key": cfg.projectKey
223
223
  },
224
- body: JSON.stringify(body),
225
- // Keep the request alive past page unload (best-effort flush).
226
- keepalive: true
224
+ body: JSON.stringify(body)
225
+ // No `keepalive: true` — Chrome caps keepalive request bodies at
226
+ // 64 KB and rejects larger ones synchronously with "Failed to
227
+ // fetch", which silently nukes uploads (FullSnapshots routinely
228
+ // exceed 64 KB). Unload-path flushing goes through sendBeacon
229
+ // instead (separate API, no throw).
227
230
  });
228
231
  return res;
229
232
  } catch {
@@ -367,7 +370,7 @@ async function activateReplay(args) {
367
370
  setTimeout(onIdle, 5e3);
368
371
  }
369
372
  };
370
- void import("../rrweb-7F2GWQCE.mjs").then(
373
+ void import("../rrweb-DCBIDQEX.mjs").then(
371
374
  ({ startRrweb }) => new Promise((resolve) => {
372
375
  scheduleRrwebStart(() => {
373
376
  startRrweb({
@@ -375,19 +378,51 @@ async function activateReplay(args) {
375
378
  options,
376
379
  sendChunk: async (chunk, useBeacon) => {
377
380
  if (!active || active.replayBlocked) return;
381
+ const bodyStr = `{"sessionUid":${JSON.stringify(sessionUid)},"chunk":[${chunk.join(",")}]}`;
382
+ const base = (transportCfg.endpoint || "https://segiapi.extn.ai").replace(/\/+$/, "").replace(/\/api\/ingest\/events$/, "").replace(/\/api\/ingest$/, "").replace(/\/api$/, "");
378
383
  if (useBeacon) {
379
- beaconTrace(transportCfg, "/replay", { sessionUid, chunk });
384
+ try {
385
+ const url = `${base}/api/trace/replay?pk=${encodeURIComponent(transportCfg.projectKey)}`;
386
+ const blob = new Blob([bodyStr], {
387
+ type: "application/json"
388
+ });
389
+ if (typeof navigator !== "undefined" && typeof navigator.sendBeacon === "function") {
390
+ navigator.sendBeacon(url, blob);
391
+ }
392
+ } catch {
393
+ }
380
394
  return;
381
395
  }
382
- const res = await postTrace(transportCfg, "/replay", {
383
- sessionUid,
384
- chunk
385
- });
386
- if (res && res.status === 429) {
387
- if (active) {
388
- active.replayBlocked = true;
389
- active.rrweb?.stop();
390
- active.rrweb = null;
396
+ try {
397
+ const res = await fetch(`${base}/api/trace/replay`, {
398
+ method: "POST",
399
+ headers: {
400
+ "Content-Type": "application/json",
401
+ "X-Segi-Project-Key": transportCfg.projectKey
402
+ },
403
+ body: bodyStr
404
+ });
405
+ if (typeof console !== "undefined") {
406
+ console.log(
407
+ "[segi.replay] /replay POST",
408
+ res.status,
409
+ bodyStr.length,
410
+ "bytes"
411
+ );
412
+ }
413
+ if (res.status === 429) {
414
+ if (active) {
415
+ active.replayBlocked = true;
416
+ active.rrweb?.stop();
417
+ active.rrweb = null;
418
+ }
419
+ }
420
+ } catch (err) {
421
+ if (typeof console !== "undefined") {
422
+ console.log(
423
+ "[segi.replay] /replay POST FETCH FAILED:",
424
+ err.message
425
+ );
391
426
  }
392
427
  }
393
428
  }
@@ -59,6 +59,17 @@ async function startRrweb(args) {
59
59
  emit(event) {
60
60
  emitCount++;
61
61
  const e = event;
62
+ if (paused || stopped) return;
63
+ let serialized;
64
+ try {
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
+ }
62
73
  if (emitCount <= 10) {
63
74
  log(
64
75
  `emit #${emitCount}`,
@@ -66,18 +77,12 @@ async function startRrweb(args) {
66
77
  e.type,
67
78
  "source:",
68
79
  e.data?.source,
69
- "paused:",
70
- paused,
71
- "stopped:",
72
- stopped
80
+ "size:",
81
+ serialized.length
73
82
  );
74
83
  }
75
- if (paused || stopped) return;
76
- buffer.push(event);
77
- try {
78
- bufferBytes += JSON.stringify(event).length;
79
- } catch {
80
- }
84
+ buffer.push(serialized);
85
+ bufferBytes += serialized.length;
81
86
  if (bufferBytes >= FLUSH_BYTES) flush();
82
87
  },
83
88
  // `input: "last"` emits only the final value of each keystroke
@@ -141,6 +146,25 @@ async function startRrweb(args) {
141
146
  const chunk = buffer;
142
147
  buffer = [];
143
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
+ }
144
168
  try {
145
169
  args.sendChunk(chunk, useBeacon);
146
170
  } catch {
@@ -59,25 +59,30 @@ async function startRrweb(args) {
59
59
  emit(event) {
60
60
  emitCount++;
61
61
  const e = event;
62
+ if (paused || stopped) return;
63
+ let serialized;
64
+ try {
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
+ }
62
73
  if (emitCount <= 10) {
63
74
  log(
64
75
  `emit #${emitCount}`,
65
76
  "type:",
66
77
  e.type,
67
78
  "source:",
68
- _optionalChain([e, 'access', _7 => _7.data, 'optionalAccess', _8 => _8.source]),
69
- "paused:",
70
- paused,
71
- "stopped:",
72
- stopped
79
+ _optionalChain([e, 'access', _9 => _9.data, 'optionalAccess', _10 => _10.source]),
80
+ "size:",
81
+ serialized.length
73
82
  );
74
83
  }
75
- if (paused || stopped) return;
76
- buffer.push(event);
77
- try {
78
- bufferBytes += JSON.stringify(event).length;
79
- } catch (e3) {
80
- }
84
+ buffer.push(serialized);
85
+ bufferBytes += serialized.length;
81
86
  if (bufferBytes >= FLUSH_BYTES) flush();
82
87
  },
83
88
  // `input: "last"` emits only the final value of each keystroke
@@ -130,7 +135,7 @@ async function startRrweb(args) {
130
135
  }
131
136
  function stopRrwebOnly() {
132
137
  try {
133
- _optionalChain([stopFn, 'optionalCall', _9 => _9()]);
138
+ _optionalChain([stopFn, 'optionalCall', _11 => _11()]);
134
139
  } finally {
135
140
  stopFn = null;
136
141
  }
@@ -141,9 +146,28 @@ async function startRrweb(args) {
141
146
  const chunk = buffer;
142
147
  buffer = [];
143
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
+ }
144
168
  try {
145
169
  args.sendChunk(chunk, useBeacon);
146
- } catch (e4) {
170
+ } catch (e3) {
147
171
  }
148
172
  }
149
173
  function onActivity() {
@@ -192,8 +216,8 @@ async function startRrweb(args) {
192
216
  if (stopped || paused) return;
193
217
  try {
194
218
  const rec = rrweb.record;
195
- _optionalChain([rec, 'access', _10 => _10.takeFullSnapshot, 'optionalCall', _11 => _11()]);
196
- } catch (e5) {
219
+ _optionalChain([rec, 'access', _12 => _12.takeFullSnapshot, 'optionalCall', _13 => _13()]);
220
+ } catch (e4) {
197
221
  }
198
222
  }
199
223
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@extn/segi-js",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "Browser JavaScript SDK for the segi error monitoring service",
5
5
  "license": "UNLICENSED",
6
6
  "main": "./dist/index.js",