@posthog/rrweb-snapshot 0.0.30 → 0.0.34

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.
Files changed (39) hide show
  1. package/dist/record.cjs +983 -0
  2. package/dist/record.cjs.map +1 -0
  3. package/dist/record.d.cts +265 -0
  4. package/dist/record.d.ts +265 -0
  5. package/dist/record.js +984 -0
  6. package/dist/record.js.map +1 -0
  7. package/dist/record.umd.cjs +1559 -0
  8. package/dist/record.umd.cjs.map +7 -0
  9. package/dist/record.umd.min.cjs +32 -0
  10. package/dist/record.umd.min.cjs.map +7 -0
  11. package/dist/replay.cjs +4362 -0
  12. package/dist/replay.cjs.map +1 -0
  13. package/dist/replay.d.cts +219 -0
  14. package/dist/replay.d.ts +219 -0
  15. package/dist/replay.js +4363 -0
  16. package/dist/replay.js.map +1 -0
  17. package/dist/replay.umd.cjs +4968 -0
  18. package/dist/replay.umd.cjs.map +7 -0
  19. package/dist/replay.umd.min.cjs +60 -0
  20. package/dist/replay.umd.min.cjs.map +7 -0
  21. package/dist/rrweb-snapshot.cjs +38 -5816
  22. package/dist/rrweb-snapshot.cjs.map +1 -1
  23. package/dist/rrweb-snapshot.js +24 -5802
  24. package/dist/rrweb-snapshot.js.map +1 -1
  25. package/dist/rrweb-snapshot.umd.cjs +5590 -5468
  26. package/dist/rrweb-snapshot.umd.cjs.map +4 -4
  27. package/dist/rrweb-snapshot.umd.min.cjs +20 -20
  28. package/dist/rrweb-snapshot.umd.min.cjs.map +4 -4
  29. package/dist/types-FDk_ocpu.js +535 -0
  30. package/dist/types-FDk_ocpu.js.map +1 -0
  31. package/dist/types-pLXhbZlp.cjs +534 -0
  32. package/dist/types-pLXhbZlp.cjs.map +1 -0
  33. package/dist/types-pLXhbZlp.umd.cjs +567 -0
  34. package/dist/types-pLXhbZlp.umd.cjs.map +7 -0
  35. package/dist/types-pLXhbZlp.umd.min.cjs +32 -0
  36. package/dist/types-pLXhbZlp.umd.min.cjs.map +7 -0
  37. package/package.json +26 -6
  38. /package/dist/{index.d.cts → rrweb-snapshot.d.cts} +0 -0
  39. /package/dist/{index.d.ts → rrweb-snapshot.d.ts} +0 -0
package/dist/record.js ADDED
@@ -0,0 +1,984 @@
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-FDk_ocpu.js";
2
+ import { N, h, e, f, d, g, k, c } from "./types-FDk_ocpu.js";
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 = 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 c2 = attributeValue.charAt(pos);
54
+ if (c2 === "") {
55
+ output.push((url + descriptorsStr).trim());
56
+ break;
57
+ } else if (!inParens) {
58
+ if (c2 === ",") {
59
+ pos += 1;
60
+ output.push((url + descriptorsStr).trim());
61
+ break;
62
+ } else if (c2 === "(") {
63
+ inParens = true;
64
+ }
65
+ } else {
66
+ if (c2 === ")") {
67
+ inParens = false;
68
+ }
69
+ }
70
+ descriptorsStr += c2;
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 = recompressBase64Image(
112
+ img,
113
+ transformedValue,
114
+ dataURLOptions.type,
115
+ dataURLOptions.quality
116
+ );
117
+ }
118
+ if (dataURLOptions == null ? void 0 : dataURLOptions.maxBase64ImageLength) {
119
+ processedDataURL = 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 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 (e2) {
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(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(index.parentNode(node), regex, checkAncestors);
178
+ }
179
+ function needMaskingText(node, maskTextClass, maskTextSelector, checkAncestors) {
180
+ let el;
181
+ if (isElement(node)) {
182
+ el = node;
183
+ if (!index.childNodes(el).length) {
184
+ return false;
185
+ }
186
+ } else if (index.parentElement(node) === null) {
187
+ return false;
188
+ } else {
189
+ el = 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 (e2) {
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: NodeType.Document,
289
+ childNodes: [],
290
+ compatMode: n.compatMode
291
+ // probably "BackCompat"
292
+ };
293
+ } else {
294
+ return {
295
+ type: NodeType.Document,
296
+ childNodes: []
297
+ };
298
+ }
299
+ case n.DOCUMENT_TYPE_NODE:
300
+ return {
301
+ type: NodeType.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: NodeType.CDATA,
332
+ textContent: "",
333
+ rootId
334
+ };
335
+ case n.COMMENT_NODE:
336
+ return {
337
+ type: NodeType.Comment,
338
+ textContent: 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 = index.parentNode(n);
354
+ const parentTagName = parent && parent.tagName;
355
+ let text = 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 = 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 = 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, index.parentElement(n)) : text.replace(/[\S]/g, "*");
377
+ }
378
+ return {
379
+ type: NodeType.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
+ 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 = 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 || index.textContent(n) || "").trim().length) {
447
+ const cssText = 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 = maskInputValue({
459
+ element: n,
460
+ type: 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 (!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 (e2) {
585
+ }
586
+ return {
587
+ type: NodeType.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 === NodeType.Comment) {
606
+ return true;
607
+ } else if (sn.type === NodeType.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" && 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
+ function serializeNodeWithId(n, options) {
637
+ const {
638
+ doc,
639
+ mirror,
640
+ blockClass,
641
+ blockSelector,
642
+ maskTextClass,
643
+ maskTextSelector,
644
+ skipChild = false,
645
+ inlineStylesheet = true,
646
+ maskInputOptions = {},
647
+ maskTextFn,
648
+ maskInputFn,
649
+ slimDOMOptions,
650
+ dataURLOptions = {},
651
+ inlineImages = false,
652
+ recordCanvas = false,
653
+ onSerialize,
654
+ onIframeLoad,
655
+ iframeLoadTimeout = 5e3,
656
+ onStylesheetLoad,
657
+ stylesheetLoadTimeout = 5e3,
658
+ keepIframeSrcFn = () => false,
659
+ newlyAddedElement = false
660
+ } = options;
661
+ let { needsMask } = options;
662
+ let { preserveWhiteSpace = true } = options;
663
+ if (!needsMask) {
664
+ const checkAncestors = needsMask === void 0;
665
+ needsMask = needMaskingText(
666
+ n,
667
+ maskTextClass,
668
+ maskTextSelector,
669
+ checkAncestors
670
+ );
671
+ }
672
+ const _serializedNode = serializeNode(n, {
673
+ doc,
674
+ mirror,
675
+ blockClass,
676
+ blockSelector,
677
+ needsMask,
678
+ inlineStylesheet,
679
+ maskInputOptions,
680
+ maskTextFn,
681
+ maskInputFn,
682
+ dataURLOptions,
683
+ inlineImages,
684
+ recordCanvas,
685
+ keepIframeSrcFn,
686
+ newlyAddedElement
687
+ });
688
+ if (!_serializedNode) {
689
+ console.warn(n, "not serialized");
690
+ return null;
691
+ }
692
+ let id;
693
+ if (mirror.hasNode(n)) {
694
+ id = mirror.getId(n);
695
+ } else if (slimDOMExcluded(_serializedNode, slimDOMOptions) || !preserveWhiteSpace && _serializedNode.type === NodeType.Text && !_serializedNode.isStyle && !_serializedNode.textContent.replace(/^\s+|\s+$/gm, "").length) {
696
+ id = IGNORED_NODE;
697
+ } else {
698
+ id = genId();
699
+ }
700
+ const serializedNode = Object.assign(_serializedNode, { id });
701
+ mirror.add(n, serializedNode);
702
+ if (id === IGNORED_NODE) {
703
+ return null;
704
+ }
705
+ if (onSerialize) {
706
+ onSerialize(n);
707
+ }
708
+ let recordChild = !skipChild;
709
+ if (serializedNode.type === NodeType.Element) {
710
+ recordChild = recordChild && !serializedNode.needBlock;
711
+ delete serializedNode.needBlock;
712
+ const shadowRootEl = index.shadowRoot(n);
713
+ if (shadowRootEl && isNativeShadowDom(shadowRootEl))
714
+ serializedNode.isShadowHost = true;
715
+ }
716
+ if ((serializedNode.type === NodeType.Document || serializedNode.type === NodeType.Element) && recordChild) {
717
+ if (slimDOMOptions.headWhitespace && serializedNode.type === NodeType.Element && serializedNode.tagName === "head") {
718
+ preserveWhiteSpace = false;
719
+ }
720
+ const bypassOptions = {
721
+ doc,
722
+ mirror,
723
+ blockClass,
724
+ blockSelector,
725
+ needsMask,
726
+ maskTextClass,
727
+ maskTextSelector,
728
+ skipChild,
729
+ inlineStylesheet,
730
+ maskInputOptions,
731
+ maskTextFn,
732
+ maskInputFn,
733
+ slimDOMOptions,
734
+ dataURLOptions,
735
+ inlineImages,
736
+ recordCanvas,
737
+ preserveWhiteSpace,
738
+ onSerialize,
739
+ onIframeLoad,
740
+ iframeLoadTimeout,
741
+ onStylesheetLoad,
742
+ stylesheetLoadTimeout,
743
+ keepIframeSrcFn
744
+ };
745
+ if (serializedNode.type === NodeType.Element && serializedNode.tagName === "textarea" && serializedNode.attributes.value !== void 0) ;
746
+ else {
747
+ for (const childN of Array.from(index.childNodes(n))) {
748
+ const serializedChildNode = serializeNodeWithId(childN, bypassOptions);
749
+ if (serializedChildNode) {
750
+ serializedNode.childNodes.push(serializedChildNode);
751
+ }
752
+ }
753
+ }
754
+ let shadowRootEl = null;
755
+ if (isElement(n) && (shadowRootEl = index.shadowRoot(n))) {
756
+ for (const childN of Array.from(index.childNodes(shadowRootEl))) {
757
+ const serializedChildNode = serializeNodeWithId(childN, bypassOptions);
758
+ if (serializedChildNode) {
759
+ isNativeShadowDom(shadowRootEl) && (serializedChildNode.isShadow = true);
760
+ serializedNode.childNodes.push(serializedChildNode);
761
+ }
762
+ }
763
+ }
764
+ }
765
+ const parent = index.parentNode(n);
766
+ if (parent && isShadowRoot(parent) && isNativeShadowDom(parent)) {
767
+ serializedNode.isShadow = true;
768
+ }
769
+ if (serializedNode.type === NodeType.Element && serializedNode.tagName === "iframe") {
770
+ onceIframeLoaded(
771
+ n,
772
+ () => {
773
+ const iframeDoc = n.contentDocument;
774
+ if (iframeDoc && onIframeLoad) {
775
+ const serializedIframeNode = serializeNodeWithId(iframeDoc, {
776
+ doc: iframeDoc,
777
+ mirror,
778
+ blockClass,
779
+ blockSelector,
780
+ needsMask,
781
+ maskTextClass,
782
+ maskTextSelector,
783
+ skipChild: false,
784
+ inlineStylesheet,
785
+ maskInputOptions,
786
+ maskTextFn,
787
+ maskInputFn,
788
+ slimDOMOptions,
789
+ dataURLOptions,
790
+ inlineImages,
791
+ recordCanvas,
792
+ preserveWhiteSpace,
793
+ onSerialize,
794
+ onIframeLoad,
795
+ iframeLoadTimeout,
796
+ onStylesheetLoad,
797
+ stylesheetLoadTimeout,
798
+ keepIframeSrcFn
799
+ });
800
+ if (serializedIframeNode) {
801
+ onIframeLoad(
802
+ n,
803
+ serializedIframeNode
804
+ );
805
+ }
806
+ }
807
+ },
808
+ iframeLoadTimeout
809
+ );
810
+ }
811
+ 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")) {
812
+ onceStylesheetLoaded(
813
+ n,
814
+ () => {
815
+ if (onStylesheetLoad) {
816
+ const serializedLinkNode = serializeNodeWithId(n, {
817
+ doc,
818
+ mirror,
819
+ blockClass,
820
+ blockSelector,
821
+ needsMask,
822
+ maskTextClass,
823
+ maskTextSelector,
824
+ skipChild: false,
825
+ inlineStylesheet,
826
+ maskInputOptions,
827
+ maskTextFn,
828
+ maskInputFn,
829
+ slimDOMOptions,
830
+ dataURLOptions,
831
+ inlineImages,
832
+ recordCanvas,
833
+ preserveWhiteSpace,
834
+ onSerialize,
835
+ onIframeLoad,
836
+ iframeLoadTimeout,
837
+ onStylesheetLoad,
838
+ stylesheetLoadTimeout,
839
+ keepIframeSrcFn
840
+ });
841
+ if (serializedLinkNode) {
842
+ onStylesheetLoad(
843
+ n,
844
+ serializedLinkNode
845
+ );
846
+ }
847
+ }
848
+ },
849
+ stylesheetLoadTimeout
850
+ );
851
+ }
852
+ return serializedNode;
853
+ }
854
+ function snapshot(n, options) {
855
+ const {
856
+ mirror = new Mirror(),
857
+ blockClass = "rr-block",
858
+ blockSelector = null,
859
+ maskTextClass = "rr-mask",
860
+ maskTextSelector = null,
861
+ inlineStylesheet = true,
862
+ inlineImages = false,
863
+ recordCanvas = false,
864
+ maskAllInputs = false,
865
+ maskTextFn,
866
+ maskInputFn,
867
+ slimDOM = false,
868
+ dataURLOptions,
869
+ preserveWhiteSpace,
870
+ onSerialize,
871
+ onIframeLoad,
872
+ iframeLoadTimeout,
873
+ onStylesheetLoad,
874
+ stylesheetLoadTimeout,
875
+ keepIframeSrcFn = () => false
876
+ } = options || {};
877
+ const maskInputOptions = maskAllInputs === true ? {
878
+ color: true,
879
+ date: true,
880
+ "datetime-local": true,
881
+ email: true,
882
+ month: true,
883
+ number: true,
884
+ range: true,
885
+ search: true,
886
+ tel: true,
887
+ text: true,
888
+ time: true,
889
+ url: true,
890
+ week: true,
891
+ textarea: true,
892
+ select: true,
893
+ password: true
894
+ } : maskAllInputs === false ? {
895
+ password: true
896
+ } : maskAllInputs;
897
+ const slimDOMOptions = slimDOM === true || slimDOM === "all" ? (
898
+ // if true: set of sensible options that should not throw away any information
899
+ {
900
+ script: true,
901
+ comment: true,
902
+ headFavicon: true,
903
+ headWhitespace: true,
904
+ headMetaDescKeywords: slimDOM === "all",
905
+ // destructive
906
+ headMetaSocial: true,
907
+ headMetaRobots: true,
908
+ headMetaHttpEquiv: true,
909
+ headMetaAuthorship: true,
910
+ headMetaVerification: true
911
+ }
912
+ ) : slimDOM === false ? {} : slimDOM;
913
+ return serializeNodeWithId(n, {
914
+ doc: n,
915
+ mirror,
916
+ blockClass,
917
+ blockSelector,
918
+ maskTextClass,
919
+ maskTextSelector,
920
+ skipChild: false,
921
+ inlineStylesheet,
922
+ maskInputOptions,
923
+ maskTextFn,
924
+ maskInputFn,
925
+ slimDOMOptions,
926
+ dataURLOptions,
927
+ inlineImages,
928
+ recordCanvas,
929
+ preserveWhiteSpace,
930
+ onSerialize,
931
+ onIframeLoad,
932
+ iframeLoadTimeout,
933
+ onStylesheetLoad,
934
+ stylesheetLoadTimeout,
935
+ keepIframeSrcFn,
936
+ newlyAddedElement: false
937
+ });
938
+ }
939
+ function visitSnapshot(node, onVisit) {
940
+ function walk(current) {
941
+ onVisit(current);
942
+ if (current.type === NodeType.Document || current.type === NodeType.Element) {
943
+ current.childNodes.forEach(walk);
944
+ }
945
+ }
946
+ walk(node);
947
+ }
948
+ function cleanupSnapshot() {
949
+ _id = 1;
950
+ }
951
+ export {
952
+ IGNORED_NODE,
953
+ Mirror,
954
+ N as NodeType,
955
+ absolutifyURLs,
956
+ checkDataURLSize,
957
+ classMatchesRegex,
958
+ cleanupSnapshot,
959
+ h as createMirror,
960
+ e as escapeImportStatement,
961
+ extractFileExtension,
962
+ f as fixSafariColons,
963
+ genId,
964
+ getInputType,
965
+ ignoreAttribute,
966
+ is2DCanvasBlank,
967
+ d as isCSSImportRule,
968
+ g as isCSSStyleRule,
969
+ isElement,
970
+ isNativeShadowDom,
971
+ k as isNodeMetaEqual,
972
+ isShadowRoot,
973
+ maskInputValue,
974
+ needMaskingText,
975
+ recompressBase64Image,
976
+ serializeNodeWithId,
977
+ snapshot,
978
+ c as stringifyRule,
979
+ stringifyStylesheet,
980
+ toLowerCase,
981
+ transformAttribute,
982
+ visitSnapshot
983
+ };
984
+ //# sourceMappingURL=record.js.map