Skip to content

Commit

Permalink
feat: add observer for 'selected' setter of HTMLOptionElement and try…
Browse files Browse the repository at this point in the history
… to fix issue #746
  • Loading branch information
YunFeng0817 committed Jan 25, 2022
1 parent 0c27ad2 commit 1312dbd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/rrweb-snapshot/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ function serializeNode(
}
}
if (tagName === 'option') {
if ((n as HTMLOptionElement).selected) {
if ((n as HTMLOptionElement).selected && !maskInputOptions['select']) {
attributes.selected = true;
} else {
// ignore the html attribute (which corresponds to DOM (n as HTMLOptionElement).defaultSelected)
Expand Down
5 changes: 4 additions & 1 deletion packages/rrweb/src/record/observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,10 @@ function initInputObserver(
userTriggeredOnInput: boolean,
): listenerHandler {
function eventHandler(event: Event) {
const target = getEventTarget(event);
let target = getEventTarget(event);
const userTriggered = event.isTrusted;
if (target && (target as Element).tagName === 'OPTION')
target = (target as Element).parentElement;
if (
!target ||
!(target as Element).tagName ||
Expand Down Expand Up @@ -463,6 +465,7 @@ function initInputObserver(
[HTMLTextAreaElement.prototype, 'value'],
// Some UI library use selectedIndex to set select value
[HTMLSelectElement.prototype, 'selectedIndex'],
[HTMLOptionElement.prototype, 'selected'],
];
if (propertyDescriptor && propertyDescriptor.set) {
handlers.push(
Expand Down
3 changes: 1 addition & 2 deletions packages/rrweb/test/__snapshots__/integration.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6066,8 +6066,7 @@ exports[`record integration tests should not record input values if maskAllInput
\\"type\\": 2,
\\"tagName\\": \\"option\\",
\\"attributes\\": {
\\"value\\": \\"1\\",
\\"selected\\": true
\\"value\\": \\"1\\"
},
\\"childNodes\\": [
{
Expand Down

0 comments on commit 1312dbd

Please sign in to comment.