@sailfish-ai/recorder 1.5.8 → 1.6.0

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/index.js CHANGED
@@ -4,7 +4,7 @@ import { gatherAndCacheDeviceInfo } from "./deviceInfo";
4
4
  import { sendRecordingEvents } from "./eventCache";
5
5
  import { fetchCaptureSettings, sendDomainsToNotPropagateHeaderTo, startRecordingSession, } from "./graphql";
6
6
  import { sendMapUuidIfAvailable } from "./mapUuid";
7
- import { initializeRecording } from "./recording";
7
+ import { initializeConsolePlugin, initializeRecording } from "./recording";
8
8
  import { sendMessage } from "./websocket";
9
9
  // Default list of domains to ignore
10
10
  const DOMAINS_TO_NOT_PROPAGATE_HEADER_TO_DEFAULT = [
@@ -16,7 +16,6 @@ const DOMAINS_TO_NOT_PROPAGATE_HEADER_TO_DEFAULT = [
16
16
  "*.smooch.io", // Exclude smooch-related requests
17
17
  "*.zendesk.com", // Exclude zendesk-related requests
18
18
  ];
19
- const DOMAINS_TO_NOT_RECORD_NETWORK_REQUESTS_TO = [];
20
19
  export const DEFAULT_CAPTURE_SETTINGS = {
21
20
  recordCanvas: false,
22
21
  recordCrossOriginIframes: false,
@@ -39,7 +38,6 @@ export const DEFAULT_CONSOLE_RECORDING_SETTINGS = {
39
38
  },
40
39
  logger: "console",
41
40
  };
42
- const PERSIST_SESSION_FOR_REOPENING_TABS = false;
43
41
  // export const DEFAULT_NETWORK_CAPTURE_SETTINGS: NetworkRecordOptions = {
44
42
  // initiatorTypes: ["fetch", "xmlhttprequest"],
45
43
  // ignoreRequestFn: (request) => {
@@ -118,42 +116,13 @@ function getOrSetUserDeviceUuid() {
118
116
  }
119
117
  return userDeviceUuid;
120
118
  }
121
- // Function to generate a unique key for storing sessionId in localStorage
122
- function getTabKey() {
123
- let tabKey = sessionStorage.getItem("sailfishTabKey");
124
- if (!tabKey) {
125
- tabKey = uuidv4();
126
- sessionStorage.setItem("sailfishTabKey", tabKey);
127
- }
128
- return tabKey;
129
- }
130
- // Function to get or set the current sessionId in sessionStorage
131
- function getOrSetSessionId(forceNew = false) {
132
- let sessionId = sessionStorage.getItem("sailfishSessionId");
133
- if (!sessionId || forceNew) {
134
- const tabKey = getTabKey();
135
- const storedSessionId = PERSIST_SESSION_FOR_REOPENING_TABS
136
- ? localStorage.getItem(`sailfishSessionId_${tabKey}`)
137
- : null;
138
- if (storedSessionId && !forceNew) {
139
- sessionId = storedSessionId;
140
- }
141
- else {
142
- sessionId = uuidv4();
143
- }
144
- sessionStorage.setItem("sailfishSessionId", sessionId);
145
- }
146
- return sessionId;
147
- }
148
- // Function to store the current sessionId in localStorage on page unload
149
- function storeSessionId() {
150
- if (PERSIST_SESSION_FOR_REOPENING_TABS) {
151
- const tabKey = getTabKey();
152
- const sessionId = sessionStorage.getItem("sailfishSessionId");
153
- if (sessionId) {
154
- localStorage.setItem(`sailfishSessionId_${tabKey}`, sessionId);
155
- }
119
+ // Storing the sailfishSessionId in window.name, as window.name retains its value after a page refresh
120
+ // but resets when a new tab (including a duplicated tab) is opened.
121
+ function getOrSetSessionId() {
122
+ if (!window.name) {
123
+ window.name = uuidv4();
156
124
  }
125
+ return window.name;
157
126
  }
158
127
  // Function to handle resetting the sessionId when the page becomes visible again
159
128
  function handleVisibilityChange() {
@@ -163,7 +132,6 @@ function handleVisibilityChange() {
163
132
  }
164
133
  // Initialize event listeners for visibility change and page unload
165
134
  document.addEventListener("visibilitychange", handleVisibilityChange);
166
- window.addEventListener("beforeunload", storeSessionId);
167
135
  function storeCredentialsAndConnection({ apiKey, backendApi, }) {
168
136
  sessionStorage.setItem("sailfishApiKey", apiKey);
169
137
  sessionStorage.setItem("sailfishBackendApi", backendApi);
@@ -352,6 +320,7 @@ function setupFetchInterceptor(domainsToNotPropagateHeadersTo, domainsToPropagat
352
320
  }
353
321
  // Main Recording Function
354
322
  export async function startRecording({ apiKey, backendApi = "https://api-service.sailfishqa.com", domainsToPropagateHeaderTo = [], domainsToNotPropagateHeaderTo = [], serviceVersion = "", }) {
323
+ initializeConsolePlugin(DEFAULT_CONSOLE_RECORDING_SETTINGS);
355
324
  let sessionId = getOrSetSessionId();
356
325
  storeCredentialsAndConnection({ apiKey, backendApi });
357
326
  trackDomainChanges();
@@ -369,16 +338,12 @@ export async function startRecording({ apiKey, backendApi = "https://api-service
369
338
  DEFAULT_CAPTURE_SETTINGS;
370
339
  const sessionResponse = await startRecordingSession(apiKey, sessionId, backendApi);
371
340
  if (sessionResponse.data?.startRecordingSession) {
372
- const websocket = await initializeRecording(captureSettings, DEFAULT_CONSOLE_RECORDING_SETTINGS,
341
+ const websocket = await initializeRecording(captureSettings,
373
342
  // DEFAULT_NETWORK_CAPTURE_SETTINGS,
374
343
  backendApi, apiKey, sessionId);
375
344
  // Send parameters once before starting interval
376
345
  sendMapUuidIfAvailable(serviceVersion);
377
- setInterval(() => {
378
- if (websocket && websocket.readyState === WebSocket.OPEN) {
379
- sendRecordingEvents(websocket);
380
- }
381
- }, 10000);
346
+ setInterval(() => sendRecordingEvents(websocket), 10000);
382
347
  }
383
348
  else {
384
349
  console.error("Failed to start recording session:", sessionResponse.errors || sessionResponse);
package/dist/recording.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { getRecordConsolePlugin, } from "@sailfish-rrweb/rrweb-plugin-console-record";
2
2
  import record from "@sailfish-rrweb/rrweb-record-only";
3
+ import { EventType } from "@sailfish-rrweb/types";
3
4
  import { cacheEvents, sendRecordingEvents } from "./eventCache";
4
5
  import { initializeWebSocket } from "./websocket";
5
6
  const MASK_CLASS = "sailfishSanitize";
@@ -36,8 +37,18 @@ function maskInputFn(text, node) {
36
37
  // Default to returning the original text
37
38
  return text;
38
39
  }
40
+ export function initializeConsolePlugin(consoleRecordSettings) {
41
+ const { name, observer } = getRecordConsolePlugin(consoleRecordSettings);
42
+ observer((payload) => cacheEvents({
43
+ type: EventType.Plugin,
44
+ timestamp: Date.now(),
45
+ data: {
46
+ plugin: name,
47
+ payload,
48
+ },
49
+ }), window, consoleRecordSettings);
50
+ }
39
51
  export async function initializeRecording(captureSettings, // TODO - Sibyl post-launch - replace type
40
- consoleRecordSettings,
41
52
  // networkRecordSettings: NetworkRecordOptions,
42
53
  backendApi, apiKey, sessionId) {
43
54
  const webSocket = initializeWebSocket(backendApi, apiKey, sessionId);
@@ -46,10 +57,6 @@ backendApi, apiKey, sessionId) {
46
57
  emit(event) {
47
58
  cacheEvents(event);
48
59
  },
49
- plugins: [
50
- getRecordConsolePlugin(consoleRecordSettings),
51
- // getRecordNetworkPlugin(networkRecordSettings),
52
- ],
53
60
  maskInputOptions: { text: true }, // Fix the incorrect property name
54
61
  maskInputFn,
55
62
  maskTextClass: MASK_CLASS,