@monoscopetech/browser 0.5.8 → 0.5.9
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/monoscope.min.js +1 -1
- package/dist/monoscope.min.js.map +1 -1
- package/dist/monoscope.umd.js +1 -1
- package/dist/monoscope.umd.js.map +1 -1
- package/dist/replay.js +17 -6
- package/package.json +1 -1
package/dist/replay.js
CHANGED
|
@@ -106,13 +106,20 @@ export class MonoscopeReplay {
|
|
|
106
106
|
return;
|
|
107
107
|
}
|
|
108
108
|
if (this.events.length > MAX_RETRY_EVENTS) {
|
|
109
|
-
console.warn(`Event queue exceeded ${MAX_RETRY_EVENTS}, dropping
|
|
110
|
-
|
|
109
|
+
console.warn(`Event queue exceeded ${MAX_RETRY_EVENTS}, dropping middle events (preserving snapshots)`);
|
|
110
|
+
// Find full snapshot events (type 2) - these are critical for replay
|
|
111
|
+
const fullSnapshots = this.events.filter((e) => e.type === 2);
|
|
112
|
+
const otherEvents = this.events.filter((e) => e.type !== 2);
|
|
113
|
+
// Keep all snapshots and the most recent other events
|
|
114
|
+
const remainingSlots = MAX_RETRY_EVENTS - fullSnapshots.length;
|
|
115
|
+
this.events = [...fullSnapshots, ...otherEvents.slice(-remainingSlots)];
|
|
116
|
+
// Re-sort by timestamp to maintain order
|
|
117
|
+
this.events.sort((a, b) => a.timestamp - b.timestamp);
|
|
111
118
|
}
|
|
112
119
|
this.isSaving = true;
|
|
113
120
|
const { replayEventsBaseUrl, projectId } = this.config;
|
|
114
121
|
// Construct base URL
|
|
115
|
-
let baseUrl = replayEventsBaseUrl || "https://app.
|
|
122
|
+
let baseUrl = replayEventsBaseUrl || "https://app.monoscope.tech";
|
|
116
123
|
baseUrl = `${baseUrl}/rrweb/${projectId}`;
|
|
117
124
|
// Get events to send and clear buffer
|
|
118
125
|
const eventsToSend = [...this.events];
|
|
@@ -141,20 +148,24 @@ export class MonoscopeReplay {
|
|
|
141
148
|
"Content-Type": "application/json",
|
|
142
149
|
},
|
|
143
150
|
body: JSON.stringify(payload),
|
|
151
|
+
keepalive: true,
|
|
144
152
|
});
|
|
145
153
|
if (!response.ok) {
|
|
146
|
-
console.log(response);
|
|
147
154
|
throw new Error(`Failed to save replay events: ${response.status} ${response.statusText}`);
|
|
148
155
|
}
|
|
149
156
|
console.log(`Successfully saved ${eventsToSend.length} replay events`);
|
|
150
157
|
}
|
|
151
158
|
}
|
|
152
159
|
catch (error) {
|
|
153
|
-
console.log(error);
|
|
154
160
|
console.error("Failed to save replay events:", error);
|
|
155
161
|
this.events = [...eventsToSend, ...this.events];
|
|
156
162
|
if (this.events.length > MAX_RETRY_EVENTS) {
|
|
157
|
-
|
|
163
|
+
// Preserve full snapshots when trimming
|
|
164
|
+
const fullSnapshots = this.events.filter((e) => e.type === 2);
|
|
165
|
+
const otherEvents = this.events.filter((e) => e.type !== 2);
|
|
166
|
+
const remainingSlots = MAX_RETRY_EVENTS - fullSnapshots.length;
|
|
167
|
+
this.events = [...fullSnapshots, ...otherEvents.slice(-remainingSlots)];
|
|
168
|
+
this.events.sort((a, b) => a.timestamp - b.timestamp);
|
|
158
169
|
}
|
|
159
170
|
}
|
|
160
171
|
finally {
|