Skip to content

Commit 5982c89

Browse files
authored
fix: Cannot set property attributeName of #<MutationRecord> which has only a getter (#1173)
* fix: Cannot set property attributeName of #<MutationRecord> which has only a getter * fix: attributeName readonly
1 parent 4cb4d0e commit 5982c89

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

packages/rrweb-snapshot/src/snapshot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ function snapshot(
12001200
maskAllInputs?: boolean | MaskInputOptions;
12011201
maskTextFn?: MaskTextFn;
12021202
maskInputFn?: MaskTextFn;
1203-
slimDOM?: boolean | SlimDOMOptions;
1203+
slimDOM?: 'all' | boolean | SlimDOMOptions;
12041204
dataURLOptions?: DataURLOptions;
12051205
inlineImages?: boolean;
12061206
recordCanvas?: boolean;

packages/rrweb/src/record/mutation.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,9 @@ export default class MutationBuffer {
486486
}
487487
case 'attributes': {
488488
const target = m.target as HTMLElement;
489-
let value = (m.target as HTMLElement).getAttribute(m.attributeName!);
490-
if (m.attributeName === 'value') {
489+
let attributeName = m.attributeName as string;
490+
let value = (m.target as HTMLElement).getAttribute(attributeName);
491+
if (attributeName === 'value') {
491492
value = maskInputValue({
492493
maskInputOptions: this.maskInputOptions,
493494
tagName: (m.target as HTMLElement).tagName,
@@ -508,13 +509,13 @@ export default class MutationBuffer {
508509
);
509510
if (
510511
target.tagName === 'IFRAME' &&
511-
m.attributeName === 'src' &&
512+
attributeName === 'src' &&
512513
!this.keepIframeSrcFn(value as string)
513514
) {
514515
if (!(target as HTMLIFrameElement).contentDocument) {
515516
// we can't record it directly as we can't see into it
516517
// preserve the src attribute so a decision can be taken at replay time
517-
m.attributeName = 'rr_src';
518+
attributeName = 'rr_src';
518519
} else {
519520
return;
520521
}
@@ -526,7 +527,7 @@ export default class MutationBuffer {
526527
};
527528
this.attributes.push(item);
528529
}
529-
if (m.attributeName === 'style') {
530+
if (attributeName === 'style') {
530531
const old = this.doc.createElement('span');
531532
if (m.oldValue) {
532533
old.setAttribute('style', m.oldValue);
@@ -558,12 +559,12 @@ export default class MutationBuffer {
558559
styleObj[pname] = false; // delete
559560
}
560561
}
561-
} else if (!ignoreAttribute(target.tagName, m.attributeName!, value)) {
562+
} else if (!ignoreAttribute(target.tagName, attributeName, value)) {
562563
// overwrite attribute if the mutations was triggered in same time
563-
item.attributes[m.attributeName!] = transformAttribute(
564+
item.attributes[attributeName] = transformAttribute(
564565
this.doc,
565566
target.tagName,
566-
m.attributeName!,
567+
attributeName,
567568
value,
568569
);
569570
}

packages/types/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,14 +265,14 @@ export type hooksParam = {
265265
};
266266

267267
// https://dom.spec.whatwg.org/#interface-mutationrecord
268-
export type mutationRecord = {
268+
export type mutationRecord = Readonly<{
269269
type: string;
270270
target: Node;
271271
oldValue: string | null;
272272
addedNodes: NodeList;
273273
removedNodes: NodeList;
274274
attributeName: string | null;
275-
};
275+
}>;
276276

277277
export type textCursor = {
278278
node: Node;

0 commit comments

Comments
 (0)