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