@sailfish-ai/recorder 1.2.1 → 1.2.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 CHANGED
@@ -159,6 +159,7 @@ export function matchUrlWithWildcard(url, patterns) {
159
159
  // Updated XMLHttpRequest interceptor with single check function
160
160
  // Updated XMLHttpRequest interceptor to bypass for CORS-sensitive domains
161
161
  function setupXMLHttpRequestInterceptor(domainsToNotPropagateHeaderTo, domainsToPropagateHeadersTo = []) {
162
+ const originalOpen = XMLHttpRequest.prototype.open;
162
163
  const originalSend = XMLHttpRequest.prototype.send;
163
164
  const sessionId = getOrSetSessionId();
164
165
  // Combine default and passed ignore domains
@@ -166,8 +167,25 @@ function setupXMLHttpRequestInterceptor(domainsToNotPropagateHeaderTo, domainsTo
166
167
  ...DOMAINS_TO_NOT_PROPAGATE_HEADER_TO_DEFAULT,
167
168
  ...domainsToNotPropagateHeaderTo,
168
169
  ];
170
+ // Store URL during open()
171
+ 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
+ }
180
+ return originalOpen.apply(this, [method, url, ...args]);
181
+ };
182
+ // Intercept send()
169
183
  XMLHttpRequest.prototype.send = function (...args) {
170
- const url = this._url;
184
+ const url = this._requestUrl;
185
+ // If no valid URL was captured, proceed without modification
186
+ if (!url) {
187
+ return originalSend.apply(this, args);
188
+ }
171
189
  // Bypass logic for domains listed in the combinedIgnoreDomains
172
190
  if (matchUrlWithWildcard(url, combinedIgnoreDomains)) {
173
191
  return originalSend.apply(this, args);
@@ -192,13 +210,22 @@ function setupFetchInterceptor(domainsToNotPropagateHeaderTo, domainsToPropagate
192
210
  ];
193
211
  window.fetch = function (input, init) {
194
212
  let url;
213
+ // Handle different types of `input` for fetch
195
214
  if (typeof input === "string") {
215
+ // String URL
196
216
  url = input;
197
217
  }
198
218
  else if (input instanceof Request) {
219
+ // Request object (we extract the URL)
199
220
  url = input.url;
200
221
  }
222
+ else if (input instanceof URL) {
223
+ // URL object
224
+ url = input.href;
225
+ }
201
226
  else {
227
+ // Unsupported input type, skip interception
228
+ console.warn("Unsupported input type for fetch:", input);
202
229
  return originalFetch.apply(this, arguments);
203
230
  }
204
231
  // Bypass logic for domains listed in the combinedIgnoreDomains
@@ -208,8 +235,10 @@ function setupFetchInterceptor(domainsToNotPropagateHeaderTo, domainsToPropagate
208
235
  // Check if the domain should propagate headers
209
236
  const shouldPropagateHeader = domainsToPropagateHeadersTo.length === 0 ||
210
237
  matchUrlWithWildcard(url, domainsToPropagateHeadersTo);
238
+ // Proceed with fetch if header should propagate and not be excluded
211
239
  if (sessionId && shouldPropagateHeader) {
212
240
  if (input instanceof Request) {
241
+ // If input is a Request, clone it and modify the headers
213
242
  const clonedRequest = input.clone();
214
243
  const newHeaders = new Headers(clonedRequest.headers);
215
244
  newHeaders.set("X-Sf3-Rid", sessionId);
@@ -219,6 +248,7 @@ function setupFetchInterceptor(domainsToNotPropagateHeaderTo, domainsToPropagate
219
248
  return originalFetch.call(this, modifiedRequest);
220
249
  }
221
250
  else {
251
+ // For string or URL input, modify init to add headers
222
252
  const modifiedInit = { ...init };
223
253
  const newHeaders = new Headers(init?.headers || {});
224
254
  newHeaders.set("X-Sf3-Rid", sessionId);
@@ -227,6 +257,7 @@ function setupFetchInterceptor(domainsToNotPropagateHeaderTo, domainsToPropagate
227
257
  }
228
258
  }
229
259
  else {
260
+ // No header propagation required, proceed with original fetch
230
261
  return originalFetch.apply(this, arguments);
231
262
  }
232
263
  };