Skip to content

Commit 7ab581b

Browse files
authored
feat(replay): Consider user input in form field as "user activity" (#7355)
This adds user input (event from core SDK) as a trigger for user activity (to reset idle timeout). Note that this is only from input changes in a form field, it will not consider using tab key to move focus.
1 parent 0e09695 commit 7ab581b

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

packages/replay/src/coreHandlers/addBreadcrumbEvent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function addBreadcrumbEvent(replay: ReplayContainer, breadcrumb: Breadcru
1212
return;
1313
}
1414

15-
if (breadcrumb.category === 'ui.click') {
15+
if (['ui.click', 'ui.input'].includes(breadcrumb.category as string)) {
1616
replay.triggerUserActivity();
1717
} else {
1818
replay.checkAndHandleExpiredSession();

packages/replay/test/integration/sendReplayEvent.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,26 @@ describe('Integration | sendReplayEvent', () => {
129129
expect(replay.session?.lastActivity).toBe(BASE_TIMESTAMP + ELAPSED);
130130
});
131131

132+
it('update last activity when user uses keyboard input', async () => {
133+
expect(replay.session?.lastActivity).toBe(BASE_TIMESTAMP);
134+
135+
domHandler({
136+
name: 'input',
137+
});
138+
139+
expect(replay.session?.lastActivity).toBe(BASE_TIMESTAMP);
140+
141+
// Pretend 5 seconds have passed
142+
const ELAPSED = 5000;
143+
jest.advanceTimersByTime(ELAPSED);
144+
145+
domHandler({
146+
name: 'input',
147+
});
148+
149+
expect(replay.session?.lastActivity).toBe(BASE_TIMESTAMP + ELAPSED);
150+
});
151+
132152
it('uploads a replay event if 5 seconds have elapsed since the last replay event occurred', async () => {
133153
const TEST_EVENT = { data: {}, timestamp: BASE_TIMESTAMP, type: 3 };
134154
mockRecord._emitter(TEST_EVENT);

0 commit comments

Comments
 (0)