@posthog/rrweb-record 0.0.10 → 0.0.12
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 +51 -148
- package/dist/rrweb-record.cjs.map +1 -1
- package/dist/rrweb-record.js +51 -148
- package/dist/rrweb-record.js.map +1 -1
- package/dist/rrweb-record.umd.cjs +51 -148
- 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
|
@@ -51,7 +51,7 @@ var _a;
|
|
|
51
51
|
var __defProp$1 = Object.defineProperty;
|
|
52
52
|
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
53
53
|
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
54
|
-
var NodeType$
|
|
54
|
+
var NodeType$1$1 = /* @__PURE__ */ ((NodeType2) => {
|
|
55
55
|
NodeType2[NodeType2["Document"] = 0] = "Document";
|
|
56
56
|
NodeType2[NodeType2["DocumentType"] = 1] = "DocumentType";
|
|
57
57
|
NodeType2[NodeType2["Element"] = 2] = "Element";
|
|
@@ -59,7 +59,7 @@ var NodeType$3 = /* @__PURE__ */ ((NodeType2) => {
|
|
|
59
59
|
NodeType2[NodeType2["CDATA"] = 4] = "CDATA";
|
|
60
60
|
NodeType2[NodeType2["Comment"] = 5] = "Comment";
|
|
61
61
|
return NodeType2;
|
|
62
|
-
})(NodeType$
|
|
62
|
+
})(NodeType$1$1 || {});
|
|
63
63
|
const testableAccessors$1 = {
|
|
64
64
|
Node: ["childNodes", "parentNode", "parentElement", "textContent"],
|
|
65
65
|
ShadowRoot: ["host", "styleSheets"],
|
|
@@ -283,13 +283,9 @@ function stringifyStylesheet(s2) {
|
|
|
283
283
|
if (!rules2) {
|
|
284
284
|
return null;
|
|
285
285
|
}
|
|
286
|
-
let sheetHref = s2.href;
|
|
287
|
-
if (!sheetHref && s2.ownerNode && s2.ownerNode.ownerDocument) {
|
|
288
|
-
sheetHref = s2.ownerNode.ownerDocument.location.href;
|
|
289
|
-
}
|
|
290
286
|
const stringifiedRules = Array.from(
|
|
291
287
|
rules2,
|
|
292
|
-
(rule2) => stringifyRule(rule2,
|
|
288
|
+
(rule2) => stringifyRule(rule2, s2.href)
|
|
293
289
|
).join("");
|
|
294
290
|
return fixBrowserCompatibilityIssuesInCSS(stringifiedRules);
|
|
295
291
|
} catch (error) {
|
|
@@ -503,90 +499,6 @@ function absolutifyURLs(cssText, href) {
|
|
|
503
499
|
}
|
|
504
500
|
);
|
|
505
501
|
}
|
|
506
|
-
const normalizationCache = /* @__PURE__ */ new Map();
|
|
507
|
-
const splitCache = /* @__PURE__ */ new Map();
|
|
508
|
-
function normalizeCssString(cssText) {
|
|
509
|
-
if (!normalizationCache.has(cssText)) {
|
|
510
|
-
const normalized = cssText.replace(/(\/\*[^*]*\*\/)|[\s;]/g, "");
|
|
511
|
-
normalizationCache.set(cssText, normalized);
|
|
512
|
-
}
|
|
513
|
-
return normalizationCache.get(cssText);
|
|
514
|
-
}
|
|
515
|
-
function splitCssText(cssText, style) {
|
|
516
|
-
const og = cssText;
|
|
517
|
-
if (splitCache.has(cssText)) {
|
|
518
|
-
return splitCache.get(cssText);
|
|
519
|
-
}
|
|
520
|
-
const childNodes2 = Array.from(style.childNodes);
|
|
521
|
-
const splits = [];
|
|
522
|
-
let iterLimit = 0;
|
|
523
|
-
if (childNodes2.length > 1 && cssText && typeof cssText === "string") {
|
|
524
|
-
let cssTextNorm = normalizeCssString(cssText);
|
|
525
|
-
const normFactor = cssTextNorm.length / cssText.length;
|
|
526
|
-
for (let i2 = 1; i2 < childNodes2.length; i2++) {
|
|
527
|
-
if (childNodes2[i2].textContent && typeof childNodes2[i2].textContent === "string") {
|
|
528
|
-
const textContentNorm = normalizeCssString(childNodes2[i2].textContent);
|
|
529
|
-
let j = 3;
|
|
530
|
-
for (; j < textContentNorm.length; j++) {
|
|
531
|
-
if (
|
|
532
|
-
// keep consuming css identifiers (to get a decent chunk more quickly)
|
|
533
|
-
textContentNorm[j].match(/[a-zA-Z0-9]/) || // substring needs to be unique to this section
|
|
534
|
-
textContentNorm.indexOf(textContentNorm.substring(0, j), 1) !== -1
|
|
535
|
-
) {
|
|
536
|
-
continue;
|
|
537
|
-
}
|
|
538
|
-
break;
|
|
539
|
-
}
|
|
540
|
-
for (; j < textContentNorm.length; j++) {
|
|
541
|
-
const bit = textContentNorm.substring(0, j);
|
|
542
|
-
const bits = cssTextNorm.split(bit);
|
|
543
|
-
let splitNorm = -1;
|
|
544
|
-
if (bits.length === 2) {
|
|
545
|
-
splitNorm = cssTextNorm.indexOf(bit);
|
|
546
|
-
} else if (bits.length > 2 && bits[0] === "" && childNodes2[i2 - 1].textContent !== "") {
|
|
547
|
-
splitNorm = cssTextNorm.indexOf(bit, 1);
|
|
548
|
-
}
|
|
549
|
-
if (splitNorm !== -1) {
|
|
550
|
-
let k = Math.floor(splitNorm / normFactor);
|
|
551
|
-
for (; k > 0 && k < cssText.length; ) {
|
|
552
|
-
iterLimit += 1;
|
|
553
|
-
if (iterLimit > 50 * childNodes2.length) {
|
|
554
|
-
splits.push(cssText);
|
|
555
|
-
return splits;
|
|
556
|
-
}
|
|
557
|
-
const normPart = normalizeCssString(cssText.substring(0, k));
|
|
558
|
-
if (normPart.length === splitNorm) {
|
|
559
|
-
splits.push(cssText.substring(0, k));
|
|
560
|
-
cssText = cssText.substring(k);
|
|
561
|
-
cssTextNorm = cssTextNorm.substring(splitNorm);
|
|
562
|
-
break;
|
|
563
|
-
} else if (normPart.length < splitNorm) {
|
|
564
|
-
k += Math.max(
|
|
565
|
-
1,
|
|
566
|
-
Math.floor((splitNorm - normPart.length) / normFactor)
|
|
567
|
-
);
|
|
568
|
-
} else {
|
|
569
|
-
k -= Math.max(
|
|
570
|
-
1,
|
|
571
|
-
Math.floor((normPart.length - splitNorm) * normFactor)
|
|
572
|
-
);
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
break;
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
splits.push(cssText);
|
|
582
|
-
if (og) {
|
|
583
|
-
splitCache.set(og, splits);
|
|
584
|
-
}
|
|
585
|
-
return splits;
|
|
586
|
-
}
|
|
587
|
-
function markCssSplits(cssText, style) {
|
|
588
|
-
return splitCssText(cssText, style).join("/* rr_split */");
|
|
589
|
-
}
|
|
590
502
|
let _id = 1;
|
|
591
503
|
const tagNameRegex = new RegExp("[^a-z0-9-_:]");
|
|
592
504
|
const IGNORED_NODE = -2;
|
|
@@ -845,28 +757,27 @@ function serializeNode(n2, options) {
|
|
|
845
757
|
inlineImages,
|
|
846
758
|
recordCanvas,
|
|
847
759
|
keepIframeSrcFn,
|
|
848
|
-
newlyAddedElement = false
|
|
849
|
-
cssCaptured = false
|
|
760
|
+
newlyAddedElement = false
|
|
850
761
|
} = options;
|
|
851
762
|
const rootId = getRootId(doc, mirror2);
|
|
852
763
|
switch (n2.nodeType) {
|
|
853
764
|
case n2.DOCUMENT_NODE:
|
|
854
765
|
if (n2.compatMode !== "CSS1Compat") {
|
|
855
766
|
return {
|
|
856
|
-
type: NodeType$
|
|
767
|
+
type: NodeType$1$1.Document,
|
|
857
768
|
childNodes: [],
|
|
858
769
|
compatMode: n2.compatMode
|
|
859
770
|
// probably "BackCompat"
|
|
860
771
|
};
|
|
861
772
|
} else {
|
|
862
773
|
return {
|
|
863
|
-
type: NodeType$
|
|
774
|
+
type: NodeType$1$1.Document,
|
|
864
775
|
childNodes: []
|
|
865
776
|
};
|
|
866
777
|
}
|
|
867
778
|
case n2.DOCUMENT_TYPE_NODE:
|
|
868
779
|
return {
|
|
869
|
-
type: NodeType$
|
|
780
|
+
type: NodeType$1$1.DocumentType,
|
|
870
781
|
name: n2.name,
|
|
871
782
|
publicId: n2.publicId,
|
|
872
783
|
systemId: n2.systemId,
|
|
@@ -892,18 +803,17 @@ function serializeNode(n2, options) {
|
|
|
892
803
|
doc,
|
|
893
804
|
needsMask,
|
|
894
805
|
maskTextFn,
|
|
895
|
-
rootId
|
|
896
|
-
cssCaptured
|
|
806
|
+
rootId
|
|
897
807
|
});
|
|
898
808
|
case n2.CDATA_SECTION_NODE:
|
|
899
809
|
return {
|
|
900
|
-
type: NodeType$
|
|
810
|
+
type: NodeType$1$1.CDATA,
|
|
901
811
|
textContent: "",
|
|
902
812
|
rootId
|
|
903
813
|
};
|
|
904
814
|
case n2.COMMENT_NODE:
|
|
905
815
|
return {
|
|
906
|
-
type: NodeType$
|
|
816
|
+
type: NodeType$1$1.Comment,
|
|
907
817
|
textContent: index$1.textContent(n2) || "",
|
|
908
818
|
rootId
|
|
909
819
|
};
|
|
@@ -917,26 +827,37 @@ function getRootId(doc, mirror2) {
|
|
|
917
827
|
return docId === 1 ? void 0 : docId;
|
|
918
828
|
}
|
|
919
829
|
function serializeTextNode(n2, options) {
|
|
920
|
-
|
|
830
|
+
var _a2;
|
|
831
|
+
const { needsMask, maskTextFn, rootId } = options;
|
|
921
832
|
const parent = index$1.parentNode(n2);
|
|
922
833
|
const parentTagName = parent && parent.tagName;
|
|
923
|
-
let
|
|
834
|
+
let text = index$1.textContent(n2);
|
|
924
835
|
const isStyle = parentTagName === "STYLE" ? true : void 0;
|
|
925
836
|
const isScript = parentTagName === "SCRIPT" ? true : void 0;
|
|
926
|
-
if (
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
837
|
+
if (isStyle && text) {
|
|
838
|
+
try {
|
|
839
|
+
if (n2.nextSibling || n2.previousSibling) {
|
|
840
|
+
} else if ((_a2 = parent.sheet) == null ? void 0 : _a2.cssRules) {
|
|
841
|
+
text = stringifyStylesheet(parent.sheet);
|
|
842
|
+
}
|
|
843
|
+
} catch (err) {
|
|
844
|
+
console.warn(
|
|
845
|
+
`Cannot get CSS styles from text's parentNode. Error: ${err}`,
|
|
846
|
+
n2
|
|
847
|
+
);
|
|
932
848
|
}
|
|
849
|
+
text = absolutifyURLs(text, getHref(options.doc));
|
|
933
850
|
}
|
|
934
|
-
if (
|
|
935
|
-
|
|
851
|
+
if (isScript) {
|
|
852
|
+
text = "SCRIPT_PLACEHOLDER";
|
|
853
|
+
}
|
|
854
|
+
if (!isStyle && !isScript && text && needsMask) {
|
|
855
|
+
text = maskTextFn ? maskTextFn(text, index$1.parentElement(n2)) : text.replace(/[\S]/g, "*");
|
|
936
856
|
}
|
|
937
857
|
return {
|
|
938
|
-
type: NodeType$
|
|
939
|
-
textContent:
|
|
858
|
+
type: NodeType$1$1.Text,
|
|
859
|
+
textContent: text || "",
|
|
860
|
+
isStyle,
|
|
940
861
|
rootId
|
|
941
862
|
};
|
|
942
863
|
}
|
|
@@ -997,14 +918,12 @@ function serializeElementNode(n2, options) {
|
|
|
997
918
|
}
|
|
998
919
|
}
|
|
999
920
|
}
|
|
1000
|
-
if (tagName === "style" && n2.sheet
|
|
1001
|
-
|
|
921
|
+
if (tagName === "style" && n2.sheet && // TODO: Currently we only try to get dynamic stylesheet when it is an empty style element
|
|
922
|
+
!(n2.innerText || index$1.textContent(n2) || "").trim().length) {
|
|
923
|
+
const cssText = stringifyStylesheet(
|
|
1002
924
|
n2.sheet
|
|
1003
925
|
);
|
|
1004
926
|
if (cssText) {
|
|
1005
|
-
if (n2.childNodes.length > 1) {
|
|
1006
|
-
cssText = markCssSplits(cssText, n2);
|
|
1007
|
-
}
|
|
1008
927
|
attributes._cssText = cssText;
|
|
1009
928
|
}
|
|
1010
929
|
}
|
|
@@ -1139,7 +1058,7 @@ function serializeElementNode(n2, options) {
|
|
|
1139
1058
|
} catch (e2) {
|
|
1140
1059
|
}
|
|
1141
1060
|
return {
|
|
1142
|
-
type: NodeType$
|
|
1061
|
+
type: NodeType$1$1.Element,
|
|
1143
1062
|
tagName,
|
|
1144
1063
|
attributes,
|
|
1145
1064
|
childNodes: [],
|
|
@@ -1157,9 +1076,9 @@ function lowerIfExists(maybeAttr) {
|
|
|
1157
1076
|
}
|
|
1158
1077
|
}
|
|
1159
1078
|
function slimDOMExcluded(sn, slimDOMOptions) {
|
|
1160
|
-
if (slimDOMOptions.comment && sn.type === NodeType$
|
|
1079
|
+
if (slimDOMOptions.comment && sn.type === NodeType$1$1.Comment) {
|
|
1161
1080
|
return true;
|
|
1162
|
-
} else if (sn.type === NodeType$
|
|
1081
|
+
} else if (sn.type === NodeType$1$1.Element) {
|
|
1163
1082
|
if (slimDOMOptions.script && // script tag
|
|
1164
1083
|
(sn.tagName === "script" || // (module)preload link
|
|
1165
1084
|
sn.tagName === "link" && (sn.attributes.rel === "preload" && sn.attributes.as === "script" || sn.attributes.rel === "modulepreload") || // prefetch link
|
|
@@ -1211,8 +1130,7 @@ function serializeNodeWithId(n2, options) {
|
|
|
1211
1130
|
onStylesheetLoad,
|
|
1212
1131
|
stylesheetLoadTimeout = 5e3,
|
|
1213
1132
|
keepIframeSrcFn = () => false,
|
|
1214
|
-
newlyAddedElement = false
|
|
1215
|
-
cssCaptured = false
|
|
1133
|
+
newlyAddedElement = false
|
|
1216
1134
|
} = options;
|
|
1217
1135
|
let { needsMask } = options;
|
|
1218
1136
|
let { preserveWhiteSpace = true } = options;
|
|
@@ -1239,8 +1157,7 @@ function serializeNodeWithId(n2, options) {
|
|
|
1239
1157
|
inlineImages,
|
|
1240
1158
|
recordCanvas,
|
|
1241
1159
|
keepIframeSrcFn,
|
|
1242
|
-
newlyAddedElement
|
|
1243
|
-
cssCaptured
|
|
1160
|
+
newlyAddedElement
|
|
1244
1161
|
});
|
|
1245
1162
|
if (!_serializedNode) {
|
|
1246
1163
|
console.warn(n2, "not serialized");
|
|
@@ -1249,7 +1166,7 @@ function serializeNodeWithId(n2, options) {
|
|
|
1249
1166
|
let id;
|
|
1250
1167
|
if (mirror2.hasNode(n2)) {
|
|
1251
1168
|
id = mirror2.getId(n2);
|
|
1252
|
-
} else if (slimDOMExcluded(_serializedNode, slimDOMOptions) || !preserveWhiteSpace && _serializedNode.type === NodeType$
|
|
1169
|
+
} else if (slimDOMExcluded(_serializedNode, slimDOMOptions) || !preserveWhiteSpace && _serializedNode.type === NodeType$1$1.Text && !_serializedNode.isStyle && !_serializedNode.textContent.replace(/^\s+|\s+$/gm, "").length) {
|
|
1253
1170
|
id = IGNORED_NODE;
|
|
1254
1171
|
} else {
|
|
1255
1172
|
id = genId();
|
|
@@ -1263,15 +1180,15 @@ function serializeNodeWithId(n2, options) {
|
|
|
1263
1180
|
onSerialize(n2);
|
|
1264
1181
|
}
|
|
1265
1182
|
let recordChild = !skipChild;
|
|
1266
|
-
if (serializedNode.type === NodeType$
|
|
1183
|
+
if (serializedNode.type === NodeType$1$1.Element) {
|
|
1267
1184
|
recordChild = recordChild && !serializedNode.needBlock;
|
|
1268
1185
|
delete serializedNode.needBlock;
|
|
1269
1186
|
const shadowRootEl = index$1.shadowRoot(n2);
|
|
1270
1187
|
if (shadowRootEl && isNativeShadowDom(shadowRootEl))
|
|
1271
1188
|
serializedNode.isShadowHost = true;
|
|
1272
1189
|
}
|
|
1273
|
-
if ((serializedNode.type === NodeType$
|
|
1274
|
-
if (slimDOMOptions.headWhitespace && serializedNode.type === NodeType$
|
|
1190
|
+
if ((serializedNode.type === NodeType$1$1.Document || serializedNode.type === NodeType$1$1.Element) && recordChild) {
|
|
1191
|
+
if (slimDOMOptions.headWhitespace && serializedNode.type === NodeType$1$1.Element && serializedNode.tagName === "head") {
|
|
1275
1192
|
preserveWhiteSpace = false;
|
|
1276
1193
|
}
|
|
1277
1194
|
const bypassOptions = {
|
|
@@ -1297,14 +1214,10 @@ function serializeNodeWithId(n2, options) {
|
|
|
1297
1214
|
iframeLoadTimeout,
|
|
1298
1215
|
onStylesheetLoad,
|
|
1299
1216
|
stylesheetLoadTimeout,
|
|
1300
|
-
keepIframeSrcFn
|
|
1301
|
-
cssCaptured: false
|
|
1217
|
+
keepIframeSrcFn
|
|
1302
1218
|
};
|
|
1303
|
-
if (serializedNode.type === NodeType$
|
|
1219
|
+
if (serializedNode.type === NodeType$1$1.Element && serializedNode.tagName === "textarea" && serializedNode.attributes.value !== void 0) ;
|
|
1304
1220
|
else {
|
|
1305
|
-
if (serializedNode.type === NodeType$3.Element && serializedNode.attributes._cssText !== void 0 && typeof serializedNode.attributes._cssText === "string") {
|
|
1306
|
-
bypassOptions.cssCaptured = true;
|
|
1307
|
-
}
|
|
1308
1221
|
for (const childN of Array.from(index$1.childNodes(n2))) {
|
|
1309
1222
|
const serializedChildNode = serializeNodeWithId(childN, bypassOptions);
|
|
1310
1223
|
if (serializedChildNode) {
|
|
@@ -1327,7 +1240,7 @@ function serializeNodeWithId(n2, options) {
|
|
|
1327
1240
|
if (parent && isShadowRoot(parent) && isNativeShadowDom(parent)) {
|
|
1328
1241
|
serializedNode.isShadow = true;
|
|
1329
1242
|
}
|
|
1330
|
-
if (serializedNode.type === NodeType$
|
|
1243
|
+
if (serializedNode.type === NodeType$1$1.Element && serializedNode.tagName === "iframe") {
|
|
1331
1244
|
onceIframeLoaded(
|
|
1332
1245
|
n2,
|
|
1333
1246
|
() => {
|
|
@@ -1369,7 +1282,7 @@ function serializeNodeWithId(n2, options) {
|
|
|
1369
1282
|
iframeLoadTimeout
|
|
1370
1283
|
);
|
|
1371
1284
|
}
|
|
1372
|
-
if (serializedNode.type === NodeType$
|
|
1285
|
+
if (serializedNode.type === NodeType$1$1.Element && serializedNode.tagName === "link" && typeof serializedNode.attributes.rel === "string" && (serializedNode.attributes.rel === "stylesheet" || serializedNode.attributes.rel === "preload" && typeof serializedNode.attributes.href === "string" && extractFileExtension(serializedNode.attributes.href) === "css")) {
|
|
1373
1286
|
onceStylesheetLoaded(
|
|
1374
1287
|
n2,
|
|
1375
1288
|
() => {
|
|
@@ -10010,18 +9923,9 @@ class MutationBuffer {
|
|
|
10010
9923
|
};
|
|
10011
9924
|
const pushAdd = (n2) => {
|
|
10012
9925
|
const parent = index.parentNode(n2);
|
|
10013
|
-
if (!parent || !inDom(n2)) {
|
|
9926
|
+
if (!parent || !inDom(n2) || parent.tagName === "TEXTAREA") {
|
|
10014
9927
|
return;
|
|
10015
9928
|
}
|
|
10016
|
-
let cssCaptured = false;
|
|
10017
|
-
if (n2.nodeType === Node.TEXT_NODE) {
|
|
10018
|
-
const parentTag = parent.tagName;
|
|
10019
|
-
if (parentTag === "TEXTAREA") {
|
|
10020
|
-
return;
|
|
10021
|
-
} else if (parentTag === "STYLE" && this.addedSet.has(parent)) {
|
|
10022
|
-
cssCaptured = true;
|
|
10023
|
-
}
|
|
10024
|
-
}
|
|
10025
9929
|
const parentId = isShadowRoot(parent) ? this.mirror.getId(getShadowHost(n2)) : this.mirror.getId(parent);
|
|
10026
9930
|
const nextId = getNextId(n2);
|
|
10027
9931
|
if (parentId === -1 || nextId === -1) {
|
|
@@ -10063,8 +9967,7 @@ class MutationBuffer {
|
|
|
10063
9967
|
},
|
|
10064
9968
|
onStylesheetLoad: (link, childSn) => {
|
|
10065
9969
|
this.stylesheetManager.attachLinkElement(link, childSn);
|
|
10066
|
-
}
|
|
10067
|
-
cssCaptured
|
|
9970
|
+
}
|
|
10068
9971
|
});
|
|
10069
9972
|
if (sn) {
|
|
10070
9973
|
adds.push({
|