@posthog/rrweb-snapshot 0.0.40 → 0.0.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/record.cjs CHANGED
@@ -1,954 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const record = require("./record-oACzRSl-.cjs");
3
4
  const types = require("./types-B7TTv7Jc.cjs");
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" || lowerIfExists(sn.attributes.rel) === "icon" || lowerIfExists(sn.attributes.rel) === "apple-touch-icon" || lowerIfExists(sn.attributes.rel) === "shortcut icon"))) {
617
- return true;
618
- } else if (sn.tagName === "meta") {
619
- if (slimDOMOptions.headMetaDescKeywords && lowerIfExists(sn.attributes.name).match(/^description|keywords$/)) {
620
- return true;
621
- } else if (slimDOMOptions.headMetaSocial && (lowerIfExists(sn.attributes.property).match(/^(og|twitter|fb):/) || // og = opengraph (facebook)
622
- lowerIfExists(sn.attributes.name).match(/^(og|twitter):/) || lowerIfExists(sn.attributes.name) === "pinterest")) {
623
- return true;
624
- } else if (slimDOMOptions.headMetaRobots && (lowerIfExists(sn.attributes.name) === "robots" || lowerIfExists(sn.attributes.name) === "googlebot" || lowerIfExists(sn.attributes.name) === "bingbot")) {
625
- return true;
626
- } else if (slimDOMOptions.headMetaHttpEquiv && sn.attributes["http-equiv"] !== void 0) {
627
- return true;
628
- } 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:/))) {
629
- return true;
630
- } 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")) {
631
- return true;
632
- }
633
- }
634
- }
635
- return false;
636
- }
637
- function serializeNodeWithId(n, options) {
638
- const {
639
- doc,
640
- mirror,
641
- blockClass,
642
- blockSelector,
643
- maskTextClass,
644
- maskTextSelector,
645
- skipChild = false,
646
- inlineStylesheet = true,
647
- maskInputOptions = {},
648
- maskTextFn,
649
- maskInputFn,
650
- slimDOMOptions,
651
- dataURLOptions = {},
652
- inlineImages = false,
653
- recordCanvas = false,
654
- onSerialize,
655
- onIframeLoad,
656
- iframeLoadTimeout = 5e3,
657
- onStylesheetLoad,
658
- stylesheetLoadTimeout = 5e3,
659
- keepIframeSrcFn = () => false,
660
- newlyAddedElement = false
661
- } = options;
662
- let { needsMask } = options;
663
- let { preserveWhiteSpace = true } = options;
664
- if (!needsMask) {
665
- const checkAncestors = needsMask === void 0;
666
- needsMask = needMaskingText(
667
- n,
668
- maskTextClass,
669
- maskTextSelector,
670
- checkAncestors
671
- );
672
- }
673
- const _serializedNode = serializeNode(n, {
674
- doc,
675
- mirror,
676
- blockClass,
677
- blockSelector,
678
- needsMask,
679
- inlineStylesheet,
680
- maskInputOptions,
681
- maskTextFn,
682
- maskInputFn,
683
- dataURLOptions,
684
- inlineImages,
685
- recordCanvas,
686
- keepIframeSrcFn,
687
- newlyAddedElement
688
- });
689
- if (!_serializedNode) {
690
- console.warn(n, "not serialized");
691
- return null;
692
- }
693
- let id;
694
- if (mirror.hasNode(n)) {
695
- id = mirror.getId(n);
696
- } else if (slimDOMExcluded(_serializedNode, slimDOMOptions) || !preserveWhiteSpace && _serializedNode.type === types.NodeType$1.Text && !_serializedNode.isStyle && !_serializedNode.textContent.replace(/^\s+|\s+$/gm, "").length) {
697
- id = IGNORED_NODE;
698
- } else {
699
- id = genId();
700
- }
701
- const serializedNode = Object.assign(_serializedNode, { id });
702
- mirror.add(n, serializedNode);
703
- if (id === IGNORED_NODE) {
704
- return null;
705
- }
706
- if (onSerialize) {
707
- onSerialize(n);
708
- }
709
- let recordChild = !skipChild;
710
- if (serializedNode.type === types.NodeType$1.Element) {
711
- recordChild = recordChild && !serializedNode.needBlock;
712
- delete serializedNode.needBlock;
713
- const shadowRootEl = types.index.shadowRoot(n);
714
- if (shadowRootEl && types.isNativeShadowDom(shadowRootEl))
715
- serializedNode.isShadowHost = true;
716
- }
717
- if ((serializedNode.type === types.NodeType$1.Document || serializedNode.type === types.NodeType$1.Element) && recordChild) {
718
- if (slimDOMOptions.headWhitespace && serializedNode.type === types.NodeType$1.Element && serializedNode.tagName === "head") {
719
- preserveWhiteSpace = false;
720
- }
721
- const bypassOptions = {
722
- doc,
723
- mirror,
724
- blockClass,
725
- blockSelector,
726
- needsMask,
727
- maskTextClass,
728
- maskTextSelector,
729
- skipChild,
730
- inlineStylesheet,
731
- maskInputOptions,
732
- maskTextFn,
733
- maskInputFn,
734
- slimDOMOptions,
735
- dataURLOptions,
736
- inlineImages,
737
- recordCanvas,
738
- preserveWhiteSpace,
739
- onSerialize,
740
- onIframeLoad,
741
- iframeLoadTimeout,
742
- onStylesheetLoad,
743
- stylesheetLoadTimeout,
744
- keepIframeSrcFn
745
- };
746
- if (serializedNode.type === types.NodeType$1.Element && serializedNode.tagName === "textarea" && serializedNode.attributes.value !== void 0) ;
747
- else {
748
- for (const childN of Array.from(types.index.childNodes(n))) {
749
- const serializedChildNode = serializeNodeWithId(childN, bypassOptions);
750
- if (serializedChildNode) {
751
- serializedNode.childNodes.push(serializedChildNode);
752
- }
753
- }
754
- }
755
- let shadowRootEl = null;
756
- if (types.isElement(n) && (shadowRootEl = types.index.shadowRoot(n))) {
757
- for (const childN of Array.from(types.index.childNodes(shadowRootEl))) {
758
- const serializedChildNode = serializeNodeWithId(childN, bypassOptions);
759
- if (serializedChildNode) {
760
- types.isNativeShadowDom(shadowRootEl) && (serializedChildNode.isShadow = true);
761
- serializedNode.childNodes.push(serializedChildNode);
762
- }
763
- }
764
- }
765
- }
766
- const parent = types.index.parentNode(n);
767
- if (parent && types.isShadowRoot(parent) && types.isNativeShadowDom(parent)) {
768
- serializedNode.isShadow = true;
769
- }
770
- if (serializedNode.type === types.NodeType$1.Element && serializedNode.tagName === "iframe") {
771
- onceIframeLoaded(
772
- n,
773
- () => {
774
- const iframeDoc = n.contentDocument;
775
- if (iframeDoc && onIframeLoad) {
776
- const serializedIframeNode = serializeNodeWithId(iframeDoc, {
777
- doc: iframeDoc,
778
- mirror,
779
- blockClass,
780
- blockSelector,
781
- needsMask,
782
- maskTextClass,
783
- maskTextSelector,
784
- skipChild: false,
785
- inlineStylesheet,
786
- maskInputOptions,
787
- maskTextFn,
788
- maskInputFn,
789
- slimDOMOptions,
790
- dataURLOptions,
791
- inlineImages,
792
- recordCanvas,
793
- preserveWhiteSpace,
794
- onSerialize,
795
- onIframeLoad,
796
- iframeLoadTimeout,
797
- onStylesheetLoad,
798
- stylesheetLoadTimeout,
799
- keepIframeSrcFn
800
- });
801
- if (serializedIframeNode) {
802
- onIframeLoad(
803
- n,
804
- serializedIframeNode
805
- );
806
- }
807
- }
808
- },
809
- iframeLoadTimeout
810
- );
811
- }
812
- 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")) {
813
- onceStylesheetLoaded(
814
- n,
815
- () => {
816
- if (onStylesheetLoad) {
817
- const serializedLinkNode = serializeNodeWithId(n, {
818
- doc,
819
- mirror,
820
- blockClass,
821
- blockSelector,
822
- needsMask,
823
- maskTextClass,
824
- maskTextSelector,
825
- skipChild: false,
826
- inlineStylesheet,
827
- maskInputOptions,
828
- maskTextFn,
829
- maskInputFn,
830
- slimDOMOptions,
831
- dataURLOptions,
832
- inlineImages,
833
- recordCanvas,
834
- preserveWhiteSpace,
835
- onSerialize,
836
- onIframeLoad,
837
- iframeLoadTimeout,
838
- onStylesheetLoad,
839
- stylesheetLoadTimeout,
840
- keepIframeSrcFn
841
- });
842
- if (serializedLinkNode) {
843
- onStylesheetLoad(
844
- n,
845
- serializedLinkNode
846
- );
847
- }
848
- }
849
- },
850
- stylesheetLoadTimeout
851
- );
852
- }
853
- return serializedNode;
854
- }
855
- function snapshot(n, options) {
856
- const {
857
- mirror = new types.Mirror(),
858
- blockClass = "rr-block",
859
- blockSelector = null,
860
- maskTextClass = "rr-mask",
861
- maskTextSelector = null,
862
- inlineStylesheet = true,
863
- inlineImages = false,
864
- recordCanvas = false,
865
- maskAllInputs = false,
866
- maskTextFn,
867
- maskInputFn,
868
- slimDOM = false,
869
- dataURLOptions,
870
- preserveWhiteSpace,
871
- onSerialize,
872
- onIframeLoad,
873
- iframeLoadTimeout,
874
- onStylesheetLoad,
875
- stylesheetLoadTimeout,
876
- keepIframeSrcFn = () => false
877
- } = options || {};
878
- const maskInputOptions = maskAllInputs === true ? {
879
- color: true,
880
- date: true,
881
- "datetime-local": true,
882
- email: true,
883
- month: true,
884
- number: true,
885
- range: true,
886
- search: true,
887
- tel: true,
888
- text: true,
889
- time: true,
890
- url: true,
891
- week: true,
892
- textarea: true,
893
- select: true,
894
- password: true
895
- } : maskAllInputs === false ? {
896
- password: true
897
- } : maskAllInputs;
898
- const slimDOMOptions = slimDOM === true || slimDOM === "all" ? (
899
- // if true: set of sensible options that should not throw away any information
900
- {
901
- script: true,
902
- comment: true,
903
- headFavicon: true,
904
- headWhitespace: true,
905
- headMetaDescKeywords: slimDOM === "all",
906
- // destructive
907
- headMetaSocial: true,
908
- headMetaRobots: true,
909
- headMetaHttpEquiv: true,
910
- headMetaAuthorship: true,
911
- headMetaVerification: true
912
- }
913
- ) : slimDOM === false ? {} : slimDOM;
914
- return serializeNodeWithId(n, {
915
- doc: n,
916
- mirror,
917
- blockClass,
918
- blockSelector,
919
- maskTextClass,
920
- maskTextSelector,
921
- skipChild: false,
922
- inlineStylesheet,
923
- maskInputOptions,
924
- maskTextFn,
925
- maskInputFn,
926
- slimDOMOptions,
927
- dataURLOptions,
928
- inlineImages,
929
- recordCanvas,
930
- preserveWhiteSpace,
931
- onSerialize,
932
- onIframeLoad,
933
- iframeLoadTimeout,
934
- onStylesheetLoad,
935
- stylesheetLoadTimeout,
936
- keepIframeSrcFn,
937
- newlyAddedElement: false
938
- });
939
- }
940
- function visitSnapshot(node, onVisit) {
941
- function walk(current) {
942
- onVisit(current);
943
- if (current.type === types.NodeType$1.Document || current.type === types.NodeType$1.Element) {
944
- current.childNodes.forEach(walk);
945
- }
946
- }
947
- walk(node);
948
- }
949
- function cleanupSnapshot() {
950
- _id = 1;
951
- }
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;
952
17
  exports.Mirror = types.Mirror;
953
18
  exports.NodeType = types.NodeType;
954
19
  exports.absolutifyURLs = types.absolutifyURLs;
@@ -970,14 +35,4 @@ exports.recompressBase64Image = types.recompressBase64Image;
970
35
  exports.stringifyRule = types.stringifyRule;
971
36
  exports.stringifyStylesheet = types.stringifyStylesheet;
972
37
  exports.toLowerCase = types.toLowerCase;
973
- exports.IGNORED_NODE = IGNORED_NODE;
974
- exports.classMatchesRegex = classMatchesRegex;
975
- exports.cleanupSnapshot = cleanupSnapshot;
976
- exports.genId = genId;
977
- exports.ignoreAttribute = ignoreAttribute;
978
- exports.needMaskingText = needMaskingText;
979
- exports.serializeNodeWithId = serializeNodeWithId;
980
- exports.snapshot = snapshot;
981
- exports.transformAttribute = transformAttribute;
982
- exports.visitSnapshot = visitSnapshot;
983
38
  //# sourceMappingURL=record.cjs.map