@sailfish-ai/recorder 1.2.10 → 1.3.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
@@ -55,22 +55,6 @@ export const DEFAULT_CONSOLE_RECORDING_SETTINGS = {
55
55
  // recordBody: true,
56
56
  // recordInitialRequests: false,
57
57
  // };
58
- // Function to strip 'www.' and get the effective domain from a URL without tldts
59
- function getEffectiveDomain(url) {
60
- try {
61
- const parsedUrl = new URL(url);
62
- let domain = parsedUrl.hostname;
63
- // Strip 'www.' if present
64
- if (domain.startsWith("www.")) {
65
- domain = domain.slice(4);
66
- }
67
- return domain;
68
- }
69
- catch (error) {
70
- console.error("Invalid URL passed to getEffectiveDomain:", url);
71
- return url; // Return the input if URL parsing fails
72
- }
73
- }
74
58
  // Functions
75
59
  // Function to get the current sessionId from sessionStorage
76
60
  function getOrSetSessionId(forceNew = false) {
@@ -98,7 +82,6 @@ function storeCredentialsAndConnection({ apiKey, backendApi, }) {
98
82
  }
99
83
  // Utility function to match domains or paths with wildcard support
100
84
  export function matchUrlWithWildcard(url, patterns) {
101
- console.log(`Calling matchUrlWithWildcard against ${url}`);
102
85
  if (!url || typeof url !== "string") {
103
86
  throw new Error("Invalid URL input");
104
87
  }
@@ -162,7 +145,6 @@ export function matchUrlWithWildcard(url, patterns) {
162
145
  return true;
163
146
  });
164
147
  }
165
- // Updated XMLHttpRequest interceptor with CORS protection
166
148
  // Updated XMLHttpRequest interceptor with domain exclusion
167
149
  function setupXMLHttpRequestInterceptor(domainsToNotPropagateHeaderTo, domainsToPropagateHeadersTo = []) {
168
150
  const originalOpen = XMLHttpRequest.prototype.open;
@@ -175,31 +157,22 @@ function setupXMLHttpRequestInterceptor(domainsToNotPropagateHeaderTo, domainsTo
175
157
  ];
176
158
  // Intercept open()
177
159
  XMLHttpRequest.prototype.open = function (method, url, ...args) {
178
- console.log("Sailfish XMLHttpRequest.prototype.open", method, url);
179
160
  this._requestUrl = typeof url === "string" && url.length > 0 ? url : null;
180
- // Skip interception for excluded domains
181
- if (matchUrlWithWildcard(url, combinedIgnoreDomains)) {
182
- console.log(`[XML] Skipping request for excluded domain: ${url}`);
183
- return originalOpen.apply(this, [method, url, ...args]);
184
- }
185
161
  return originalOpen.apply(this, [method, url, ...args]);
186
162
  };
187
163
  // Intercept send()
188
164
  XMLHttpRequest.prototype.send = function (...args) {
189
- console.log("Sailfish XMLHttpRequest.prototype.send", this._requestUrl);
190
165
  const url = this._requestUrl;
191
166
  if (!url)
192
167
  return originalSend.apply(this, args);
193
168
  // Skip domain check for excluded domains
194
169
  if (matchUrlWithWildcard(url, combinedIgnoreDomains)) {
195
- console.log(`[XML] [ExcludedDomain] IGNORE --> ${url}`);
196
170
  return originalSend.apply(this, args);
197
171
  }
198
172
  // Check if domain should propagate headers
199
173
  const shouldPropagateHeader = domainsToPropagateHeadersTo.length === 0 ||
200
174
  matchUrlWithWildcard(url, domainsToPropagateHeadersTo);
201
175
  if (sessionId && shouldPropagateHeader) {
202
- console.log(`[XML] [InPropagateDomains] PROPAGATE FOR --> ${url}`);
203
176
  try {
204
177
  this.setRequestHeader("X-Sf3-Rid", sessionId);
205
178
  }
@@ -207,9 +180,6 @@ function setupXMLHttpRequestInterceptor(domainsToNotPropagateHeaderTo, domainsTo
207
180
  console.warn(`Could not set X-Sf3-Rid header for ${url}`, e);
208
181
  }
209
182
  }
210
- else {
211
- console.log(`[XML] [NOT InPropagateDomains] IGNORE --> ${url}`);
212
- }
213
183
  return originalSend.apply(this, args);
214
184
  };
215
185
  }
@@ -237,24 +207,20 @@ function setupFetchInterceptor(domainsToNotPropagateHeadersTo, domainsToPropagat
237
207
  url = input.href;
238
208
  }
239
209
  else {
240
- console.log("Unsupported args -->", args);
241
210
  return target.apply(thisArg, args); // Skip unsupported inputs
242
211
  }
243
212
  // Cache check
244
213
  if (cache.has(url)) {
245
214
  const cachedResult = cache.get(url);
246
215
  if (cachedResult === "ignore") {
247
- console.log(`[CACHE] IGNORE --> ${url}`);
248
216
  return target.apply(thisArg, args);
249
217
  }
250
218
  if (cachedResult === "propagate") {
251
- console.log(`[CACHE] PROPAGATE FOR --> ${url}`);
252
219
  return injectHeader(target, thisArg, args, input, init, sessionId);
253
220
  }
254
221
  }
255
222
  // Check domain exclusion
256
223
  if (matchUrlWithWildcard(url, combinedIgnoreDomains)) {
257
- console.log(`[InIgnoreDomains] IGNORE --> ${url}`);
258
224
  cache.set(url, "ignore");
259
225
  return target.apply(thisArg, args);
260
226
  }
@@ -262,12 +228,10 @@ function setupFetchInterceptor(domainsToNotPropagateHeadersTo, domainsToPropagat
262
228
  const shouldPropagateHeader = domainsToPropagateHeadersTo.length === 0 ||
263
229
  matchUrlWithWildcard(url, domainsToPropagateHeadersTo);
264
230
  if (!shouldPropagateHeader) {
265
- console.log(`[NOT InPropagateDomans] IGNORE --> ${url}`);
266
231
  cache.set(url, "ignore");
267
232
  return target.apply(thisArg, args);
268
233
  }
269
234
  cache.set(url, "propagate");
270
- console.log(`[InPropagateDomans] PROPAGATE FOR --> ${url}`);
271
235
  return injectHeader(target, thisArg, args, input, init, sessionId);
272
236
  },
273
237
  });
@@ -282,7 +246,6 @@ function setupFetchInterceptor(domainsToNotPropagateHeadersTo, domainsToPropagat
282
246
  const modifiedRequest = new Request(clonedRequest, {
283
247
  headers: newHeaders,
284
248
  });
285
- console.log(`[modified call] newHeaders --> `, newHeaders);
286
249
  return target.call(thisArg, modifiedRequest, init);
287
250
  }
288
251
  else {
@@ -291,12 +254,10 @@ function setupFetchInterceptor(domainsToNotPropagateHeadersTo, domainsToPropagat
291
254
  const newHeaders = new Headers(init.headers || {});
292
255
  newHeaders.set("X-Sf3-Rid", sessionId);
293
256
  modifiedInit.headers = newHeaders;
294
- console.log(`[modified call] newHeaders --> `, newHeaders);
295
257
  return target.call(thisArg, input, modifiedInit);
296
258
  }
297
259
  }
298
260
  else {
299
- console.log("[UNMODIFIED CALL]");
300
261
  return target.apply(thisArg, args);
301
262
  }
302
263
  }