@sailfish-ai/recorder 1.2.6 → 1.2.8

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
@@ -93,6 +93,7 @@ function storeCredentialsAndConnection({ apiKey, backendApi, }) {
93
93
  }
94
94
  // Utility function to match domains or paths with wildcard support
95
95
  export function matchUrlWithWildcard(url, patterns) {
96
+ console.log(`Calling matchUrlWithWildcard against ${url}`);
96
97
  if (!url || typeof url !== "string") {
97
98
  throw new Error("Invalid URL input");
98
99
  }
@@ -156,9 +157,7 @@ export function matchUrlWithWildcard(url, patterns) {
156
157
  return true;
157
158
  });
158
159
  }
159
- // Updated XMLHttpRequest interceptor with single check function
160
- // Updated XMLHttpRequest interceptor to bypass for CORS-sensitive domains
161
- // Updated XMLHttpRequest interceptor with exclusion handling
160
+ // Updated XMLHttpRequest interceptor with CORS protection
162
161
  function setupXMLHttpRequestInterceptor(domainsToNotPropagateHeaderTo, domainsToPropagateHeadersTo = []) {
163
162
  const originalOpen = XMLHttpRequest.prototype.open;
164
163
  const originalSend = XMLHttpRequest.prototype.send;
@@ -168,29 +167,47 @@ function setupXMLHttpRequestInterceptor(domainsToNotPropagateHeaderTo, domainsTo
168
167
  ...DOMAINS_TO_NOT_PROPAGATE_HEADER_TO_DEFAULT,
169
168
  ...domainsToNotPropagateHeaderTo,
170
169
  ];
171
- // Store URL during open()
170
+ // Exclude certain resource types (like images) from being intercepted
171
+ const resourceExcludeList = ["image", "font", "script"];
172
+ // Intercept open()
172
173
  XMLHttpRequest.prototype.open = function (method, url, ...args) {
174
+ console.log("Sailfish XMLHttpRequest.prototype.open", method, url);
173
175
  this._requestUrl = typeof url === "string" && url.length > 0 ? url : null;
176
+ // Skip interception for excluded resource types (e.g., images)
177
+ const resourceType = this.getResponseHeader("content-type");
178
+ if (resourceType &&
179
+ resourceExcludeList.some((type) => resourceType.includes(type))) {
180
+ console.log(`[XML] Skipping resource request for ${url} (type: ${resourceType})`);
181
+ return originalOpen.apply(this, [method, url, ...args]);
182
+ }
174
183
  return originalOpen.apply(this, [method, url, ...args]);
175
184
  };
176
185
  // Intercept send()
177
186
  XMLHttpRequest.prototype.send = function (...args) {
187
+ console.log("Sailfish XMLHttpRequest.prototype.send", this._requestUrl);
178
188
  const url = this._requestUrl;
179
189
  if (!url)
180
190
  return originalSend.apply(this, args);
181
- // Check if domain should be ignored based on combined ignore list
191
+ // Skip domain check for certain resources like images or fonts
182
192
  if (matchUrlWithWildcard(url, combinedIgnoreDomains)) {
183
- console.log([`[XML] [InIgnoreDomains] IGNORE --> ${url}`]);
193
+ console.log(`[XML] [InIgnoreDomains] IGNORE --> ${url}`);
184
194
  return originalSend.apply(this, args);
185
195
  }
186
196
  // Check if domain should propagate headers
187
197
  const shouldPropagateHeader = domainsToPropagateHeadersTo.length === 0 ||
188
198
  matchUrlWithWildcard(url, domainsToPropagateHeadersTo);
189
199
  if (sessionId && shouldPropagateHeader) {
190
- console.log([`[XML] [InPropagateDomans] PROPAGATE FOR --> ${url}`]);
191
- this.setRequestHeader("X-Sf3-Rid", sessionId);
200
+ console.log(`[XML] [InPropagateDomains] PROPAGATE FOR --> ${url}`);
201
+ try {
202
+ this.setRequestHeader("X-Sf3-Rid", sessionId);
203
+ }
204
+ catch (e) {
205
+ console.warn(`Could not set X-Sf3-Rid header for ${url}`, e);
206
+ }
207
+ }
208
+ else {
209
+ console.log(`[XML] [NOT InPropagateDomains] IGNORE --> ${url}`);
192
210
  }
193
- console.log([`[XML] [NOT InPropagateDomans] IGNORE --> ${url}`]);
194
211
  return originalSend.apply(this, args);
195
212
  };
196
213
  }
@@ -218,6 +235,7 @@ function setupFetchInterceptor(domainsToNotPropagateHeadersTo, domainsToPropagat
218
235
  url = input.href;
219
236
  }
220
237
  else {
238
+ console.log("Unsupported args -->", args);
221
239
  return target.apply(thisArg, args); // Skip unsupported inputs
222
240
  }
223
241
  // Cache check
@@ -234,16 +252,16 @@ function setupFetchInterceptor(domainsToNotPropagateHeadersTo, domainsToPropagat
234
252
  }
235
253
  // Check domain exclusion
236
254
  if (matchUrlWithWildcard(url, combinedIgnoreDomains)) {
237
- cache.set(url, "ignore");
238
255
  console.log(`[InIgnoreDomains] IGNORE --> ${url}`);
256
+ cache.set(url, "ignore");
239
257
  return target.apply(thisArg, args);
240
258
  }
241
259
  // Check domain propagation
242
260
  const shouldPropagateHeader = domainsToPropagateHeadersTo.length === 0 ||
243
261
  matchUrlWithWildcard(url, domainsToPropagateHeadersTo);
244
262
  if (!shouldPropagateHeader) {
245
- cache.set(url, "ignore");
246
263
  console.log(`[NOT InPropagateDomans] IGNORE --> ${url}`);
264
+ cache.set(url, "ignore");
247
265
  return target.apply(thisArg, args);
248
266
  }
249
267
  cache.set(url, "propagate");
@@ -262,6 +280,7 @@ function setupFetchInterceptor(domainsToNotPropagateHeadersTo, domainsToPropagat
262
280
  const modifiedRequest = new Request(clonedRequest, {
263
281
  headers: newHeaders,
264
282
  });
283
+ console.log(`[modified call] newHeaders --> `, newHeaders);
265
284
  return target.call(thisArg, modifiedRequest, init);
266
285
  }
267
286
  else {
@@ -270,10 +289,12 @@ function setupFetchInterceptor(domainsToNotPropagateHeadersTo, domainsToPropagat
270
289
  const newHeaders = new Headers(init.headers || {});
271
290
  newHeaders.set("X-Sf3-Rid", sessionId);
272
291
  modifiedInit.headers = newHeaders;
292
+ console.log(`[modified call] newHeaders --> `, newHeaders);
273
293
  return target.call(thisArg, input, modifiedInit);
274
294
  }
275
295
  }
276
296
  else {
297
+ console.log("[UNMODIFIED CALL]");
277
298
  return target.apply(thisArg, args);
278
299
  }
279
300
  }