Skip to content

Commit 3c00c68

Browse files
authored
fix(replay: Keep session active on key press (#8037)
1 parent 9ea2bca commit 3c00c68

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

packages/replay/src/replay.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,7 @@ export class ReplayContainer implements ReplayContainerInterface {
620620
WINDOW.document.addEventListener('visibilitychange', this._handleVisibilityChange);
621621
WINDOW.addEventListener('blur', this._handleWindowBlur);
622622
WINDOW.addEventListener('focus', this._handleWindowFocus);
623+
WINDOW.addEventListener('keydown', this._handleKeyboardEvent);
623624

624625
// There is no way to remove these listeners, so ensure they are only added once
625626
if (!this._hasInitializedCoreListeners) {
@@ -648,6 +649,7 @@ export class ReplayContainer implements ReplayContainerInterface {
648649

649650
WINDOW.removeEventListener('blur', this._handleWindowBlur);
650651
WINDOW.removeEventListener('focus', this._handleWindowFocus);
652+
WINDOW.removeEventListener('keydown', this._handleKeyboardEvent);
651653

652654
if (this._performanceObserver) {
653655
this._performanceObserver.disconnect();
@@ -698,6 +700,11 @@ export class ReplayContainer implements ReplayContainerInterface {
698700
this._doChangeToForegroundTasks(breadcrumb);
699701
};
700702

703+
/** Ensure page remains active when a key is pressed. */
704+
private _handleKeyboardEvent: (event: KeyboardEvent) => void = () => {
705+
this.triggerUserActivity();
706+
};
707+
701708
/**
702709
* Tasks to run when we consider a page to be hidden (via blurring and/or visibility)
703710
*/

0 commit comments

Comments
 (0)