Skip to content

Commit

Permalink
Add option to block animation on <title> tag which can generate massi…
Browse files Browse the repository at this point in the history
…ve recordings on some websites (think scrolling title tag)
  • Loading branch information
eoghanmurray committed Nov 26, 2021
1 parent 1f26708 commit ff98727
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/rrweb/src/record/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ function record<T = eventWithTime>(
// as they destroy some (hidden) info:
headMetaAuthorship: _slimDOMOptions === 'all',
headMetaDescKeywords: _slimDOMOptions === 'all',
headTitleMutations: _slimDOMOptions === 'all', // block title tag 'animation' which can generate a lot of mutations that aren't usually displayed in replayers
}
: _slimDOMOptions
? _slimDOMOptions
Expand Down
6 changes: 3 additions & 3 deletions packages/rrweb/src/record/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ export default class MutationBuffer {
};

private processMutation = (m: mutationRecord) => {
if (isIgnored(m.target)) {
if (isIgnored(m.target, this.slimDOMOptions)) {
return;
}
switch (m.type) {
Expand Down Expand Up @@ -529,7 +529,7 @@ export default class MutationBuffer {
const parentId = isShadowRoot(m.target)
? this.mirror.getId((m.target.host as unknown) as INode)
: this.mirror.getId(m.target as INode);
if (isBlocked(m.target, this.blockClass) || isIgnored(n)) {
if (isBlocked(m.target, this.blockClass) || isIgnored(n, this.slimDOMOptions)) {
return;
}
// removed node has not been serialized yet, just remove it from the Set
Expand Down Expand Up @@ -578,7 +578,7 @@ export default class MutationBuffer {
return;
}
if (isINode(n)) {
if (isIgnored(n)) {
if (isIgnored(n, this.slimDOMOptions)) {
return;
}
this.movedSet.add(n);
Expand Down
8 changes: 7 additions & 1 deletion packages/rrweb/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,13 @@ export function isBlocked(node: Node | null, blockClass: blockClass): boolean {
return isBlocked(node.parentNode, blockClass);
}

export function isIgnored(n: Node | INode): boolean {
export function isIgnored(n: Node | INode, slimDOMOptions: SlimDOMOptions): boolean {
if ((n as Node).tagName === 'TITLE' && slimDOMOptions.headTitleMutations) {
// we do this check here but not in rrweb-snapshot
// to block mutations/animations on the title.
// the headTitleMutations options isn't intended to block recording of the initial value
return true;
}
if ('__sn' in n) {
return (n as INode).__sn.id === IGNORED_NODE;
}
Expand Down

0 comments on commit ff98727

Please sign in to comment.