@sailfish-ai/recorder 1.8.10 → 1.8.12

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/recording.js CHANGED
@@ -155,8 +155,8 @@ export function initializeConsolePlugin(consoleRecordSettings, sessionId) {
155
155
  }
156
156
  export async function initializeRecording(captureSettings, // TODO - Sibyl post-launch - replace type
157
157
  // networkRecordSettings: NetworkRecordOptions,
158
- backendApi, apiKey, sessionId) {
159
- const webSocket = initializeWebSocket(backendApi, apiKey, sessionId);
158
+ backendApi, apiKey, sessionId, envValue) {
159
+ const webSocket = initializeWebSocket(backendApi, apiKey, sessionId, envValue);
160
160
  try {
161
161
  record({
162
162
  emit(event) {
package/dist/session.js CHANGED
@@ -1,12 +1,49 @@
1
1
  import { v4 as uuidv4 } from "uuid";
2
2
  import { HAS_WINDOW } from "./runtimeEnv";
3
- // Storing the sailfishSessionId in window.name, as window.name retains its value after a page refresh
4
- // but resets when a new tab (including a duplicated tab) is opened.
3
+ // Hybrid approach: use window.name as a temporary "refresh flag" and sessionStorage for persistence
4
+ // - window.name flag is removed immediately after reading, preserving customer's data
5
+ // - sessionStorage stores the actual session ID
6
+ // - beforeunload sets a flag in window.name to detect page refresh vs duplicate tab
7
+ const SESSION_ID_KEY = "sailfishSessionId";
8
+ const REFRESH_FLAG = "__sailfish_refresh__";
9
+ // Cache the resolved session ID to avoid regenerating on multiple calls
10
+ let resolvedSessionId = null;
5
11
  export function getOrSetSessionId() {
6
12
  if (!HAS_WINDOW)
7
13
  return uuidv4();
8
- if (!window.name) {
9
- window.name = uuidv4();
14
+ // Return cached session ID if already resolved
15
+ if (resolvedSessionId) {
16
+ return resolvedSessionId;
10
17
  }
11
- return window.name;
18
+ // Check if window.name contains our refresh flag
19
+ const isRefresh = window.name.startsWith(REFRESH_FLAG);
20
+ // Remove our flag and restore customer's original window.name
21
+ if (isRefresh) {
22
+ window.name = window.name.substring(REFRESH_FLAG.length);
23
+ }
24
+ if (isRefresh) {
25
+ // Page refresh - reuse existing session ID from sessionStorage
26
+ const existingSessionId = window.sessionStorage.getItem(SESSION_ID_KEY);
27
+ if (existingSessionId) {
28
+ resolvedSessionId = existingSessionId;
29
+ return existingSessionId;
30
+ }
31
+ }
32
+ // New tab or duplicate tab - generate new session ID
33
+ const sessionId = uuidv4();
34
+ resolvedSessionId = sessionId;
35
+ try {
36
+ window.sessionStorage.setItem(SESSION_ID_KEY, sessionId);
37
+ }
38
+ catch (error) {
39
+ // Ignore storage errors, use in-memory session ID
40
+ }
41
+ return sessionId;
42
+ }
43
+ // Set up beforeunload listener to mark page refresh
44
+ if (HAS_WINDOW) {
45
+ window.addEventListener("beforeunload", () => {
46
+ // Prepend our flag to preserve customer's window.name
47
+ window.name = REFRESH_FLAG + window.name;
48
+ });
12
49
  }
@@ -31,6 +31,7 @@ export * from "./graphql";
31
31
  export { openReportIssueModal } from "./inAppReportIssueModal";
32
32
  export * from "./recording";
33
33
  export * from "./sendSailfishMessages";
34
+ export { getOrSetSessionId } from "./session";
34
35
  export * from "./types";
35
36
  export * from "./utils";
36
37
  export * from "./websocket";
@@ -10,4 +10,4 @@ export declare const getUrlAndStoredUuids: () => {
10
10
  export declare function initializeDomContentEvents(sessionId: string): void;
11
11
  export declare function initializeConsolePlugin(consoleRecordSettings: LogRecordOptions, sessionId: string): void;
12
12
  export declare function initializeRecording(captureSettings: any, // TODO - Sibyl post-launch - replace type
13
- backendApi: string, apiKey: string, sessionId: string): Promise<ReconnectingWebSocket>;
13
+ backendApi: string, apiKey: string, sessionId: string, envValue?: string): Promise<ReconnectingWebSocket>;
@@ -1,7 +1,7 @@
1
1
  import ReconnectingWebSocket from "reconnecting-websocket";
2
2
  export declare function flushBufferedEvents(): Promise<void>;
3
3
  export declare function sendEvent(event: any): void;
4
- export declare function initializeWebSocket(backendApi: string, apiKey: string, sessionId: string): ReconnectingWebSocket;
4
+ export declare function initializeWebSocket(backendApi: string, apiKey: string, sessionId: string, envValue?: string): ReconnectingWebSocket;
5
5
  export declare function sendMessage(message: Record<string, any>): void;
6
6
  /**
7
7
  * Enable function span tracking for this session (e.g., when report issue recording starts)
package/dist/websocket.js CHANGED
@@ -203,14 +203,18 @@ export function sendEvent(event) {
203
203
  saveEventToIDB(enrichedEvent);
204
204
  }
205
205
  }
206
- export function initializeWebSocket(backendApi, apiKey, sessionId) {
206
+ export function initializeWebSocket(backendApi, apiKey, sessionId, envValue) {
207
207
  // Note: Global function span tracking state is now loaded at module initialization time
208
208
  // (see IIFE above) so headers work immediately, even before WebSocket connects.
209
209
  // The WebSocket "funcSpanTrackingControl" message will update the state if needed.
210
210
  const wsHost = getWebSocketHost(backendApi);
211
211
  const apiProtocol = new URL(backendApi).protocol;
212
212
  const wsScheme = apiProtocol === "https:" ? "wss" : "ws";
213
- const wsUrl = `${wsScheme}://${wsHost}/ws/notify/?apiKey=${apiKey}&sessionId=${sessionId}&sender=JS%2FTS&version=${version}`;
213
+ let wsUrl = `${wsScheme}://${wsHost}/ws/notify/?apiKey=${apiKey}&sessionId=${sessionId}&sender=JS%2FTS&version=${version}`;
214
+ // Append envValue if provided
215
+ if (envValue) {
216
+ wsUrl += `&envValue=${encodeURIComponent(envValue)}`;
217
+ }
214
218
  const options = {
215
219
  connectionTimeout: 30000,
216
220
  };
@@ -364,7 +368,12 @@ export function sendMessage(message) {
364
368
  ...message,
365
369
  app_url: message?.app_url ?? window?.location?.href,
366
370
  });
367
- if (isWebSocketOpen(webSocket)) {
371
+ // Check isDraining to prevent out-of-order delivery during reconnection
372
+ // When draining buffered events, queue new messages to maintain order
373
+ if (isDraining || !isWebSocketOpen(webSocket)) {
374
+ saveNotifyMessageToIDB(msg);
375
+ }
376
+ else {
368
377
  try {
369
378
  webSocket.send(msg);
370
379
  }
@@ -372,9 +381,6 @@ export function sendMessage(message) {
372
381
  saveNotifyMessageToIDB(msg);
373
382
  }
374
383
  }
375
- else {
376
- saveNotifyMessageToIDB(msg);
377
- }
378
384
  }
379
385
  function getWebSocketHost(url) {
380
386
  const parser = document.createElement("a");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sailfish-ai/recorder",
3
- "version": "1.8.10",
3
+ "version": "1.8.12",
4
4
  "publishPublicly": true,
5
5
  "type": "module",
6
6
  "main": "dist/recorder.cjs",
@@ -37,7 +37,7 @@
37
37
  "dist"
38
38
  ],
39
39
  "dependencies": {
40
- "@sailfish-ai/sf-map-utils": "0.4.3",
40
+ "@sailfish-ai/sf-map-utils": "0.4.4",
41
41
  "@sailfish-rrweb/rrweb-plugin-console-record": "0.5.2",
42
42
  "@sailfish-rrweb/rrweb-record-only": "0.5.2",
43
43
  "@sailfish-rrweb/types": "0.5.2",