@sailfish-ai/recorder 1.2.11 → 1.3.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.
- package/dist/index.js +53 -27
- package/dist/sailfish-recorder.cjs.js +1 -1
- package/dist/sailfish-recorder.cjs.js.br +0 -0
- package/dist/sailfish-recorder.cjs.js.gz +0 -0
- package/dist/sailfish-recorder.es.js +1 -1
- package/dist/sailfish-recorder.es.js.br +0 -0
- package/dist/sailfish-recorder.es.js.gz +0 -0
- package/dist/sailfish-recorder.umd.js +1 -1
- package/dist/sailfish-recorder.umd.js.br +0 -0
- package/dist/sailfish-recorder.umd.js.gz +0 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import { gatherAndCacheDeviceInfo } from "./deviceInfo";
|
|
|
4
4
|
import { sendRecordingEvents } from "./eventCache";
|
|
5
5
|
import { fetchCaptureSettings, sendDomainsToNotPropagateHeaderTo, startRecordingSession, } from "./graphql";
|
|
6
6
|
import { initializeRecording } from "./recording";
|
|
7
|
+
import { sendMessage } from "./websocket";
|
|
7
8
|
// Default list of domains to ignore
|
|
8
9
|
const DOMAINS_TO_NOT_PROPAGATE_HEADER_TO_DEFAULT = [
|
|
9
10
|
"t.co",
|
|
@@ -55,34 +56,78 @@ export const DEFAULT_CONSOLE_RECORDING_SETTINGS = {
|
|
|
55
56
|
// recordBody: true,
|
|
56
57
|
// recordInitialRequests: false,
|
|
57
58
|
// };
|
|
59
|
+
const PERSIST_SESSION_FOR_REOPENING_TABS = false;
|
|
58
60
|
// Functions
|
|
59
|
-
// Function to get the
|
|
61
|
+
// Function to get or set the device & program UUID in localStorage
|
|
62
|
+
function getOrSetUserDeviceUuid() {
|
|
63
|
+
let userDeviceUuid = localStorage.getItem("sailfishUserDeviceUuid");
|
|
64
|
+
if (!userDeviceUuid) {
|
|
65
|
+
userDeviceUuid = uuidv4();
|
|
66
|
+
localStorage.setItem("sailfishUserDeviceUuid", userDeviceUuid);
|
|
67
|
+
}
|
|
68
|
+
return userDeviceUuid;
|
|
69
|
+
}
|
|
70
|
+
// Function to generate a unique key for storing sessionId in localStorage
|
|
71
|
+
function getTabKey() {
|
|
72
|
+
let tabKey = sessionStorage.getItem("sailfishTabKey");
|
|
73
|
+
if (!tabKey) {
|
|
74
|
+
tabKey = uuidv4();
|
|
75
|
+
sessionStorage.setItem("sailfishTabKey", tabKey);
|
|
76
|
+
}
|
|
77
|
+
return tabKey;
|
|
78
|
+
}
|
|
79
|
+
// Function to get or set the current sessionId in sessionStorage
|
|
60
80
|
function getOrSetSessionId(forceNew = false) {
|
|
61
81
|
let sessionId = sessionStorage.getItem("sailfishSessionId");
|
|
62
82
|
if (!sessionId || forceNew) {
|
|
63
|
-
|
|
83
|
+
const tabKey = getTabKey();
|
|
84
|
+
const storedSessionId = PERSIST_SESSION_FOR_REOPENING_TABS
|
|
85
|
+
? localStorage.getItem(`sailfishSessionId_${tabKey}`)
|
|
86
|
+
: null;
|
|
87
|
+
if (storedSessionId && !forceNew) {
|
|
88
|
+
sessionId = storedSessionId;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
sessionId = uuidv4();
|
|
92
|
+
}
|
|
64
93
|
sessionStorage.setItem("sailfishSessionId", sessionId);
|
|
65
94
|
}
|
|
66
95
|
return sessionId;
|
|
67
96
|
}
|
|
68
|
-
// Function to
|
|
97
|
+
// Function to store the current sessionId in localStorage on page unload
|
|
98
|
+
function storeSessionId() {
|
|
99
|
+
if (PERSIST_SESSION_FOR_REOPENING_TABS) {
|
|
100
|
+
const tabKey = getTabKey();
|
|
101
|
+
const sessionId = sessionStorage.getItem("sailfishSessionId");
|
|
102
|
+
if (sessionId) {
|
|
103
|
+
localStorage.setItem(`sailfishSessionId_${tabKey}`, sessionId);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// Function to handle resetting the sessionId when the page becomes visible again
|
|
69
108
|
function handleVisibilityChange() {
|
|
70
109
|
if (document.visibilityState === "visible") {
|
|
71
|
-
getOrSetSessionId(
|
|
110
|
+
getOrSetSessionId(); // Restore sessionId when the user returns to the page
|
|
72
111
|
}
|
|
73
112
|
}
|
|
74
113
|
// Initialize event listeners for visibility change and page unload
|
|
75
114
|
document.addEventListener("visibilitychange", handleVisibilityChange);
|
|
76
|
-
window.addEventListener("beforeunload",
|
|
77
|
-
|
|
78
|
-
|
|
115
|
+
window.addEventListener("beforeunload", storeSessionId);
|
|
116
|
+
export function sendUserUuid() {
|
|
117
|
+
const userDeviceUuid = getOrSetUserDeviceUuid();
|
|
118
|
+
const message = {
|
|
119
|
+
type: "userDeviceUuid",
|
|
120
|
+
userDeviceUuid,
|
|
121
|
+
};
|
|
122
|
+
sendMessage(message);
|
|
123
|
+
}
|
|
124
|
+
sendUserUuid();
|
|
79
125
|
function storeCredentialsAndConnection({ apiKey, backendApi, }) {
|
|
80
126
|
sessionStorage.setItem("sailfishApiKey", apiKey);
|
|
81
127
|
sessionStorage.setItem("sailfishBackendApi", backendApi);
|
|
82
128
|
}
|
|
83
129
|
// Utility function to match domains or paths with wildcard support
|
|
84
130
|
export function matchUrlWithWildcard(url, patterns) {
|
|
85
|
-
console.log(`Calling matchUrlWithWildcard against ${url}`);
|
|
86
131
|
if (!url || typeof url !== "string") {
|
|
87
132
|
throw new Error("Invalid URL input");
|
|
88
133
|
}
|
|
@@ -148,7 +193,6 @@ export function matchUrlWithWildcard(url, patterns) {
|
|
|
148
193
|
}
|
|
149
194
|
// Updated XMLHttpRequest interceptor with domain exclusion
|
|
150
195
|
function setupXMLHttpRequestInterceptor(domainsToNotPropagateHeaderTo, domainsToPropagateHeadersTo = []) {
|
|
151
|
-
console.log("[Sailfish] RUNNING setupXMLHttpRequestInterceptor");
|
|
152
196
|
const originalOpen = XMLHttpRequest.prototype.open;
|
|
153
197
|
const originalSend = XMLHttpRequest.prototype.send;
|
|
154
198
|
const sessionId = getOrSetSessionId();
|
|
@@ -159,26 +203,22 @@ function setupXMLHttpRequestInterceptor(domainsToNotPropagateHeaderTo, domainsTo
|
|
|
159
203
|
];
|
|
160
204
|
// Intercept open()
|
|
161
205
|
XMLHttpRequest.prototype.open = function (method, url, ...args) {
|
|
162
|
-
console.log("Sailfish XMLHttpRequest.prototype.open", method, url);
|
|
163
206
|
this._requestUrl = typeof url === "string" && url.length > 0 ? url : null;
|
|
164
207
|
return originalOpen.apply(this, [method, url, ...args]);
|
|
165
208
|
};
|
|
166
209
|
// Intercept send()
|
|
167
210
|
XMLHttpRequest.prototype.send = function (...args) {
|
|
168
|
-
console.log("Sailfish XMLHttpRequest.prototype.send", this._requestUrl);
|
|
169
211
|
const url = this._requestUrl;
|
|
170
212
|
if (!url)
|
|
171
213
|
return originalSend.apply(this, args);
|
|
172
214
|
// Skip domain check for excluded domains
|
|
173
215
|
if (matchUrlWithWildcard(url, combinedIgnoreDomains)) {
|
|
174
|
-
console.log(`[XML] [ExcludedDomain] IGNORE --> ${url}`);
|
|
175
216
|
return originalSend.apply(this, args);
|
|
176
217
|
}
|
|
177
218
|
// Check if domain should propagate headers
|
|
178
219
|
const shouldPropagateHeader = domainsToPropagateHeadersTo.length === 0 ||
|
|
179
220
|
matchUrlWithWildcard(url, domainsToPropagateHeadersTo);
|
|
180
221
|
if (sessionId && shouldPropagateHeader) {
|
|
181
|
-
console.log(`[XML] [InPropagateDomains] PROPAGATE FOR --> ${url}`);
|
|
182
222
|
try {
|
|
183
223
|
this.setRequestHeader("X-Sf3-Rid", sessionId);
|
|
184
224
|
}
|
|
@@ -186,15 +226,11 @@ function setupXMLHttpRequestInterceptor(domainsToNotPropagateHeaderTo, domainsTo
|
|
|
186
226
|
console.warn(`Could not set X-Sf3-Rid header for ${url}`, e);
|
|
187
227
|
}
|
|
188
228
|
}
|
|
189
|
-
else {
|
|
190
|
-
console.log(`[XML] [NOT InPropagateDomains] IGNORE --> ${url}`);
|
|
191
|
-
}
|
|
192
229
|
return originalSend.apply(this, args);
|
|
193
230
|
};
|
|
194
231
|
}
|
|
195
232
|
// Updated fetch interceptor with exclusion handling
|
|
196
233
|
function setupFetchInterceptor(domainsToNotPropagateHeadersTo, domainsToPropagateHeadersTo = []) {
|
|
197
|
-
console.log("[Sailfish] RUNNING setupFetchInterceptor");
|
|
198
234
|
const originalFetch = window.fetch;
|
|
199
235
|
const sessionId = getOrSetSessionId();
|
|
200
236
|
const combinedIgnoreDomains = [
|
|
@@ -217,24 +253,20 @@ function setupFetchInterceptor(domainsToNotPropagateHeadersTo, domainsToPropagat
|
|
|
217
253
|
url = input.href;
|
|
218
254
|
}
|
|
219
255
|
else {
|
|
220
|
-
console.log("Unsupported args -->", args);
|
|
221
256
|
return target.apply(thisArg, args); // Skip unsupported inputs
|
|
222
257
|
}
|
|
223
258
|
// Cache check
|
|
224
259
|
if (cache.has(url)) {
|
|
225
260
|
const cachedResult = cache.get(url);
|
|
226
261
|
if (cachedResult === "ignore") {
|
|
227
|
-
console.log(`[CACHE] IGNORE --> ${url}`);
|
|
228
262
|
return target.apply(thisArg, args);
|
|
229
263
|
}
|
|
230
264
|
if (cachedResult === "propagate") {
|
|
231
|
-
console.log(`[CACHE] PROPAGATE FOR --> ${url}`);
|
|
232
265
|
return injectHeader(target, thisArg, args, input, init, sessionId);
|
|
233
266
|
}
|
|
234
267
|
}
|
|
235
268
|
// Check domain exclusion
|
|
236
269
|
if (matchUrlWithWildcard(url, combinedIgnoreDomains)) {
|
|
237
|
-
console.log(`[InIgnoreDomains] IGNORE --> ${url}`);
|
|
238
270
|
cache.set(url, "ignore");
|
|
239
271
|
return target.apply(thisArg, args);
|
|
240
272
|
}
|
|
@@ -242,18 +274,15 @@ function setupFetchInterceptor(domainsToNotPropagateHeadersTo, domainsToPropagat
|
|
|
242
274
|
const shouldPropagateHeader = domainsToPropagateHeadersTo.length === 0 ||
|
|
243
275
|
matchUrlWithWildcard(url, domainsToPropagateHeadersTo);
|
|
244
276
|
if (!shouldPropagateHeader) {
|
|
245
|
-
console.log(`[NOT InPropagateDomans] IGNORE --> ${url}`);
|
|
246
277
|
cache.set(url, "ignore");
|
|
247
278
|
return target.apply(thisArg, args);
|
|
248
279
|
}
|
|
249
280
|
cache.set(url, "propagate");
|
|
250
|
-
console.log(`[InPropagateDomans] PROPAGATE FOR --> ${url}`);
|
|
251
281
|
return injectHeader(target, thisArg, args, input, init, sessionId);
|
|
252
282
|
},
|
|
253
283
|
});
|
|
254
284
|
// Helper function to inject the X-Sf3-Rid header
|
|
255
285
|
function injectHeader(target, thisArg, args, input, init, sessionId) {
|
|
256
|
-
console.log("[Sailfish] RUNNING injectHeader");
|
|
257
286
|
if (sessionId) {
|
|
258
287
|
if (input instanceof Request) {
|
|
259
288
|
// Clone the Request and modify headers
|
|
@@ -263,7 +292,6 @@ function setupFetchInterceptor(domainsToNotPropagateHeadersTo, domainsToPropagat
|
|
|
263
292
|
const modifiedRequest = new Request(clonedRequest, {
|
|
264
293
|
headers: newHeaders,
|
|
265
294
|
});
|
|
266
|
-
console.log(`[modified call] newHeaders --> `, newHeaders);
|
|
267
295
|
return target.call(thisArg, modifiedRequest, init);
|
|
268
296
|
}
|
|
269
297
|
else {
|
|
@@ -272,12 +300,10 @@ function setupFetchInterceptor(domainsToNotPropagateHeadersTo, domainsToPropagat
|
|
|
272
300
|
const newHeaders = new Headers(init.headers || {});
|
|
273
301
|
newHeaders.set("X-Sf3-Rid", sessionId);
|
|
274
302
|
modifiedInit.headers = newHeaders;
|
|
275
|
-
console.log(`[modified call] newHeaders --> `, newHeaders);
|
|
276
303
|
return target.call(thisArg, input, modifiedInit);
|
|
277
304
|
}
|
|
278
305
|
}
|
|
279
306
|
else {
|
|
280
|
-
console.log("[UNMODIFIED CALL]");
|
|
281
307
|
return target.apply(thisArg, args);
|
|
282
308
|
}
|
|
283
309
|
}
|