@highlight-run/rrweb 2.0.6 → 2.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/plugins/console-record.min.js.map +1 -1
  2. package/dist/plugins/console-replay.min.js.map +1 -1
  3. package/dist/record/rrweb-record-pack.min.js.map +1 -1
  4. package/dist/record/rrweb-record.js +3 -3
  5. package/dist/record/rrweb-record.min.js +3 -3
  6. package/dist/record/rrweb-record.min.js.map +1 -1
  7. package/dist/replay/rrweb-replay-unpack.js +4 -4
  8. package/dist/replay/rrweb-replay-unpack.min.js +4 -4
  9. package/dist/replay/rrweb-replay-unpack.min.js.map +1 -1
  10. package/dist/replay/rrweb-replay.js +4 -4
  11. package/dist/replay/rrweb-replay.min.js +4 -4
  12. package/dist/replay/rrweb-replay.min.js.map +1 -1
  13. package/dist/rrweb-all.js +12 -12
  14. package/dist/rrweb-all.min.js +12 -12
  15. package/dist/rrweb-all.min.js.map +1 -1
  16. package/dist/rrweb.js +5 -5
  17. package/dist/rrweb.min.js +5 -5
  18. package/dist/rrweb.min.js.map +1 -1
  19. package/es/rrweb/packages/rrdom/es/virtual-dom.js +47 -24
  20. package/es/rrweb/packages/rrweb/src/record/index.js +5 -2
  21. package/es/rrweb/packages/rrweb/src/record/mutation.js +23 -11
  22. package/es/rrweb/packages/rrweb/src/record/observer.js +6 -6
  23. package/es/rrweb/packages/rrweb/src/record/observers/canvas/2d.js +1 -1
  24. package/es/rrweb/packages/rrweb/src/record/observers/canvas/canvas.js +2 -2
  25. package/es/rrweb/packages/rrweb/src/record/observers/canvas/webgl.js +1 -2
  26. package/es/rrweb/packages/rrweb/src/utils.js +16 -23
  27. package/es/rrweb/packages/rrweb-snapshot/es/rrweb-snapshot.js +292 -236
  28. package/lib/record/rrweb-record.js +333 -280
  29. package/lib/replay/rrweb-replay-unpack.js +57 -24
  30. package/lib/replay/rrweb-replay.js +57 -24
  31. package/lib/rrweb-all.js +390 -304
  32. package/lib/rrweb.js +390 -304
  33. package/package.json +4 -4
  34. package/typings/utils.d.ts +1 -1
@@ -535,7 +535,7 @@ function diff(oldTree, newTree, replayer, rrnodeMirror) {
535
535
  break;
536
536
  }
537
537
  case NodeType$1.Element: {
538
- const oldElement = (oldTree);
538
+ const oldElement = oldTree;
539
539
  const newRRElement = newTree;
540
540
  diffProps(oldElement, newRRElement, rrnodeMirror);
541
541
  scrollDataToApply = newRRElement.scrollData;
@@ -543,7 +543,7 @@ function diff(oldTree, newTree, replayer, rrnodeMirror) {
543
543
  switch (newRRElement.tagName) {
544
544
  case 'AUDIO':
545
545
  case 'VIDEO': {
546
- const oldMediaElement = (oldTree);
546
+ const oldMediaElement = oldTree;
547
547
  const newMediaRRElement = newRRElement;
548
548
  if (newMediaRRElement.paused !== undefined)
549
549
  newMediaRRElement.paused
@@ -558,7 +558,7 @@ function diff(oldTree, newTree, replayer, rrnodeMirror) {
558
558
  break;
559
559
  }
560
560
  case 'CANVAS':
561
- newTree.canvasMutations.forEach((canvasMutation) => replayer.applyCanvas(canvasMutation.event, canvasMutation.mutation, (oldTree)));
561
+ newTree.canvasMutations.forEach((canvasMutation) => replayer.applyCanvas(canvasMutation.event, canvasMutation.mutation, oldTree));
562
562
  break;
563
563
  case 'STYLE':
564
564
  applyVirtualStyleRulesToNode(oldElement, newTree.rules);
@@ -585,8 +585,7 @@ function diff(oldTree, newTree, replayer, rrnodeMirror) {
585
585
  scrollDataToApply && replayer.applyScroll(scrollDataToApply, true);
586
586
  inputDataToApply && replayer.applyInput(inputDataToApply);
587
587
  if (newTree.nodeName === 'IFRAME') {
588
- const oldContentDocument = (oldTree)
589
- .contentDocument;
588
+ const oldContentDocument = oldTree.contentDocument;
590
589
  const newIFrameElement = newTree;
591
590
  if (oldContentDocument) {
592
591
  const sn = rrnodeMirror.getMeta(newIFrameElement.contentDocument);
@@ -647,16 +646,26 @@ function diffChildren(oldChildren, newChildren, parentNode, replayer, rrnodeMirr
647
646
  newEndNode = newChildren[--newEndIndex];
648
647
  }
649
648
  else if (replayer.mirror.getId(oldStartNode) === rrnodeMirror.getId(newEndNode)) {
650
- parentNode.insertBefore(oldStartNode, oldEndNode.nextSibling);
651
- diff(oldStartNode, newEndNode, replayer, rrnodeMirror);
652
- oldStartNode = oldChildren[++oldStartIndex];
653
- newEndNode = newChildren[--newEndIndex];
649
+ try {
650
+ parentNode.insertBefore(oldStartNode, oldEndNode.nextSibling);
651
+ diff(oldStartNode, newEndNode, replayer, rrnodeMirror);
652
+ oldStartNode = oldChildren[++oldStartIndex];
653
+ newEndNode = newChildren[--newEndIndex];
654
+ }
655
+ catch (e) {
656
+ console.error(e, parentNode, oldStartNode, oldEndNode);
657
+ }
654
658
  }
655
659
  else if (replayer.mirror.getId(oldEndNode) === rrnodeMirror.getId(newStartNode)) {
656
- parentNode.insertBefore(oldEndNode, oldStartNode);
657
- diff(oldEndNode, newStartNode, replayer, rrnodeMirror);
658
- oldEndNode = oldChildren[--oldEndIndex];
659
- newStartNode = newChildren[++newStartIndex];
660
+ try {
661
+ parentNode.insertBefore(oldEndNode, oldStartNode);
662
+ diff(oldEndNode, newStartNode, replayer, rrnodeMirror);
663
+ oldEndNode = oldChildren[--oldEndIndex];
664
+ newStartNode = newChildren[++newStartIndex];
665
+ }
666
+ catch (e) {
667
+ console.error(e, parentNode, oldEndNode, oldStartNode);
668
+ }
660
669
  }
661
670
  else {
662
671
  if (!oldIdToIndex) {
@@ -670,21 +679,31 @@ function diffChildren(oldChildren, newChildren, parentNode, replayer, rrnodeMirr
670
679
  indexInOld = oldIdToIndex[rrnodeMirror.getId(newStartNode)];
671
680
  if (indexInOld) {
672
681
  const nodeToMove = oldChildren[indexInOld];
673
- parentNode.insertBefore(nodeToMove, oldStartNode);
674
- diff(nodeToMove, newStartNode, replayer, rrnodeMirror);
675
- oldChildren[indexInOld] = undefined;
682
+ try {
683
+ parentNode.insertBefore(nodeToMove, oldStartNode);
684
+ diff(nodeToMove, newStartNode, replayer, rrnodeMirror);
685
+ oldChildren[indexInOld] = undefined;
686
+ }
687
+ catch (e) {
688
+ console.error(e, parentNode, nodeToMove, oldStartNode);
689
+ }
676
690
  }
677
691
  else {
678
692
  const newNode = createOrGetNode(newStartNode, replayer.mirror, rrnodeMirror);
679
693
  if (((_a = replayer.mirror.getMeta(parentNode)) === null || _a === void 0 ? void 0 : _a.type) === NodeType$1.Document &&
680
694
  ((_b = replayer.mirror.getMeta(newNode)) === null || _b === void 0 ? void 0 : _b.type) === NodeType$1.Element &&
681
- (parentNode).documentElement) {
682
- parentNode.removeChild((parentNode).documentElement);
695
+ parentNode.documentElement) {
696
+ parentNode.removeChild(parentNode.documentElement);
683
697
  oldChildren[oldStartIndex] = undefined;
684
698
  oldStartNode = undefined;
685
699
  }
686
- parentNode.insertBefore(newNode, oldStartNode || null);
687
- diff(newNode, newStartNode, replayer, rrnodeMirror);
700
+ try {
701
+ parentNode.insertBefore(newNode, oldStartNode || null);
702
+ diff(newNode, newStartNode, replayer, rrnodeMirror);
703
+ }
704
+ catch (e) {
705
+ console.error(e, parentNode, newNode, oldStartNode || null);
706
+ }
688
707
  }
689
708
  newStartNode = newChildren[++newStartIndex];
690
709
  }
@@ -699,8 +718,13 @@ function diffChildren(oldChildren, newChildren, parentNode, replayer, rrnodeMirr
699
718
  });
700
719
  for (; newStartIndex <= newEndIndex; ++newStartIndex) {
701
720
  const newNode = createOrGetNode(newChildren[newStartIndex], replayer.mirror, rrnodeMirror);
702
- parentNode.insertBefore(newNode, referenceNode);
703
- diff(newNode, newChildren[newStartIndex], replayer, rrnodeMirror);
721
+ try {
722
+ parentNode.insertBefore(newNode, referenceNode);
723
+ diff(newNode, newChildren[newStartIndex], replayer, rrnodeMirror);
724
+ }
725
+ catch (e) {
726
+ console.error(e, parentNode, newNode, referenceNode);
727
+ }
704
728
  }
705
729
  }
706
730
  else if (newStartIndex > newEndIndex) {
@@ -754,8 +778,7 @@ function getNestedRule(rules, position) {
754
778
  return rule;
755
779
  }
756
780
  else {
757
- return getNestedRule((rule).cssRules[position[1]]
758
- .cssRules, position.slice(2));
781
+ return getNestedRule(rule.cssRules[position[1]].cssRules, position.slice(2));
759
782
  }
760
783
  }
761
784
  var StyleRuleType;
@@ -1,6 +1,6 @@
1
1
  import { createMirror, snapshot } from '../../../rrweb-snapshot/es/rrweb-snapshot.js';
2
2
  import { initObservers, mutationBuffers } from './observer.js';
3
- import { polyfill, on, getWindowWidth, getWindowHeight, isSerializedIframe, hasShadowRoot } from '../utils.js';
3
+ import { polyfill, on, getWindowWidth, getWindowHeight, isSerializedIframe, isSerializedStylesheet, hasShadowRoot } from '../utils.js';
4
4
  import { EventType, IncrementalSource } from '../types.js';
5
5
  import { IframeManager } from './iframe-manager.js';
6
6
  import { ShadowDomManager } from './shadow-dom-manager.js';
@@ -180,6 +180,9 @@ function record(options = {}) {
180
180
  if (isSerializedIframe(n, mirror)) {
181
181
  iframeManager.addIframe(n);
182
182
  }
183
+ if (isSerializedStylesheet(n, mirror)) {
184
+ stylesheetManager.addStylesheet(n);
185
+ }
183
186
  if (hasShadowRoot(n)) {
184
187
  shadowDomManager.addShadowRoot(n.shadowRoot, document);
185
188
  }
@@ -189,7 +192,7 @@ function record(options = {}) {
189
192
  shadowDomManager.observeAttachShadow(iframe);
190
193
  },
191
194
  onStylesheetLoad: (linkEl, childSn) => {
192
- this.stylesheetManager.attachStylesheet(linkEl, childSn, this.mirror);
195
+ stylesheetManager.attachStylesheet(linkEl, childSn, mirror);
193
196
  },
194
197
  keepIframeSrcFn,
195
198
  });
@@ -166,6 +166,7 @@ class MutationBuffer {
166
166
  onStylesheetLoad: (link, childSn) => {
167
167
  this.stylesheetManager.attachStylesheet(link, childSn, this.mirror);
168
168
  },
169
+ newlyAddedElement: true,
169
170
  });
170
171
  if (sn) {
171
172
  adds.push({
@@ -274,7 +275,8 @@ class MutationBuffer {
274
275
  switch (m.type) {
275
276
  case 'characterData': {
276
277
  const value = m.target.textContent;
277
- if (!isBlocked(m.target, this.blockClass) && value !== m.oldValue) {
278
+ if (!isBlocked(m.target, this.blockClass, false) &&
279
+ value !== m.oldValue) {
278
280
  this.texts.push({
279
281
  value: needMaskingText(m.target, this.maskTextClass, this.maskTextSelector) && value
280
282
  ? this.maskTextFn
@@ -298,7 +300,8 @@ class MutationBuffer {
298
300
  maskInputFn: this.maskInputFn,
299
301
  });
300
302
  }
301
- if (isBlocked(m.target, this.blockClass) || value === m.oldValue) {
303
+ if (isBlocked(m.target, this.blockClass, false) ||
304
+ value === m.oldValue) {
302
305
  return;
303
306
  }
304
307
  let item = this.attributes.find((a) => a.node === m.target);
@@ -352,13 +355,15 @@ class MutationBuffer {
352
355
  break;
353
356
  }
354
357
  case 'childList': {
358
+ if (isBlocked(m.target, this.blockClass, true))
359
+ return;
355
360
  m.addedNodes.forEach((n) => this.genAdds(n, m.target));
356
361
  m.removedNodes.forEach((n) => {
357
362
  const nodeId = this.mirror.getId(n);
358
363
  const parentId = isShadowRoot(m.target)
359
364
  ? this.mirror.getId(m.target.host)
360
365
  : this.mirror.getId(m.target);
361
- if (isBlocked(m.target, this.blockClass) ||
366
+ if (isBlocked(m.target, this.blockClass, false) ||
362
367
  isIgnored(n, this.mirror) ||
363
368
  !isSerialized(n, this.mirror)) {
364
369
  return;
@@ -387,16 +392,13 @@ class MutationBuffer {
387
392
  }
388
393
  };
389
394
  this.genAdds = (n, target) => {
390
- if (target && isBlocked(target, this.blockClass)) {
391
- return;
392
- }
393
- if (this.mirror.getMeta(n)) {
395
+ if (this.mirror.hasNode(n)) {
394
396
  if (isIgnored(n, this.mirror)) {
395
397
  return;
396
398
  }
397
399
  this.movedSet.add(n);
398
400
  let targetId = null;
399
- if (target && this.mirror.getMeta(target)) {
401
+ if (target && this.mirror.hasNode(target)) {
400
402
  targetId = this.mirror.getId(target);
401
403
  }
402
404
  if (targetId && targetId !== -1) {
@@ -407,7 +409,7 @@ class MutationBuffer {
407
409
  this.addedSet.add(n);
408
410
  this.droppedSet.delete(n);
409
411
  }
410
- if (!isBlocked(n, this.blockClass))
412
+ if (!isBlocked(n, this.blockClass, false))
411
413
  n.childNodes.forEach((childN) => this.genAdds(childN));
412
414
  };
413
415
  }
@@ -467,6 +469,11 @@ function deepDelete(addsSet, n) {
467
469
  n.childNodes.forEach((childN) => deepDelete(addsSet, childN));
468
470
  }
469
471
  function isParentRemoved(removes, n, mirror) {
472
+ if (removes.length === 0)
473
+ return false;
474
+ return _isParentRemoved(removes, n, mirror);
475
+ }
476
+ function _isParentRemoved(removes, n, mirror) {
470
477
  const { parentNode } = n;
471
478
  if (!parentNode) {
472
479
  return false;
@@ -475,9 +482,14 @@ function isParentRemoved(removes, n, mirror) {
475
482
  if (removes.some((r) => r.id === parentId)) {
476
483
  return true;
477
484
  }
478
- return isParentRemoved(removes, parentNode, mirror);
485
+ return _isParentRemoved(removes, parentNode, mirror);
479
486
  }
480
487
  function isAncestorInSet(set, n) {
488
+ if (set.size === 0)
489
+ return false;
490
+ return _isAncestorInSet(set, n);
491
+ }
492
+ function _isAncestorInSet(set, n) {
481
493
  const { parentNode } = n;
482
494
  if (!parentNode) {
483
495
  return false;
@@ -485,7 +497,7 @@ function isAncestorInSet(set, n) {
485
497
  if (set.has(parentNode)) {
486
498
  return true;
487
499
  }
488
- return isAncestorInSet(set, parentNode);
500
+ return _isAncestorInSet(set, parentNode);
489
501
  }
490
502
 
491
503
  export { MutationBuffer as default };
@@ -110,7 +110,7 @@ function initMouseInteractionObserver({ mouseInteractionCb, doc, mirror, blockCl
110
110
  const getHandler = (eventKey) => {
111
111
  return (event) => {
112
112
  const target = getEventTarget(event);
113
- if (isBlocked(target, blockClass) ||
113
+ if (isBlocked(target, blockClass, true) ||
114
114
  isCanvasNode(target)) {
115
115
  return;
116
116
  }
@@ -144,7 +144,7 @@ function initMouseInteractionObserver({ mouseInteractionCb, doc, mirror, blockCl
144
144
  function initScrollObserver({ scrollCb, doc, mirror, blockClass, sampling, }) {
145
145
  const updatePosition = throttle((evt) => {
146
146
  const target = getEventTarget(evt);
147
- if (!target || isBlocked(target, blockClass)) {
147
+ if (!target || isBlocked(target, blockClass, true)) {
148
148
  return;
149
149
  }
150
150
  const id = mirror.getId(target);
@@ -200,7 +200,7 @@ function initInputObserver({ inputCb, doc, mirror, blockClass, ignoreClass, mask
200
200
  if (!target ||
201
201
  !target.tagName ||
202
202
  INPUT_TAGS.indexOf(target.tagName) < 0 ||
203
- isBlocked(target, blockClass)) {
203
+ isBlocked(target, blockClass, true)) {
204
204
  return;
205
205
  }
206
206
  const type = target.type;
@@ -335,8 +335,8 @@ function initStyleSheetObserver({ styleSheetRuleCb, mirror }, { win }) {
335
335
  const unmodifiedFunctions = {};
336
336
  Object.entries(supportedNestedCSSRuleTypes).forEach(([typeKey, type]) => {
337
337
  unmodifiedFunctions[typeKey] = {
338
- insertRule: (type).prototype.insertRule,
339
- deleteRule: (type).prototype.deleteRule,
338
+ insertRule: type.prototype.insertRule,
339
+ deleteRule: type.prototype.deleteRule,
340
340
  };
341
341
  type.prototype.insertRule = function (rule, index) {
342
342
  const id = mirror.getId(this.parentStyleSheet.ownerNode);
@@ -417,7 +417,7 @@ function initStyleDeclarationObserver({ styleDeclarationCb, mirror }, { win }) {
417
417
  function initMediaInteractionObserver({ mediaInteractionCb, blockClass, mirror, sampling, }) {
418
418
  const handler = (type) => throttle((event) => {
419
419
  const target = getEventTarget(event);
420
- if (!target || isBlocked(target, blockClass)) {
420
+ if (!target || isBlocked(target, blockClass, true)) {
421
421
  return;
422
422
  }
423
423
  const { currentTime, volume, muted } = target;
@@ -12,7 +12,7 @@ function initCanvas2DMutationObserver(cb, win, blockClass, mirror) {
12
12
  }
13
13
  const restoreHandler = patch(win.CanvasRenderingContext2D.prototype, prop, function (original) {
14
14
  return function (...args) {
15
- if (!isBlocked(this.canvas, blockClass)) {
15
+ if (!isBlocked(this.canvas, blockClass, true)) {
16
16
  setTimeout(() => {
17
17
  const recordArgs = serializeArgs([...args], win, this);
18
18
  cb(this.canvas, {
@@ -5,9 +5,9 @@ function initCanvasContextObserver(win, blockClass) {
5
5
  try {
6
6
  const restoreHandler = patch(win.HTMLCanvasElement.prototype, 'getContext', function (original) {
7
7
  return function (contextType, ...args) {
8
- if (!isBlocked(this, blockClass)) {
8
+ if (!isBlocked(this, blockClass, true)) {
9
9
  if (!('__context' in this))
10
- (this).__context = contextType;
10
+ this.__context = contextType;
11
11
  }
12
12
  return original.apply(this, [contextType, ...args]);
13
13
  };
@@ -14,8 +14,7 @@ function patchGLPrototype(prototype, type, cb, blockClass, mirror, win) {
14
14
  return function (...args) {
15
15
  const result = original.apply(this, args);
16
16
  saveWebGLVar(result, win, prototype);
17
- if (!isBlocked(this.canvas, blockClass)) {
18
- const id = mirror.getId(this.canvas);
17
+ if (!isBlocked(this.canvas, blockClass, true)) {
19
18
  const recordArgs = serializeArgs([...args], win, prototype);
20
19
  const mutation = {
21
20
  type,
@@ -1,4 +1,4 @@
1
- import { IGNORED_NODE, isShadowRoot } from '../../rrweb-snapshot/es/rrweb-snapshot.js';
1
+ import { classMatchesRegex, IGNORED_NODE, isShadowRoot } from '../../rrweb-snapshot/es/rrweb-snapshot.js';
2
2
 
3
3
  function on(type, fn, target = document) {
4
4
  const options = { capture: true, passive: true };
@@ -131,33 +131,26 @@ const isCanvasNode = (node) => {
131
131
  }
132
132
  return false;
133
133
  };
134
- function isBlocked(node, blockClass) {
134
+ function isBlocked(node, blockClass, checkAncestors) {
135
135
  if (!node) {
136
136
  return false;
137
137
  }
138
- if (node.nodeType === node.ELEMENT_NODE) {
139
- let needBlock = false;
140
- if (typeof blockClass === 'string') {
141
- if (node.closest !== undefined) {
142
- return node.closest('.' + blockClass) !== null;
143
- }
144
- else {
145
- needBlock = node.classList.contains(blockClass);
146
- }
147
- }
148
- else {
149
- node.classList.forEach((className) => {
150
- if (blockClass.test(className)) {
151
- needBlock = true;
152
- }
153
- });
154
- }
155
- return needBlock || isBlocked(node.parentNode, blockClass);
138
+ const el = node.nodeType === node.ELEMENT_NODE
139
+ ? node
140
+ : node.parentElement;
141
+ if (!el)
142
+ return false;
143
+ if (typeof blockClass === 'string') {
144
+ if (el.classList.contains(blockClass))
145
+ return true;
146
+ if (checkAncestors && el.closest('.' + blockClass) !== null)
147
+ return true;
156
148
  }
157
- if (node.nodeType === node.TEXT_NODE) {
158
- return isBlocked(node.parentNode, blockClass);
149
+ else {
150
+ if (classMatchesRegex(el, blockClass, checkAncestors))
151
+ return true;
159
152
  }
160
- return isBlocked(node.parentNode, blockClass);
153
+ return false;
161
154
  }
162
155
  function isSerialized(n, mirror) {
163
156
  return mirror.getId(n) !== -1;