Skip to content

Commit

Permalink
fix: Cannot set property attributeName of #<MutationRecord> which has…
Browse files Browse the repository at this point in the history
… only a getter (#1173)

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

* fix: attributeName readonly
  • Loading branch information
wfk007 authored Mar 15, 2023
1 parent 4cb4d0e commit 5982c89
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 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 @@ -1200,7 +1200,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)
) {
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

0 comments on commit 5982c89

Please sign in to comment.