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