Skip to content

Commit 2bd51a3

Browse files
eoghanmurrayjeffdnguyen
authored andcommitted
Add option to block animation on <title> tag (rrweb-io#760)
* Add option to block animation on <title> tag which can generate massive recordings on some websites (think scrolling title tag) * Add new option to slimDOMOptions type with tsdoc as suggested by Justin
1 parent 599fd8d commit 2bd51a3

File tree

5 files changed

+26
-5
lines changed

5 files changed

+26
-5
lines changed

.changeset/title-deanimate-option.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"rrweb-snapshot": patch
3+
"rrweb": patch
4+
---
5+
6+
Add slimDOM option to block animation on <title> tag; enabled when the 'all' value is used for slimDOM

packages/rrweb-snapshot/src/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ export type SlimDOMOptions = Partial<{
169169
headMetaHttpEquiv: boolean;
170170
headMetaAuthorship: boolean;
171171
headMetaVerification: boolean;
172+
/**
173+
* blocks title tag 'animations' which can generate a lot of mutations that aren't usually displayed in replayers
174+
**/
175+
headTitleMutations: boolean;
172176
}>;
173177

174178
export type DataURLOptions = Partial<{

packages/rrweb/src/record/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ function record<T = eventWithTime>(
175175
// as they destroy some (hidden) info:
176176
headMetaAuthorship: _slimDOMOptions === 'all',
177177
headMetaDescKeywords: _slimDOMOptions === 'all',
178+
headTitleMutations: _slimDOMOptions === 'all',
178179
}
179180
: _slimDOMOptions
180181
? _slimDOMOptions

packages/rrweb/src/record/mutation.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ export default class MutationBuffer {
567567
};
568568

569569
private processMutation = (m: mutationRecord) => {
570-
if (isIgnored(m.target, this.mirror)) {
570+
if (isIgnored(m.target, this.mirror, this.slimDOMOptions)) {
571571
return;
572572
}
573573
switch (m.type) {
@@ -733,7 +733,7 @@ export default class MutationBuffer {
733733
: this.mirror.getId(m.target);
734734
if (
735735
isBlocked(m.target, this.blockClass, this.blockSelector, false) ||
736-
isIgnored(n, this.mirror) ||
736+
isIgnored(n, this.mirror, this.slimDOMOptions) ||
737737
!isSerialized(n, this.mirror)
738738
) {
739739
return;
@@ -793,7 +793,7 @@ export default class MutationBuffer {
793793
if (this.addedSet.has(n) || this.movedSet.has(n)) return;
794794

795795
if (this.mirror.hasNode(n)) {
796-
if (isIgnored(n, this.mirror)) {
796+
if (isIgnored(n, this.mirror, this.slimDOMOptions)) {
797797
return;
798798
}
799799
this.movedSet.add(n);

packages/rrweb/src/utils.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type {
99
DeprecatedMirror,
1010
textMutation,
1111
} from '@rrweb/types';
12-
import type { IMirror, Mirror } from 'rrweb-snapshot';
12+
import type { IMirror, Mirror, SlimDOMOptions } from 'rrweb-snapshot';
1313
import {
1414
isShadowRoot,
1515
IGNORED_NODE,
@@ -298,7 +298,17 @@ export function isSerialized(n: Node, mirror: Mirror): boolean {
298298
return mirror.getId(n) !== -1;
299299
}
300300

301-
export function isIgnored(n: Node, mirror: Mirror): boolean {
301+
export function isIgnored(
302+
n: Node,
303+
mirror: Mirror,
304+
slimDOMOptions: SlimDOMOptions,
305+
): boolean {
306+
if ((n as Element).tagName === 'TITLE' && slimDOMOptions.headTitleMutations) {
307+
// we do this check here but not in rrweb-snapshot
308+
// to block mutations/animations on the title.
309+
// the headTitleMutations option isn't intended to block recording of the initial value
310+
return true;
311+
}
302312
// The main part of the slimDOM check happens in
303313
// rrweb-snapshot::serializeNodeWithId
304314
return mirror.getId(n) === IGNORED_NODE;

0 commit comments

Comments
 (0)