@posthog/rrweb-record 0.0.29 → 0.0.30
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/rrweb-record.cjs +65 -5
- package/dist/rrweb-record.cjs.map +1 -1
- package/dist/rrweb-record.js +65 -5
- package/dist/rrweb-record.js.map +1 -1
- package/dist/rrweb-record.umd.cjs +64 -5
- package/dist/rrweb-record.umd.cjs.map +2 -2
- package/dist/rrweb-record.umd.min.cjs +35 -35
- package/dist/rrweb-record.umd.min.cjs.map +3 -3
- package/package.json +1 -1
package/dist/rrweb-record.cjs
CHANGED
|
@@ -462,6 +462,36 @@ function absolutifyURLs(cssText, href) {
|
|
|
462
462
|
}
|
|
463
463
|
);
|
|
464
464
|
}
|
|
465
|
+
const STRIPED_PLACEHOLDER_SVG = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgogIDxkZWZzPgogICAgPHBhdHRlcm4gaWQ9InN0cmlwZXMiIHBhdHRlcm5Vbml0cz0idXNlclNwYWNlT25Vc2UiIHdpZHRoPSIxNiIgaGVpZ2h0PSIxNiI+CiAgICAgIDxyZWN0IHdpZHRoPSIxNiIgaGVpZ2h0PSIxNiIgZmlsbD0iYmxhY2siLz4KICAgICAgPHBhdGggZD0iTTggMEgxNkwwIDE2VjhMOCAwWiIgZmlsbD0iIzJEMkQyRCIvPgogICAgICA8cGF0aCBkPSJNMTYgOFYxNkg4TDE2IDhaIiBmaWxsPSIjMkQyRDJEIi8+CiAgICA8L3BhdHRlcm4+CiAgPC9kZWZzPgogIDxyZWN0IHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9InVybCgjc3RyaXBlcykiLz4KPC9zdmc+Cg==";
|
|
466
|
+
const MAX_IMAGE_DIMENSION_FOR_RECOMPRESSION = 4096;
|
|
467
|
+
function recompressBase64Image(img, dataURL, type, quality) {
|
|
468
|
+
if (!img.complete || img.naturalWidth === 0) {
|
|
469
|
+
return dataURL;
|
|
470
|
+
}
|
|
471
|
+
if (img.naturalWidth > MAX_IMAGE_DIMENSION_FOR_RECOMPRESSION || img.naturalHeight > MAX_IMAGE_DIMENSION_FOR_RECOMPRESSION) {
|
|
472
|
+
return dataURL;
|
|
473
|
+
}
|
|
474
|
+
try {
|
|
475
|
+
const canvas = document.createElement("canvas");
|
|
476
|
+
canvas.width = img.naturalWidth;
|
|
477
|
+
canvas.height = img.naturalHeight;
|
|
478
|
+
const ctx = canvas.getContext("2d");
|
|
479
|
+
if (!ctx) {
|
|
480
|
+
return dataURL;
|
|
481
|
+
}
|
|
482
|
+
ctx.drawImage(img, 0, 0);
|
|
483
|
+
const recompressed = canvas.toDataURL(type || "image/webp", quality ?? 0.4);
|
|
484
|
+
return recompressed;
|
|
485
|
+
} catch (err) {
|
|
486
|
+
return dataURL;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
function checkDataURLSize(dataURL, maxLength) {
|
|
490
|
+
if (!maxLength || dataURL.length <= maxLength) {
|
|
491
|
+
return dataURL;
|
|
492
|
+
}
|
|
493
|
+
return STRIPED_PLACEHOLDER_SVG;
|
|
494
|
+
}
|
|
465
495
|
let _id = 1;
|
|
466
496
|
const tagNameRegex = new RegExp("[^a-z0-9-_:]");
|
|
467
497
|
const IGNORED_NODE = -2;
|
|
@@ -560,12 +590,32 @@ function getHref(doc, customHref) {
|
|
|
560
590
|
a2.setAttribute("href", customHref);
|
|
561
591
|
return a2.href;
|
|
562
592
|
}
|
|
563
|
-
function transformAttribute(doc, tagName, name, value) {
|
|
593
|
+
function transformAttribute(doc, tagName, name, value, element, dataURLOptions) {
|
|
564
594
|
if (!value) {
|
|
565
595
|
return value;
|
|
566
596
|
}
|
|
567
597
|
if (name === "src" || name === "href" && !(tagName === "use" && value[0] === "#")) {
|
|
568
|
-
|
|
598
|
+
const transformedValue = absoluteToDoc(doc, value);
|
|
599
|
+
if (tagName === "img" && transformedValue.startsWith("data:") && element) {
|
|
600
|
+
const img = element;
|
|
601
|
+
let processedDataURL = transformedValue;
|
|
602
|
+
if ((dataURLOptions == null ? void 0 : dataURLOptions.type) || (dataURLOptions == null ? void 0 : dataURLOptions.quality) !== void 0) {
|
|
603
|
+
processedDataURL = recompressBase64Image(
|
|
604
|
+
img,
|
|
605
|
+
transformedValue,
|
|
606
|
+
dataURLOptions.type,
|
|
607
|
+
dataURLOptions.quality
|
|
608
|
+
);
|
|
609
|
+
}
|
|
610
|
+
if (dataURLOptions == null ? void 0 : dataURLOptions.maxBase64ImageLength) {
|
|
611
|
+
processedDataURL = checkDataURLSize(
|
|
612
|
+
processedDataURL,
|
|
613
|
+
dataURLOptions.maxBase64ImageLength
|
|
614
|
+
);
|
|
615
|
+
}
|
|
616
|
+
return processedDataURL;
|
|
617
|
+
}
|
|
618
|
+
return transformedValue;
|
|
569
619
|
} else if (name === "xlink:href" && value[0] !== "#") {
|
|
570
620
|
return absoluteToDoc(doc, value);
|
|
571
621
|
} else if (name === "background" && (tagName === "table" || tagName === "td" || tagName === "th")) {
|
|
@@ -856,7 +906,9 @@ function serializeElementNode(n2, options) {
|
|
|
856
906
|
doc,
|
|
857
907
|
tagName,
|
|
858
908
|
toLowerCase(attr.name),
|
|
859
|
-
attr.value
|
|
909
|
+
attr.value,
|
|
910
|
+
n2,
|
|
911
|
+
dataURLOptions
|
|
860
912
|
);
|
|
861
913
|
}
|
|
862
914
|
}
|
|
@@ -10134,7 +10186,9 @@ class MutationBuffer {
|
|
|
10134
10186
|
this.doc,
|
|
10135
10187
|
toLowerCase(target.tagName),
|
|
10136
10188
|
toLowerCase(attributeName),
|
|
10137
|
-
value
|
|
10189
|
+
value,
|
|
10190
|
+
target,
|
|
10191
|
+
this.dataURLOptions
|
|
10138
10192
|
);
|
|
10139
10193
|
if (attributeName === "style") {
|
|
10140
10194
|
if (!this.unattachedDoc) {
|
|
@@ -12491,7 +12545,7 @@ function record(options = {}) {
|
|
|
12491
12545
|
hooks,
|
|
12492
12546
|
packFn,
|
|
12493
12547
|
sampling = {},
|
|
12494
|
-
dataURLOptions = {},
|
|
12548
|
+
dataURLOptions: _dataURLOptions = {},
|
|
12495
12549
|
mousemoveWait,
|
|
12496
12550
|
recordDOM = true,
|
|
12497
12551
|
recordCanvas = false,
|
|
@@ -12506,6 +12560,12 @@ function record(options = {}) {
|
|
|
12506
12560
|
errorHandler: errorHandler2
|
|
12507
12561
|
} = options;
|
|
12508
12562
|
registerErrorHandler(errorHandler2);
|
|
12563
|
+
const dataURLOptions = {
|
|
12564
|
+
type: "image/webp",
|
|
12565
|
+
quality: 0.4,
|
|
12566
|
+
maxBase64ImageLength: 1048576,
|
|
12567
|
+
..._dataURLOptions
|
|
12568
|
+
};
|
|
12509
12569
|
const inEmittingFrame = recordCrossOriginIframes ? window.parent === window : true;
|
|
12510
12570
|
let passEmitsToParent = false;
|
|
12511
12571
|
if (!inEmittingFrame) {
|