@sailfish-ai/recorder 1.2.3 → 1.2.4
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 +53 -51
- package/dist/sailfish-recorder.cjs.js +1 -1
- package/dist/sailfish-recorder.cjs.js.br +0 -0
- package/dist/sailfish-recorder.cjs.js.gz +0 -0
- package/dist/sailfish-recorder.es.js +1 -1
- package/dist/sailfish-recorder.es.js.br +0 -0
- package/dist/sailfish-recorder.es.js.gz +0 -0
- package/dist/sailfish-recorder.umd.js +1 -1
- package/dist/sailfish-recorder.umd.js.br +0 -0
- package/dist/sailfish-recorder.umd.js.gz +0 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -208,60 +208,62 @@ function setupFetchInterceptor(domainsToNotPropagateHeaderTo, domainsToPropagate
|
|
|
208
208
|
...DOMAINS_TO_NOT_PROPAGATE_HEADER_TO_DEFAULT,
|
|
209
209
|
...domainsToNotPropagateHeaderTo,
|
|
210
210
|
];
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
url
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
else {
|
|
227
|
-
// Unsupported input type, skip interception
|
|
228
|
-
return originalFetch.apply(this, arguments);
|
|
229
|
-
}
|
|
230
|
-
// Bypass logic for domains listed in the combinedIgnoreDomains
|
|
231
|
-
if (matchUrlWithWildcard(url, combinedIgnoreDomains)) {
|
|
232
|
-
return originalFetch.apply(this, arguments);
|
|
233
|
-
}
|
|
234
|
-
// Check if the domain should propagate headers
|
|
235
|
-
const shouldPropagateHeader = domainsToPropagateHeadersTo.length === 0 ||
|
|
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
|
-
}
|
|
242
|
-
if (sessionId && shouldPropagateHeader) {
|
|
243
|
-
if (input instanceof Request) {
|
|
244
|
-
const clonedRequest = input.clone();
|
|
245
|
-
const newHeaders = new Headers(clonedRequest.headers);
|
|
246
|
-
newHeaders.set("X-Sf3-Rid", sessionId);
|
|
247
|
-
const modifiedRequest = new Request(clonedRequest, {
|
|
248
|
-
headers: newHeaders,
|
|
249
|
-
});
|
|
250
|
-
return originalFetch.call(this, modifiedRequest);
|
|
211
|
+
// Proxy to conditionally intercept fetch based on domains
|
|
212
|
+
window.fetch = new Proxy(originalFetch, {
|
|
213
|
+
apply: (target, thisArg, args) => {
|
|
214
|
+
let input = args[0];
|
|
215
|
+
let init = args[1] || {};
|
|
216
|
+
let url;
|
|
217
|
+
// Handle different types of `input` for fetch
|
|
218
|
+
if (typeof input === "string") {
|
|
219
|
+
url = input;
|
|
220
|
+
}
|
|
221
|
+
else if (input instanceof Request) {
|
|
222
|
+
url = input.url;
|
|
223
|
+
}
|
|
224
|
+
else if (input instanceof URL) {
|
|
225
|
+
url = input.href;
|
|
251
226
|
}
|
|
252
227
|
else {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
modifiedInit.headers = newHeaders;
|
|
257
|
-
return originalFetch.call(this, input, modifiedInit);
|
|
228
|
+
// Unsupported type, skip interception
|
|
229
|
+
console.warn("Unsupported input type for fetch:", input);
|
|
230
|
+
return target.apply(thisArg, args);
|
|
258
231
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
232
|
+
// ** Check if we should skip patching fetch entirely for this domain **
|
|
233
|
+
if (matchUrlWithWildcard(url, combinedIgnoreDomains)) {
|
|
234
|
+
return target.apply(thisArg, args);
|
|
235
|
+
}
|
|
236
|
+
// Check if the domain should propagate the header
|
|
237
|
+
const shouldPropagateHeader = domainsToPropagateHeadersTo.length === 0 ||
|
|
238
|
+
matchUrlWithWildcard(url, domainsToPropagateHeadersTo);
|
|
239
|
+
// ** Skip CORS-sensitive requests **
|
|
240
|
+
// Ensure we don't modify headers for cross-origin requests to non-whitelisted domains
|
|
241
|
+
if (!shouldPropagateHeader) {
|
|
242
|
+
return target.apply(thisArg, args);
|
|
243
|
+
}
|
|
244
|
+
// ** Add X-Sf3-Rid header if needed **
|
|
245
|
+
if (sessionId && shouldPropagateHeader) {
|
|
246
|
+
if (input instanceof Request) {
|
|
247
|
+
const clonedRequest = input.clone();
|
|
248
|
+
const newHeaders = new Headers(clonedRequest.headers);
|
|
249
|
+
newHeaders.set("X-Sf3-Rid", sessionId);
|
|
250
|
+
const modifiedRequest = new Request(clonedRequest, {
|
|
251
|
+
headers: newHeaders,
|
|
252
|
+
});
|
|
253
|
+
return target.call(thisArg, modifiedRequest, init);
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
const modifiedInit = { ...init };
|
|
257
|
+
const newHeaders = new Headers(init.headers || {});
|
|
258
|
+
newHeaders.set("X-Sf3-Rid", sessionId);
|
|
259
|
+
modifiedInit.headers = newHeaders;
|
|
260
|
+
return target.call(thisArg, input, modifiedInit);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
// If no header propagation, return the original fetch call
|
|
264
|
+
return target.apply(thisArg, args);
|
|
265
|
+
},
|
|
266
|
+
});
|
|
265
267
|
}
|
|
266
268
|
// Main Recording Function
|
|
267
269
|
export async function startRecording({ apiKey, backendApi, domainsToPropagateHeaderTo = [], domainsToNotPropagateHeaderTo = [], }) {
|