From 425a04092d8cb036d83bd9e230be7ab8aebe6354 Mon Sep 17 00:00:00 2001 From: Joris Machielse Date: Fri, 2 Oct 2020 09:39:22 +0200 Subject: [PATCH] @Juice10: Add a flag for rrweb generated events Port of @Juice10/record-once-rrweb/commit/0aef9569a7c5eabe167a9abc8aecf8fd5987bf0a --- src/record/observer.ts | 7 +++++-- src/types.ts | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/record/observer.ts b/src/record/observer.ts index 1e0e1afe1f..357aaf4b0c 100644 --- a/src/record/observer.ts +++ b/src/record/observer.ts @@ -223,6 +223,8 @@ function initInputObserver( ): listenerHandler { function eventHandler(event: KeyboardEvent) { // was Event const { target } = event; + const rrwebGenerated = !event.isTrusted; + if ( !target || !(target as Element).tagName || @@ -233,7 +235,7 @@ function initInputObserver( } if (event.type === 'keyup' && event.key === 'Enter') { - return cbWithDedup(target, { key: 'Enter' }); + return cbWithDedup(target, { key: 'Enter', rrwebGenerated }); } const type: string | undefined = (target as HTMLInputElement).type; @@ -255,7 +257,7 @@ function initInputObserver( ) { text = '*'.repeat(text.length); } - cbWithDedup(target, { text, isChecked }); + cbWithDedup(target, { text, isChecked, rrwebGenerated }); // if a radio was checked // the other radios with the same name attribute will be unchecked. const name: string | undefined = (target as HTMLInputElement).name; @@ -267,6 +269,7 @@ function initInputObserver( cbWithDedup(el, { text: (el as HTMLInputElement).value, isChecked: !isChecked, + rrwebGenerated: true, }); } }); diff --git a/src/types.ts b/src/types.ts index 1298c4bd94..2501776b33 100644 --- a/src/types.ts +++ b/src/types.ts @@ -359,6 +359,7 @@ export type inputValue = { text?: string; isChecked?: boolean; key?: string; + rrwebGenerated: boolean; }; export type inputCallback = (v: inputValue & { id: number }) => void;