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