@@ -20,6 +20,7 @@ import {
2020 maskInputValue ,
2121 isNativeShadowDom ,
2222 getCssRulesString ,
23+ getInputValue ,
2324} from './utils' ;
2425
2526let _id = 1 ;
@@ -31,12 +32,14 @@ export function genId(): number {
3132 return _id ++ ;
3233}
3334
34- function getValidTagName ( element : HTMLElement ) : string {
35+ function getValidTagName ( element : HTMLElement ) : Lowercase < string > {
3536 if ( element instanceof HTMLFormElement ) {
3637 return 'form' ;
3738 }
3839
39- const processedTagName = element . tagName . toLowerCase ( ) . trim ( ) ;
40+ const processedTagName = element . tagName
41+ . toLowerCase ( )
42+ . trim ( ) as unknown as Lowercase < string > ;
4043
4144 if ( tagNameRegex . test ( processedTagName ) ) {
4245 // if the tag name is odd and we cannot extract
@@ -501,6 +504,8 @@ function serializeNode(
501504 maskTextClass,
502505 maskTextSelector,
503506 maskTextFn,
507+ maskInputOptions,
508+ maskInputFn,
504509 rootId,
505510 } ) ;
506511 case n . CDATA_SECTION_NODE :
@@ -532,10 +537,19 @@ function serializeTextNode(
532537 maskTextClass : string | RegExp ;
533538 maskTextSelector : string | null ;
534539 maskTextFn : MaskTextFn | undefined ;
540+ maskInputOptions : MaskInputOptions ;
541+ maskInputFn : MaskInputFn | undefined ;
535542 rootId : number | undefined ;
536543 } ,
537544) : serializedNode {
538- const { maskTextClass, maskTextSelector, maskTextFn, rootId } = options ;
545+ const {
546+ maskTextClass,
547+ maskTextSelector,
548+ maskTextFn,
549+ maskInputFn,
550+ maskInputOptions,
551+ rootId,
552+ } = options ;
539553 // The parent node may not be a html element which has a tagName attribute.
540554 // So just let it be undefined which is ok in this use case.
541555 const parentTagName = n . parentNode && ( n . parentNode as HTMLElement ) . tagName ;
@@ -577,6 +591,17 @@ function serializeTextNode(
577591 : textContent . replace ( / [ \S ] / g, '*' ) ;
578592 }
579593
594+ // Handle <option> text like an input value
595+ if ( parentTagName === 'OPTION' && textContent ) {
596+ textContent = maskInputValue ( {
597+ type : null ,
598+ tagName : parentTagName ,
599+ value : textContent ,
600+ maskInputOptions,
601+ maskInputFn,
602+ } ) ;
603+ }
604+
580605 return {
581606 type : NodeType . Text ,
582607 textContent : textContent || '' ,
@@ -664,24 +689,30 @@ function serializeElementNode(
664689 }
665690 }
666691 // form fields
667- if ( tagName === 'input' || tagName === 'textarea' || tagName === 'select' ) {
668- const value = ( n as HTMLInputElement | HTMLTextAreaElement ) . value ;
692+ if (
693+ tagName === 'input' ||
694+ tagName === 'textarea' ||
695+ tagName === 'select' ||
696+ tagName === 'option'
697+ ) {
698+ const el = n as
699+ | HTMLInputElement
700+ | HTMLTextAreaElement
701+ | HTMLSelectElement
702+ | HTMLOptionElement ;
703+
704+ const value = getInputValue ( el , tagName . toUpperCase ( ) as Uppercase < typeof tagName > , attributes . type ) ;
669705 const checked = ( n as HTMLInputElement ) . checked ;
670- if (
671- attributes . type !== 'radio' &&
672- attributes . type !== 'checkbox' &&
673- attributes . type !== 'submit' &&
674- attributes . type !== 'button' &&
675- value
676- ) {
706+ if ( attributes . type !== 'submit' && attributes . type !== 'button' && value ) {
677707 attributes . value = maskInputValue ( {
678708 type : attributes . type ,
679- tagName,
709+ tagName : tagName . toUpperCase ( ) as Uppercase < typeof tagName > ,
680710 value,
681711 maskInputOptions,
682712 maskInputFn,
683713 } ) ;
684- } else if ( checked ) {
714+ }
715+ if ( checked ) {
685716 attributes . checked = checked ;
686717 }
687718 }
0 commit comments