@posthog/rrweb-snapshot 0.0.41 → 0.0.42

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.
@@ -0,0 +1,995 @@
1
+ import { M as Mirror, q as NodeType, u as index, b as isNativeShadowDom, i as isElement, a as isShadowRoot, n as extractFileExtension, r as recompressBase64Image, p as checkDataURLSize, o as absolutifyURLs, s as stringifyStylesheet, t as toLowerCase, m as maskInputValue, l as getInputType, j as is2DCanvasBlank } from "./types-OLXvwyjP.js";
2
+ let _id = 1;
3
+ const tagNameRegex = new RegExp("[^a-z0-9-_:]");
4
+ const IGNORED_NODE = -2;
5
+ function genId() {
6
+ return _id++;
7
+ }
8
+ function getValidTagName(element) {
9
+ if (element instanceof HTMLFormElement) {
10
+ return "form";
11
+ }
12
+ const processedTagName = toLowerCase(element.tagName);
13
+ if (tagNameRegex.test(processedTagName)) {
14
+ return "div";
15
+ }
16
+ return processedTagName;
17
+ }
18
+ let canvasService;
19
+ let canvasCtx;
20
+ const SRCSET_NOT_SPACES = /^[^ \t\n\r\u000c]+/;
21
+ const SRCSET_COMMAS_OR_SPACES = /^[, \t\n\r\u000c]+/;
22
+ function getAbsoluteSrcsetString(doc, attributeValue) {
23
+ if (attributeValue.trim() === "") {
24
+ return attributeValue;
25
+ }
26
+ let pos = 0;
27
+ function collectCharacters(regEx) {
28
+ let chars;
29
+ const match = regEx.exec(attributeValue.substring(pos));
30
+ if (match) {
31
+ chars = match[0];
32
+ pos += chars.length;
33
+ return chars;
34
+ }
35
+ return "";
36
+ }
37
+ const output = [];
38
+ while (true) {
39
+ collectCharacters(SRCSET_COMMAS_OR_SPACES);
40
+ if (pos >= attributeValue.length) {
41
+ break;
42
+ }
43
+ let url = collectCharacters(SRCSET_NOT_SPACES);
44
+ if (url.slice(-1) === ",") {
45
+ url = absoluteToDoc(doc, url.substring(0, url.length - 1));
46
+ output.push(url);
47
+ } else {
48
+ let descriptorsStr = "";
49
+ url = absoluteToDoc(doc, url);
50
+ let inParens = false;
51
+ while (true) {
52
+ const c = attributeValue.charAt(pos);
53
+ if (c === "") {
54
+ output.push((url + descriptorsStr).trim());
55
+ break;
56
+ } else if (!inParens) {
57
+ if (c === ",") {
58
+ pos += 1;
59
+ output.push((url + descriptorsStr).trim());
60
+ break;
61
+ } else if (c === "(") {
62
+ inParens = true;
63
+ }
64
+ } else {
65
+ if (c === ")") {
66
+ inParens = false;
67
+ }
68
+ }
69
+ descriptorsStr += c;
70
+ pos += 1;
71
+ }
72
+ }
73
+ }
74
+ return output.join(", ");
75
+ }
76
+ const cachedDocument = /* @__PURE__ */ new WeakMap();
77
+ function absoluteToDoc(doc, attributeValue) {
78
+ if (!attributeValue || attributeValue.trim() === "") {
79
+ return attributeValue;
80
+ }
81
+ return getHref(doc, attributeValue);
82
+ }
83
+ function isSVGElement(el) {
84
+ return Boolean(el.tagName === "svg" || el.ownerSVGElement);
85
+ }
86
+ function getHref(doc, customHref) {
87
+ let a = cachedDocument.get(doc);
88
+ if (!a) {
89
+ a = doc.createElement("a");
90
+ cachedDocument.set(doc, a);
91
+ }
92
+ if (!customHref) {
93
+ customHref = "";
94
+ } else if (customHref.startsWith("blob:") || customHref.startsWith("data:")) {
95
+ return customHref;
96
+ }
97
+ a.setAttribute("href", customHref);
98
+ return a.href;
99
+ }
100
+ function transformAttribute(doc, tagName, name, value, element, dataURLOptions) {
101
+ if (!value) {
102
+ return value;
103
+ }
104
+ if (name === "src" || name === "href" && !(tagName === "use" && value[0] === "#")) {
105
+ const transformedValue = absoluteToDoc(doc, value);
106
+ if (tagName === "img" && transformedValue.startsWith("data:") && element) {
107
+ const img = element;
108
+ let processedDataURL = transformedValue;
109
+ if ((dataURLOptions == null ? void 0 : dataURLOptions.type) || (dataURLOptions == null ? void 0 : dataURLOptions.quality) !== void 0) {
110
+ processedDataURL = recompressBase64Image(
111
+ img,
112
+ transformedValue,
113
+ dataURLOptions.type,
114
+ dataURLOptions.quality
115
+ );
116
+ }
117
+ if (dataURLOptions == null ? void 0 : dataURLOptions.maxBase64ImageLength) {
118
+ processedDataURL = checkDataURLSize(
119
+ processedDataURL,
120
+ dataURLOptions.maxBase64ImageLength
121
+ );
122
+ }
123
+ return processedDataURL;
124
+ }
125
+ return transformedValue;
126
+ } else if (name === "xlink:href" && value[0] !== "#") {
127
+ return absoluteToDoc(doc, value);
128
+ } else if (name === "background" && (tagName === "table" || tagName === "td" || tagName === "th")) {
129
+ return absoluteToDoc(doc, value);
130
+ } else if (name === "srcset") {
131
+ return getAbsoluteSrcsetString(doc, value);
132
+ } else if (name === "style") {
133
+ return absolutifyURLs(value, getHref(doc));
134
+ } else if (tagName === "object" && name === "data") {
135
+ return absoluteToDoc(doc, value);
136
+ }
137
+ return value;
138
+ }
139
+ function ignoreAttribute(tagName, name, _value) {
140
+ return (tagName === "video" || tagName === "audio") && name === "autoplay";
141
+ }
142
+ function _isBlockedElement(element, blockClass, blockSelector) {
143
+ try {
144
+ if (typeof blockClass === "string") {
145
+ if (element.classList.contains(blockClass)) {
146
+ return true;
147
+ }
148
+ } else {
149
+ for (let eIndex = element.classList.length; eIndex--; ) {
150
+ const className = element.classList[eIndex];
151
+ if (blockClass.test(className)) {
152
+ return true;
153
+ }
154
+ }
155
+ }
156
+ if (blockSelector) {
157
+ return element.matches(blockSelector);
158
+ }
159
+ } catch (e) {
160
+ }
161
+ return false;
162
+ }
163
+ function classMatchesRegex(node, regex, checkAncestors) {
164
+ if (!node) return false;
165
+ if (node.nodeType !== node.ELEMENT_NODE) {
166
+ if (!checkAncestors) return false;
167
+ return classMatchesRegex(index.parentNode(node), regex, checkAncestors);
168
+ }
169
+ for (let eIndex = node.classList.length; eIndex--; ) {
170
+ const className = node.classList[eIndex];
171
+ if (regex.test(className)) {
172
+ return true;
173
+ }
174
+ }
175
+ if (!checkAncestors) return false;
176
+ return classMatchesRegex(index.parentNode(node), regex, checkAncestors);
177
+ }
178
+ function needMaskingText(node, maskTextClass, maskTextSelector, checkAncestors) {
179
+ let el;
180
+ if (isElement(node)) {
181
+ el = node;
182
+ if (!index.childNodes(el).length) {
183
+ return false;
184
+ }
185
+ } else if (index.parentElement(node) === null) {
186
+ return false;
187
+ } else {
188
+ el = index.parentElement(node);
189
+ }
190
+ try {
191
+ if (typeof maskTextClass === "string") {
192
+ if (checkAncestors) {
193
+ if (el.closest(`.${maskTextClass}`)) return true;
194
+ } else {
195
+ if (el.classList.contains(maskTextClass)) return true;
196
+ }
197
+ } else {
198
+ if (classMatchesRegex(el, maskTextClass, checkAncestors)) return true;
199
+ }
200
+ if (maskTextSelector) {
201
+ if (checkAncestors) {
202
+ if (el.closest(maskTextSelector)) return true;
203
+ } else {
204
+ if (el.matches(maskTextSelector)) return true;
205
+ }
206
+ }
207
+ } catch (e) {
208
+ }
209
+ return false;
210
+ }
211
+ function onceIframeLoaded(iframeEl, listener, iframeLoadTimeout) {
212
+ const win = iframeEl.contentWindow;
213
+ if (!win) {
214
+ return;
215
+ }
216
+ let fired = false;
217
+ let readyState;
218
+ try {
219
+ readyState = win.document.readyState;
220
+ } catch (error) {
221
+ return;
222
+ }
223
+ if (readyState !== "complete") {
224
+ const timer = setTimeout(() => {
225
+ if (!fired) {
226
+ listener();
227
+ fired = true;
228
+ }
229
+ }, iframeLoadTimeout);
230
+ iframeEl.addEventListener("load", () => {
231
+ clearTimeout(timer);
232
+ fired = true;
233
+ listener();
234
+ });
235
+ return;
236
+ }
237
+ const blankUrl = "about:blank";
238
+ if (win.location.href !== blankUrl || iframeEl.src === blankUrl || iframeEl.src === "") {
239
+ setTimeout(listener, 0);
240
+ return iframeEl.addEventListener("load", listener);
241
+ }
242
+ iframeEl.addEventListener("load", listener);
243
+ }
244
+ function onceStylesheetLoaded(link, listener, styleSheetLoadTimeout) {
245
+ let fired = false;
246
+ let styleSheetLoaded;
247
+ try {
248
+ styleSheetLoaded = link.sheet;
249
+ } catch (error) {
250
+ return;
251
+ }
252
+ if (styleSheetLoaded) return;
253
+ const timer = setTimeout(() => {
254
+ if (!fired) {
255
+ listener();
256
+ fired = true;
257
+ }
258
+ }, styleSheetLoadTimeout);
259
+ link.addEventListener("load", () => {
260
+ clearTimeout(timer);
261
+ fired = true;
262
+ listener();
263
+ });
264
+ }
265
+ function serializeNode(n, options) {
266
+ const {
267
+ doc,
268
+ mirror,
269
+ blockClass,
270
+ blockSelector,
271
+ needsMask,
272
+ inlineStylesheet,
273
+ maskInputOptions = {},
274
+ maskTextFn,
275
+ maskInputFn,
276
+ dataURLOptions = {},
277
+ inlineImages,
278
+ recordCanvas,
279
+ keepIframeSrcFn,
280
+ newlyAddedElement = false
281
+ } = options;
282
+ const rootId = getRootId(doc, mirror);
283
+ switch (n.nodeType) {
284
+ case n.DOCUMENT_NODE:
285
+ if (n.compatMode !== "CSS1Compat") {
286
+ return {
287
+ type: NodeType.Document,
288
+ childNodes: [],
289
+ compatMode: n.compatMode
290
+ // probably "BackCompat"
291
+ };
292
+ } else {
293
+ return {
294
+ type: NodeType.Document,
295
+ childNodes: []
296
+ };
297
+ }
298
+ case n.DOCUMENT_TYPE_NODE:
299
+ return {
300
+ type: NodeType.DocumentType,
301
+ name: n.name,
302
+ publicId: n.publicId,
303
+ systemId: n.systemId,
304
+ rootId
305
+ };
306
+ case n.ELEMENT_NODE:
307
+ return serializeElementNode(n, {
308
+ doc,
309
+ blockClass,
310
+ blockSelector,
311
+ inlineStylesheet,
312
+ maskInputOptions,
313
+ maskInputFn,
314
+ dataURLOptions,
315
+ inlineImages,
316
+ recordCanvas,
317
+ keepIframeSrcFn,
318
+ newlyAddedElement,
319
+ rootId
320
+ });
321
+ case n.TEXT_NODE:
322
+ return serializeTextNode(n, {
323
+ doc,
324
+ needsMask,
325
+ maskTextFn,
326
+ rootId
327
+ });
328
+ case n.CDATA_SECTION_NODE:
329
+ return {
330
+ type: NodeType.CDATA,
331
+ textContent: "",
332
+ rootId
333
+ };
334
+ case n.COMMENT_NODE:
335
+ return {
336
+ type: NodeType.Comment,
337
+ textContent: index.textContent(n) || "",
338
+ rootId
339
+ };
340
+ default:
341
+ return false;
342
+ }
343
+ }
344
+ function getRootId(doc, mirror) {
345
+ if (!mirror.hasNode(doc)) return void 0;
346
+ const docId = mirror.getId(doc);
347
+ return docId === 1 ? void 0 : docId;
348
+ }
349
+ function serializeTextNode(n, options) {
350
+ var _a;
351
+ const { needsMask, maskTextFn, rootId } = options;
352
+ const parent = index.parentNode(n);
353
+ const parentTagName = parent && parent.tagName;
354
+ let text = index.textContent(n);
355
+ const isStyle = parentTagName === "STYLE" ? true : void 0;
356
+ const isScript = parentTagName === "SCRIPT" ? true : void 0;
357
+ if (isStyle && text) {
358
+ try {
359
+ if (n.nextSibling || n.previousSibling) {
360
+ } else if ((_a = parent.sheet) == null ? void 0 : _a.cssRules) {
361
+ text = stringifyStylesheet(parent.sheet);
362
+ }
363
+ } catch (err) {
364
+ console.warn(
365
+ `Cannot get CSS styles from text's parentNode. Error: ${err}`,
366
+ n
367
+ );
368
+ }
369
+ text = absolutifyURLs(text, getHref(options.doc));
370
+ }
371
+ if (isScript) {
372
+ text = "SCRIPT_PLACEHOLDER";
373
+ }
374
+ if (!isStyle && !isScript && text && needsMask) {
375
+ text = maskTextFn ? maskTextFn(text, index.parentElement(n)) : text.replace(/[\S]/g, "*");
376
+ }
377
+ return {
378
+ type: NodeType.Text,
379
+ textContent: text || "",
380
+ isStyle,
381
+ rootId
382
+ };
383
+ }
384
+ function findStylesheet(doc, href) {
385
+ return Array.from(doc.styleSheets).find((s) => s.href === href);
386
+ }
387
+ function hrefFrom(n) {
388
+ return n.href;
389
+ }
390
+ function serializeElementNode(n, options) {
391
+ var _a, _b;
392
+ const {
393
+ doc,
394
+ blockClass,
395
+ blockSelector,
396
+ inlineStylesheet,
397
+ maskInputOptions = {},
398
+ maskInputFn,
399
+ dataURLOptions = {},
400
+ inlineImages,
401
+ recordCanvas,
402
+ keepIframeSrcFn,
403
+ newlyAddedElement = false,
404
+ rootId
405
+ } = options;
406
+ const needBlock = _isBlockedElement(n, blockClass, blockSelector);
407
+ const tagName = getValidTagName(n);
408
+ let attributes = {};
409
+ const len = n.attributes.length;
410
+ for (let i = 0; i < len; i++) {
411
+ const attr = n.attributes[i];
412
+ if (!ignoreAttribute(tagName, attr.name, attr.value)) {
413
+ attributes[attr.name] = transformAttribute(
414
+ doc,
415
+ tagName,
416
+ toLowerCase(attr.name),
417
+ attr.value,
418
+ n,
419
+ dataURLOptions
420
+ );
421
+ }
422
+ }
423
+ if (tagName === "link" && inlineStylesheet) {
424
+ const href = hrefFrom(n);
425
+ if (href) {
426
+ let stylesheet = findStylesheet(doc, href);
427
+ if (!stylesheet && href.includes(".css")) {
428
+ const rootDomain = window.location.origin;
429
+ const stylesheetPath = href.replace(window.location.href, "");
430
+ const potentialStylesheetHref = rootDomain + "/" + stylesheetPath;
431
+ stylesheet = findStylesheet(doc, potentialStylesheetHref);
432
+ }
433
+ let cssText = null;
434
+ if (stylesheet) {
435
+ cssText = stringifyStylesheet(stylesheet);
436
+ }
437
+ if (cssText) {
438
+ delete attributes.rel;
439
+ delete attributes.href;
440
+ attributes._cssText = cssText;
441
+ }
442
+ }
443
+ }
444
+ if (tagName === "style" && n.sheet && // TODO: Currently we only try to get dynamic stylesheet when it is an empty style element
445
+ !(n.innerText || index.textContent(n) || "").trim().length) {
446
+ const cssText = stringifyStylesheet(
447
+ n.sheet
448
+ );
449
+ if (cssText) {
450
+ attributes._cssText = cssText;
451
+ }
452
+ }
453
+ if (tagName === "input" || tagName === "textarea" || tagName === "select") {
454
+ const value = n.value;
455
+ const checked = n.checked;
456
+ if (attributes.type !== "radio" && attributes.type !== "checkbox" && attributes.type !== "submit" && attributes.type !== "button" && value) {
457
+ attributes.value = maskInputValue({
458
+ element: n,
459
+ type: getInputType(n),
460
+ tagName,
461
+ value,
462
+ maskInputOptions,
463
+ maskInputFn
464
+ });
465
+ } else if (checked) {
466
+ attributes.checked = checked;
467
+ }
468
+ }
469
+ if (tagName === "option") {
470
+ if (n.selected && !maskInputOptions["select"]) {
471
+ attributes.selected = true;
472
+ } else {
473
+ delete attributes.selected;
474
+ }
475
+ }
476
+ if (tagName === "dialog" && n.open) {
477
+ try {
478
+ attributes.rr_open_mode = n.matches("dialog:modal") ? "modal" : "non-modal";
479
+ } catch {
480
+ attributes.rr_open_mode = "modal";
481
+ attributes.ph_rr_could_not_detect_modal = true;
482
+ }
483
+ }
484
+ if (tagName === "canvas" && recordCanvas) {
485
+ if (n.__context === "2d") {
486
+ if (!is2DCanvasBlank(n)) {
487
+ attributes.rr_dataURL = n.toDataURL(
488
+ dataURLOptions.type,
489
+ dataURLOptions.quality
490
+ );
491
+ }
492
+ } else if (!("__context" in n)) {
493
+ const canvasDataURL = n.toDataURL(
494
+ dataURLOptions.type,
495
+ dataURLOptions.quality
496
+ );
497
+ const blankCanvas = doc.createElement("canvas");
498
+ blankCanvas.width = n.width;
499
+ blankCanvas.height = n.height;
500
+ const blankCanvasDataURL = blankCanvas.toDataURL(
501
+ dataURLOptions.type,
502
+ dataURLOptions.quality
503
+ );
504
+ if (canvasDataURL !== blankCanvasDataURL) {
505
+ attributes.rr_dataURL = canvasDataURL;
506
+ }
507
+ }
508
+ }
509
+ if (tagName === "img" && inlineImages) {
510
+ if (!canvasService) {
511
+ canvasService = doc.createElement("canvas");
512
+ canvasCtx = canvasService.getContext("2d");
513
+ }
514
+ const image = n;
515
+ const imageSrc = image.currentSrc || image.getAttribute("src") || "<unknown-src>";
516
+ const priorCrossOrigin = image.crossOrigin;
517
+ const recordInlineImage = () => {
518
+ image.removeEventListener("load", recordInlineImage);
519
+ try {
520
+ canvasService.width = image.naturalWidth;
521
+ canvasService.height = image.naturalHeight;
522
+ canvasCtx.drawImage(image, 0, 0);
523
+ attributes.rr_dataURL = canvasService.toDataURL(
524
+ dataURLOptions.type,
525
+ dataURLOptions.quality
526
+ );
527
+ } catch (err) {
528
+ if (image.crossOrigin !== "anonymous") {
529
+ image.crossOrigin = "anonymous";
530
+ if (image.complete && image.naturalWidth !== 0)
531
+ recordInlineImage();
532
+ else image.addEventListener("load", recordInlineImage);
533
+ return;
534
+ } else {
535
+ console.warn(
536
+ `Cannot inline img src=${imageSrc}! Error: ${err}`
537
+ );
538
+ }
539
+ }
540
+ if (image.crossOrigin === "anonymous") {
541
+ priorCrossOrigin ? attributes.crossOrigin = priorCrossOrigin : image.removeAttribute("crossorigin");
542
+ }
543
+ };
544
+ if (image.complete && image.naturalWidth !== 0) recordInlineImage();
545
+ else image.addEventListener("load", recordInlineImage);
546
+ }
547
+ if (tagName === "audio" || tagName === "video") {
548
+ const mediaAttributes = attributes;
549
+ mediaAttributes.rr_mediaState = n.paused ? "paused" : "played";
550
+ mediaAttributes.rr_mediaCurrentTime = n.currentTime;
551
+ mediaAttributes.rr_mediaPlaybackRate = n.playbackRate;
552
+ mediaAttributes.rr_mediaMuted = n.muted;
553
+ mediaAttributes.rr_mediaLoop = n.loop;
554
+ mediaAttributes.rr_mediaVolume = n.volume;
555
+ }
556
+ if (!newlyAddedElement) {
557
+ if (n.scrollLeft) {
558
+ attributes.rr_scrollLeft = n.scrollLeft;
559
+ }
560
+ if (n.scrollTop) {
561
+ attributes.rr_scrollTop = n.scrollTop;
562
+ }
563
+ }
564
+ if (needBlock) {
565
+ const { width, height, left, top } = n.getBoundingClientRect();
566
+ attributes = {
567
+ class: attributes.class,
568
+ rr_width: `${width}px`,
569
+ rr_height: `${height}px`,
570
+ rr_left: `${Math.floor(left + (((_a = doc.defaultView) == null ? void 0 : _a.scrollX) || 0))}px`,
571
+ rr_top: `${Math.floor(top + (((_b = doc.defaultView) == null ? void 0 : _b.scrollY) || 0))}px`
572
+ };
573
+ }
574
+ if (tagName === "iframe" && !keepIframeSrcFn(attributes.src)) {
575
+ if (!n.contentDocument) {
576
+ attributes.rr_src = attributes.src;
577
+ }
578
+ delete attributes.src;
579
+ }
580
+ let isCustomElement;
581
+ try {
582
+ if (customElements.get(tagName)) isCustomElement = true;
583
+ } catch (e) {
584
+ }
585
+ return {
586
+ type: NodeType.Element,
587
+ tagName,
588
+ attributes,
589
+ childNodes: [],
590
+ isSVG: isSVGElement(n) || void 0,
591
+ needBlock,
592
+ rootId,
593
+ isCustom: isCustomElement
594
+ };
595
+ }
596
+ function lowerIfExists(maybeAttr) {
597
+ if (maybeAttr === void 0 || maybeAttr === null) {
598
+ return "";
599
+ } else {
600
+ return maybeAttr.toLowerCase();
601
+ }
602
+ }
603
+ function slimDOMExcluded(sn, slimDOMOptions) {
604
+ if (slimDOMOptions.comment && sn.type === NodeType.Comment) {
605
+ return true;
606
+ } else if (sn.type === NodeType.Element) {
607
+ if (slimDOMOptions.script && // script tag
608
+ (sn.tagName === "script" || // (module)preload link
609
+ sn.tagName === "link" && (sn.attributes.rel === "preload" && sn.attributes.as === "script" || sn.attributes.rel === "modulepreload") || // prefetch link
610
+ sn.tagName === "link" && sn.attributes.rel === "prefetch" && typeof sn.attributes.href === "string" && extractFileExtension(sn.attributes.href) === "js")) {
611
+ return true;
612
+ } else if (slimDOMOptions.headFavicon && (sn.tagName === "link" && sn.attributes.rel === "shortcut icon" || sn.tagName === "meta" && (lowerIfExists(sn.attributes.name).match(
613
+ /^msapplication-tile(image|color)$/
614
+ ) || lowerIfExists(sn.attributes.name) === "application-name" || lowerIfExists(sn.attributes.rel) === "icon" || lowerIfExists(sn.attributes.rel) === "apple-touch-icon" || lowerIfExists(sn.attributes.rel) === "shortcut icon"))) {
615
+ return true;
616
+ } else if (sn.tagName === "meta") {
617
+ if (slimDOMOptions.headMetaDescKeywords && lowerIfExists(sn.attributes.name).match(/^description|keywords$/)) {
618
+ return true;
619
+ } else if (slimDOMOptions.headMetaSocial && (lowerIfExists(sn.attributes.property).match(/^(og|twitter|fb):/) || // og = opengraph (facebook)
620
+ lowerIfExists(sn.attributes.name).match(/^(og|twitter):/) || lowerIfExists(sn.attributes.name) === "pinterest")) {
621
+ return true;
622
+ } else if (slimDOMOptions.headMetaRobots && (lowerIfExists(sn.attributes.name) === "robots" || lowerIfExists(sn.attributes.name) === "googlebot" || lowerIfExists(sn.attributes.name) === "bingbot")) {
623
+ return true;
624
+ } else if (slimDOMOptions.headMetaHttpEquiv && sn.attributes["http-equiv"] !== void 0) {
625
+ return true;
626
+ } else if (slimDOMOptions.headMetaAuthorship && (lowerIfExists(sn.attributes.name) === "author" || lowerIfExists(sn.attributes.name) === "generator" || lowerIfExists(sn.attributes.name) === "framework" || lowerIfExists(sn.attributes.name) === "publisher" || lowerIfExists(sn.attributes.name) === "progid" || lowerIfExists(sn.attributes.property).match(/^article:/) || lowerIfExists(sn.attributes.property).match(/^product:/))) {
627
+ return true;
628
+ } else if (slimDOMOptions.headMetaVerification && (lowerIfExists(sn.attributes.name) === "google-site-verification" || lowerIfExists(sn.attributes.name) === "yandex-verification" || lowerIfExists(sn.attributes.name) === "csrf-token" || lowerIfExists(sn.attributes.name) === "p:domain_verify" || lowerIfExists(sn.attributes.name) === "verify-v1" || lowerIfExists(sn.attributes.name) === "verification" || lowerIfExists(sn.attributes.name) === "shopify-checkout-api-token")) {
629
+ return true;
630
+ }
631
+ }
632
+ }
633
+ return false;
634
+ }
635
+ const DEFAULT_MAX_DEPTH = 50;
636
+ let _maxDepthWarned = false;
637
+ let _maxDepthReached = false;
638
+ function wasMaxDepthReached() {
639
+ return _maxDepthReached;
640
+ }
641
+ function resetMaxDepthState() {
642
+ _maxDepthReached = false;
643
+ _maxDepthWarned = false;
644
+ }
645
+ function serializeNodeWithId(n, options) {
646
+ const {
647
+ doc,
648
+ mirror,
649
+ blockClass,
650
+ blockSelector,
651
+ maskTextClass,
652
+ maskTextSelector,
653
+ skipChild = false,
654
+ inlineStylesheet = true,
655
+ maskInputOptions = {},
656
+ maskTextFn,
657
+ maskInputFn,
658
+ slimDOMOptions,
659
+ dataURLOptions = {},
660
+ inlineImages = false,
661
+ recordCanvas = false,
662
+ onSerialize,
663
+ onIframeLoad,
664
+ iframeLoadTimeout = 5e3,
665
+ onStylesheetLoad,
666
+ stylesheetLoadTimeout = 5e3,
667
+ keepIframeSrcFn = () => false,
668
+ newlyAddedElement = false,
669
+ depth = 0,
670
+ maxDepth = DEFAULT_MAX_DEPTH
671
+ } = options;
672
+ let { needsMask } = options;
673
+ let { preserveWhiteSpace = true } = options;
674
+ if (depth >= maxDepth) {
675
+ _maxDepthReached = true;
676
+ if (!_maxDepthWarned) {
677
+ _maxDepthWarned = true;
678
+ console.warn(
679
+ `[rrweb-snapshot] DOM tree depth exceeded max depth of ${maxDepth}. Children beyond this depth will not be recorded. This may indicate deeply nested DOM structures.`
680
+ );
681
+ }
682
+ return null;
683
+ }
684
+ if (!needsMask) {
685
+ const checkAncestors = needsMask === void 0;
686
+ needsMask = needMaskingText(
687
+ n,
688
+ maskTextClass,
689
+ maskTextSelector,
690
+ checkAncestors
691
+ );
692
+ }
693
+ const _serializedNode = serializeNode(n, {
694
+ doc,
695
+ mirror,
696
+ blockClass,
697
+ blockSelector,
698
+ needsMask,
699
+ inlineStylesheet,
700
+ maskInputOptions,
701
+ maskTextFn,
702
+ maskInputFn,
703
+ dataURLOptions,
704
+ inlineImages,
705
+ recordCanvas,
706
+ keepIframeSrcFn,
707
+ newlyAddedElement
708
+ });
709
+ if (!_serializedNode) {
710
+ console.warn(n, "not serialized");
711
+ return null;
712
+ }
713
+ let id;
714
+ if (mirror.hasNode(n)) {
715
+ id = mirror.getId(n);
716
+ } else if (slimDOMExcluded(_serializedNode, slimDOMOptions) || !preserveWhiteSpace && _serializedNode.type === NodeType.Text && !_serializedNode.isStyle && !_serializedNode.textContent.replace(/^\s+|\s+$/gm, "").length) {
717
+ id = IGNORED_NODE;
718
+ } else {
719
+ id = genId();
720
+ }
721
+ const serializedNode = Object.assign(_serializedNode, { id });
722
+ mirror.add(n, serializedNode);
723
+ if (id === IGNORED_NODE) {
724
+ return null;
725
+ }
726
+ if (onSerialize) {
727
+ onSerialize(n);
728
+ }
729
+ let recordChild = !skipChild;
730
+ if (serializedNode.type === NodeType.Element) {
731
+ recordChild = recordChild && !serializedNode.needBlock;
732
+ delete serializedNode.needBlock;
733
+ const shadowRootEl = index.shadowRoot(n);
734
+ if (shadowRootEl && isNativeShadowDom(shadowRootEl))
735
+ serializedNode.isShadowHost = true;
736
+ }
737
+ if ((serializedNode.type === NodeType.Document || serializedNode.type === NodeType.Element) && recordChild) {
738
+ if (slimDOMOptions.headWhitespace && serializedNode.type === NodeType.Element && serializedNode.tagName === "head") {
739
+ preserveWhiteSpace = false;
740
+ }
741
+ const bypassOptions = {
742
+ doc,
743
+ mirror,
744
+ blockClass,
745
+ blockSelector,
746
+ needsMask,
747
+ maskTextClass,
748
+ maskTextSelector,
749
+ skipChild,
750
+ inlineStylesheet,
751
+ maskInputOptions,
752
+ maskTextFn,
753
+ maskInputFn,
754
+ slimDOMOptions,
755
+ dataURLOptions,
756
+ inlineImages,
757
+ recordCanvas,
758
+ preserveWhiteSpace,
759
+ onSerialize,
760
+ onIframeLoad,
761
+ iframeLoadTimeout,
762
+ onStylesheetLoad,
763
+ stylesheetLoadTimeout,
764
+ keepIframeSrcFn,
765
+ depth: depth + 1,
766
+ maxDepth
767
+ };
768
+ if (serializedNode.type === NodeType.Element && serializedNode.tagName === "textarea" && serializedNode.attributes.value !== void 0) ;
769
+ else {
770
+ for (const childN of Array.from(index.childNodes(n))) {
771
+ const serializedChildNode = serializeNodeWithId(childN, bypassOptions);
772
+ if (serializedChildNode) {
773
+ serializedNode.childNodes.push(serializedChildNode);
774
+ }
775
+ }
776
+ }
777
+ let shadowRootEl = null;
778
+ if (isElement(n) && (shadowRootEl = index.shadowRoot(n))) {
779
+ for (const childN of Array.from(index.childNodes(shadowRootEl))) {
780
+ const serializedChildNode = serializeNodeWithId(childN, bypassOptions);
781
+ if (serializedChildNode) {
782
+ isNativeShadowDom(shadowRootEl) && (serializedChildNode.isShadow = true);
783
+ serializedNode.childNodes.push(serializedChildNode);
784
+ }
785
+ }
786
+ }
787
+ }
788
+ const parent = index.parentNode(n);
789
+ if (parent && isShadowRoot(parent) && isNativeShadowDom(parent)) {
790
+ serializedNode.isShadow = true;
791
+ }
792
+ if (serializedNode.type === NodeType.Element && serializedNode.tagName === "iframe") {
793
+ onceIframeLoaded(
794
+ n,
795
+ () => {
796
+ const iframeDoc = n.contentDocument;
797
+ if (iframeDoc && onIframeLoad) {
798
+ const serializedIframeNode = serializeNodeWithId(iframeDoc, {
799
+ doc: iframeDoc,
800
+ mirror,
801
+ blockClass,
802
+ blockSelector,
803
+ needsMask,
804
+ maskTextClass,
805
+ maskTextSelector,
806
+ skipChild: false,
807
+ inlineStylesheet,
808
+ maskInputOptions,
809
+ maskTextFn,
810
+ maskInputFn,
811
+ slimDOMOptions,
812
+ dataURLOptions,
813
+ inlineImages,
814
+ recordCanvas,
815
+ preserveWhiteSpace,
816
+ onSerialize,
817
+ onIframeLoad,
818
+ iframeLoadTimeout,
819
+ onStylesheetLoad,
820
+ stylesheetLoadTimeout,
821
+ keepIframeSrcFn,
822
+ depth: depth + 1,
823
+ maxDepth
824
+ });
825
+ if (serializedIframeNode) {
826
+ onIframeLoad(
827
+ n,
828
+ serializedIframeNode
829
+ );
830
+ }
831
+ }
832
+ },
833
+ iframeLoadTimeout
834
+ );
835
+ }
836
+ if (serializedNode.type === NodeType.Element && serializedNode.tagName === "link" && typeof serializedNode.attributes.rel === "string" && (serializedNode.attributes.rel === "stylesheet" || serializedNode.attributes.rel === "preload" && typeof serializedNode.attributes.href === "string" && extractFileExtension(serializedNode.attributes.href) === "css")) {
837
+ onceStylesheetLoaded(
838
+ n,
839
+ () => {
840
+ if (onStylesheetLoad) {
841
+ const serializedLinkNode = serializeNodeWithId(n, {
842
+ doc,
843
+ mirror,
844
+ blockClass,
845
+ blockSelector,
846
+ needsMask,
847
+ maskTextClass,
848
+ maskTextSelector,
849
+ skipChild: false,
850
+ inlineStylesheet,
851
+ maskInputOptions,
852
+ maskTextFn,
853
+ maskInputFn,
854
+ slimDOMOptions,
855
+ dataURLOptions,
856
+ inlineImages,
857
+ recordCanvas,
858
+ preserveWhiteSpace,
859
+ onSerialize,
860
+ onIframeLoad,
861
+ iframeLoadTimeout,
862
+ onStylesheetLoad,
863
+ stylesheetLoadTimeout,
864
+ keepIframeSrcFn,
865
+ depth,
866
+ maxDepth
867
+ });
868
+ if (serializedLinkNode) {
869
+ onStylesheetLoad(
870
+ n,
871
+ serializedLinkNode
872
+ );
873
+ }
874
+ }
875
+ },
876
+ stylesheetLoadTimeout
877
+ );
878
+ }
879
+ return serializedNode;
880
+ }
881
+ function snapshot(n, options) {
882
+ const {
883
+ mirror = new Mirror(),
884
+ blockClass = "rr-block",
885
+ blockSelector = null,
886
+ maskTextClass = "rr-mask",
887
+ maskTextSelector = null,
888
+ inlineStylesheet = true,
889
+ inlineImages = false,
890
+ recordCanvas = false,
891
+ maskAllInputs = false,
892
+ maskTextFn,
893
+ maskInputFn,
894
+ slimDOM = false,
895
+ dataURLOptions,
896
+ preserveWhiteSpace,
897
+ onSerialize,
898
+ onIframeLoad,
899
+ iframeLoadTimeout,
900
+ onStylesheetLoad,
901
+ stylesheetLoadTimeout,
902
+ keepIframeSrcFn = () => false,
903
+ maxDepth
904
+ } = options || {};
905
+ const maskInputOptions = maskAllInputs === true ? {
906
+ color: true,
907
+ date: true,
908
+ "datetime-local": true,
909
+ email: true,
910
+ month: true,
911
+ number: true,
912
+ range: true,
913
+ search: true,
914
+ tel: true,
915
+ text: true,
916
+ time: true,
917
+ url: true,
918
+ week: true,
919
+ textarea: true,
920
+ select: true,
921
+ password: true
922
+ } : maskAllInputs === false ? {
923
+ password: true
924
+ } : maskAllInputs;
925
+ const slimDOMOptions = slimDOM === true || slimDOM === "all" ? (
926
+ // if true: set of sensible options that should not throw away any information
927
+ {
928
+ script: true,
929
+ comment: true,
930
+ headFavicon: true,
931
+ headWhitespace: true,
932
+ headMetaDescKeywords: slimDOM === "all",
933
+ // destructive
934
+ headMetaSocial: true,
935
+ headMetaRobots: true,
936
+ headMetaHttpEquiv: true,
937
+ headMetaAuthorship: true,
938
+ headMetaVerification: true
939
+ }
940
+ ) : slimDOM === false ? {} : slimDOM;
941
+ return serializeNodeWithId(n, {
942
+ doc: n,
943
+ mirror,
944
+ blockClass,
945
+ blockSelector,
946
+ maskTextClass,
947
+ maskTextSelector,
948
+ skipChild: false,
949
+ inlineStylesheet,
950
+ maskInputOptions,
951
+ maskTextFn,
952
+ maskInputFn,
953
+ slimDOMOptions,
954
+ dataURLOptions,
955
+ inlineImages,
956
+ recordCanvas,
957
+ preserveWhiteSpace,
958
+ onSerialize,
959
+ onIframeLoad,
960
+ iframeLoadTimeout,
961
+ onStylesheetLoad,
962
+ stylesheetLoadTimeout,
963
+ keepIframeSrcFn,
964
+ newlyAddedElement: false,
965
+ maxDepth
966
+ });
967
+ }
968
+ function visitSnapshot(node, onVisit) {
969
+ function walk(current) {
970
+ onVisit(current);
971
+ if (current.type === NodeType.Document || current.type === NodeType.Element) {
972
+ current.childNodes.forEach(walk);
973
+ }
974
+ }
975
+ walk(node);
976
+ }
977
+ function cleanupSnapshot() {
978
+ _id = 1;
979
+ }
980
+ export {
981
+ DEFAULT_MAX_DEPTH as D,
982
+ IGNORED_NODE as I,
983
+ serializeNodeWithId as a,
984
+ classMatchesRegex as b,
985
+ cleanupSnapshot as c,
986
+ genId as g,
987
+ ignoreAttribute as i,
988
+ needMaskingText as n,
989
+ resetMaxDepthState as r,
990
+ snapshot as s,
991
+ transformAttribute as t,
992
+ visitSnapshot as v,
993
+ wasMaxDepthReached as w
994
+ };
995
+ //# sourceMappingURL=record-B2nV9UFB.js.map