@posthog/rrweb-snapshot 0.0.55 → 0.0.57

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