@highlight-run/rrweb 2.0.6 → 2.0.7

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 (33) hide show
  1. package/dist/plugins/console-record.js +1 -1
  2. package/dist/plugins/console-record.min.js +1 -1
  3. package/dist/plugins/console-record.min.js.map +1 -1
  4. package/dist/plugins/console-replay.min.js.map +1 -1
  5. package/dist/record/rrweb-record-pack.min.js.map +1 -1
  6. package/dist/record/rrweb-record.js +3 -3
  7. package/dist/record/rrweb-record.min.js +3 -3
  8. package/dist/record/rrweb-record.min.js.map +1 -1
  9. package/dist/replay/rrweb-replay-unpack.js +4 -4
  10. package/dist/replay/rrweb-replay-unpack.min.js +4 -4
  11. package/dist/replay/rrweb-replay-unpack.min.js.map +1 -1
  12. package/dist/replay/rrweb-replay.js +3 -3
  13. package/dist/replay/rrweb-replay.min.js +3 -3
  14. package/dist/replay/rrweb-replay.min.js.map +1 -1
  15. package/dist/rrweb-all.js +12 -12
  16. package/dist/rrweb-all.min.js +12 -12
  17. package/dist/rrweb-all.min.js.map +1 -1
  18. package/dist/rrweb.js +5 -5
  19. package/dist/rrweb.min.js +5 -5
  20. package/dist/rrweb.min.js.map +1 -1
  21. package/es/rrweb/packages/rrweb/src/record/index.js +5 -2
  22. package/es/rrweb/packages/rrweb/src/record/mutation.js +23 -11
  23. package/es/rrweb/packages/rrweb/src/record/observer.js +6 -6
  24. package/es/rrweb/packages/rrweb/src/record/observers/canvas/2d.js +1 -1
  25. package/es/rrweb/packages/rrweb/src/record/observers/canvas/canvas.js +2 -2
  26. package/es/rrweb/packages/rrweb/src/record/observers/canvas/webgl.js +1 -2
  27. package/es/rrweb/packages/rrweb/src/utils.js +16 -23
  28. package/es/rrweb/packages/rrweb-snapshot/es/rrweb-snapshot.js +282 -236
  29. package/lib/record/rrweb-record.js +333 -280
  30. package/lib/rrweb-all.js +333 -280
  31. package/lib/rrweb.js +333 -280
  32. package/package.json +4 -4
  33. package/typings/utils.d.ts +1 -1
@@ -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;