Skip to content

Commit

Permalink
Add option to block animation on <title> tag (#760)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
eoghanmurray authored Jun 13, 2024
1 parent 4beaf2d commit e08706a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changeset/title-deanimate-option.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"rrweb-snapshot": patch
"rrweb": patch
---

Add slimDOM option to block animation on <title> tag; enabled when the 'all' value is used for slimDOM
4 changes: 4 additions & 0 deletions packages/rrweb-snapshot/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ export type SlimDOMOptions = Partial<{
headMetaHttpEquiv: boolean;
headMetaAuthorship: boolean;
headMetaVerification: boolean;
/**
* blocks title tag 'animations' which can generate a lot of mutations that aren't usually displayed in replayers
**/
headTitleMutations: boolean;
}>;

export type DataURLOptions = Partial<{
Expand Down
1 change: 1 addition & 0 deletions packages/rrweb/src/record/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ function record<T = eventWithTime>(
// as they destroy some (hidden) info:
headMetaAuthorship: _slimDOMOptions === 'all',
headMetaDescKeywords: _slimDOMOptions === 'all',
headTitleMutations: _slimDOMOptions === 'all',
}
: _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 @@ -530,7 +530,7 @@ export default class MutationBuffer {
};

private processMutation = (m: mutationRecord) => {
if (isIgnored(m.target, this.mirror)) {
if (isIgnored(m.target, this.mirror, this.slimDOMOptions)) {
return;
}
switch (m.type) {
Expand Down Expand Up @@ -688,7 +688,7 @@ export default class MutationBuffer {
: this.mirror.getId(m.target);
if (
isBlocked(m.target, this.blockClass, this.blockSelector, false) ||
isIgnored(n, this.mirror) ||
isIgnored(n, this.mirror, this.slimDOMOptions) ||
!isSerialized(n, this.mirror)
) {
return;
Expand Down Expand Up @@ -747,7 +747,7 @@ export default class MutationBuffer {
if (this.addedSet.has(n) || this.movedSet.has(n)) return;

if (this.mirror.hasNode(n)) {
if (isIgnored(n, this.mirror)) {
if (isIgnored(n, this.mirror, this.slimDOMOptions)) {
return;
}
this.movedSet.add(n);
Expand Down
14 changes: 12 additions & 2 deletions packages/rrweb/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {
DeprecatedMirror,
textMutation,
} from '@rrweb/types';
import type { IMirror, Mirror } from 'rrweb-snapshot';
import type { IMirror, Mirror, SlimDOMOptions } from 'rrweb-snapshot';
import { isShadowRoot, IGNORED_NODE, classMatchesRegex } from 'rrweb-snapshot';
import type { RRNode, RRIFrameElement } from 'rrdom';

Expand Down Expand Up @@ -276,7 +276,17 @@ export function isSerialized(n: Node, mirror: Mirror): boolean {
return mirror.getId(n) !== -1;
}

export function isIgnored(n: Node, mirror: Mirror): boolean {
export function isIgnored(
n: Node,
mirror: Mirror,
slimDOMOptions: SlimDOMOptions,
): boolean {
if ((n as Element).tagName === 'TITLE' && slimDOMOptions.headTitleMutations) {
// we do this check here but not in rrweb-snapshot
// to block mutations/animations on the title.
// the headTitleMutations option isn't intended to block recording of the initial value
return true;
}
// The main part of the slimDOM check happens in
// rrweb-snapshot::serializeNodeWithId
return mirror.getId(n) === IGNORED_NODE;
Expand Down

0 comments on commit e08706a

Please sign in to comment.