@watchforge/browser 0.1.9 → 0.1.10
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/package.json +1 -1
- package/src/contexts.js +1 -1
- package/src/replay.js +39 -3
package/package.json
CHANGED
package/src/contexts.js
CHANGED
|
@@ -7,7 +7,7 @@ const isNode =
|
|
|
7
7
|
typeof process !== "undefined" && process.versions && process.versions.node;
|
|
8
8
|
|
|
9
9
|
export const SDK_NAME = "@watchforge/browser";
|
|
10
|
-
export const SDK_VERSION = "0.1.
|
|
10
|
+
export const SDK_VERSION = "0.1.10";
|
|
11
11
|
|
|
12
12
|
export function getSdkMetadata() {
|
|
13
13
|
return {
|
package/src/replay.js
CHANGED
|
@@ -3,6 +3,8 @@ import { sendReplay } from "./transport.js";
|
|
|
3
3
|
const isBrowser = typeof window !== "undefined";
|
|
4
4
|
const MAX_BUFFER_MS = 60 * 1000;
|
|
5
5
|
const MAX_EVENTS = 500;
|
|
6
|
+
const RRWEB_FULL_SNAPSHOT = 2;
|
|
7
|
+
const RRWEB_META = 4;
|
|
6
8
|
|
|
7
9
|
let options = {
|
|
8
10
|
replaysSessionSampleRate: 0,
|
|
@@ -37,9 +39,43 @@ function shouldSample(rate) {
|
|
|
37
39
|
|
|
38
40
|
function trimBuffer(now = Date.now()) {
|
|
39
41
|
events = events.filter((event) => now - event.timestamp <= MAX_BUFFER_MS);
|
|
40
|
-
if (events.length
|
|
41
|
-
|
|
42
|
+
if (events.length <= MAX_EVENTS) return;
|
|
43
|
+
|
|
44
|
+
const tail = events.slice(-MAX_EVENTS);
|
|
45
|
+
if (tail.some((event) => event.type === RRWEB_FULL_SNAPSHOT)) {
|
|
46
|
+
events = tail;
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const fullSnapshotIndex = findLastEventIndex(events, RRWEB_FULL_SNAPSHOT);
|
|
51
|
+
if (fullSnapshotIndex === -1) {
|
|
52
|
+
events = tail;
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const metaIndex = findLastEventIndex(
|
|
57
|
+
events.slice(0, fullSnapshotIndex),
|
|
58
|
+
RRWEB_META
|
|
59
|
+
);
|
|
60
|
+
const anchorEvents = [
|
|
61
|
+
...(metaIndex >= 0 ? [events[metaIndex]] : []),
|
|
62
|
+
events[fullSnapshotIndex],
|
|
63
|
+
];
|
|
64
|
+
const remainingSlots = Math.max(MAX_EVENTS - anchorEvents.length, 0);
|
|
65
|
+
const recentEvents = events
|
|
66
|
+
.slice(fullSnapshotIndex + 1)
|
|
67
|
+
.slice(-remainingSlots);
|
|
68
|
+
|
|
69
|
+
events = [...anchorEvents, ...recentEvents].sort(
|
|
70
|
+
(a, b) => (a.timestamp || 0) - (b.timestamp || 0)
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function findLastEventIndex(list, type) {
|
|
75
|
+
for (let i = list.length - 1; i >= 0; i--) {
|
|
76
|
+
if (list[i]?.type === type) return i;
|
|
42
77
|
}
|
|
78
|
+
return -1;
|
|
43
79
|
}
|
|
44
80
|
|
|
45
81
|
export async function initReplay(config = {}) {
|
|
@@ -115,7 +151,7 @@ export function flushReplayForEvent(dsn, eventId) {
|
|
|
115
151
|
events,
|
|
116
152
|
sdk: {
|
|
117
153
|
name: "@watchforge/browser",
|
|
118
|
-
version: "0.1.
|
|
154
|
+
version: "0.1.10",
|
|
119
155
|
},
|
|
120
156
|
};
|
|
121
157
|
|