@sailfish-ai/recorder 1.4.4 → 1.5.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/README.md CHANGED
@@ -1,3 +1,3 @@
1
1
  # JS/TS Record-Only Package
2
2
 
3
- ## TODO - Rename all Sailfish to GrepLion
3
+ ## TODO - Rename all SailfishQA to SailfishCloud
package/dist/index.js CHANGED
@@ -57,6 +57,37 @@ const PERSIST_SESSION_FOR_REOPENING_TABS = false;
57
57
  // recordBody: true,
58
58
  // recordInitialRequests: false,
59
59
  // };
60
+ function trackDomainChanges() {
61
+ let lastDomain = window.location.href;
62
+ const checkDomainChange = (forceSend = false) => {
63
+ const currentDomain = window.location.href;
64
+ if (forceSend || currentDomain !== lastDomain) {
65
+ console.log(`Domain changed from ${lastDomain} to ${currentDomain}`);
66
+ lastDomain = currentDomain;
67
+ const timestamp = Date.now();
68
+ sendMessage({
69
+ type: "routeChange",
70
+ data: {
71
+ url: currentDomain,
72
+ timestamp,
73
+ },
74
+ });
75
+ }
76
+ };
77
+ const debouncedCheck = debounce(() => checkDomainChange(), 500);
78
+ // Force the first check to send the initial URL on load
79
+ checkDomainChange(true);
80
+ // Set interval to periodically check if the domain or path has changed
81
+ setInterval(debouncedCheck, 1000); // Adjust the interval as needed
82
+ }
83
+ // Debounce utility function
84
+ function debounce(func, wait) {
85
+ let timeout;
86
+ return function (...args) {
87
+ clearTimeout(timeout);
88
+ timeout = setTimeout(() => func(...args), wait);
89
+ };
90
+ }
60
91
  // Functions
61
92
  function sendUserDeviceUuid() {
62
93
  const userDeviceUuid = getOrSetUserDeviceUuid();
@@ -322,6 +353,7 @@ function setupFetchInterceptor(domainsToNotPropagateHeadersTo, domainsToPropagat
322
353
  export async function startRecording({ apiKey, backendApi = "https://api-service.sailfishqa.com", domainsToPropagateHeaderTo = [], domainsToNotPropagateHeaderTo = [], }) {
323
354
  let sessionId = getOrSetSessionId();
324
355
  storeCredentialsAndConnection({ apiKey, backendApi });
356
+ trackDomainChanges();
325
357
  // Non-blocking GraphQL request to send the domains if provided
326
358
  if (domainsToNotPropagateHeaderTo.length > 0) {
327
359
  sendDomainsToNotPropagateHeaderTo(apiKey, domainsToNotPropagateHeaderTo, backendApi).catch((error) => console.error("Failed to send domains to not propagate header to:", error));