@sailfish-ai/recorder 1.2.1 → 1.2.3

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,21 @@ 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
202
228
  return originalFetch.apply(this, arguments);
203
229
  }
204
230
  // Bypass logic for domains listed in the combinedIgnoreDomains
@@ -208,6 +234,11 @@ function setupFetchInterceptor(domainsToNotPropagateHeaderTo, domainsToPropagate
208
234
  // Check if the domain should propagate headers
209
235
  const shouldPropagateHeader = domainsToPropagateHeadersTo.length === 0 ||
210
236
  matchUrlWithWildcard(url, domainsToPropagateHeadersTo);
237
+ // ** Skip CORS-sensitive requests **
238
+ // Ensure we don't modify headers for cross-origin requests to non-whitelisted domains
239
+ if (!shouldPropagateHeader) {
240
+ return originalFetch.apply(this, arguments);
241
+ }
211
242
  if (sessionId && shouldPropagateHeader) {
212
243
  if (input instanceof Request) {
213
244
  const clonedRequest = input.clone();
@@ -227,6 +258,7 @@ function setupFetchInterceptor(domainsToNotPropagateHeaderTo, domainsToPropagate
227
258
  }
228
259
  }
229
260
  else {
261
+ // No header propagation required, proceed with original fetch
230
262
  return originalFetch.apply(this, arguments);
231
263
  }
232
264
  };