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
This commit is contained in:
fukang wang
2026-04-01 12:00:00 +08:00
committed by GitHub
parent 1c5acb69be
commit 18d7456ed7
3 changed files with 12 additions and 11 deletions

View File

@@ -1200,7 +1200,7 @@ function snapshot(
maskAllInputs?: boolean | MaskInputOptions; maskAllInputs?: boolean | MaskInputOptions;
maskTextFn?: MaskTextFn; maskTextFn?: MaskTextFn;
maskInputFn?: MaskTextFn; maskInputFn?: MaskTextFn;
slimDOM?: boolean | SlimDOMOptions; slimDOM?: 'all' | boolean | SlimDOMOptions;
dataURLOptions?: DataURLOptions; dataURLOptions?: DataURLOptions;
inlineImages?: boolean; inlineImages?: boolean;
recordCanvas?: boolean; recordCanvas?: boolean;

View File

@@ -486,8 +486,9 @@ export default class MutationBuffer {
} }
case 'attributes': { case 'attributes': {
const target = m.target as HTMLElement; const target = m.target as HTMLElement;
let value = (m.target as HTMLElement).getAttribute(m.attributeName!); let attributeName = m.attributeName as string;
if (m.attributeName === 'value') { let value = (m.target as HTMLElement).getAttribute(attributeName);
if (attributeName === 'value') {
value = maskInputValue({ value = maskInputValue({
maskInputOptions: this.maskInputOptions, maskInputOptions: this.maskInputOptions,
tagName: (m.target as HTMLElement).tagName, tagName: (m.target as HTMLElement).tagName,
@@ -508,13 +509,13 @@ export default class MutationBuffer {
); );
if ( if (
target.tagName === 'IFRAME' && target.tagName === 'IFRAME' &&
m.attributeName === 'src' && attributeName === 'src' &&
!this.keepIframeSrcFn(value as string) !this.keepIframeSrcFn(value as string)
) { ) {
if (!(target as HTMLIFrameElement).contentDocument) { if (!(target as HTMLIFrameElement).contentDocument) {
// we can't record it directly as we can't see into it // 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 // preserve the src attribute so a decision can be taken at replay time
m.attributeName = 'rr_src'; attributeName = 'rr_src';
} else { } else {
return; return;
} }
@@ -526,7 +527,7 @@ export default class MutationBuffer {
}; };
this.attributes.push(item); this.attributes.push(item);
} }
if (m.attributeName === 'style') { if (attributeName === 'style') {
const old = this.doc.createElement('span'); const old = this.doc.createElement('span');
if (m.oldValue) { if (m.oldValue) {
old.setAttribute('style', m.oldValue); old.setAttribute('style', m.oldValue);
@@ -558,12 +559,12 @@ export default class MutationBuffer {
styleObj[pname] = false; // delete 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 // overwrite attribute if the mutations was triggered in same time
item.attributes[m.attributeName!] = transformAttribute( item.attributes[attributeName] = transformAttribute(
this.doc, this.doc,
target.tagName, target.tagName,
m.attributeName!, attributeName,
value, value,
); );
} }

View File

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