From a22d338bf6bc605376923cb2c17fa35cc1db749c Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Thu, 4 May 2023 10:43:40 +0200 Subject: [PATCH] fix(replay: Keep page active on key press --- packages/replay/src/replay.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/replay/src/replay.ts b/packages/replay/src/replay.ts index 3cbb7f0002da..3d2fe4a6d7af 100644 --- a/packages/replay/src/replay.ts +++ b/packages/replay/src/replay.ts @@ -620,6 +620,7 @@ export class ReplayContainer implements ReplayContainerInterface { WINDOW.document.addEventListener('visibilitychange', this._handleVisibilityChange); WINDOW.addEventListener('blur', this._handleWindowBlur); WINDOW.addEventListener('focus', this._handleWindowFocus); + WINDOW.addEventListener('keydown', this._handleKeyboardEvent); // There is no way to remove these listeners, so ensure they are only added once if (!this._hasInitializedCoreListeners) { @@ -648,6 +649,7 @@ export class ReplayContainer implements ReplayContainerInterface { WINDOW.removeEventListener('blur', this._handleWindowBlur); WINDOW.removeEventListener('focus', this._handleWindowFocus); + WINDOW.removeEventListener('keydown', this._handleKeyboardEvent); if (this._performanceObserver) { this._performanceObserver.disconnect(); @@ -698,6 +700,11 @@ export class ReplayContainer implements ReplayContainerInterface { this._doChangeToForegroundTasks(breadcrumb); }; + /** Ensure page remains active when a key is pressed. */ + private _handleKeyboardEvent: (event: KeyboardEvent) => void = () => { + this.triggerUserActivity(); + }; + /** * Tasks to run when we consider a page to be hidden (via blurring and/or visibility) */