@@ -435,6 +435,7 @@ export class ReplayContainer implements ReplayContainerInterface {
435
435
try {
436
436
WINDOW . document . addEventListener ( 'visibilitychange' , this . _handleVisibilityChange ) ;
437
437
WINDOW . addEventListener ( 'blur' , this . _handleWindowBlur ) ;
438
+ WINDOW . addEventListener ( 'beforeunload' , this . _handleWindowUnload ) ;
438
439
WINDOW . addEventListener ( 'focus' , this . _handleWindowFocus ) ;
439
440
440
441
// We need to filter out dropped events captured by `addGlobalEventProcessor(this.handleGlobalEvent)` below
@@ -467,6 +468,7 @@ export class ReplayContainer implements ReplayContainerInterface {
467
468
468
469
WINDOW . removeEventListener ( 'blur' , this . _handleWindowBlur ) ;
469
470
WINDOW . removeEventListener ( 'focus' , this . _handleWindowFocus ) ;
471
+ WINDOW . removeEventListener ( 'beforeunload' , this . _handleWindowUnload ) ;
470
472
471
473
restoreRecordDroppedEvent ( ) ;
472
474
@@ -571,6 +573,19 @@ export class ReplayContainer implements ReplayContainerInterface {
571
573
this . _doChangeToBackgroundTasks ( breadcrumb ) ;
572
574
} ;
573
575
576
+ /**
577
+ * Handle when page is unloaded (=left).
578
+ */
579
+ private _handleWindowUnload : ( ) => void = ( ) => {
580
+ const breadcrumb = createBreadcrumb ( {
581
+ category : 'ui.unload' ,
582
+ } ) ;
583
+
584
+ // Do not count blur as a user action -- it's part of the process of them
585
+ // leaving the page
586
+ this . _doChangeToBackgroundTasks ( breadcrumb ) ;
587
+ } ;
588
+
574
589
/**
575
590
* Handle when page is focused
576
591
*/
0 commit comments