Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/replay/src/replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ export class ReplayContainer implements ReplayContainerInterface {
try {
WINDOW.document.addEventListener('visibilitychange', this._handleVisibilityChange);
WINDOW.addEventListener('blur', this._handleWindowBlur);
WINDOW.addEventListener('beforeunload', this._handleWindowUnload);
WINDOW.addEventListener('focus', this._handleWindowFocus);

// We need to filter out dropped events captured by `addGlobalEventProcessor(this.handleGlobalEvent)` below
Expand Down Expand Up @@ -467,6 +468,7 @@ export class ReplayContainer implements ReplayContainerInterface {

WINDOW.removeEventListener('blur', this._handleWindowBlur);
WINDOW.removeEventListener('focus', this._handleWindowFocus);
WINDOW.removeEventListener('beforeunload', this._handleWindowUnload);

restoreRecordDroppedEvent();

Expand Down Expand Up @@ -571,6 +573,19 @@ export class ReplayContainer implements ReplayContainerInterface {
this._doChangeToBackgroundTasks(breadcrumb);
};

/**
* Handle when page is unloaded (=left).
*/
private _handleWindowUnload: () => void = () => {
const breadcrumb = createBreadcrumb({
category: 'ui.unload',
});

// Do not count blur as a user action -- it's part of the process of them
// leaving the page
this._doChangeToBackgroundTasks(breadcrumb);
};

/**
* Handle when page is focused
*/
Expand Down