@sailfish-ai/recorder 1.2.5 → 1.2.6

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
@@ -158,79 +158,56 @@ export function matchUrlWithWildcard(url, patterns) {
158
158
  }
159
159
  // Updated XMLHttpRequest interceptor with single check function
160
160
  // Updated XMLHttpRequest interceptor to bypass for CORS-sensitive domains
161
+ // Updated XMLHttpRequest interceptor with exclusion handling
161
162
  function setupXMLHttpRequestInterceptor(domainsToNotPropagateHeaderTo, domainsToPropagateHeadersTo = []) {
162
163
  const originalOpen = XMLHttpRequest.prototype.open;
163
164
  const originalSend = XMLHttpRequest.prototype.send;
164
165
  const sessionId = getOrSetSessionId();
165
- // Combine default and passed ignore domains
166
+ // Combined ignore and propagate logic
166
167
  const combinedIgnoreDomains = [
167
168
  ...DOMAINS_TO_NOT_PROPAGATE_HEADER_TO_DEFAULT,
168
169
  ...domainsToNotPropagateHeaderTo,
169
170
  ];
170
171
  // Store URL during open()
171
172
  XMLHttpRequest.prototype.open = function (method, url, ...args) {
172
- // Ensure the URL is a string, otherwise handle gracefully
173
- if (typeof url === "string" && url.length > 0) {
174
- this._requestUrl = url; // Capture the valid URL
175
- }
176
- else {
177
- console.warn("Invalid or non-string URL passed to XMLHttpRequest:", url);
178
- this._requestUrl = null; // Handle invalid or non-string URL
179
- }
173
+ this._requestUrl = typeof url === "string" && url.length > 0 ? url : null;
180
174
  return originalOpen.apply(this, [method, url, ...args]);
181
175
  };
182
176
  // Intercept send()
183
177
  XMLHttpRequest.prototype.send = function (...args) {
184
178
  const url = this._requestUrl;
185
- // If no valid URL was captured, proceed without modification
186
- if (!url) {
179
+ if (!url)
187
180
  return originalSend.apply(this, args);
188
- }
189
- // Bypass logic for domains listed in the combinedIgnoreDomains
181
+ // Check if domain should be ignored based on combined ignore list
190
182
  if (matchUrlWithWildcard(url, combinedIgnoreDomains)) {
183
+ console.log([`[XML] [InIgnoreDomains] IGNORE --> ${url}`]);
191
184
  return originalSend.apply(this, args);
192
185
  }
193
- // Check if the domain should propagate headers
186
+ // Check if domain should propagate headers
194
187
  const shouldPropagateHeader = domainsToPropagateHeadersTo.length === 0 ||
195
188
  matchUrlWithWildcard(url, domainsToPropagateHeadersTo);
196
189
  if (sessionId && shouldPropagateHeader) {
190
+ console.log([`[XML] [InPropagateDomans] PROPAGATE FOR --> ${url}`]);
197
191
  this.setRequestHeader("X-Sf3-Rid", sessionId);
198
192
  }
193
+ console.log([`[XML] [NOT InPropagateDomans] IGNORE --> ${url}`]);
199
194
  return originalSend.apply(this, args);
200
195
  };
201
196
  }
202
- // Updated fetch interceptor to bypass for CORS-sensitive domains
203
- function setupFetchInterceptor(domainsToNotPatchFetchFor, domainsToPropagateHeadersTo = []) {
197
+ // Updated fetch interceptor with exclusion handling
198
+ function setupFetchInterceptor(domainsToNotPropagateHeadersTo, domainsToPropagateHeadersTo = []) {
204
199
  const originalFetch = window.fetch;
205
200
  const sessionId = getOrSetSessionId();
206
- // Combine default and passed ignore domains
207
201
  const combinedIgnoreDomains = [
208
202
  ...DOMAINS_TO_NOT_PROPAGATE_HEADER_TO_DEFAULT,
209
- ...domainsToNotPatchFetchFor,
203
+ ...domainsToNotPropagateHeadersTo,
210
204
  ];
211
- // Cache results of domain checks to reduce performance overhead
212
205
  const cache = new Map();
213
- // Function to check if the input is a non-standard fetch input (Blob, FormData, etc.)
214
- function isNonStandardRequestInfo(input) {
215
- return (input instanceof Blob ||
216
- input instanceof FormData ||
217
- input instanceof ArrayBuffer);
218
- }
219
- // Function to check if fetch is polyfilled (e.g., in older browsers or Node.js)
220
- function isPolyfilledFetch() {
221
- return !window.fetch.toString().includes("[native code]");
222
- }
223
- // Log a warning if fetch is polyfilled
224
- if (isPolyfilledFetch()) {
225
- console.log("Fetch is polyfilled, behavior may differ from native fetch.");
226
- }
227
- // Proxy to conditionally intercept fetch based on domains
228
206
  window.fetch = new Proxy(originalFetch, {
229
207
  apply: (target, thisArg, args) => {
230
208
  let input = args[0];
231
209
  let init = args[1] || {};
232
210
  let url;
233
- // Handle different types of `input` for fetch
234
211
  if (typeof input === "string") {
235
212
  url = input;
236
213
  }
@@ -240,52 +217,38 @@ function setupFetchInterceptor(domainsToNotPatchFetchFor, domainsToPropagateHead
240
217
  else if (input instanceof URL) {
241
218
  url = input.href;
242
219
  }
243
- else if (isNonStandardRequestInfo(input)) {
244
- // Pass through non-standard inputs like Blob, FormData, etc.
245
- return target.apply(thisArg, args);
246
- }
247
220
  else {
248
- // Unsupported input type, skip interception
249
- console.warn("Unsupported input type for fetch:", input);
250
- return target.apply(thisArg, args);
221
+ return target.apply(thisArg, args); // Skip unsupported inputs
251
222
  }
252
- // Check the cache for domain results to avoid redundant checks
223
+ // Cache check
253
224
  if (cache.has(url)) {
254
225
  const cachedResult = cache.get(url);
255
226
  if (cachedResult === "ignore") {
227
+ console.log(`[CACHE] IGNORE --> ${url}`);
256
228
  return target.apply(thisArg, args);
257
229
  }
258
230
  if (cachedResult === "propagate") {
231
+ console.log(`[CACHE] PROPAGATE FOR --> ${url}`);
259
232
  return injectHeader(target, thisArg, args, input, init, sessionId);
260
233
  }
261
234
  }
262
- // ** Security Restriction Handling **
263
- try {
264
- // ** Check if we should skip patching fetch entirely for this domain **
265
- if (matchUrlWithWildcard(url, combinedIgnoreDomains)) {
266
- // Cache the result for this domain to avoid future checks
267
- cache.set(url, "ignore");
268
- return target.apply(thisArg, args);
269
- }
270
- // Check if the domain should propagate the header
271
- const shouldPropagateHeader = domainsToPropagateHeadersTo.length === 0 ||
272
- matchUrlWithWildcard(url, domainsToPropagateHeadersTo);
273
- // ** Skip CORS-sensitive requests **
274
- if (!shouldPropagateHeader) {
275
- // Cache the result for this domain to avoid future checks
276
- cache.set(url, "ignore");
277
- return target.apply(thisArg, args);
278
- }
279
- // Cache the result for this domain
280
- cache.set(url, "propagate");
281
- // ** Proceed to inject X-Sf3-Rid header **
282
- return injectHeader(target, thisArg, args, input, init, sessionId);
235
+ // Check domain exclusion
236
+ if (matchUrlWithWildcard(url, combinedIgnoreDomains)) {
237
+ cache.set(url, "ignore");
238
+ console.log(`[InIgnoreDomains] IGNORE --> ${url}`);
239
+ return target.apply(thisArg, args);
283
240
  }
284
- catch (error) {
285
- // ** Handle security restrictions and fallback to the original fetch **
286
- console.error("Failed to intercept fetch due to security restrictions:", error);
241
+ // Check domain propagation
242
+ const shouldPropagateHeader = domainsToPropagateHeadersTo.length === 0 ||
243
+ matchUrlWithWildcard(url, domainsToPropagateHeadersTo);
244
+ if (!shouldPropagateHeader) {
245
+ cache.set(url, "ignore");
246
+ console.log(`[NOT InPropagateDomans] IGNORE --> ${url}`);
287
247
  return target.apply(thisArg, args);
288
248
  }
249
+ cache.set(url, "propagate");
250
+ console.log(`[InPropagateDomans] PROPAGATE FOR --> ${url}`);
251
+ return injectHeader(target, thisArg, args, input, init, sessionId);
289
252
  },
290
253
  });
291
254
  // Helper function to inject the X-Sf3-Rid header