@extn/segi-js 0.2.0 → 0.2.2

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.
@@ -348,28 +348,51 @@ async function activateReplay(args) {
348
348
  clickCount: 0,
349
349
  recordingEnabled: true
350
350
  };
351
- void Promise.resolve().then(() => _interopRequireWildcard(require("../rrweb-H4UUMFZ5.js"))).then(
352
- ({ startRrweb }) => startRrweb({
353
- sessionUid,
354
- options,
355
- sendChunk: async (chunk, useBeacon) => {
356
- if (!active || active.replayBlocked) return;
357
- if (useBeacon) {
358
- beaconTrace(transportCfg, "/replay", { sessionUid, chunk });
359
- return;
360
- }
361
- const res = await postTrace(transportCfg, "/replay", {
351
+ const w = window;
352
+ const scheduleRrwebStart = (run) => {
353
+ let fired = false;
354
+ const onIdle = () => {
355
+ if (fired) return;
356
+ fired = true;
357
+ if (typeof w.requestIdleCallback === "function") {
358
+ w.requestIdleCallback(run, { timeout: 2e3 });
359
+ } else {
360
+ setTimeout(run, 1e3);
361
+ }
362
+ };
363
+ if (typeof document !== "undefined" && document.readyState === "complete") {
364
+ onIdle();
365
+ } else {
366
+ window.addEventListener("load", onIdle, { once: true });
367
+ setTimeout(onIdle, 5e3);
368
+ }
369
+ };
370
+ void Promise.resolve().then(() => _interopRequireWildcard(require("../rrweb-CS5CEEFJ.js"))).then(
371
+ ({ startRrweb }) => new Promise((resolve) => {
372
+ scheduleRrwebStart(() => {
373
+ startRrweb({
362
374
  sessionUid,
363
- chunk
364
- });
365
- if (res && res.status === 429) {
366
- if (active) {
367
- active.replayBlocked = true;
368
- _optionalChain([active, 'access', _28 => _28.rrweb, 'optionalAccess', _29 => _29.stop, 'call', _30 => _30()]);
369
- active.rrweb = null;
375
+ options,
376
+ sendChunk: async (chunk, useBeacon) => {
377
+ if (!active || active.replayBlocked) return;
378
+ if (useBeacon) {
379
+ beaconTrace(transportCfg, "/replay", { sessionUid, chunk });
380
+ return;
381
+ }
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;
391
+ }
392
+ }
370
393
  }
371
- }
372
- }
394
+ }).then(resolve, () => resolve(null));
395
+ });
373
396
  })
374
397
  ).then((handles) => {
375
398
  if (handles && active) active.rrweb = handles;
@@ -456,6 +479,7 @@ var replayApi = {
456
479
  active.paused = false;
457
480
  }
458
481
  active.pagesVisited += 1;
482
+ _optionalChain([active, 'access', _59 => _59.rrweb, 'optionalAccess', _60 => _60.takeFullSnapshot, 'call', _61 => _61()]);
459
483
  void postTrace(active.config, "/events", {
460
484
  events: [
461
485
  {
@@ -470,7 +494,7 @@ var replayApi = {
470
494
  },
471
495
  /** Test seam: returns null when replay was not activated for this session. */
472
496
  _sessionUid() {
473
- return _nullishCoalesce(_optionalChain([active, 'optionalAccess', _59 => _59.sessionUid]), () => ( null));
497
+ return _nullishCoalesce(_optionalChain([active, 'optionalAccess', _62 => _62.sessionUid]), () => ( null));
474
498
  }
475
499
  };
476
500
 
@@ -348,28 +348,51 @@ async function activateReplay(args) {
348
348
  clickCount: 0,
349
349
  recordingEnabled: true
350
350
  };
351
- void import("../rrweb-JCHV7B75.mjs").then(
352
- ({ startRrweb }) => startRrweb({
353
- sessionUid,
354
- options,
355
- sendChunk: async (chunk, useBeacon) => {
356
- if (!active || active.replayBlocked) return;
357
- if (useBeacon) {
358
- beaconTrace(transportCfg, "/replay", { sessionUid, chunk });
359
- return;
360
- }
361
- const res = await postTrace(transportCfg, "/replay", {
351
+ const w = window;
352
+ const scheduleRrwebStart = (run) => {
353
+ let fired = false;
354
+ const onIdle = () => {
355
+ if (fired) return;
356
+ fired = true;
357
+ if (typeof w.requestIdleCallback === "function") {
358
+ w.requestIdleCallback(run, { timeout: 2e3 });
359
+ } else {
360
+ setTimeout(run, 1e3);
361
+ }
362
+ };
363
+ if (typeof document !== "undefined" && document.readyState === "complete") {
364
+ onIdle();
365
+ } else {
366
+ window.addEventListener("load", onIdle, { once: true });
367
+ setTimeout(onIdle, 5e3);
368
+ }
369
+ };
370
+ void import("../rrweb-2AZRG7VC.mjs").then(
371
+ ({ startRrweb }) => new Promise((resolve) => {
372
+ scheduleRrwebStart(() => {
373
+ startRrweb({
362
374
  sessionUid,
363
- chunk
364
- });
365
- if (res && res.status === 429) {
366
- if (active) {
367
- active.replayBlocked = true;
368
- active.rrweb?.stop();
369
- active.rrweb = null;
375
+ options,
376
+ sendChunk: async (chunk, useBeacon) => {
377
+ if (!active || active.replayBlocked) return;
378
+ if (useBeacon) {
379
+ beaconTrace(transportCfg, "/replay", { sessionUid, chunk });
380
+ return;
381
+ }
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;
391
+ }
392
+ }
370
393
  }
371
- }
372
- }
394
+ }).then(resolve, () => resolve(null));
395
+ });
373
396
  })
374
397
  ).then((handles) => {
375
398
  if (handles && active) active.rrweb = handles;
@@ -456,6 +479,7 @@ var replayApi = {
456
479
  active.paused = false;
457
480
  }
458
481
  active.pagesVisited += 1;
482
+ active.rrweb?.takeFullSnapshot();
459
483
  void postTrace(active.config, "/events", {
460
484
  events: [
461
485
  {
@@ -58,7 +58,10 @@ async function startRrweb(args) {
58
58
  }
59
59
  if (bufferBytes >= FLUSH_BYTES) flush();
60
60
  },
61
- sampling: { mousemove: 20, scroll: 150 },
61
+ // `input: "last"` emits only the final value of each keystroke
62
+ // run, not one event per character. Smaller payloads, less PII risk
63
+ // for non-masked inputs.
64
+ sampling: { mousemove: 20, scroll: 150, input: "last" },
62
65
  maskAllInputs: inputMode === "all",
63
66
  maskInputOptions,
64
67
  blockClass: maskClass,
@@ -66,7 +69,13 @@ async function startRrweb(args) {
66
69
  maskTextClass: maskClass,
67
70
  recordCanvas: false,
68
71
  collectFonts: false,
69
- checkoutEveryNms: CHECKOUT_EVERY_MS
72
+ checkoutEveryNms: CHECKOUT_EVERY_MS,
73
+ // Explicit (rather than relying on default) so we don't regress
74
+ // when the rrweb default changes between alpha builds. Inlines
75
+ // <link rel="stylesheet"> CSS at snapshot time — playback in the
76
+ // admin iframe doesn't have access to the customer's origin to
77
+ // fetch them otherwise.
78
+ inlineStylesheet: true
70
79
  });
71
80
  stopFn = typeof stop === "function" ? stop : null;
72
81
  }
@@ -93,10 +102,18 @@ async function startRrweb(args) {
93
102
  if (!stopFn && !paused && !stopped) startRecorder();
94
103
  }
95
104
  for (const ev of ACTIVITY_EVENTS) {
96
- window.addEventListener(ev, onActivity, { passive: true });
105
+ window.addEventListener(ev, onActivity, { passive: true, capture: true });
97
106
  }
98
107
  const onPageHide = () => flush(true);
108
+ const onVisibilityChange = () => {
109
+ if (typeof document !== "undefined" && document.visibilityState === "hidden") {
110
+ flush(true);
111
+ }
112
+ };
99
113
  window.addEventListener("pagehide", onPageHide);
114
+ if (typeof document !== "undefined") {
115
+ document.addEventListener("visibilitychange", onVisibilityChange);
116
+ }
100
117
  startRecorder();
101
118
  return {
102
119
  pause() {
@@ -114,11 +131,22 @@ async function startRrweb(args) {
114
131
  clearInterval(flushTimer);
115
132
  clearInterval(idleTimer);
116
133
  for (const ev of ACTIVITY_EVENTS) {
117
- window.removeEventListener(ev, onActivity);
134
+ window.removeEventListener(ev, onActivity, { capture: true });
118
135
  }
119
136
  window.removeEventListener("pagehide", onPageHide);
137
+ if (typeof document !== "undefined") {
138
+ document.removeEventListener("visibilitychange", onVisibilityChange);
139
+ }
120
140
  },
121
- flush
141
+ flush,
142
+ takeFullSnapshot() {
143
+ if (stopped || paused) return;
144
+ try {
145
+ const rec = rrweb.record;
146
+ rec.takeFullSnapshot?.();
147
+ } catch {
148
+ }
149
+ }
122
150
  };
123
151
  }
124
152
  export {
@@ -58,7 +58,10 @@ async function startRrweb(args) {
58
58
  }
59
59
  if (bufferBytes >= FLUSH_BYTES) flush();
60
60
  },
61
- sampling: { mousemove: 20, scroll: 150 },
61
+ // `input: "last"` emits only the final value of each keystroke
62
+ // run, not one event per character. Smaller payloads, less PII risk
63
+ // for non-masked inputs.
64
+ sampling: { mousemove: 20, scroll: 150, input: "last" },
62
65
  maskAllInputs: inputMode === "all",
63
66
  maskInputOptions,
64
67
  blockClass: maskClass,
@@ -66,7 +69,13 @@ async function startRrweb(args) {
66
69
  maskTextClass: maskClass,
67
70
  recordCanvas: false,
68
71
  collectFonts: false,
69
- checkoutEveryNms: CHECKOUT_EVERY_MS
72
+ checkoutEveryNms: CHECKOUT_EVERY_MS,
73
+ // Explicit (rather than relying on default) so we don't regress
74
+ // when the rrweb default changes between alpha builds. Inlines
75
+ // <link rel="stylesheet"> CSS at snapshot time — playback in the
76
+ // admin iframe doesn't have access to the customer's origin to
77
+ // fetch them otherwise.
78
+ inlineStylesheet: true
70
79
  });
71
80
  stopFn = typeof stop === "function" ? stop : null;
72
81
  }
@@ -93,10 +102,18 @@ async function startRrweb(args) {
93
102
  if (!stopFn && !paused && !stopped) startRecorder();
94
103
  }
95
104
  for (const ev of ACTIVITY_EVENTS) {
96
- window.addEventListener(ev, onActivity, { passive: true });
105
+ window.addEventListener(ev, onActivity, { passive: true, capture: true });
97
106
  }
98
107
  const onPageHide = () => flush(true);
108
+ const onVisibilityChange = () => {
109
+ if (typeof document !== "undefined" && document.visibilityState === "hidden") {
110
+ flush(true);
111
+ }
112
+ };
99
113
  window.addEventListener("pagehide", onPageHide);
114
+ if (typeof document !== "undefined") {
115
+ document.addEventListener("visibilitychange", onVisibilityChange);
116
+ }
100
117
  startRecorder();
101
118
  return {
102
119
  pause() {
@@ -114,11 +131,22 @@ async function startRrweb(args) {
114
131
  clearInterval(flushTimer);
115
132
  clearInterval(idleTimer);
116
133
  for (const ev of ACTIVITY_EVENTS) {
117
- window.removeEventListener(ev, onActivity);
134
+ window.removeEventListener(ev, onActivity, { capture: true });
118
135
  }
119
136
  window.removeEventListener("pagehide", onPageHide);
137
+ if (typeof document !== "undefined") {
138
+ document.removeEventListener("visibilitychange", onVisibilityChange);
139
+ }
120
140
  },
121
- flush
141
+ flush,
142
+ takeFullSnapshot() {
143
+ if (stopped || paused) return;
144
+ try {
145
+ const rec = rrweb.record;
146
+ _optionalChain([rec, 'access', _8 => _8.takeFullSnapshot, 'optionalCall', _9 => _9()]);
147
+ } catch (e4) {
148
+ }
149
+ }
122
150
  };
123
151
  }
124
152
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@extn/segi-js",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Browser JavaScript SDK for the segi error monitoring service",
5
5
  "license": "UNLICENSED",
6
6
  "main": "./dist/index.js",