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