@screeb/rrweb 1.0.7 → 1.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.
package/dist/rrweb.d.cts CHANGED
@@ -114,8 +114,6 @@ declare function iterateResolveTree(tree: ResolveTree, cb: (mutation: addedNodeM
114
114
 
115
115
  declare function legacy_isTouchEvent(event: MouseEvent | TouchEvent | PointerEvent): event is TouchEvent;
116
116
 
117
- export { listenerHandler }
118
-
119
117
  export declare let mirror: DeprecatedMirror;
120
118
 
121
119
  export { MouseInteractions }
@@ -124,10 +122,6 @@ declare let nowTimestamp: () => number;
124
122
 
125
123
  declare function on(type: string, fn: EventListenerOrEventListenerObject, target?: Document | IWindow): listenerHandler;
126
124
 
127
- declare function patch(source: {
128
- [key: string]: any;
129
- }, name: string, replacement: (...args: unknown[]) => unknown): () => void;
130
-
131
125
  declare type PlayerAssets = {
132
126
  emitter: Emitter;
133
127
  applyEventsSynchronously(events: Array<eventWithTime>): void;
@@ -433,7 +427,6 @@ declare namespace utils {
433
427
  on,
434
428
  throttle,
435
429
  hookSetter,
436
- patch,
437
430
  getWindowScroll,
438
431
  getWindowHeight,
439
432
  getWindowWidth,
package/dist/rrweb.d.ts CHANGED
@@ -114,8 +114,6 @@ declare function iterateResolveTree(tree: ResolveTree, cb: (mutation: addedNodeM
114
114
 
115
115
  declare function legacy_isTouchEvent(event: MouseEvent | TouchEvent | PointerEvent): event is TouchEvent;
116
116
 
117
- export { listenerHandler }
118
-
119
117
  export declare let mirror: DeprecatedMirror;
120
118
 
121
119
  export { MouseInteractions }
@@ -124,10 +122,6 @@ declare let nowTimestamp: () => number;
124
122
 
125
123
  declare function on(type: string, fn: EventListenerOrEventListenerObject, target?: Document | IWindow): listenerHandler;
126
124
 
127
- declare function patch(source: {
128
- [key: string]: any;
129
- }, name: string, replacement: (...args: unknown[]) => unknown): () => void;
130
-
131
125
  declare type PlayerAssets = {
132
126
  emitter: Emitter;
133
127
  applyEventsSynchronously(events: Array<eventWithTime>): void;
@@ -433,7 +427,6 @@ declare namespace utils {
433
427
  on,
434
428
  throttle,
435
429
  hookSetter,
436
- patch,
437
430
  getWindowScroll,
438
431
  getWindowHeight,
439
432
  getWindowWidth,
package/dist/rrweb.js CHANGED
@@ -142,6 +142,32 @@ function querySelectorAll$1(n2, selectors) {
142
142
  function mutationObserverCtor$1() {
143
143
  return getUntaintedPrototype$1("MutationObserver").constructor;
144
144
  }
145
+ function patch$1(source, name, replacement) {
146
+ try {
147
+ if (!(name in source)) {
148
+ return () => {
149
+ };
150
+ }
151
+ const original = source[name];
152
+ const wrapped = replacement(original);
153
+ if (typeof wrapped === "function") {
154
+ wrapped.prototype = wrapped.prototype || {};
155
+ Object.defineProperties(wrapped, {
156
+ __rrweb_original__: {
157
+ enumerable: false,
158
+ value: original
159
+ }
160
+ });
161
+ }
162
+ source[name] = wrapped;
163
+ return () => {
164
+ source[name] = original;
165
+ };
166
+ } catch {
167
+ return () => {
168
+ };
169
+ }
170
+ }
145
171
  const index$1 = {
146
172
  childNodes: childNodes$1,
147
173
  parentNode: parentNode$1,
@@ -154,7 +180,8 @@ const index$1 = {
154
180
  shadowRoot: shadowRoot$1,
155
181
  querySelector: querySelector$1,
156
182
  querySelectorAll: querySelectorAll$1,
157
- mutationObserver: mutationObserverCtor$1
183
+ mutationObserver: mutationObserverCtor$1,
184
+ patch: patch$1
158
185
  };
159
186
  function isElement(n2) {
160
187
  return n2.nodeType === n2.ELEMENT_NODE;
@@ -435,26 +462,97 @@ function absolutifyURLs(cssText, href) {
435
462
  }
436
463
  );
437
464
  }
438
- function normalizeCssString(cssText) {
439
- return cssText.replace(/(\/\*[^*]*\*\/)|[\s;]/g, "");
465
+ function normalizeCssString(cssText, _testNoPxNorm = false) {
466
+ if (_testNoPxNorm) {
467
+ return cssText.replace(/(\/\*[^*]*\*\/)|[\s;]/g, "");
468
+ } else {
469
+ return cssText.replace(/(\/\*[^*]*\*\/)|[\s;]/g, "").replace(/0px/g, "0");
470
+ }
440
471
  }
441
- function splitCssText(cssText, style) {
472
+ function splitCssText(cssText, style, _testNoPxNorm = false) {
442
473
  const childNodes2 = Array.from(style.childNodes);
443
474
  const splits = [];
475
+ let iterCount = 0;
444
476
  if (childNodes2.length > 1 && cssText && typeof cssText === "string") {
445
- const cssTextNorm = normalizeCssString(cssText);
477
+ let cssTextNorm = normalizeCssString(cssText, _testNoPxNorm);
478
+ const normFactor = cssTextNorm.length / cssText.length;
446
479
  for (let i2 = 1; i2 < childNodes2.length; i2++) {
447
480
  if (childNodes2[i2].textContent && typeof childNodes2[i2].textContent === "string") {
448
- const textContentNorm = normalizeCssString(childNodes2[i2].textContent);
449
- for (let j = 3; j < textContentNorm.length; j++) {
450
- const bit = textContentNorm.substring(0, j);
451
- if (cssTextNorm.split(bit).length === 2) {
452
- const splitNorm = cssTextNorm.indexOf(bit);
453
- for (let k = splitNorm; k < cssText.length; k++) {
454
- if (normalizeCssString(cssText.substring(0, k)).length === splitNorm) {
481
+ const textContentNorm = normalizeCssString(
482
+ childNodes2[i2].textContent,
483
+ _testNoPxNorm
484
+ );
485
+ const jLimit = 100;
486
+ let j = 3;
487
+ for (; j < textContentNorm.length; j++) {
488
+ if (
489
+ // keep consuming css identifiers (to get a decent chunk more quickly)
490
+ textContentNorm[j].match(/[a-zA-Z0-9]/) || // substring needs to be unique to this section
491
+ textContentNorm.indexOf(textContentNorm.substring(0, j), 1) !== -1
492
+ ) {
493
+ continue;
494
+ }
495
+ break;
496
+ }
497
+ for (; j < textContentNorm.length; j++) {
498
+ let startSubstring = textContentNorm.substring(0, j);
499
+ let cssNormSplits = cssTextNorm.split(startSubstring);
500
+ let splitNorm = -1;
501
+ if (cssNormSplits.length === 2) {
502
+ splitNorm = cssNormSplits[0].length;
503
+ } else if (cssNormSplits.length > 2 && cssNormSplits[0] === "" && childNodes2[i2 - 1].textContent !== "") {
504
+ splitNorm = cssTextNorm.indexOf(startSubstring, 1);
505
+ } else if (cssNormSplits.length === 1) {
506
+ startSubstring = startSubstring.substring(
507
+ 0,
508
+ startSubstring.length - 1
509
+ );
510
+ cssNormSplits = cssTextNorm.split(startSubstring);
511
+ if (cssNormSplits.length <= 1) {
512
+ splits.push(cssText);
513
+ return splits;
514
+ }
515
+ j = jLimit + 1;
516
+ } else if (j === textContentNorm.length - 1) {
517
+ splitNorm = cssTextNorm.indexOf(startSubstring);
518
+ }
519
+ if (cssNormSplits.length >= 2 && j > jLimit) {
520
+ const prevTextContent = childNodes2[i2 - 1].textContent;
521
+ if (prevTextContent && typeof prevTextContent === "string") {
522
+ const prevMinLength = normalizeCssString(prevTextContent).length;
523
+ splitNorm = cssTextNorm.indexOf(startSubstring, prevMinLength);
524
+ }
525
+ if (splitNorm === -1) {
526
+ splitNorm = cssNormSplits[0].length;
527
+ }
528
+ }
529
+ if (splitNorm !== -1) {
530
+ let k = Math.floor(splitNorm / normFactor);
531
+ for (; k > 0 && k < cssText.length; ) {
532
+ iterCount += 1;
533
+ if (iterCount > 50 * childNodes2.length) {
534
+ splits.push(cssText);
535
+ return splits;
536
+ }
537
+ const normPart = normalizeCssString(
538
+ cssText.substring(0, k),
539
+ _testNoPxNorm
540
+ );
541
+ if (normPart.length === splitNorm) {
455
542
  splits.push(cssText.substring(0, k));
456
543
  cssText = cssText.substring(k);
544
+ cssTextNorm = cssTextNorm.substring(splitNorm);
457
545
  break;
546
+ } else if (normPart.length < splitNorm) {
547
+ k += Math.max(
548
+ 1,
549
+ Math.floor((splitNorm - normPart.length) / normFactor)
550
+ );
551
+ } else {
552
+ k -= Math.max(
553
+ 1,
554
+ Math.floor((normPart.length - splitNorm) * normFactor)
555
+ );
458
556
  }
459
557
  }
460
558
  break;
@@ -5009,11 +5107,16 @@ function getTagName(n2) {
5009
5107
  function adaptCssForReplay(cssText, cache) {
5010
5108
  const cachedStyle = cache == null ? void 0 : cache.stylesWithHoverClass.get(cssText);
5011
5109
  if (cachedStyle) return cachedStyle;
5012
- const ast = postcss$1$1([
5013
- mediaSelectorPlugin,
5014
- pseudoClassPlugin
5015
- ]).process(cssText);
5016
- const result2 = ast.css;
5110
+ let result2 = cssText;
5111
+ try {
5112
+ const ast = postcss$1$1([
5113
+ mediaSelectorPlugin,
5114
+ pseudoClassPlugin
5115
+ ]).process(cssText);
5116
+ result2 = ast.css;
5117
+ } catch (error) {
5118
+ console.warn("Failed to adapt css for replay", error);
5119
+ }
5017
5120
  cache == null ? void 0 : cache.stylesWithHoverClass.set(cssText, result2);
5018
5121
  return result2;
5019
5122
  }
@@ -5034,11 +5137,39 @@ function applyCssSplits(n2, cssText, hackCss, cache) {
5034
5137
  while (cssTextSplits.length > 1 && cssTextSplits.length > childTextNodes.length) {
5035
5138
  cssTextSplits.splice(-2, 2, cssTextSplits.slice(-2).join(""));
5036
5139
  }
5140
+ let adaptedCss = "";
5141
+ if (hackCss) {
5142
+ adaptedCss = adaptCssForReplay(cssTextSplits.join(""), cache);
5143
+ }
5144
+ let startIndex = 0;
5037
5145
  for (let i2 = 0; i2 < childTextNodes.length; i2++) {
5146
+ if (i2 === cssTextSplits.length) {
5147
+ break;
5148
+ }
5038
5149
  const childTextNode = childTextNodes[i2];
5039
- const cssTextSection = cssTextSplits[i2];
5040
- if (childTextNode && cssTextSection) {
5041
- childTextNode.textContent = hackCss ? adaptCssForReplay(cssTextSection, cache) : cssTextSection;
5150
+ if (!hackCss) {
5151
+ childTextNode.textContent = cssTextSplits[i2];
5152
+ } else if (i2 < cssTextSplits.length - 1) {
5153
+ let endIndex = startIndex;
5154
+ let endSearch = cssTextSplits[i2 + 1].length;
5155
+ endSearch = Math.min(endSearch, 30);
5156
+ let found = false;
5157
+ for (; endSearch > 2; endSearch--) {
5158
+ const searchBit = cssTextSplits[i2 + 1].substring(0, endSearch);
5159
+ const searchIndex = adaptedCss.substring(startIndex).indexOf(searchBit);
5160
+ found = searchIndex !== -1;
5161
+ if (found) {
5162
+ endIndex += searchIndex;
5163
+ break;
5164
+ }
5165
+ }
5166
+ if (!found) {
5167
+ endIndex += cssTextSplits[i2].length;
5168
+ }
5169
+ childTextNode.textContent = adaptedCss.substring(startIndex, endIndex);
5170
+ startIndex = endIndex;
5171
+ } else {
5172
+ childTextNode.textContent = adaptedCss.substring(startIndex);
5042
5173
  }
5043
5174
  }
5044
5175
  }
@@ -10357,6 +10488,32 @@ function querySelectorAll(n2, selectors) {
10357
10488
  function mutationObserverCtor() {
10358
10489
  return getUntaintedPrototype("MutationObserver").constructor;
10359
10490
  }
10491
+ function patch(source, name, replacement) {
10492
+ try {
10493
+ if (!(name in source)) {
10494
+ return () => {
10495
+ };
10496
+ }
10497
+ const original = source[name];
10498
+ const wrapped = replacement(original);
10499
+ if (typeof wrapped === "function") {
10500
+ wrapped.prototype = wrapped.prototype || {};
10501
+ Object.defineProperties(wrapped, {
10502
+ __rrweb_original__: {
10503
+ enumerable: false,
10504
+ value: original
10505
+ }
10506
+ });
10507
+ }
10508
+ source[name] = wrapped;
10509
+ return () => {
10510
+ source[name] = original;
10511
+ };
10512
+ } catch {
10513
+ return () => {
10514
+ };
10515
+ }
10516
+ }
10360
10517
  const index = {
10361
10518
  childNodes,
10362
10519
  parentNode,
@@ -10369,7 +10526,8 @@ const index = {
10369
10526
  shadowRoot,
10370
10527
  querySelector,
10371
10528
  querySelectorAll,
10372
- mutationObserver: mutationObserverCtor
10529
+ mutationObserver: mutationObserverCtor,
10530
+ patch
10373
10531
  };
10374
10532
  function on(type, fn, target = document) {
10375
10533
  const options = { capture: true, passive: true };
@@ -10452,32 +10610,6 @@ function hookSetter(target, key, d, isRevoked, win = window) {
10452
10610
  );
10453
10611
  return () => hookSetter(target, key, original || {}, true);
10454
10612
  }
10455
- function patch(source, name, replacement) {
10456
- try {
10457
- if (!(name in source)) {
10458
- return () => {
10459
- };
10460
- }
10461
- const original = source[name];
10462
- const wrapped = replacement(original);
10463
- if (typeof wrapped === "function") {
10464
- wrapped.prototype = wrapped.prototype || {};
10465
- Object.defineProperties(wrapped, {
10466
- __rrweb_original__: {
10467
- enumerable: false,
10468
- value: original
10469
- }
10470
- });
10471
- }
10472
- source[name] = wrapped;
10473
- return () => {
10474
- source[name] = original;
10475
- };
10476
- } catch {
10477
- return () => {
10478
- };
10479
- }
10480
- }
10481
10613
  let nowTimestamp = Date.now;
10482
10614
  if (!/* @__PURE__ */ /[1-9][0-9]{12}/.test(Date.now().toString())) {
10483
10615
  nowTimestamp = () => (/* @__PURE__ */ new Date()).getTime();
@@ -10491,10 +10623,12 @@ function getWindowScroll(win) {
10491
10623
  };
10492
10624
  }
10493
10625
  function getWindowHeight(win) {
10494
- return win.innerHeight || win.document.documentElement && win.document.documentElement.clientHeight || win.document.body && win.document.body.clientHeight;
10626
+ var _a2, _b;
10627
+ return win.innerHeight || ((_a2 = win.document.documentElement) == null ? void 0 : _a2.clientHeight) || ((_b = win.document.body) == null ? void 0 : _b.clientHeight);
10495
10628
  }
10496
10629
  function getWindowWidth(win) {
10497
- return win.innerWidth || win.document.documentElement && win.document.documentElement.clientWidth || win.document.body && win.document.body.clientWidth;
10630
+ var _a2, _b;
10631
+ return win.innerWidth || ((_a2 = win.document.documentElement) == null ? void 0 : _a2.clientWidth) || ((_b = win.document.body) == null ? void 0 : _b.clientWidth);
10498
10632
  }
10499
10633
  function closestElementOfNode(node2) {
10500
10634
  if (!node2) {
@@ -10763,7 +10897,6 @@ const utils = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePropert
10763
10897
  return nowTimestamp;
10764
10898
  },
10765
10899
  on,
10766
- patch,
10767
10900
  polyfill: polyfill$1,
10768
10901
  queueToResolveTrees,
10769
10902
  shadowHostInDom,
@@ -11206,10 +11339,18 @@ class MutationBuffer {
11206
11339
  this.attributes.push(item);
11207
11340
  this.attributeMap.set(textarea, item);
11208
11341
  }
11209
- item.attributes.value = Array.from(
11342
+ const value = Array.from(
11210
11343
  index.childNodes(textarea),
11211
11344
  (cn) => index.textContent(cn) || ""
11212
11345
  ).join("");
11346
+ item.attributes.value = maskInputValue({
11347
+ element: textarea,
11348
+ maskInputOptions: this.maskInputOptions,
11349
+ tagName: textarea.tagName,
11350
+ type: getInputType(textarea),
11351
+ value,
11352
+ maskInputFn: this.maskInputFn
11353
+ });
11213
11354
  });
11214
11355
  __publicField(this, "processMutation", (m) => {
11215
11356
  if (isIgnored(m.target, this.mirror, this.slimDOMOptions)) {
@@ -12823,7 +12964,7 @@ class ShadowDomManager {
12823
12964
  }
12824
12965
  init() {
12825
12966
  this.reset();
12826
- this.patchAttachShadow(Element, document);
12967
+ this.patchAttachShadow(Element, this.bypassOptions.win.document);
12827
12968
  }
12828
12969
  addShadowRoot(shadowRoot2, doc) {
12829
12970
  if (!isNativeShadowDom(shadowRoot2)) return;
@@ -14014,7 +14155,7 @@ function record(options = {}) {
14014
14155
  data: {}
14015
14156
  });
14016
14157
  if (recordAfter === "DOMContentLoaded") init();
14017
- })
14158
+ }, win.document)
14018
14159
  );
14019
14160
  handlers.push(
14020
14161
  on(
@@ -15363,21 +15504,21 @@ class Replayer {
15363
15504
  if (plugin3.handler) plugin3.handler(event, isSync, { replayer: this });
15364
15505
  }
15365
15506
  this.service.send({ type: "CAST_EVENT", payload: { event } });
15366
- const last_index = this.service.state.context.events.length - 1;
15367
- if (!this.config.liveMode && event === this.service.state.context.events[last_index]) {
15507
+ const lastIndex = this.service.state.context.events.length - 1;
15508
+ if (!this.config.liveMode && event === this.service.state.context.events[lastIndex]) {
15368
15509
  const finish = () => {
15369
- if (last_index < this.service.state.context.events.length - 1) {
15510
+ if (lastIndex < this.service.state.context.events.length - 1) {
15370
15511
  return;
15371
15512
  }
15372
15513
  this.backToNormal();
15373
15514
  this.service.send("END");
15374
15515
  this.emitter.emit(ReplayerEvents.Finish);
15375
15516
  };
15376
- let finish_buffer = 50;
15517
+ let finishBuffer = 50;
15377
15518
  if (event.type === EventType.IncrementalSnapshot && event.data.source === IncrementalSource.MouseMove && event.data.positions.length) {
15378
- finish_buffer += Math.max(0, -event.data.positions[0].timeOffset);
15519
+ finishBuffer += Math.max(0, -event.data.positions[0].timeOffset);
15379
15520
  }
15380
- setTimeout(finish, finish_buffer);
15521
+ setTimeout(finish, finishBuffer);
15381
15522
  }
15382
15523
  this.emitter.emit(ReplayerEvents.EventCast, event);
15383
15524
  };
@@ -16560,18 +16701,27 @@ class Replayer {
16560
16701
  const newSn = mirror2.getMeta(
16561
16702
  target
16562
16703
  );
16704
+ const newNode = buildNodeWithSN(
16705
+ {
16706
+ ...newSn,
16707
+ attributes: {
16708
+ ...newSn.attributes,
16709
+ ...mutation.attributes
16710
+ }
16711
+ },
16712
+ {
16713
+ doc: target.ownerDocument,
16714
+ // can be Document or RRDocument
16715
+ mirror: mirror2,
16716
+ skipChild: true,
16717
+ hackCss: true,
16718
+ cache: this.cache
16719
+ }
16720
+ );
16563
16721
  Object.assign(
16564
16722
  newSn.attributes,
16565
16723
  mutation.attributes
16566
16724
  );
16567
- const newNode = buildNodeWithSN(newSn, {
16568
- doc: target.ownerDocument,
16569
- // can be Document or RRDocument
16570
- mirror: mirror2,
16571
- skipChild: true,
16572
- hackCss: true,
16573
- cache: this.cache
16574
- });
16575
16725
  const siblingNode = target.nextSibling;
16576
16726
  const parentNode2 = target.parentNode;
16577
16727
  if (newNode && parentNode2) {