@posthog/rrweb-snapshot 0.0.41 → 0.0.43

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