@sailfish-ai/recorder 1.2.2 → 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 -50
- 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,59 +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
|
-
console.warn("Unsupported input type for fetch:", input);
|
|
229
|
-
return originalFetch.apply(this, arguments);
|
|
230
|
-
}
|
|
231
|
-
// Bypass logic for domains listed in the combinedIgnoreDomains
|
|
232
|
-
if (matchUrlWithWildcard(url, combinedIgnoreDomains)) {
|
|
233
|
-
return originalFetch.apply(this, arguments);
|
|
234
|
-
}
|
|
235
|
-
// Check if the domain should propagate headers
|
|
236
|
-
const shouldPropagateHeader = domainsToPropagateHeadersTo.length === 0 ||
|
|
237
|
-
matchUrlWithWildcard(url, domainsToPropagateHeadersTo);
|
|
238
|
-
// Proceed with fetch if header should propagate and not be excluded
|
|
239
|
-
if (sessionId && shouldPropagateHeader) {
|
|
240
|
-
if (input instanceof Request) {
|
|
241
|
-
// If input is a Request, clone it and modify the headers
|
|
242
|
-
const clonedRequest = input.clone();
|
|
243
|
-
const newHeaders = new Headers(clonedRequest.headers);
|
|
244
|
-
newHeaders.set("X-Sf3-Rid", sessionId);
|
|
245
|
-
const modifiedRequest = new Request(clonedRequest, {
|
|
246
|
-
headers: newHeaders,
|
|
247
|
-
});
|
|
248
|
-
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;
|
|
249
226
|
}
|
|
250
227
|
else {
|
|
251
|
-
//
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
newHeaders.set("X-Sf3-Rid", sessionId);
|
|
255
|
-
modifiedInit.headers = newHeaders;
|
|
256
|
-
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);
|
|
257
231
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
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
|
+
});
|
|
264
267
|
}
|
|
265
268
|
// Main Recording Function
|
|
266
269
|
export async function startRecording({ apiKey, backendApi, domainsToPropagateHeaderTo = [], domainsToNotPropagateHeaderTo = [], }) {
|