Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Cannot set property attributeName of #<MutationRecord> which has only a getter #1173

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/rrweb-snapshot/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ function snapshot(
maskAllInputs?: boolean | MaskInputOptions;
maskTextFn?: MaskTextFn;
maskInputFn?: MaskTextFn;
slimDOM?: boolean | SlimDOMOptions;
slimDOM?: 'all' | boolean | SlimDOMOptions;
dataURLOptions?: DataURLOptions;
inlineImages?: boolean;
recordCanvas?: boolean;
Expand Down
17 changes: 9 additions & 8 deletions packages/rrweb/src/record/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,9 @@ export default class MutationBuffer {
}
case 'attributes': {
const target = m.target as HTMLElement;
let value = (m.target as HTMLElement).getAttribute(m.attributeName!);
if (m.attributeName === 'value') {
let attributeName = m.attributeName as string;
let value = (m.target as HTMLElement).getAttribute(attributeName);
if (attributeName === 'value') {
value = maskInputValue({
maskInputOptions: this.maskInputOptions,
tagName: (m.target as HTMLElement).tagName,
Expand All @@ -508,13 +509,13 @@ export default class MutationBuffer {
);
if (
target.tagName === 'IFRAME' &&
m.attributeName === 'src' &&
attributeName === 'src' &&
!this.keepIframeSrcFn(value as string)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other changes all look good. But what's the motivation for this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other changes all look good. But what's the motivation for this change?

If the attributeName is read-only, this line seems useless, so in order to keep code and logic clean, I delete this line.
But if it is necessary to keep it, I can restore this change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is important because some people may rely on this configuration. Do you know how to keep its original logic and keep mutation unchanged?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is important because some people may rely on this configuration. Do you know how to keep its original logic and keep mutation unchanged?

@YunFeng0817 updated

) {
if (!(target as HTMLIFrameElement).contentDocument) {
// we can't record it directly as we can't see into it
// preserve the src attribute so a decision can be taken at replay time
m.attributeName = 'rr_src';
attributeName = 'rr_src';
} else {
return;
}
Expand All @@ -526,7 +527,7 @@ export default class MutationBuffer {
};
this.attributes.push(item);
}
if (m.attributeName === 'style') {
if (attributeName === 'style') {
const old = this.doc.createElement('span');
if (m.oldValue) {
old.setAttribute('style', m.oldValue);
Expand Down Expand Up @@ -558,12 +559,12 @@ export default class MutationBuffer {
styleObj[pname] = false; // delete
}
}
} else if (!ignoreAttribute(target.tagName, m.attributeName!, value)) {
} else if (!ignoreAttribute(target.tagName, attributeName, value)) {
// overwrite attribute if the mutations was triggered in same time
item.attributes[m.attributeName!] = transformAttribute(
item.attributes[attributeName] = transformAttribute(
this.doc,
target.tagName,
m.attributeName!,
attributeName,
value,
);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,14 @@ export type hooksParam = {
};

// https://dom.spec.whatwg.org/#interface-mutationrecord
export type mutationRecord = {
export type mutationRecord = Readonly<{
type: string;
target: Node;
oldValue: string | null;
addedNodes: NodeList;
removedNodes: NodeList;
attributeName: string | null;
};
}>;

export type textCursor = {
node: Node;
Expand Down