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