@sentry/replay 7.70.0-beta.0 → 7.70.0

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/esm/index.js CHANGED
@@ -61,159 +61,44 @@ var NodeType$1;
61
61
  NodeType[NodeType["Comment"] = 5] = "Comment";
62
62
  })(NodeType$1 || (NodeType$1 = {}));
63
63
 
64
- function isElement$1(n) {
64
+ function isElement(n) {
65
65
  return n.nodeType === n.ELEMENT_NODE;
66
66
  }
67
67
  function isShadowRoot(n) {
68
68
  const host = n === null || n === void 0 ? void 0 : n.host;
69
- return Boolean((host === null || host === void 0 ? void 0 : host.shadowRoot) === n);
69
+ return Boolean(host && host.shadowRoot && host.shadowRoot === n);
70
70
  }
71
- function isNativeShadowDom(shadowRoot) {
72
- return Object.prototype.toString.call(shadowRoot) === '[object ShadowRoot]';
73
- }
74
- function fixBrowserCompatibilityIssuesInCSS(cssText) {
75
- if (cssText.includes(' background-clip: text;') &&
76
- !cssText.includes(' -webkit-background-clip: text;')) {
77
- cssText = cssText.replace(' background-clip: text;', ' -webkit-background-clip: text; background-clip: text;');
71
+ function isInputTypeMasked({ maskInputOptions, tagName, type, }) {
72
+ if (tagName.toLowerCase() === 'option') {
73
+ tagName = 'select';
78
74
  }
79
- return cssText;
75
+ const actualType = typeof type === 'string' ? type.toLowerCase() : undefined;
76
+ return (maskInputOptions[tagName.toLowerCase()] ||
77
+ (actualType && maskInputOptions[actualType]) ||
78
+ actualType === 'password' ||
79
+ (tagName === 'input' && !type && maskInputOptions['text']));
80
80
  }
81
- function escapeImportStatement(rule) {
82
- const { cssText } = rule;
83
- if (cssText.split('"').length < 3)
84
- return cssText;
85
- const statement = ['@import', `url(${JSON.stringify(rule.href)})`];
86
- if (rule.layerName === '') {
87
- statement.push(`layer`);
88
- }
89
- else if (rule.layerName) {
90
- statement.push(`layer(${rule.layerName})`);
91
- }
92
- if (rule.supportsText) {
93
- statement.push(`supports(${rule.supportsText})`);
94
- }
95
- if (rule.media.length) {
96
- statement.push(rule.media.mediaText);
97
- }
98
- return statement.join(' ') + ';';
99
- }
100
- function stringifyStylesheet(s) {
101
- try {
102
- const rules = s.rules || s.cssRules;
103
- return rules
104
- ? fixBrowserCompatibilityIssuesInCSS(Array.from(rules, stringifyRule).join(''))
105
- : null;
106
- }
107
- catch (error) {
108
- return null;
109
- }
81
+ function hasInputMaskOptions({ tagName, type, maskInputOptions, maskInputSelector, }) {
82
+ return (maskInputSelector || isInputTypeMasked({ maskInputOptions, tagName, type }));
110
83
  }
111
- function stringifyRule(rule) {
112
- let importStringified;
113
- if (isCSSImportRule(rule)) {
114
- try {
115
- importStringified =
116
- stringifyStylesheet(rule.styleSheet) ||
117
- escapeImportStatement(rule);
118
- }
119
- catch (error) {
120
- }
121
- }
122
- else if (isCSSStyleRule(rule) && rule.selectorText.includes(':')) {
123
- return fixSafariColons(rule.cssText);
124
- }
125
- return importStringified || rule.cssText;
126
- }
127
- function fixSafariColons(cssStringified) {
128
- const regex = /(\[(?:[\w-]+)[^\\])(:(?:[\w-]+)\])/gm;
129
- return cssStringified.replace(regex, '$1\\$2');
130
- }
131
- function isCSSImportRule(rule) {
132
- return 'styleSheet' in rule;
133
- }
134
- function isCSSStyleRule(rule) {
135
- return 'selectorText' in rule;
136
- }
137
- class Mirror {
138
- constructor() {
139
- this.idNodeMap = new Map();
140
- this.nodeMetaMap = new WeakMap();
141
- }
142
- getId(n) {
143
- var _a;
144
- if (!n)
145
- return -1;
146
- const id = (_a = this.getMeta(n)) === null || _a === void 0 ? void 0 : _a.id;
147
- return id !== null && id !== void 0 ? id : -1;
148
- }
149
- getNode(id) {
150
- return this.idNodeMap.get(id) || null;
151
- }
152
- getIds() {
153
- return Array.from(this.idNodeMap.keys());
84
+ function maskInputValue({ input, maskInputSelector, unmaskInputSelector, maskInputOptions, tagName, type, value, maskInputFn, }) {
85
+ let text = value || '';
86
+ if (unmaskInputSelector && input.matches(unmaskInputSelector)) {
87
+ return text;
154
88
  }
155
- getMeta(n) {
156
- return this.nodeMetaMap.get(n) || null;
89
+ if (input.hasAttribute('data-rr-is-password')) {
90
+ type = 'password';
157
91
  }
158
- removeNodeFromMap(n) {
159
- const id = this.getId(n);
160
- this.idNodeMap.delete(id);
161
- if (n.childNodes) {
162
- n.childNodes.forEach((childNode) => this.removeNodeFromMap(childNode));
92
+ if (isInputTypeMasked({ maskInputOptions, tagName, type }) ||
93
+ (maskInputSelector && input.matches(maskInputSelector))) {
94
+ if (maskInputFn) {
95
+ text = maskInputFn(text);
163
96
  }
164
- }
165
- has(id) {
166
- return this.idNodeMap.has(id);
167
- }
168
- hasNode(node) {
169
- return this.nodeMetaMap.has(node);
170
- }
171
- add(n, meta) {
172
- const id = meta.id;
173
- this.idNodeMap.set(id, n);
174
- this.nodeMetaMap.set(n, meta);
175
- }
176
- replace(id, n) {
177
- const oldNode = this.getNode(id);
178
- if (oldNode) {
179
- const meta = this.nodeMetaMap.get(oldNode);
180
- if (meta)
181
- this.nodeMetaMap.set(n, meta);
97
+ else {
98
+ text = '*'.repeat(text.length);
182
99
  }
183
- this.idNodeMap.set(id, n);
184
- }
185
- reset() {
186
- this.idNodeMap = new Map();
187
- this.nodeMetaMap = new WeakMap();
188
100
  }
189
- }
190
- function createMirror() {
191
- return new Mirror();
192
- }
193
- function shouldMaskInput({ maskInputOptions, tagName, type, }) {
194
- if (tagName === 'OPTION') {
195
- tagName = 'SELECT';
196
- }
197
- return Boolean(maskInputOptions[tagName.toLowerCase()] ||
198
- (type && maskInputOptions[type]) ||
199
- type === 'password' ||
200
- (tagName === 'INPUT' && !type && maskInputOptions['text']));
201
- }
202
- function maskInputValue({ isMasked, element, value, maskInputFn, }) {
203
- let text = value || '';
204
- if (!isMasked) {
205
- return text;
206
- }
207
- if (maskInputFn) {
208
- text = maskInputFn(text, element);
209
- }
210
- return '*'.repeat(text.length);
211
- }
212
- function toLowerCase(str) {
213
- return str.toLowerCase();
214
- }
215
- function toUpperCase(str) {
216
- return str.toUpperCase();
101
+ return text;
217
102
  }
218
103
  const ORIGINAL_ATTRIBUTE_NAME = '__rrweb_original__';
219
104
  function is2DCanvasBlank(canvas) {
@@ -239,11 +124,11 @@ function getInputType(element) {
239
124
  return element.hasAttribute('data-rr-is-password')
240
125
  ? 'password'
241
126
  : type
242
- ?
243
- toLowerCase(type)
127
+ ? type.toLowerCase()
244
128
  : null;
245
129
  }
246
130
  function getInputValue(el, tagName, type) {
131
+ typeof type === 'string' ? type.toLowerCase() : '';
247
132
  if (tagName === 'INPUT' && (type === 'radio' || type === 'checkbox')) {
248
133
  return el.getAttribute('value') || '';
249
134
  }
@@ -253,6 +138,9 @@ function getInputValue(el, tagName, type) {
253
138
  let _id = 1;
254
139
  const tagNameRegex = new RegExp('[^a-z0-9-_:]');
255
140
  const IGNORED_NODE = -2;
141
+ function defaultMaskFn(str) {
142
+ return str ? str.replace(/[\S]/g, '*') : '';
143
+ }
256
144
  function genId() {
257
145
  return _id++;
258
146
  }
@@ -260,12 +148,49 @@ function getValidTagName(element) {
260
148
  if (element instanceof HTMLFormElement) {
261
149
  return 'form';
262
150
  }
263
- const processedTagName = toLowerCase(element.tagName);
151
+ const processedTagName = element.tagName.toLowerCase().trim();
264
152
  if (tagNameRegex.test(processedTagName)) {
265
153
  return 'div';
266
154
  }
267
155
  return processedTagName;
268
156
  }
157
+ function getCssRulesString(s) {
158
+ try {
159
+ const rules = s.rules || s.cssRules;
160
+ return rules ? Array.from(rules).map(getCssRuleString).join('') : null;
161
+ }
162
+ catch (error) {
163
+ return null;
164
+ }
165
+ }
166
+ function getCssRuleString(rule) {
167
+ let cssStringified = rule.cssText;
168
+ if (isCSSImportRule(rule)) {
169
+ try {
170
+ cssStringified = getCssRulesString(rule.styleSheet) || cssStringified;
171
+ }
172
+ catch (_a) {
173
+ }
174
+ }
175
+ return validateStringifiedCssRule(cssStringified);
176
+ }
177
+ function validateStringifiedCssRule(cssStringified) {
178
+ if (cssStringified.indexOf(':') > -1) {
179
+ const regex = /(\[(?:[\w-]+)[^\\])(:(?:[\w-]+)\])/gm;
180
+ return cssStringified.replace(regex, '$1\\$2');
181
+ }
182
+ return cssStringified;
183
+ }
184
+ function isCSSImportRule(rule) {
185
+ return 'styleSheet' in rule;
186
+ }
187
+ function stringifyStyleSheet(sheet) {
188
+ return sheet.cssRules
189
+ ? Array.from(sheet.cssRules)
190
+ .map((rule) => rule.cssText ? validateStringifiedCssRule(rule.cssText) : '')
191
+ .join('')
192
+ : '';
193
+ }
269
194
  function extractOrigin(url) {
270
195
  let origin = '';
271
196
  if (url.indexOf('//') > -1) {
@@ -280,8 +205,7 @@ function extractOrigin(url) {
280
205
  let canvasService;
281
206
  let canvasCtx;
282
207
  const URL_IN_CSS_REF = /url\((?:(')([^']*)'|(")(.*?)"|([^)]*))\)/gm;
283
- const URL_PROTOCOL_MATCH = /^(?:[a-z+]+:)?\/\//i;
284
- const URL_WWW_MATCH = /^www\..*/i;
208
+ const RELATIVE_PATH = /^(?!www\.|(?:http|ftp)s?:\/\/|[A-Za-z]:\\|\/\/|#).*/;
285
209
  const DATA_URI = /^(data:)([^,]*),(.*)/i;
286
210
  function absoluteToStylesheet(cssText, href) {
287
211
  return (cssText || '').replace(URL_IN_CSS_REF, (origin, quote1, path1, quote2, path2, path3) => {
@@ -290,7 +214,7 @@ function absoluteToStylesheet(cssText, href) {
290
214
  if (!filePath) {
291
215
  return origin;
292
216
  }
293
- if (URL_PROTOCOL_MATCH.test(filePath) || URL_WWW_MATCH.test(filePath)) {
217
+ if (!RELATIVE_PATH.test(filePath)) {
294
218
  return `url(${maybeQuote}${filePath}${maybeQuote})`;
295
219
  }
296
220
  if (DATA_URI.test(filePath)) {
@@ -325,7 +249,7 @@ function getAbsoluteSrcsetString(doc, attributeValue) {
325
249
  let pos = 0;
326
250
  function collectCharacters(regEx) {
327
251
  let chars;
328
- const match = regEx.exec(attributeValue.substring(pos));
252
+ let match = regEx.exec(attributeValue.substring(pos));
329
253
  if (match) {
330
254
  chars = match[0];
331
255
  pos += chars.length;
@@ -333,7 +257,7 @@ function getAbsoluteSrcsetString(doc, attributeValue) {
333
257
  }
334
258
  return '';
335
259
  }
336
- const output = [];
260
+ let output = [];
337
261
  while (true) {
338
262
  collectCharacters(SRCSET_COMMAS_OR_SPACES);
339
263
  if (pos >= attributeValue.length) {
@@ -349,7 +273,7 @@ function getAbsoluteSrcsetString(doc, attributeValue) {
349
273
  url = absoluteToDoc(doc, url);
350
274
  let inParens = false;
351
275
  while (true) {
352
- const c = attributeValue.charAt(pos);
276
+ let c = attributeValue.charAt(pos);
353
277
  if (c === '') {
354
278
  output.push((url + descriptorsStr).trim());
355
279
  break;
@@ -392,12 +316,13 @@ function getHref() {
392
316
  a.href = '';
393
317
  return a.href;
394
318
  }
395
- function transformAttribute(doc, tagName, name, value, element, maskAttributeFn) {
319
+ function transformAttribute(doc, element, _tagName, _name, value, maskAllText, unmaskTextSelector, maskTextFn) {
396
320
  if (!value) {
397
321
  return value;
398
322
  }
399
- if (name === 'src' ||
400
- (name === 'href' && !(tagName === 'use' && value[0] === '#'))) {
323
+ const name = _name.toLowerCase();
324
+ const tagName = _tagName.toLowerCase();
325
+ if (name === 'src' || name === 'href') {
401
326
  return absoluteToDoc(doc, value);
402
327
  }
403
328
  else if (name === 'xlink:href' && value[0] !== '#') {
@@ -416,113 +341,79 @@ function transformAttribute(doc, tagName, name, value, element, maskAttributeFn)
416
341
  else if (tagName === 'object' && name === 'data') {
417
342
  return absoluteToDoc(doc, value);
418
343
  }
419
- if (typeof maskAttributeFn === 'function') {
420
- return maskAttributeFn(name, value, element);
344
+ else if (maskAllText &&
345
+ _shouldMaskAttribute(element, name, tagName, unmaskTextSelector)) {
346
+ return maskTextFn ? maskTextFn(value) : defaultMaskFn(value);
421
347
  }
422
348
  return value;
423
349
  }
424
- function ignoreAttribute(tagName, name, _value) {
425
- return (tagName === 'video' || tagName === 'audio') && name === 'autoplay';
350
+ function _shouldMaskAttribute(element, attribute, tagName, unmaskTextSelector) {
351
+ if (unmaskTextSelector && element.matches(unmaskTextSelector)) {
352
+ return false;
353
+ }
354
+ return (['placeholder', 'title', 'aria-label'].indexOf(attribute) > -1 ||
355
+ (tagName === 'input' &&
356
+ attribute === 'value' &&
357
+ element.hasAttribute('type') &&
358
+ ['submit', 'button'].indexOf(element.getAttribute('type').toLowerCase()) > -1));
426
359
  }
427
360
  function _isBlockedElement(element, blockClass, blockSelector, unblockSelector) {
428
- try {
429
- if (unblockSelector && element.matches(unblockSelector)) {
430
- return false;
361
+ if (unblockSelector && element.matches(unblockSelector)) {
362
+ return false;
363
+ }
364
+ if (typeof blockClass === 'string') {
365
+ if (element.classList.contains(blockClass)) {
366
+ return true;
431
367
  }
432
- if (typeof blockClass === 'string') {
433
- if (element.classList.contains(blockClass)) {
368
+ }
369
+ else {
370
+ for (let eIndex = 0; eIndex < element.classList.length; eIndex++) {
371
+ const className = element.classList[eIndex];
372
+ if (blockClass.test(className)) {
434
373
  return true;
435
374
  }
436
375
  }
437
- else {
438
- for (let eIndex = element.classList.length; eIndex--;) {
439
- const className = element.classList[eIndex];
440
- if (blockClass.test(className)) {
441
- return true;
442
- }
443
- }
444
- }
445
- if (blockSelector) {
446
- return element.matches(blockSelector);
447
- }
448
376
  }
449
- catch (e) {
377
+ if (blockSelector) {
378
+ return element.matches(blockSelector);
450
379
  }
451
380
  return false;
452
381
  }
453
- function elementClassMatchesRegex(el, regex) {
454
- for (let eIndex = el.classList.length; eIndex--;) {
455
- const className = el.classList[eIndex];
456
- if (regex.test(className)) {
457
- return true;
458
- }
382
+ function needMaskingText(node, maskTextClass, maskTextSelector, unmaskTextSelector, maskAllText) {
383
+ if (!node) {
384
+ return false;
459
385
  }
460
- return false;
461
- }
462
- function distanceToMatch(node, matchPredicate, limit = Infinity, distance = 0) {
463
- if (!node)
464
- return -1;
465
- if (node.nodeType !== node.ELEMENT_NODE)
466
- return -1;
467
- if (distance > limit)
468
- return -1;
469
- if (matchPredicate(node))
470
- return distance;
471
- return distanceToMatch(node.parentNode, matchPredicate, limit, distance + 1);
472
- }
473
- function createMatchPredicate(className, selector) {
474
- return (node) => {
475
- const el = node;
476
- if (el === null)
386
+ if (node.nodeType !== node.ELEMENT_NODE) {
387
+ return needMaskingText(node.parentNode, maskTextClass, maskTextSelector, unmaskTextSelector, maskAllText);
388
+ }
389
+ if (unmaskTextSelector) {
390
+ if (node.matches(unmaskTextSelector) ||
391
+ node.closest(unmaskTextSelector)) {
477
392
  return false;
478
- if (className) {
479
- if (typeof className === 'string') {
480
- if (el.matches(`.${className}`))
481
- return true;
482
- }
483
- else if (elementClassMatchesRegex(el, className)) {
484
- return true;
485
- }
486
393
  }
487
- if (selector && el.matches(selector))
394
+ }
395
+ if (maskAllText) {
396
+ return true;
397
+ }
398
+ if (typeof maskTextClass === 'string') {
399
+ if (node.classList.contains(maskTextClass)) {
488
400
  return true;
489
- return false;
490
- };
491
- }
492
- function needMaskingText(node, maskTextClass, maskTextSelector, unmaskTextClass, unmaskTextSelector, maskAllText) {
493
- try {
494
- const el = node.nodeType === node.ELEMENT_NODE
495
- ? node
496
- : node.parentElement;
497
- if (el === null)
498
- return false;
499
- let maskDistance = -1;
500
- let unmaskDistance = -1;
501
- if (maskAllText) {
502
- unmaskDistance = distanceToMatch(el, createMatchPredicate(unmaskTextClass, unmaskTextSelector));
503
- if (unmaskDistance < 0) {
504
- return true;
505
- }
506
- maskDistance = distanceToMatch(el, createMatchPredicate(maskTextClass, maskTextSelector), unmaskDistance >= 0 ? unmaskDistance : Infinity);
507
401
  }
508
- else {
509
- maskDistance = distanceToMatch(el, createMatchPredicate(maskTextClass, maskTextSelector));
510
- if (maskDistance < 0) {
511
- return false;
402
+ }
403
+ else {
404
+ for (let eIndex = 0; eIndex < node.classList.length; eIndex++) {
405
+ const className = node.classList[eIndex];
406
+ if (maskTextClass.test(className)) {
407
+ return true;
512
408
  }
513
- unmaskDistance = distanceToMatch(el, createMatchPredicate(unmaskTextClass, unmaskTextSelector), maskDistance >= 0 ? maskDistance : Infinity);
514
409
  }
515
- return maskDistance >= 0
516
- ? unmaskDistance >= 0
517
- ? maskDistance <= unmaskDistance
518
- : true
519
- : unmaskDistance >= 0
520
- ? false
521
- : !!maskAllText;
522
410
  }
523
- catch (e) {
411
+ if (maskTextSelector) {
412
+ if (node.matches(maskTextSelector)) {
413
+ return true;
414
+ }
524
415
  }
525
- return !!maskAllText;
416
+ return needMaskingText(node.parentNode, maskTextClass, maskTextSelector, unmaskTextSelector, maskAllText);
526
417
  }
527
418
  function onceIframeLoaded(iframeEl, listener, iframeLoadTimeout) {
528
419
  const win = iframeEl.contentWindow;
@@ -556,36 +447,18 @@ function onceIframeLoaded(iframeEl, listener, iframeLoadTimeout) {
556
447
  iframeEl.src === blankUrl ||
557
448
  iframeEl.src === '') {
558
449
  setTimeout(listener, 0);
559
- return iframeEl.addEventListener('load', listener);
560
- }
561
- iframeEl.addEventListener('load', listener);
562
- }
563
- function onceStylesheetLoaded(link, listener, styleSheetLoadTimeout) {
564
- let fired = false;
565
- let styleSheetLoaded;
566
- try {
567
- styleSheetLoaded = link.sheet;
568
- }
569
- catch (error) {
570
450
  return;
571
451
  }
572
- if (styleSheetLoaded)
573
- return;
574
- const timer = setTimeout(() => {
575
- if (!fired) {
576
- listener();
577
- fired = true;
578
- }
579
- }, styleSheetLoadTimeout);
580
- link.addEventListener('load', () => {
581
- clearTimeout(timer);
582
- fired = true;
583
- listener();
584
- });
452
+ iframeEl.addEventListener('load', listener);
585
453
  }
586
454
  function serializeNode(n, options) {
587
- const { doc, mirror, blockClass, blockSelector, unblockSelector, maskAllText, maskAttributeFn, maskTextClass, unmaskTextClass, maskTextSelector, unmaskTextSelector, inlineStylesheet, maskInputOptions = {}, maskTextFn, maskInputFn, dataURLOptions = {}, inlineImages, recordCanvas, keepIframeSrcFn, newlyAddedElement = false, } = options;
588
- const rootId = getRootId(doc, mirror);
455
+ var _a;
456
+ const { doc, blockClass, blockSelector, unblockSelector, maskTextClass, maskTextSelector, unmaskTextSelector, inlineStylesheet, maskInputSelector, unmaskInputSelector, maskAllText, maskInputOptions = {}, maskTextFn, maskInputFn, dataURLOptions = {}, inlineImages, recordCanvas, keepIframeSrcFn, } = options;
457
+ let rootId;
458
+ if (doc.__sn) {
459
+ const docId = doc.__sn.id;
460
+ rootId = docId === 1 ? undefined : docId;
461
+ }
589
462
  switch (n.nodeType) {
590
463
  case n.DOCUMENT_NODE:
591
464
  if (n.compatMode !== 'CSS1Compat') {
@@ -593,12 +466,14 @@ function serializeNode(n, options) {
593
466
  type: NodeType$1.Document,
594
467
  childNodes: [],
595
468
  compatMode: n.compatMode,
469
+ rootId,
596
470
  };
597
471
  }
598
472
  else {
599
473
  return {
600
474
  type: NodeType$1.Document,
601
475
  childNodes: [],
476
+ rootId,
602
477
  };
603
478
  }
604
479
  case n.DOCUMENT_TYPE_NODE:
@@ -610,39 +485,202 @@ function serializeNode(n, options) {
610
485
  rootId,
611
486
  };
612
487
  case n.ELEMENT_NODE:
613
- return serializeElementNode(n, {
614
- doc,
615
- blockClass,
616
- blockSelector,
617
- unblockSelector,
618
- inlineStylesheet,
619
- maskAttributeFn,
620
- maskInputOptions,
621
- maskInputFn,
622
- dataURLOptions,
623
- inlineImages,
624
- recordCanvas,
625
- keepIframeSrcFn,
626
- newlyAddedElement,
488
+ const needBlock = _isBlockedElement(n, blockClass, blockSelector, unblockSelector);
489
+ const tagName = getValidTagName(n);
490
+ let attributes = {};
491
+ for (const { name, value } of Array.from(n.attributes)) {
492
+ if (!skipAttribute(tagName, name)) {
493
+ attributes[name] = transformAttribute(doc, n, tagName, name, value, maskAllText, unmaskTextSelector, maskTextFn);
494
+ }
495
+ }
496
+ if (tagName === 'link' && inlineStylesheet) {
497
+ const stylesheet = Array.from(doc.styleSheets).find((s) => {
498
+ return s.href === n.href;
499
+ });
500
+ let cssText = null;
501
+ if (stylesheet) {
502
+ cssText = getCssRulesString(stylesheet);
503
+ }
504
+ if (cssText) {
505
+ delete attributes.rel;
506
+ delete attributes.href;
507
+ attributes._cssText = absoluteToStylesheet(cssText, stylesheet.href);
508
+ }
509
+ }
510
+ if (tagName === 'style' &&
511
+ n.sheet &&
512
+ !(n.innerText ||
513
+ n.textContent ||
514
+ '').trim().length) {
515
+ const cssText = getCssRulesString(n.sheet);
516
+ if (cssText) {
517
+ attributes._cssText = absoluteToStylesheet(cssText, getHref());
518
+ }
519
+ }
520
+ if (tagName === 'input' ||
521
+ tagName === 'textarea' ||
522
+ tagName === 'select' ||
523
+ tagName === 'option') {
524
+ const el = n;
525
+ const type = getInputType(el);
526
+ const value = getInputValue(el, tagName.toUpperCase(), type);
527
+ const checked = n.checked;
528
+ if (type !== 'submit' &&
529
+ type !== 'button' &&
530
+ value) {
531
+ attributes.value = maskInputValue({
532
+ input: el,
533
+ type,
534
+ tagName,
535
+ value,
536
+ maskInputSelector,
537
+ unmaskInputSelector,
538
+ maskInputOptions,
539
+ maskInputFn,
540
+ });
541
+ }
542
+ if (checked) {
543
+ attributes.checked = checked;
544
+ }
545
+ }
546
+ if (tagName === 'option') {
547
+ if (n.selected && !maskInputOptions['select']) {
548
+ attributes.selected = true;
549
+ }
550
+ else {
551
+ delete attributes.selected;
552
+ }
553
+ }
554
+ if (tagName === 'canvas' && recordCanvas) {
555
+ if (n.__context === '2d') {
556
+ if (!is2DCanvasBlank(n)) {
557
+ attributes.rr_dataURL = n.toDataURL(dataURLOptions.type, dataURLOptions.quality);
558
+ }
559
+ }
560
+ else if (!('__context' in n)) {
561
+ const canvasDataURL = n.toDataURL(dataURLOptions.type, dataURLOptions.quality);
562
+ const blankCanvas = document.createElement('canvas');
563
+ blankCanvas.width = n.width;
564
+ blankCanvas.height = n.height;
565
+ const blankCanvasDataURL = blankCanvas.toDataURL(dataURLOptions.type, dataURLOptions.quality);
566
+ if (canvasDataURL !== blankCanvasDataURL) {
567
+ attributes.rr_dataURL = canvasDataURL;
568
+ }
569
+ }
570
+ }
571
+ if (tagName === 'img' && inlineImages) {
572
+ if (!canvasService) {
573
+ canvasService = doc.createElement('canvas');
574
+ canvasCtx = canvasService.getContext('2d');
575
+ }
576
+ const image = n;
577
+ const oldValue = image.crossOrigin;
578
+ image.crossOrigin = 'anonymous';
579
+ const recordInlineImage = () => {
580
+ try {
581
+ canvasService.width = image.naturalWidth;
582
+ canvasService.height = image.naturalHeight;
583
+ canvasCtx.drawImage(image, 0, 0);
584
+ attributes.rr_dataURL = canvasService.toDataURL(dataURLOptions.type, dataURLOptions.quality);
585
+ }
586
+ catch (err) {
587
+ console.warn(`Cannot inline img src=${image.currentSrc}! Error: ${err}`);
588
+ }
589
+ oldValue
590
+ ? (attributes.crossOrigin = oldValue)
591
+ : delete attributes.crossOrigin;
592
+ };
593
+ if (image.complete && image.naturalWidth !== 0)
594
+ recordInlineImage();
595
+ else
596
+ image.onload = recordInlineImage;
597
+ }
598
+ if (tagName === 'audio' || tagName === 'video') {
599
+ attributes.rr_mediaState = n.paused
600
+ ? 'paused'
601
+ : 'played';
602
+ attributes.rr_mediaCurrentTime = n.currentTime;
603
+ }
604
+ if (n.scrollLeft) {
605
+ attributes.rr_scrollLeft = n.scrollLeft;
606
+ }
607
+ if (n.scrollTop) {
608
+ attributes.rr_scrollTop = n.scrollTop;
609
+ }
610
+ if (needBlock) {
611
+ const { width, height } = n.getBoundingClientRect();
612
+ attributes = {
613
+ class: attributes.class,
614
+ rr_width: `${width}px`,
615
+ rr_height: `${height}px`,
616
+ };
617
+ }
618
+ if (tagName === 'iframe' && !keepIframeSrcFn(attributes.src)) {
619
+ if (!n.contentDocument) {
620
+ attributes.rr_src = attributes.src;
621
+ }
622
+ delete attributes.src;
623
+ }
624
+ return {
625
+ type: NodeType$1.Element,
626
+ tagName,
627
+ attributes,
628
+ childNodes: [],
629
+ isSVG: isSVGElement(n) || undefined,
630
+ needBlock,
627
631
  rootId,
628
- maskAllText,
629
- maskTextClass,
630
- unmaskTextClass,
631
- maskTextSelector,
632
- unmaskTextSelector,
633
- });
632
+ };
634
633
  case n.TEXT_NODE:
635
- return serializeTextNode(n, {
636
- maskAllText,
637
- maskTextClass,
638
- unmaskTextClass,
639
- maskTextSelector,
640
- unmaskTextSelector,
641
- maskTextFn,
642
- maskInputOptions,
643
- maskInputFn,
634
+ const parentTagName = n.parentNode && n.parentNode.tagName;
635
+ let textContent = n.textContent;
636
+ const isStyle = parentTagName === 'STYLE' ? true : undefined;
637
+ const isScript = parentTagName === 'SCRIPT' ? true : undefined;
638
+ if (isStyle && textContent) {
639
+ try {
640
+ if (n.nextSibling || n.previousSibling) {
641
+ }
642
+ else if ((_a = n.parentNode.sheet) === null || _a === void 0 ? void 0 : _a.cssRules) {
643
+ textContent = stringifyStyleSheet(n.parentNode.sheet);
644
+ }
645
+ }
646
+ catch (err) {
647
+ console.warn(`Cannot get CSS styles from text's parentNode. Error: ${err}`, n);
648
+ }
649
+ textContent = absoluteToStylesheet(textContent, getHref());
650
+ }
651
+ if (isScript) {
652
+ textContent = 'SCRIPT_PLACEHOLDER';
653
+ }
654
+ if (parentTagName === 'TEXTAREA' && textContent) {
655
+ textContent = '';
656
+ }
657
+ else if (parentTagName === 'OPTION' && textContent) {
658
+ const option = n.parentNode;
659
+ textContent = maskInputValue({
660
+ input: option,
661
+ type: null,
662
+ tagName: parentTagName,
663
+ value: textContent,
664
+ maskInputSelector,
665
+ unmaskInputSelector,
666
+ maskInputOptions,
667
+ maskInputFn,
668
+ });
669
+ }
670
+ else if (!isStyle &&
671
+ !isScript &&
672
+ needMaskingText(n, maskTextClass, maskTextSelector, unmaskTextSelector, maskAllText) &&
673
+ textContent) {
674
+ textContent = maskTextFn
675
+ ? maskTextFn(textContent)
676
+ : defaultMaskFn(textContent);
677
+ }
678
+ return {
679
+ type: NodeType$1.Text,
680
+ textContent: textContent || '',
681
+ isStyle,
644
682
  rootId,
645
- });
683
+ };
646
684
  case n.CDATA_SECTION_NODE:
647
685
  return {
648
686
  type: NodeType$1.CDATA,
@@ -659,225 +697,6 @@ function serializeNode(n, options) {
659
697
  return false;
660
698
  }
661
699
  }
662
- function getRootId(doc, mirror) {
663
- if (!mirror.hasNode(doc))
664
- return undefined;
665
- const docId = mirror.getId(doc);
666
- return docId === 1 ? undefined : docId;
667
- }
668
- function serializeTextNode(n, options) {
669
- var _a;
670
- const { maskAllText, maskTextClass, unmaskTextClass, maskTextSelector, unmaskTextSelector, maskTextFn, maskInputOptions, maskInputFn, rootId, } = options;
671
- const parentTagName = n.parentNode && n.parentNode.tagName;
672
- let textContent = n.textContent;
673
- const isStyle = parentTagName === 'STYLE' ? true : undefined;
674
- const isScript = parentTagName === 'SCRIPT' ? true : undefined;
675
- const isTextarea = parentTagName === 'TEXTAREA' ? true : undefined;
676
- if (isStyle && textContent) {
677
- try {
678
- if (n.nextSibling || n.previousSibling) {
679
- }
680
- else if ((_a = n.parentNode.sheet) === null || _a === void 0 ? void 0 : _a.cssRules) {
681
- textContent = stringifyStylesheet(n.parentNode.sheet);
682
- }
683
- }
684
- catch (err) {
685
- console.warn(`Cannot get CSS styles from text's parentNode. Error: ${err}`, n);
686
- }
687
- textContent = absoluteToStylesheet(textContent, getHref());
688
- }
689
- if (isScript) {
690
- textContent = 'SCRIPT_PLACEHOLDER';
691
- }
692
- const forceMask = needMaskingText(n, maskTextClass, maskTextSelector, unmaskTextClass, unmaskTextSelector, maskAllText);
693
- if (!isStyle && !isScript && !isTextarea && textContent && forceMask) {
694
- textContent = maskTextFn
695
- ? maskTextFn(textContent)
696
- : textContent.replace(/[\S]/g, '*');
697
- }
698
- if (isTextarea && textContent && (maskInputOptions.textarea || forceMask)) {
699
- textContent = maskInputFn
700
- ? maskInputFn(textContent, n.parentNode)
701
- : textContent.replace(/[\S]/g, '*');
702
- }
703
- if (parentTagName === 'OPTION' && textContent) {
704
- const isInputMasked = shouldMaskInput({
705
- type: null,
706
- tagName: parentTagName,
707
- maskInputOptions,
708
- });
709
- textContent = maskInputValue({
710
- isMasked: needMaskingText(n, maskTextClass, maskTextSelector, unmaskTextClass, unmaskTextSelector, isInputMasked),
711
- element: n,
712
- value: textContent,
713
- maskInputFn,
714
- });
715
- }
716
- return {
717
- type: NodeType$1.Text,
718
- textContent: textContent || '',
719
- isStyle,
720
- rootId,
721
- };
722
- }
723
- function serializeElementNode(n, options) {
724
- const { doc, blockClass, blockSelector, unblockSelector, inlineStylesheet, maskInputOptions = {}, maskAttributeFn, maskInputFn, dataURLOptions = {}, inlineImages, recordCanvas, keepIframeSrcFn, newlyAddedElement = false, rootId, maskAllText, maskTextClass, unmaskTextClass, maskTextSelector, unmaskTextSelector, } = options;
725
- const needBlock = _isBlockedElement(n, blockClass, blockSelector, unblockSelector);
726
- const tagName = getValidTagName(n);
727
- let attributes = {};
728
- const len = n.attributes.length;
729
- for (let i = 0; i < len; i++) {
730
- const attr = n.attributes[i];
731
- if (!ignoreAttribute(tagName, attr.name, attr.value)) {
732
- attributes[attr.name] = transformAttribute(doc, tagName, toLowerCase(attr.name), attr.value, n, maskAttributeFn);
733
- }
734
- }
735
- if (tagName === 'link' && inlineStylesheet) {
736
- const stylesheet = Array.from(doc.styleSheets).find((s) => {
737
- return s.href === n.href;
738
- });
739
- let cssText = null;
740
- if (stylesheet) {
741
- cssText = stringifyStylesheet(stylesheet);
742
- }
743
- if (cssText) {
744
- delete attributes.rel;
745
- delete attributes.href;
746
- attributes._cssText = absoluteToStylesheet(cssText, stylesheet.href);
747
- }
748
- }
749
- if (tagName === 'style' &&
750
- n.sheet &&
751
- !(n.innerText || n.textContent || '').trim().length) {
752
- const cssText = stringifyStylesheet(n.sheet);
753
- if (cssText) {
754
- attributes._cssText = absoluteToStylesheet(cssText, getHref());
755
- }
756
- }
757
- if (tagName === 'input' ||
758
- tagName === 'textarea' ||
759
- tagName === 'select' ||
760
- tagName === 'option') {
761
- const el = n;
762
- const type = getInputType(el);
763
- const value = getInputValue(el, toUpperCase(tagName), type);
764
- const checked = el.checked;
765
- if (type !== 'submit' && type !== 'button' && value) {
766
- const forceMask = needMaskingText(el, maskTextClass, maskTextSelector, unmaskTextClass, unmaskTextSelector, shouldMaskInput({
767
- type,
768
- tagName: toUpperCase(tagName),
769
- maskInputOptions,
770
- }));
771
- attributes.value = maskInputValue({
772
- isMasked: forceMask,
773
- element: el,
774
- value,
775
- maskInputFn,
776
- });
777
- }
778
- if (checked) {
779
- attributes.checked = checked;
780
- }
781
- }
782
- if (tagName === 'option') {
783
- if (n.selected && !maskInputOptions['select']) {
784
- attributes.selected = true;
785
- }
786
- else {
787
- delete attributes.selected;
788
- }
789
- }
790
- if (tagName === 'canvas' && recordCanvas) {
791
- if (n.__context === '2d') {
792
- if (!is2DCanvasBlank(n)) {
793
- attributes.rr_dataURL = n.toDataURL(dataURLOptions.type, dataURLOptions.quality);
794
- }
795
- }
796
- else if (!('__context' in n)) {
797
- const canvasDataURL = n.toDataURL(dataURLOptions.type, dataURLOptions.quality);
798
- const blankCanvas = document.createElement('canvas');
799
- blankCanvas.width = n.width;
800
- blankCanvas.height = n.height;
801
- const blankCanvasDataURL = blankCanvas.toDataURL(dataURLOptions.type, dataURLOptions.quality);
802
- if (canvasDataURL !== blankCanvasDataURL) {
803
- attributes.rr_dataURL = canvasDataURL;
804
- }
805
- }
806
- }
807
- if (tagName === 'img' && inlineImages) {
808
- if (!canvasService) {
809
- canvasService = doc.createElement('canvas');
810
- canvasCtx = canvasService.getContext('2d');
811
- }
812
- const image = n;
813
- const oldValue = image.crossOrigin;
814
- image.crossOrigin = 'anonymous';
815
- const recordInlineImage = () => {
816
- image.removeEventListener('load', recordInlineImage);
817
- try {
818
- canvasService.width = image.naturalWidth;
819
- canvasService.height = image.naturalHeight;
820
- canvasCtx.drawImage(image, 0, 0);
821
- attributes.rr_dataURL = canvasService.toDataURL(dataURLOptions.type, dataURLOptions.quality);
822
- }
823
- catch (err) {
824
- console.warn(`Cannot inline img src=${image.currentSrc}! Error: ${err}`);
825
- }
826
- oldValue
827
- ? (attributes.crossOrigin = oldValue)
828
- : image.removeAttribute('crossorigin');
829
- };
830
- if (image.complete && image.naturalWidth !== 0)
831
- recordInlineImage();
832
- else
833
- image.addEventListener('load', recordInlineImage);
834
- }
835
- if (tagName === 'audio' || tagName === 'video') {
836
- attributes.rr_mediaState = n.paused
837
- ? 'paused'
838
- : 'played';
839
- attributes.rr_mediaCurrentTime = n.currentTime;
840
- }
841
- if (!newlyAddedElement) {
842
- if (n.scrollLeft) {
843
- attributes.rr_scrollLeft = n.scrollLeft;
844
- }
845
- if (n.scrollTop) {
846
- attributes.rr_scrollTop = n.scrollTop;
847
- }
848
- }
849
- if (needBlock) {
850
- const { width, height } = n.getBoundingClientRect();
851
- attributes = {
852
- class: attributes.class,
853
- rr_width: `${width}px`,
854
- rr_height: `${height}px`,
855
- };
856
- }
857
- if (tagName === 'iframe' && !keepIframeSrcFn(attributes.src)) {
858
- if (!n.contentDocument) {
859
- attributes.rr_src = attributes.src;
860
- }
861
- delete attributes.src;
862
- }
863
- let isCustomElement;
864
- try {
865
- if (customElements.get(tagName))
866
- isCustomElement = true;
867
- }
868
- catch (e) {
869
- }
870
- return {
871
- type: NodeType$1.Element,
872
- tagName,
873
- attributes,
874
- childNodes: [],
875
- isSVG: isSVGElement(n) || undefined,
876
- needBlock,
877
- rootId,
878
- isCustom: isCustomElement,
879
- };
880
- }
881
700
  function lowerIfExists(maybeAttr) {
882
701
  if (maybeAttr === undefined || maybeAttr === null) {
883
702
  return '';
@@ -959,37 +778,35 @@ function slimDOMExcluded(sn, slimDOMOptions) {
959
778
  return false;
960
779
  }
961
780
  function serializeNodeWithId(n, options) {
962
- const { doc, mirror, blockClass, blockSelector, unblockSelector, maskAllText, maskTextClass, unmaskTextClass, maskTextSelector, unmaskTextSelector, skipChild = false, inlineStylesheet = true, maskInputOptions = {}, maskAttributeFn, maskTextFn, maskInputFn, slimDOMOptions, dataURLOptions = {}, inlineImages = false, recordCanvas = false, onSerialize, onIframeLoad, iframeLoadTimeout = 5000, onStylesheetLoad, stylesheetLoadTimeout = 5000, keepIframeSrcFn = () => false, newlyAddedElement = false, } = options;
781
+ const { doc, map, blockClass, blockSelector, unblockSelector, maskTextClass, maskTextSelector, unmaskTextSelector, skipChild = false, inlineStylesheet = true, maskInputSelector, unmaskInputSelector, maskAllText, maskInputOptions = {}, maskTextFn, maskInputFn, slimDOMOptions, dataURLOptions = {}, inlineImages = false, recordCanvas = false, onSerialize, onIframeLoad, iframeLoadTimeout = 5000, keepIframeSrcFn = () => false, } = options;
963
782
  let { preserveWhiteSpace = true } = options;
964
783
  const _serializedNode = serializeNode(n, {
965
784
  doc,
966
- mirror,
967
785
  blockClass,
968
786
  blockSelector,
969
- maskAllText,
970
787
  unblockSelector,
971
788
  maskTextClass,
972
- unmaskTextClass,
973
789
  maskTextSelector,
974
790
  unmaskTextSelector,
975
791
  inlineStylesheet,
792
+ maskInputSelector,
793
+ unmaskInputSelector,
794
+ maskAllText,
976
795
  maskInputOptions,
977
- maskAttributeFn,
978
796
  maskTextFn,
979
797
  maskInputFn,
980
798
  dataURLOptions,
981
799
  inlineImages,
982
800
  recordCanvas,
983
801
  keepIframeSrcFn,
984
- newlyAddedElement,
985
802
  });
986
803
  if (!_serializedNode) {
987
804
  console.warn(n, 'not serialized');
988
805
  return null;
989
806
  }
990
807
  let id;
991
- if (mirror.hasNode(n)) {
992
- id = mirror.getId(n);
808
+ if ('__sn' in n) {
809
+ id = n.__sn.id;
993
810
  }
994
811
  else if (slimDOMExcluded(_serializedNode, slimDOMOptions) ||
995
812
  (!preserveWhiteSpace &&
@@ -1002,10 +819,11 @@ function serializeNodeWithId(n, options) {
1002
819
  id = genId();
1003
820
  }
1004
821
  const serializedNode = Object.assign(_serializedNode, { id });
1005
- mirror.add(n, serializedNode);
822
+ n.__sn = serializedNode;
1006
823
  if (id === IGNORED_NODE) {
1007
824
  return null;
1008
825
  }
826
+ map[id] = n;
1009
827
  if (onSerialize) {
1010
828
  onSerialize(n);
1011
829
  }
@@ -1013,33 +831,32 @@ function serializeNodeWithId(n, options) {
1013
831
  if (serializedNode.type === NodeType$1.Element) {
1014
832
  recordChild = recordChild && !serializedNode.needBlock;
1015
833
  delete serializedNode.needBlock;
1016
- const shadowRoot = n.shadowRoot;
1017
- if (shadowRoot && isNativeShadowDom(shadowRoot))
834
+ if (n.shadowRoot)
1018
835
  serializedNode.isShadowHost = true;
1019
836
  }
1020
837
  if ((serializedNode.type === NodeType$1.Document ||
1021
838
  serializedNode.type === NodeType$1.Element) &&
1022
839
  recordChild) {
1023
840
  if (slimDOMOptions.headWhitespace &&
1024
- serializedNode.type === NodeType$1.Element &&
1025
- serializedNode.tagName === 'head') {
841
+ _serializedNode.type === NodeType$1.Element &&
842
+ _serializedNode.tagName === 'head') {
1026
843
  preserveWhiteSpace = false;
1027
844
  }
1028
845
  const bypassOptions = {
1029
846
  doc,
1030
- mirror,
847
+ map,
1031
848
  blockClass,
1032
849
  blockSelector,
1033
- maskAllText,
1034
850
  unblockSelector,
1035
851
  maskTextClass,
1036
- unmaskTextClass,
1037
852
  maskTextSelector,
1038
853
  unmaskTextSelector,
1039
854
  skipChild,
1040
855
  inlineStylesheet,
856
+ maskInputSelector,
857
+ unmaskInputSelector,
858
+ maskAllText,
1041
859
  maskInputOptions,
1042
- maskAttributeFn,
1043
860
  maskTextFn,
1044
861
  maskInputFn,
1045
862
  slimDOMOptions,
@@ -1050,8 +867,6 @@ function serializeNodeWithId(n, options) {
1050
867
  onSerialize,
1051
868
  onIframeLoad,
1052
869
  iframeLoadTimeout,
1053
- onStylesheetLoad,
1054
- stylesheetLoadTimeout,
1055
870
  keepIframeSrcFn,
1056
871
  };
1057
872
  for (const childN of Array.from(n.childNodes)) {
@@ -1060,20 +875,17 @@ function serializeNodeWithId(n, options) {
1060
875
  serializedNode.childNodes.push(serializedChildNode);
1061
876
  }
1062
877
  }
1063
- if (isElement$1(n) && n.shadowRoot) {
878
+ if (isElement(n) && n.shadowRoot) {
1064
879
  for (const childN of Array.from(n.shadowRoot.childNodes)) {
1065
880
  const serializedChildNode = serializeNodeWithId(childN, bypassOptions);
1066
881
  if (serializedChildNode) {
1067
- isNativeShadowDom(n.shadowRoot) &&
1068
- (serializedChildNode.isShadow = true);
882
+ serializedChildNode.isShadow = true;
1069
883
  serializedNode.childNodes.push(serializedChildNode);
1070
884
  }
1071
885
  }
1072
886
  }
1073
887
  }
1074
- if (n.parentNode &&
1075
- isShadowRoot(n.parentNode) &&
1076
- isNativeShadowDom(n.parentNode)) {
888
+ if (n.parentNode && isShadowRoot(n.parentNode)) {
1077
889
  serializedNode.isShadow = true;
1078
890
  }
1079
891
  if (serializedNode.type === NodeType$1.Element &&
@@ -1083,19 +895,19 @@ function serializeNodeWithId(n, options) {
1083
895
  if (iframeDoc && onIframeLoad) {
1084
896
  const serializedIframeNode = serializeNodeWithId(iframeDoc, {
1085
897
  doc: iframeDoc,
1086
- mirror,
898
+ map,
1087
899
  blockClass,
1088
900
  blockSelector,
1089
901
  unblockSelector,
1090
- maskAllText,
1091
902
  maskTextClass,
1092
- unmaskTextClass,
1093
903
  maskTextSelector,
1094
904
  unmaskTextSelector,
1095
905
  skipChild: false,
1096
906
  inlineStylesheet,
907
+ maskInputSelector,
908
+ unmaskInputSelector,
909
+ maskAllText,
1097
910
  maskInputOptions,
1098
- maskAttributeFn,
1099
911
  maskTextFn,
1100
912
  maskInputFn,
1101
913
  slimDOMOptions,
@@ -1106,8 +918,6 @@ function serializeNodeWithId(n, options) {
1106
918
  onSerialize,
1107
919
  onIframeLoad,
1108
920
  iframeLoadTimeout,
1109
- onStylesheetLoad,
1110
- stylesheetLoadTimeout,
1111
921
  keepIframeSrcFn,
1112
922
  });
1113
923
  if (serializedIframeNode) {
@@ -1116,50 +926,11 @@ function serializeNodeWithId(n, options) {
1116
926
  }
1117
927
  }, iframeLoadTimeout);
1118
928
  }
1119
- if (serializedNode.type === NodeType$1.Element &&
1120
- serializedNode.tagName === 'link' &&
1121
- serializedNode.attributes.rel === 'stylesheet') {
1122
- onceStylesheetLoaded(n, () => {
1123
- if (onStylesheetLoad) {
1124
- const serializedLinkNode = serializeNodeWithId(n, {
1125
- doc,
1126
- mirror,
1127
- blockClass,
1128
- blockSelector,
1129
- unblockSelector,
1130
- maskAllText,
1131
- maskTextClass,
1132
- unmaskTextClass,
1133
- maskTextSelector,
1134
- unmaskTextSelector,
1135
- skipChild: false,
1136
- inlineStylesheet,
1137
- maskInputOptions,
1138
- maskAttributeFn,
1139
- maskTextFn,
1140
- maskInputFn,
1141
- slimDOMOptions,
1142
- dataURLOptions,
1143
- inlineImages,
1144
- recordCanvas,
1145
- preserveWhiteSpace,
1146
- onSerialize,
1147
- onIframeLoad,
1148
- iframeLoadTimeout,
1149
- onStylesheetLoad,
1150
- stylesheetLoadTimeout,
1151
- keepIframeSrcFn,
1152
- });
1153
- if (serializedLinkNode) {
1154
- onStylesheetLoad(n, serializedLinkNode);
1155
- }
1156
- }
1157
- }, stylesheetLoadTimeout);
1158
- }
1159
929
  return serializedNode;
1160
930
  }
1161
931
  function snapshot(n, options) {
1162
- const { mirror = new Mirror(), blockClass = 'rr-block', blockSelector = null, unblockSelector = null, maskAllText = false, maskTextClass = 'rr-mask', unmaskTextClass = null, maskTextSelector = null, unmaskTextSelector = null, inlineStylesheet = true, inlineImages = false, recordCanvas = false, maskAllInputs = false, maskAttributeFn, maskTextFn, maskInputFn, slimDOM = false, dataURLOptions, preserveWhiteSpace, onSerialize, onIframeLoad, iframeLoadTimeout, onStylesheetLoad, stylesheetLoadTimeout, keepIframeSrcFn = () => false, } = options || {};
932
+ const { blockClass = 'rr-block', blockSelector = null, unblockSelector = null, maskTextClass = 'rr-mask', maskTextSelector = null, unmaskTextSelector = null, inlineStylesheet = true, inlineImages = false, recordCanvas = false, maskInputSelector = null, unmaskInputSelector = null, maskAllText = false, maskAllInputs = false, maskTextFn, maskInputFn, slimDOM = false, dataURLOptions, preserveWhiteSpace, onSerialize, onIframeLoad, iframeLoadTimeout, keepIframeSrcFn = () => false, } = options || {};
933
+ const idNodeMap = {};
1163
934
  const maskInputOptions = maskAllInputs === true
1164
935
  ? {
1165
936
  color: true,
@@ -1198,43 +969,147 @@ function snapshot(n, options) {
1198
969
  : slimDOM === false
1199
970
  ? {}
1200
971
  : slimDOM;
1201
- return serializeNodeWithId(n, {
1202
- doc: n,
1203
- mirror,
1204
- blockClass,
1205
- blockSelector,
1206
- unblockSelector,
1207
- maskAllText,
1208
- maskTextClass,
1209
- unmaskTextClass,
1210
- maskTextSelector,
1211
- unmaskTextSelector,
1212
- skipChild: false,
1213
- inlineStylesheet,
1214
- maskInputOptions,
1215
- maskAttributeFn,
1216
- maskTextFn,
1217
- maskInputFn,
1218
- slimDOMOptions,
1219
- dataURLOptions,
1220
- inlineImages,
1221
- recordCanvas,
1222
- preserveWhiteSpace,
1223
- onSerialize,
1224
- onIframeLoad,
1225
- iframeLoadTimeout,
1226
- onStylesheetLoad,
1227
- stylesheetLoadTimeout,
1228
- keepIframeSrcFn,
1229
- newlyAddedElement: false,
1230
- });
972
+ return [
973
+ serializeNodeWithId(n, {
974
+ doc: n,
975
+ map: idNodeMap,
976
+ blockClass,
977
+ blockSelector,
978
+ unblockSelector,
979
+ maskTextClass,
980
+ maskTextSelector,
981
+ unmaskTextSelector,
982
+ skipChild: false,
983
+ inlineStylesheet,
984
+ maskInputSelector,
985
+ unmaskInputSelector,
986
+ maskAllText,
987
+ maskInputOptions,
988
+ maskTextFn,
989
+ maskInputFn,
990
+ slimDOMOptions,
991
+ dataURLOptions,
992
+ inlineImages,
993
+ recordCanvas,
994
+ preserveWhiteSpace,
995
+ onSerialize,
996
+ onIframeLoad,
997
+ iframeLoadTimeout,
998
+ keepIframeSrcFn,
999
+ }),
1000
+ idNodeMap,
1001
+ ];
1231
1002
  }
1003
+ function skipAttribute(tagName, attributeName, value) {
1004
+ return ((tagName === 'video' || tagName === 'audio') && attributeName === 'autoplay');
1005
+ }
1006
+
1007
+ var EventType;
1008
+ (function (EventType) {
1009
+ EventType[EventType["DomContentLoaded"] = 0] = "DomContentLoaded";
1010
+ EventType[EventType["Load"] = 1] = "Load";
1011
+ EventType[EventType["FullSnapshot"] = 2] = "FullSnapshot";
1012
+ EventType[EventType["IncrementalSnapshot"] = 3] = "IncrementalSnapshot";
1013
+ EventType[EventType["Meta"] = 4] = "Meta";
1014
+ EventType[EventType["Custom"] = 5] = "Custom";
1015
+ EventType[EventType["Plugin"] = 6] = "Plugin";
1016
+ })(EventType || (EventType = {}));
1017
+ var IncrementalSource;
1018
+ (function (IncrementalSource) {
1019
+ IncrementalSource[IncrementalSource["Mutation"] = 0] = "Mutation";
1020
+ IncrementalSource[IncrementalSource["MouseMove"] = 1] = "MouseMove";
1021
+ IncrementalSource[IncrementalSource["MouseInteraction"] = 2] = "MouseInteraction";
1022
+ IncrementalSource[IncrementalSource["Scroll"] = 3] = "Scroll";
1023
+ IncrementalSource[IncrementalSource["ViewportResize"] = 4] = "ViewportResize";
1024
+ IncrementalSource[IncrementalSource["Input"] = 5] = "Input";
1025
+ IncrementalSource[IncrementalSource["TouchMove"] = 6] = "TouchMove";
1026
+ IncrementalSource[IncrementalSource["MediaInteraction"] = 7] = "MediaInteraction";
1027
+ IncrementalSource[IncrementalSource["StyleSheetRule"] = 8] = "StyleSheetRule";
1028
+ IncrementalSource[IncrementalSource["CanvasMutation"] = 9] = "CanvasMutation";
1029
+ IncrementalSource[IncrementalSource["Font"] = 10] = "Font";
1030
+ IncrementalSource[IncrementalSource["Log"] = 11] = "Log";
1031
+ IncrementalSource[IncrementalSource["Drag"] = 12] = "Drag";
1032
+ IncrementalSource[IncrementalSource["StyleDeclaration"] = 13] = "StyleDeclaration";
1033
+ })(IncrementalSource || (IncrementalSource = {}));
1034
+ var MouseInteractions;
1035
+ (function (MouseInteractions) {
1036
+ MouseInteractions[MouseInteractions["MouseUp"] = 0] = "MouseUp";
1037
+ MouseInteractions[MouseInteractions["MouseDown"] = 1] = "MouseDown";
1038
+ MouseInteractions[MouseInteractions["Click"] = 2] = "Click";
1039
+ MouseInteractions[MouseInteractions["ContextMenu"] = 3] = "ContextMenu";
1040
+ MouseInteractions[MouseInteractions["DblClick"] = 4] = "DblClick";
1041
+ MouseInteractions[MouseInteractions["Focus"] = 5] = "Focus";
1042
+ MouseInteractions[MouseInteractions["Blur"] = 6] = "Blur";
1043
+ MouseInteractions[MouseInteractions["TouchStart"] = 7] = "TouchStart";
1044
+ MouseInteractions[MouseInteractions["TouchMove_Departed"] = 8] = "TouchMove_Departed";
1045
+ MouseInteractions[MouseInteractions["TouchEnd"] = 9] = "TouchEnd";
1046
+ MouseInteractions[MouseInteractions["TouchCancel"] = 10] = "TouchCancel";
1047
+ })(MouseInteractions || (MouseInteractions = {}));
1048
+ var CanvasContext;
1049
+ (function (CanvasContext) {
1050
+ CanvasContext[CanvasContext["2D"] = 0] = "2D";
1051
+ CanvasContext[CanvasContext["WebGL"] = 1] = "WebGL";
1052
+ CanvasContext[CanvasContext["WebGL2"] = 2] = "WebGL2";
1053
+ })(CanvasContext || (CanvasContext = {}));
1054
+ var MediaInteractions;
1055
+ (function (MediaInteractions) {
1056
+ MediaInteractions[MediaInteractions["Play"] = 0] = "Play";
1057
+ MediaInteractions[MediaInteractions["Pause"] = 1] = "Pause";
1058
+ MediaInteractions[MediaInteractions["Seeked"] = 2] = "Seeked";
1059
+ MediaInteractions[MediaInteractions["VolumeChange"] = 3] = "VolumeChange";
1060
+ })(MediaInteractions || (MediaInteractions = {}));
1061
+ var ReplayerEvents;
1062
+ (function (ReplayerEvents) {
1063
+ ReplayerEvents["Start"] = "start";
1064
+ ReplayerEvents["Pause"] = "pause";
1065
+ ReplayerEvents["Resume"] = "resume";
1066
+ ReplayerEvents["Resize"] = "resize";
1067
+ ReplayerEvents["Finish"] = "finish";
1068
+ ReplayerEvents["FullsnapshotRebuilded"] = "fullsnapshot-rebuilded";
1069
+ ReplayerEvents["LoadStylesheetStart"] = "load-stylesheet-start";
1070
+ ReplayerEvents["LoadStylesheetEnd"] = "load-stylesheet-end";
1071
+ ReplayerEvents["SkipStart"] = "skip-start";
1072
+ ReplayerEvents["SkipEnd"] = "skip-end";
1073
+ ReplayerEvents["MouseInteraction"] = "mouse-interaction";
1074
+ ReplayerEvents["EventCast"] = "event-cast";
1075
+ ReplayerEvents["CustomEvent"] = "custom-event";
1076
+ ReplayerEvents["Flush"] = "flush";
1077
+ ReplayerEvents["StateChange"] = "state-change";
1078
+ ReplayerEvents["PlayBack"] = "play-back";
1079
+ })(ReplayerEvents || (ReplayerEvents = {}));
1232
1080
 
1233
1081
  function on(type, fn, target = document) {
1234
1082
  const options = { capture: true, passive: true };
1235
1083
  target.addEventListener(type, fn, options);
1236
1084
  return () => target.removeEventListener(type, fn, options);
1237
1085
  }
1086
+ function createMirror() {
1087
+ return {
1088
+ map: {},
1089
+ getId(n) {
1090
+ if (!n || !n.__sn) {
1091
+ return -1;
1092
+ }
1093
+ return n.__sn.id;
1094
+ },
1095
+ getNode(id) {
1096
+ return this.map[id] || null;
1097
+ },
1098
+ removeNodeFromMap(n) {
1099
+ const id = n.__sn && n.__sn.id;
1100
+ delete this.map[id];
1101
+ if (n.childNodes) {
1102
+ n.childNodes.forEach((child) => this.removeNodeFromMap(child));
1103
+ }
1104
+ },
1105
+ has(id) {
1106
+ return this.map.hasOwnProperty(id);
1107
+ },
1108
+ reset() {
1109
+ this.map = {};
1110
+ },
1111
+ };
1112
+ }
1238
1113
  const DEPARTED_MIRROR_ACCESS_WARNING = 'Please stop import mirror directly. Instead of that,' +
1239
1114
  '\r\n' +
1240
1115
  'now you can use replayer.getMirror() to access the mirror instance of a replayer,' +
@@ -1274,13 +1149,14 @@ if (typeof window !== 'undefined' && window.Proxy && window.Reflect) {
1274
1149
  function throttle$1(func, wait, options = {}) {
1275
1150
  let timeout = null;
1276
1151
  let previous = 0;
1277
- return function (...args) {
1278
- const now = Date.now();
1152
+ return function (arg) {
1153
+ let now = Date.now();
1279
1154
  if (!previous && options.leading === false) {
1280
1155
  previous = now;
1281
1156
  }
1282
- const remaining = wait - (now - previous);
1283
- const context = this;
1157
+ let remaining = wait - (now - previous);
1158
+ let context = this;
1159
+ let args = arguments;
1284
1160
  if (remaining <= 0 || remaining > wait) {
1285
1161
  if (timeout) {
1286
1162
  clearTimeout(timeout);
@@ -1317,8 +1193,7 @@ function hookSetter(target, key, d, isRevoked, win = window) {
1317
1193
  function patch(source, name, replacement) {
1318
1194
  try {
1319
1195
  if (!(name in source)) {
1320
- return () => {
1321
- };
1196
+ return () => { };
1322
1197
  }
1323
1198
  const original = source[name];
1324
1199
  const wrapped = replacement(original);
@@ -1337,36 +1212,9 @@ function patch(source, name, replacement) {
1337
1212
  };
1338
1213
  }
1339
1214
  catch (_a) {
1340
- return () => {
1341
- };
1215
+ return () => { };
1342
1216
  }
1343
1217
  }
1344
- let nowTimestamp = Date.now;
1345
- if (!(/[1-9][0-9]{12}/.test(Date.now().toString()))) {
1346
- nowTimestamp = () => new Date().getTime();
1347
- }
1348
- function getWindowScroll(win) {
1349
- var _a, _b, _c, _d, _e, _f;
1350
- const doc = win.document;
1351
- return {
1352
- left: doc.scrollingElement
1353
- ? doc.scrollingElement.scrollLeft
1354
- : win.pageXOffset !== undefined
1355
- ? win.pageXOffset
1356
- : (doc === null || doc === void 0 ? void 0 : doc.documentElement.scrollLeft) ||
1357
- ((_b = (_a = doc === null || doc === void 0 ? void 0 : doc.body) === null || _a === void 0 ? void 0 : _a.parentElement) === null || _b === void 0 ? void 0 : _b.scrollLeft) ||
1358
- ((_c = doc === null || doc === void 0 ? void 0 : doc.body) === null || _c === void 0 ? void 0 : _c.scrollLeft) ||
1359
- 0,
1360
- top: doc.scrollingElement
1361
- ? doc.scrollingElement.scrollTop
1362
- : win.pageYOffset !== undefined
1363
- ? win.pageYOffset
1364
- : (doc === null || doc === void 0 ? void 0 : doc.documentElement.scrollTop) ||
1365
- ((_e = (_d = doc === null || doc === void 0 ? void 0 : doc.body) === null || _d === void 0 ? void 0 : _d.parentElement) === null || _e === void 0 ? void 0 : _e.scrollTop) ||
1366
- ((_f = doc === null || doc === void 0 ? void 0 : doc.body) === null || _f === void 0 ? void 0 : _f.scrollTop) ||
1367
- 0,
1368
- };
1369
- }
1370
1218
  function getWindowHeight() {
1371
1219
  return (window.innerHeight ||
1372
1220
  (document.documentElement && document.documentElement.clientHeight) ||
@@ -1377,38 +1225,48 @@ function getWindowWidth() {
1377
1225
  (document.documentElement && document.documentElement.clientWidth) ||
1378
1226
  (document.body && document.body.clientWidth));
1379
1227
  }
1380
- function isBlocked(node, blockClass, blockSelector, unblockSelector, checkAncestors) {
1228
+ function isBlocked(node, blockClass, blockSelector, unblockSelector) {
1381
1229
  if (!node) {
1382
1230
  return false;
1383
1231
  }
1384
- const el = node.nodeType === node.ELEMENT_NODE
1385
- ? node
1386
- : node.parentElement;
1387
- if (!el)
1388
- return false;
1389
- const blockedPredicate = createMatchPredicate(blockClass, blockSelector);
1390
- if (!checkAncestors) {
1391
- const isUnblocked = unblockSelector && el.matches(unblockSelector);
1392
- return blockedPredicate(el) && !isUnblocked;
1393
- }
1394
- const blockDistance = distanceToMatch(el, blockedPredicate);
1395
- let unblockDistance = -1;
1396
- if (blockDistance < 0) {
1397
- return false;
1398
- }
1399
- if (unblockSelector) {
1400
- unblockDistance = distanceToMatch(el, createMatchPredicate(null, unblockSelector));
1232
+ if (node.nodeType === node.ELEMENT_NODE) {
1233
+ let needBlock = false;
1234
+ const needUnblock = unblockSelector && node.matches(unblockSelector);
1235
+ if (typeof blockClass === 'string') {
1236
+ if (node.closest !== undefined) {
1237
+ needBlock =
1238
+ !needUnblock &&
1239
+ node.closest('.' + blockClass) !== null;
1240
+ }
1241
+ else {
1242
+ needBlock =
1243
+ !needUnblock && node.classList.contains(blockClass);
1244
+ }
1245
+ }
1246
+ else {
1247
+ !needUnblock &&
1248
+ node.classList.forEach((className) => {
1249
+ if (blockClass.test(className)) {
1250
+ needBlock = true;
1251
+ }
1252
+ });
1253
+ }
1254
+ if (!needBlock && blockSelector) {
1255
+ needBlock = node.matches(blockSelector);
1256
+ }
1257
+ return ((!needUnblock && needBlock) ||
1258
+ isBlocked(node.parentNode, blockClass, blockSelector, unblockSelector));
1401
1259
  }
1402
- if (blockDistance > -1 && unblockDistance < 0) {
1403
- return true;
1260
+ if (node.nodeType === node.TEXT_NODE) {
1261
+ return isBlocked(node.parentNode, blockClass, blockSelector, unblockSelector);
1404
1262
  }
1405
- return blockDistance < unblockDistance;
1406
- }
1407
- function isSerialized(n, mirror) {
1408
- return mirror.getId(n) !== -1;
1263
+ return isBlocked(node.parentNode, blockClass, blockSelector, unblockSelector);
1409
1264
  }
1410
- function isIgnored(n, mirror) {
1411
- return mirror.getId(n) === IGNORED_NODE;
1265
+ function isIgnored(n) {
1266
+ if ('__sn' in n) {
1267
+ return n.__sn.id === IGNORED_NODE;
1268
+ }
1269
+ return false;
1412
1270
  }
1413
1271
  function isAncestorRemoved(target, mirror) {
1414
1272
  if (isShadowRoot(target)) {
@@ -1427,7 +1285,7 @@ function isAncestorRemoved(target, mirror) {
1427
1285
  }
1428
1286
  return isAncestorRemoved(target.parentNode, mirror);
1429
1287
  }
1430
- function legacy_isTouchEvent(event) {
1288
+ function isTouchEvent(event) {
1431
1289
  return Boolean(event.changedTouches);
1432
1290
  }
1433
1291
  function polyfill(win = window) {
@@ -1440,9 +1298,8 @@ function polyfill(win = window) {
1440
1298
  .forEach;
1441
1299
  }
1442
1300
  if (!Node.prototype.contains) {
1443
- Node.prototype.contains = (...args) => {
1444
- let node = args[0];
1445
- if (!(0 in args)) {
1301
+ Node.prototype.contains = function contains(node) {
1302
+ if (!(0 in arguments)) {
1446
1303
  throw new TypeError('1 argument is required');
1447
1304
  }
1448
1305
  do {
@@ -1454,142 +1311,15 @@ function polyfill(win = window) {
1454
1311
  };
1455
1312
  }
1456
1313
  }
1457
- function isSerializedIframe(n, mirror) {
1458
- return Boolean(n.nodeName === 'IFRAME' && mirror.getMeta(n));
1459
- }
1460
- function isSerializedStylesheet(n, mirror) {
1461
- return Boolean(n.nodeName === 'LINK' &&
1462
- n.nodeType === n.ELEMENT_NODE &&
1463
- n.getAttribute &&
1464
- n.getAttribute('rel') === 'stylesheet' &&
1465
- mirror.getMeta(n));
1314
+ function isIframeINode(node) {
1315
+ if ('__sn' in node) {
1316
+ return (node.__sn.type === NodeType$1.Element && node.__sn.tagName === 'iframe');
1317
+ }
1318
+ return false;
1466
1319
  }
1467
1320
  function hasShadowRoot(n) {
1468
1321
  return Boolean(n === null || n === void 0 ? void 0 : n.shadowRoot);
1469
1322
  }
1470
- class StyleSheetMirror {
1471
- constructor() {
1472
- this.id = 1;
1473
- this.styleIDMap = new WeakMap();
1474
- this.idStyleMap = new Map();
1475
- }
1476
- getId(stylesheet) {
1477
- var _a;
1478
- return (_a = this.styleIDMap.get(stylesheet)) !== null && _a !== void 0 ? _a : -1;
1479
- }
1480
- has(stylesheet) {
1481
- return this.styleIDMap.has(stylesheet);
1482
- }
1483
- add(stylesheet, id) {
1484
- if (this.has(stylesheet))
1485
- return this.getId(stylesheet);
1486
- let newId;
1487
- if (id === undefined) {
1488
- newId = this.id++;
1489
- }
1490
- else
1491
- newId = id;
1492
- this.styleIDMap.set(stylesheet, newId);
1493
- this.idStyleMap.set(newId, stylesheet);
1494
- return newId;
1495
- }
1496
- getStyle(id) {
1497
- return this.idStyleMap.get(id) || null;
1498
- }
1499
- reset() {
1500
- this.styleIDMap = new WeakMap();
1501
- this.idStyleMap = new Map();
1502
- this.id = 1;
1503
- }
1504
- generateId() {
1505
- return this.id++;
1506
- }
1507
- }
1508
- function getShadowHost(n) {
1509
- var _a, _b;
1510
- let shadowHost = null;
1511
- if (((_b = (_a = n.getRootNode) === null || _a === void 0 ? void 0 : _a.call(n)) === null || _b === void 0 ? void 0 : _b.nodeType) === Node.DOCUMENT_FRAGMENT_NODE &&
1512
- n.getRootNode().host)
1513
- shadowHost = n.getRootNode().host;
1514
- return shadowHost;
1515
- }
1516
- function getRootShadowHost(n) {
1517
- let rootShadowHost = n;
1518
- let shadowHost;
1519
- while ((shadowHost = getShadowHost(rootShadowHost)))
1520
- rootShadowHost = shadowHost;
1521
- return rootShadowHost;
1522
- }
1523
- function shadowHostInDom(n) {
1524
- const doc = n.ownerDocument;
1525
- if (!doc)
1526
- return false;
1527
- const shadowHost = getRootShadowHost(n);
1528
- return doc.contains(shadowHost);
1529
- }
1530
- function inDom(n) {
1531
- const doc = n.ownerDocument;
1532
- if (!doc)
1533
- return false;
1534
- return doc.contains(n) || shadowHostInDom(n);
1535
- }
1536
-
1537
- var EventType = /* @__PURE__ */ ((EventType2) => {
1538
- EventType2[EventType2["DomContentLoaded"] = 0] = "DomContentLoaded";
1539
- EventType2[EventType2["Load"] = 1] = "Load";
1540
- EventType2[EventType2["FullSnapshot"] = 2] = "FullSnapshot";
1541
- EventType2[EventType2["IncrementalSnapshot"] = 3] = "IncrementalSnapshot";
1542
- EventType2[EventType2["Meta"] = 4] = "Meta";
1543
- EventType2[EventType2["Custom"] = 5] = "Custom";
1544
- EventType2[EventType2["Plugin"] = 6] = "Plugin";
1545
- return EventType2;
1546
- })(EventType || {});
1547
- var IncrementalSource = /* @__PURE__ */ ((IncrementalSource2) => {
1548
- IncrementalSource2[IncrementalSource2["Mutation"] = 0] = "Mutation";
1549
- IncrementalSource2[IncrementalSource2["MouseMove"] = 1] = "MouseMove";
1550
- IncrementalSource2[IncrementalSource2["MouseInteraction"] = 2] = "MouseInteraction";
1551
- IncrementalSource2[IncrementalSource2["Scroll"] = 3] = "Scroll";
1552
- IncrementalSource2[IncrementalSource2["ViewportResize"] = 4] = "ViewportResize";
1553
- IncrementalSource2[IncrementalSource2["Input"] = 5] = "Input";
1554
- IncrementalSource2[IncrementalSource2["TouchMove"] = 6] = "TouchMove";
1555
- IncrementalSource2[IncrementalSource2["MediaInteraction"] = 7] = "MediaInteraction";
1556
- IncrementalSource2[IncrementalSource2["StyleSheetRule"] = 8] = "StyleSheetRule";
1557
- IncrementalSource2[IncrementalSource2["CanvasMutation"] = 9] = "CanvasMutation";
1558
- IncrementalSource2[IncrementalSource2["Font"] = 10] = "Font";
1559
- IncrementalSource2[IncrementalSource2["Log"] = 11] = "Log";
1560
- IncrementalSource2[IncrementalSource2["Drag"] = 12] = "Drag";
1561
- IncrementalSource2[IncrementalSource2["StyleDeclaration"] = 13] = "StyleDeclaration";
1562
- IncrementalSource2[IncrementalSource2["Selection"] = 14] = "Selection";
1563
- IncrementalSource2[IncrementalSource2["AdoptedStyleSheet"] = 15] = "AdoptedStyleSheet";
1564
- IncrementalSource2[IncrementalSource2["CustomElement"] = 16] = "CustomElement";
1565
- return IncrementalSource2;
1566
- })(IncrementalSource || {});
1567
- var MouseInteractions = /* @__PURE__ */ ((MouseInteractions2) => {
1568
- MouseInteractions2[MouseInteractions2["MouseUp"] = 0] = "MouseUp";
1569
- MouseInteractions2[MouseInteractions2["MouseDown"] = 1] = "MouseDown";
1570
- MouseInteractions2[MouseInteractions2["Click"] = 2] = "Click";
1571
- MouseInteractions2[MouseInteractions2["ContextMenu"] = 3] = "ContextMenu";
1572
- MouseInteractions2[MouseInteractions2["DblClick"] = 4] = "DblClick";
1573
- MouseInteractions2[MouseInteractions2["Focus"] = 5] = "Focus";
1574
- MouseInteractions2[MouseInteractions2["Blur"] = 6] = "Blur";
1575
- MouseInteractions2[MouseInteractions2["TouchStart"] = 7] = "TouchStart";
1576
- MouseInteractions2[MouseInteractions2["TouchMove_Departed"] = 8] = "TouchMove_Departed";
1577
- MouseInteractions2[MouseInteractions2["TouchEnd"] = 9] = "TouchEnd";
1578
- MouseInteractions2[MouseInteractions2["TouchCancel"] = 10] = "TouchCancel";
1579
- return MouseInteractions2;
1580
- })(MouseInteractions || {});
1581
- var PointerTypes = /* @__PURE__ */ ((PointerTypes2) => {
1582
- PointerTypes2[PointerTypes2["Mouse"] = 0] = "Mouse";
1583
- PointerTypes2[PointerTypes2["Pen"] = 1] = "Pen";
1584
- PointerTypes2[PointerTypes2["Touch"] = 2] = "Touch";
1585
- return PointerTypes2;
1586
- })(PointerTypes || {});
1587
- var CanvasContext = /* @__PURE__ */ ((CanvasContext2) => {
1588
- CanvasContext2[CanvasContext2["2D"] = 0] = "2D";
1589
- CanvasContext2[CanvasContext2["WebGL"] = 1] = "WebGL";
1590
- CanvasContext2[CanvasContext2["WebGL2"] = 2] = "WebGL2";
1591
- return CanvasContext2;
1592
- })(CanvasContext || {});
1593
1323
 
1594
1324
  function isNodeInLinkedList(n) {
1595
1325
  return '__ln' in n;
@@ -1598,7 +1328,6 @@ class DoubleLinkedList {
1598
1328
  constructor() {
1599
1329
  this.length = 0;
1600
1330
  this.head = null;
1601
- this.tail = null;
1602
1331
  }
1603
1332
  get(position) {
1604
1333
  if (position >= this.length) {
@@ -1644,9 +1373,6 @@ class DoubleLinkedList {
1644
1373
  node.next = this.head;
1645
1374
  this.head = node;
1646
1375
  }
1647
- if (node.next === null) {
1648
- this.tail = node;
1649
- }
1650
1376
  this.length++;
1651
1377
  }
1652
1378
  removeNode(n) {
@@ -1659,18 +1385,12 @@ class DoubleLinkedList {
1659
1385
  if (this.head) {
1660
1386
  this.head.previous = null;
1661
1387
  }
1662
- else {
1663
- this.tail = null;
1664
- }
1665
1388
  }
1666
1389
  else {
1667
1390
  current.previous.next = current.next;
1668
1391
  if (current.next) {
1669
1392
  current.next.previous = current.previous;
1670
1393
  }
1671
- else {
1672
- this.tail = current.previous;
1673
- }
1674
1394
  }
1675
1395
  if (n.__ln) {
1676
1396
  delete n.__ln;
@@ -1679,6 +1399,9 @@ class DoubleLinkedList {
1679
1399
  }
1680
1400
  }
1681
1401
  const moveKey = (id, parentId) => `${id}@${parentId}`;
1402
+ function isINode(n) {
1403
+ return '__sn' in n;
1404
+ }
1682
1405
  class MutationBuffer {
1683
1406
  constructor() {
1684
1407
  this.frozen = false;
@@ -1700,7 +1423,6 @@ class MutationBuffer {
1700
1423
  return;
1701
1424
  }
1702
1425
  const adds = [];
1703
- const addedIds = new Set();
1704
1426
  const addList = new DoubleLinkedList();
1705
1427
  const getNextId = (n) => {
1706
1428
  let ns = n;
@@ -1712,56 +1434,59 @@ class MutationBuffer {
1712
1434
  return nextId;
1713
1435
  };
1714
1436
  const pushAdd = (n) => {
1715
- if (!n.parentNode || !inDom(n)) {
1437
+ var _a, _b, _c, _d, _e;
1438
+ const shadowHost = n.getRootNode
1439
+ ? (_a = n.getRootNode()) === null || _a === void 0 ? void 0 : _a.host
1440
+ : null;
1441
+ let rootShadowHost = shadowHost;
1442
+ while ((_c = (_b = rootShadowHost === null || rootShadowHost === void 0 ? void 0 : rootShadowHost.getRootNode) === null || _b === void 0 ? void 0 : _b.call(rootShadowHost)) === null || _c === void 0 ? void 0 : _c.host)
1443
+ rootShadowHost =
1444
+ ((_e = (_d = rootShadowHost === null || rootShadowHost === void 0 ? void 0 : rootShadowHost.getRootNode) === null || _d === void 0 ? void 0 : _d.call(rootShadowHost)) === null || _e === void 0 ? void 0 : _e.host) ||
1445
+ null;
1446
+ const notInDoc = !this.doc.contains(n) &&
1447
+ (!rootShadowHost || !this.doc.contains(rootShadowHost));
1448
+ if (!n.parentNode || notInDoc) {
1716
1449
  return;
1717
1450
  }
1718
1451
  const parentId = isShadowRoot(n.parentNode)
1719
- ? this.mirror.getId(getShadowHost(n))
1452
+ ? this.mirror.getId(shadowHost)
1720
1453
  : this.mirror.getId(n.parentNode);
1721
1454
  const nextId = getNextId(n);
1722
1455
  if (parentId === -1 || nextId === -1) {
1723
1456
  return addList.addNode(n);
1724
1457
  }
1725
- const sn = serializeNodeWithId(n, {
1458
+ let sn = serializeNodeWithId(n, {
1726
1459
  doc: this.doc,
1727
- mirror: this.mirror,
1460
+ map: this.mirror.map,
1728
1461
  blockClass: this.blockClass,
1729
1462
  blockSelector: this.blockSelector,
1730
- maskAllText: this.maskAllText,
1731
1463
  unblockSelector: this.unblockSelector,
1732
1464
  maskTextClass: this.maskTextClass,
1733
- unmaskTextClass: this.unmaskTextClass,
1734
1465
  maskTextSelector: this.maskTextSelector,
1735
1466
  unmaskTextSelector: this.unmaskTextSelector,
1467
+ maskInputSelector: this.maskInputSelector,
1468
+ unmaskInputSelector: this.unmaskInputSelector,
1736
1469
  skipChild: true,
1737
- newlyAddedElement: true,
1738
1470
  inlineStylesheet: this.inlineStylesheet,
1471
+ maskAllText: this.maskAllText,
1739
1472
  maskInputOptions: this.maskInputOptions,
1740
- maskAttributeFn: this.maskAttributeFn,
1741
1473
  maskTextFn: this.maskTextFn,
1742
1474
  maskInputFn: this.maskInputFn,
1743
1475
  slimDOMOptions: this.slimDOMOptions,
1744
- dataURLOptions: this.dataURLOptions,
1745
1476
  recordCanvas: this.recordCanvas,
1746
1477
  inlineImages: this.inlineImages,
1747
1478
  onSerialize: (currentN) => {
1748
- if (isSerializedIframe(currentN, this.mirror)) {
1479
+ if (isIframeINode(currentN)) {
1749
1480
  this.iframeManager.addIframe(currentN);
1750
1481
  }
1751
- if (isSerializedStylesheet(currentN, this.mirror)) {
1752
- this.stylesheetManager.trackLinkElement(currentN);
1753
- }
1754
1482
  if (hasShadowRoot(n)) {
1755
- this.shadowDomManager.addShadowRoot(n.shadowRoot, this.doc);
1483
+ this.shadowDomManager.addShadowRoot(n.shadowRoot, document);
1756
1484
  }
1757
1485
  },
1758
1486
  onIframeLoad: (iframe, childSn) => {
1759
1487
  this.iframeManager.attachIframe(iframe, childSn);
1760
1488
  this.shadowDomManager.observeAttachShadow(iframe);
1761
1489
  },
1762
- onStylesheetLoad: (link, childSn) => {
1763
- this.stylesheetManager.attachLinkElement(link, childSn);
1764
- },
1765
1490
  });
1766
1491
  if (sn) {
1767
1492
  adds.push({
@@ -1769,7 +1494,6 @@ class MutationBuffer {
1769
1494
  nextId,
1770
1495
  node: sn,
1771
1496
  });
1772
- addedIds.add(sn.id);
1773
1497
  }
1774
1498
  };
1775
1499
  while (this.mapRemoves.length) {
@@ -1805,33 +1529,15 @@ class MutationBuffer {
1805
1529
  }
1806
1530
  }
1807
1531
  if (!node) {
1808
- let tailNode = addList.tail;
1809
- while (tailNode) {
1810
- const _node = tailNode;
1811
- tailNode = tailNode.previous;
1532
+ for (let index = addList.length - 1; index >= 0; index--) {
1533
+ const _node = addList.get(index);
1812
1534
  if (_node) {
1813
1535
  const parentId = this.mirror.getId(_node.value.parentNode);
1814
1536
  const nextId = getNextId(_node.value);
1815
- if (nextId === -1)
1816
- continue;
1817
- else if (parentId !== -1) {
1537
+ if (parentId !== -1 && nextId !== -1) {
1818
1538
  node = _node;
1819
1539
  break;
1820
1540
  }
1821
- else {
1822
- const unhandledNode = _node.value;
1823
- if (unhandledNode.parentNode &&
1824
- unhandledNode.parentNode.nodeType ===
1825
- Node.DOCUMENT_FRAGMENT_NODE) {
1826
- const shadowHost = unhandledNode.parentNode
1827
- .host;
1828
- const parentId = this.mirror.getId(shadowHost);
1829
- if (parentId !== -1) {
1830
- node = _node;
1831
- break;
1832
- }
1833
- }
1834
- }
1835
1541
  }
1836
1542
  }
1837
1543
  }
@@ -1851,27 +1557,12 @@ class MutationBuffer {
1851
1557
  id: this.mirror.getId(text.node),
1852
1558
  value: text.value,
1853
1559
  }))
1854
- .filter((text) => !addedIds.has(text.id))
1855
1560
  .filter((text) => this.mirror.has(text.id)),
1856
1561
  attributes: this.attributes
1857
- .map((attribute) => {
1858
- const { attributes } = attribute;
1859
- if (typeof attributes.style === 'string') {
1860
- const diffAsStr = JSON.stringify(attribute.styleDiff);
1861
- const unchangedAsStr = JSON.stringify(attribute._unchangedStyles);
1862
- if (diffAsStr.length < attributes.style.length) {
1863
- if ((diffAsStr + unchangedAsStr).split('var(').length ===
1864
- attributes.style.split('var(').length) {
1865
- attributes.style = attribute.styleDiff;
1866
- }
1867
- }
1868
- }
1869
- return {
1870
- id: this.mirror.getId(attribute.node),
1871
- attributes: attributes,
1872
- };
1873
- })
1874
- .filter((attribute) => !addedIds.has(attribute.id))
1562
+ .map((attribute) => ({
1563
+ id: this.mirror.getId(attribute.node),
1564
+ attributes: attribute.attributes,
1565
+ }))
1875
1566
  .filter((attribute) => this.mirror.has(attribute.id)),
1876
1567
  removes: this.removes,
1877
1568
  adds,
@@ -1892,23 +1583,15 @@ class MutationBuffer {
1892
1583
  this.mutationCb(payload);
1893
1584
  };
1894
1585
  this.processMutation = (m) => {
1895
- if (isIgnored(m.target, this.mirror)) {
1586
+ if (isIgnored(m.target)) {
1896
1587
  return;
1897
1588
  }
1898
- let unattachedDoc;
1899
- try {
1900
- unattachedDoc = document.implementation.createHTMLDocument();
1901
- }
1902
- catch (e) {
1903
- unattachedDoc = this.doc;
1904
- }
1905
1589
  switch (m.type) {
1906
1590
  case 'characterData': {
1907
1591
  const value = m.target.textContent;
1908
- if (!isBlocked(m.target, this.blockClass, this.blockSelector, this.unblockSelector, false) &&
1909
- value !== m.oldValue) {
1592
+ if (!isBlocked(m.target, this.blockClass, this.blockSelector, this.unblockSelector) && value !== m.oldValue) {
1910
1593
  this.texts.push({
1911
- value: needMaskingText(m.target, this.maskTextClass, this.maskTextSelector, this.unmaskTextClass, this.unmaskTextSelector, this.maskAllText) && value
1594
+ value: needMaskingText(m.target, this.maskTextClass, this.maskTextSelector, this.unmaskTextSelector, this.maskAllText) && value
1912
1595
  ? this.maskTextFn
1913
1596
  ? this.maskTextFn(value)
1914
1597
  : value.replace(/[\S]/g, '*')
@@ -1920,99 +1603,83 @@ class MutationBuffer {
1920
1603
  }
1921
1604
  case 'attributes': {
1922
1605
  const target = m.target;
1923
- let attributeName = m.attributeName;
1924
- let value = m.target.getAttribute(attributeName);
1925
- if (attributeName === 'value') {
1926
- const type = getInputType(target);
1927
- const tagName = target.tagName;
1928
- value = getInputValue(target, tagName, type);
1929
- const isInputMasked = shouldMaskInput({
1930
- maskInputOptions: this.maskInputOptions,
1931
- tagName,
1932
- type,
1933
- });
1934
- const forceMask = needMaskingText(m.target, this.maskTextClass, this.maskTextSelector, this.unmaskTextClass, this.unmaskTextSelector, isInputMasked);
1606
+ let value = target.getAttribute(m.attributeName);
1607
+ if (m.attributeName === 'value') {
1935
1608
  value = maskInputValue({
1936
- isMasked: forceMask,
1937
- element: target,
1609
+ input: target,
1610
+ maskInputSelector: this.maskInputSelector,
1611
+ unmaskInputSelector: this.unmaskInputSelector,
1612
+ maskInputOptions: this.maskInputOptions,
1613
+ tagName: target.tagName,
1614
+ type: target.getAttribute('type'),
1938
1615
  value,
1939
1616
  maskInputFn: this.maskInputFn,
1940
1617
  });
1941
1618
  }
1942
- if (isBlocked(m.target, this.blockClass, this.blockSelector, this.unblockSelector, false) ||
1943
- value === m.oldValue) {
1619
+ if (isBlocked(m.target, this.blockClass, this.blockSelector, this.unblockSelector) || value === m.oldValue) {
1944
1620
  return;
1945
1621
  }
1946
- let item = this.attributes.find((a) => a.node === m.target);
1947
- if (target.tagName === 'IFRAME' &&
1948
- attributeName === 'src' &&
1949
- !this.keepIframeSrcFn(value)) {
1950
- if (!target.contentDocument) {
1951
- attributeName = 'rr_src';
1952
- }
1953
- else {
1954
- return;
1955
- }
1956
- }
1622
+ let item = this.attributes.find((a) => a.node === m.target);
1957
1623
  if (!item) {
1958
1624
  item = {
1959
1625
  node: m.target,
1960
1626
  attributes: {},
1961
- styleDiff: {},
1962
- _unchangedStyles: {},
1963
1627
  };
1964
1628
  this.attributes.push(item);
1965
1629
  }
1966
- if (attributeName === 'type' &&
1630
+ if (m.attributeName === 'type' &&
1967
1631
  target.tagName === 'INPUT' &&
1968
1632
  (m.oldValue || '').toLowerCase() === 'password') {
1969
1633
  target.setAttribute('data-rr-is-password', 'true');
1970
1634
  }
1971
- if (!ignoreAttribute(target.tagName, attributeName)) {
1972
- item.attributes[attributeName] = transformAttribute(this.doc, toLowerCase(target.tagName), toLowerCase(attributeName), value, target, this.maskAttributeFn);
1973
- if (attributeName === 'style') {
1974
- const old = unattachedDoc.createElement('span');
1975
- if (m.oldValue) {
1976
- old.setAttribute('style', m.oldValue);
1977
- }
1635
+ if (m.attributeName === 'style') {
1636
+ const old = this.doc.createElement('span');
1637
+ if (m.oldValue) {
1638
+ old.setAttribute('style', m.oldValue);
1639
+ }
1640
+ if (item.attributes.style === undefined ||
1641
+ item.attributes.style === null) {
1642
+ item.attributes.style = {};
1643
+ }
1644
+ try {
1645
+ const styleObj = item.attributes.style;
1978
1646
  for (const pname of Array.from(target.style)) {
1979
1647
  const newValue = target.style.getPropertyValue(pname);
1980
1648
  const newPriority = target.style.getPropertyPriority(pname);
1981
1649
  if (newValue !== old.style.getPropertyValue(pname) ||
1982
1650
  newPriority !== old.style.getPropertyPriority(pname)) {
1983
1651
  if (newPriority === '') {
1984
- item.styleDiff[pname] = newValue;
1652
+ styleObj[pname] = newValue;
1985
1653
  }
1986
1654
  else {
1987
- item.styleDiff[pname] = [newValue, newPriority];
1655
+ styleObj[pname] = [newValue, newPriority];
1988
1656
  }
1989
1657
  }
1990
- else {
1991
- item._unchangedStyles[pname] = [newValue, newPriority];
1992
- }
1993
1658
  }
1994
1659
  for (const pname of Array.from(old.style)) {
1995
1660
  if (target.style.getPropertyValue(pname) === '') {
1996
- item.styleDiff[pname] = false;
1661
+ styleObj[pname] = false;
1997
1662
  }
1998
1663
  }
1999
1664
  }
1665
+ catch (error) {
1666
+ console.warn('[rrweb] Error when parsing update to style attribute:', error);
1667
+ }
1668
+ }
1669
+ else {
1670
+ const element = m.target;
1671
+ item.attributes[m.attributeName] = transformAttribute(this.doc, element, element.tagName, m.attributeName, value, this.maskAllText, this.unmaskTextSelector, this.maskTextFn);
2000
1672
  }
2001
1673
  break;
2002
1674
  }
2003
1675
  case 'childList': {
2004
- if (isBlocked(m.target, this.blockClass, this.blockSelector, this.unblockSelector, true)) {
2005
- return;
2006
- }
2007
1676
  m.addedNodes.forEach((n) => this.genAdds(n, m.target));
2008
1677
  m.removedNodes.forEach((n) => {
2009
1678
  const nodeId = this.mirror.getId(n);
2010
1679
  const parentId = isShadowRoot(m.target)
2011
1680
  ? this.mirror.getId(m.target.host)
2012
1681
  : this.mirror.getId(m.target);
2013
- if (isBlocked(m.target, this.blockClass, this.blockSelector, this.unblockSelector, false) ||
2014
- isIgnored(n, this.mirror) ||
2015
- !isSerialized(n, this.mirror)) {
1682
+ if (isBlocked(m.target, this.blockClass, this.blockSelector, this.unblockSelector) || isIgnored(n)) {
2016
1683
  return;
2017
1684
  }
2018
1685
  if (this.addedSet.has(n)) {
@@ -2029,9 +1696,7 @@ class MutationBuffer {
2029
1696
  this.removes.push({
2030
1697
  parentId,
2031
1698
  id: nodeId,
2032
- isShadow: isShadowRoot(m.target) && isNativeShadowDom(m.target)
2033
- ? true
2034
- : undefined,
1699
+ isShadow: isShadowRoot(m.target) ? true : undefined,
2035
1700
  });
2036
1701
  }
2037
1702
  this.mapRemoves.push(n);
@@ -2041,36 +1706,28 @@ class MutationBuffer {
2041
1706
  }
2042
1707
  };
2043
1708
  this.genAdds = (n, target) => {
2044
- if (this.processedNodeManager.inOtherBuffer(n, this))
2045
- return;
2046
- if (this.addedSet.has(n) || this.movedSet.has(n))
1709
+ if (target && isBlocked(target, this.blockClass, this.blockSelector, this.unblockSelector)) {
2047
1710
  return;
2048
- if (this.mirror.hasNode(n)) {
2049
- if (isIgnored(n, this.mirror)) {
1711
+ }
1712
+ if (isINode(n)) {
1713
+ if (isIgnored(n)) {
2050
1714
  return;
2051
1715
  }
2052
1716
  this.movedSet.add(n);
2053
1717
  let targetId = null;
2054
- if (target && this.mirror.hasNode(target)) {
2055
- targetId = this.mirror.getId(target);
1718
+ if (target && isINode(target)) {
1719
+ targetId = target.__sn.id;
2056
1720
  }
2057
- if (targetId && targetId !== -1) {
2058
- this.movedMap[moveKey(this.mirror.getId(n), targetId)] = true;
1721
+ if (targetId) {
1722
+ this.movedMap[moveKey(n.__sn.id, targetId)] = true;
2059
1723
  }
2060
1724
  }
2061
1725
  else {
2062
1726
  this.addedSet.add(n);
2063
1727
  this.droppedSet.delete(n);
2064
1728
  }
2065
- if (!isBlocked(n, this.blockClass, this.blockSelector, this.unblockSelector, false)) {
1729
+ if (!isBlocked(n, this.blockClass, this.blockSelector, this.unblockSelector))
2066
1730
  n.childNodes.forEach((childN) => this.genAdds(childN));
2067
- if (hasShadowRoot(n)) {
2068
- n.shadowRoot.childNodes.forEach((childN) => {
2069
- this.processedNodeManager.add(childN, this);
2070
- this.genAdds(childN, n);
2071
- });
2072
- }
2073
- }
2074
1731
  };
2075
1732
  }
2076
1733
  init(options) {
@@ -2079,28 +1736,24 @@ class MutationBuffer {
2079
1736
  'blockClass',
2080
1737
  'blockSelector',
2081
1738
  'unblockSelector',
2082
- 'maskAllText',
2083
1739
  'maskTextClass',
2084
- 'unmaskTextClass',
2085
1740
  'maskTextSelector',
2086
1741
  'unmaskTextSelector',
1742
+ 'maskInputSelector',
1743
+ 'unmaskInputSelector',
2087
1744
  'inlineStylesheet',
1745
+ 'maskAllText',
2088
1746
  'maskInputOptions',
2089
- 'maskAttributeFn',
2090
1747
  'maskTextFn',
2091
1748
  'maskInputFn',
2092
- 'keepIframeSrcFn',
2093
1749
  'recordCanvas',
2094
1750
  'inlineImages',
2095
1751
  'slimDOMOptions',
2096
- 'dataURLOptions',
2097
1752
  'doc',
2098
1753
  'mirror',
2099
1754
  'iframeManager',
2100
- 'stylesheetManager',
2101
1755
  'shadowDomManager',
2102
1756
  'canvasManager',
2103
- 'processedNodeManager',
2104
1757
  ].forEach((key) => {
2105
1758
  this[key] = options[key];
2106
1759
  });
@@ -2136,11 +1789,6 @@ function deepDelete(addsSet, n) {
2136
1789
  n.childNodes.forEach((childN) => deepDelete(addsSet, childN));
2137
1790
  }
2138
1791
  function isParentRemoved(removes, n, mirror) {
2139
- if (removes.length === 0)
2140
- return false;
2141
- return _isParentRemoved(removes, n, mirror);
2142
- }
2143
- function _isParentRemoved(removes, n, mirror) {
2144
1792
  const { parentNode } = n;
2145
1793
  if (!parentNode) {
2146
1794
  return false;
@@ -2149,14 +1797,9 @@ function _isParentRemoved(removes, n, mirror) {
2149
1797
  if (removes.some((r) => r.id === parentId)) {
2150
1798
  return true;
2151
1799
  }
2152
- return _isParentRemoved(removes, parentNode, mirror);
1800
+ return isParentRemoved(removes, parentNode, mirror);
2153
1801
  }
2154
1802
  function isAncestorInSet(set, n) {
2155
- if (set.size === 0)
2156
- return false;
2157
- return _isAncestorInSet(set, n);
2158
- }
2159
- function _isAncestorInSet(set, n) {
2160
1803
  const { parentNode } = n;
2161
1804
  if (!parentNode) {
2162
1805
  return false;
@@ -2164,32 +1807,23 @@ function _isAncestorInSet(set, n) {
2164
1807
  if (set.has(parentNode)) {
2165
1808
  return true;
2166
1809
  }
2167
- return _isAncestorInSet(set, parentNode);
1810
+ return isAncestorInSet(set, parentNode);
2168
1811
  }
2169
1812
 
2170
- let errorHandler;
2171
- function registerErrorHandler(handler) {
2172
- errorHandler = handler;
2173
- }
2174
- function unregisterErrorHandler() {
2175
- errorHandler = undefined;
2176
- }
2177
1813
  const callbackWrapper = (cb) => {
2178
- if (!errorHandler) {
2179
- return cb;
2180
- }
2181
- const rrwebWrapped = ((...rest) => {
1814
+ const rrwebWrapped = (...rest) => {
2182
1815
  try {
2183
1816
  return cb(...rest);
2184
1817
  }
2185
1818
  catch (error) {
2186
- if (errorHandler && errorHandler(error) === true) {
2187
- return () => {
2188
- };
1819
+ try {
1820
+ error.__rrweb__ = true;
1821
+ }
1822
+ catch (_a) {
2189
1823
  }
2190
1824
  throw error;
2191
1825
  }
2192
- });
1826
+ };
2193
1827
  return rrwebWrapped;
2194
1828
  };
2195
1829
 
@@ -2206,8 +1840,7 @@ function getEventTarget(event) {
2206
1840
  return event.path[0];
2207
1841
  }
2208
1842
  }
2209
- catch (_a) {
2210
- }
1843
+ catch (_a) { }
2211
1844
  return event && event.target;
2212
1845
  }
2213
1846
  function initMutationObserver(options, rootEl) {
@@ -2226,7 +1859,7 @@ function initMutationObserver(options, rootEl) {
2226
1859
  if (options.onMutation && options.onMutation(mutations) === false) {
2227
1860
  return;
2228
1861
  }
2229
- mutationBuffer.processMutations.bind(mutationBuffer)(mutations);
1862
+ mutationBuffer.processMutations(mutations);
2230
1863
  }));
2231
1864
  observer.observe(rootEl, {
2232
1865
  attributes: true,
@@ -2240,8 +1873,7 @@ function initMutationObserver(options, rootEl) {
2240
1873
  }
2241
1874
  function initMoveObserver({ mousemoveCb, sampling, doc, mirror, }) {
2242
1875
  if (sampling.mousemove === false) {
2243
- return () => {
2244
- };
1876
+ return () => { };
2245
1877
  }
2246
1878
  const threshold = typeof sampling.mousemove === 'number' ? sampling.mousemove : 50;
2247
1879
  const callbackThreshold = typeof sampling.mousemoveCallback === 'number'
@@ -2249,41 +1881,41 @@ function initMoveObserver({ mousemoveCb, sampling, doc, mirror, }) {
2249
1881
  : 500;
2250
1882
  let positions = [];
2251
1883
  let timeBaseline;
2252
- const wrappedCb = throttle$1(callbackWrapper((source) => {
1884
+ const wrappedCb = throttle$1((source) => {
2253
1885
  const totalOffset = Date.now() - timeBaseline;
2254
- mousemoveCb(positions.map((p) => {
1886
+ callbackWrapper(mousemoveCb)(positions.map((p) => {
2255
1887
  p.timeOffset -= totalOffset;
2256
1888
  return p;
2257
1889
  }), source);
2258
1890
  positions = [];
2259
1891
  timeBaseline = null;
2260
- }), callbackThreshold);
2261
- const updatePosition = callbackWrapper(throttle$1(callbackWrapper((evt) => {
1892
+ }, callbackThreshold);
1893
+ const updatePosition = throttle$1((evt) => {
2262
1894
  const target = getEventTarget(evt);
2263
- const { clientX, clientY } = legacy_isTouchEvent(evt)
1895
+ const { clientX, clientY } = isTouchEvent(evt)
2264
1896
  ? evt.changedTouches[0]
2265
1897
  : evt;
2266
1898
  if (!timeBaseline) {
2267
- timeBaseline = nowTimestamp();
1899
+ timeBaseline = Date.now();
2268
1900
  }
2269
1901
  positions.push({
2270
1902
  x: clientX,
2271
1903
  y: clientY,
2272
1904
  id: mirror.getId(target),
2273
- timeOffset: nowTimestamp() - timeBaseline,
1905
+ timeOffset: Date.now() - timeBaseline,
2274
1906
  });
2275
1907
  wrappedCb(typeof DragEvent !== 'undefined' && evt instanceof DragEvent
2276
1908
  ? IncrementalSource.Drag
2277
1909
  : evt instanceof MouseEvent
2278
1910
  ? IncrementalSource.MouseMove
2279
1911
  : IncrementalSource.TouchMove);
2280
- }), threshold, {
1912
+ }, threshold, {
2281
1913
  trailing: false,
2282
- }));
1914
+ });
2283
1915
  const handlers = [
2284
- on('mousemove', updatePosition, doc),
2285
- on('touchmove', updatePosition, doc),
2286
- on('drag', updatePosition, doc),
1916
+ on('mousemove', callbackWrapper(updatePosition), doc),
1917
+ on('touchmove', callbackWrapper(updatePosition), doc),
1918
+ on('drag', callbackWrapper(updatePosition), doc),
2287
1919
  ];
2288
1920
  return callbackWrapper(() => {
2289
1921
  handlers.forEach((h) => h());
@@ -2291,68 +1923,31 @@ function initMoveObserver({ mousemoveCb, sampling, doc, mirror, }) {
2291
1923
  }
2292
1924
  function initMouseInteractionObserver({ mouseInteractionCb, doc, mirror, blockClass, blockSelector, unblockSelector, sampling, }) {
2293
1925
  if (sampling.mouseInteraction === false) {
2294
- return () => {
2295
- };
1926
+ return () => { };
2296
1927
  }
2297
1928
  const disableMap = sampling.mouseInteraction === true ||
2298
1929
  sampling.mouseInteraction === undefined
2299
1930
  ? {}
2300
1931
  : sampling.mouseInteraction;
2301
1932
  const handlers = [];
2302
- let currentPointerType = null;
2303
1933
  const getHandler = (eventKey) => {
2304
1934
  return (event) => {
2305
1935
  const target = getEventTarget(event);
2306
- if (isBlocked(target, blockClass, blockSelector, unblockSelector, true)) {
1936
+ if (isBlocked(target, blockClass, blockSelector, unblockSelector)) {
2307
1937
  return;
2308
1938
  }
2309
- let pointerType = null;
2310
- let thisEventKey = eventKey;
2311
- if ('pointerType' in event) {
2312
- switch (event.pointerType) {
2313
- case 'mouse':
2314
- pointerType = PointerTypes.Mouse;
2315
- break;
2316
- case 'touch':
2317
- pointerType = PointerTypes.Touch;
2318
- break;
2319
- case 'pen':
2320
- pointerType = PointerTypes.Pen;
2321
- break;
2322
- }
2323
- if (pointerType === PointerTypes.Touch) {
2324
- if (MouseInteractions[eventKey] === MouseInteractions.MouseDown) {
2325
- thisEventKey = 'TouchStart';
2326
- }
2327
- else if (MouseInteractions[eventKey] === MouseInteractions.MouseUp) {
2328
- thisEventKey = 'TouchEnd';
2329
- }
2330
- }
2331
- else if (pointerType === PointerTypes.Pen) ;
2332
- }
2333
- else if (legacy_isTouchEvent(event)) {
2334
- pointerType = PointerTypes.Touch;
2335
- }
2336
- if (pointerType !== null) {
2337
- currentPointerType = pointerType;
2338
- if ((thisEventKey.startsWith('Touch') &&
2339
- pointerType === PointerTypes.Touch) ||
2340
- (thisEventKey.startsWith('Mouse') &&
2341
- pointerType === PointerTypes.Mouse)) {
2342
- pointerType = null;
2343
- }
2344
- }
2345
- else if (MouseInteractions[eventKey] === MouseInteractions.Click) {
2346
- pointerType = currentPointerType;
2347
- currentPointerType = null;
2348
- }
2349
- const e = legacy_isTouchEvent(event) ? event.changedTouches[0] : event;
1939
+ const e = isTouchEvent(event) ? event.changedTouches[0] : event;
2350
1940
  if (!e) {
2351
1941
  return;
2352
1942
  }
2353
1943
  const id = mirror.getId(target);
2354
1944
  const { clientX, clientY } = e;
2355
- callbackWrapper(mouseInteractionCb)(Object.assign({ type: MouseInteractions[thisEventKey], id, x: clientX, y: clientY }, (pointerType !== null && { pointerType })));
1945
+ callbackWrapper(mouseInteractionCb)({
1946
+ type: MouseInteractions[eventKey],
1947
+ id,
1948
+ x: clientX,
1949
+ y: clientY,
1950
+ });
2356
1951
  };
2357
1952
  };
2358
1953
  Object.keys(MouseInteractions)
@@ -2360,19 +1955,8 @@ function initMouseInteractionObserver({ mouseInteractionCb, doc, mirror, blockCl
2360
1955
  !key.endsWith('_Departed') &&
2361
1956
  disableMap[key] !== false)
2362
1957
  .forEach((eventKey) => {
2363
- let eventName = toLowerCase(eventKey);
2364
- const handler = getHandler(eventKey);
2365
- if (window.PointerEvent) {
2366
- switch (MouseInteractions[eventKey]) {
2367
- case MouseInteractions.MouseDown:
2368
- case MouseInteractions.MouseUp:
2369
- eventName = eventName.replace('mouse', 'pointer');
2370
- break;
2371
- case MouseInteractions.TouchStart:
2372
- case MouseInteractions.TouchEnd:
2373
- return;
2374
- }
2375
- }
1958
+ const eventName = eventKey.toLowerCase();
1959
+ const handler = callbackWrapper(getHandler(eventKey));
2376
1960
  handlers.push(on(eventName, handler, doc));
2377
1961
  });
2378
1962
  return callbackWrapper(() => {
@@ -2380,47 +1964,47 @@ function initMouseInteractionObserver({ mouseInteractionCb, doc, mirror, blockCl
2380
1964
  });
2381
1965
  }
2382
1966
  function initScrollObserver({ scrollCb, doc, mirror, blockClass, blockSelector, unblockSelector, sampling, }) {
2383
- const updatePosition = callbackWrapper(throttle$1(callbackWrapper((evt) => {
1967
+ const updatePosition = throttle$1((evt) => {
2384
1968
  const target = getEventTarget(evt);
2385
1969
  if (!target ||
2386
- isBlocked(target, blockClass, blockSelector, unblockSelector, true)) {
1970
+ isBlocked(target, blockClass, blockSelector, unblockSelector)) {
2387
1971
  return;
2388
1972
  }
2389
1973
  const id = mirror.getId(target);
2390
- if (target === doc && doc.defaultView) {
2391
- const scrollLeftTop = getWindowScroll(doc.defaultView);
2392
- scrollCb({
1974
+ if (target === doc) {
1975
+ const scrollEl = (doc.scrollingElement || doc.documentElement);
1976
+ callbackWrapper(scrollCb)({
2393
1977
  id,
2394
- x: scrollLeftTop.left,
2395
- y: scrollLeftTop.top,
1978
+ x: scrollEl.scrollLeft,
1979
+ y: scrollEl.scrollTop,
2396
1980
  });
2397
1981
  }
2398
1982
  else {
2399
- scrollCb({
1983
+ callbackWrapper(scrollCb)({
2400
1984
  id,
2401
1985
  x: target.scrollLeft,
2402
1986
  y: target.scrollTop,
2403
1987
  });
2404
1988
  }
2405
- }), sampling.scroll || 100));
2406
- return on('scroll', updatePosition, doc);
1989
+ }, sampling.scroll || 100);
1990
+ return on('scroll', callbackWrapper(updatePosition), doc);
2407
1991
  }
2408
- function initViewportResizeObserver({ viewportResizeCb }, { win }) {
1992
+ function initViewportResizeObserver({ viewportResizeCb, }) {
2409
1993
  let lastH = -1;
2410
1994
  let lastW = -1;
2411
- const updateDimension = callbackWrapper(throttle$1(callbackWrapper(() => {
1995
+ const updateDimension = throttle$1(() => {
2412
1996
  const height = getWindowHeight();
2413
1997
  const width = getWindowWidth();
2414
1998
  if (lastH !== height || lastW !== width) {
2415
- viewportResizeCb({
1999
+ callbackWrapper(viewportResizeCb)({
2416
2000
  width: Number(width),
2417
2001
  height: Number(height),
2418
2002
  });
2419
2003
  lastH = height;
2420
2004
  lastW = width;
2421
2005
  }
2422
- }), 200));
2423
- return on('resize', updateDimension, win);
2006
+ }, 200);
2007
+ return on('resize', callbackWrapper(updateDimension), window);
2424
2008
  }
2425
2009
  function wrapEventWithUserTriggeredFlag(v, enable) {
2426
2010
  const value = Object.assign({}, v);
@@ -2430,42 +2014,47 @@ function wrapEventWithUserTriggeredFlag(v, enable) {
2430
2014
  }
2431
2015
  const INPUT_TAGS = ['INPUT', 'TEXTAREA', 'SELECT'];
2432
2016
  const lastInputValueMap = new WeakMap();
2433
- function initInputObserver({ inputCb, doc, mirror, blockClass, blockSelector, unblockSelector, ignoreClass, ignoreSelector, maskInputOptions, maskInputFn, sampling, userTriggeredOnInput, maskTextClass, unmaskTextClass, maskTextSelector, unmaskTextSelector, }) {
2017
+ function initInputObserver({ inputCb, doc, mirror, blockClass, blockSelector, unblockSelector, ignoreClass, ignoreSelector, maskInputSelector, unmaskInputSelector, maskInputOptions, maskInputFn, sampling, userTriggeredOnInput, }) {
2434
2018
  function eventHandler(event) {
2435
2019
  let target = getEventTarget(event);
2020
+ const tagName = target && target.tagName;
2436
2021
  const userTriggered = event.isTrusted;
2437
- const tagName = target && toUpperCase(target.tagName);
2438
2022
  if (tagName === 'OPTION')
2439
2023
  target = target.parentElement;
2440
2024
  if (!target ||
2441
2025
  !tagName ||
2442
2026
  INPUT_TAGS.indexOf(tagName) < 0 ||
2443
- isBlocked(target, blockClass, blockSelector, unblockSelector, true)) {
2027
+ isBlocked(target, blockClass, blockSelector, unblockSelector)) {
2444
2028
  return;
2445
2029
  }
2446
2030
  const el = target;
2031
+ const type = getInputType(el);
2447
2032
  if (el.classList.contains(ignoreClass) ||
2448
2033
  (ignoreSelector && el.matches(ignoreSelector))) {
2449
2034
  return;
2450
2035
  }
2451
- const type = getInputType(target);
2452
2036
  let text = getInputValue(el, tagName, type);
2453
2037
  let isChecked = false;
2454
- const isInputMasked = shouldMaskInput({
2038
+ if (type === 'radio' || type === 'checkbox') {
2039
+ isChecked = target.checked;
2040
+ }
2041
+ if (hasInputMaskOptions({
2455
2042
  maskInputOptions,
2043
+ maskInputSelector,
2456
2044
  tagName,
2457
2045
  type,
2458
- });
2459
- const forceMask = needMaskingText(target, maskTextClass, maskTextSelector, unmaskTextClass, unmaskTextSelector, isInputMasked);
2460
- if (type === 'radio' || type === 'checkbox') {
2461
- isChecked = target.checked;
2046
+ })) {
2047
+ text = maskInputValue({
2048
+ input: el,
2049
+ maskInputOptions,
2050
+ maskInputSelector,
2051
+ unmaskInputSelector,
2052
+ tagName,
2053
+ type,
2054
+ value: text,
2055
+ maskInputFn,
2056
+ });
2462
2057
  }
2463
- text = maskInputValue({
2464
- isMasked: forceMask,
2465
- element: target,
2466
- value: text,
2467
- maskInputFn,
2468
- });
2469
2058
  cbWithDedup(target, callbackWrapper(wrapEventWithUserTriggeredFlag)({ text, isChecked, userTriggered }, userTriggeredOnInput));
2470
2059
  const name = target.name;
2471
2060
  if (type === 'radio' && name && isChecked) {
@@ -2474,8 +2063,12 @@ function initInputObserver({ inputCb, doc, mirror, blockClass, blockSelector, un
2474
2063
  .forEach((el) => {
2475
2064
  if (el !== target) {
2476
2065
  const text = maskInputValue({
2477
- isMasked: forceMask,
2478
- element: el,
2066
+ input: el,
2067
+ maskInputOptions,
2068
+ maskInputSelector,
2069
+ unmaskInputSelector,
2070
+ tagName,
2071
+ type,
2479
2072
  value: getInputValue(el, tagName, type),
2480
2073
  maskInputFn,
2481
2074
  });
@@ -2495,35 +2088,26 @@ function initInputObserver({ inputCb, doc, mirror, blockClass, blockSelector, un
2495
2088
  lastInputValue.isChecked !== v.isChecked) {
2496
2089
  lastInputValueMap.set(target, v);
2497
2090
  const id = mirror.getId(target);
2498
- callbackWrapper(inputCb)(Object.assign(Object.assign({}, v), { id }));
2091
+ inputCb(Object.assign(Object.assign({}, v), { id }));
2499
2092
  }
2500
2093
  }
2501
2094
  const events = sampling.input === 'last' ? ['change'] : ['input', 'change'];
2502
2095
  const handlers = events.map((eventName) => on(eventName, callbackWrapper(eventHandler), doc));
2503
- const currentWindow = doc.defaultView;
2504
- if (!currentWindow) {
2505
- return () => {
2506
- handlers.forEach((h) => h());
2507
- };
2508
- }
2509
- const propertyDescriptor = currentWindow.Object.getOwnPropertyDescriptor(currentWindow.HTMLInputElement.prototype, 'value');
2096
+ const propertyDescriptor = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value');
2510
2097
  const hookProperties = [
2511
- [currentWindow.HTMLInputElement.prototype, 'value'],
2512
- [currentWindow.HTMLInputElement.prototype, 'checked'],
2513
- [currentWindow.HTMLSelectElement.prototype, 'value'],
2514
- [currentWindow.HTMLTextAreaElement.prototype, 'value'],
2515
- [currentWindow.HTMLSelectElement.prototype, 'selectedIndex'],
2516
- [currentWindow.HTMLOptionElement.prototype, 'selected'],
2098
+ [HTMLInputElement.prototype, 'value'],
2099
+ [HTMLInputElement.prototype, 'checked'],
2100
+ [HTMLSelectElement.prototype, 'value'],
2101
+ [HTMLTextAreaElement.prototype, 'value'],
2102
+ [HTMLSelectElement.prototype, 'selectedIndex'],
2103
+ [HTMLOptionElement.prototype, 'selected'],
2517
2104
  ];
2518
2105
  if (propertyDescriptor && propertyDescriptor.set) {
2519
2106
  handlers.push(...hookProperties.map((p) => hookSetter(p[0], p[1], {
2520
2107
  set() {
2521
- callbackWrapper(eventHandler)({
2522
- target: this,
2523
- isTrusted: false,
2524
- });
2108
+ callbackWrapper(eventHandler)({ target: this });
2525
2109
  },
2526
- }, false, currentWindow)));
2110
+ })));
2527
2111
  }
2528
2112
  return callbackWrapper(() => {
2529
2113
  handlers.forEach((h) => h());
@@ -2544,7 +2128,7 @@ function getNestedCSSRulePositions(rule) {
2544
2128
  const index = rules.indexOf(childRule);
2545
2129
  pos.unshift(index);
2546
2130
  }
2547
- else if (childRule.parentStyleSheet) {
2131
+ else {
2548
2132
  const rules = Array.from(childRule.parentStyleSheet.cssRules);
2549
2133
  const index = rules.indexOf(childRule);
2550
2134
  pos.unshift(index);
@@ -2553,33 +2137,18 @@ function getNestedCSSRulePositions(rule) {
2553
2137
  }
2554
2138
  return recurse(rule, positions);
2555
2139
  }
2556
- function getIdAndStyleId(sheet, mirror, styleMirror) {
2557
- let id, styleId;
2558
- if (!sheet)
2559
- return {};
2560
- if (sheet.ownerNode)
2561
- id = mirror.getId(sheet.ownerNode);
2562
- else
2563
- styleId = styleMirror.getId(sheet);
2564
- return {
2565
- styleId,
2566
- id,
2567
- };
2568
- }
2569
- function initStyleSheetObserver({ styleSheetRuleCb, mirror, stylesheetManager }, { win }) {
2140
+ function initStyleSheetObserver({ styleSheetRuleCb, mirror }, { win }) {
2570
2141
  if (!win.CSSStyleSheet || !win.CSSStyleSheet.prototype) {
2571
- return () => {
2572
- };
2142
+ return () => { };
2573
2143
  }
2574
2144
  const insertRule = win.CSSStyleSheet.prototype.insertRule;
2575
2145
  win.CSSStyleSheet.prototype.insertRule = new Proxy(insertRule, {
2576
2146
  apply: callbackWrapper((target, thisArg, argumentsList) => {
2577
2147
  const [rule, index] = argumentsList;
2578
- const { id, styleId } = getIdAndStyleId(thisArg, mirror, stylesheetManager.styleMirror);
2579
- if ((id && id !== -1) || (styleId && styleId !== -1)) {
2148
+ const id = mirror.getId(thisArg.ownerNode);
2149
+ if (id !== -1) {
2580
2150
  styleSheetRuleCb({
2581
2151
  id,
2582
- styleId,
2583
2152
  adds: [{ rule, index }],
2584
2153
  });
2585
2154
  }
@@ -2590,53 +2159,16 @@ function initStyleSheetObserver({ styleSheetRuleCb, mirror, stylesheetManager },
2590
2159
  win.CSSStyleSheet.prototype.deleteRule = new Proxy(deleteRule, {
2591
2160
  apply: callbackWrapper((target, thisArg, argumentsList) => {
2592
2161
  const [index] = argumentsList;
2593
- const { id, styleId } = getIdAndStyleId(thisArg, mirror, stylesheetManager.styleMirror);
2594
- if ((id && id !== -1) || (styleId && styleId !== -1)) {
2162
+ const id = mirror.getId(thisArg.ownerNode);
2163
+ if (id !== -1) {
2595
2164
  styleSheetRuleCb({
2596
2165
  id,
2597
- styleId,
2598
2166
  removes: [{ index }],
2599
2167
  });
2600
2168
  }
2601
2169
  return target.apply(thisArg, argumentsList);
2602
2170
  }),
2603
2171
  });
2604
- let replace;
2605
- if (win.CSSStyleSheet.prototype.replace) {
2606
- replace = win.CSSStyleSheet.prototype.replace;
2607
- win.CSSStyleSheet.prototype.replace = new Proxy(replace, {
2608
- apply: callbackWrapper((target, thisArg, argumentsList) => {
2609
- const [text] = argumentsList;
2610
- const { id, styleId } = getIdAndStyleId(thisArg, mirror, stylesheetManager.styleMirror);
2611
- if ((id && id !== -1) || (styleId && styleId !== -1)) {
2612
- styleSheetRuleCb({
2613
- id,
2614
- styleId,
2615
- replace: text,
2616
- });
2617
- }
2618
- return target.apply(thisArg, argumentsList);
2619
- }),
2620
- });
2621
- }
2622
- let replaceSync;
2623
- if (win.CSSStyleSheet.prototype.replaceSync) {
2624
- replaceSync = win.CSSStyleSheet.prototype.replaceSync;
2625
- win.CSSStyleSheet.prototype.replaceSync = new Proxy(replaceSync, {
2626
- apply: callbackWrapper((target, thisArg, argumentsList) => {
2627
- const [text] = argumentsList;
2628
- const { id, styleId } = getIdAndStyleId(thisArg, mirror, stylesheetManager.styleMirror);
2629
- if ((id && id !== -1) || (styleId && styleId !== -1)) {
2630
- styleSheetRuleCb({
2631
- id,
2632
- styleId,
2633
- replaceSync: text,
2634
- });
2635
- }
2636
- return target.apply(thisArg, argumentsList);
2637
- }),
2638
- });
2639
- }
2640
2172
  const supportedNestedCSSRuleTypes = {};
2641
2173
  if (canMonkeyPatchNestedCSSRule('CSSGroupingRule')) {
2642
2174
  supportedNestedCSSRuleTypes.CSSGroupingRule = win.CSSGroupingRule;
@@ -2661,11 +2193,10 @@ function initStyleSheetObserver({ styleSheetRuleCb, mirror, stylesheetManager },
2661
2193
  type.prototype.insertRule = new Proxy(unmodifiedFunctions[typeKey].insertRule, {
2662
2194
  apply: callbackWrapper((target, thisArg, argumentsList) => {
2663
2195
  const [rule, index] = argumentsList;
2664
- const { id, styleId } = getIdAndStyleId(thisArg.parentStyleSheet, mirror, stylesheetManager.styleMirror);
2665
- if ((id && id !== -1) || (styleId && styleId !== -1)) {
2196
+ const id = mirror.getId(thisArg.parentStyleSheet.ownerNode);
2197
+ if (id !== -1) {
2666
2198
  styleSheetRuleCb({
2667
2199
  id,
2668
- styleId,
2669
2200
  adds: [
2670
2201
  {
2671
2202
  rule,
@@ -2683,11 +2214,10 @@ function initStyleSheetObserver({ styleSheetRuleCb, mirror, stylesheetManager },
2683
2214
  type.prototype.deleteRule = new Proxy(unmodifiedFunctions[typeKey].deleteRule, {
2684
2215
  apply: callbackWrapper((target, thisArg, argumentsList) => {
2685
2216
  const [index] = argumentsList;
2686
- const { id, styleId } = getIdAndStyleId(thisArg.parentStyleSheet, mirror, stylesheetManager.styleMirror);
2687
- if ((id && id !== -1) || (styleId && styleId !== -1)) {
2217
+ const id = mirror.getId(thisArg.parentStyleSheet.ownerNode);
2218
+ if (id !== -1) {
2688
2219
  styleSheetRuleCb({
2689
2220
  id,
2690
- styleId,
2691
2221
  removes: [
2692
2222
  { index: [...getNestedCSSRulePositions(thisArg), index] },
2693
2223
  ],
@@ -2700,74 +2230,22 @@ function initStyleSheetObserver({ styleSheetRuleCb, mirror, stylesheetManager },
2700
2230
  return callbackWrapper(() => {
2701
2231
  win.CSSStyleSheet.prototype.insertRule = insertRule;
2702
2232
  win.CSSStyleSheet.prototype.deleteRule = deleteRule;
2703
- replace && (win.CSSStyleSheet.prototype.replace = replace);
2704
- replaceSync && (win.CSSStyleSheet.prototype.replaceSync = replaceSync);
2705
2233
  Object.entries(supportedNestedCSSRuleTypes).forEach(([typeKey, type]) => {
2706
2234
  type.prototype.insertRule = unmodifiedFunctions[typeKey].insertRule;
2707
2235
  type.prototype.deleteRule = unmodifiedFunctions[typeKey].deleteRule;
2708
2236
  });
2709
2237
  });
2710
2238
  }
2711
- function initAdoptedStyleSheetObserver({ mirror, stylesheetManager, }, host) {
2712
- var _a, _b, _c;
2713
- let hostId = null;
2714
- if (host.nodeName === '#document')
2715
- hostId = mirror.getId(host);
2716
- else
2717
- hostId = mirror.getId(host.host);
2718
- const patchTarget = host.nodeName === '#document'
2719
- ? (_a = host.defaultView) === null || _a === void 0 ? void 0 : _a.Document
2720
- : (_c = (_b = host.ownerDocument) === null || _b === void 0 ? void 0 : _b.defaultView) === null || _c === void 0 ? void 0 : _c.ShadowRoot;
2721
- const originalPropertyDescriptor = Object.getOwnPropertyDescriptor(patchTarget === null || patchTarget === void 0 ? void 0 : patchTarget.prototype, 'adoptedStyleSheets');
2722
- if (hostId === null ||
2723
- hostId === -1 ||
2724
- !patchTarget ||
2725
- !originalPropertyDescriptor)
2726
- return () => {
2727
- };
2728
- Object.defineProperty(host, 'adoptedStyleSheets', {
2729
- configurable: originalPropertyDescriptor.configurable,
2730
- enumerable: originalPropertyDescriptor.enumerable,
2731
- get() {
2732
- var _a;
2733
- return (_a = originalPropertyDescriptor.get) === null || _a === void 0 ? void 0 : _a.call(this);
2734
- },
2735
- set(sheets) {
2736
- var _a;
2737
- const result = (_a = originalPropertyDescriptor.set) === null || _a === void 0 ? void 0 : _a.call(this, sheets);
2738
- if (hostId !== null && hostId !== -1) {
2739
- try {
2740
- stylesheetManager.adoptStyleSheets(sheets, hostId);
2741
- }
2742
- catch (e) {
2743
- }
2744
- }
2745
- return result;
2746
- },
2747
- });
2748
- return callbackWrapper(() => {
2749
- Object.defineProperty(host, 'adoptedStyleSheets', {
2750
- configurable: originalPropertyDescriptor.configurable,
2751
- enumerable: originalPropertyDescriptor.enumerable,
2752
- get: originalPropertyDescriptor.get,
2753
- set: originalPropertyDescriptor.set,
2754
- });
2755
- });
2756
- }
2757
- function initStyleDeclarationObserver({ styleDeclarationCb, mirror, ignoreCSSAttributes, stylesheetManager, }, { win }) {
2239
+ function initStyleDeclarationObserver({ styleDeclarationCb, mirror }, { win }) {
2758
2240
  const setProperty = win.CSSStyleDeclaration.prototype.setProperty;
2759
2241
  win.CSSStyleDeclaration.prototype.setProperty = new Proxy(setProperty, {
2760
2242
  apply: callbackWrapper((target, thisArg, argumentsList) => {
2761
- var _a;
2243
+ var _a, _b;
2762
2244
  const [property, value, priority] = argumentsList;
2763
- if (ignoreCSSAttributes.has(property)) {
2764
- return setProperty.apply(thisArg, [property, value, priority]);
2765
- }
2766
- const { id, styleId } = getIdAndStyleId((_a = thisArg.parentRule) === null || _a === void 0 ? void 0 : _a.parentStyleSheet, mirror, stylesheetManager.styleMirror);
2767
- if ((id && id !== -1) || (styleId && styleId !== -1)) {
2245
+ const id = mirror.getId((_b = (_a = thisArg.parentRule) === null || _a === void 0 ? void 0 : _a.parentStyleSheet) === null || _b === void 0 ? void 0 : _b.ownerNode);
2246
+ if (id !== -1) {
2768
2247
  styleDeclarationCb({
2769
2248
  id,
2770
- styleId,
2771
2249
  set: {
2772
2250
  property,
2773
2251
  value,
@@ -2782,16 +2260,12 @@ function initStyleDeclarationObserver({ styleDeclarationCb, mirror, ignoreCSSAtt
2782
2260
  const removeProperty = win.CSSStyleDeclaration.prototype.removeProperty;
2783
2261
  win.CSSStyleDeclaration.prototype.removeProperty = new Proxy(removeProperty, {
2784
2262
  apply: callbackWrapper((target, thisArg, argumentsList) => {
2785
- var _a;
2263
+ var _a, _b;
2786
2264
  const [property] = argumentsList;
2787
- if (ignoreCSSAttributes.has(property)) {
2788
- return removeProperty.apply(thisArg, [property]);
2789
- }
2790
- const { id, styleId } = getIdAndStyleId((_a = thisArg.parentRule) === null || _a === void 0 ? void 0 : _a.parentStyleSheet, mirror, stylesheetManager.styleMirror);
2791
- if ((id && id !== -1) || (styleId && styleId !== -1)) {
2265
+ const id = mirror.getId((_b = (_a = thisArg.parentRule) === null || _a === void 0 ? void 0 : _a.parentStyleSheet) === null || _b === void 0 ? void 0 : _b.ownerNode);
2266
+ if (id !== -1) {
2792
2267
  styleDeclarationCb({
2793
2268
  id,
2794
- styleId,
2795
2269
  remove: {
2796
2270
  property,
2797
2271
  },
@@ -2806,29 +2280,27 @@ function initStyleDeclarationObserver({ styleDeclarationCb, mirror, ignoreCSSAtt
2806
2280
  win.CSSStyleDeclaration.prototype.removeProperty = removeProperty;
2807
2281
  });
2808
2282
  }
2809
- function initMediaInteractionObserver({ mediaInteractionCb, blockClass, blockSelector, unblockSelector, mirror, sampling, doc, }) {
2810
- const handler = callbackWrapper((type) => throttle$1(callbackWrapper((event) => {
2283
+ function initMediaInteractionObserver({ mediaInteractionCb, blockClass, blockSelector, unblockSelector, mirror, sampling, }) {
2284
+ const handler = (type) => throttle$1(callbackWrapper((event) => {
2811
2285
  const target = getEventTarget(event);
2812
2286
  if (!target ||
2813
- isBlocked(target, blockClass, blockSelector, unblockSelector, true)) {
2287
+ isBlocked(target, blockClass, blockSelector, unblockSelector)) {
2814
2288
  return;
2815
2289
  }
2816
- const { currentTime, volume, muted, playbackRate } = target;
2290
+ const { currentTime, volume, muted } = target;
2817
2291
  mediaInteractionCb({
2818
2292
  type,
2819
2293
  id: mirror.getId(target),
2820
2294
  currentTime,
2821
2295
  volume,
2822
2296
  muted,
2823
- playbackRate,
2824
2297
  });
2825
- }), sampling.media || 500));
2298
+ }), sampling.media || 500);
2826
2299
  const handlers = [
2827
- on('play', handler(0), doc),
2828
- on('pause', handler(1), doc),
2829
- on('seeked', handler(2), doc),
2830
- on('volumechange', handler(3), doc),
2831
- on('ratechange', handler(4), doc),
2300
+ on('play', handler(0)),
2301
+ on('pause', handler(1)),
2302
+ on('seeked', handler(2)),
2303
+ on('volumechange', handler(3)),
2832
2304
  ];
2833
2305
  return callbackWrapper(() => {
2834
2306
  handlers.forEach((h) => h());
@@ -2837,8 +2309,7 @@ function initMediaInteractionObserver({ mediaInteractionCb, blockClass, blockSel
2837
2309
  function initFontObserver({ fontCb, doc }) {
2838
2310
  const win = doc.defaultView;
2839
2311
  if (!win) {
2840
- return () => {
2841
- };
2312
+ return () => { };
2842
2313
  }
2843
2314
  const handlers = [];
2844
2315
  const fontMap = new WeakMap();
@@ -2851,19 +2322,20 @@ function initFontObserver({ fontCb, doc }) {
2851
2322
  descriptors,
2852
2323
  fontSource: typeof source === 'string'
2853
2324
  ? source
2854
- : JSON.stringify(Array.from(new Uint8Array(source))),
2325
+ :
2326
+ JSON.stringify(Array.from(new Uint8Array(source))),
2855
2327
  });
2856
2328
  return fontFace;
2857
2329
  };
2858
2330
  const restoreHandler = patch(doc.fonts, 'add', function (original) {
2859
2331
  return function (fontFace) {
2860
- setTimeout(callbackWrapper(() => {
2332
+ setTimeout(() => {
2861
2333
  const p = fontMap.get(fontFace);
2862
2334
  if (p) {
2863
2335
  fontCb(p);
2864
2336
  fontMap.delete(fontFace);
2865
2337
  }
2866
- }), 0);
2338
+ }, 0);
2867
2339
  return original.apply(this, [fontFace]);
2868
2340
  };
2869
2341
  });
@@ -2875,59 +2347,8 @@ function initFontObserver({ fontCb, doc }) {
2875
2347
  handlers.forEach((h) => h());
2876
2348
  });
2877
2349
  }
2878
- function initSelectionObserver(param) {
2879
- const { doc, mirror, blockClass, blockSelector, unblockSelector, selectionCb, } = param;
2880
- let collapsed = true;
2881
- const updateSelection = callbackWrapper(() => {
2882
- const selection = doc.getSelection();
2883
- if (!selection || (collapsed && (selection === null || selection === void 0 ? void 0 : selection.isCollapsed)))
2884
- return;
2885
- collapsed = selection.isCollapsed || false;
2886
- const ranges = [];
2887
- const count = selection.rangeCount || 0;
2888
- for (let i = 0; i < count; i++) {
2889
- const range = selection.getRangeAt(i);
2890
- const { startContainer, startOffset, endContainer, endOffset } = range;
2891
- const blocked = isBlocked(startContainer, blockClass, blockSelector, unblockSelector, true) ||
2892
- isBlocked(endContainer, blockClass, blockSelector, unblockSelector, true);
2893
- if (blocked)
2894
- continue;
2895
- ranges.push({
2896
- start: mirror.getId(startContainer),
2897
- startOffset,
2898
- end: mirror.getId(endContainer),
2899
- endOffset,
2900
- });
2901
- }
2902
- selectionCb({ ranges });
2903
- });
2904
- updateSelection();
2905
- return on('selectionchange', updateSelection);
2906
- }
2907
- function initCustomElementObserver({ doc, customElementCb, }) {
2908
- const win = doc.defaultView;
2909
- if (!win || !win.customElements) {
2910
- return () => {
2911
- };
2912
- }
2913
- const restoreHandler = patch(win.customElements, 'define', function (original) {
2914
- return function (name, constructor, options) {
2915
- try {
2916
- customElementCb({
2917
- define: {
2918
- name,
2919
- },
2920
- });
2921
- }
2922
- catch (e) {
2923
- }
2924
- return original.apply(this, [name, constructor, options]);
2925
- };
2926
- });
2927
- return restoreHandler;
2928
- }
2929
2350
  function mergeHooks(o, hooks) {
2930
- const { mutationCb, mousemoveCb, mouseInteractionCb, scrollCb, viewportResizeCb, inputCb, mediaInteractionCb, styleSheetRuleCb, styleDeclarationCb, canvasMutationCb, fontCb, selectionCb, customElementCb, } = o;
2351
+ const { mutationCb, mousemoveCb, mouseInteractionCb, scrollCb, viewportResizeCb, inputCb, mediaInteractionCb, styleSheetRuleCb, styleDeclarationCb, canvasMutationCb, fontCb, } = o;
2931
2352
  o.mutationCb = (...p) => {
2932
2353
  if (hooks.mutation) {
2933
2354
  hooks.mutation(...p);
@@ -2994,46 +2415,25 @@ function mergeHooks(o, hooks) {
2994
2415
  }
2995
2416
  fontCb(...p);
2996
2417
  };
2997
- o.selectionCb = (...p) => {
2998
- if (hooks.selection) {
2999
- hooks.selection(...p);
3000
- }
3001
- selectionCb(...p);
3002
- };
3003
- o.customElementCb = (...c) => {
3004
- if (hooks.customElement) {
3005
- hooks.customElement(...c);
3006
- }
3007
- customElementCb(...c);
3008
- };
3009
2418
  }
3010
2419
  function initObservers(o, hooks = {}) {
3011
2420
  const currentWindow = o.doc.defaultView;
3012
2421
  if (!currentWindow) {
3013
- return () => {
3014
- };
2422
+ return () => { };
3015
2423
  }
3016
2424
  mergeHooks(o, hooks);
3017
2425
  const mutationObserver = initMutationObserver(o, o.doc);
3018
2426
  const mousemoveHandler = initMoveObserver(o);
3019
2427
  const mouseInteractionHandler = initMouseInteractionObserver(o);
3020
2428
  const scrollHandler = initScrollObserver(o);
3021
- const viewportResizeHandler = initViewportResizeObserver(o, {
3022
- win: currentWindow,
3023
- });
2429
+ const viewportResizeHandler = initViewportResizeObserver(o);
3024
2430
  const inputHandler = initInputObserver(o);
3025
2431
  const mediaInteractionHandler = initMediaInteractionObserver(o);
3026
2432
  const styleSheetObserver = initStyleSheetObserver(o, { win: currentWindow });
3027
- const adoptedStyleSheetObserver = initAdoptedStyleSheetObserver(o, o.doc);
3028
2433
  const styleDeclarationObserver = initStyleDeclarationObserver(o, {
3029
2434
  win: currentWindow,
3030
2435
  });
3031
- const fontObserver = o.collectFonts
3032
- ? initFontObserver(o)
3033
- : () => {
3034
- };
3035
- const selectionObserver = initSelectionObserver(o);
3036
- const customElementObserver = initCustomElementObserver(o);
2436
+ const fontObserver = o.collectFonts ? initFontObserver(o) : () => { };
3037
2437
  const pluginHandlers = [];
3038
2438
  for (const plugin of o.plugins) {
3039
2439
  pluginHandlers.push(plugin.observer(plugin.callback, currentWindow, plugin.options));
@@ -3047,12 +2447,13 @@ function initObservers(o, hooks = {}) {
3047
2447
  viewportResizeHandler();
3048
2448
  inputHandler();
3049
2449
  mediaInteractionHandler();
3050
- styleSheetObserver();
3051
- adoptedStyleSheetObserver();
3052
- styleDeclarationObserver();
2450
+ try {
2451
+ styleSheetObserver();
2452
+ styleDeclarationObserver();
2453
+ }
2454
+ catch (e) {
2455
+ }
3053
2456
  fontObserver();
3054
- selectionObserver();
3055
- customElementObserver();
3056
2457
  pluginHandlers.forEach((h) => h());
3057
2458
  });
3058
2459
  }
@@ -3066,88 +2467,13 @@ function canMonkeyPatchNestedCSSRule(prop) {
3066
2467
  'deleteRule' in window[prop].prototype);
3067
2468
  }
3068
2469
 
3069
- class CrossOriginIframeMirror {
3070
- constructor(generateIdFn) {
3071
- this.generateIdFn = generateIdFn;
3072
- this.iframeIdToRemoteIdMap = new WeakMap();
3073
- this.iframeRemoteIdToIdMap = new WeakMap();
3074
- }
3075
- getId(iframe, remoteId, idToRemoteMap, remoteToIdMap) {
3076
- const idToRemoteIdMap = idToRemoteMap || this.getIdToRemoteIdMap(iframe);
3077
- const remoteIdToIdMap = remoteToIdMap || this.getRemoteIdToIdMap(iframe);
3078
- let id = idToRemoteIdMap.get(remoteId);
3079
- if (!id) {
3080
- id = this.generateIdFn();
3081
- idToRemoteIdMap.set(remoteId, id);
3082
- remoteIdToIdMap.set(id, remoteId);
3083
- }
3084
- return id;
3085
- }
3086
- getIds(iframe, remoteId) {
3087
- const idToRemoteIdMap = this.getIdToRemoteIdMap(iframe);
3088
- const remoteIdToIdMap = this.getRemoteIdToIdMap(iframe);
3089
- return remoteId.map((id) => this.getId(iframe, id, idToRemoteIdMap, remoteIdToIdMap));
3090
- }
3091
- getRemoteId(iframe, id, map) {
3092
- const remoteIdToIdMap = map || this.getRemoteIdToIdMap(iframe);
3093
- if (typeof id !== 'number')
3094
- return id;
3095
- const remoteId = remoteIdToIdMap.get(id);
3096
- if (!remoteId)
3097
- return -1;
3098
- return remoteId;
3099
- }
3100
- getRemoteIds(iframe, ids) {
3101
- const remoteIdToIdMap = this.getRemoteIdToIdMap(iframe);
3102
- return ids.map((id) => this.getRemoteId(iframe, id, remoteIdToIdMap));
3103
- }
3104
- reset(iframe) {
3105
- if (!iframe) {
3106
- this.iframeIdToRemoteIdMap = new WeakMap();
3107
- this.iframeRemoteIdToIdMap = new WeakMap();
3108
- return;
3109
- }
3110
- this.iframeIdToRemoteIdMap.delete(iframe);
3111
- this.iframeRemoteIdToIdMap.delete(iframe);
3112
- }
3113
- getIdToRemoteIdMap(iframe) {
3114
- let idToRemoteIdMap = this.iframeIdToRemoteIdMap.get(iframe);
3115
- if (!idToRemoteIdMap) {
3116
- idToRemoteIdMap = new Map();
3117
- this.iframeIdToRemoteIdMap.set(iframe, idToRemoteIdMap);
3118
- }
3119
- return idToRemoteIdMap;
3120
- }
3121
- getRemoteIdToIdMap(iframe) {
3122
- let remoteIdToIdMap = this.iframeRemoteIdToIdMap.get(iframe);
3123
- if (!remoteIdToIdMap) {
3124
- remoteIdToIdMap = new Map();
3125
- this.iframeRemoteIdToIdMap.set(iframe, remoteIdToIdMap);
3126
- }
3127
- return remoteIdToIdMap;
3128
- }
3129
- }
3130
-
3131
2470
  class IframeManager {
3132
2471
  constructor(options) {
3133
2472
  this.iframes = new WeakMap();
3134
- this.crossOriginIframeMap = new WeakMap();
3135
- this.crossOriginIframeMirror = new CrossOriginIframeMirror(genId);
3136
- this.crossOriginIframeRootIdMap = new WeakMap();
3137
2473
  this.mutationCb = options.mutationCb;
3138
- this.wrappedEmit = options.wrappedEmit;
3139
- this.stylesheetManager = options.stylesheetManager;
3140
- this.recordCrossOriginIframes = options.recordCrossOriginIframes;
3141
- this.crossOriginIframeStyleMirror = new CrossOriginIframeMirror(this.stylesheetManager.styleMirror.generateId.bind(this.stylesheetManager.styleMirror));
3142
- this.mirror = options.mirror;
3143
- if (this.recordCrossOriginIframes) {
3144
- window.addEventListener('message', this.handleMessage.bind(this));
3145
- }
3146
2474
  }
3147
2475
  addIframe(iframeEl) {
3148
2476
  this.iframes.set(iframeEl, true);
3149
- if (iframeEl.contentWindow)
3150
- this.crossOriginIframeMap.set(iframeEl.contentWindow, iframeEl);
3151
2477
  }
3152
2478
  addLoadListener(cb) {
3153
2479
  this.loadListener = cb;
@@ -3157,7 +2483,7 @@ class IframeManager {
3157
2483
  this.mutationCb({
3158
2484
  adds: [
3159
2485
  {
3160
- parentId: this.mirror.getId(iframeEl),
2486
+ parentId: iframeEl.__sn.id,
3161
2487
  nextId: null,
3162
2488
  node: childSn,
3163
2489
  },
@@ -3168,239 +2494,49 @@ class IframeManager {
3168
2494
  isAttachIframe: true,
3169
2495
  });
3170
2496
  (_a = this.loadListener) === null || _a === void 0 ? void 0 : _a.call(this, iframeEl);
3171
- if (iframeEl.contentDocument &&
3172
- iframeEl.contentDocument.adoptedStyleSheets &&
3173
- iframeEl.contentDocument.adoptedStyleSheets.length > 0)
3174
- this.stylesheetManager.adoptStyleSheets(iframeEl.contentDocument.adoptedStyleSheets, this.mirror.getId(iframeEl.contentDocument));
3175
- }
3176
- handleMessage(message) {
3177
- const crossOriginMessageEvent = message;
3178
- if (crossOriginMessageEvent.data.type !== 'rrweb' ||
3179
- crossOriginMessageEvent.origin !== crossOriginMessageEvent.data.origin)
3180
- return;
3181
- const iframeSourceWindow = message.source;
3182
- if (!iframeSourceWindow)
3183
- return;
3184
- const iframeEl = this.crossOriginIframeMap.get(message.source);
3185
- if (!iframeEl)
3186
- return;
3187
- const transformedEvent = this.transformCrossOriginEvent(iframeEl, crossOriginMessageEvent.data.event);
3188
- if (transformedEvent)
3189
- this.wrappedEmit(transformedEvent, crossOriginMessageEvent.data.isCheckout);
3190
- }
3191
- transformCrossOriginEvent(iframeEl, e) {
3192
- var _a;
3193
- switch (e.type) {
3194
- case EventType.FullSnapshot: {
3195
- this.crossOriginIframeMirror.reset(iframeEl);
3196
- this.crossOriginIframeStyleMirror.reset(iframeEl);
3197
- this.replaceIdOnNode(e.data.node, iframeEl);
3198
- const rootId = e.data.node.id;
3199
- this.crossOriginIframeRootIdMap.set(iframeEl, rootId);
3200
- this.patchRootIdOnNode(e.data.node, rootId);
3201
- return {
3202
- timestamp: e.timestamp,
3203
- type: EventType.IncrementalSnapshot,
3204
- data: {
3205
- source: IncrementalSource.Mutation,
3206
- adds: [
3207
- {
3208
- parentId: this.mirror.getId(iframeEl),
3209
- nextId: null,
3210
- node: e.data.node,
3211
- },
3212
- ],
3213
- removes: [],
3214
- texts: [],
3215
- attributes: [],
3216
- isAttachIframe: true,
3217
- },
3218
- };
3219
- }
3220
- case EventType.Meta:
3221
- case EventType.Load:
3222
- case EventType.DomContentLoaded: {
3223
- return false;
3224
- }
3225
- case EventType.Plugin: {
3226
- return e;
3227
- }
3228
- case EventType.Custom: {
3229
- this.replaceIds(e.data.payload, iframeEl, ['id', 'parentId', 'previousId', 'nextId']);
3230
- return e;
3231
- }
3232
- case EventType.IncrementalSnapshot: {
3233
- switch (e.data.source) {
3234
- case IncrementalSource.Mutation: {
3235
- e.data.adds.forEach((n) => {
3236
- this.replaceIds(n, iframeEl, [
3237
- 'parentId',
3238
- 'nextId',
3239
- 'previousId',
3240
- ]);
3241
- this.replaceIdOnNode(n.node, iframeEl);
3242
- const rootId = this.crossOriginIframeRootIdMap.get(iframeEl);
3243
- rootId && this.patchRootIdOnNode(n.node, rootId);
3244
- });
3245
- e.data.removes.forEach((n) => {
3246
- this.replaceIds(n, iframeEl, ['parentId', 'id']);
3247
- });
3248
- e.data.attributes.forEach((n) => {
3249
- this.replaceIds(n, iframeEl, ['id']);
3250
- });
3251
- e.data.texts.forEach((n) => {
3252
- this.replaceIds(n, iframeEl, ['id']);
3253
- });
3254
- return e;
3255
- }
3256
- case IncrementalSource.Drag:
3257
- case IncrementalSource.TouchMove:
3258
- case IncrementalSource.MouseMove: {
3259
- e.data.positions.forEach((p) => {
3260
- this.replaceIds(p, iframeEl, ['id']);
3261
- });
3262
- return e;
3263
- }
3264
- case IncrementalSource.ViewportResize: {
3265
- return false;
3266
- }
3267
- case IncrementalSource.MediaInteraction:
3268
- case IncrementalSource.MouseInteraction:
3269
- case IncrementalSource.Scroll:
3270
- case IncrementalSource.CanvasMutation:
3271
- case IncrementalSource.Input: {
3272
- this.replaceIds(e.data, iframeEl, ['id']);
3273
- return e;
3274
- }
3275
- case IncrementalSource.StyleSheetRule:
3276
- case IncrementalSource.StyleDeclaration: {
3277
- this.replaceIds(e.data, iframeEl, ['id']);
3278
- this.replaceStyleIds(e.data, iframeEl, ['styleId']);
3279
- return e;
3280
- }
3281
- case IncrementalSource.Font: {
3282
- return e;
3283
- }
3284
- case IncrementalSource.Selection: {
3285
- e.data.ranges.forEach((range) => {
3286
- this.replaceIds(range, iframeEl, ['start', 'end']);
3287
- });
3288
- return e;
3289
- }
3290
- case IncrementalSource.AdoptedStyleSheet: {
3291
- this.replaceIds(e.data, iframeEl, ['id']);
3292
- this.replaceStyleIds(e.data, iframeEl, ['styleIds']);
3293
- (_a = e.data.styles) === null || _a === void 0 ? void 0 : _a.forEach((style) => {
3294
- this.replaceStyleIds(style, iframeEl, ['styleId']);
3295
- });
3296
- return e;
3297
- }
3298
- }
3299
- }
3300
- }
3301
- return false;
3302
- }
3303
- replace(iframeMirror, obj, iframeEl, keys) {
3304
- for (const key of keys) {
3305
- if (!Array.isArray(obj[key]) && typeof obj[key] !== 'number')
3306
- continue;
3307
- if (Array.isArray(obj[key])) {
3308
- obj[key] = iframeMirror.getIds(iframeEl, obj[key]);
3309
- }
3310
- else {
3311
- obj[key] = iframeMirror.getId(iframeEl, obj[key]);
3312
- }
3313
- }
3314
- return obj;
3315
- }
3316
- replaceIds(obj, iframeEl, keys) {
3317
- return this.replace(this.crossOriginIframeMirror, obj, iframeEl, keys);
3318
- }
3319
- replaceStyleIds(obj, iframeEl, keys) {
3320
- return this.replace(this.crossOriginIframeStyleMirror, obj, iframeEl, keys);
3321
- }
3322
- replaceIdOnNode(node, iframeEl) {
3323
- this.replaceIds(node, iframeEl, ['id', 'rootId']);
3324
- if ('childNodes' in node) {
3325
- node.childNodes.forEach((child) => {
3326
- this.replaceIdOnNode(child, iframeEl);
3327
- });
3328
- }
3329
- }
3330
- patchRootIdOnNode(node, rootId) {
3331
- if (node.type !== NodeType$1.Document && !node.rootId)
3332
- node.rootId = rootId;
3333
- if ('childNodes' in node) {
3334
- node.childNodes.forEach((child) => {
3335
- this.patchRootIdOnNode(child, rootId);
3336
- });
3337
- }
3338
2497
  }
3339
2498
  }
3340
2499
 
3341
2500
  class ShadowDomManager {
3342
2501
  constructor(options) {
3343
- this.shadowDoms = new WeakSet();
3344
- this.restoreHandlers = [];
2502
+ this.restorePatches = [];
3345
2503
  this.mutationCb = options.mutationCb;
3346
2504
  this.scrollCb = options.scrollCb;
3347
2505
  this.bypassOptions = options.bypassOptions;
3348
2506
  this.mirror = options.mirror;
3349
- this.init();
3350
- }
3351
- init() {
3352
- this.reset();
3353
- this.patchAttachShadow(Element, document);
3354
- }
3355
- addShadowRoot(shadowRoot, doc) {
3356
- if (!isNativeShadowDom(shadowRoot))
3357
- return;
3358
- if (this.shadowDoms.has(shadowRoot))
3359
- return;
3360
- this.shadowDoms.add(shadowRoot);
3361
- const observer = initMutationObserver(Object.assign(Object.assign({}, this.bypassOptions), { doc, mutationCb: this.mutationCb, mirror: this.mirror, shadowDomManager: this }), shadowRoot);
3362
- this.restoreHandlers.push(() => observer.disconnect());
3363
- this.restoreHandlers.push(initScrollObserver(Object.assign(Object.assign({}, this.bypassOptions), { scrollCb: this.scrollCb, doc: shadowRoot, mirror: this.mirror })));
3364
- setTimeout(() => {
3365
- if (shadowRoot.adoptedStyleSheets &&
3366
- shadowRoot.adoptedStyleSheets.length > 0)
3367
- this.bypassOptions.stylesheetManager.adoptStyleSheets(shadowRoot.adoptedStyleSheets, this.mirror.getId(shadowRoot.host));
3368
- this.restoreHandlers.push(initAdoptedStyleSheetObserver({
3369
- mirror: this.mirror,
3370
- stylesheetManager: this.bypassOptions.stylesheetManager,
3371
- }, shadowRoot));
3372
- }, 0);
3373
- }
3374
- observeAttachShadow(iframeElement) {
3375
- if (!iframeElement.contentWindow || !iframeElement.contentDocument)
3376
- return;
3377
- this.patchAttachShadow(iframeElement.contentWindow.Element, iframeElement.contentDocument);
3378
- }
3379
- patchAttachShadow(element, doc) {
3380
2507
  const manager = this;
3381
- this.restoreHandlers.push(patch(element.prototype, 'attachShadow', function (original) {
3382
- return function (option) {
3383
- const shadowRoot = original.call(this, option);
3384
- if (this.shadowRoot && inDom(this))
3385
- manager.addShadowRoot(this.shadowRoot, doc);
2508
+ this.restorePatches.push(patch(HTMLElement.prototype, 'attachShadow', function (original) {
2509
+ return function () {
2510
+ const shadowRoot = original.apply(this, arguments);
2511
+ if (this.shadowRoot)
2512
+ manager.addShadowRoot(this.shadowRoot, this.ownerDocument);
3386
2513
  return shadowRoot;
3387
2514
  };
3388
2515
  }));
3389
2516
  }
2517
+ addShadowRoot(shadowRoot, doc) {
2518
+ initMutationObserver(Object.assign(Object.assign({}, this.bypassOptions), { doc, mutationCb: this.mutationCb, mirror: this.mirror, shadowDomManager: this }), shadowRoot);
2519
+ initScrollObserver(Object.assign(Object.assign({}, this.bypassOptions), { scrollCb: this.scrollCb, doc: shadowRoot, mirror: this.mirror }));
2520
+ }
2521
+ observeAttachShadow(iframeElement) {
2522
+ if (iframeElement.contentWindow) {
2523
+ const manager = this;
2524
+ this.restorePatches.push(patch(iframeElement.contentWindow.HTMLElement.prototype, 'attachShadow', function (original) {
2525
+ return function () {
2526
+ const shadowRoot = original.apply(this, arguments);
2527
+ if (this.shadowRoot)
2528
+ manager.addShadowRoot(this.shadowRoot, iframeElement.contentDocument);
2529
+ return shadowRoot;
2530
+ };
2531
+ }));
2532
+ }
2533
+ }
3390
2534
  reset() {
3391
- this.restoreHandlers.forEach((handler) => {
3392
- try {
3393
- handler();
3394
- }
3395
- catch (e) {
3396
- }
3397
- });
3398
- this.restoreHandlers = [];
3399
- this.shadowDoms = new WeakSet();
2535
+ this.restorePatches.forEach((restorePatch) => restorePatch());
3400
2536
  }
3401
2537
  }
3402
2538
 
3403
- /*! *****************************************************************************
2539
+ /******************************************************************************
3404
2540
  Copyright (c) Microsoft Corporation.
3405
2541
 
3406
2542
  Permission to use, copy, modify, and/or distribute this software for any
@@ -3424,22 +2560,88 @@ function __rest(s, e) {
3424
2560
  if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
3425
2561
  t[p[i]] = s[p[i]];
3426
2562
  }
3427
- return t;
2563
+ return t;
2564
+ }
2565
+
2566
+ function initCanvas2DMutationObserver(cb, win, blockClass, unblockSelector, blockSelector, mirror) {
2567
+ const handlers = [];
2568
+ const props2D = Object.getOwnPropertyNames(win.CanvasRenderingContext2D.prototype);
2569
+ for (const prop of props2D) {
2570
+ try {
2571
+ if (typeof win.CanvasRenderingContext2D.prototype[prop] !== 'function') {
2572
+ continue;
2573
+ }
2574
+ const restoreHandler = patch(win.CanvasRenderingContext2D.prototype, prop, function (original) {
2575
+ return function (...args) {
2576
+ if (!isBlocked(this.canvas, blockClass, blockSelector, unblockSelector)) {
2577
+ setTimeout(() => {
2578
+ const recordArgs = [...args];
2579
+ if (prop === 'drawImage') {
2580
+ if (recordArgs[0] &&
2581
+ recordArgs[0] instanceof HTMLCanvasElement) {
2582
+ const canvas = recordArgs[0];
2583
+ const ctx = canvas.getContext('2d');
2584
+ let imgd = ctx === null || ctx === void 0 ? void 0 : ctx.getImageData(0, 0, canvas.width, canvas.height);
2585
+ let pix = imgd === null || imgd === void 0 ? void 0 : imgd.data;
2586
+ recordArgs[0] = JSON.stringify(pix);
2587
+ }
2588
+ }
2589
+ cb(this.canvas, {
2590
+ type: CanvasContext['2D'],
2591
+ property: prop,
2592
+ args: recordArgs,
2593
+ });
2594
+ }, 0);
2595
+ }
2596
+ return original.apply(this, args);
2597
+ };
2598
+ });
2599
+ handlers.push(restoreHandler);
2600
+ }
2601
+ catch (_a) {
2602
+ const hookHandler = hookSetter(win.CanvasRenderingContext2D.prototype, prop, {
2603
+ set(v) {
2604
+ cb(this.canvas, {
2605
+ type: CanvasContext['2D'],
2606
+ property: prop,
2607
+ args: [v],
2608
+ setter: true,
2609
+ });
2610
+ },
2611
+ });
2612
+ handlers.push(hookHandler);
2613
+ }
2614
+ }
2615
+ return () => {
2616
+ handlers.forEach((h) => h());
2617
+ };
3428
2618
  }
3429
2619
 
3430
- function __awaiter(thisArg, _arguments, P, generator) {
3431
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3432
- return new (P || (P = Promise))(function (resolve, reject) {
3433
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
3434
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
3435
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
3436
- step((generator = generator.apply(thisArg, _arguments || [])).next());
3437
- });
2620
+ function initCanvasContextObserver(win, blockClass, blockSelector, unblockSelector) {
2621
+ const handlers = [];
2622
+ try {
2623
+ const restoreHandler = patch(win.HTMLCanvasElement.prototype, 'getContext', function (original) {
2624
+ return function (contextType, ...args) {
2625
+ if (!isBlocked(this, blockClass, blockSelector, unblockSelector)) {
2626
+ if (!('__context' in this))
2627
+ this.__context = contextType;
2628
+ }
2629
+ return original.apply(this, [contextType, ...args]);
2630
+ };
2631
+ });
2632
+ handlers.push(restoreHandler);
2633
+ }
2634
+ catch (_a) {
2635
+ console.error('failed to patch HTMLCanvasElement.prototype.getContext');
2636
+ }
2637
+ return () => {
2638
+ handlers.forEach((h) => h());
2639
+ };
3438
2640
  }
3439
2641
 
3440
2642
  /*
3441
- * base64-arraybuffer 1.0.1 <https://github.com/niklasvh/base64-arraybuffer>
3442
- * Copyright (c) 2021 Niklas von Hertzen <https://hertzen.com>
2643
+ * base64-arraybuffer 1.0.2 <https://github.com/niklasvh/base64-arraybuffer>
2644
+ * Copyright (c) 2022 Niklas von Hertzen <https://hertzen.com>
3443
2645
  * Released under MIT License
3444
2646
  */
3445
2647
  var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
@@ -3465,12 +2667,12 @@ var encode = function (arraybuffer) {
3465
2667
  return base64;
3466
2668
  };
3467
2669
 
3468
- const canvasVarMap = new Map();
2670
+ const webGLVarMap = new Map();
3469
2671
  function variableListFor(ctx, ctor) {
3470
- let contextMap = canvasVarMap.get(ctx);
2672
+ let contextMap = webGLVarMap.get(ctx);
3471
2673
  if (!contextMap) {
3472
2674
  contextMap = new Map();
3473
- canvasVarMap.set(ctx, contextMap);
2675
+ webGLVarMap.set(ctx, contextMap);
3474
2676
  }
3475
2677
  if (!contextMap.has(ctor)) {
3476
2678
  contextMap.set(ctor, []);
@@ -3539,14 +2741,6 @@ function serializeArg(value, win, ctx) {
3539
2741
  src,
3540
2742
  };
3541
2743
  }
3542
- else if (value instanceof HTMLCanvasElement) {
3543
- const name = 'HTMLImageElement';
3544
- const src = value.toDataURL();
3545
- return {
3546
- rr_type: name,
3547
- src,
3548
- };
3549
- }
3550
2744
  else if (value instanceof ImageData) {
3551
2745
  const name = value.constructor.name;
3552
2746
  return {
@@ -3585,102 +2779,10 @@ const isInstanceOfWebGLObject = (value, win) => {
3585
2779
  return Boolean(supportedWebGLConstructorNames.find((name) => value instanceof win[name]));
3586
2780
  };
3587
2781
 
3588
- function initCanvas2DMutationObserver(cb, win, blockClass, blockSelector, unblockSelector) {
3589
- const handlers = [];
3590
- const props2D = Object.getOwnPropertyNames(win.CanvasRenderingContext2D.prototype);
3591
- for (const prop of props2D) {
3592
- try {
3593
- if (typeof win.CanvasRenderingContext2D.prototype[prop] !== 'function') {
3594
- continue;
3595
- }
3596
- const restoreHandler = patch(win.CanvasRenderingContext2D.prototype, prop, function (original) {
3597
- return function (...args) {
3598
- if (!isBlocked(this.canvas, blockClass, blockSelector, unblockSelector, true)) {
3599
- setTimeout(() => {
3600
- const recordArgs = serializeArgs([...args], win, this);
3601
- cb(this.canvas, {
3602
- type: CanvasContext['2D'],
3603
- property: prop,
3604
- args: recordArgs,
3605
- });
3606
- }, 0);
3607
- }
3608
- return original.apply(this, args);
3609
- };
3610
- });
3611
- handlers.push(restoreHandler);
3612
- }
3613
- catch (_a) {
3614
- const hookHandler = hookSetter(win.CanvasRenderingContext2D.prototype, prop, {
3615
- set(v) {
3616
- cb(this.canvas, {
3617
- type: CanvasContext['2D'],
3618
- property: prop,
3619
- args: [v],
3620
- setter: true,
3621
- });
3622
- },
3623
- });
3624
- handlers.push(hookHandler);
3625
- }
3626
- }
3627
- return () => {
3628
- handlers.forEach((h) => h());
3629
- };
3630
- }
3631
-
3632
- function getNormalizedContextName(contextType) {
3633
- return contextType === 'experimental-webgl' ? 'webgl' : contextType;
3634
- }
3635
- function initCanvasContextObserver(win, blockClass, blockSelector, unblockSelector, setPreserveDrawingBufferToTrue) {
3636
- const handlers = [];
3637
- try {
3638
- const restoreHandler = patch(win.HTMLCanvasElement.prototype, 'getContext', function (original) {
3639
- return function (contextType, ...args) {
3640
- if (!isBlocked(this, blockClass, blockSelector, unblockSelector, true)) {
3641
- const ctxName = getNormalizedContextName(contextType);
3642
- if (!('__context' in this))
3643
- this.__context = ctxName;
3644
- if (setPreserveDrawingBufferToTrue &&
3645
- ['webgl', 'webgl2'].includes(ctxName)) {
3646
- if (args[0] && typeof args[0] === 'object') {
3647
- const contextAttributes = args[0];
3648
- if (!contextAttributes.preserveDrawingBuffer) {
3649
- contextAttributes.preserveDrawingBuffer = true;
3650
- }
3651
- }
3652
- else {
3653
- args.splice(0, 1, {
3654
- preserveDrawingBuffer: true,
3655
- });
3656
- }
3657
- }
3658
- }
3659
- return original.apply(this, [contextType, ...args]);
3660
- };
3661
- });
3662
- handlers.push(restoreHandler);
3663
- }
3664
- catch (_a) {
3665
- console.error('failed to patch HTMLCanvasElement.prototype.getContext');
3666
- }
3667
- return () => {
3668
- handlers.forEach((h) => h());
3669
- };
3670
- }
3671
-
3672
- function patchGLPrototype(prototype, type, cb, blockClass, blockSelector, unblockSelector, mirror, win) {
2782
+ function patchGLPrototype(prototype, type, cb, blockClass, unblockSelector, blockSelector, mirror, win) {
3673
2783
  const handlers = [];
3674
2784
  const props = Object.getOwnPropertyNames(prototype);
3675
2785
  for (const prop of props) {
3676
- if ([
3677
- 'isContextLost',
3678
- 'canvas',
3679
- 'drawingBufferWidth',
3680
- 'drawingBufferHeight',
3681
- ].includes(prop)) {
3682
- continue;
3683
- }
3684
2786
  try {
3685
2787
  if (typeof prototype[prop] !== 'function') {
3686
2788
  continue;
@@ -3688,10 +2790,10 @@ function patchGLPrototype(prototype, type, cb, blockClass, blockSelector, unbloc
3688
2790
  const restoreHandler = patch(prototype, prop, function (original) {
3689
2791
  return function (...args) {
3690
2792
  const result = original.apply(this, args);
3691
- saveWebGLVar(result, win, this);
3692
- if ('tagName' in this.canvas &&
3693
- !isBlocked(this.canvas, blockClass, blockSelector, unblockSelector, true)) {
3694
- const recordArgs = serializeArgs([...args], win, this);
2793
+ saveWebGLVar(result, win, prototype);
2794
+ if (!isBlocked(this.canvas, blockClass, blockSelector, unblockSelector)) {
2795
+ const id = mirror.getId(this.canvas);
2796
+ const recordArgs = serializeArgs([...args], win, prototype);
3695
2797
  const mutation = {
3696
2798
  type,
3697
2799
  property: prop,
@@ -3731,38 +2833,6 @@ function initCanvasWebGLMutationObserver(cb, win, blockClass, blockSelector, unb
3731
2833
  };
3732
2834
  }
3733
2835
 
3734
- function decodeBase64(base64, enableUnicode) {
3735
- var binaryString = atob(base64);
3736
- if (enableUnicode) {
3737
- var binaryView = new Uint8Array(binaryString.length);
3738
- for (var i = 0, n = binaryString.length; i < n; ++i) {
3739
- binaryView[i] = binaryString.charCodeAt(i);
3740
- }
3741
- return String.fromCharCode.apply(null, new Uint16Array(binaryView.buffer));
3742
- }
3743
- return binaryString;
3744
- }
3745
-
3746
- function createURL(base64, sourcemapArg, enableUnicodeArg) {
3747
- var sourcemap = sourcemapArg === undefined ? null : sourcemapArg;
3748
- var enableUnicode = enableUnicodeArg === undefined ? false : enableUnicodeArg;
3749
- var source = decodeBase64(base64, enableUnicode);
3750
- var start = source.indexOf('\n', 10) + 1;
3751
- var body = source.substring(start) + (sourcemap ? '\/\/# sourceMappingURL=' + sourcemap : '');
3752
- var blob = new Blob([body], { type: 'application/javascript' });
3753
- return URL.createObjectURL(blob);
3754
- }
3755
-
3756
- function createBase64WorkerFactory(base64, sourcemapArg, enableUnicodeArg) {
3757
- var url;
3758
- return function WorkerFactory(options) {
3759
- url = url || createURL(base64, sourcemapArg, enableUnicodeArg);
3760
- return new Worker(url, options);
3761
- };
3762
- }
3763
-
3764
- var WorkerFactory = createBase64WorkerFactory('Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwooZnVuY3Rpb24gKCkgewogICAgJ3VzZSBzdHJpY3QnOwoKICAgIC8qISAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKg0KICAgIENvcHlyaWdodCAoYykgTWljcm9zb2Z0IENvcnBvcmF0aW9uLg0KDQogICAgUGVybWlzc2lvbiB0byB1c2UsIGNvcHksIG1vZGlmeSwgYW5kL29yIGRpc3RyaWJ1dGUgdGhpcyBzb2Z0d2FyZSBmb3IgYW55DQogICAgcHVycG9zZSB3aXRoIG9yIHdpdGhvdXQgZmVlIGlzIGhlcmVieSBncmFudGVkLg0KDQogICAgVEhFIFNPRlRXQVJFIElTIFBST1ZJREVEICJBUyBJUyIgQU5EIFRIRSBBVVRIT1IgRElTQ0xBSU1TIEFMTCBXQVJSQU5USUVTIFdJVEgNCiAgICBSRUdBUkQgVE8gVEhJUyBTT0ZUV0FSRSBJTkNMVURJTkcgQUxMIElNUExJRUQgV0FSUkFOVElFUyBPRiBNRVJDSEFOVEFCSUxJVFkNCiAgICBBTkQgRklUTkVTUy4gSU4gTk8gRVZFTlQgU0hBTEwgVEhFIEFVVEhPUiBCRSBMSUFCTEUgRk9SIEFOWSBTUEVDSUFMLCBESVJFQ1QsDQogICAgSU5ESVJFQ1QsIE9SIENPTlNFUVVFTlRJQUwgREFNQUdFUyBPUiBBTlkgREFNQUdFUyBXSEFUU09FVkVSIFJFU1VMVElORyBGUk9NDQogICAgTE9TUyBPRiBVU0UsIERBVEEgT1IgUFJPRklUUywgV0hFVEhFUiBJTiBBTiBBQ1RJT04gT0YgQ09OVFJBQ1QsIE5FR0xJR0VOQ0UgT1INCiAgICBPVEhFUiBUT1JUSU9VUyBBQ1RJT04sIEFSSVNJTkcgT1VUIE9GIE9SIElOIENPTk5FQ1RJT04gV0lUSCBUSEUgVVNFIE9SDQogICAgUEVSRk9STUFOQ0UgT0YgVEhJUyBTT0ZUV0FSRS4NCiAgICAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiAqLw0KDQogICAgZnVuY3Rpb24gX19hd2FpdGVyKHRoaXNBcmcsIF9hcmd1bWVudHMsIFAsIGdlbmVyYXRvcikgew0KICAgICAgICBmdW5jdGlvbiBhZG9wdCh2YWx1ZSkgeyByZXR1cm4gdmFsdWUgaW5zdGFuY2VvZiBQID8gdmFsdWUgOiBuZXcgUChmdW5jdGlvbiAocmVzb2x2ZSkgeyByZXNvbHZlKHZhbHVlKTsgfSk7IH0NCiAgICAgICAgcmV0dXJuIG5ldyAoUCB8fCAoUCA9IFByb21pc2UpKShmdW5jdGlvbiAocmVzb2x2ZSwgcmVqZWN0KSB7DQogICAgICAgICAgICBmdW5jdGlvbiBmdWxmaWxsZWQodmFsdWUpIHsgdHJ5IHsgc3RlcChnZW5lcmF0b3IubmV4dCh2YWx1ZSkpOyB9IGNhdGNoIChlKSB7IHJlamVjdChlKTsgfSB9DQogICAgICAgICAgICBmdW5jdGlvbiByZWplY3RlZCh2YWx1ZSkgeyB0cnkgeyBzdGVwKGdlbmVyYXRvclsidGhyb3ciXSh2YWx1ZSkpOyB9IGNhdGNoIChlKSB7IHJlamVjdChlKTsgfSB9DQogICAgICAgICAgICBmdW5jdGlvbiBzdGVwKHJlc3VsdCkgeyByZXN1bHQuZG9uZSA/IHJlc29sdmUocmVzdWx0LnZhbHVlKSA6IGFkb3B0KHJlc3VsdC52YWx1ZSkudGhlbihmdWxmaWxsZWQsIHJlamVjdGVkKTsgfQ0KICAgICAgICAgICAgc3RlcCgoZ2VuZXJhdG9yID0gZ2VuZXJhdG9yLmFwcGx5KHRoaXNBcmcsIF9hcmd1bWVudHMgfHwgW10pKS5uZXh0KCkpOw0KICAgICAgICB9KTsNCiAgICB9CgogICAgLyoKICAgICAqIGJhc2U2NC1hcnJheWJ1ZmZlciAxLjAuMSA8aHR0cHM6Ly9naXRodWIuY29tL25pa2xhc3ZoL2Jhc2U2NC1hcnJheWJ1ZmZlcj4KICAgICAqIENvcHlyaWdodCAoYykgMjAyMSBOaWtsYXMgdm9uIEhlcnR6ZW4gPGh0dHBzOi8vaGVydHplbi5jb20+CiAgICAgKiBSZWxlYXNlZCB1bmRlciBNSVQgTGljZW5zZQogICAgICovCiAgICB2YXIgY2hhcnMgPSAnQUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ejAxMjM0NTY3ODkrLyc7CiAgICAvLyBVc2UgYSBsb29rdXAgdGFibGUgdG8gZmluZCB0aGUgaW5kZXguCiAgICB2YXIgbG9va3VwID0gdHlwZW9mIFVpbnQ4QXJyYXkgPT09ICd1bmRlZmluZWQnID8gW10gOiBuZXcgVWludDhBcnJheSgyNTYpOwogICAgZm9yICh2YXIgaSA9IDA7IGkgPCBjaGFycy5sZW5ndGg7IGkrKykgewogICAgICAgIGxvb2t1cFtjaGFycy5jaGFyQ29kZUF0KGkpXSA9IGk7CiAgICB9CiAgICB2YXIgZW5jb2RlID0gZnVuY3Rpb24gKGFycmF5YnVmZmVyKSB7CiAgICAgICAgdmFyIGJ5dGVzID0gbmV3IFVpbnQ4QXJyYXkoYXJyYXlidWZmZXIpLCBpLCBsZW4gPSBieXRlcy5sZW5ndGgsIGJhc2U2NCA9ICcnOwogICAgICAgIGZvciAoaSA9IDA7IGkgPCBsZW47IGkgKz0gMykgewogICAgICAgICAgICBiYXNlNjQgKz0gY2hhcnNbYnl0ZXNbaV0gPj4gMl07CiAgICAgICAgICAgIGJhc2U2NCArPSBjaGFyc1soKGJ5dGVzW2ldICYgMykgPDwgNCkgfCAoYnl0ZXNbaSArIDFdID4+IDQpXTsKICAgICAgICAgICAgYmFzZTY0ICs9IGNoYXJzWygoYnl0ZXNbaSArIDFdICYgMTUpIDw8IDIpIHwgKGJ5dGVzW2kgKyAyXSA+PiA2KV07CiAgICAgICAgICAgIGJhc2U2NCArPSBjaGFyc1tieXRlc1tpICsgMl0gJiA2M107CiAgICAgICAgfQogICAgICAgIGlmIChsZW4gJSAzID09PSAyKSB7CiAgICAgICAgICAgIGJhc2U2NCA9IGJhc2U2NC5zdWJzdHJpbmcoMCwgYmFzZTY0Lmxlbmd0aCAtIDEpICsgJz0nOwogICAgICAgIH0KICAgICAgICBlbHNlIGlmIChsZW4gJSAzID09PSAxKSB7CiAgICAgICAgICAgIGJhc2U2NCA9IGJhc2U2NC5zdWJzdHJpbmcoMCwgYmFzZTY0Lmxlbmd0aCAtIDIpICsgJz09JzsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJhc2U2NDsKICAgIH07CgogICAgY29uc3QgbGFzdEJsb2JNYXAgPSBuZXcgTWFwKCk7DQogICAgY29uc3QgdHJhbnNwYXJlbnRCbG9iTWFwID0gbmV3IE1hcCgpOw0KICAgIGZ1bmN0aW9uIGdldFRyYW5zcGFyZW50QmxvYkZvcih3aWR0aCwgaGVpZ2h0LCBkYXRhVVJMT3B0aW9ucykgew0KICAgICAgICByZXR1cm4gX19hd2FpdGVyKHRoaXMsIHZvaWQgMCwgdm9pZCAwLCBmdW5jdGlvbiogKCkgew0KICAgICAgICAgICAgY29uc3QgaWQgPSBgJHt3aWR0aH0tJHtoZWlnaHR9YDsNCiAgICAgICAgICAgIGlmICgnT2Zmc2NyZWVuQ2FudmFzJyBpbiBnbG9iYWxUaGlzKSB7DQogICAgICAgICAgICAgICAgaWYgKHRyYW5zcGFyZW50QmxvYk1hcC5oYXMoaWQpKQ0KICAgICAgICAgICAgICAgICAgICByZXR1cm4gdHJhbnNwYXJlbnRCbG9iTWFwLmdldChpZCk7DQogICAgICAgICAgICAgICAgY29uc3Qgb2Zmc2NyZWVuID0gbmV3IE9mZnNjcmVlbkNhbnZhcyh3aWR0aCwgaGVpZ2h0KTsNCiAgICAgICAgICAgICAgICBvZmZzY3JlZW4uZ2V0Q29udGV4dCgnMmQnKTsNCiAgICAgICAgICAgICAgICBjb25zdCBibG9iID0geWllbGQgb2Zmc2NyZWVuLmNvbnZlcnRUb0Jsb2IoZGF0YVVSTE9wdGlvbnMpOw0KICAgICAgICAgICAgICAgIGNvbnN0IGFycmF5QnVmZmVyID0geWllbGQgYmxvYi5hcnJheUJ1ZmZlcigpOw0KICAgICAgICAgICAgICAgIGNvbnN0IGJhc2U2NCA9IGVuY29kZShhcnJheUJ1ZmZlcik7DQogICAgICAgICAgICAgICAgdHJhbnNwYXJlbnRCbG9iTWFwLnNldChpZCwgYmFzZTY0KTsNCiAgICAgICAgICAgICAgICByZXR1cm4gYmFzZTY0Ow0KICAgICAgICAgICAgfQ0KICAgICAgICAgICAgZWxzZSB7DQogICAgICAgICAgICAgICAgcmV0dXJuICcnOw0KICAgICAgICAgICAgfQ0KICAgICAgICB9KTsNCiAgICB9DQogICAgY29uc3Qgd29ya2VyID0gc2VsZjsNCiAgICB3b3JrZXIub25tZXNzYWdlID0gZnVuY3Rpb24gKGUpIHsNCiAgICAgICAgcmV0dXJuIF9fYXdhaXRlcih0aGlzLCB2b2lkIDAsIHZvaWQgMCwgZnVuY3Rpb24qICgpIHsNCiAgICAgICAgICAgIGlmICgnT2Zmc2NyZWVuQ2FudmFzJyBpbiBnbG9iYWxUaGlzKSB7DQogICAgICAgICAgICAgICAgY29uc3QgeyBpZCwgYml0bWFwLCB3aWR0aCwgaGVpZ2h0LCBkYXRhVVJMT3B0aW9ucyB9ID0gZS5kYXRhOw0KICAgICAgICAgICAgICAgIGNvbnN0IHRyYW5zcGFyZW50QmFzZTY0ID0gZ2V0VHJhbnNwYXJlbnRCbG9iRm9yKHdpZHRoLCBoZWlnaHQsIGRhdGFVUkxPcHRpb25zKTsNCiAgICAgICAgICAgICAgICBjb25zdCBvZmZzY3JlZW4gPSBuZXcgT2Zmc2NyZWVuQ2FudmFzKHdpZHRoLCBoZWlnaHQpOw0KICAgICAgICAgICAgICAgIGNvbnN0IGN0eCA9IG9mZnNjcmVlbi5nZXRDb250ZXh0KCcyZCcpOw0KICAgICAgICAgICAgICAgIGN0eC5kcmF3SW1hZ2UoYml0bWFwLCAwLCAwKTsNCiAgICAgICAgICAgICAgICBiaXRtYXAuY2xvc2UoKTsNCiAgICAgICAgICAgICAgICBjb25zdCBibG9iID0geWllbGQgb2Zmc2NyZWVuLmNvbnZlcnRUb0Jsb2IoZGF0YVVSTE9wdGlvbnMpOw0KICAgICAgICAgICAgICAgIGNvbnN0IHR5cGUgPSBibG9iLnR5cGU7DQogICAgICAgICAgICAgICAgY29uc3QgYXJyYXlCdWZmZXIgPSB5aWVsZCBibG9iLmFycmF5QnVmZmVyKCk7DQogICAgICAgICAgICAgICAgY29uc3QgYmFzZTY0ID0gZW5jb2RlKGFycmF5QnVmZmVyKTsNCiAgICAgICAgICAgICAgICBpZiAoIWxhc3RCbG9iTWFwLmhhcyhpZCkgJiYgKHlpZWxkIHRyYW5zcGFyZW50QmFzZTY0KSA9PT0gYmFzZTY0KSB7DQogICAgICAgICAgICAgICAgICAgIGxhc3RCbG9iTWFwLnNldChpZCwgYmFzZTY0KTsNCiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHdvcmtlci5wb3N0TWVzc2FnZSh7IGlkIH0pOw0KICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICBpZiAobGFzdEJsb2JNYXAuZ2V0KGlkKSA9PT0gYmFzZTY0KQ0KICAgICAgICAgICAgICAgICAgICByZXR1cm4gd29ya2VyLnBvc3RNZXNzYWdlKHsgaWQgfSk7DQogICAgICAgICAgICAgICAgd29ya2VyLnBvc3RNZXNzYWdlKHsNCiAgICAgICAgICAgICAgICAgICAgaWQsDQogICAgICAgICAgICAgICAgICAgIHR5cGUsDQogICAgICAgICAgICAgICAgICAgIGJhc2U2NCwNCiAgICAgICAgICAgICAgICAgICAgd2lkdGgsDQogICAgICAgICAgICAgICAgICAgIGhlaWdodCwNCiAgICAgICAgICAgICAgICB9KTsNCiAgICAgICAgICAgICAgICBsYXN0QmxvYk1hcC5zZXQoaWQsIGJhc2U2NCk7DQogICAgICAgICAgICB9DQogICAgICAgICAgICBlbHNlIHsNCiAgICAgICAgICAgICAgICByZXR1cm4gd29ya2VyLnBvc3RNZXNzYWdlKHsgaWQ6IGUuZGF0YS5pZCB9KTsNCiAgICAgICAgICAgIH0NCiAgICAgICAgfSk7DQogICAgfTsKCn0pKCk7Cgo=', null, false);
3765
-
3766
2836
  class CanvasManager {
3767
2837
  reset() {
3768
2838
  this.pendingCanvasMutations.clear();
@@ -3785,7 +2855,7 @@ class CanvasManager {
3785
2855
  this.rafStamps = { latestId: 0, invokeId: null };
3786
2856
  this.frozen = false;
3787
2857
  this.locked = false;
3788
- this.processMutation = (target, mutation) => {
2858
+ this.processMutation = function (target, mutation) {
3789
2859
  const newFrame = this.rafStamps.invokeId &&
3790
2860
  this.rafStamps.latestId !== this.rafStamps.invokeId;
3791
2861
  if (newFrame || !this.rafStamps.invokeId)
@@ -3795,108 +2865,16 @@ class CanvasManager {
3795
2865
  }
3796
2866
  this.pendingCanvasMutations.get(target).push(mutation);
3797
2867
  };
3798
- const { sampling = 'all', win, blockClass, blockSelector, unblockSelector, recordCanvas, dataURLOptions, } = options;
3799
2868
  this.mutationCb = options.mutationCb;
3800
2869
  this.mirror = options.mirror;
3801
- if (recordCanvas && sampling === 'all')
3802
- this.initCanvasMutationObserver(win, blockClass, blockSelector, unblockSelector);
3803
- if (recordCanvas && typeof sampling === 'number')
3804
- this.initCanvasFPSObserver(sampling, win, blockClass, blockSelector, unblockSelector, {
3805
- dataURLOptions,
3806
- });
3807
- }
3808
- initCanvasFPSObserver(fps, win, blockClass, blockSelector, unblockSelector, options) {
3809
- const canvasContextReset = initCanvasContextObserver(win, blockClass, blockSelector, unblockSelector, true);
3810
- const snapshotInProgressMap = new Map();
3811
- const worker = new WorkerFactory();
3812
- worker.onmessage = (e) => {
3813
- const { id } = e.data;
3814
- snapshotInProgressMap.set(id, false);
3815
- if (!('base64' in e.data))
3816
- return;
3817
- const { base64, type, width, height } = e.data;
3818
- this.mutationCb({
3819
- id,
3820
- type: CanvasContext['2D'],
3821
- commands: [
3822
- {
3823
- property: 'clearRect',
3824
- args: [0, 0, width, height],
3825
- },
3826
- {
3827
- property: 'drawImage',
3828
- args: [
3829
- {
3830
- rr_type: 'ImageBitmap',
3831
- args: [
3832
- {
3833
- rr_type: 'Blob',
3834
- data: [{ rr_type: 'ArrayBuffer', base64 }],
3835
- type,
3836
- },
3837
- ],
3838
- },
3839
- 0,
3840
- 0,
3841
- ],
3842
- },
3843
- ],
3844
- });
3845
- };
3846
- const timeBetweenSnapshots = 1000 / fps;
3847
- let lastSnapshotTime = 0;
3848
- let rafId;
3849
- const getCanvas = () => {
3850
- const matchedCanvas = [];
3851
- win.document.querySelectorAll('canvas').forEach((canvas) => {
3852
- if (!isBlocked(canvas, blockClass, blockSelector, unblockSelector, true)) {
3853
- matchedCanvas.push(canvas);
3854
- }
3855
- });
3856
- return matchedCanvas;
3857
- };
3858
- const takeCanvasSnapshots = (timestamp) => {
3859
- if (lastSnapshotTime &&
3860
- timestamp - lastSnapshotTime < timeBetweenSnapshots) {
3861
- rafId = requestAnimationFrame(takeCanvasSnapshots);
3862
- return;
3863
- }
3864
- lastSnapshotTime = timestamp;
3865
- getCanvas()
3866
- .forEach((canvas) => __awaiter(this, void 0, void 0, function* () {
3867
- var _a;
3868
- const id = this.mirror.getId(canvas);
3869
- if (snapshotInProgressMap.get(id))
3870
- return;
3871
- snapshotInProgressMap.set(id, true);
3872
- if (['webgl', 'webgl2'].includes(canvas.__context)) {
3873
- const context = canvas.getContext(canvas.__context);
3874
- if (((_a = context === null || context === void 0 ? void 0 : context.getContextAttributes()) === null || _a === void 0 ? void 0 : _a.preserveDrawingBuffer) === false) {
3875
- context.clear(context.COLOR_BUFFER_BIT);
3876
- }
3877
- }
3878
- const bitmap = yield createImageBitmap(canvas);
3879
- worker.postMessage({
3880
- id,
3881
- bitmap,
3882
- width: canvas.width,
3883
- height: canvas.height,
3884
- dataURLOptions: options.dataURLOptions,
3885
- }, [bitmap]);
3886
- }));
3887
- rafId = requestAnimationFrame(takeCanvasSnapshots);
3888
- };
3889
- rafId = requestAnimationFrame(takeCanvasSnapshots);
3890
- this.resetObservers = () => {
3891
- canvasContextReset();
3892
- cancelAnimationFrame(rafId);
3893
- };
2870
+ if (options.recordCanvas === true)
2871
+ this.initCanvasMutationObserver(options.win, options.blockClass, options.blockSelector, options.unblockSelector);
3894
2872
  }
3895
- initCanvasMutationObserver(win, blockClass, blockSelector, unblockSelector) {
2873
+ initCanvasMutationObserver(win, blockClass, unblockSelector, blockSelector) {
3896
2874
  this.startRAFTimestamping();
3897
2875
  this.startPendingCanvasMutationFlusher();
3898
- const canvasContextReset = initCanvasContextObserver(win, blockClass, blockSelector, unblockSelector, false);
3899
- const canvas2DReset = initCanvas2DMutationObserver(this.processMutation.bind(this), win, blockClass, blockSelector, unblockSelector);
2876
+ const canvasContextReset = initCanvasContextObserver(win, blockClass, blockSelector, unblockSelector);
2877
+ const canvas2DReset = initCanvas2DMutationObserver(this.processMutation.bind(this), win, blockClass, blockSelector, unblockSelector, this.mirror);
3900
2878
  const canvasWebGL1and2Reset = initCanvasWebGLMutationObserver(this.processMutation.bind(this), win, blockClass, blockSelector, unblockSelector, this.mirror);
3901
2879
  this.resetObservers = () => {
3902
2880
  canvasContextReset();
@@ -3938,133 +2916,20 @@ class CanvasManager {
3938
2916
  }
3939
2917
  }
3940
2918
 
3941
- class StylesheetManager {
3942
- constructor(options) {
3943
- this.trackedLinkElements = new WeakSet();
3944
- this.styleMirror = new StyleSheetMirror();
3945
- this.mutationCb = options.mutationCb;
3946
- this.adoptedStyleSheetCb = options.adoptedStyleSheetCb;
3947
- }
3948
- attachLinkElement(linkEl, childSn) {
3949
- if ('_cssText' in childSn.attributes)
3950
- this.mutationCb({
3951
- adds: [],
3952
- removes: [],
3953
- texts: [],
3954
- attributes: [
3955
- {
3956
- id: childSn.id,
3957
- attributes: childSn
3958
- .attributes,
3959
- },
3960
- ],
3961
- });
3962
- this.trackLinkElement(linkEl);
3963
- }
3964
- trackLinkElement(linkEl) {
3965
- if (this.trackedLinkElements.has(linkEl))
3966
- return;
3967
- this.trackedLinkElements.add(linkEl);
3968
- this.trackStylesheetInLinkElement(linkEl);
3969
- }
3970
- adoptStyleSheets(sheets, hostId) {
3971
- if (sheets.length === 0)
3972
- return;
3973
- const adoptedStyleSheetData = {
3974
- id: hostId,
3975
- styleIds: [],
3976
- };
3977
- const styles = [];
3978
- for (const sheet of sheets) {
3979
- let styleId;
3980
- if (!this.styleMirror.has(sheet)) {
3981
- styleId = this.styleMirror.add(sheet);
3982
- styles.push({
3983
- styleId,
3984
- rules: Array.from(sheet.rules || CSSRule, (r, index) => ({
3985
- rule: stringifyRule(r),
3986
- index,
3987
- })),
3988
- });
3989
- }
3990
- else
3991
- styleId = this.styleMirror.getId(sheet);
3992
- adoptedStyleSheetData.styleIds.push(styleId);
3993
- }
3994
- if (styles.length > 0)
3995
- adoptedStyleSheetData.styles = styles;
3996
- this.adoptedStyleSheetCb(adoptedStyleSheetData);
3997
- }
3998
- reset() {
3999
- this.styleMirror.reset();
4000
- this.trackedLinkElements = new WeakSet();
4001
- }
4002
- trackStylesheetInLinkElement(linkEl) {
4003
- }
4004
- }
4005
-
4006
- class ProcessedNodeManager {
4007
- constructor() {
4008
- this.nodeMap = new WeakMap();
4009
- this.loop = true;
4010
- this.periodicallyClear();
4011
- }
4012
- periodicallyClear() {
4013
- requestAnimationFrame(() => {
4014
- this.clear();
4015
- if (this.loop)
4016
- this.periodicallyClear();
4017
- });
4018
- }
4019
- inOtherBuffer(node, thisBuffer) {
4020
- const buffers = this.nodeMap.get(node);
4021
- return (buffers && Array.from(buffers).some((buffer) => buffer !== thisBuffer));
4022
- }
4023
- add(node, buffer) {
4024
- this.nodeMap.set(node, (this.nodeMap.get(node) || new Set()).add(buffer));
4025
- }
4026
- clear() {
4027
- this.nodeMap = new WeakMap();
4028
- }
4029
- destroy() {
4030
- this.loop = false;
4031
- }
4032
- }
4033
-
4034
2919
  function wrapEvent(e) {
4035
- return Object.assign(Object.assign({}, e), { timestamp: nowTimestamp() });
2920
+ return Object.assign(Object.assign({}, e), { timestamp: Date.now() });
4036
2921
  }
4037
2922
  let wrappedEmit;
4038
2923
  let takeFullSnapshot;
4039
- let canvasManager;
4040
- let recording = false;
4041
2924
  const mirror = createMirror();
4042
2925
  function record(options = {}) {
4043
- const { emit, checkoutEveryNms, checkoutEveryNth, blockClass = 'rr-block', blockSelector = null, unblockSelector = null, ignoreClass = 'rr-ignore', ignoreSelector = null, maskAllText = false, maskTextClass = 'rr-mask', unmaskTextClass = null, maskTextSelector = null, unmaskTextSelector = null, inlineStylesheet = true, maskAllInputs, maskInputOptions: _maskInputOptions, slimDOMOptions: _slimDOMOptions, maskAttributeFn, maskInputFn, maskTextFn, hooks, packFn, sampling = {}, dataURLOptions = {}, mousemoveWait, recordCanvas = false, recordCrossOriginIframes = false, recordAfter = options.recordAfter === 'DOMContentLoaded'
4044
- ? options.recordAfter
4045
- : 'load', userTriggeredOnInput = false, collectFonts = false, inlineImages = false, plugins, keepIframeSrcFn = () => false, ignoreCSSAttributes = new Set([]), errorHandler, onMutation, } = options;
4046
- registerErrorHandler(errorHandler);
4047
- const inEmittingFrame = recordCrossOriginIframes
4048
- ? window.parent === window
4049
- : true;
4050
- let passEmitsToParent = false;
4051
- if (!inEmittingFrame) {
4052
- try {
4053
- if (window.parent.document) {
4054
- passEmitsToParent = false;
4055
- }
4056
- }
4057
- catch (e) {
4058
- passEmitsToParent = true;
4059
- }
4060
- }
4061
- if (inEmittingFrame && !emit) {
2926
+ const { emit, checkoutEveryNms, checkoutEveryNth, blockClass = 'rr-block', blockSelector = null, unblockSelector = null, ignoreClass = 'rr-ignore', ignoreSelector = null, maskTextClass = 'rr-mask', maskTextSelector = null, maskInputSelector = null, unmaskTextSelector = null, unmaskInputSelector = null, inlineStylesheet = true, maskAllText = false, maskAllInputs, maskInputOptions: _maskInputOptions, slimDOMOptions: _slimDOMOptions, maskInputFn, maskTextFn, hooks, packFn, sampling = {}, mousemoveWait, recordCanvas = false, userTriggeredOnInput = false, collectFonts = false, inlineImages = false, plugins, keepIframeSrcFn = () => false, onMutation, } = options;
2927
+ if (!emit) {
4062
2928
  throw new Error('emit function is required');
4063
2929
  }
4064
2930
  if (mousemoveWait !== undefined && sampling.mousemove === undefined) {
4065
2931
  sampling.mousemove = mousemoveWait;
4066
2932
  }
4067
- mirror.reset();
4068
2933
  const maskInputOptions = maskAllInputs === true
4069
2934
  ? {
4070
2935
  color: true,
@@ -4113,8 +2978,7 @@ function record(options = {}) {
4113
2978
  e = plugin.eventProcessor(e);
4114
2979
  }
4115
2980
  }
4116
- if (packFn &&
4117
- !passEmitsToParent) {
2981
+ if (packFn) {
4118
2982
  e = packFn(e);
4119
2983
  }
4120
2984
  return e;
@@ -4127,18 +2991,7 @@ function record(options = {}) {
4127
2991
  e.data.source === IncrementalSource.Mutation)) {
4128
2992
  mutationBuffers.forEach((buf) => buf.unfreeze());
4129
2993
  }
4130
- if (inEmittingFrame) {
4131
- emit === null || emit === void 0 ? void 0 : emit(eventProcessor(e), isCheckout);
4132
- }
4133
- else if (passEmitsToParent) {
4134
- const message = {
4135
- type: 'rrweb',
4136
- event: eventProcessor(e),
4137
- origin: window.location.origin,
4138
- isCheckout,
4139
- };
4140
- window.parent.postMessage(message, '*');
4141
- }
2994
+ emit(eventProcessor(e), isCheckout);
4142
2995
  if (e.type === EventType.FullSnapshot) {
4143
2996
  lastFullSnapshotEvent = e;
4144
2997
  incrementalSnapshotCount = 0;
@@ -4171,31 +3024,10 @@ function record(options = {}) {
4171
3024
  type: EventType.IncrementalSnapshot,
4172
3025
  data: Object.assign({ source: IncrementalSource.CanvasMutation }, p),
4173
3026
  }));
4174
- const wrappedAdoptedStyleSheetEmit = (a) => wrappedEmit(wrapEvent({
4175
- type: EventType.IncrementalSnapshot,
4176
- data: Object.assign({ source: IncrementalSource.AdoptedStyleSheet }, a),
4177
- }));
4178
- const stylesheetManager = new StylesheetManager({
4179
- mutationCb: wrappedMutationEmit,
4180
- adoptedStyleSheetCb: wrappedAdoptedStyleSheetEmit,
4181
- });
4182
3027
  const iframeManager = new IframeManager({
4183
- mirror,
4184
3028
  mutationCb: wrappedMutationEmit,
4185
- stylesheetManager: stylesheetManager,
4186
- recordCrossOriginIframes,
4187
- wrappedEmit,
4188
3029
  });
4189
- for (const plugin of plugins || []) {
4190
- if (plugin.getMirror)
4191
- plugin.getMirror({
4192
- nodeMirror: mirror,
4193
- crossOriginIframeMirror: iframeManager.crossOriginIframeMirror,
4194
- crossOriginIframeStyleMirror: iframeManager.crossOriginIframeStyleMirror,
4195
- });
4196
- }
4197
- const processedNodeManager = new ProcessedNodeManager();
4198
- canvasManager = new CanvasManager({
3030
+ const canvasManager = new CanvasManager({
4199
3031
  recordCanvas,
4200
3032
  mutationCb: wrappedCanvasMutationEmit,
4201
3033
  win: window,
@@ -4203,8 +3035,6 @@ function record(options = {}) {
4203
3035
  blockSelector,
4204
3036
  unblockSelector,
4205
3037
  mirror,
4206
- sampling: sampling.canvas,
4207
- dataURLOptions,
4208
3038
  });
4209
3039
  const shadowDomManager = new ShadowDomManager({
4210
3040
  mutationCb: wrappedMutationEmit,
@@ -4214,15 +3044,14 @@ function record(options = {}) {
4214
3044
  blockClass,
4215
3045
  blockSelector,
4216
3046
  unblockSelector,
4217
- maskAllText,
4218
3047
  maskTextClass,
4219
- unmaskTextClass,
4220
3048
  maskTextSelector,
4221
3049
  unmaskTextSelector,
3050
+ maskInputSelector,
3051
+ unmaskInputSelector,
4222
3052
  inlineStylesheet,
3053
+ maskAllText,
4223
3054
  maskInputOptions,
4224
- dataURLOptions,
4225
- maskAttributeFn,
4226
3055
  maskTextFn,
4227
3056
  maskInputFn,
4228
3057
  recordCanvas,
@@ -4230,14 +3059,12 @@ function record(options = {}) {
4230
3059
  sampling,
4231
3060
  slimDOMOptions,
4232
3061
  iframeManager,
4233
- stylesheetManager,
4234
3062
  canvasManager,
4235
- keepIframeSrcFn,
4236
- processedNodeManager,
4237
3063
  },
4238
3064
  mirror,
4239
3065
  });
4240
3066
  takeFullSnapshot = (isCheckout = false) => {
3067
+ var _a, _b, _c, _d;
4241
3068
  wrappedEmit(wrapEvent({
4242
3069
  type: EventType.Meta,
4243
3070
  data: {
@@ -4246,35 +3073,27 @@ function record(options = {}) {
4246
3073
  height: getWindowHeight(),
4247
3074
  },
4248
3075
  }), isCheckout);
4249
- stylesheetManager.reset();
4250
- shadowDomManager.init();
4251
3076
  mutationBuffers.forEach((buf) => buf.lock());
4252
- const node = snapshot(document, {
4253
- mirror,
3077
+ const [node, idNodeMap] = snapshot(document, {
4254
3078
  blockClass,
4255
3079
  blockSelector,
4256
3080
  unblockSelector,
4257
- maskAllText,
4258
3081
  maskTextClass,
4259
- unmaskTextClass,
4260
3082
  maskTextSelector,
4261
3083
  unmaskTextSelector,
3084
+ maskInputSelector,
3085
+ unmaskInputSelector,
4262
3086
  inlineStylesheet,
3087
+ maskAllText,
4263
3088
  maskAllInputs: maskInputOptions,
4264
- maskAttributeFn,
4265
- maskInputFn,
4266
3089
  maskTextFn,
4267
3090
  slimDOM: slimDOMOptions,
4268
- dataURLOptions,
4269
3091
  recordCanvas,
4270
3092
  inlineImages,
4271
3093
  onSerialize: (n) => {
4272
- if (isSerializedIframe(n, mirror)) {
3094
+ if (isIframeINode(n)) {
4273
3095
  iframeManager.addIframe(n);
4274
3096
  }
4275
- if (isSerializedStylesheet(n, mirror)) {
4276
- stylesheetManager.trackLinkElement(n);
4277
- }
4278
3097
  if (hasShadowRoot(n)) {
4279
3098
  shadowDomManager.addShadowRoot(n.shadowRoot, document);
4280
3099
  }
@@ -4283,27 +3102,42 @@ function record(options = {}) {
4283
3102
  iframeManager.attachIframe(iframe, childSn);
4284
3103
  shadowDomManager.observeAttachShadow(iframe);
4285
3104
  },
4286
- onStylesheetLoad: (linkEl, childSn) => {
4287
- stylesheetManager.attachLinkElement(linkEl, childSn);
4288
- },
4289
3105
  keepIframeSrcFn,
4290
3106
  });
4291
3107
  if (!node) {
4292
3108
  return console.warn('Failed to snapshot the document');
4293
3109
  }
3110
+ mirror.map = idNodeMap;
4294
3111
  wrappedEmit(wrapEvent({
4295
3112
  type: EventType.FullSnapshot,
4296
3113
  data: {
4297
3114
  node,
4298
- initialOffset: getWindowScroll(window),
3115
+ initialOffset: {
3116
+ left: window.pageXOffset !== undefined
3117
+ ? window.pageXOffset
3118
+ : (document === null || document === void 0 ? void 0 : document.documentElement.scrollLeft) ||
3119
+ ((_b = (_a = document === null || document === void 0 ? void 0 : document.body) === null || _a === void 0 ? void 0 : _a.parentElement) === null || _b === void 0 ? void 0 : _b.scrollLeft) ||
3120
+ (document === null || document === void 0 ? void 0 : document.body.scrollLeft) ||
3121
+ 0,
3122
+ top: window.pageYOffset !== undefined
3123
+ ? window.pageYOffset
3124
+ : (document === null || document === void 0 ? void 0 : document.documentElement.scrollTop) ||
3125
+ ((_d = (_c = document === null || document === void 0 ? void 0 : document.body) === null || _c === void 0 ? void 0 : _c.parentElement) === null || _d === void 0 ? void 0 : _d.scrollTop) ||
3126
+ (document === null || document === void 0 ? void 0 : document.body.scrollTop) ||
3127
+ 0,
3128
+ },
4299
3129
  },
4300
- }), isCheckout);
3130
+ }));
4301
3131
  mutationBuffers.forEach((buf) => buf.unlock());
4302
- if (document.adoptedStyleSheets && document.adoptedStyleSheets.length > 0)
4303
- stylesheetManager.adoptStyleSheets(document.adoptedStyleSheets, mirror.getId(document));
4304
3132
  };
4305
3133
  try {
4306
3134
  const handlers = [];
3135
+ handlers.push(on('DOMContentLoaded', () => {
3136
+ wrappedEmit(wrapEvent({
3137
+ type: EventType.DomContentLoaded,
3138
+ data: {},
3139
+ }));
3140
+ }));
4307
3141
  const observe = (doc) => {
4308
3142
  var _a;
4309
3143
  return callbackWrapper(initObservers)({
@@ -4346,26 +3180,14 @@ function record(options = {}) {
4346
3180
  type: EventType.IncrementalSnapshot,
4347
3181
  data: Object.assign({ source: IncrementalSource.Font }, p),
4348
3182
  })),
4349
- selectionCb: (p) => {
4350
- wrappedEmit(wrapEvent({
4351
- type: EventType.IncrementalSnapshot,
4352
- data: Object.assign({ source: IncrementalSource.Selection }, p),
4353
- }));
4354
- },
4355
- customElementCb: (c) => {
4356
- wrappedEmit(wrapEvent({
4357
- type: EventType.IncrementalSnapshot,
4358
- data: Object.assign({ source: IncrementalSource.CustomElement }, c),
4359
- }));
4360
- },
4361
3183
  blockClass,
4362
3184
  ignoreClass,
4363
3185
  ignoreSelector,
4364
- maskAllText,
4365
3186
  maskTextClass,
4366
- unmaskTextClass,
4367
3187
  maskTextSelector,
4368
3188
  unmaskTextSelector,
3189
+ maskInputSelector,
3190
+ unmaskInputSelector,
4369
3191
  maskInputOptions,
4370
3192
  inlineStylesheet,
4371
3193
  sampling,
@@ -4374,21 +3196,16 @@ function record(options = {}) {
4374
3196
  userTriggeredOnInput,
4375
3197
  collectFonts,
4376
3198
  doc,
4377
- maskAttributeFn,
3199
+ maskAllText,
4378
3200
  maskInputFn,
4379
3201
  maskTextFn,
4380
- keepIframeSrcFn,
4381
3202
  blockSelector,
4382
3203
  unblockSelector,
4383
3204
  slimDOMOptions,
4384
- dataURLOptions,
4385
3205
  mirror,
4386
3206
  iframeManager,
4387
- stylesheetManager,
4388
3207
  shadowDomManager,
4389
- processedNodeManager,
4390
3208
  canvasManager,
4391
- ignoreCSSAttributes,
4392
3209
  plugins: ((_a = plugins === null || plugins === void 0 ? void 0 : plugins.filter((p) => p.observer)) === null || _a === void 0 ? void 0 : _a.map((p) => ({
4393
3210
  observer: p.observer,
4394
3211
  options: p.options,
@@ -4413,35 +3230,22 @@ function record(options = {}) {
4413
3230
  const init = () => {
4414
3231
  takeFullSnapshot();
4415
3232
  handlers.push(observe(document));
4416
- recording = true;
4417
3233
  };
4418
3234
  if (document.readyState === 'interactive' ||
4419
3235
  document.readyState === 'complete') {
4420
3236
  init();
4421
3237
  }
4422
3238
  else {
4423
- handlers.push(on('DOMContentLoaded', () => {
4424
- wrappedEmit(wrapEvent({
4425
- type: EventType.DomContentLoaded,
4426
- data: {},
4427
- }));
4428
- if (recordAfter === 'DOMContentLoaded')
4429
- init();
4430
- }));
4431
3239
  handlers.push(on('load', () => {
4432
3240
  wrappedEmit(wrapEvent({
4433
3241
  type: EventType.Load,
4434
3242
  data: {},
4435
3243
  }));
4436
- if (recordAfter === 'load')
4437
- init();
3244
+ init();
4438
3245
  }, window));
4439
3246
  }
4440
3247
  return () => {
4441
3248
  handlers.forEach((h) => h());
4442
- processedNodeManager.destroy();
4443
- recording = false;
4444
- unregisterErrorHandler();
4445
3249
  };
4446
3250
  }
4447
3251
  catch (error) {
@@ -4449,7 +3253,7 @@ function record(options = {}) {
4449
3253
  }
4450
3254
  }
4451
3255
  record.addCustomEvent = (tag, payload) => {
4452
- if (!recording) {
3256
+ if (!wrappedEmit) {
4453
3257
  throw new Error('please add custom event after start recording');
4454
3258
  }
4455
3259
  wrappedEmit(wrapEvent({
@@ -4464,7 +3268,7 @@ record.freezePage = () => {
4464
3268
  mutationBuffers.forEach((buf) => buf.freeze());
4465
3269
  };
4466
3270
  record.takeFullSnapshot = (isCheckout) => {
4467
- if (!recording) {
3271
+ if (!takeFullSnapshot) {
4468
3272
  throw new Error('please take full snapshot after start recording');
4469
3273
  }
4470
3274
  takeFullSnapshot(isCheckout);
@@ -4960,25 +3764,27 @@ const handleDomListener = (
4960
3764
 
4961
3765
  /** Get the base DOM breadcrumb. */
4962
3766
  function getBaseDomBreadcrumb(target, message) {
4963
- const nodeId = record.mirror.getId(target);
4964
- const node = nodeId && record.mirror.getNode(nodeId);
4965
- const meta = node && record.mirror.getMeta(node);
4966
- const element = meta && isElement(meta) ? meta : null;
3767
+ // `__sn` property is the serialized node created by rrweb
3768
+ const serializedNode = target && isRrwebNode(target) && target.__sn.type === NodeType.Element ? target.__sn : null;
4967
3769
 
4968
3770
  return {
4969
3771
  message,
4970
- data: element
3772
+ data: serializedNode
4971
3773
  ? {
4972
- nodeId,
3774
+ nodeId: serializedNode.id,
4973
3775
  node: {
4974
- id: nodeId,
4975
- tagName: element.tagName,
4976
- textContent: Array.from(element.childNodes)
4977
- .map((node) => node.type === NodeType.Text && node.textContent)
4978
- .filter(Boolean) // filter out empty values
4979
- .map(text => (text ).trim())
4980
- .join(''),
4981
- attributes: getAttributesToRecord(element.attributes),
3776
+ id: serializedNode.id,
3777
+ tagName: serializedNode.tagName,
3778
+ textContent: target
3779
+ ? Array.from(target.childNodes)
3780
+ .map(
3781
+ (node) => '__sn' in node && node.__sn.type === NodeType.Text && node.__sn.textContent,
3782
+ )
3783
+ .filter(Boolean) // filter out empty values
3784
+ .map(text => (text ).trim())
3785
+ .join('')
3786
+ : '',
3787
+ attributes: getAttributesToRecord(serializedNode.attributes),
4982
3788
  },
4983
3789
  }
4984
3790
  : {},
@@ -5015,8 +3821,8 @@ function getDomTarget(handlerData) {
5015
3821
  return { target, message };
5016
3822
  }
5017
3823
 
5018
- function isElement(node) {
5019
- return node.type === NodeType.Element;
3824
+ function isRrwebNode(node) {
3825
+ return '__sn' in node;
5020
3826
  }
5021
3827
 
5022
3828
  /** Handle keyboard events & create breadcrumbs. */
@@ -7841,7 +6647,9 @@ function createLargestContentfulPaint(
7841
6647
  data: {
7842
6648
  value, // LCP "duration" in ms
7843
6649
  size,
7844
- nodeId: record.mirror.getId(entry.element),
6650
+ // Not sure why this errors, Node should be correct (Argument of type 'Node' is not assignable to parameter of type 'INode')
6651
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6652
+ nodeId: record.mirror.getId(entry.element ),
7845
6653
  },
7846
6654
  };
7847
6655
  }
@@ -8117,11 +6925,19 @@ async function prepareReplayEvent({
8117
6925
  typeof client._integrations === 'object' && client._integrations !== null && !Array.isArray(client._integrations)
8118
6926
  ? Object.keys(client._integrations)
8119
6927
  : undefined;
6928
+
6929
+ const eventHint = { event_id, integrations };
6930
+
6931
+ if (client.emit) {
6932
+ client.emit('preprocessEvent', event, eventHint);
6933
+ }
6934
+
8120
6935
  const preparedEvent = (await prepareEvent(
8121
6936
  client.getOptions(),
8122
6937
  event,
8123
- { event_id, integrations },
6938
+ eventHint,
8124
6939
  scope,
6940
+ client,
8125
6941
  )) ;
8126
6942
 
8127
6943
  // If e.g. a global event processor returned null
@@ -8697,9 +7513,7 @@ class ReplayContainer {
8697
7513
 
8698
7514
  try {
8699
7515
  logInfo(
8700
- `[Replay] Stopping Replay${reason ? ` triggered by ${reason}` : ''} ${new Date().toISOString()} ${
8701
- this._isEnabled
8702
- }`,
7516
+ `[Replay] Stopping Replay${reason ? ` triggered by ${reason}` : ''}`,
8703
7517
  this._options._experiments.traceInternals,
8704
7518
  );
8705
7519
 
@@ -9632,6 +8446,8 @@ function getPrivacyOptions({
9632
8446
  // We are making the decision to make text and input selectors the same
9633
8447
  maskTextSelector: maskSelector,
9634
8448
  unmaskTextSelector: unmaskSelector,
8449
+ maskInputSelector: maskSelector,
8450
+ unmaskInputSelector: unmaskSelector,
9635
8451
 
9636
8452
  blockSelector: getOption(
9637
8453
  block,
@@ -9667,39 +8483,6 @@ function isElectronNodeRenderer() {
9667
8483
  return typeof process !== 'undefined' && (process ).type === 'renderer';
9668
8484
  }
9669
8485
 
9670
- /**
9671
- * Masks an attribute if necessary, otherwise return attribute value as-is.
9672
- */
9673
- function maskAttribute({
9674
- el,
9675
- key,
9676
- maskAttributes,
9677
- maskAllText,
9678
- privacyOptions,
9679
- value,
9680
- }) {
9681
- // We only mask attributes if `maskAllText` is true
9682
- if (!maskAllText) {
9683
- return value;
9684
- }
9685
-
9686
- // unmaskTextSelector takes precendence
9687
- if (privacyOptions.unmaskTextSelector && el.matches(privacyOptions.unmaskTextSelector)) {
9688
- return value;
9689
- }
9690
-
9691
- if (
9692
- maskAttributes.includes(key) ||
9693
- // Need to mask `value` attribute for `<input>` if it's a button-like
9694
- // type
9695
- (key === 'value' && el.tagName === 'INPUT' && ['submit', 'button'].includes(el.getAttribute('type') || ''))
9696
- ) {
9697
- return value.replace(/[\S]/g, '*');
9698
- }
9699
-
9700
- return value;
9701
- }
9702
-
9703
8486
  const MEDIA_SELECTORS =
9704
8487
  'img,image,svg,video,object,picture,embed,map,audio,link[rel="icon"],link[rel="apple-touch-icon"]';
9705
8488
 
@@ -9759,7 +8542,6 @@ class Replay {
9759
8542
  networkResponseHeaders = [],
9760
8543
 
9761
8544
  mask = [],
9762
- maskAttributes = ['title', 'placeholder'],
9763
8545
  unmask = [],
9764
8546
  block = [],
9765
8547
  unblock = [],
@@ -9783,36 +8565,25 @@ class Replay {
9783
8565
  } = {}) {
9784
8566
  this.name = Replay.id;
9785
8567
 
9786
- const privacyOptions = getPrivacyOptions({
9787
- mask,
9788
- unmask,
9789
- block,
9790
- unblock,
9791
- ignore,
9792
- blockClass,
9793
- blockSelector,
9794
- maskTextClass,
9795
- maskTextSelector,
9796
- ignoreClass,
9797
- });
9798
-
9799
8568
  this._recordingOptions = {
9800
8569
  maskAllInputs,
9801
8570
  maskAllText,
9802
8571
  maskInputOptions: { ...(maskInputOptions || {}), password: true },
9803
8572
  maskTextFn: maskFn,
9804
8573
  maskInputFn: maskFn,
9805
- maskAttributeFn: (key, value, el) =>
9806
- maskAttribute({
9807
- maskAttributes,
9808
- maskAllText,
9809
- privacyOptions,
9810
- key,
9811
- value,
9812
- el,
9813
- }),
9814
8574
 
9815
- ...privacyOptions,
8575
+ ...getPrivacyOptions({
8576
+ mask,
8577
+ unmask,
8578
+ block,
8579
+ unblock,
8580
+ ignore,
8581
+ blockClass,
8582
+ blockSelector,
8583
+ maskTextClass,
8584
+ maskTextSelector,
8585
+ ignoreClass,
8586
+ }),
9816
8587
 
9817
8588
  // Our defaults
9818
8589
  slimDOMOptions: 'all',
@@ -9822,16 +8593,6 @@ class Replay {
9822
8593
  // collect fonts, but be aware that `sentry.io` needs to be an allowed
9823
8594
  // origin for playback
9824
8595
  collectFonts: true,
9825
- errorHandler: (err) => {
9826
- try {
9827
- // @ts-expect-error Set this so that replay SDK can ignore errors originating from rrweb
9828
- err.__rrweb__ = true;
9829
- } catch (e) {
9830
- // avoid any potential hazards here
9831
- }
9832
- // return true to suppress throwing the error inside of rrweb
9833
- return true;
9834
- },
9835
8596
  };
9836
8597
 
9837
8598
  this._initialOptions = {