@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
|
@@ -507,6 +507,36 @@ function absolutifyURLs(cssText, href) {
|
|
|
507
507
|
}
|
|
508
508
|
);
|
|
509
509
|
}
|
|
510
|
+
const STRIPED_PLACEHOLDER_SVG = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgogIDxkZWZzPgogICAgPHBhdHRlcm4gaWQ9InN0cmlwZXMiIHBhdHRlcm5Vbml0cz0idXNlclNwYWNlT25Vc2UiIHdpZHRoPSIxNiIgaGVpZ2h0PSIxNiI+CiAgICAgIDxyZWN0IHdpZHRoPSIxNiIgaGVpZ2h0PSIxNiIgZmlsbD0iYmxhY2siLz4KICAgICAgPHBhdGggZD0iTTggMEgxNkwwIDE2VjhMOCAwWiIgZmlsbD0iIzJEMkQyRCIvPgogICAgICA8cGF0aCBkPSJNMTYgOFYxNkg4TDE2IDhaIiBmaWxsPSIjMkQyRDJEIi8+CiAgICA8L3BhdHRlcm4+CiAgPC9kZWZzPgogIDxyZWN0IHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9InVybCgjc3RyaXBlcykiLz4KPC9zdmc+Cg==";
|
|
511
|
+
const MAX_IMAGE_DIMENSION_FOR_RECOMPRESSION = 4096;
|
|
512
|
+
function recompressBase64Image(img, dataURL, type, quality) {
|
|
513
|
+
if (!img.complete || img.naturalWidth === 0) {
|
|
514
|
+
return dataURL;
|
|
515
|
+
}
|
|
516
|
+
if (img.naturalWidth > MAX_IMAGE_DIMENSION_FOR_RECOMPRESSION || img.naturalHeight > MAX_IMAGE_DIMENSION_FOR_RECOMPRESSION) {
|
|
517
|
+
return dataURL;
|
|
518
|
+
}
|
|
519
|
+
try {
|
|
520
|
+
const canvas = document.createElement("canvas");
|
|
521
|
+
canvas.width = img.naturalWidth;
|
|
522
|
+
canvas.height = img.naturalHeight;
|
|
523
|
+
const ctx = canvas.getContext("2d");
|
|
524
|
+
if (!ctx) {
|
|
525
|
+
return dataURL;
|
|
526
|
+
}
|
|
527
|
+
ctx.drawImage(img, 0, 0);
|
|
528
|
+
const recompressed = canvas.toDataURL(type || "image/webp", quality != null ? quality : 0.4);
|
|
529
|
+
return recompressed;
|
|
530
|
+
} catch (err) {
|
|
531
|
+
return dataURL;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
function checkDataURLSize(dataURL, maxLength) {
|
|
535
|
+
if (!maxLength || dataURL.length <= maxLength) {
|
|
536
|
+
return dataURL;
|
|
537
|
+
}
|
|
538
|
+
return STRIPED_PLACEHOLDER_SVG;
|
|
539
|
+
}
|
|
510
540
|
let _id = 1;
|
|
511
541
|
const tagNameRegex = new RegExp("[^a-z0-9-_:]");
|
|
512
542
|
const IGNORED_NODE = -2;
|
|
@@ -605,12 +635,32 @@ function getHref(doc, customHref) {
|
|
|
605
635
|
a2.setAttribute("href", customHref);
|
|
606
636
|
return a2.href;
|
|
607
637
|
}
|
|
608
|
-
function transformAttribute(doc, tagName, name, value) {
|
|
638
|
+
function transformAttribute(doc, tagName, name, value, element, dataURLOptions) {
|
|
609
639
|
if (!value) {
|
|
610
640
|
return value;
|
|
611
641
|
}
|
|
612
642
|
if (name === "src" || name === "href" && !(tagName === "use" && value[0] === "#")) {
|
|
613
|
-
|
|
643
|
+
const transformedValue = absoluteToDoc(doc, value);
|
|
644
|
+
if (tagName === "img" && transformedValue.startsWith("data:") && element) {
|
|
645
|
+
const img = element;
|
|
646
|
+
let processedDataURL = transformedValue;
|
|
647
|
+
if ((dataURLOptions == null ? void 0 : dataURLOptions.type) || (dataURLOptions == null ? void 0 : dataURLOptions.quality) !== void 0) {
|
|
648
|
+
processedDataURL = recompressBase64Image(
|
|
649
|
+
img,
|
|
650
|
+
transformedValue,
|
|
651
|
+
dataURLOptions.type,
|
|
652
|
+
dataURLOptions.quality
|
|
653
|
+
);
|
|
654
|
+
}
|
|
655
|
+
if (dataURLOptions == null ? void 0 : dataURLOptions.maxBase64ImageLength) {
|
|
656
|
+
processedDataURL = checkDataURLSize(
|
|
657
|
+
processedDataURL,
|
|
658
|
+
dataURLOptions.maxBase64ImageLength
|
|
659
|
+
);
|
|
660
|
+
}
|
|
661
|
+
return processedDataURL;
|
|
662
|
+
}
|
|
663
|
+
return transformedValue;
|
|
614
664
|
} else if (name === "xlink:href" && value[0] !== "#") {
|
|
615
665
|
return absoluteToDoc(doc, value);
|
|
616
666
|
} else if (name === "background" && (tagName === "table" || tagName === "td" || tagName === "th")) {
|
|
@@ -901,7 +951,9 @@ function serializeElementNode(n2, options) {
|
|
|
901
951
|
doc,
|
|
902
952
|
tagName,
|
|
903
953
|
toLowerCase(attr.name),
|
|
904
|
-
attr.value
|
|
954
|
+
attr.value,
|
|
955
|
+
n2,
|
|
956
|
+
dataURLOptions
|
|
905
957
|
);
|
|
906
958
|
}
|
|
907
959
|
}
|
|
@@ -10178,7 +10230,9 @@ class MutationBuffer {
|
|
|
10178
10230
|
this.doc,
|
|
10179
10231
|
toLowerCase(target.tagName),
|
|
10180
10232
|
toLowerCase(attributeName),
|
|
10181
|
-
value
|
|
10233
|
+
value,
|
|
10234
|
+
target,
|
|
10235
|
+
this.dataURLOptions
|
|
10182
10236
|
);
|
|
10183
10237
|
if (attributeName === "style") {
|
|
10184
10238
|
if (!this.unattachedDoc) {
|
|
@@ -12531,7 +12585,7 @@ function record(options = {}) {
|
|
|
12531
12585
|
hooks,
|
|
12532
12586
|
packFn,
|
|
12533
12587
|
sampling = {},
|
|
12534
|
-
dataURLOptions = {},
|
|
12588
|
+
dataURLOptions: _dataURLOptions = {},
|
|
12535
12589
|
mousemoveWait,
|
|
12536
12590
|
recordDOM = true,
|
|
12537
12591
|
recordCanvas = false,
|
|
@@ -12546,6 +12600,11 @@ function record(options = {}) {
|
|
|
12546
12600
|
errorHandler: errorHandler2
|
|
12547
12601
|
} = options;
|
|
12548
12602
|
registerErrorHandler(errorHandler2);
|
|
12603
|
+
const dataURLOptions = __spreadValues({
|
|
12604
|
+
type: "image/webp",
|
|
12605
|
+
quality: 0.4,
|
|
12606
|
+
maxBase64ImageLength: 1048576
|
|
12607
|
+
}, _dataURLOptions);
|
|
12549
12608
|
const inEmittingFrame = recordCrossOriginIframes ? window.parent === window : true;
|
|
12550
12609
|
let passEmitsToParent = false;
|
|
12551
12610
|
if (!inEmittingFrame) {
|