@devskin/browser-sdk 1.0.34 → 1.0.35

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.
@@ -14178,6 +14178,7 @@ class DevSkinSDK {
14178
14178
  }
14179
14179
  setupUnloadTracking() {
14180
14180
  // CRITICAL: Flush data BEFORE page unloads to avoid losing final events
14181
+ // IMPORTANT: NEVER clear sessionStorage - it expires naturally when tab closes
14181
14182
  // 1. visibilitychange - fires when tab is hidden (most reliable)
14182
14183
  document.addEventListener('visibilitychange', () => {
14183
14184
  var _a, _b;
@@ -14189,30 +14190,23 @@ class DevSkinSDK {
14189
14190
  }
14190
14191
  });
14191
14192
  // 2. pagehide - fires when page is being unloaded
14192
- window.addEventListener('pagehide', (event) => {
14193
+ window.addEventListener('pagehide', () => {
14193
14194
  var _a, _b;
14194
- const isActualClose = !event.persisted;
14195
- if (isActualClose) {
14196
- // Tab is closing - end session
14197
- this.track('page_unload');
14198
- this.updateSessionDuration(true); // true = session ending
14199
- // Clear session storage since session is ending
14200
- sessionStorage.removeItem('devskin_session_id');
14201
- sessionStorage.removeItem('devskin_session_start');
14202
- }
14203
- else {
14204
- // Navigation - track page change
14205
- this.track('page_navigation');
14206
- this.updateSessionDuration();
14207
- }
14208
- // ALWAYS flush (whether navigation or close)
14195
+ // Track navigation (we can't distinguish between page navigation and tab close reliably)
14196
+ this.track('page_navigation');
14197
+ // Update duration but DON'T mark as ending (let heartbeat timeout handle session expiry)
14198
+ this.updateSessionDuration(false);
14199
+ // NEVER clear sessionStorage - it persists across navigations in same tab
14200
+ // and expires automatically when tab actually closes
14201
+ // Flush data before page unloads
14209
14202
  (_a = this.rrwebRecorder) === null || _a === void 0 ? void 0 : _a.stop(); // Stop recording and flush remaining events
14210
14203
  (_b = this.transport) === null || _b === void 0 ? void 0 : _b.flush(true); // Use beacon for reliability
14211
14204
  });
14212
14205
  // 3. beforeunload - backup for older browsers
14213
14206
  window.addEventListener('beforeunload', () => {
14214
14207
  var _a, _b;
14215
- this.updateSessionDuration(true);
14208
+ // Update duration but DON'T mark as ending
14209
+ this.updateSessionDuration(false);
14216
14210
  (_a = this.rrwebRecorder) === null || _a === void 0 ? void 0 : _a.stop();
14217
14211
  (_b = this.transport) === null || _b === void 0 ? void 0 : _b.flush(true);
14218
14212
  });