@posthog/rrweb 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.cjs +65 -5
- package/dist/rrweb.cjs.map +1 -1
- package/dist/rrweb.js +65 -5
- package/dist/rrweb.js.map +1 -1
- package/dist/rrweb.umd.cjs +64 -5
- package/dist/rrweb.umd.cjs.map +2 -2
- package/dist/rrweb.umd.min.cjs +19 -19
- package/dist/rrweb.umd.min.cjs.map +3 -3
- package/package.json +1 -1
package/dist/rrweb.js
CHANGED
|
@@ -472,6 +472,36 @@ function absolutifyURLs(cssText, href) {
|
|
|
472
472
|
}
|
|
473
473
|
);
|
|
474
474
|
}
|
|
475
|
+
const STRIPED_PLACEHOLDER_SVG = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgogIDxkZWZzPgogICAgPHBhdHRlcm4gaWQ9InN0cmlwZXMiIHBhdHRlcm5Vbml0cz0idXNlclNwYWNlT25Vc2UiIHdpZHRoPSIxNiIgaGVpZ2h0PSIxNiI+CiAgICAgIDxyZWN0IHdpZHRoPSIxNiIgaGVpZ2h0PSIxNiIgZmlsbD0iYmxhY2siLz4KICAgICAgPHBhdGggZD0iTTggMEgxNkwwIDE2VjhMOCAwWiIgZmlsbD0iIzJEMkQyRCIvPgogICAgICA8cGF0aCBkPSJNMTYgOFYxNkg4TDE2IDhaIiBmaWxsPSIjMkQyRDJEIi8+CiAgICA8L3BhdHRlcm4+CiAgPC9kZWZzPgogIDxyZWN0IHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9InVybCgjc3RyaXBlcykiLz4KPC9zdmc+Cg==";
|
|
476
|
+
const MAX_IMAGE_DIMENSION_FOR_RECOMPRESSION = 4096;
|
|
477
|
+
function recompressBase64Image(img, dataURL, type, quality) {
|
|
478
|
+
if (!img.complete || img.naturalWidth === 0) {
|
|
479
|
+
return dataURL;
|
|
480
|
+
}
|
|
481
|
+
if (img.naturalWidth > MAX_IMAGE_DIMENSION_FOR_RECOMPRESSION || img.naturalHeight > MAX_IMAGE_DIMENSION_FOR_RECOMPRESSION) {
|
|
482
|
+
return dataURL;
|
|
483
|
+
}
|
|
484
|
+
try {
|
|
485
|
+
const canvas = document.createElement("canvas");
|
|
486
|
+
canvas.width = img.naturalWidth;
|
|
487
|
+
canvas.height = img.naturalHeight;
|
|
488
|
+
const ctx = canvas.getContext("2d");
|
|
489
|
+
if (!ctx) {
|
|
490
|
+
return dataURL;
|
|
491
|
+
}
|
|
492
|
+
ctx.drawImage(img, 0, 0);
|
|
493
|
+
const recompressed = canvas.toDataURL(type || "image/webp", quality ?? 0.4);
|
|
494
|
+
return recompressed;
|
|
495
|
+
} catch (err) {
|
|
496
|
+
return dataURL;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
function checkDataURLSize(dataURL, maxLength) {
|
|
500
|
+
if (!maxLength || dataURL.length <= maxLength) {
|
|
501
|
+
return dataURL;
|
|
502
|
+
}
|
|
503
|
+
return STRIPED_PLACEHOLDER_SVG;
|
|
504
|
+
}
|
|
475
505
|
let _id = 1;
|
|
476
506
|
const tagNameRegex = new RegExp("[^a-z0-9-_:]");
|
|
477
507
|
const IGNORED_NODE = -2;
|
|
@@ -570,12 +600,32 @@ function getHref(doc, customHref) {
|
|
|
570
600
|
a2.setAttribute("href", customHref);
|
|
571
601
|
return a2.href;
|
|
572
602
|
}
|
|
573
|
-
function transformAttribute(doc, tagName, name, value) {
|
|
603
|
+
function transformAttribute(doc, tagName, name, value, element, dataURLOptions) {
|
|
574
604
|
if (!value) {
|
|
575
605
|
return value;
|
|
576
606
|
}
|
|
577
607
|
if (name === "src" || name === "href" && !(tagName === "use" && value[0] === "#")) {
|
|
578
|
-
|
|
608
|
+
const transformedValue = absoluteToDoc(doc, value);
|
|
609
|
+
if (tagName === "img" && transformedValue.startsWith("data:") && element) {
|
|
610
|
+
const img = element;
|
|
611
|
+
let processedDataURL = transformedValue;
|
|
612
|
+
if ((dataURLOptions == null ? void 0 : dataURLOptions.type) || (dataURLOptions == null ? void 0 : dataURLOptions.quality) !== void 0) {
|
|
613
|
+
processedDataURL = recompressBase64Image(
|
|
614
|
+
img,
|
|
615
|
+
transformedValue,
|
|
616
|
+
dataURLOptions.type,
|
|
617
|
+
dataURLOptions.quality
|
|
618
|
+
);
|
|
619
|
+
}
|
|
620
|
+
if (dataURLOptions == null ? void 0 : dataURLOptions.maxBase64ImageLength) {
|
|
621
|
+
processedDataURL = checkDataURLSize(
|
|
622
|
+
processedDataURL,
|
|
623
|
+
dataURLOptions.maxBase64ImageLength
|
|
624
|
+
);
|
|
625
|
+
}
|
|
626
|
+
return processedDataURL;
|
|
627
|
+
}
|
|
628
|
+
return transformedValue;
|
|
579
629
|
} else if (name === "xlink:href" && value[0] !== "#") {
|
|
580
630
|
return absoluteToDoc(doc, value);
|
|
581
631
|
} else if (name === "background" && (tagName === "table" || tagName === "td" || tagName === "th")) {
|
|
@@ -866,7 +916,9 @@ function serializeElementNode(n2, options) {
|
|
|
866
916
|
doc,
|
|
867
917
|
tagName,
|
|
868
918
|
toLowerCase(attr.name),
|
|
869
|
-
attr.value
|
|
919
|
+
attr.value,
|
|
920
|
+
n2,
|
|
921
|
+
dataURLOptions
|
|
870
922
|
);
|
|
871
923
|
}
|
|
872
924
|
}
|
|
@@ -12004,7 +12056,9 @@ class MutationBuffer {
|
|
|
12004
12056
|
this.doc,
|
|
12005
12057
|
toLowerCase(target.tagName),
|
|
12006
12058
|
toLowerCase(attributeName),
|
|
12007
|
-
value
|
|
12059
|
+
value,
|
|
12060
|
+
target,
|
|
12061
|
+
this.dataURLOptions
|
|
12008
12062
|
);
|
|
12009
12063
|
if (attributeName === "style") {
|
|
12010
12064
|
if (!this.unattachedDoc) {
|
|
@@ -14385,7 +14439,7 @@ function record(options = {}) {
|
|
|
14385
14439
|
hooks,
|
|
14386
14440
|
packFn,
|
|
14387
14441
|
sampling = {},
|
|
14388
|
-
dataURLOptions = {},
|
|
14442
|
+
dataURLOptions: _dataURLOptions = {},
|
|
14389
14443
|
mousemoveWait,
|
|
14390
14444
|
recordDOM = true,
|
|
14391
14445
|
recordCanvas = false,
|
|
@@ -14400,6 +14454,12 @@ function record(options = {}) {
|
|
|
14400
14454
|
errorHandler: errorHandler2
|
|
14401
14455
|
} = options;
|
|
14402
14456
|
registerErrorHandler(errorHandler2);
|
|
14457
|
+
const dataURLOptions = {
|
|
14458
|
+
type: "image/webp",
|
|
14459
|
+
quality: 0.4,
|
|
14460
|
+
maxBase64ImageLength: 1048576,
|
|
14461
|
+
..._dataURLOptions
|
|
14462
|
+
};
|
|
14403
14463
|
const inEmittingFrame = recordCrossOriginIframes ? window.parent === window : true;
|
|
14404
14464
|
let passEmitsToParent = false;
|
|
14405
14465
|
if (!inEmittingFrame) {
|