@checkflow/sdk 1.0.6 → 1.0.7
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/index.esm.js +4507 -337
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +4507 -337
- package/dist/index.js.map +1 -1
- package/dist/session-recording-rrweb.d.ts +100 -0
- package/package.json +3 -2
package/dist/index.esm.js
CHANGED
|
@@ -2714,77 +2714,4074 @@ class FeedbackWidget {
|
|
|
2714
2714
|
}
|
|
2715
2715
|
}
|
|
2716
2716
|
|
|
2717
|
+
var NodeType;
|
|
2718
|
+
(function (NodeType) {
|
|
2719
|
+
NodeType[NodeType["Document"] = 0] = "Document";
|
|
2720
|
+
NodeType[NodeType["DocumentType"] = 1] = "DocumentType";
|
|
2721
|
+
NodeType[NodeType["Element"] = 2] = "Element";
|
|
2722
|
+
NodeType[NodeType["Text"] = 3] = "Text";
|
|
2723
|
+
NodeType[NodeType["CDATA"] = 4] = "CDATA";
|
|
2724
|
+
NodeType[NodeType["Comment"] = 5] = "Comment";
|
|
2725
|
+
})(NodeType || (NodeType = {}));
|
|
2726
|
+
|
|
2727
|
+
function isElement(n) {
|
|
2728
|
+
return n.nodeType === n.ELEMENT_NODE;
|
|
2729
|
+
}
|
|
2730
|
+
function isShadowRoot(n) {
|
|
2731
|
+
var host = n === null || n === void 0 ? void 0 : n.host;
|
|
2732
|
+
return Boolean((host === null || host === void 0 ? void 0 : host.shadowRoot) === n);
|
|
2733
|
+
}
|
|
2734
|
+
function isNativeShadowDom(shadowRoot) {
|
|
2735
|
+
return Object.prototype.toString.call(shadowRoot) === '[object ShadowRoot]';
|
|
2736
|
+
}
|
|
2737
|
+
function fixBrowserCompatibilityIssuesInCSS(cssText) {
|
|
2738
|
+
if (cssText.includes(' background-clip: text;') &&
|
|
2739
|
+
!cssText.includes(' -webkit-background-clip: text;')) {
|
|
2740
|
+
cssText = cssText.replace(' background-clip: text;', ' -webkit-background-clip: text; background-clip: text;');
|
|
2741
|
+
}
|
|
2742
|
+
return cssText;
|
|
2743
|
+
}
|
|
2744
|
+
function getCssRulesString(s) {
|
|
2745
|
+
try {
|
|
2746
|
+
var rules = s.rules || s.cssRules;
|
|
2747
|
+
return rules
|
|
2748
|
+
? fixBrowserCompatibilityIssuesInCSS(Array.from(rules).map(getCssRuleString).join(''))
|
|
2749
|
+
: null;
|
|
2750
|
+
}
|
|
2751
|
+
catch (error) {
|
|
2752
|
+
return null;
|
|
2753
|
+
}
|
|
2754
|
+
}
|
|
2755
|
+
function getCssRuleString(rule) {
|
|
2756
|
+
var cssStringified = rule.cssText;
|
|
2757
|
+
if (isCSSImportRule(rule)) {
|
|
2758
|
+
try {
|
|
2759
|
+
cssStringified = getCssRulesString(rule.styleSheet) || cssStringified;
|
|
2760
|
+
}
|
|
2761
|
+
catch (_a) {
|
|
2762
|
+
}
|
|
2763
|
+
}
|
|
2764
|
+
return cssStringified;
|
|
2765
|
+
}
|
|
2766
|
+
function isCSSImportRule(rule) {
|
|
2767
|
+
return 'styleSheet' in rule;
|
|
2768
|
+
}
|
|
2769
|
+
var Mirror = (function () {
|
|
2770
|
+
function Mirror() {
|
|
2771
|
+
this.idNodeMap = new Map();
|
|
2772
|
+
this.nodeMetaMap = new WeakMap();
|
|
2773
|
+
}
|
|
2774
|
+
Mirror.prototype.getId = function (n) {
|
|
2775
|
+
var _a;
|
|
2776
|
+
if (!n)
|
|
2777
|
+
return -1;
|
|
2778
|
+
var id = (_a = this.getMeta(n)) === null || _a === void 0 ? void 0 : _a.id;
|
|
2779
|
+
return id !== null && id !== void 0 ? id : -1;
|
|
2780
|
+
};
|
|
2781
|
+
Mirror.prototype.getNode = function (id) {
|
|
2782
|
+
return this.idNodeMap.get(id) || null;
|
|
2783
|
+
};
|
|
2784
|
+
Mirror.prototype.getIds = function () {
|
|
2785
|
+
return Array.from(this.idNodeMap.keys());
|
|
2786
|
+
};
|
|
2787
|
+
Mirror.prototype.getMeta = function (n) {
|
|
2788
|
+
return this.nodeMetaMap.get(n) || null;
|
|
2789
|
+
};
|
|
2790
|
+
Mirror.prototype.removeNodeFromMap = function (n) {
|
|
2791
|
+
var _this = this;
|
|
2792
|
+
var id = this.getId(n);
|
|
2793
|
+
this.idNodeMap["delete"](id);
|
|
2794
|
+
if (n.childNodes) {
|
|
2795
|
+
n.childNodes.forEach(function (childNode) {
|
|
2796
|
+
return _this.removeNodeFromMap(childNode);
|
|
2797
|
+
});
|
|
2798
|
+
}
|
|
2799
|
+
};
|
|
2800
|
+
Mirror.prototype.has = function (id) {
|
|
2801
|
+
return this.idNodeMap.has(id);
|
|
2802
|
+
};
|
|
2803
|
+
Mirror.prototype.hasNode = function (node) {
|
|
2804
|
+
return this.nodeMetaMap.has(node);
|
|
2805
|
+
};
|
|
2806
|
+
Mirror.prototype.add = function (n, meta) {
|
|
2807
|
+
var id = meta.id;
|
|
2808
|
+
this.idNodeMap.set(id, n);
|
|
2809
|
+
this.nodeMetaMap.set(n, meta);
|
|
2810
|
+
};
|
|
2811
|
+
Mirror.prototype.replace = function (id, n) {
|
|
2812
|
+
var oldNode = this.getNode(id);
|
|
2813
|
+
if (oldNode) {
|
|
2814
|
+
var meta = this.nodeMetaMap.get(oldNode);
|
|
2815
|
+
if (meta)
|
|
2816
|
+
this.nodeMetaMap.set(n, meta);
|
|
2817
|
+
}
|
|
2818
|
+
this.idNodeMap.set(id, n);
|
|
2819
|
+
};
|
|
2820
|
+
Mirror.prototype.reset = function () {
|
|
2821
|
+
this.idNodeMap = new Map();
|
|
2822
|
+
this.nodeMetaMap = new WeakMap();
|
|
2823
|
+
};
|
|
2824
|
+
return Mirror;
|
|
2825
|
+
}());
|
|
2826
|
+
function createMirror() {
|
|
2827
|
+
return new Mirror();
|
|
2828
|
+
}
|
|
2829
|
+
function maskInputValue(_a) {
|
|
2830
|
+
var maskInputOptions = _a.maskInputOptions, tagName = _a.tagName, type = _a.type, value = _a.value, maskInputFn = _a.maskInputFn;
|
|
2831
|
+
var text = value || '';
|
|
2832
|
+
if (maskInputOptions[tagName.toLowerCase()] ||
|
|
2833
|
+
maskInputOptions[type]) {
|
|
2834
|
+
if (maskInputFn) {
|
|
2835
|
+
text = maskInputFn(text);
|
|
2836
|
+
}
|
|
2837
|
+
else {
|
|
2838
|
+
text = '*'.repeat(text.length);
|
|
2839
|
+
}
|
|
2840
|
+
}
|
|
2841
|
+
return text;
|
|
2842
|
+
}
|
|
2843
|
+
var ORIGINAL_ATTRIBUTE_NAME = '__rrweb_original__';
|
|
2844
|
+
function is2DCanvasBlank(canvas) {
|
|
2845
|
+
var ctx = canvas.getContext('2d');
|
|
2846
|
+
if (!ctx)
|
|
2847
|
+
return true;
|
|
2848
|
+
var chunkSize = 50;
|
|
2849
|
+
for (var x = 0; x < canvas.width; x += chunkSize) {
|
|
2850
|
+
for (var y = 0; y < canvas.height; y += chunkSize) {
|
|
2851
|
+
var getImageData = ctx.getImageData;
|
|
2852
|
+
var originalGetImageData = ORIGINAL_ATTRIBUTE_NAME in getImageData
|
|
2853
|
+
? getImageData[ORIGINAL_ATTRIBUTE_NAME]
|
|
2854
|
+
: getImageData;
|
|
2855
|
+
var pixelBuffer = new Uint32Array(originalGetImageData.call(ctx, x, y, Math.min(chunkSize, canvas.width - x), Math.min(chunkSize, canvas.height - y)).data.buffer);
|
|
2856
|
+
if (pixelBuffer.some(function (pixel) { return pixel !== 0; }))
|
|
2857
|
+
return false;
|
|
2858
|
+
}
|
|
2859
|
+
}
|
|
2860
|
+
return true;
|
|
2861
|
+
}
|
|
2862
|
+
|
|
2863
|
+
var _id = 1;
|
|
2864
|
+
var tagNameRegex = new RegExp('[^a-z0-9-_:]');
|
|
2865
|
+
var IGNORED_NODE = -2;
|
|
2866
|
+
function genId() {
|
|
2867
|
+
return _id++;
|
|
2868
|
+
}
|
|
2869
|
+
function getValidTagName(element) {
|
|
2870
|
+
if (element instanceof HTMLFormElement) {
|
|
2871
|
+
return 'form';
|
|
2872
|
+
}
|
|
2873
|
+
var processedTagName = element.tagName.toLowerCase().trim();
|
|
2874
|
+
if (tagNameRegex.test(processedTagName)) {
|
|
2875
|
+
return 'div';
|
|
2876
|
+
}
|
|
2877
|
+
return processedTagName;
|
|
2878
|
+
}
|
|
2879
|
+
function stringifyStyleSheet(sheet) {
|
|
2880
|
+
return sheet.cssRules
|
|
2881
|
+
? Array.from(sheet.cssRules)
|
|
2882
|
+
.map(function (rule) { return rule.cssText || ''; })
|
|
2883
|
+
.join('')
|
|
2884
|
+
: '';
|
|
2885
|
+
}
|
|
2886
|
+
function extractOrigin(url) {
|
|
2887
|
+
var origin = '';
|
|
2888
|
+
if (url.indexOf('//') > -1) {
|
|
2889
|
+
origin = url.split('/').slice(0, 3).join('/');
|
|
2890
|
+
}
|
|
2891
|
+
else {
|
|
2892
|
+
origin = url.split('/')[0];
|
|
2893
|
+
}
|
|
2894
|
+
origin = origin.split('?')[0];
|
|
2895
|
+
return origin;
|
|
2896
|
+
}
|
|
2897
|
+
var canvasService;
|
|
2898
|
+
var canvasCtx;
|
|
2899
|
+
var URL_IN_CSS_REF = /url\((?:(')([^']*)'|(")(.*?)"|([^)]*))\)/gm;
|
|
2900
|
+
var RELATIVE_PATH = /^(?!www\.|(?:http|ftp)s?:\/\/|[A-Za-z]:\\|\/\/|#).*/;
|
|
2901
|
+
var DATA_URI = /^(data:)([^,]*),(.*)/i;
|
|
2902
|
+
function absoluteToStylesheet(cssText, href) {
|
|
2903
|
+
return (cssText || '').replace(URL_IN_CSS_REF, function (origin, quote1, path1, quote2, path2, path3) {
|
|
2904
|
+
var filePath = path1 || path2 || path3;
|
|
2905
|
+
var maybeQuote = quote1 || quote2 || '';
|
|
2906
|
+
if (!filePath) {
|
|
2907
|
+
return origin;
|
|
2908
|
+
}
|
|
2909
|
+
if (!RELATIVE_PATH.test(filePath)) {
|
|
2910
|
+
return "url(".concat(maybeQuote).concat(filePath).concat(maybeQuote, ")");
|
|
2911
|
+
}
|
|
2912
|
+
if (DATA_URI.test(filePath)) {
|
|
2913
|
+
return "url(".concat(maybeQuote).concat(filePath).concat(maybeQuote, ")");
|
|
2914
|
+
}
|
|
2915
|
+
if (filePath[0] === '/') {
|
|
2916
|
+
return "url(".concat(maybeQuote).concat(extractOrigin(href) + filePath).concat(maybeQuote, ")");
|
|
2917
|
+
}
|
|
2918
|
+
var stack = href.split('/');
|
|
2919
|
+
var parts = filePath.split('/');
|
|
2920
|
+
stack.pop();
|
|
2921
|
+
for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
|
|
2922
|
+
var part = parts_1[_i];
|
|
2923
|
+
if (part === '.') {
|
|
2924
|
+
continue;
|
|
2925
|
+
}
|
|
2926
|
+
else if (part === '..') {
|
|
2927
|
+
stack.pop();
|
|
2928
|
+
}
|
|
2929
|
+
else {
|
|
2930
|
+
stack.push(part);
|
|
2931
|
+
}
|
|
2932
|
+
}
|
|
2933
|
+
return "url(".concat(maybeQuote).concat(stack.join('/')).concat(maybeQuote, ")");
|
|
2934
|
+
});
|
|
2935
|
+
}
|
|
2936
|
+
var SRCSET_NOT_SPACES = /^[^ \t\n\r\u000c]+/;
|
|
2937
|
+
var SRCSET_COMMAS_OR_SPACES = /^[, \t\n\r\u000c]+/;
|
|
2938
|
+
function getAbsoluteSrcsetString(doc, attributeValue) {
|
|
2939
|
+
if (attributeValue.trim() === '') {
|
|
2940
|
+
return attributeValue;
|
|
2941
|
+
}
|
|
2942
|
+
var pos = 0;
|
|
2943
|
+
function collectCharacters(regEx) {
|
|
2944
|
+
var chars;
|
|
2945
|
+
var match = regEx.exec(attributeValue.substring(pos));
|
|
2946
|
+
if (match) {
|
|
2947
|
+
chars = match[0];
|
|
2948
|
+
pos += chars.length;
|
|
2949
|
+
return chars;
|
|
2950
|
+
}
|
|
2951
|
+
return '';
|
|
2952
|
+
}
|
|
2953
|
+
var output = [];
|
|
2954
|
+
while (true) {
|
|
2955
|
+
collectCharacters(SRCSET_COMMAS_OR_SPACES);
|
|
2956
|
+
if (pos >= attributeValue.length) {
|
|
2957
|
+
break;
|
|
2958
|
+
}
|
|
2959
|
+
var url = collectCharacters(SRCSET_NOT_SPACES);
|
|
2960
|
+
if (url.slice(-1) === ',') {
|
|
2961
|
+
url = absoluteToDoc(doc, url.substring(0, url.length - 1));
|
|
2962
|
+
output.push(url);
|
|
2963
|
+
}
|
|
2964
|
+
else {
|
|
2965
|
+
var descriptorsStr = '';
|
|
2966
|
+
url = absoluteToDoc(doc, url);
|
|
2967
|
+
var inParens = false;
|
|
2968
|
+
while (true) {
|
|
2969
|
+
var c = attributeValue.charAt(pos);
|
|
2970
|
+
if (c === '') {
|
|
2971
|
+
output.push((url + descriptorsStr).trim());
|
|
2972
|
+
break;
|
|
2973
|
+
}
|
|
2974
|
+
else if (!inParens) {
|
|
2975
|
+
if (c === ',') {
|
|
2976
|
+
pos += 1;
|
|
2977
|
+
output.push((url + descriptorsStr).trim());
|
|
2978
|
+
break;
|
|
2979
|
+
}
|
|
2980
|
+
else if (c === '(') {
|
|
2981
|
+
inParens = true;
|
|
2982
|
+
}
|
|
2983
|
+
}
|
|
2984
|
+
else {
|
|
2985
|
+
if (c === ')') {
|
|
2986
|
+
inParens = false;
|
|
2987
|
+
}
|
|
2988
|
+
}
|
|
2989
|
+
descriptorsStr += c;
|
|
2990
|
+
pos += 1;
|
|
2991
|
+
}
|
|
2992
|
+
}
|
|
2993
|
+
}
|
|
2994
|
+
return output.join(', ');
|
|
2995
|
+
}
|
|
2996
|
+
function absoluteToDoc(doc, attributeValue) {
|
|
2997
|
+
if (!attributeValue || attributeValue.trim() === '') {
|
|
2998
|
+
return attributeValue;
|
|
2999
|
+
}
|
|
3000
|
+
var a = doc.createElement('a');
|
|
3001
|
+
a.href = attributeValue;
|
|
3002
|
+
return a.href;
|
|
3003
|
+
}
|
|
3004
|
+
function isSVGElement(el) {
|
|
3005
|
+
return Boolean(el.tagName === 'svg' || el.ownerSVGElement);
|
|
3006
|
+
}
|
|
3007
|
+
function getHref() {
|
|
3008
|
+
var a = document.createElement('a');
|
|
3009
|
+
a.href = '';
|
|
3010
|
+
return a.href;
|
|
3011
|
+
}
|
|
3012
|
+
function transformAttribute(doc, tagName, name, value) {
|
|
3013
|
+
if (name === 'src' ||
|
|
3014
|
+
(name === 'href' && value && !(tagName === 'use' && value[0] === '#'))) {
|
|
3015
|
+
return absoluteToDoc(doc, value);
|
|
3016
|
+
}
|
|
3017
|
+
else if (name === 'xlink:href' && value && value[0] !== '#') {
|
|
3018
|
+
return absoluteToDoc(doc, value);
|
|
3019
|
+
}
|
|
3020
|
+
else if (name === 'background' &&
|
|
3021
|
+
value &&
|
|
3022
|
+
(tagName === 'table' || tagName === 'td' || tagName === 'th')) {
|
|
3023
|
+
return absoluteToDoc(doc, value);
|
|
3024
|
+
}
|
|
3025
|
+
else if (name === 'srcset' && value) {
|
|
3026
|
+
return getAbsoluteSrcsetString(doc, value);
|
|
3027
|
+
}
|
|
3028
|
+
else if (name === 'style' && value) {
|
|
3029
|
+
return absoluteToStylesheet(value, getHref());
|
|
3030
|
+
}
|
|
3031
|
+
else if (tagName === 'object' && name === 'data' && value) {
|
|
3032
|
+
return absoluteToDoc(doc, value);
|
|
3033
|
+
}
|
|
3034
|
+
else {
|
|
3035
|
+
return value;
|
|
3036
|
+
}
|
|
3037
|
+
}
|
|
3038
|
+
function _isBlockedElement(element, blockClass, blockSelector) {
|
|
3039
|
+
if (typeof blockClass === 'string') {
|
|
3040
|
+
if (element.classList.contains(blockClass)) {
|
|
3041
|
+
return true;
|
|
3042
|
+
}
|
|
3043
|
+
}
|
|
3044
|
+
else {
|
|
3045
|
+
for (var eIndex = element.classList.length; eIndex--;) {
|
|
3046
|
+
var className = element.classList[eIndex];
|
|
3047
|
+
if (blockClass.test(className)) {
|
|
3048
|
+
return true;
|
|
3049
|
+
}
|
|
3050
|
+
}
|
|
3051
|
+
}
|
|
3052
|
+
if (blockSelector) {
|
|
3053
|
+
return element.matches(blockSelector);
|
|
3054
|
+
}
|
|
3055
|
+
return false;
|
|
3056
|
+
}
|
|
3057
|
+
function classMatchesRegex(node, regex, checkAncestors) {
|
|
3058
|
+
if (!node)
|
|
3059
|
+
return false;
|
|
3060
|
+
if (node.nodeType !== node.ELEMENT_NODE) {
|
|
3061
|
+
if (!checkAncestors)
|
|
3062
|
+
return false;
|
|
3063
|
+
return classMatchesRegex(node.parentNode, regex, checkAncestors);
|
|
3064
|
+
}
|
|
3065
|
+
for (var eIndex = node.classList.length; eIndex--;) {
|
|
3066
|
+
var className = node.classList[eIndex];
|
|
3067
|
+
if (regex.test(className)) {
|
|
3068
|
+
return true;
|
|
3069
|
+
}
|
|
3070
|
+
}
|
|
3071
|
+
if (!checkAncestors)
|
|
3072
|
+
return false;
|
|
3073
|
+
return classMatchesRegex(node.parentNode, regex, checkAncestors);
|
|
3074
|
+
}
|
|
3075
|
+
function needMaskingText(node, maskTextClass, maskTextSelector) {
|
|
3076
|
+
var el = node.nodeType === node.ELEMENT_NODE
|
|
3077
|
+
? node
|
|
3078
|
+
: node.parentElement;
|
|
3079
|
+
if (el === null)
|
|
3080
|
+
return false;
|
|
3081
|
+
if (typeof maskTextClass === 'string') {
|
|
3082
|
+
if (el.classList.contains(maskTextClass))
|
|
3083
|
+
return true;
|
|
3084
|
+
if (el.closest(".".concat(maskTextClass)))
|
|
3085
|
+
return true;
|
|
3086
|
+
}
|
|
3087
|
+
else {
|
|
3088
|
+
if (classMatchesRegex(el, maskTextClass, true))
|
|
3089
|
+
return true;
|
|
3090
|
+
}
|
|
3091
|
+
if (maskTextSelector) {
|
|
3092
|
+
if (el.matches(maskTextSelector))
|
|
3093
|
+
return true;
|
|
3094
|
+
if (el.closest(maskTextSelector))
|
|
3095
|
+
return true;
|
|
3096
|
+
}
|
|
3097
|
+
return false;
|
|
3098
|
+
}
|
|
3099
|
+
function onceIframeLoaded(iframeEl, listener, iframeLoadTimeout) {
|
|
3100
|
+
var win = iframeEl.contentWindow;
|
|
3101
|
+
if (!win) {
|
|
3102
|
+
return;
|
|
3103
|
+
}
|
|
3104
|
+
var fired = false;
|
|
3105
|
+
var readyState;
|
|
3106
|
+
try {
|
|
3107
|
+
readyState = win.document.readyState;
|
|
3108
|
+
}
|
|
3109
|
+
catch (error) {
|
|
3110
|
+
return;
|
|
3111
|
+
}
|
|
3112
|
+
if (readyState !== 'complete') {
|
|
3113
|
+
var timer_1 = setTimeout(function () {
|
|
3114
|
+
if (!fired) {
|
|
3115
|
+
listener();
|
|
3116
|
+
fired = true;
|
|
3117
|
+
}
|
|
3118
|
+
}, iframeLoadTimeout);
|
|
3119
|
+
iframeEl.addEventListener('load', function () {
|
|
3120
|
+
clearTimeout(timer_1);
|
|
3121
|
+
fired = true;
|
|
3122
|
+
listener();
|
|
3123
|
+
});
|
|
3124
|
+
return;
|
|
3125
|
+
}
|
|
3126
|
+
var blankUrl = 'about:blank';
|
|
3127
|
+
if (win.location.href !== blankUrl ||
|
|
3128
|
+
iframeEl.src === blankUrl ||
|
|
3129
|
+
iframeEl.src === '') {
|
|
3130
|
+
setTimeout(listener, 0);
|
|
3131
|
+
return iframeEl.addEventListener('load', listener);
|
|
3132
|
+
}
|
|
3133
|
+
iframeEl.addEventListener('load', listener);
|
|
3134
|
+
}
|
|
3135
|
+
function onceStylesheetLoaded(link, listener, styleSheetLoadTimeout) {
|
|
3136
|
+
var fired = false;
|
|
3137
|
+
var styleSheetLoaded;
|
|
3138
|
+
try {
|
|
3139
|
+
styleSheetLoaded = link.sheet;
|
|
3140
|
+
}
|
|
3141
|
+
catch (error) {
|
|
3142
|
+
return;
|
|
3143
|
+
}
|
|
3144
|
+
if (styleSheetLoaded)
|
|
3145
|
+
return;
|
|
3146
|
+
var timer = setTimeout(function () {
|
|
3147
|
+
if (!fired) {
|
|
3148
|
+
listener();
|
|
3149
|
+
fired = true;
|
|
3150
|
+
}
|
|
3151
|
+
}, styleSheetLoadTimeout);
|
|
3152
|
+
link.addEventListener('load', function () {
|
|
3153
|
+
clearTimeout(timer);
|
|
3154
|
+
fired = true;
|
|
3155
|
+
listener();
|
|
3156
|
+
});
|
|
3157
|
+
}
|
|
3158
|
+
function serializeNode(n, options) {
|
|
3159
|
+
var doc = options.doc, mirror = options.mirror, blockClass = options.blockClass, blockSelector = options.blockSelector, maskTextClass = options.maskTextClass, maskTextSelector = options.maskTextSelector, inlineStylesheet = options.inlineStylesheet, _a = options.maskInputOptions, maskInputOptions = _a === void 0 ? {} : _a, maskTextFn = options.maskTextFn, maskInputFn = options.maskInputFn, _b = options.dataURLOptions, dataURLOptions = _b === void 0 ? {} : _b, inlineImages = options.inlineImages, recordCanvas = options.recordCanvas, keepIframeSrcFn = options.keepIframeSrcFn, _c = options.newlyAddedElement, newlyAddedElement = _c === void 0 ? false : _c;
|
|
3160
|
+
var rootId = getRootId(doc, mirror);
|
|
3161
|
+
switch (n.nodeType) {
|
|
3162
|
+
case n.DOCUMENT_NODE:
|
|
3163
|
+
if (n.compatMode !== 'CSS1Compat') {
|
|
3164
|
+
return {
|
|
3165
|
+
type: NodeType.Document,
|
|
3166
|
+
childNodes: [],
|
|
3167
|
+
compatMode: n.compatMode
|
|
3168
|
+
};
|
|
3169
|
+
}
|
|
3170
|
+
else {
|
|
3171
|
+
return {
|
|
3172
|
+
type: NodeType.Document,
|
|
3173
|
+
childNodes: []
|
|
3174
|
+
};
|
|
3175
|
+
}
|
|
3176
|
+
case n.DOCUMENT_TYPE_NODE:
|
|
3177
|
+
return {
|
|
3178
|
+
type: NodeType.DocumentType,
|
|
3179
|
+
name: n.name,
|
|
3180
|
+
publicId: n.publicId,
|
|
3181
|
+
systemId: n.systemId,
|
|
3182
|
+
rootId: rootId
|
|
3183
|
+
};
|
|
3184
|
+
case n.ELEMENT_NODE:
|
|
3185
|
+
return serializeElementNode(n, {
|
|
3186
|
+
doc: doc,
|
|
3187
|
+
blockClass: blockClass,
|
|
3188
|
+
blockSelector: blockSelector,
|
|
3189
|
+
inlineStylesheet: inlineStylesheet,
|
|
3190
|
+
maskInputOptions: maskInputOptions,
|
|
3191
|
+
maskInputFn: maskInputFn,
|
|
3192
|
+
dataURLOptions: dataURLOptions,
|
|
3193
|
+
inlineImages: inlineImages,
|
|
3194
|
+
recordCanvas: recordCanvas,
|
|
3195
|
+
keepIframeSrcFn: keepIframeSrcFn,
|
|
3196
|
+
newlyAddedElement: newlyAddedElement,
|
|
3197
|
+
rootId: rootId
|
|
3198
|
+
});
|
|
3199
|
+
case n.TEXT_NODE:
|
|
3200
|
+
return serializeTextNode(n, {
|
|
3201
|
+
maskTextClass: maskTextClass,
|
|
3202
|
+
maskTextSelector: maskTextSelector,
|
|
3203
|
+
maskTextFn: maskTextFn,
|
|
3204
|
+
rootId: rootId
|
|
3205
|
+
});
|
|
3206
|
+
case n.CDATA_SECTION_NODE:
|
|
3207
|
+
return {
|
|
3208
|
+
type: NodeType.CDATA,
|
|
3209
|
+
textContent: '',
|
|
3210
|
+
rootId: rootId
|
|
3211
|
+
};
|
|
3212
|
+
case n.COMMENT_NODE:
|
|
3213
|
+
return {
|
|
3214
|
+
type: NodeType.Comment,
|
|
3215
|
+
textContent: n.textContent || '',
|
|
3216
|
+
rootId: rootId
|
|
3217
|
+
};
|
|
3218
|
+
default:
|
|
3219
|
+
return false;
|
|
3220
|
+
}
|
|
3221
|
+
}
|
|
3222
|
+
function getRootId(doc, mirror) {
|
|
3223
|
+
if (!mirror.hasNode(doc))
|
|
3224
|
+
return undefined;
|
|
3225
|
+
var docId = mirror.getId(doc);
|
|
3226
|
+
return docId === 1 ? undefined : docId;
|
|
3227
|
+
}
|
|
3228
|
+
function serializeTextNode(n, options) {
|
|
3229
|
+
var _a;
|
|
3230
|
+
var maskTextClass = options.maskTextClass, maskTextSelector = options.maskTextSelector, maskTextFn = options.maskTextFn, rootId = options.rootId;
|
|
3231
|
+
var parentTagName = n.parentNode && n.parentNode.tagName;
|
|
3232
|
+
var textContent = n.textContent;
|
|
3233
|
+
var isStyle = parentTagName === 'STYLE' ? true : undefined;
|
|
3234
|
+
var isScript = parentTagName === 'SCRIPT' ? true : undefined;
|
|
3235
|
+
if (isStyle && textContent) {
|
|
3236
|
+
try {
|
|
3237
|
+
if (n.nextSibling || n.previousSibling) {
|
|
3238
|
+
}
|
|
3239
|
+
else if ((_a = n.parentNode.sheet) === null || _a === void 0 ? void 0 : _a.cssRules) {
|
|
3240
|
+
textContent = stringifyStyleSheet(n.parentNode.sheet);
|
|
3241
|
+
}
|
|
3242
|
+
}
|
|
3243
|
+
catch (err) {
|
|
3244
|
+
console.warn("Cannot get CSS styles from text's parentNode. Error: ".concat(err), n);
|
|
3245
|
+
}
|
|
3246
|
+
textContent = absoluteToStylesheet(textContent, getHref());
|
|
3247
|
+
}
|
|
3248
|
+
if (isScript) {
|
|
3249
|
+
textContent = 'SCRIPT_PLACEHOLDER';
|
|
3250
|
+
}
|
|
3251
|
+
if (!isStyle &&
|
|
3252
|
+
!isScript &&
|
|
3253
|
+
textContent &&
|
|
3254
|
+
needMaskingText(n, maskTextClass, maskTextSelector)) {
|
|
3255
|
+
textContent = maskTextFn
|
|
3256
|
+
? maskTextFn(textContent)
|
|
3257
|
+
: textContent.replace(/[\S]/g, '*');
|
|
3258
|
+
}
|
|
3259
|
+
return {
|
|
3260
|
+
type: NodeType.Text,
|
|
3261
|
+
textContent: textContent || '',
|
|
3262
|
+
isStyle: isStyle,
|
|
3263
|
+
rootId: rootId
|
|
3264
|
+
};
|
|
3265
|
+
}
|
|
3266
|
+
function serializeElementNode(n, options) {
|
|
3267
|
+
var doc = options.doc, blockClass = options.blockClass, blockSelector = options.blockSelector, inlineStylesheet = options.inlineStylesheet, _a = options.maskInputOptions, maskInputOptions = _a === void 0 ? {} : _a, maskInputFn = options.maskInputFn, _b = options.dataURLOptions, dataURLOptions = _b === void 0 ? {} : _b, inlineImages = options.inlineImages, recordCanvas = options.recordCanvas, keepIframeSrcFn = options.keepIframeSrcFn, _c = options.newlyAddedElement, newlyAddedElement = _c === void 0 ? false : _c, rootId = options.rootId;
|
|
3268
|
+
var needBlock = _isBlockedElement(n, blockClass, blockSelector);
|
|
3269
|
+
var tagName = getValidTagName(n);
|
|
3270
|
+
var attributes = {};
|
|
3271
|
+
var len = n.attributes.length;
|
|
3272
|
+
for (var i = 0; i < len; i++) {
|
|
3273
|
+
var attr = n.attributes[i];
|
|
3274
|
+
attributes[attr.name] = transformAttribute(doc, tagName, attr.name, attr.value);
|
|
3275
|
+
}
|
|
3276
|
+
if (tagName === 'link' && inlineStylesheet) {
|
|
3277
|
+
var stylesheet = Array.from(doc.styleSheets).find(function (s) {
|
|
3278
|
+
return s.href === n.href;
|
|
3279
|
+
});
|
|
3280
|
+
var cssText = null;
|
|
3281
|
+
if (stylesheet) {
|
|
3282
|
+
cssText = getCssRulesString(stylesheet);
|
|
3283
|
+
}
|
|
3284
|
+
if (cssText) {
|
|
3285
|
+
delete attributes.rel;
|
|
3286
|
+
delete attributes.href;
|
|
3287
|
+
attributes._cssText = absoluteToStylesheet(cssText, stylesheet.href);
|
|
3288
|
+
}
|
|
3289
|
+
}
|
|
3290
|
+
if (tagName === 'style' &&
|
|
3291
|
+
n.sheet &&
|
|
3292
|
+
!(n.innerText || n.textContent || '').trim().length) {
|
|
3293
|
+
var cssText = getCssRulesString(n.sheet);
|
|
3294
|
+
if (cssText) {
|
|
3295
|
+
attributes._cssText = absoluteToStylesheet(cssText, getHref());
|
|
3296
|
+
}
|
|
3297
|
+
}
|
|
3298
|
+
if (tagName === 'input' || tagName === 'textarea' || tagName === 'select') {
|
|
3299
|
+
var value = n.value;
|
|
3300
|
+
var checked = n.checked;
|
|
3301
|
+
if (attributes.type !== 'radio' &&
|
|
3302
|
+
attributes.type !== 'checkbox' &&
|
|
3303
|
+
attributes.type !== 'submit' &&
|
|
3304
|
+
attributes.type !== 'button' &&
|
|
3305
|
+
value) {
|
|
3306
|
+
attributes.value = maskInputValue({
|
|
3307
|
+
type: attributes.type,
|
|
3308
|
+
tagName: tagName,
|
|
3309
|
+
value: value,
|
|
3310
|
+
maskInputOptions: maskInputOptions,
|
|
3311
|
+
maskInputFn: maskInputFn
|
|
3312
|
+
});
|
|
3313
|
+
}
|
|
3314
|
+
else if (checked) {
|
|
3315
|
+
attributes.checked = checked;
|
|
3316
|
+
}
|
|
3317
|
+
}
|
|
3318
|
+
if (tagName === 'option') {
|
|
3319
|
+
if (n.selected && !maskInputOptions['select']) {
|
|
3320
|
+
attributes.selected = true;
|
|
3321
|
+
}
|
|
3322
|
+
else {
|
|
3323
|
+
delete attributes.selected;
|
|
3324
|
+
}
|
|
3325
|
+
}
|
|
3326
|
+
if (tagName === 'canvas' && recordCanvas) {
|
|
3327
|
+
if (n.__context === '2d') {
|
|
3328
|
+
if (!is2DCanvasBlank(n)) {
|
|
3329
|
+
attributes.rr_dataURL = n.toDataURL(dataURLOptions.type, dataURLOptions.quality);
|
|
3330
|
+
}
|
|
3331
|
+
}
|
|
3332
|
+
else if (!('__context' in n)) {
|
|
3333
|
+
var canvasDataURL = n.toDataURL(dataURLOptions.type, dataURLOptions.quality);
|
|
3334
|
+
var blankCanvas = document.createElement('canvas');
|
|
3335
|
+
blankCanvas.width = n.width;
|
|
3336
|
+
blankCanvas.height = n.height;
|
|
3337
|
+
var blankCanvasDataURL = blankCanvas.toDataURL(dataURLOptions.type, dataURLOptions.quality);
|
|
3338
|
+
if (canvasDataURL !== blankCanvasDataURL) {
|
|
3339
|
+
attributes.rr_dataURL = canvasDataURL;
|
|
3340
|
+
}
|
|
3341
|
+
}
|
|
3342
|
+
}
|
|
3343
|
+
if (tagName === 'img' && inlineImages) {
|
|
3344
|
+
if (!canvasService) {
|
|
3345
|
+
canvasService = doc.createElement('canvas');
|
|
3346
|
+
canvasCtx = canvasService.getContext('2d');
|
|
3347
|
+
}
|
|
3348
|
+
var image_1 = n;
|
|
3349
|
+
var oldValue_1 = image_1.crossOrigin;
|
|
3350
|
+
image_1.crossOrigin = 'anonymous';
|
|
3351
|
+
var recordInlineImage = function () {
|
|
3352
|
+
try {
|
|
3353
|
+
canvasService.width = image_1.naturalWidth;
|
|
3354
|
+
canvasService.height = image_1.naturalHeight;
|
|
3355
|
+
canvasCtx.drawImage(image_1, 0, 0);
|
|
3356
|
+
attributes.rr_dataURL = canvasService.toDataURL(dataURLOptions.type, dataURLOptions.quality);
|
|
3357
|
+
}
|
|
3358
|
+
catch (err) {
|
|
3359
|
+
console.warn("Cannot inline img src=".concat(image_1.currentSrc, "! Error: ").concat(err));
|
|
3360
|
+
}
|
|
3361
|
+
oldValue_1
|
|
3362
|
+
? (attributes.crossOrigin = oldValue_1)
|
|
3363
|
+
: image_1.removeAttribute('crossorigin');
|
|
3364
|
+
};
|
|
3365
|
+
if (image_1.complete && image_1.naturalWidth !== 0)
|
|
3366
|
+
recordInlineImage();
|
|
3367
|
+
else
|
|
3368
|
+
image_1.onload = recordInlineImage;
|
|
3369
|
+
}
|
|
3370
|
+
if (tagName === 'audio' || tagName === 'video') {
|
|
3371
|
+
attributes.rr_mediaState = n.paused
|
|
3372
|
+
? 'paused'
|
|
3373
|
+
: 'played';
|
|
3374
|
+
attributes.rr_mediaCurrentTime = n.currentTime;
|
|
3375
|
+
}
|
|
3376
|
+
if (!newlyAddedElement) {
|
|
3377
|
+
if (n.scrollLeft) {
|
|
3378
|
+
attributes.rr_scrollLeft = n.scrollLeft;
|
|
3379
|
+
}
|
|
3380
|
+
if (n.scrollTop) {
|
|
3381
|
+
attributes.rr_scrollTop = n.scrollTop;
|
|
3382
|
+
}
|
|
3383
|
+
}
|
|
3384
|
+
if (needBlock) {
|
|
3385
|
+
var _d = n.getBoundingClientRect(), width = _d.width, height = _d.height;
|
|
3386
|
+
attributes = {
|
|
3387
|
+
"class": attributes["class"],
|
|
3388
|
+
rr_width: "".concat(width, "px"),
|
|
3389
|
+
rr_height: "".concat(height, "px")
|
|
3390
|
+
};
|
|
3391
|
+
}
|
|
3392
|
+
if (tagName === 'iframe' && !keepIframeSrcFn(attributes.src)) {
|
|
3393
|
+
if (!n.contentDocument) {
|
|
3394
|
+
attributes.rr_src = attributes.src;
|
|
3395
|
+
}
|
|
3396
|
+
delete attributes.src;
|
|
3397
|
+
}
|
|
3398
|
+
return {
|
|
3399
|
+
type: NodeType.Element,
|
|
3400
|
+
tagName: tagName,
|
|
3401
|
+
attributes: attributes,
|
|
3402
|
+
childNodes: [],
|
|
3403
|
+
isSVG: isSVGElement(n) || undefined,
|
|
3404
|
+
needBlock: needBlock,
|
|
3405
|
+
rootId: rootId
|
|
3406
|
+
};
|
|
3407
|
+
}
|
|
3408
|
+
function lowerIfExists(maybeAttr) {
|
|
3409
|
+
if (maybeAttr === undefined) {
|
|
3410
|
+
return '';
|
|
3411
|
+
}
|
|
3412
|
+
else {
|
|
3413
|
+
return maybeAttr.toLowerCase();
|
|
3414
|
+
}
|
|
3415
|
+
}
|
|
3416
|
+
function slimDOMExcluded(sn, slimDOMOptions) {
|
|
3417
|
+
if (slimDOMOptions.comment && sn.type === NodeType.Comment) {
|
|
3418
|
+
return true;
|
|
3419
|
+
}
|
|
3420
|
+
else if (sn.type === NodeType.Element) {
|
|
3421
|
+
if (slimDOMOptions.script &&
|
|
3422
|
+
(sn.tagName === 'script' ||
|
|
3423
|
+
(sn.tagName === 'link' &&
|
|
3424
|
+
sn.attributes.rel === 'preload' &&
|
|
3425
|
+
sn.attributes.as === 'script') ||
|
|
3426
|
+
(sn.tagName === 'link' &&
|
|
3427
|
+
sn.attributes.rel === 'prefetch' &&
|
|
3428
|
+
typeof sn.attributes.href === 'string' &&
|
|
3429
|
+
sn.attributes.href.endsWith('.js')))) {
|
|
3430
|
+
return true;
|
|
3431
|
+
}
|
|
3432
|
+
else if (slimDOMOptions.headFavicon &&
|
|
3433
|
+
((sn.tagName === 'link' && sn.attributes.rel === 'shortcut icon') ||
|
|
3434
|
+
(sn.tagName === 'meta' &&
|
|
3435
|
+
(lowerIfExists(sn.attributes.name).match(/^msapplication-tile(image|color)$/) ||
|
|
3436
|
+
lowerIfExists(sn.attributes.name) === 'application-name' ||
|
|
3437
|
+
lowerIfExists(sn.attributes.rel) === 'icon' ||
|
|
3438
|
+
lowerIfExists(sn.attributes.rel) === 'apple-touch-icon' ||
|
|
3439
|
+
lowerIfExists(sn.attributes.rel) === 'shortcut icon')))) {
|
|
3440
|
+
return true;
|
|
3441
|
+
}
|
|
3442
|
+
else if (sn.tagName === 'meta') {
|
|
3443
|
+
if (slimDOMOptions.headMetaDescKeywords &&
|
|
3444
|
+
lowerIfExists(sn.attributes.name).match(/^description|keywords$/)) {
|
|
3445
|
+
return true;
|
|
3446
|
+
}
|
|
3447
|
+
else if (slimDOMOptions.headMetaSocial &&
|
|
3448
|
+
(lowerIfExists(sn.attributes.property).match(/^(og|twitter|fb):/) ||
|
|
3449
|
+
lowerIfExists(sn.attributes.name).match(/^(og|twitter):/) ||
|
|
3450
|
+
lowerIfExists(sn.attributes.name) === 'pinterest')) {
|
|
3451
|
+
return true;
|
|
3452
|
+
}
|
|
3453
|
+
else if (slimDOMOptions.headMetaRobots &&
|
|
3454
|
+
(lowerIfExists(sn.attributes.name) === 'robots' ||
|
|
3455
|
+
lowerIfExists(sn.attributes.name) === 'googlebot' ||
|
|
3456
|
+
lowerIfExists(sn.attributes.name) === 'bingbot')) {
|
|
3457
|
+
return true;
|
|
3458
|
+
}
|
|
3459
|
+
else if (slimDOMOptions.headMetaHttpEquiv &&
|
|
3460
|
+
sn.attributes['http-equiv'] !== undefined) {
|
|
3461
|
+
return true;
|
|
3462
|
+
}
|
|
3463
|
+
else if (slimDOMOptions.headMetaAuthorship &&
|
|
3464
|
+
(lowerIfExists(sn.attributes.name) === 'author' ||
|
|
3465
|
+
lowerIfExists(sn.attributes.name) === 'generator' ||
|
|
3466
|
+
lowerIfExists(sn.attributes.name) === 'framework' ||
|
|
3467
|
+
lowerIfExists(sn.attributes.name) === 'publisher' ||
|
|
3468
|
+
lowerIfExists(sn.attributes.name) === 'progid' ||
|
|
3469
|
+
lowerIfExists(sn.attributes.property).match(/^article:/) ||
|
|
3470
|
+
lowerIfExists(sn.attributes.property).match(/^product:/))) {
|
|
3471
|
+
return true;
|
|
3472
|
+
}
|
|
3473
|
+
else if (slimDOMOptions.headMetaVerification &&
|
|
3474
|
+
(lowerIfExists(sn.attributes.name) === 'google-site-verification' ||
|
|
3475
|
+
lowerIfExists(sn.attributes.name) === 'yandex-verification' ||
|
|
3476
|
+
lowerIfExists(sn.attributes.name) === 'csrf-token' ||
|
|
3477
|
+
lowerIfExists(sn.attributes.name) === 'p:domain_verify' ||
|
|
3478
|
+
lowerIfExists(sn.attributes.name) === 'verify-v1' ||
|
|
3479
|
+
lowerIfExists(sn.attributes.name) === 'verification' ||
|
|
3480
|
+
lowerIfExists(sn.attributes.name) === 'shopify-checkout-api-token')) {
|
|
3481
|
+
return true;
|
|
3482
|
+
}
|
|
3483
|
+
}
|
|
3484
|
+
}
|
|
3485
|
+
return false;
|
|
3486
|
+
}
|
|
3487
|
+
function serializeNodeWithId(n, options) {
|
|
3488
|
+
var doc = options.doc, mirror = options.mirror, blockClass = options.blockClass, blockSelector = options.blockSelector, maskTextClass = options.maskTextClass, maskTextSelector = options.maskTextSelector, _a = options.skipChild, skipChild = _a === void 0 ? false : _a, _b = options.inlineStylesheet, inlineStylesheet = _b === void 0 ? true : _b, _c = options.maskInputOptions, maskInputOptions = _c === void 0 ? {} : _c, maskTextFn = options.maskTextFn, maskInputFn = options.maskInputFn, slimDOMOptions = options.slimDOMOptions, _d = options.dataURLOptions, dataURLOptions = _d === void 0 ? {} : _d, _e = options.inlineImages, inlineImages = _e === void 0 ? false : _e, _f = options.recordCanvas, recordCanvas = _f === void 0 ? false : _f, onSerialize = options.onSerialize, onIframeLoad = options.onIframeLoad, _g = options.iframeLoadTimeout, iframeLoadTimeout = _g === void 0 ? 5000 : _g, onStylesheetLoad = options.onStylesheetLoad, _h = options.stylesheetLoadTimeout, stylesheetLoadTimeout = _h === void 0 ? 5000 : _h, _j = options.keepIframeSrcFn, keepIframeSrcFn = _j === void 0 ? function () { return false; } : _j, _k = options.newlyAddedElement, newlyAddedElement = _k === void 0 ? false : _k;
|
|
3489
|
+
var _l = options.preserveWhiteSpace, preserveWhiteSpace = _l === void 0 ? true : _l;
|
|
3490
|
+
var _serializedNode = serializeNode(n, {
|
|
3491
|
+
doc: doc,
|
|
3492
|
+
mirror: mirror,
|
|
3493
|
+
blockClass: blockClass,
|
|
3494
|
+
blockSelector: blockSelector,
|
|
3495
|
+
maskTextClass: maskTextClass,
|
|
3496
|
+
maskTextSelector: maskTextSelector,
|
|
3497
|
+
inlineStylesheet: inlineStylesheet,
|
|
3498
|
+
maskInputOptions: maskInputOptions,
|
|
3499
|
+
maskTextFn: maskTextFn,
|
|
3500
|
+
maskInputFn: maskInputFn,
|
|
3501
|
+
dataURLOptions: dataURLOptions,
|
|
3502
|
+
inlineImages: inlineImages,
|
|
3503
|
+
recordCanvas: recordCanvas,
|
|
3504
|
+
keepIframeSrcFn: keepIframeSrcFn,
|
|
3505
|
+
newlyAddedElement: newlyAddedElement
|
|
3506
|
+
});
|
|
3507
|
+
if (!_serializedNode) {
|
|
3508
|
+
console.warn(n, 'not serialized');
|
|
3509
|
+
return null;
|
|
3510
|
+
}
|
|
3511
|
+
var id;
|
|
3512
|
+
if (mirror.hasNode(n)) {
|
|
3513
|
+
id = mirror.getId(n);
|
|
3514
|
+
}
|
|
3515
|
+
else if (slimDOMExcluded(_serializedNode, slimDOMOptions) ||
|
|
3516
|
+
(!preserveWhiteSpace &&
|
|
3517
|
+
_serializedNode.type === NodeType.Text &&
|
|
3518
|
+
!_serializedNode.isStyle &&
|
|
3519
|
+
!_serializedNode.textContent.replace(/^\s+|\s+$/gm, '').length)) {
|
|
3520
|
+
id = IGNORED_NODE;
|
|
3521
|
+
}
|
|
3522
|
+
else {
|
|
3523
|
+
id = genId();
|
|
3524
|
+
}
|
|
3525
|
+
var serializedNode = Object.assign(_serializedNode, { id: id });
|
|
3526
|
+
mirror.add(n, serializedNode);
|
|
3527
|
+
if (id === IGNORED_NODE) {
|
|
3528
|
+
return null;
|
|
3529
|
+
}
|
|
3530
|
+
if (onSerialize) {
|
|
3531
|
+
onSerialize(n);
|
|
3532
|
+
}
|
|
3533
|
+
var recordChild = !skipChild;
|
|
3534
|
+
if (serializedNode.type === NodeType.Element) {
|
|
3535
|
+
recordChild = recordChild && !serializedNode.needBlock;
|
|
3536
|
+
delete serializedNode.needBlock;
|
|
3537
|
+
var shadowRoot = n.shadowRoot;
|
|
3538
|
+
if (shadowRoot && isNativeShadowDom(shadowRoot))
|
|
3539
|
+
serializedNode.isShadowHost = true;
|
|
3540
|
+
}
|
|
3541
|
+
if ((serializedNode.type === NodeType.Document ||
|
|
3542
|
+
serializedNode.type === NodeType.Element) &&
|
|
3543
|
+
recordChild) {
|
|
3544
|
+
if (slimDOMOptions.headWhitespace &&
|
|
3545
|
+
serializedNode.type === NodeType.Element &&
|
|
3546
|
+
serializedNode.tagName === 'head') {
|
|
3547
|
+
preserveWhiteSpace = false;
|
|
3548
|
+
}
|
|
3549
|
+
var bypassOptions = {
|
|
3550
|
+
doc: doc,
|
|
3551
|
+
mirror: mirror,
|
|
3552
|
+
blockClass: blockClass,
|
|
3553
|
+
blockSelector: blockSelector,
|
|
3554
|
+
maskTextClass: maskTextClass,
|
|
3555
|
+
maskTextSelector: maskTextSelector,
|
|
3556
|
+
skipChild: skipChild,
|
|
3557
|
+
inlineStylesheet: inlineStylesheet,
|
|
3558
|
+
maskInputOptions: maskInputOptions,
|
|
3559
|
+
maskTextFn: maskTextFn,
|
|
3560
|
+
maskInputFn: maskInputFn,
|
|
3561
|
+
slimDOMOptions: slimDOMOptions,
|
|
3562
|
+
dataURLOptions: dataURLOptions,
|
|
3563
|
+
inlineImages: inlineImages,
|
|
3564
|
+
recordCanvas: recordCanvas,
|
|
3565
|
+
preserveWhiteSpace: preserveWhiteSpace,
|
|
3566
|
+
onSerialize: onSerialize,
|
|
3567
|
+
onIframeLoad: onIframeLoad,
|
|
3568
|
+
iframeLoadTimeout: iframeLoadTimeout,
|
|
3569
|
+
onStylesheetLoad: onStylesheetLoad,
|
|
3570
|
+
stylesheetLoadTimeout: stylesheetLoadTimeout,
|
|
3571
|
+
keepIframeSrcFn: keepIframeSrcFn
|
|
3572
|
+
};
|
|
3573
|
+
for (var _i = 0, _m = Array.from(n.childNodes); _i < _m.length; _i++) {
|
|
3574
|
+
var childN = _m[_i];
|
|
3575
|
+
var serializedChildNode = serializeNodeWithId(childN, bypassOptions);
|
|
3576
|
+
if (serializedChildNode) {
|
|
3577
|
+
serializedNode.childNodes.push(serializedChildNode);
|
|
3578
|
+
}
|
|
3579
|
+
}
|
|
3580
|
+
if (isElement(n) && n.shadowRoot) {
|
|
3581
|
+
for (var _o = 0, _p = Array.from(n.shadowRoot.childNodes); _o < _p.length; _o++) {
|
|
3582
|
+
var childN = _p[_o];
|
|
3583
|
+
var serializedChildNode = serializeNodeWithId(childN, bypassOptions);
|
|
3584
|
+
if (serializedChildNode) {
|
|
3585
|
+
isNativeShadowDom(n.shadowRoot) &&
|
|
3586
|
+
(serializedChildNode.isShadow = true);
|
|
3587
|
+
serializedNode.childNodes.push(serializedChildNode);
|
|
3588
|
+
}
|
|
3589
|
+
}
|
|
3590
|
+
}
|
|
3591
|
+
}
|
|
3592
|
+
if (n.parentNode &&
|
|
3593
|
+
isShadowRoot(n.parentNode) &&
|
|
3594
|
+
isNativeShadowDom(n.parentNode)) {
|
|
3595
|
+
serializedNode.isShadow = true;
|
|
3596
|
+
}
|
|
3597
|
+
if (serializedNode.type === NodeType.Element &&
|
|
3598
|
+
serializedNode.tagName === 'iframe') {
|
|
3599
|
+
onceIframeLoaded(n, function () {
|
|
3600
|
+
var iframeDoc = n.contentDocument;
|
|
3601
|
+
if (iframeDoc && onIframeLoad) {
|
|
3602
|
+
var serializedIframeNode = serializeNodeWithId(iframeDoc, {
|
|
3603
|
+
doc: iframeDoc,
|
|
3604
|
+
mirror: mirror,
|
|
3605
|
+
blockClass: blockClass,
|
|
3606
|
+
blockSelector: blockSelector,
|
|
3607
|
+
maskTextClass: maskTextClass,
|
|
3608
|
+
maskTextSelector: maskTextSelector,
|
|
3609
|
+
skipChild: false,
|
|
3610
|
+
inlineStylesheet: inlineStylesheet,
|
|
3611
|
+
maskInputOptions: maskInputOptions,
|
|
3612
|
+
maskTextFn: maskTextFn,
|
|
3613
|
+
maskInputFn: maskInputFn,
|
|
3614
|
+
slimDOMOptions: slimDOMOptions,
|
|
3615
|
+
dataURLOptions: dataURLOptions,
|
|
3616
|
+
inlineImages: inlineImages,
|
|
3617
|
+
recordCanvas: recordCanvas,
|
|
3618
|
+
preserveWhiteSpace: preserveWhiteSpace,
|
|
3619
|
+
onSerialize: onSerialize,
|
|
3620
|
+
onIframeLoad: onIframeLoad,
|
|
3621
|
+
iframeLoadTimeout: iframeLoadTimeout,
|
|
3622
|
+
onStylesheetLoad: onStylesheetLoad,
|
|
3623
|
+
stylesheetLoadTimeout: stylesheetLoadTimeout,
|
|
3624
|
+
keepIframeSrcFn: keepIframeSrcFn
|
|
3625
|
+
});
|
|
3626
|
+
if (serializedIframeNode) {
|
|
3627
|
+
onIframeLoad(n, serializedIframeNode);
|
|
3628
|
+
}
|
|
3629
|
+
}
|
|
3630
|
+
}, iframeLoadTimeout);
|
|
3631
|
+
}
|
|
3632
|
+
if (serializedNode.type === NodeType.Element &&
|
|
3633
|
+
serializedNode.tagName === 'link' &&
|
|
3634
|
+
serializedNode.attributes.rel === 'stylesheet') {
|
|
3635
|
+
onceStylesheetLoaded(n, function () {
|
|
3636
|
+
if (onStylesheetLoad) {
|
|
3637
|
+
var serializedLinkNode = serializeNodeWithId(n, {
|
|
3638
|
+
doc: doc,
|
|
3639
|
+
mirror: mirror,
|
|
3640
|
+
blockClass: blockClass,
|
|
3641
|
+
blockSelector: blockSelector,
|
|
3642
|
+
maskTextClass: maskTextClass,
|
|
3643
|
+
maskTextSelector: maskTextSelector,
|
|
3644
|
+
skipChild: false,
|
|
3645
|
+
inlineStylesheet: inlineStylesheet,
|
|
3646
|
+
maskInputOptions: maskInputOptions,
|
|
3647
|
+
maskTextFn: maskTextFn,
|
|
3648
|
+
maskInputFn: maskInputFn,
|
|
3649
|
+
slimDOMOptions: slimDOMOptions,
|
|
3650
|
+
dataURLOptions: dataURLOptions,
|
|
3651
|
+
inlineImages: inlineImages,
|
|
3652
|
+
recordCanvas: recordCanvas,
|
|
3653
|
+
preserveWhiteSpace: preserveWhiteSpace,
|
|
3654
|
+
onSerialize: onSerialize,
|
|
3655
|
+
onIframeLoad: onIframeLoad,
|
|
3656
|
+
iframeLoadTimeout: iframeLoadTimeout,
|
|
3657
|
+
onStylesheetLoad: onStylesheetLoad,
|
|
3658
|
+
stylesheetLoadTimeout: stylesheetLoadTimeout,
|
|
3659
|
+
keepIframeSrcFn: keepIframeSrcFn
|
|
3660
|
+
});
|
|
3661
|
+
if (serializedLinkNode) {
|
|
3662
|
+
onStylesheetLoad(n, serializedLinkNode);
|
|
3663
|
+
}
|
|
3664
|
+
}
|
|
3665
|
+
}, stylesheetLoadTimeout);
|
|
3666
|
+
}
|
|
3667
|
+
return serializedNode;
|
|
3668
|
+
}
|
|
3669
|
+
function snapshot(n, options) {
|
|
3670
|
+
var _a = options || {}, _b = _a.mirror, mirror = _b === void 0 ? new Mirror() : _b, _c = _a.blockClass, blockClass = _c === void 0 ? 'rr-block' : _c, _d = _a.blockSelector, blockSelector = _d === void 0 ? null : _d, _e = _a.maskTextClass, maskTextClass = _e === void 0 ? 'rr-mask' : _e, _f = _a.maskTextSelector, maskTextSelector = _f === void 0 ? null : _f, _g = _a.inlineStylesheet, inlineStylesheet = _g === void 0 ? true : _g, _h = _a.inlineImages, inlineImages = _h === void 0 ? false : _h, _j = _a.recordCanvas, recordCanvas = _j === void 0 ? false : _j, _k = _a.maskAllInputs, maskAllInputs = _k === void 0 ? false : _k, maskTextFn = _a.maskTextFn, maskInputFn = _a.maskInputFn, _l = _a.slimDOM, slimDOM = _l === void 0 ? false : _l, dataURLOptions = _a.dataURLOptions, preserveWhiteSpace = _a.preserveWhiteSpace, onSerialize = _a.onSerialize, onIframeLoad = _a.onIframeLoad, iframeLoadTimeout = _a.iframeLoadTimeout, onStylesheetLoad = _a.onStylesheetLoad, stylesheetLoadTimeout = _a.stylesheetLoadTimeout, _m = _a.keepIframeSrcFn, keepIframeSrcFn = _m === void 0 ? function () { return false; } : _m;
|
|
3671
|
+
var maskInputOptions = maskAllInputs === true
|
|
3672
|
+
? {
|
|
3673
|
+
color: true,
|
|
3674
|
+
date: true,
|
|
3675
|
+
'datetime-local': true,
|
|
3676
|
+
email: true,
|
|
3677
|
+
month: true,
|
|
3678
|
+
number: true,
|
|
3679
|
+
range: true,
|
|
3680
|
+
search: true,
|
|
3681
|
+
tel: true,
|
|
3682
|
+
text: true,
|
|
3683
|
+
time: true,
|
|
3684
|
+
url: true,
|
|
3685
|
+
week: true,
|
|
3686
|
+
textarea: true,
|
|
3687
|
+
select: true,
|
|
3688
|
+
password: true
|
|
3689
|
+
}
|
|
3690
|
+
: maskAllInputs === false
|
|
3691
|
+
? {
|
|
3692
|
+
password: true
|
|
3693
|
+
}
|
|
3694
|
+
: maskAllInputs;
|
|
3695
|
+
var slimDOMOptions = slimDOM === true || slimDOM === 'all'
|
|
3696
|
+
?
|
|
3697
|
+
{
|
|
3698
|
+
script: true,
|
|
3699
|
+
comment: true,
|
|
3700
|
+
headFavicon: true,
|
|
3701
|
+
headWhitespace: true,
|
|
3702
|
+
headMetaDescKeywords: slimDOM === 'all',
|
|
3703
|
+
headMetaSocial: true,
|
|
3704
|
+
headMetaRobots: true,
|
|
3705
|
+
headMetaHttpEquiv: true,
|
|
3706
|
+
headMetaAuthorship: true,
|
|
3707
|
+
headMetaVerification: true
|
|
3708
|
+
}
|
|
3709
|
+
: slimDOM === false
|
|
3710
|
+
? {}
|
|
3711
|
+
: slimDOM;
|
|
3712
|
+
return serializeNodeWithId(n, {
|
|
3713
|
+
doc: n,
|
|
3714
|
+
mirror: mirror,
|
|
3715
|
+
blockClass: blockClass,
|
|
3716
|
+
blockSelector: blockSelector,
|
|
3717
|
+
maskTextClass: maskTextClass,
|
|
3718
|
+
maskTextSelector: maskTextSelector,
|
|
3719
|
+
skipChild: false,
|
|
3720
|
+
inlineStylesheet: inlineStylesheet,
|
|
3721
|
+
maskInputOptions: maskInputOptions,
|
|
3722
|
+
maskTextFn: maskTextFn,
|
|
3723
|
+
maskInputFn: maskInputFn,
|
|
3724
|
+
slimDOMOptions: slimDOMOptions,
|
|
3725
|
+
dataURLOptions: dataURLOptions,
|
|
3726
|
+
inlineImages: inlineImages,
|
|
3727
|
+
recordCanvas: recordCanvas,
|
|
3728
|
+
preserveWhiteSpace: preserveWhiteSpace,
|
|
3729
|
+
onSerialize: onSerialize,
|
|
3730
|
+
onIframeLoad: onIframeLoad,
|
|
3731
|
+
iframeLoadTimeout: iframeLoadTimeout,
|
|
3732
|
+
onStylesheetLoad: onStylesheetLoad,
|
|
3733
|
+
stylesheetLoadTimeout: stylesheetLoadTimeout,
|
|
3734
|
+
keepIframeSrcFn: keepIframeSrcFn,
|
|
3735
|
+
newlyAddedElement: false
|
|
3736
|
+
});
|
|
3737
|
+
}
|
|
3738
|
+
|
|
3739
|
+
function on(type, fn, target = document) {
|
|
3740
|
+
const options = { capture: true, passive: true };
|
|
3741
|
+
target.addEventListener(type, fn, options);
|
|
3742
|
+
return () => target.removeEventListener(type, fn, options);
|
|
3743
|
+
}
|
|
3744
|
+
const DEPARTED_MIRROR_ACCESS_WARNING = 'Please stop import mirror directly. Instead of that,' +
|
|
3745
|
+
'\r\n' +
|
|
3746
|
+
'now you can use replayer.getMirror() to access the mirror instance of a replayer,' +
|
|
3747
|
+
'\r\n' +
|
|
3748
|
+
'or you can use record.mirror to access the mirror instance during recording.';
|
|
3749
|
+
let _mirror = {
|
|
3750
|
+
map: {},
|
|
3751
|
+
getId() {
|
|
3752
|
+
console.error(DEPARTED_MIRROR_ACCESS_WARNING);
|
|
3753
|
+
return -1;
|
|
3754
|
+
},
|
|
3755
|
+
getNode() {
|
|
3756
|
+
console.error(DEPARTED_MIRROR_ACCESS_WARNING);
|
|
3757
|
+
return null;
|
|
3758
|
+
},
|
|
3759
|
+
removeNodeFromMap() {
|
|
3760
|
+
console.error(DEPARTED_MIRROR_ACCESS_WARNING);
|
|
3761
|
+
},
|
|
3762
|
+
has() {
|
|
3763
|
+
console.error(DEPARTED_MIRROR_ACCESS_WARNING);
|
|
3764
|
+
return false;
|
|
3765
|
+
},
|
|
3766
|
+
reset() {
|
|
3767
|
+
console.error(DEPARTED_MIRROR_ACCESS_WARNING);
|
|
3768
|
+
},
|
|
3769
|
+
};
|
|
3770
|
+
if (typeof window !== 'undefined' && window.Proxy && window.Reflect) {
|
|
3771
|
+
_mirror = new Proxy(_mirror, {
|
|
3772
|
+
get(target, prop, receiver) {
|
|
3773
|
+
if (prop === 'map') {
|
|
3774
|
+
console.error(DEPARTED_MIRROR_ACCESS_WARNING);
|
|
3775
|
+
}
|
|
3776
|
+
return Reflect.get(target, prop, receiver);
|
|
3777
|
+
},
|
|
3778
|
+
});
|
|
3779
|
+
}
|
|
3780
|
+
function throttle(func, wait, options = {}) {
|
|
3781
|
+
let timeout = null;
|
|
3782
|
+
let previous = 0;
|
|
3783
|
+
return function (...args) {
|
|
3784
|
+
const now = Date.now();
|
|
3785
|
+
if (!previous && options.leading === false) {
|
|
3786
|
+
previous = now;
|
|
3787
|
+
}
|
|
3788
|
+
const remaining = wait - (now - previous);
|
|
3789
|
+
const context = this;
|
|
3790
|
+
if (remaining <= 0 || remaining > wait) {
|
|
3791
|
+
if (timeout) {
|
|
3792
|
+
clearTimeout(timeout);
|
|
3793
|
+
timeout = null;
|
|
3794
|
+
}
|
|
3795
|
+
previous = now;
|
|
3796
|
+
func.apply(context, args);
|
|
3797
|
+
}
|
|
3798
|
+
else if (!timeout && options.trailing !== false) {
|
|
3799
|
+
timeout = setTimeout(() => {
|
|
3800
|
+
previous = options.leading === false ? 0 : Date.now();
|
|
3801
|
+
timeout = null;
|
|
3802
|
+
func.apply(context, args);
|
|
3803
|
+
}, remaining);
|
|
3804
|
+
}
|
|
3805
|
+
};
|
|
3806
|
+
}
|
|
3807
|
+
function hookSetter(target, key, d, isRevoked, win = window) {
|
|
3808
|
+
const original = win.Object.getOwnPropertyDescriptor(target, key);
|
|
3809
|
+
win.Object.defineProperty(target, key, isRevoked
|
|
3810
|
+
? d
|
|
3811
|
+
: {
|
|
3812
|
+
set(value) {
|
|
3813
|
+
setTimeout(() => {
|
|
3814
|
+
d.set.call(this, value);
|
|
3815
|
+
}, 0);
|
|
3816
|
+
if (original && original.set) {
|
|
3817
|
+
original.set.call(this, value);
|
|
3818
|
+
}
|
|
3819
|
+
},
|
|
3820
|
+
});
|
|
3821
|
+
return () => hookSetter(target, key, original || {}, true);
|
|
3822
|
+
}
|
|
3823
|
+
function patch(source, name, replacement) {
|
|
3824
|
+
try {
|
|
3825
|
+
if (!(name in source)) {
|
|
3826
|
+
return () => {
|
|
3827
|
+
};
|
|
3828
|
+
}
|
|
3829
|
+
const original = source[name];
|
|
3830
|
+
const wrapped = replacement(original);
|
|
3831
|
+
if (typeof wrapped === 'function') {
|
|
3832
|
+
wrapped.prototype = wrapped.prototype || {};
|
|
3833
|
+
Object.defineProperties(wrapped, {
|
|
3834
|
+
__rrweb_original__: {
|
|
3835
|
+
enumerable: false,
|
|
3836
|
+
value: original,
|
|
3837
|
+
},
|
|
3838
|
+
});
|
|
3839
|
+
}
|
|
3840
|
+
source[name] = wrapped;
|
|
3841
|
+
return () => {
|
|
3842
|
+
source[name] = original;
|
|
3843
|
+
};
|
|
3844
|
+
}
|
|
3845
|
+
catch (_a) {
|
|
3846
|
+
return () => {
|
|
3847
|
+
};
|
|
3848
|
+
}
|
|
3849
|
+
}
|
|
3850
|
+
function getWindowHeight() {
|
|
3851
|
+
return (window.innerHeight ||
|
|
3852
|
+
(document.documentElement && document.documentElement.clientHeight) ||
|
|
3853
|
+
(document.body && document.body.clientHeight));
|
|
3854
|
+
}
|
|
3855
|
+
function getWindowWidth() {
|
|
3856
|
+
return (window.innerWidth ||
|
|
3857
|
+
(document.documentElement && document.documentElement.clientWidth) ||
|
|
3858
|
+
(document.body && document.body.clientWidth));
|
|
3859
|
+
}
|
|
3860
|
+
function isBlocked(node, blockClass, blockSelector, checkAncestors) {
|
|
3861
|
+
if (!node) {
|
|
3862
|
+
return false;
|
|
3863
|
+
}
|
|
3864
|
+
const el = node.nodeType === node.ELEMENT_NODE
|
|
3865
|
+
? node
|
|
3866
|
+
: node.parentElement;
|
|
3867
|
+
if (!el)
|
|
3868
|
+
return false;
|
|
3869
|
+
if (typeof blockClass === 'string') {
|
|
3870
|
+
if (el.classList.contains(blockClass))
|
|
3871
|
+
return true;
|
|
3872
|
+
if (checkAncestors && el.closest('.' + blockClass) !== null)
|
|
3873
|
+
return true;
|
|
3874
|
+
}
|
|
3875
|
+
else {
|
|
3876
|
+
if (classMatchesRegex(el, blockClass, checkAncestors))
|
|
3877
|
+
return true;
|
|
3878
|
+
}
|
|
3879
|
+
if (blockSelector) {
|
|
3880
|
+
if (node.matches(blockSelector))
|
|
3881
|
+
return true;
|
|
3882
|
+
if (checkAncestors && el.closest(blockSelector) !== null)
|
|
3883
|
+
return true;
|
|
3884
|
+
}
|
|
3885
|
+
return false;
|
|
3886
|
+
}
|
|
3887
|
+
function isSerialized(n, mirror) {
|
|
3888
|
+
return mirror.getId(n) !== -1;
|
|
3889
|
+
}
|
|
3890
|
+
function isIgnored(n, mirror) {
|
|
3891
|
+
return mirror.getId(n) === IGNORED_NODE;
|
|
3892
|
+
}
|
|
3893
|
+
function isAncestorRemoved(target, mirror) {
|
|
3894
|
+
if (isShadowRoot(target)) {
|
|
3895
|
+
return false;
|
|
3896
|
+
}
|
|
3897
|
+
const id = mirror.getId(target);
|
|
3898
|
+
if (!mirror.has(id)) {
|
|
3899
|
+
return true;
|
|
3900
|
+
}
|
|
3901
|
+
if (target.parentNode &&
|
|
3902
|
+
target.parentNode.nodeType === target.DOCUMENT_NODE) {
|
|
3903
|
+
return false;
|
|
3904
|
+
}
|
|
3905
|
+
if (!target.parentNode) {
|
|
3906
|
+
return true;
|
|
3907
|
+
}
|
|
3908
|
+
return isAncestorRemoved(target.parentNode, mirror);
|
|
3909
|
+
}
|
|
3910
|
+
function isTouchEvent(event) {
|
|
3911
|
+
return Boolean(event.changedTouches);
|
|
3912
|
+
}
|
|
3913
|
+
function polyfill(win = window) {
|
|
3914
|
+
if ('NodeList' in win && !win.NodeList.prototype.forEach) {
|
|
3915
|
+
win.NodeList.prototype.forEach = Array.prototype
|
|
3916
|
+
.forEach;
|
|
3917
|
+
}
|
|
3918
|
+
if ('DOMTokenList' in win && !win.DOMTokenList.prototype.forEach) {
|
|
3919
|
+
win.DOMTokenList.prototype.forEach = Array.prototype
|
|
3920
|
+
.forEach;
|
|
3921
|
+
}
|
|
3922
|
+
if (!Node.prototype.contains) {
|
|
3923
|
+
Node.prototype.contains = (...args) => {
|
|
3924
|
+
let node = args[0];
|
|
3925
|
+
if (!(0 in args)) {
|
|
3926
|
+
throw new TypeError('1 argument is required');
|
|
3927
|
+
}
|
|
3928
|
+
do {
|
|
3929
|
+
if (this === node) {
|
|
3930
|
+
return true;
|
|
3931
|
+
}
|
|
3932
|
+
} while ((node = node && node.parentNode));
|
|
3933
|
+
return false;
|
|
3934
|
+
};
|
|
3935
|
+
}
|
|
3936
|
+
}
|
|
3937
|
+
function isSerializedIframe(n, mirror) {
|
|
3938
|
+
return Boolean(n.nodeName === 'IFRAME' && mirror.getMeta(n));
|
|
3939
|
+
}
|
|
3940
|
+
function isSerializedStylesheet(n, mirror) {
|
|
3941
|
+
return Boolean(n.nodeName === 'LINK' &&
|
|
3942
|
+
n.nodeType === n.ELEMENT_NODE &&
|
|
3943
|
+
n.getAttribute &&
|
|
3944
|
+
n.getAttribute('rel') === 'stylesheet' &&
|
|
3945
|
+
mirror.getMeta(n));
|
|
3946
|
+
}
|
|
3947
|
+
function hasShadowRoot(n) {
|
|
3948
|
+
return Boolean(n === null || n === void 0 ? void 0 : n.shadowRoot);
|
|
3949
|
+
}
|
|
3950
|
+
class StyleSheetMirror {
|
|
3951
|
+
constructor() {
|
|
3952
|
+
this.id = 1;
|
|
3953
|
+
this.styleIDMap = new WeakMap();
|
|
3954
|
+
this.idStyleMap = new Map();
|
|
3955
|
+
}
|
|
3956
|
+
getId(stylesheet) {
|
|
3957
|
+
var _a;
|
|
3958
|
+
return (_a = this.styleIDMap.get(stylesheet)) !== null && _a !== void 0 ? _a : -1;
|
|
3959
|
+
}
|
|
3960
|
+
has(stylesheet) {
|
|
3961
|
+
return this.styleIDMap.has(stylesheet);
|
|
3962
|
+
}
|
|
3963
|
+
add(stylesheet, id) {
|
|
3964
|
+
if (this.has(stylesheet))
|
|
3965
|
+
return this.getId(stylesheet);
|
|
3966
|
+
let newId;
|
|
3967
|
+
if (id === undefined) {
|
|
3968
|
+
newId = this.id++;
|
|
3969
|
+
}
|
|
3970
|
+
else
|
|
3971
|
+
newId = id;
|
|
3972
|
+
this.styleIDMap.set(stylesheet, newId);
|
|
3973
|
+
this.idStyleMap.set(newId, stylesheet);
|
|
3974
|
+
return newId;
|
|
3975
|
+
}
|
|
3976
|
+
getStyle(id) {
|
|
3977
|
+
return this.idStyleMap.get(id) || null;
|
|
3978
|
+
}
|
|
3979
|
+
reset() {
|
|
3980
|
+
this.styleIDMap = new WeakMap();
|
|
3981
|
+
this.idStyleMap = new Map();
|
|
3982
|
+
this.id = 1;
|
|
3983
|
+
}
|
|
3984
|
+
generateId() {
|
|
3985
|
+
return this.id++;
|
|
3986
|
+
}
|
|
3987
|
+
}
|
|
3988
|
+
|
|
3989
|
+
var EventType = /* @__PURE__ */ ((EventType2) => {
|
|
3990
|
+
EventType2[EventType2["DomContentLoaded"] = 0] = "DomContentLoaded";
|
|
3991
|
+
EventType2[EventType2["Load"] = 1] = "Load";
|
|
3992
|
+
EventType2[EventType2["FullSnapshot"] = 2] = "FullSnapshot";
|
|
3993
|
+
EventType2[EventType2["IncrementalSnapshot"] = 3] = "IncrementalSnapshot";
|
|
3994
|
+
EventType2[EventType2["Meta"] = 4] = "Meta";
|
|
3995
|
+
EventType2[EventType2["Custom"] = 5] = "Custom";
|
|
3996
|
+
EventType2[EventType2["Plugin"] = 6] = "Plugin";
|
|
3997
|
+
return EventType2;
|
|
3998
|
+
})(EventType || {});
|
|
3999
|
+
var IncrementalSource = /* @__PURE__ */ ((IncrementalSource2) => {
|
|
4000
|
+
IncrementalSource2[IncrementalSource2["Mutation"] = 0] = "Mutation";
|
|
4001
|
+
IncrementalSource2[IncrementalSource2["MouseMove"] = 1] = "MouseMove";
|
|
4002
|
+
IncrementalSource2[IncrementalSource2["MouseInteraction"] = 2] = "MouseInteraction";
|
|
4003
|
+
IncrementalSource2[IncrementalSource2["Scroll"] = 3] = "Scroll";
|
|
4004
|
+
IncrementalSource2[IncrementalSource2["ViewportResize"] = 4] = "ViewportResize";
|
|
4005
|
+
IncrementalSource2[IncrementalSource2["Input"] = 5] = "Input";
|
|
4006
|
+
IncrementalSource2[IncrementalSource2["TouchMove"] = 6] = "TouchMove";
|
|
4007
|
+
IncrementalSource2[IncrementalSource2["MediaInteraction"] = 7] = "MediaInteraction";
|
|
4008
|
+
IncrementalSource2[IncrementalSource2["StyleSheetRule"] = 8] = "StyleSheetRule";
|
|
4009
|
+
IncrementalSource2[IncrementalSource2["CanvasMutation"] = 9] = "CanvasMutation";
|
|
4010
|
+
IncrementalSource2[IncrementalSource2["Font"] = 10] = "Font";
|
|
4011
|
+
IncrementalSource2[IncrementalSource2["Log"] = 11] = "Log";
|
|
4012
|
+
IncrementalSource2[IncrementalSource2["Drag"] = 12] = "Drag";
|
|
4013
|
+
IncrementalSource2[IncrementalSource2["StyleDeclaration"] = 13] = "StyleDeclaration";
|
|
4014
|
+
IncrementalSource2[IncrementalSource2["Selection"] = 14] = "Selection";
|
|
4015
|
+
IncrementalSource2[IncrementalSource2["AdoptedStyleSheet"] = 15] = "AdoptedStyleSheet";
|
|
4016
|
+
return IncrementalSource2;
|
|
4017
|
+
})(IncrementalSource || {});
|
|
4018
|
+
var MouseInteractions = /* @__PURE__ */ ((MouseInteractions2) => {
|
|
4019
|
+
MouseInteractions2[MouseInteractions2["MouseUp"] = 0] = "MouseUp";
|
|
4020
|
+
MouseInteractions2[MouseInteractions2["MouseDown"] = 1] = "MouseDown";
|
|
4021
|
+
MouseInteractions2[MouseInteractions2["Click"] = 2] = "Click";
|
|
4022
|
+
MouseInteractions2[MouseInteractions2["ContextMenu"] = 3] = "ContextMenu";
|
|
4023
|
+
MouseInteractions2[MouseInteractions2["DblClick"] = 4] = "DblClick";
|
|
4024
|
+
MouseInteractions2[MouseInteractions2["Focus"] = 5] = "Focus";
|
|
4025
|
+
MouseInteractions2[MouseInteractions2["Blur"] = 6] = "Blur";
|
|
4026
|
+
MouseInteractions2[MouseInteractions2["TouchStart"] = 7] = "TouchStart";
|
|
4027
|
+
MouseInteractions2[MouseInteractions2["TouchMove_Departed"] = 8] = "TouchMove_Departed";
|
|
4028
|
+
MouseInteractions2[MouseInteractions2["TouchEnd"] = 9] = "TouchEnd";
|
|
4029
|
+
MouseInteractions2[MouseInteractions2["TouchCancel"] = 10] = "TouchCancel";
|
|
4030
|
+
return MouseInteractions2;
|
|
4031
|
+
})(MouseInteractions || {});
|
|
4032
|
+
var CanvasContext = /* @__PURE__ */ ((CanvasContext2) => {
|
|
4033
|
+
CanvasContext2[CanvasContext2["2D"] = 0] = "2D";
|
|
4034
|
+
CanvasContext2[CanvasContext2["WebGL"] = 1] = "WebGL";
|
|
4035
|
+
CanvasContext2[CanvasContext2["WebGL2"] = 2] = "WebGL2";
|
|
4036
|
+
return CanvasContext2;
|
|
4037
|
+
})(CanvasContext || {});
|
|
4038
|
+
|
|
4039
|
+
function isNodeInLinkedList(n) {
|
|
4040
|
+
return '__ln' in n;
|
|
4041
|
+
}
|
|
4042
|
+
class DoubleLinkedList {
|
|
4043
|
+
constructor() {
|
|
4044
|
+
this.length = 0;
|
|
4045
|
+
this.head = null;
|
|
4046
|
+
}
|
|
4047
|
+
get(position) {
|
|
4048
|
+
if (position >= this.length) {
|
|
4049
|
+
throw new Error('Position outside of list range');
|
|
4050
|
+
}
|
|
4051
|
+
let current = this.head;
|
|
4052
|
+
for (let index = 0; index < position; index++) {
|
|
4053
|
+
current = (current === null || current === void 0 ? void 0 : current.next) || null;
|
|
4054
|
+
}
|
|
4055
|
+
return current;
|
|
4056
|
+
}
|
|
4057
|
+
addNode(n) {
|
|
4058
|
+
const node = {
|
|
4059
|
+
value: n,
|
|
4060
|
+
previous: null,
|
|
4061
|
+
next: null,
|
|
4062
|
+
};
|
|
4063
|
+
n.__ln = node;
|
|
4064
|
+
if (n.previousSibling && isNodeInLinkedList(n.previousSibling)) {
|
|
4065
|
+
const current = n.previousSibling.__ln.next;
|
|
4066
|
+
node.next = current;
|
|
4067
|
+
node.previous = n.previousSibling.__ln;
|
|
4068
|
+
n.previousSibling.__ln.next = node;
|
|
4069
|
+
if (current) {
|
|
4070
|
+
current.previous = node;
|
|
4071
|
+
}
|
|
4072
|
+
}
|
|
4073
|
+
else if (n.nextSibling &&
|
|
4074
|
+
isNodeInLinkedList(n.nextSibling) &&
|
|
4075
|
+
n.nextSibling.__ln.previous) {
|
|
4076
|
+
const current = n.nextSibling.__ln.previous;
|
|
4077
|
+
node.previous = current;
|
|
4078
|
+
node.next = n.nextSibling.__ln;
|
|
4079
|
+
n.nextSibling.__ln.previous = node;
|
|
4080
|
+
if (current) {
|
|
4081
|
+
current.next = node;
|
|
4082
|
+
}
|
|
4083
|
+
}
|
|
4084
|
+
else {
|
|
4085
|
+
if (this.head) {
|
|
4086
|
+
this.head.previous = node;
|
|
4087
|
+
}
|
|
4088
|
+
node.next = this.head;
|
|
4089
|
+
this.head = node;
|
|
4090
|
+
}
|
|
4091
|
+
this.length++;
|
|
4092
|
+
}
|
|
4093
|
+
removeNode(n) {
|
|
4094
|
+
const current = n.__ln;
|
|
4095
|
+
if (!this.head) {
|
|
4096
|
+
return;
|
|
4097
|
+
}
|
|
4098
|
+
if (!current.previous) {
|
|
4099
|
+
this.head = current.next;
|
|
4100
|
+
if (this.head) {
|
|
4101
|
+
this.head.previous = null;
|
|
4102
|
+
}
|
|
4103
|
+
}
|
|
4104
|
+
else {
|
|
4105
|
+
current.previous.next = current.next;
|
|
4106
|
+
if (current.next) {
|
|
4107
|
+
current.next.previous = current.previous;
|
|
4108
|
+
}
|
|
4109
|
+
}
|
|
4110
|
+
if (n.__ln) {
|
|
4111
|
+
delete n.__ln;
|
|
4112
|
+
}
|
|
4113
|
+
this.length--;
|
|
4114
|
+
}
|
|
4115
|
+
}
|
|
4116
|
+
const moveKey = (id, parentId) => `${id}@${parentId}`;
|
|
4117
|
+
class MutationBuffer {
|
|
4118
|
+
constructor() {
|
|
4119
|
+
this.frozen = false;
|
|
4120
|
+
this.locked = false;
|
|
4121
|
+
this.texts = [];
|
|
4122
|
+
this.attributes = [];
|
|
4123
|
+
this.removes = [];
|
|
4124
|
+
this.mapRemoves = [];
|
|
4125
|
+
this.movedMap = {};
|
|
4126
|
+
this.addedSet = new Set();
|
|
4127
|
+
this.movedSet = new Set();
|
|
4128
|
+
this.droppedSet = new Set();
|
|
4129
|
+
this.processMutations = (mutations) => {
|
|
4130
|
+
mutations.forEach(this.processMutation);
|
|
4131
|
+
this.emit();
|
|
4132
|
+
};
|
|
4133
|
+
this.emit = () => {
|
|
4134
|
+
if (this.frozen || this.locked) {
|
|
4135
|
+
return;
|
|
4136
|
+
}
|
|
4137
|
+
const adds = [];
|
|
4138
|
+
const addList = new DoubleLinkedList();
|
|
4139
|
+
const getNextId = (n) => {
|
|
4140
|
+
let ns = n;
|
|
4141
|
+
let nextId = IGNORED_NODE;
|
|
4142
|
+
while (nextId === IGNORED_NODE) {
|
|
4143
|
+
ns = ns && ns.nextSibling;
|
|
4144
|
+
nextId = ns && this.mirror.getId(ns);
|
|
4145
|
+
}
|
|
4146
|
+
return nextId;
|
|
4147
|
+
};
|
|
4148
|
+
const pushAdd = (n) => {
|
|
4149
|
+
var _a, _b, _c, _d;
|
|
4150
|
+
let shadowHost = null;
|
|
4151
|
+
if (((_b = (_a = n.getRootNode) === null || _a === void 0 ? void 0 : _a.call(n)) === null || _b === void 0 ? void 0 : _b.nodeType) === Node.DOCUMENT_FRAGMENT_NODE &&
|
|
4152
|
+
n.getRootNode().host)
|
|
4153
|
+
shadowHost = n.getRootNode().host;
|
|
4154
|
+
let rootShadowHost = shadowHost;
|
|
4155
|
+
while (((_d = (_c = rootShadowHost === null || rootShadowHost === void 0 ? void 0 : rootShadowHost.getRootNode) === null || _c === void 0 ? void 0 : _c.call(rootShadowHost)) === null || _d === void 0 ? void 0 : _d.nodeType) ===
|
|
4156
|
+
Node.DOCUMENT_FRAGMENT_NODE &&
|
|
4157
|
+
rootShadowHost.getRootNode().host)
|
|
4158
|
+
rootShadowHost = rootShadowHost.getRootNode().host;
|
|
4159
|
+
const notInDoc = !this.doc.contains(n) &&
|
|
4160
|
+
(!rootShadowHost || !this.doc.contains(rootShadowHost));
|
|
4161
|
+
if (!n.parentNode || notInDoc) {
|
|
4162
|
+
return;
|
|
4163
|
+
}
|
|
4164
|
+
const parentId = isShadowRoot(n.parentNode)
|
|
4165
|
+
? this.mirror.getId(shadowHost)
|
|
4166
|
+
: this.mirror.getId(n.parentNode);
|
|
4167
|
+
const nextId = getNextId(n);
|
|
4168
|
+
if (parentId === -1 || nextId === -1) {
|
|
4169
|
+
return addList.addNode(n);
|
|
4170
|
+
}
|
|
4171
|
+
const sn = serializeNodeWithId(n, {
|
|
4172
|
+
doc: this.doc,
|
|
4173
|
+
mirror: this.mirror,
|
|
4174
|
+
blockClass: this.blockClass,
|
|
4175
|
+
blockSelector: this.blockSelector,
|
|
4176
|
+
maskTextClass: this.maskTextClass,
|
|
4177
|
+
maskTextSelector: this.maskTextSelector,
|
|
4178
|
+
skipChild: true,
|
|
4179
|
+
newlyAddedElement: true,
|
|
4180
|
+
inlineStylesheet: this.inlineStylesheet,
|
|
4181
|
+
maskInputOptions: this.maskInputOptions,
|
|
4182
|
+
maskTextFn: this.maskTextFn,
|
|
4183
|
+
maskInputFn: this.maskInputFn,
|
|
4184
|
+
slimDOMOptions: this.slimDOMOptions,
|
|
4185
|
+
dataURLOptions: this.dataURLOptions,
|
|
4186
|
+
recordCanvas: this.recordCanvas,
|
|
4187
|
+
inlineImages: this.inlineImages,
|
|
4188
|
+
onSerialize: (currentN) => {
|
|
4189
|
+
if (isSerializedIframe(currentN, this.mirror)) {
|
|
4190
|
+
this.iframeManager.addIframe(currentN);
|
|
4191
|
+
}
|
|
4192
|
+
if (isSerializedStylesheet(currentN, this.mirror)) {
|
|
4193
|
+
this.stylesheetManager.trackLinkElement(currentN);
|
|
4194
|
+
}
|
|
4195
|
+
if (hasShadowRoot(n)) {
|
|
4196
|
+
this.shadowDomManager.addShadowRoot(n.shadowRoot, this.doc);
|
|
4197
|
+
}
|
|
4198
|
+
},
|
|
4199
|
+
onIframeLoad: (iframe, childSn) => {
|
|
4200
|
+
this.iframeManager.attachIframe(iframe, childSn);
|
|
4201
|
+
this.shadowDomManager.observeAttachShadow(iframe);
|
|
4202
|
+
},
|
|
4203
|
+
onStylesheetLoad: (link, childSn) => {
|
|
4204
|
+
this.stylesheetManager.attachLinkElement(link, childSn);
|
|
4205
|
+
},
|
|
4206
|
+
});
|
|
4207
|
+
if (sn) {
|
|
4208
|
+
adds.push({
|
|
4209
|
+
parentId,
|
|
4210
|
+
nextId,
|
|
4211
|
+
node: sn,
|
|
4212
|
+
});
|
|
4213
|
+
}
|
|
4214
|
+
};
|
|
4215
|
+
while (this.mapRemoves.length) {
|
|
4216
|
+
this.mirror.removeNodeFromMap(this.mapRemoves.shift());
|
|
4217
|
+
}
|
|
4218
|
+
for (const n of Array.from(this.movedSet.values())) {
|
|
4219
|
+
if (isParentRemoved(this.removes, n, this.mirror) &&
|
|
4220
|
+
!this.movedSet.has(n.parentNode)) {
|
|
4221
|
+
continue;
|
|
4222
|
+
}
|
|
4223
|
+
pushAdd(n);
|
|
4224
|
+
}
|
|
4225
|
+
for (const n of Array.from(this.addedSet.values())) {
|
|
4226
|
+
if (!isAncestorInSet(this.droppedSet, n) &&
|
|
4227
|
+
!isParentRemoved(this.removes, n, this.mirror)) {
|
|
4228
|
+
pushAdd(n);
|
|
4229
|
+
}
|
|
4230
|
+
else if (isAncestorInSet(this.movedSet, n)) {
|
|
4231
|
+
pushAdd(n);
|
|
4232
|
+
}
|
|
4233
|
+
else {
|
|
4234
|
+
this.droppedSet.add(n);
|
|
4235
|
+
}
|
|
4236
|
+
}
|
|
4237
|
+
let candidate = null;
|
|
4238
|
+
while (addList.length) {
|
|
4239
|
+
let node = null;
|
|
4240
|
+
if (candidate) {
|
|
4241
|
+
const parentId = this.mirror.getId(candidate.value.parentNode);
|
|
4242
|
+
const nextId = getNextId(candidate.value);
|
|
4243
|
+
if (parentId !== -1 && nextId !== -1) {
|
|
4244
|
+
node = candidate;
|
|
4245
|
+
}
|
|
4246
|
+
}
|
|
4247
|
+
if (!node) {
|
|
4248
|
+
for (let index = addList.length - 1; index >= 0; index--) {
|
|
4249
|
+
const _node = addList.get(index);
|
|
4250
|
+
if (_node) {
|
|
4251
|
+
const parentId = this.mirror.getId(_node.value.parentNode);
|
|
4252
|
+
const nextId = getNextId(_node.value);
|
|
4253
|
+
if (nextId === -1)
|
|
4254
|
+
continue;
|
|
4255
|
+
else if (parentId !== -1) {
|
|
4256
|
+
node = _node;
|
|
4257
|
+
break;
|
|
4258
|
+
}
|
|
4259
|
+
else {
|
|
4260
|
+
const unhandledNode = _node.value;
|
|
4261
|
+
if (unhandledNode.parentNode &&
|
|
4262
|
+
unhandledNode.parentNode.nodeType ===
|
|
4263
|
+
Node.DOCUMENT_FRAGMENT_NODE) {
|
|
4264
|
+
const shadowHost = unhandledNode.parentNode
|
|
4265
|
+
.host;
|
|
4266
|
+
const parentId = this.mirror.getId(shadowHost);
|
|
4267
|
+
if (parentId !== -1) {
|
|
4268
|
+
node = _node;
|
|
4269
|
+
break;
|
|
4270
|
+
}
|
|
4271
|
+
}
|
|
4272
|
+
}
|
|
4273
|
+
}
|
|
4274
|
+
}
|
|
4275
|
+
}
|
|
4276
|
+
if (!node) {
|
|
4277
|
+
while (addList.head) {
|
|
4278
|
+
addList.removeNode(addList.head.value);
|
|
4279
|
+
}
|
|
4280
|
+
break;
|
|
4281
|
+
}
|
|
4282
|
+
candidate = node.previous;
|
|
4283
|
+
addList.removeNode(node.value);
|
|
4284
|
+
pushAdd(node.value);
|
|
4285
|
+
}
|
|
4286
|
+
const payload = {
|
|
4287
|
+
texts: this.texts
|
|
4288
|
+
.map((text) => ({
|
|
4289
|
+
id: this.mirror.getId(text.node),
|
|
4290
|
+
value: text.value,
|
|
4291
|
+
}))
|
|
4292
|
+
.filter((text) => this.mirror.has(text.id)),
|
|
4293
|
+
attributes: this.attributes
|
|
4294
|
+
.map((attribute) => ({
|
|
4295
|
+
id: this.mirror.getId(attribute.node),
|
|
4296
|
+
attributes: attribute.attributes,
|
|
4297
|
+
}))
|
|
4298
|
+
.filter((attribute) => this.mirror.has(attribute.id)),
|
|
4299
|
+
removes: this.removes,
|
|
4300
|
+
adds,
|
|
4301
|
+
};
|
|
4302
|
+
if (!payload.texts.length &&
|
|
4303
|
+
!payload.attributes.length &&
|
|
4304
|
+
!payload.removes.length &&
|
|
4305
|
+
!payload.adds.length) {
|
|
4306
|
+
return;
|
|
4307
|
+
}
|
|
4308
|
+
this.texts = [];
|
|
4309
|
+
this.attributes = [];
|
|
4310
|
+
this.removes = [];
|
|
4311
|
+
this.addedSet = new Set();
|
|
4312
|
+
this.movedSet = new Set();
|
|
4313
|
+
this.droppedSet = new Set();
|
|
4314
|
+
this.movedMap = {};
|
|
4315
|
+
this.mutationCb(payload);
|
|
4316
|
+
};
|
|
4317
|
+
this.processMutation = (m) => {
|
|
4318
|
+
if (isIgnored(m.target, this.mirror)) {
|
|
4319
|
+
return;
|
|
4320
|
+
}
|
|
4321
|
+
switch (m.type) {
|
|
4322
|
+
case 'characterData': {
|
|
4323
|
+
const value = m.target.textContent;
|
|
4324
|
+
if (!isBlocked(m.target, this.blockClass, this.blockSelector, false) &&
|
|
4325
|
+
value !== m.oldValue) {
|
|
4326
|
+
this.texts.push({
|
|
4327
|
+
value: needMaskingText(m.target, this.maskTextClass, this.maskTextSelector) && value
|
|
4328
|
+
? this.maskTextFn
|
|
4329
|
+
? this.maskTextFn(value)
|
|
4330
|
+
: value.replace(/[\S]/g, '*')
|
|
4331
|
+
: value,
|
|
4332
|
+
node: m.target,
|
|
4333
|
+
});
|
|
4334
|
+
}
|
|
4335
|
+
break;
|
|
4336
|
+
}
|
|
4337
|
+
case 'attributes': {
|
|
4338
|
+
const target = m.target;
|
|
4339
|
+
let value = m.target.getAttribute(m.attributeName);
|
|
4340
|
+
if (m.attributeName === 'value') {
|
|
4341
|
+
value = maskInputValue({
|
|
4342
|
+
maskInputOptions: this.maskInputOptions,
|
|
4343
|
+
tagName: m.target.tagName,
|
|
4344
|
+
type: m.target.getAttribute('type'),
|
|
4345
|
+
value,
|
|
4346
|
+
maskInputFn: this.maskInputFn,
|
|
4347
|
+
});
|
|
4348
|
+
}
|
|
4349
|
+
if (isBlocked(m.target, this.blockClass, this.blockSelector, false) ||
|
|
4350
|
+
value === m.oldValue) {
|
|
4351
|
+
return;
|
|
4352
|
+
}
|
|
4353
|
+
let item = this.attributes.find((a) => a.node === m.target);
|
|
4354
|
+
if (target.tagName === 'IFRAME' &&
|
|
4355
|
+
m.attributeName === 'src' &&
|
|
4356
|
+
!this.keepIframeSrcFn(value)) {
|
|
4357
|
+
if (!target.contentDocument) {
|
|
4358
|
+
m.attributeName = 'rr_src';
|
|
4359
|
+
}
|
|
4360
|
+
else {
|
|
4361
|
+
return;
|
|
4362
|
+
}
|
|
4363
|
+
}
|
|
4364
|
+
if (!item) {
|
|
4365
|
+
item = {
|
|
4366
|
+
node: m.target,
|
|
4367
|
+
attributes: {},
|
|
4368
|
+
};
|
|
4369
|
+
this.attributes.push(item);
|
|
4370
|
+
}
|
|
4371
|
+
if (m.attributeName === 'style') {
|
|
4372
|
+
const old = this.doc.createElement('span');
|
|
4373
|
+
if (m.oldValue) {
|
|
4374
|
+
old.setAttribute('style', m.oldValue);
|
|
4375
|
+
}
|
|
4376
|
+
if (item.attributes.style === undefined ||
|
|
4377
|
+
item.attributes.style === null) {
|
|
4378
|
+
item.attributes.style = {};
|
|
4379
|
+
}
|
|
4380
|
+
const styleObj = item.attributes.style;
|
|
4381
|
+
for (const pname of Array.from(target.style)) {
|
|
4382
|
+
const newValue = target.style.getPropertyValue(pname);
|
|
4383
|
+
const newPriority = target.style.getPropertyPriority(pname);
|
|
4384
|
+
if (newValue !== old.style.getPropertyValue(pname) ||
|
|
4385
|
+
newPriority !== old.style.getPropertyPriority(pname)) {
|
|
4386
|
+
if (newPriority === '') {
|
|
4387
|
+
styleObj[pname] = newValue;
|
|
4388
|
+
}
|
|
4389
|
+
else {
|
|
4390
|
+
styleObj[pname] = [newValue, newPriority];
|
|
4391
|
+
}
|
|
4392
|
+
}
|
|
4393
|
+
}
|
|
4394
|
+
for (const pname of Array.from(old.style)) {
|
|
4395
|
+
if (target.style.getPropertyValue(pname) === '') {
|
|
4396
|
+
styleObj[pname] = false;
|
|
4397
|
+
}
|
|
4398
|
+
}
|
|
4399
|
+
}
|
|
4400
|
+
else {
|
|
4401
|
+
item.attributes[m.attributeName] = transformAttribute(this.doc, target.tagName, m.attributeName, value);
|
|
4402
|
+
}
|
|
4403
|
+
break;
|
|
4404
|
+
}
|
|
4405
|
+
case 'childList': {
|
|
4406
|
+
if (isBlocked(m.target, this.blockClass, this.blockSelector, true))
|
|
4407
|
+
return;
|
|
4408
|
+
m.addedNodes.forEach((n) => this.genAdds(n, m.target));
|
|
4409
|
+
m.removedNodes.forEach((n) => {
|
|
4410
|
+
const nodeId = this.mirror.getId(n);
|
|
4411
|
+
const parentId = isShadowRoot(m.target)
|
|
4412
|
+
? this.mirror.getId(m.target.host)
|
|
4413
|
+
: this.mirror.getId(m.target);
|
|
4414
|
+
if (isBlocked(m.target, this.blockClass, this.blockSelector, false) ||
|
|
4415
|
+
isIgnored(n, this.mirror) ||
|
|
4416
|
+
!isSerialized(n, this.mirror)) {
|
|
4417
|
+
return;
|
|
4418
|
+
}
|
|
4419
|
+
if (this.addedSet.has(n)) {
|
|
4420
|
+
deepDelete(this.addedSet, n);
|
|
4421
|
+
this.droppedSet.add(n);
|
|
4422
|
+
}
|
|
4423
|
+
else if (this.addedSet.has(m.target) && nodeId === -1) ;
|
|
4424
|
+
else if (isAncestorRemoved(m.target, this.mirror)) ;
|
|
4425
|
+
else if (this.movedSet.has(n) &&
|
|
4426
|
+
this.movedMap[moveKey(nodeId, parentId)]) {
|
|
4427
|
+
deepDelete(this.movedSet, n);
|
|
4428
|
+
}
|
|
4429
|
+
else {
|
|
4430
|
+
this.removes.push({
|
|
4431
|
+
parentId,
|
|
4432
|
+
id: nodeId,
|
|
4433
|
+
isShadow: isShadowRoot(m.target) && isNativeShadowDom(m.target)
|
|
4434
|
+
? true
|
|
4435
|
+
: undefined,
|
|
4436
|
+
});
|
|
4437
|
+
}
|
|
4438
|
+
this.mapRemoves.push(n);
|
|
4439
|
+
});
|
|
4440
|
+
break;
|
|
4441
|
+
}
|
|
4442
|
+
}
|
|
4443
|
+
};
|
|
4444
|
+
this.genAdds = (n, target) => {
|
|
4445
|
+
if (this.mirror.hasNode(n)) {
|
|
4446
|
+
if (isIgnored(n, this.mirror)) {
|
|
4447
|
+
return;
|
|
4448
|
+
}
|
|
4449
|
+
this.movedSet.add(n);
|
|
4450
|
+
let targetId = null;
|
|
4451
|
+
if (target && this.mirror.hasNode(target)) {
|
|
4452
|
+
targetId = this.mirror.getId(target);
|
|
4453
|
+
}
|
|
4454
|
+
if (targetId && targetId !== -1) {
|
|
4455
|
+
this.movedMap[moveKey(this.mirror.getId(n), targetId)] = true;
|
|
4456
|
+
}
|
|
4457
|
+
}
|
|
4458
|
+
else {
|
|
4459
|
+
this.addedSet.add(n);
|
|
4460
|
+
this.droppedSet.delete(n);
|
|
4461
|
+
}
|
|
4462
|
+
if (!isBlocked(n, this.blockClass, this.blockSelector, false))
|
|
4463
|
+
n.childNodes.forEach((childN) => this.genAdds(childN));
|
|
4464
|
+
};
|
|
4465
|
+
}
|
|
4466
|
+
init(options) {
|
|
4467
|
+
[
|
|
4468
|
+
'mutationCb',
|
|
4469
|
+
'blockClass',
|
|
4470
|
+
'blockSelector',
|
|
4471
|
+
'maskTextClass',
|
|
4472
|
+
'maskTextSelector',
|
|
4473
|
+
'inlineStylesheet',
|
|
4474
|
+
'maskInputOptions',
|
|
4475
|
+
'maskTextFn',
|
|
4476
|
+
'maskInputFn',
|
|
4477
|
+
'keepIframeSrcFn',
|
|
4478
|
+
'recordCanvas',
|
|
4479
|
+
'inlineImages',
|
|
4480
|
+
'slimDOMOptions',
|
|
4481
|
+
'dataURLOptions',
|
|
4482
|
+
'doc',
|
|
4483
|
+
'mirror',
|
|
4484
|
+
'iframeManager',
|
|
4485
|
+
'stylesheetManager',
|
|
4486
|
+
'shadowDomManager',
|
|
4487
|
+
'canvasManager',
|
|
4488
|
+
].forEach((key) => {
|
|
4489
|
+
this[key] = options[key];
|
|
4490
|
+
});
|
|
4491
|
+
}
|
|
4492
|
+
freeze() {
|
|
4493
|
+
this.frozen = true;
|
|
4494
|
+
this.canvasManager.freeze();
|
|
4495
|
+
}
|
|
4496
|
+
unfreeze() {
|
|
4497
|
+
this.frozen = false;
|
|
4498
|
+
this.canvasManager.unfreeze();
|
|
4499
|
+
this.emit();
|
|
4500
|
+
}
|
|
4501
|
+
isFrozen() {
|
|
4502
|
+
return this.frozen;
|
|
4503
|
+
}
|
|
4504
|
+
lock() {
|
|
4505
|
+
this.locked = true;
|
|
4506
|
+
this.canvasManager.lock();
|
|
4507
|
+
}
|
|
4508
|
+
unlock() {
|
|
4509
|
+
this.locked = false;
|
|
4510
|
+
this.canvasManager.unlock();
|
|
4511
|
+
this.emit();
|
|
4512
|
+
}
|
|
4513
|
+
reset() {
|
|
4514
|
+
this.shadowDomManager.reset();
|
|
4515
|
+
this.canvasManager.reset();
|
|
4516
|
+
}
|
|
4517
|
+
}
|
|
4518
|
+
function deepDelete(addsSet, n) {
|
|
4519
|
+
addsSet.delete(n);
|
|
4520
|
+
n.childNodes.forEach((childN) => deepDelete(addsSet, childN));
|
|
4521
|
+
}
|
|
4522
|
+
function isParentRemoved(removes, n, mirror) {
|
|
4523
|
+
if (removes.length === 0)
|
|
4524
|
+
return false;
|
|
4525
|
+
return _isParentRemoved(removes, n, mirror);
|
|
4526
|
+
}
|
|
4527
|
+
function _isParentRemoved(removes, n, mirror) {
|
|
4528
|
+
const { parentNode } = n;
|
|
4529
|
+
if (!parentNode) {
|
|
4530
|
+
return false;
|
|
4531
|
+
}
|
|
4532
|
+
const parentId = mirror.getId(parentNode);
|
|
4533
|
+
if (removes.some((r) => r.id === parentId)) {
|
|
4534
|
+
return true;
|
|
4535
|
+
}
|
|
4536
|
+
return _isParentRemoved(removes, parentNode, mirror);
|
|
4537
|
+
}
|
|
4538
|
+
function isAncestorInSet(set, n) {
|
|
4539
|
+
if (set.size === 0)
|
|
4540
|
+
return false;
|
|
4541
|
+
return _isAncestorInSet(set, n);
|
|
4542
|
+
}
|
|
4543
|
+
function _isAncestorInSet(set, n) {
|
|
4544
|
+
const { parentNode } = n;
|
|
4545
|
+
if (!parentNode) {
|
|
4546
|
+
return false;
|
|
4547
|
+
}
|
|
4548
|
+
if (set.has(parentNode)) {
|
|
4549
|
+
return true;
|
|
4550
|
+
}
|
|
4551
|
+
return _isAncestorInSet(set, parentNode);
|
|
4552
|
+
}
|
|
4553
|
+
|
|
4554
|
+
const mutationBuffers = [];
|
|
4555
|
+
const isCSSGroupingRuleSupported = typeof CSSGroupingRule !== 'undefined';
|
|
4556
|
+
const isCSSMediaRuleSupported = typeof CSSMediaRule !== 'undefined';
|
|
4557
|
+
const isCSSSupportsRuleSupported = typeof CSSSupportsRule !== 'undefined';
|
|
4558
|
+
const isCSSConditionRuleSupported = typeof CSSConditionRule !== 'undefined';
|
|
4559
|
+
function getEventTarget(event) {
|
|
4560
|
+
try {
|
|
4561
|
+
if ('composedPath' in event) {
|
|
4562
|
+
const path = event.composedPath();
|
|
4563
|
+
if (path.length) {
|
|
4564
|
+
return path[0];
|
|
4565
|
+
}
|
|
4566
|
+
}
|
|
4567
|
+
else if ('path' in event && event.path.length) {
|
|
4568
|
+
return event.path[0];
|
|
4569
|
+
}
|
|
4570
|
+
return event.target;
|
|
4571
|
+
}
|
|
4572
|
+
catch (_a) {
|
|
4573
|
+
return event.target;
|
|
4574
|
+
}
|
|
4575
|
+
}
|
|
4576
|
+
function initMutationObserver(options, rootEl) {
|
|
4577
|
+
var _a, _b;
|
|
4578
|
+
const mutationBuffer = new MutationBuffer();
|
|
4579
|
+
mutationBuffers.push(mutationBuffer);
|
|
4580
|
+
mutationBuffer.init(options);
|
|
4581
|
+
let mutationObserverCtor = window.MutationObserver ||
|
|
4582
|
+
window.__rrMutationObserver;
|
|
4583
|
+
const angularZoneSymbol = (_b = (_a = window === null || window === void 0 ? void 0 : window.Zone) === null || _a === void 0 ? void 0 : _a.__symbol__) === null || _b === void 0 ? void 0 : _b.call(_a, 'MutationObserver');
|
|
4584
|
+
if (angularZoneSymbol &&
|
|
4585
|
+
window[angularZoneSymbol]) {
|
|
4586
|
+
mutationObserverCtor = window[angularZoneSymbol];
|
|
4587
|
+
}
|
|
4588
|
+
const observer = new mutationObserverCtor(mutationBuffer.processMutations.bind(mutationBuffer));
|
|
4589
|
+
observer.observe(rootEl, {
|
|
4590
|
+
attributes: true,
|
|
4591
|
+
attributeOldValue: true,
|
|
4592
|
+
characterData: true,
|
|
4593
|
+
characterDataOldValue: true,
|
|
4594
|
+
childList: true,
|
|
4595
|
+
subtree: true,
|
|
4596
|
+
});
|
|
4597
|
+
return observer;
|
|
4598
|
+
}
|
|
4599
|
+
function initMoveObserver({ mousemoveCb, sampling, doc, mirror, }) {
|
|
4600
|
+
if (sampling.mousemove === false) {
|
|
4601
|
+
return () => {
|
|
4602
|
+
};
|
|
4603
|
+
}
|
|
4604
|
+
const threshold = typeof sampling.mousemove === 'number' ? sampling.mousemove : 50;
|
|
4605
|
+
const callbackThreshold = typeof sampling.mousemoveCallback === 'number'
|
|
4606
|
+
? sampling.mousemoveCallback
|
|
4607
|
+
: 500;
|
|
4608
|
+
let positions = [];
|
|
4609
|
+
let timeBaseline;
|
|
4610
|
+
const wrappedCb = throttle((source) => {
|
|
4611
|
+
const totalOffset = Date.now() - timeBaseline;
|
|
4612
|
+
mousemoveCb(positions.map((p) => {
|
|
4613
|
+
p.timeOffset -= totalOffset;
|
|
4614
|
+
return p;
|
|
4615
|
+
}), source);
|
|
4616
|
+
positions = [];
|
|
4617
|
+
timeBaseline = null;
|
|
4618
|
+
}, callbackThreshold);
|
|
4619
|
+
const updatePosition = throttle((evt) => {
|
|
4620
|
+
const target = getEventTarget(evt);
|
|
4621
|
+
const { clientX, clientY } = isTouchEvent(evt)
|
|
4622
|
+
? evt.changedTouches[0]
|
|
4623
|
+
: evt;
|
|
4624
|
+
if (!timeBaseline) {
|
|
4625
|
+
timeBaseline = Date.now();
|
|
4626
|
+
}
|
|
4627
|
+
positions.push({
|
|
4628
|
+
x: clientX,
|
|
4629
|
+
y: clientY,
|
|
4630
|
+
id: mirror.getId(target),
|
|
4631
|
+
timeOffset: Date.now() - timeBaseline,
|
|
4632
|
+
});
|
|
4633
|
+
wrappedCb(typeof DragEvent !== 'undefined' && evt instanceof DragEvent
|
|
4634
|
+
? IncrementalSource.Drag
|
|
4635
|
+
: evt instanceof MouseEvent
|
|
4636
|
+
? IncrementalSource.MouseMove
|
|
4637
|
+
: IncrementalSource.TouchMove);
|
|
4638
|
+
}, threshold, {
|
|
4639
|
+
trailing: false,
|
|
4640
|
+
});
|
|
4641
|
+
const handlers = [
|
|
4642
|
+
on('mousemove', updatePosition, doc),
|
|
4643
|
+
on('touchmove', updatePosition, doc),
|
|
4644
|
+
on('drag', updatePosition, doc),
|
|
4645
|
+
];
|
|
4646
|
+
return () => {
|
|
4647
|
+
handlers.forEach((h) => h());
|
|
4648
|
+
};
|
|
4649
|
+
}
|
|
4650
|
+
function initMouseInteractionObserver({ mouseInteractionCb, doc, mirror, blockClass, blockSelector, sampling, }) {
|
|
4651
|
+
if (sampling.mouseInteraction === false) {
|
|
4652
|
+
return () => {
|
|
4653
|
+
};
|
|
4654
|
+
}
|
|
4655
|
+
const disableMap = sampling.mouseInteraction === true ||
|
|
4656
|
+
sampling.mouseInteraction === undefined
|
|
4657
|
+
? {}
|
|
4658
|
+
: sampling.mouseInteraction;
|
|
4659
|
+
const handlers = [];
|
|
4660
|
+
const getHandler = (eventKey) => {
|
|
4661
|
+
return (event) => {
|
|
4662
|
+
const target = getEventTarget(event);
|
|
4663
|
+
if (isBlocked(target, blockClass, blockSelector, true)) {
|
|
4664
|
+
return;
|
|
4665
|
+
}
|
|
4666
|
+
const e = isTouchEvent(event) ? event.changedTouches[0] : event;
|
|
4667
|
+
if (!e) {
|
|
4668
|
+
return;
|
|
4669
|
+
}
|
|
4670
|
+
const id = mirror.getId(target);
|
|
4671
|
+
const { clientX, clientY } = e;
|
|
4672
|
+
mouseInteractionCb({
|
|
4673
|
+
type: MouseInteractions[eventKey],
|
|
4674
|
+
id,
|
|
4675
|
+
x: clientX,
|
|
4676
|
+
y: clientY,
|
|
4677
|
+
});
|
|
4678
|
+
};
|
|
4679
|
+
};
|
|
4680
|
+
Object.keys(MouseInteractions)
|
|
4681
|
+
.filter((key) => Number.isNaN(Number(key)) &&
|
|
4682
|
+
!key.endsWith('_Departed') &&
|
|
4683
|
+
disableMap[key] !== false)
|
|
4684
|
+
.forEach((eventKey) => {
|
|
4685
|
+
const eventName = eventKey.toLowerCase();
|
|
4686
|
+
const handler = getHandler(eventKey);
|
|
4687
|
+
handlers.push(on(eventName, handler, doc));
|
|
4688
|
+
});
|
|
4689
|
+
return () => {
|
|
4690
|
+
handlers.forEach((h) => h());
|
|
4691
|
+
};
|
|
4692
|
+
}
|
|
4693
|
+
function initScrollObserver({ scrollCb, doc, mirror, blockClass, blockSelector, sampling, }) {
|
|
4694
|
+
const updatePosition = throttle((evt) => {
|
|
4695
|
+
const target = getEventTarget(evt);
|
|
4696
|
+
if (!target || isBlocked(target, blockClass, blockSelector, true)) {
|
|
4697
|
+
return;
|
|
4698
|
+
}
|
|
4699
|
+
const id = mirror.getId(target);
|
|
4700
|
+
if (target === doc) {
|
|
4701
|
+
const scrollEl = (doc.scrollingElement || doc.documentElement);
|
|
4702
|
+
scrollCb({
|
|
4703
|
+
id,
|
|
4704
|
+
x: scrollEl.scrollLeft,
|
|
4705
|
+
y: scrollEl.scrollTop,
|
|
4706
|
+
});
|
|
4707
|
+
}
|
|
4708
|
+
else {
|
|
4709
|
+
scrollCb({
|
|
4710
|
+
id,
|
|
4711
|
+
x: target.scrollLeft,
|
|
4712
|
+
y: target.scrollTop,
|
|
4713
|
+
});
|
|
4714
|
+
}
|
|
4715
|
+
}, sampling.scroll || 100);
|
|
4716
|
+
return on('scroll', updatePosition, doc);
|
|
4717
|
+
}
|
|
4718
|
+
function initViewportResizeObserver({ viewportResizeCb, }) {
|
|
4719
|
+
let lastH = -1;
|
|
4720
|
+
let lastW = -1;
|
|
4721
|
+
const updateDimension = throttle(() => {
|
|
4722
|
+
const height = getWindowHeight();
|
|
4723
|
+
const width = getWindowWidth();
|
|
4724
|
+
if (lastH !== height || lastW !== width) {
|
|
4725
|
+
viewportResizeCb({
|
|
4726
|
+
width: Number(width),
|
|
4727
|
+
height: Number(height),
|
|
4728
|
+
});
|
|
4729
|
+
lastH = height;
|
|
4730
|
+
lastW = width;
|
|
4731
|
+
}
|
|
4732
|
+
}, 200);
|
|
4733
|
+
return on('resize', updateDimension, window);
|
|
4734
|
+
}
|
|
4735
|
+
function wrapEventWithUserTriggeredFlag(v, enable) {
|
|
4736
|
+
const value = Object.assign({}, v);
|
|
4737
|
+
if (!enable)
|
|
4738
|
+
delete value.userTriggered;
|
|
4739
|
+
return value;
|
|
4740
|
+
}
|
|
4741
|
+
const INPUT_TAGS = ['INPUT', 'TEXTAREA', 'SELECT'];
|
|
4742
|
+
const lastInputValueMap = new WeakMap();
|
|
4743
|
+
function initInputObserver({ inputCb, doc, mirror, blockClass, blockSelector, ignoreClass, maskInputOptions, maskInputFn, sampling, userTriggeredOnInput, }) {
|
|
4744
|
+
function eventHandler(event) {
|
|
4745
|
+
let target = getEventTarget(event);
|
|
4746
|
+
const userTriggered = event.isTrusted;
|
|
4747
|
+
if (target && target.tagName === 'OPTION')
|
|
4748
|
+
target = target.parentElement;
|
|
4749
|
+
if (!target ||
|
|
4750
|
+
!target.tagName ||
|
|
4751
|
+
INPUT_TAGS.indexOf(target.tagName) < 0 ||
|
|
4752
|
+
isBlocked(target, blockClass, blockSelector, true)) {
|
|
4753
|
+
return;
|
|
4754
|
+
}
|
|
4755
|
+
const type = target.type;
|
|
4756
|
+
if (target.classList.contains(ignoreClass)) {
|
|
4757
|
+
return;
|
|
4758
|
+
}
|
|
4759
|
+
let text = target.value;
|
|
4760
|
+
let isChecked = false;
|
|
4761
|
+
if (type === 'radio' || type === 'checkbox') {
|
|
4762
|
+
isChecked = target.checked;
|
|
4763
|
+
}
|
|
4764
|
+
else if (maskInputOptions[target.tagName.toLowerCase()] ||
|
|
4765
|
+
maskInputOptions[type]) {
|
|
4766
|
+
text = maskInputValue({
|
|
4767
|
+
maskInputOptions,
|
|
4768
|
+
tagName: target.tagName,
|
|
4769
|
+
type,
|
|
4770
|
+
value: text,
|
|
4771
|
+
maskInputFn,
|
|
4772
|
+
});
|
|
4773
|
+
}
|
|
4774
|
+
cbWithDedup(target, wrapEventWithUserTriggeredFlag({ text, isChecked, userTriggered }, userTriggeredOnInput));
|
|
4775
|
+
const name = target.name;
|
|
4776
|
+
if (type === 'radio' && name && isChecked) {
|
|
4777
|
+
doc
|
|
4778
|
+
.querySelectorAll(`input[type="radio"][name="${name}"]`)
|
|
4779
|
+
.forEach((el) => {
|
|
4780
|
+
if (el !== target) {
|
|
4781
|
+
cbWithDedup(el, wrapEventWithUserTriggeredFlag({
|
|
4782
|
+
text: el.value,
|
|
4783
|
+
isChecked: !isChecked,
|
|
4784
|
+
userTriggered: false,
|
|
4785
|
+
}, userTriggeredOnInput));
|
|
4786
|
+
}
|
|
4787
|
+
});
|
|
4788
|
+
}
|
|
4789
|
+
}
|
|
4790
|
+
function cbWithDedup(target, v) {
|
|
4791
|
+
const lastInputValue = lastInputValueMap.get(target);
|
|
4792
|
+
if (!lastInputValue ||
|
|
4793
|
+
lastInputValue.text !== v.text ||
|
|
4794
|
+
lastInputValue.isChecked !== v.isChecked) {
|
|
4795
|
+
lastInputValueMap.set(target, v);
|
|
4796
|
+
const id = mirror.getId(target);
|
|
4797
|
+
inputCb(Object.assign(Object.assign({}, v), { id }));
|
|
4798
|
+
}
|
|
4799
|
+
}
|
|
4800
|
+
const events = sampling.input === 'last' ? ['change'] : ['input', 'change'];
|
|
4801
|
+
const handlers = events.map((eventName) => on(eventName, eventHandler, doc));
|
|
4802
|
+
const currentWindow = doc.defaultView;
|
|
4803
|
+
if (!currentWindow) {
|
|
4804
|
+
return () => {
|
|
4805
|
+
handlers.forEach((h) => h());
|
|
4806
|
+
};
|
|
4807
|
+
}
|
|
4808
|
+
const propertyDescriptor = currentWindow.Object.getOwnPropertyDescriptor(currentWindow.HTMLInputElement.prototype, 'value');
|
|
4809
|
+
const hookProperties = [
|
|
4810
|
+
[currentWindow.HTMLInputElement.prototype, 'value'],
|
|
4811
|
+
[currentWindow.HTMLInputElement.prototype, 'checked'],
|
|
4812
|
+
[currentWindow.HTMLSelectElement.prototype, 'value'],
|
|
4813
|
+
[currentWindow.HTMLTextAreaElement.prototype, 'value'],
|
|
4814
|
+
[currentWindow.HTMLSelectElement.prototype, 'selectedIndex'],
|
|
4815
|
+
[currentWindow.HTMLOptionElement.prototype, 'selected'],
|
|
4816
|
+
];
|
|
4817
|
+
if (propertyDescriptor && propertyDescriptor.set) {
|
|
4818
|
+
handlers.push(...hookProperties.map((p) => hookSetter(p[0], p[1], {
|
|
4819
|
+
set() {
|
|
4820
|
+
eventHandler({ target: this });
|
|
4821
|
+
},
|
|
4822
|
+
}, false, currentWindow)));
|
|
4823
|
+
}
|
|
4824
|
+
return () => {
|
|
4825
|
+
handlers.forEach((h) => h());
|
|
4826
|
+
};
|
|
4827
|
+
}
|
|
4828
|
+
function getNestedCSSRulePositions(rule) {
|
|
4829
|
+
const positions = [];
|
|
4830
|
+
function recurse(childRule, pos) {
|
|
4831
|
+
if ((isCSSGroupingRuleSupported &&
|
|
4832
|
+
childRule.parentRule instanceof CSSGroupingRule) ||
|
|
4833
|
+
(isCSSMediaRuleSupported &&
|
|
4834
|
+
childRule.parentRule instanceof CSSMediaRule) ||
|
|
4835
|
+
(isCSSSupportsRuleSupported &&
|
|
4836
|
+
childRule.parentRule instanceof CSSSupportsRule) ||
|
|
4837
|
+
(isCSSConditionRuleSupported &&
|
|
4838
|
+
childRule.parentRule instanceof CSSConditionRule)) {
|
|
4839
|
+
const rules = Array.from(childRule.parentRule.cssRules);
|
|
4840
|
+
const index = rules.indexOf(childRule);
|
|
4841
|
+
pos.unshift(index);
|
|
4842
|
+
}
|
|
4843
|
+
else if (childRule.parentStyleSheet) {
|
|
4844
|
+
const rules = Array.from(childRule.parentStyleSheet.cssRules);
|
|
4845
|
+
const index = rules.indexOf(childRule);
|
|
4846
|
+
pos.unshift(index);
|
|
4847
|
+
}
|
|
4848
|
+
return pos;
|
|
4849
|
+
}
|
|
4850
|
+
return recurse(rule, positions);
|
|
4851
|
+
}
|
|
4852
|
+
function getIdAndStyleId(sheet, mirror, styleMirror) {
|
|
4853
|
+
let id, styleId;
|
|
4854
|
+
if (!sheet)
|
|
4855
|
+
return {};
|
|
4856
|
+
if (sheet.ownerNode)
|
|
4857
|
+
id = mirror.getId(sheet.ownerNode);
|
|
4858
|
+
else
|
|
4859
|
+
styleId = styleMirror.getId(sheet);
|
|
4860
|
+
return {
|
|
4861
|
+
styleId,
|
|
4862
|
+
id,
|
|
4863
|
+
};
|
|
4864
|
+
}
|
|
4865
|
+
function initStyleSheetObserver({ styleSheetRuleCb, mirror, stylesheetManager }, { win }) {
|
|
4866
|
+
const insertRule = win.CSSStyleSheet.prototype.insertRule;
|
|
4867
|
+
win.CSSStyleSheet.prototype.insertRule = function (rule, index) {
|
|
4868
|
+
const { id, styleId } = getIdAndStyleId(this, mirror, stylesheetManager.styleMirror);
|
|
4869
|
+
if ((id && id !== -1) || (styleId && styleId !== -1)) {
|
|
4870
|
+
styleSheetRuleCb({
|
|
4871
|
+
id,
|
|
4872
|
+
styleId,
|
|
4873
|
+
adds: [{ rule, index }],
|
|
4874
|
+
});
|
|
4875
|
+
}
|
|
4876
|
+
return insertRule.apply(this, [rule, index]);
|
|
4877
|
+
};
|
|
4878
|
+
const deleteRule = win.CSSStyleSheet.prototype.deleteRule;
|
|
4879
|
+
win.CSSStyleSheet.prototype.deleteRule = function (index) {
|
|
4880
|
+
const { id, styleId } = getIdAndStyleId(this, mirror, stylesheetManager.styleMirror);
|
|
4881
|
+
if ((id && id !== -1) || (styleId && styleId !== -1)) {
|
|
4882
|
+
styleSheetRuleCb({
|
|
4883
|
+
id,
|
|
4884
|
+
styleId,
|
|
4885
|
+
removes: [{ index }],
|
|
4886
|
+
});
|
|
4887
|
+
}
|
|
4888
|
+
return deleteRule.apply(this, [index]);
|
|
4889
|
+
};
|
|
4890
|
+
let replace;
|
|
4891
|
+
if (win.CSSStyleSheet.prototype.replace) {
|
|
4892
|
+
replace = win.CSSStyleSheet.prototype.replace;
|
|
4893
|
+
win.CSSStyleSheet.prototype.replace = function (text) {
|
|
4894
|
+
const { id, styleId } = getIdAndStyleId(this, mirror, stylesheetManager.styleMirror);
|
|
4895
|
+
if ((id && id !== -1) || (styleId && styleId !== -1)) {
|
|
4896
|
+
styleSheetRuleCb({
|
|
4897
|
+
id,
|
|
4898
|
+
styleId,
|
|
4899
|
+
replace: text,
|
|
4900
|
+
});
|
|
4901
|
+
}
|
|
4902
|
+
return replace.apply(this, [text]);
|
|
4903
|
+
};
|
|
4904
|
+
}
|
|
4905
|
+
let replaceSync;
|
|
4906
|
+
if (win.CSSStyleSheet.prototype.replaceSync) {
|
|
4907
|
+
replaceSync = win.CSSStyleSheet.prototype.replaceSync;
|
|
4908
|
+
win.CSSStyleSheet.prototype.replaceSync = function (text) {
|
|
4909
|
+
const { id, styleId } = getIdAndStyleId(this, mirror, stylesheetManager.styleMirror);
|
|
4910
|
+
if ((id && id !== -1) || (styleId && styleId !== -1)) {
|
|
4911
|
+
styleSheetRuleCb({
|
|
4912
|
+
id,
|
|
4913
|
+
styleId,
|
|
4914
|
+
replaceSync: text,
|
|
4915
|
+
});
|
|
4916
|
+
}
|
|
4917
|
+
return replaceSync.apply(this, [text]);
|
|
4918
|
+
};
|
|
4919
|
+
}
|
|
4920
|
+
const supportedNestedCSSRuleTypes = {};
|
|
4921
|
+
if (isCSSGroupingRuleSupported) {
|
|
4922
|
+
supportedNestedCSSRuleTypes.CSSGroupingRule = win.CSSGroupingRule;
|
|
4923
|
+
}
|
|
4924
|
+
else {
|
|
4925
|
+
if (isCSSMediaRuleSupported) {
|
|
4926
|
+
supportedNestedCSSRuleTypes.CSSMediaRule = win.CSSMediaRule;
|
|
4927
|
+
}
|
|
4928
|
+
if (isCSSConditionRuleSupported) {
|
|
4929
|
+
supportedNestedCSSRuleTypes.CSSConditionRule = win.CSSConditionRule;
|
|
4930
|
+
}
|
|
4931
|
+
if (isCSSSupportsRuleSupported) {
|
|
4932
|
+
supportedNestedCSSRuleTypes.CSSSupportsRule = win.CSSSupportsRule;
|
|
4933
|
+
}
|
|
4934
|
+
}
|
|
4935
|
+
const unmodifiedFunctions = {};
|
|
4936
|
+
Object.entries(supportedNestedCSSRuleTypes).forEach(([typeKey, type]) => {
|
|
4937
|
+
unmodifiedFunctions[typeKey] = {
|
|
4938
|
+
insertRule: type.prototype.insertRule,
|
|
4939
|
+
deleteRule: type.prototype.deleteRule,
|
|
4940
|
+
};
|
|
4941
|
+
type.prototype.insertRule = function (rule, index) {
|
|
4942
|
+
const { id, styleId } = getIdAndStyleId(this.parentStyleSheet, mirror, stylesheetManager.styleMirror);
|
|
4943
|
+
if ((id && id !== -1) || (styleId && styleId !== -1)) {
|
|
4944
|
+
styleSheetRuleCb({
|
|
4945
|
+
id,
|
|
4946
|
+
styleId,
|
|
4947
|
+
adds: [
|
|
4948
|
+
{
|
|
4949
|
+
rule,
|
|
4950
|
+
index: [
|
|
4951
|
+
...getNestedCSSRulePositions(this),
|
|
4952
|
+
index || 0,
|
|
4953
|
+
],
|
|
4954
|
+
},
|
|
4955
|
+
],
|
|
4956
|
+
});
|
|
4957
|
+
}
|
|
4958
|
+
return unmodifiedFunctions[typeKey].insertRule.apply(this, [rule, index]);
|
|
4959
|
+
};
|
|
4960
|
+
type.prototype.deleteRule = function (index) {
|
|
4961
|
+
const { id, styleId } = getIdAndStyleId(this.parentStyleSheet, mirror, stylesheetManager.styleMirror);
|
|
4962
|
+
if ((id && id !== -1) || (styleId && styleId !== -1)) {
|
|
4963
|
+
styleSheetRuleCb({
|
|
4964
|
+
id,
|
|
4965
|
+
styleId,
|
|
4966
|
+
removes: [
|
|
4967
|
+
{ index: [...getNestedCSSRulePositions(this), index] },
|
|
4968
|
+
],
|
|
4969
|
+
});
|
|
4970
|
+
}
|
|
4971
|
+
return unmodifiedFunctions[typeKey].deleteRule.apply(this, [index]);
|
|
4972
|
+
};
|
|
4973
|
+
});
|
|
4974
|
+
return () => {
|
|
4975
|
+
win.CSSStyleSheet.prototype.insertRule = insertRule;
|
|
4976
|
+
win.CSSStyleSheet.prototype.deleteRule = deleteRule;
|
|
4977
|
+
replace && (win.CSSStyleSheet.prototype.replace = replace);
|
|
4978
|
+
replaceSync && (win.CSSStyleSheet.prototype.replaceSync = replaceSync);
|
|
4979
|
+
Object.entries(supportedNestedCSSRuleTypes).forEach(([typeKey, type]) => {
|
|
4980
|
+
type.prototype.insertRule = unmodifiedFunctions[typeKey].insertRule;
|
|
4981
|
+
type.prototype.deleteRule = unmodifiedFunctions[typeKey].deleteRule;
|
|
4982
|
+
});
|
|
4983
|
+
};
|
|
4984
|
+
}
|
|
4985
|
+
function initAdoptedStyleSheetObserver({ mirror, stylesheetManager, }, host) {
|
|
4986
|
+
var _a, _b, _c;
|
|
4987
|
+
let hostId = null;
|
|
4988
|
+
if (host.nodeName === '#document')
|
|
4989
|
+
hostId = mirror.getId(host);
|
|
4990
|
+
else
|
|
4991
|
+
hostId = mirror.getId(host.host);
|
|
4992
|
+
const patchTarget = host.nodeName === '#document'
|
|
4993
|
+
? (_a = host.defaultView) === null || _a === void 0 ? void 0 : _a.Document
|
|
4994
|
+
: (_c = (_b = host.ownerDocument) === null || _b === void 0 ? void 0 : _b.defaultView) === null || _c === void 0 ? void 0 : _c.ShadowRoot;
|
|
4995
|
+
const originalPropertyDescriptor = Object.getOwnPropertyDescriptor(patchTarget === null || patchTarget === void 0 ? void 0 : patchTarget.prototype, 'adoptedStyleSheets');
|
|
4996
|
+
if (hostId === null ||
|
|
4997
|
+
hostId === -1 ||
|
|
4998
|
+
!patchTarget ||
|
|
4999
|
+
!originalPropertyDescriptor)
|
|
5000
|
+
return () => {
|
|
5001
|
+
};
|
|
5002
|
+
Object.defineProperty(host, 'adoptedStyleSheets', {
|
|
5003
|
+
configurable: originalPropertyDescriptor.configurable,
|
|
5004
|
+
enumerable: originalPropertyDescriptor.enumerable,
|
|
5005
|
+
get() {
|
|
5006
|
+
var _a;
|
|
5007
|
+
return (_a = originalPropertyDescriptor.get) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
5008
|
+
},
|
|
5009
|
+
set(sheets) {
|
|
5010
|
+
var _a;
|
|
5011
|
+
const result = (_a = originalPropertyDescriptor.set) === null || _a === void 0 ? void 0 : _a.call(this, sheets);
|
|
5012
|
+
if (hostId !== null && hostId !== -1) {
|
|
5013
|
+
try {
|
|
5014
|
+
stylesheetManager.adoptStyleSheets(sheets, hostId);
|
|
5015
|
+
}
|
|
5016
|
+
catch (e) {
|
|
5017
|
+
}
|
|
5018
|
+
}
|
|
5019
|
+
return result;
|
|
5020
|
+
},
|
|
5021
|
+
});
|
|
5022
|
+
return () => {
|
|
5023
|
+
Object.defineProperty(host, 'adoptedStyleSheets', {
|
|
5024
|
+
configurable: originalPropertyDescriptor.configurable,
|
|
5025
|
+
enumerable: originalPropertyDescriptor.enumerable,
|
|
5026
|
+
get: originalPropertyDescriptor.get,
|
|
5027
|
+
set: originalPropertyDescriptor.set,
|
|
5028
|
+
});
|
|
5029
|
+
};
|
|
5030
|
+
}
|
|
5031
|
+
function initStyleDeclarationObserver({ styleDeclarationCb, mirror, ignoreCSSAttributes, stylesheetManager, }, { win }) {
|
|
5032
|
+
const setProperty = win.CSSStyleDeclaration.prototype.setProperty;
|
|
5033
|
+
win.CSSStyleDeclaration.prototype.setProperty = function (property, value, priority) {
|
|
5034
|
+
var _a;
|
|
5035
|
+
if (ignoreCSSAttributes.has(property)) {
|
|
5036
|
+
return setProperty.apply(this, [property, value, priority]);
|
|
5037
|
+
}
|
|
5038
|
+
const { id, styleId } = getIdAndStyleId((_a = this.parentRule) === null || _a === void 0 ? void 0 : _a.parentStyleSheet, mirror, stylesheetManager.styleMirror);
|
|
5039
|
+
if ((id && id !== -1) || (styleId && styleId !== -1)) {
|
|
5040
|
+
styleDeclarationCb({
|
|
5041
|
+
id,
|
|
5042
|
+
styleId,
|
|
5043
|
+
set: {
|
|
5044
|
+
property,
|
|
5045
|
+
value,
|
|
5046
|
+
priority,
|
|
5047
|
+
},
|
|
5048
|
+
index: getNestedCSSRulePositions(this.parentRule),
|
|
5049
|
+
});
|
|
5050
|
+
}
|
|
5051
|
+
return setProperty.apply(this, [property, value, priority]);
|
|
5052
|
+
};
|
|
5053
|
+
const removeProperty = win.CSSStyleDeclaration.prototype.removeProperty;
|
|
5054
|
+
win.CSSStyleDeclaration.prototype.removeProperty = function (property) {
|
|
5055
|
+
var _a;
|
|
5056
|
+
if (ignoreCSSAttributes.has(property)) {
|
|
5057
|
+
return removeProperty.apply(this, [property]);
|
|
5058
|
+
}
|
|
5059
|
+
const { id, styleId } = getIdAndStyleId((_a = this.parentRule) === null || _a === void 0 ? void 0 : _a.parentStyleSheet, mirror, stylesheetManager.styleMirror);
|
|
5060
|
+
if ((id && id !== -1) || (styleId && styleId !== -1)) {
|
|
5061
|
+
styleDeclarationCb({
|
|
5062
|
+
id,
|
|
5063
|
+
styleId,
|
|
5064
|
+
remove: {
|
|
5065
|
+
property,
|
|
5066
|
+
},
|
|
5067
|
+
index: getNestedCSSRulePositions(this.parentRule),
|
|
5068
|
+
});
|
|
5069
|
+
}
|
|
5070
|
+
return removeProperty.apply(this, [property]);
|
|
5071
|
+
};
|
|
5072
|
+
return () => {
|
|
5073
|
+
win.CSSStyleDeclaration.prototype.setProperty = setProperty;
|
|
5074
|
+
win.CSSStyleDeclaration.prototype.removeProperty = removeProperty;
|
|
5075
|
+
};
|
|
5076
|
+
}
|
|
5077
|
+
function initMediaInteractionObserver({ mediaInteractionCb, blockClass, blockSelector, mirror, sampling, }) {
|
|
5078
|
+
const handler = (type) => throttle((event) => {
|
|
5079
|
+
const target = getEventTarget(event);
|
|
5080
|
+
if (!target ||
|
|
5081
|
+
isBlocked(target, blockClass, blockSelector, true)) {
|
|
5082
|
+
return;
|
|
5083
|
+
}
|
|
5084
|
+
const { currentTime, volume, muted, playbackRate, } = target;
|
|
5085
|
+
mediaInteractionCb({
|
|
5086
|
+
type,
|
|
5087
|
+
id: mirror.getId(target),
|
|
5088
|
+
currentTime,
|
|
5089
|
+
volume,
|
|
5090
|
+
muted,
|
|
5091
|
+
playbackRate,
|
|
5092
|
+
});
|
|
5093
|
+
}, sampling.media || 500);
|
|
5094
|
+
const handlers = [
|
|
5095
|
+
on('play', handler(0)),
|
|
5096
|
+
on('pause', handler(1)),
|
|
5097
|
+
on('seeked', handler(2)),
|
|
5098
|
+
on('volumechange', handler(3)),
|
|
5099
|
+
on('ratechange', handler(4)),
|
|
5100
|
+
];
|
|
5101
|
+
return () => {
|
|
5102
|
+
handlers.forEach((h) => h());
|
|
5103
|
+
};
|
|
5104
|
+
}
|
|
5105
|
+
function initFontObserver({ fontCb, doc }) {
|
|
5106
|
+
const win = doc.defaultView;
|
|
5107
|
+
if (!win) {
|
|
5108
|
+
return () => {
|
|
5109
|
+
};
|
|
5110
|
+
}
|
|
5111
|
+
const handlers = [];
|
|
5112
|
+
const fontMap = new WeakMap();
|
|
5113
|
+
const originalFontFace = win.FontFace;
|
|
5114
|
+
win.FontFace = function FontFace(family, source, descriptors) {
|
|
5115
|
+
const fontFace = new originalFontFace(family, source, descriptors);
|
|
5116
|
+
fontMap.set(fontFace, {
|
|
5117
|
+
family,
|
|
5118
|
+
buffer: typeof source !== 'string',
|
|
5119
|
+
descriptors,
|
|
5120
|
+
fontSource: typeof source === 'string'
|
|
5121
|
+
? source
|
|
5122
|
+
: JSON.stringify(Array.from(new Uint8Array(source))),
|
|
5123
|
+
});
|
|
5124
|
+
return fontFace;
|
|
5125
|
+
};
|
|
5126
|
+
const restoreHandler = patch(doc.fonts, 'add', function (original) {
|
|
5127
|
+
return function (fontFace) {
|
|
5128
|
+
setTimeout(() => {
|
|
5129
|
+
const p = fontMap.get(fontFace);
|
|
5130
|
+
if (p) {
|
|
5131
|
+
fontCb(p);
|
|
5132
|
+
fontMap.delete(fontFace);
|
|
5133
|
+
}
|
|
5134
|
+
}, 0);
|
|
5135
|
+
return original.apply(this, [fontFace]);
|
|
5136
|
+
};
|
|
5137
|
+
});
|
|
5138
|
+
handlers.push(() => {
|
|
5139
|
+
win.FontFace = originalFontFace;
|
|
5140
|
+
});
|
|
5141
|
+
handlers.push(restoreHandler);
|
|
5142
|
+
return () => {
|
|
5143
|
+
handlers.forEach((h) => h());
|
|
5144
|
+
};
|
|
5145
|
+
}
|
|
5146
|
+
function initSelectionObserver(param) {
|
|
5147
|
+
const { doc, mirror, blockClass, blockSelector, selectionCb } = param;
|
|
5148
|
+
let collapsed = true;
|
|
5149
|
+
const updateSelection = () => {
|
|
5150
|
+
const selection = doc.getSelection();
|
|
5151
|
+
if (!selection || (collapsed && (selection === null || selection === void 0 ? void 0 : selection.isCollapsed)))
|
|
5152
|
+
return;
|
|
5153
|
+
collapsed = selection.isCollapsed || false;
|
|
5154
|
+
const ranges = [];
|
|
5155
|
+
const count = selection.rangeCount || 0;
|
|
5156
|
+
for (let i = 0; i < count; i++) {
|
|
5157
|
+
const range = selection.getRangeAt(i);
|
|
5158
|
+
const { startContainer, startOffset, endContainer, endOffset } = range;
|
|
5159
|
+
const blocked = isBlocked(startContainer, blockClass, blockSelector, true) ||
|
|
5160
|
+
isBlocked(endContainer, blockClass, blockSelector, true);
|
|
5161
|
+
if (blocked)
|
|
5162
|
+
continue;
|
|
5163
|
+
ranges.push({
|
|
5164
|
+
start: mirror.getId(startContainer),
|
|
5165
|
+
startOffset,
|
|
5166
|
+
end: mirror.getId(endContainer),
|
|
5167
|
+
endOffset,
|
|
5168
|
+
});
|
|
5169
|
+
}
|
|
5170
|
+
selectionCb({ ranges });
|
|
5171
|
+
};
|
|
5172
|
+
updateSelection();
|
|
5173
|
+
return on('selectionchange', updateSelection);
|
|
5174
|
+
}
|
|
5175
|
+
function mergeHooks(o, hooks) {
|
|
5176
|
+
const { mutationCb, mousemoveCb, mouseInteractionCb, scrollCb, viewportResizeCb, inputCb, mediaInteractionCb, styleSheetRuleCb, styleDeclarationCb, canvasMutationCb, fontCb, selectionCb, } = o;
|
|
5177
|
+
o.mutationCb = (...p) => {
|
|
5178
|
+
if (hooks.mutation) {
|
|
5179
|
+
hooks.mutation(...p);
|
|
5180
|
+
}
|
|
5181
|
+
mutationCb(...p);
|
|
5182
|
+
};
|
|
5183
|
+
o.mousemoveCb = (...p) => {
|
|
5184
|
+
if (hooks.mousemove) {
|
|
5185
|
+
hooks.mousemove(...p);
|
|
5186
|
+
}
|
|
5187
|
+
mousemoveCb(...p);
|
|
5188
|
+
};
|
|
5189
|
+
o.mouseInteractionCb = (...p) => {
|
|
5190
|
+
if (hooks.mouseInteraction) {
|
|
5191
|
+
hooks.mouseInteraction(...p);
|
|
5192
|
+
}
|
|
5193
|
+
mouseInteractionCb(...p);
|
|
5194
|
+
};
|
|
5195
|
+
o.scrollCb = (...p) => {
|
|
5196
|
+
if (hooks.scroll) {
|
|
5197
|
+
hooks.scroll(...p);
|
|
5198
|
+
}
|
|
5199
|
+
scrollCb(...p);
|
|
5200
|
+
};
|
|
5201
|
+
o.viewportResizeCb = (...p) => {
|
|
5202
|
+
if (hooks.viewportResize) {
|
|
5203
|
+
hooks.viewportResize(...p);
|
|
5204
|
+
}
|
|
5205
|
+
viewportResizeCb(...p);
|
|
5206
|
+
};
|
|
5207
|
+
o.inputCb = (...p) => {
|
|
5208
|
+
if (hooks.input) {
|
|
5209
|
+
hooks.input(...p);
|
|
5210
|
+
}
|
|
5211
|
+
inputCb(...p);
|
|
5212
|
+
};
|
|
5213
|
+
o.mediaInteractionCb = (...p) => {
|
|
5214
|
+
if (hooks.mediaInteaction) {
|
|
5215
|
+
hooks.mediaInteaction(...p);
|
|
5216
|
+
}
|
|
5217
|
+
mediaInteractionCb(...p);
|
|
5218
|
+
};
|
|
5219
|
+
o.styleSheetRuleCb = (...p) => {
|
|
5220
|
+
if (hooks.styleSheetRule) {
|
|
5221
|
+
hooks.styleSheetRule(...p);
|
|
5222
|
+
}
|
|
5223
|
+
styleSheetRuleCb(...p);
|
|
5224
|
+
};
|
|
5225
|
+
o.styleDeclarationCb = (...p) => {
|
|
5226
|
+
if (hooks.styleDeclaration) {
|
|
5227
|
+
hooks.styleDeclaration(...p);
|
|
5228
|
+
}
|
|
5229
|
+
styleDeclarationCb(...p);
|
|
5230
|
+
};
|
|
5231
|
+
o.canvasMutationCb = (...p) => {
|
|
5232
|
+
if (hooks.canvasMutation) {
|
|
5233
|
+
hooks.canvasMutation(...p);
|
|
5234
|
+
}
|
|
5235
|
+
canvasMutationCb(...p);
|
|
5236
|
+
};
|
|
5237
|
+
o.fontCb = (...p) => {
|
|
5238
|
+
if (hooks.font) {
|
|
5239
|
+
hooks.font(...p);
|
|
5240
|
+
}
|
|
5241
|
+
fontCb(...p);
|
|
5242
|
+
};
|
|
5243
|
+
o.selectionCb = (...p) => {
|
|
5244
|
+
if (hooks.selection) {
|
|
5245
|
+
hooks.selection(...p);
|
|
5246
|
+
}
|
|
5247
|
+
selectionCb(...p);
|
|
5248
|
+
};
|
|
5249
|
+
}
|
|
5250
|
+
function initObservers(o, hooks = {}) {
|
|
5251
|
+
const currentWindow = o.doc.defaultView;
|
|
5252
|
+
if (!currentWindow) {
|
|
5253
|
+
return () => {
|
|
5254
|
+
};
|
|
5255
|
+
}
|
|
5256
|
+
mergeHooks(o, hooks);
|
|
5257
|
+
const mutationObserver = initMutationObserver(o, o.doc);
|
|
5258
|
+
const mousemoveHandler = initMoveObserver(o);
|
|
5259
|
+
const mouseInteractionHandler = initMouseInteractionObserver(o);
|
|
5260
|
+
const scrollHandler = initScrollObserver(o);
|
|
5261
|
+
const viewportResizeHandler = initViewportResizeObserver(o);
|
|
5262
|
+
const inputHandler = initInputObserver(o);
|
|
5263
|
+
const mediaInteractionHandler = initMediaInteractionObserver(o);
|
|
5264
|
+
const styleSheetObserver = initStyleSheetObserver(o, { win: currentWindow });
|
|
5265
|
+
const adoptedStyleSheetObserver = initAdoptedStyleSheetObserver(o, o.doc);
|
|
5266
|
+
const styleDeclarationObserver = initStyleDeclarationObserver(o, {
|
|
5267
|
+
win: currentWindow,
|
|
5268
|
+
});
|
|
5269
|
+
const fontObserver = o.collectFonts
|
|
5270
|
+
? initFontObserver(o)
|
|
5271
|
+
: () => {
|
|
5272
|
+
};
|
|
5273
|
+
const selectionObserver = initSelectionObserver(o);
|
|
5274
|
+
const pluginHandlers = [];
|
|
5275
|
+
for (const plugin of o.plugins) {
|
|
5276
|
+
pluginHandlers.push(plugin.observer(plugin.callback, currentWindow, plugin.options));
|
|
5277
|
+
}
|
|
5278
|
+
return () => {
|
|
5279
|
+
mutationBuffers.forEach((b) => b.reset());
|
|
5280
|
+
mutationObserver.disconnect();
|
|
5281
|
+
mousemoveHandler();
|
|
5282
|
+
mouseInteractionHandler();
|
|
5283
|
+
scrollHandler();
|
|
5284
|
+
viewportResizeHandler();
|
|
5285
|
+
inputHandler();
|
|
5286
|
+
mediaInteractionHandler();
|
|
5287
|
+
styleSheetObserver();
|
|
5288
|
+
adoptedStyleSheetObserver();
|
|
5289
|
+
styleDeclarationObserver();
|
|
5290
|
+
fontObserver();
|
|
5291
|
+
selectionObserver();
|
|
5292
|
+
pluginHandlers.forEach((h) => h());
|
|
5293
|
+
};
|
|
5294
|
+
}
|
|
5295
|
+
|
|
5296
|
+
class CrossOriginIframeMirror {
|
|
5297
|
+
constructor(generateIdFn) {
|
|
5298
|
+
this.generateIdFn = generateIdFn;
|
|
5299
|
+
this.iframeIdToRemoteIdMap = new WeakMap();
|
|
5300
|
+
this.iframeRemoteIdToIdMap = new WeakMap();
|
|
5301
|
+
}
|
|
5302
|
+
getId(iframe, remoteId, idToRemoteMap, remoteToIdMap) {
|
|
5303
|
+
const idToRemoteIdMap = idToRemoteMap || this.getIdToRemoteIdMap(iframe);
|
|
5304
|
+
const remoteIdToIdMap = remoteToIdMap || this.getRemoteIdToIdMap(iframe);
|
|
5305
|
+
let id = idToRemoteIdMap.get(remoteId);
|
|
5306
|
+
if (!id) {
|
|
5307
|
+
id = this.generateIdFn();
|
|
5308
|
+
idToRemoteIdMap.set(remoteId, id);
|
|
5309
|
+
remoteIdToIdMap.set(id, remoteId);
|
|
5310
|
+
}
|
|
5311
|
+
return id;
|
|
5312
|
+
}
|
|
5313
|
+
getIds(iframe, remoteId) {
|
|
5314
|
+
const idToRemoteIdMap = this.getIdToRemoteIdMap(iframe);
|
|
5315
|
+
const remoteIdToIdMap = this.getRemoteIdToIdMap(iframe);
|
|
5316
|
+
return remoteId.map((id) => this.getId(iframe, id, idToRemoteIdMap, remoteIdToIdMap));
|
|
5317
|
+
}
|
|
5318
|
+
getRemoteId(iframe, id, map) {
|
|
5319
|
+
const remoteIdToIdMap = map || this.getRemoteIdToIdMap(iframe);
|
|
5320
|
+
if (typeof id !== 'number')
|
|
5321
|
+
return id;
|
|
5322
|
+
const remoteId = remoteIdToIdMap.get(id);
|
|
5323
|
+
if (!remoteId)
|
|
5324
|
+
return -1;
|
|
5325
|
+
return remoteId;
|
|
5326
|
+
}
|
|
5327
|
+
getRemoteIds(iframe, ids) {
|
|
5328
|
+
const remoteIdToIdMap = this.getRemoteIdToIdMap(iframe);
|
|
5329
|
+
return ids.map((id) => this.getRemoteId(iframe, id, remoteIdToIdMap));
|
|
5330
|
+
}
|
|
5331
|
+
reset(iframe) {
|
|
5332
|
+
if (!iframe) {
|
|
5333
|
+
this.iframeIdToRemoteIdMap = new WeakMap();
|
|
5334
|
+
this.iframeRemoteIdToIdMap = new WeakMap();
|
|
5335
|
+
return;
|
|
5336
|
+
}
|
|
5337
|
+
this.iframeIdToRemoteIdMap.delete(iframe);
|
|
5338
|
+
this.iframeRemoteIdToIdMap.delete(iframe);
|
|
5339
|
+
}
|
|
5340
|
+
getIdToRemoteIdMap(iframe) {
|
|
5341
|
+
let idToRemoteIdMap = this.iframeIdToRemoteIdMap.get(iframe);
|
|
5342
|
+
if (!idToRemoteIdMap) {
|
|
5343
|
+
idToRemoteIdMap = new Map();
|
|
5344
|
+
this.iframeIdToRemoteIdMap.set(iframe, idToRemoteIdMap);
|
|
5345
|
+
}
|
|
5346
|
+
return idToRemoteIdMap;
|
|
5347
|
+
}
|
|
5348
|
+
getRemoteIdToIdMap(iframe) {
|
|
5349
|
+
let remoteIdToIdMap = this.iframeRemoteIdToIdMap.get(iframe);
|
|
5350
|
+
if (!remoteIdToIdMap) {
|
|
5351
|
+
remoteIdToIdMap = new Map();
|
|
5352
|
+
this.iframeRemoteIdToIdMap.set(iframe, remoteIdToIdMap);
|
|
5353
|
+
}
|
|
5354
|
+
return remoteIdToIdMap;
|
|
5355
|
+
}
|
|
5356
|
+
}
|
|
5357
|
+
|
|
5358
|
+
class IframeManager {
|
|
5359
|
+
constructor(options) {
|
|
5360
|
+
this.iframes = new WeakMap();
|
|
5361
|
+
this.crossOriginIframeMap = new WeakMap();
|
|
5362
|
+
this.crossOriginIframeMirror = new CrossOriginIframeMirror(genId);
|
|
5363
|
+
this.mutationCb = options.mutationCb;
|
|
5364
|
+
this.wrappedEmit = options.wrappedEmit;
|
|
5365
|
+
this.stylesheetManager = options.stylesheetManager;
|
|
5366
|
+
this.recordCrossOriginIframes = options.recordCrossOriginIframes;
|
|
5367
|
+
this.crossOriginIframeStyleMirror = new CrossOriginIframeMirror(this.stylesheetManager.styleMirror.generateId.bind(this.stylesheetManager.styleMirror));
|
|
5368
|
+
this.mirror = options.mirror;
|
|
5369
|
+
if (this.recordCrossOriginIframes) {
|
|
5370
|
+
window.addEventListener('message', this.handleMessage.bind(this));
|
|
5371
|
+
}
|
|
5372
|
+
}
|
|
5373
|
+
addIframe(iframeEl) {
|
|
5374
|
+
this.iframes.set(iframeEl, true);
|
|
5375
|
+
if (iframeEl.contentWindow)
|
|
5376
|
+
this.crossOriginIframeMap.set(iframeEl.contentWindow, iframeEl);
|
|
5377
|
+
}
|
|
5378
|
+
addLoadListener(cb) {
|
|
5379
|
+
this.loadListener = cb;
|
|
5380
|
+
}
|
|
5381
|
+
attachIframe(iframeEl, childSn) {
|
|
5382
|
+
var _a;
|
|
5383
|
+
this.mutationCb({
|
|
5384
|
+
adds: [
|
|
5385
|
+
{
|
|
5386
|
+
parentId: this.mirror.getId(iframeEl),
|
|
5387
|
+
nextId: null,
|
|
5388
|
+
node: childSn,
|
|
5389
|
+
},
|
|
5390
|
+
],
|
|
5391
|
+
removes: [],
|
|
5392
|
+
texts: [],
|
|
5393
|
+
attributes: [],
|
|
5394
|
+
isAttachIframe: true,
|
|
5395
|
+
});
|
|
5396
|
+
(_a = this.loadListener) === null || _a === void 0 ? void 0 : _a.call(this, iframeEl);
|
|
5397
|
+
if (iframeEl.contentDocument &&
|
|
5398
|
+
iframeEl.contentDocument.adoptedStyleSheets &&
|
|
5399
|
+
iframeEl.contentDocument.adoptedStyleSheets.length > 0)
|
|
5400
|
+
this.stylesheetManager.adoptStyleSheets(iframeEl.contentDocument.adoptedStyleSheets, this.mirror.getId(iframeEl.contentDocument));
|
|
5401
|
+
}
|
|
5402
|
+
handleMessage(message) {
|
|
5403
|
+
if (message.data.type === 'rrweb') {
|
|
5404
|
+
const iframeSourceWindow = message.source;
|
|
5405
|
+
if (!iframeSourceWindow)
|
|
5406
|
+
return;
|
|
5407
|
+
const iframeEl = this.crossOriginIframeMap.get(message.source);
|
|
5408
|
+
if (!iframeEl)
|
|
5409
|
+
return;
|
|
5410
|
+
const transformedEvent = this.transformCrossOriginEvent(iframeEl, message.data.event);
|
|
5411
|
+
if (transformedEvent)
|
|
5412
|
+
this.wrappedEmit(transformedEvent, message.data.isCheckout);
|
|
5413
|
+
}
|
|
5414
|
+
}
|
|
5415
|
+
transformCrossOriginEvent(iframeEl, e) {
|
|
5416
|
+
var _a;
|
|
5417
|
+
switch (e.type) {
|
|
5418
|
+
case EventType.FullSnapshot: {
|
|
5419
|
+
this.crossOriginIframeMirror.reset(iframeEl);
|
|
5420
|
+
this.crossOriginIframeStyleMirror.reset(iframeEl);
|
|
5421
|
+
this.replaceIdOnNode(e.data.node, iframeEl);
|
|
5422
|
+
return {
|
|
5423
|
+
timestamp: e.timestamp,
|
|
5424
|
+
type: EventType.IncrementalSnapshot,
|
|
5425
|
+
data: {
|
|
5426
|
+
source: IncrementalSource.Mutation,
|
|
5427
|
+
adds: [
|
|
5428
|
+
{
|
|
5429
|
+
parentId: this.mirror.getId(iframeEl),
|
|
5430
|
+
nextId: null,
|
|
5431
|
+
node: e.data.node,
|
|
5432
|
+
},
|
|
5433
|
+
],
|
|
5434
|
+
removes: [],
|
|
5435
|
+
texts: [],
|
|
5436
|
+
attributes: [],
|
|
5437
|
+
isAttachIframe: true,
|
|
5438
|
+
},
|
|
5439
|
+
};
|
|
5440
|
+
}
|
|
5441
|
+
case EventType.Meta:
|
|
5442
|
+
case EventType.Load:
|
|
5443
|
+
case EventType.DomContentLoaded: {
|
|
5444
|
+
return false;
|
|
5445
|
+
}
|
|
5446
|
+
case EventType.Plugin: {
|
|
5447
|
+
return e;
|
|
5448
|
+
}
|
|
5449
|
+
case EventType.Custom: {
|
|
5450
|
+
this.replaceIds(e.data.payload, iframeEl, ['id', 'parentId', 'previousId', 'nextId']);
|
|
5451
|
+
return e;
|
|
5452
|
+
}
|
|
5453
|
+
case EventType.IncrementalSnapshot: {
|
|
5454
|
+
switch (e.data.source) {
|
|
5455
|
+
case IncrementalSource.Mutation: {
|
|
5456
|
+
e.data.adds.forEach((n) => {
|
|
5457
|
+
this.replaceIds(n, iframeEl, [
|
|
5458
|
+
'parentId',
|
|
5459
|
+
'nextId',
|
|
5460
|
+
'previousId',
|
|
5461
|
+
]);
|
|
5462
|
+
this.replaceIdOnNode(n.node, iframeEl);
|
|
5463
|
+
});
|
|
5464
|
+
e.data.removes.forEach((n) => {
|
|
5465
|
+
this.replaceIds(n, iframeEl, ['parentId', 'id']);
|
|
5466
|
+
});
|
|
5467
|
+
e.data.attributes.forEach((n) => {
|
|
5468
|
+
this.replaceIds(n, iframeEl, ['id']);
|
|
5469
|
+
});
|
|
5470
|
+
e.data.texts.forEach((n) => {
|
|
5471
|
+
this.replaceIds(n, iframeEl, ['id']);
|
|
5472
|
+
});
|
|
5473
|
+
return e;
|
|
5474
|
+
}
|
|
5475
|
+
case IncrementalSource.Drag:
|
|
5476
|
+
case IncrementalSource.TouchMove:
|
|
5477
|
+
case IncrementalSource.MouseMove: {
|
|
5478
|
+
e.data.positions.forEach((p) => {
|
|
5479
|
+
this.replaceIds(p, iframeEl, ['id']);
|
|
5480
|
+
});
|
|
5481
|
+
return e;
|
|
5482
|
+
}
|
|
5483
|
+
case IncrementalSource.ViewportResize: {
|
|
5484
|
+
return false;
|
|
5485
|
+
}
|
|
5486
|
+
case IncrementalSource.MediaInteraction:
|
|
5487
|
+
case IncrementalSource.MouseInteraction:
|
|
5488
|
+
case IncrementalSource.Scroll:
|
|
5489
|
+
case IncrementalSource.CanvasMutation:
|
|
5490
|
+
case IncrementalSource.Input: {
|
|
5491
|
+
this.replaceIds(e.data, iframeEl, ['id']);
|
|
5492
|
+
return e;
|
|
5493
|
+
}
|
|
5494
|
+
case IncrementalSource.StyleSheetRule:
|
|
5495
|
+
case IncrementalSource.StyleDeclaration: {
|
|
5496
|
+
this.replaceIds(e.data, iframeEl, ['id']);
|
|
5497
|
+
this.replaceStyleIds(e.data, iframeEl, ['styleId']);
|
|
5498
|
+
return e;
|
|
5499
|
+
}
|
|
5500
|
+
case IncrementalSource.Font: {
|
|
5501
|
+
return e;
|
|
5502
|
+
}
|
|
5503
|
+
case IncrementalSource.Selection: {
|
|
5504
|
+
e.data.ranges.forEach((range) => {
|
|
5505
|
+
this.replaceIds(range, iframeEl, ['start', 'end']);
|
|
5506
|
+
});
|
|
5507
|
+
return e;
|
|
5508
|
+
}
|
|
5509
|
+
case IncrementalSource.AdoptedStyleSheet: {
|
|
5510
|
+
this.replaceIds(e.data, iframeEl, ['id']);
|
|
5511
|
+
this.replaceStyleIds(e.data, iframeEl, ['styleIds']);
|
|
5512
|
+
(_a = e.data.styles) === null || _a === void 0 ? void 0 : _a.forEach((style) => {
|
|
5513
|
+
this.replaceStyleIds(style, iframeEl, ['styleId']);
|
|
5514
|
+
});
|
|
5515
|
+
return e;
|
|
5516
|
+
}
|
|
5517
|
+
}
|
|
5518
|
+
}
|
|
5519
|
+
}
|
|
5520
|
+
}
|
|
5521
|
+
replace(iframeMirror, obj, iframeEl, keys) {
|
|
5522
|
+
for (const key of keys) {
|
|
5523
|
+
if (!Array.isArray(obj[key]) && typeof obj[key] !== 'number')
|
|
5524
|
+
continue;
|
|
5525
|
+
if (Array.isArray(obj[key])) {
|
|
5526
|
+
obj[key] = iframeMirror.getIds(iframeEl, obj[key]);
|
|
5527
|
+
}
|
|
5528
|
+
else {
|
|
5529
|
+
obj[key] = iframeMirror.getId(iframeEl, obj[key]);
|
|
5530
|
+
}
|
|
5531
|
+
}
|
|
5532
|
+
return obj;
|
|
5533
|
+
}
|
|
5534
|
+
replaceIds(obj, iframeEl, keys) {
|
|
5535
|
+
return this.replace(this.crossOriginIframeMirror, obj, iframeEl, keys);
|
|
5536
|
+
}
|
|
5537
|
+
replaceStyleIds(obj, iframeEl, keys) {
|
|
5538
|
+
return this.replace(this.crossOriginIframeStyleMirror, obj, iframeEl, keys);
|
|
5539
|
+
}
|
|
5540
|
+
replaceIdOnNode(node, iframeEl) {
|
|
5541
|
+
this.replaceIds(node, iframeEl, ['id']);
|
|
5542
|
+
if ('childNodes' in node) {
|
|
5543
|
+
node.childNodes.forEach((child) => {
|
|
5544
|
+
this.replaceIdOnNode(child, iframeEl);
|
|
5545
|
+
});
|
|
5546
|
+
}
|
|
5547
|
+
}
|
|
5548
|
+
}
|
|
5549
|
+
|
|
5550
|
+
class ShadowDomManager {
|
|
5551
|
+
constructor(options) {
|
|
5552
|
+
this.shadowDoms = new WeakSet();
|
|
5553
|
+
this.restorePatches = [];
|
|
5554
|
+
this.mutationCb = options.mutationCb;
|
|
5555
|
+
this.scrollCb = options.scrollCb;
|
|
5556
|
+
this.bypassOptions = options.bypassOptions;
|
|
5557
|
+
this.mirror = options.mirror;
|
|
5558
|
+
const manager = this;
|
|
5559
|
+
this.restorePatches.push(patch(Element.prototype, 'attachShadow', function (original) {
|
|
5560
|
+
return function (option) {
|
|
5561
|
+
const shadowRoot = original.call(this, option);
|
|
5562
|
+
if (this.shadowRoot)
|
|
5563
|
+
manager.addShadowRoot(this.shadowRoot, this.ownerDocument);
|
|
5564
|
+
return shadowRoot;
|
|
5565
|
+
};
|
|
5566
|
+
}));
|
|
5567
|
+
}
|
|
5568
|
+
addShadowRoot(shadowRoot, doc) {
|
|
5569
|
+
if (!isNativeShadowDom(shadowRoot))
|
|
5570
|
+
return;
|
|
5571
|
+
if (this.shadowDoms.has(shadowRoot))
|
|
5572
|
+
return;
|
|
5573
|
+
this.shadowDoms.add(shadowRoot);
|
|
5574
|
+
initMutationObserver(Object.assign(Object.assign({}, this.bypassOptions), { doc, mutationCb: this.mutationCb, mirror: this.mirror, shadowDomManager: this }), shadowRoot);
|
|
5575
|
+
initScrollObserver(Object.assign(Object.assign({}, this.bypassOptions), { scrollCb: this.scrollCb, doc: shadowRoot, mirror: this.mirror }));
|
|
5576
|
+
setTimeout(() => {
|
|
5577
|
+
if (shadowRoot.adoptedStyleSheets &&
|
|
5578
|
+
shadowRoot.adoptedStyleSheets.length > 0)
|
|
5579
|
+
this.bypassOptions.stylesheetManager.adoptStyleSheets(shadowRoot.adoptedStyleSheets, this.mirror.getId(shadowRoot.host));
|
|
5580
|
+
initAdoptedStyleSheetObserver({
|
|
5581
|
+
mirror: this.mirror,
|
|
5582
|
+
stylesheetManager: this.bypassOptions.stylesheetManager,
|
|
5583
|
+
}, shadowRoot);
|
|
5584
|
+
}, 0);
|
|
5585
|
+
}
|
|
5586
|
+
observeAttachShadow(iframeElement) {
|
|
5587
|
+
if (iframeElement.contentWindow) {
|
|
5588
|
+
const manager = this;
|
|
5589
|
+
this.restorePatches.push(patch(iframeElement.contentWindow.HTMLElement.prototype, 'attachShadow', function (original) {
|
|
5590
|
+
return function (option) {
|
|
5591
|
+
const shadowRoot = original.call(this, option);
|
|
5592
|
+
if (this.shadowRoot)
|
|
5593
|
+
manager.addShadowRoot(this.shadowRoot, iframeElement.contentDocument);
|
|
5594
|
+
return shadowRoot;
|
|
5595
|
+
};
|
|
5596
|
+
}));
|
|
5597
|
+
}
|
|
5598
|
+
}
|
|
5599
|
+
reset() {
|
|
5600
|
+
this.restorePatches.forEach((restorePatch) => restorePatch());
|
|
5601
|
+
this.shadowDoms = new WeakSet();
|
|
5602
|
+
}
|
|
5603
|
+
}
|
|
5604
|
+
|
|
5605
|
+
/*! *****************************************************************************
|
|
5606
|
+
Copyright (c) Microsoft Corporation.
|
|
5607
|
+
|
|
5608
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
5609
|
+
purpose with or without fee is hereby granted.
|
|
5610
|
+
|
|
5611
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
5612
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
5613
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
5614
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
5615
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
5616
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
5617
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
5618
|
+
***************************************************************************** */
|
|
5619
|
+
|
|
5620
|
+
function __rest(s, e) {
|
|
5621
|
+
var t = {};
|
|
5622
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5623
|
+
t[p] = s[p];
|
|
5624
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
5625
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
5626
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
5627
|
+
t[p[i]] = s[p[i]];
|
|
5628
|
+
}
|
|
5629
|
+
return t;
|
|
5630
|
+
}
|
|
5631
|
+
|
|
5632
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
5633
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5634
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5635
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5636
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
5637
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
5638
|
+
step((generator = generator.apply(thisArg, [])).next());
|
|
5639
|
+
});
|
|
5640
|
+
}
|
|
5641
|
+
|
|
5642
|
+
/*
|
|
5643
|
+
* base64-arraybuffer 1.0.1 <https://github.com/niklasvh/base64-arraybuffer>
|
|
5644
|
+
* Copyright (c) 2021 Niklas von Hertzen <https://hertzen.com>
|
|
5645
|
+
* Released under MIT License
|
|
5646
|
+
*/
|
|
5647
|
+
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
5648
|
+
// Use a lookup table to find the index.
|
|
5649
|
+
var lookup = typeof Uint8Array === 'undefined' ? [] : new Uint8Array(256);
|
|
5650
|
+
for (var i = 0; i < chars.length; i++) {
|
|
5651
|
+
lookup[chars.charCodeAt(i)] = i;
|
|
5652
|
+
}
|
|
5653
|
+
var encode = function (arraybuffer) {
|
|
5654
|
+
var bytes = new Uint8Array(arraybuffer), i, len = bytes.length, base64 = '';
|
|
5655
|
+
for (i = 0; i < len; i += 3) {
|
|
5656
|
+
base64 += chars[bytes[i] >> 2];
|
|
5657
|
+
base64 += chars[((bytes[i] & 3) << 4) | (bytes[i + 1] >> 4)];
|
|
5658
|
+
base64 += chars[((bytes[i + 1] & 15) << 2) | (bytes[i + 2] >> 6)];
|
|
5659
|
+
base64 += chars[bytes[i + 2] & 63];
|
|
5660
|
+
}
|
|
5661
|
+
if (len % 3 === 2) {
|
|
5662
|
+
base64 = base64.substring(0, base64.length - 1) + '=';
|
|
5663
|
+
}
|
|
5664
|
+
else if (len % 3 === 1) {
|
|
5665
|
+
base64 = base64.substring(0, base64.length - 2) + '==';
|
|
5666
|
+
}
|
|
5667
|
+
return base64;
|
|
5668
|
+
};
|
|
5669
|
+
|
|
5670
|
+
const canvasVarMap = new Map();
|
|
5671
|
+
function variableListFor(ctx, ctor) {
|
|
5672
|
+
let contextMap = canvasVarMap.get(ctx);
|
|
5673
|
+
if (!contextMap) {
|
|
5674
|
+
contextMap = new Map();
|
|
5675
|
+
canvasVarMap.set(ctx, contextMap);
|
|
5676
|
+
}
|
|
5677
|
+
if (!contextMap.has(ctor)) {
|
|
5678
|
+
contextMap.set(ctor, []);
|
|
5679
|
+
}
|
|
5680
|
+
return contextMap.get(ctor);
|
|
5681
|
+
}
|
|
5682
|
+
const saveWebGLVar = (value, win, ctx) => {
|
|
5683
|
+
if (!value ||
|
|
5684
|
+
!(isInstanceOfWebGLObject(value, win) || typeof value === 'object'))
|
|
5685
|
+
return;
|
|
5686
|
+
const name = value.constructor.name;
|
|
5687
|
+
const list = variableListFor(ctx, name);
|
|
5688
|
+
let index = list.indexOf(value);
|
|
5689
|
+
if (index === -1) {
|
|
5690
|
+
index = list.length;
|
|
5691
|
+
list.push(value);
|
|
5692
|
+
}
|
|
5693
|
+
return index;
|
|
5694
|
+
};
|
|
5695
|
+
function serializeArg(value, win, ctx) {
|
|
5696
|
+
if (value instanceof Array) {
|
|
5697
|
+
return value.map((arg) => serializeArg(arg, win, ctx));
|
|
5698
|
+
}
|
|
5699
|
+
else if (value === null) {
|
|
5700
|
+
return value;
|
|
5701
|
+
}
|
|
5702
|
+
else if (value instanceof Float32Array ||
|
|
5703
|
+
value instanceof Float64Array ||
|
|
5704
|
+
value instanceof Int32Array ||
|
|
5705
|
+
value instanceof Uint32Array ||
|
|
5706
|
+
value instanceof Uint8Array ||
|
|
5707
|
+
value instanceof Uint16Array ||
|
|
5708
|
+
value instanceof Int16Array ||
|
|
5709
|
+
value instanceof Int8Array ||
|
|
5710
|
+
value instanceof Uint8ClampedArray) {
|
|
5711
|
+
const name = value.constructor.name;
|
|
5712
|
+
return {
|
|
5713
|
+
rr_type: name,
|
|
5714
|
+
args: [Object.values(value)],
|
|
5715
|
+
};
|
|
5716
|
+
}
|
|
5717
|
+
else if (value instanceof ArrayBuffer) {
|
|
5718
|
+
const name = value.constructor.name;
|
|
5719
|
+
const base64 = encode(value);
|
|
5720
|
+
return {
|
|
5721
|
+
rr_type: name,
|
|
5722
|
+
base64,
|
|
5723
|
+
};
|
|
5724
|
+
}
|
|
5725
|
+
else if (value instanceof DataView) {
|
|
5726
|
+
const name = value.constructor.name;
|
|
5727
|
+
return {
|
|
5728
|
+
rr_type: name,
|
|
5729
|
+
args: [
|
|
5730
|
+
serializeArg(value.buffer, win, ctx),
|
|
5731
|
+
value.byteOffset,
|
|
5732
|
+
value.byteLength,
|
|
5733
|
+
],
|
|
5734
|
+
};
|
|
5735
|
+
}
|
|
5736
|
+
else if (value instanceof HTMLImageElement) {
|
|
5737
|
+
const name = value.constructor.name;
|
|
5738
|
+
const { src } = value;
|
|
5739
|
+
return {
|
|
5740
|
+
rr_type: name,
|
|
5741
|
+
src,
|
|
5742
|
+
};
|
|
5743
|
+
}
|
|
5744
|
+
else if (value instanceof HTMLCanvasElement) {
|
|
5745
|
+
const name = 'HTMLImageElement';
|
|
5746
|
+
const src = value.toDataURL();
|
|
5747
|
+
return {
|
|
5748
|
+
rr_type: name,
|
|
5749
|
+
src,
|
|
5750
|
+
};
|
|
5751
|
+
}
|
|
5752
|
+
else if (value instanceof ImageData) {
|
|
5753
|
+
const name = value.constructor.name;
|
|
5754
|
+
return {
|
|
5755
|
+
rr_type: name,
|
|
5756
|
+
args: [serializeArg(value.data, win, ctx), value.width, value.height],
|
|
5757
|
+
};
|
|
5758
|
+
}
|
|
5759
|
+
else if (isInstanceOfWebGLObject(value, win) || typeof value === 'object') {
|
|
5760
|
+
const name = value.constructor.name;
|
|
5761
|
+
const index = saveWebGLVar(value, win, ctx);
|
|
5762
|
+
return {
|
|
5763
|
+
rr_type: name,
|
|
5764
|
+
index: index,
|
|
5765
|
+
};
|
|
5766
|
+
}
|
|
5767
|
+
return value;
|
|
5768
|
+
}
|
|
5769
|
+
const serializeArgs = (args, win, ctx) => {
|
|
5770
|
+
return [...args].map((arg) => serializeArg(arg, win, ctx));
|
|
5771
|
+
};
|
|
5772
|
+
const isInstanceOfWebGLObject = (value, win) => {
|
|
5773
|
+
const webGLConstructorNames = [
|
|
5774
|
+
'WebGLActiveInfo',
|
|
5775
|
+
'WebGLBuffer',
|
|
5776
|
+
'WebGLFramebuffer',
|
|
5777
|
+
'WebGLProgram',
|
|
5778
|
+
'WebGLRenderbuffer',
|
|
5779
|
+
'WebGLShader',
|
|
5780
|
+
'WebGLShaderPrecisionFormat',
|
|
5781
|
+
'WebGLTexture',
|
|
5782
|
+
'WebGLUniformLocation',
|
|
5783
|
+
'WebGLVertexArrayObject',
|
|
5784
|
+
'WebGLVertexArrayObjectOES',
|
|
5785
|
+
];
|
|
5786
|
+
const supportedWebGLConstructorNames = webGLConstructorNames.filter((name) => typeof win[name] === 'function');
|
|
5787
|
+
return Boolean(supportedWebGLConstructorNames.find((name) => value instanceof win[name]));
|
|
5788
|
+
};
|
|
5789
|
+
|
|
5790
|
+
function initCanvas2DMutationObserver(cb, win, blockClass, blockSelector) {
|
|
5791
|
+
const handlers = [];
|
|
5792
|
+
const props2D = Object.getOwnPropertyNames(win.CanvasRenderingContext2D.prototype);
|
|
5793
|
+
for (const prop of props2D) {
|
|
5794
|
+
try {
|
|
5795
|
+
if (typeof win.CanvasRenderingContext2D.prototype[prop] !== 'function') {
|
|
5796
|
+
continue;
|
|
5797
|
+
}
|
|
5798
|
+
const restoreHandler = patch(win.CanvasRenderingContext2D.prototype, prop, function (original) {
|
|
5799
|
+
return function (...args) {
|
|
5800
|
+
if (!isBlocked(this.canvas, blockClass, blockSelector, true)) {
|
|
5801
|
+
setTimeout(() => {
|
|
5802
|
+
const recordArgs = serializeArgs([...args], win, this);
|
|
5803
|
+
cb(this.canvas, {
|
|
5804
|
+
type: CanvasContext['2D'],
|
|
5805
|
+
property: prop,
|
|
5806
|
+
args: recordArgs,
|
|
5807
|
+
});
|
|
5808
|
+
}, 0);
|
|
5809
|
+
}
|
|
5810
|
+
return original.apply(this, args);
|
|
5811
|
+
};
|
|
5812
|
+
});
|
|
5813
|
+
handlers.push(restoreHandler);
|
|
5814
|
+
}
|
|
5815
|
+
catch (_a) {
|
|
5816
|
+
const hookHandler = hookSetter(win.CanvasRenderingContext2D.prototype, prop, {
|
|
5817
|
+
set(v) {
|
|
5818
|
+
cb(this.canvas, {
|
|
5819
|
+
type: CanvasContext['2D'],
|
|
5820
|
+
property: prop,
|
|
5821
|
+
args: [v],
|
|
5822
|
+
setter: true,
|
|
5823
|
+
});
|
|
5824
|
+
},
|
|
5825
|
+
});
|
|
5826
|
+
handlers.push(hookHandler);
|
|
5827
|
+
}
|
|
5828
|
+
}
|
|
5829
|
+
return () => {
|
|
5830
|
+
handlers.forEach((h) => h());
|
|
5831
|
+
};
|
|
5832
|
+
}
|
|
5833
|
+
|
|
5834
|
+
function initCanvasContextObserver(win, blockClass, blockSelector) {
|
|
5835
|
+
const handlers = [];
|
|
5836
|
+
try {
|
|
5837
|
+
const restoreHandler = patch(win.HTMLCanvasElement.prototype, 'getContext', function (original) {
|
|
5838
|
+
return function (contextType, ...args) {
|
|
5839
|
+
if (!isBlocked(this, blockClass, blockSelector, true)) {
|
|
5840
|
+
if (!('__context' in this))
|
|
5841
|
+
this.__context = contextType;
|
|
5842
|
+
}
|
|
5843
|
+
return original.apply(this, [contextType, ...args]);
|
|
5844
|
+
};
|
|
5845
|
+
});
|
|
5846
|
+
handlers.push(restoreHandler);
|
|
5847
|
+
}
|
|
5848
|
+
catch (_a) {
|
|
5849
|
+
console.error('failed to patch HTMLCanvasElement.prototype.getContext');
|
|
5850
|
+
}
|
|
5851
|
+
return () => {
|
|
5852
|
+
handlers.forEach((h) => h());
|
|
5853
|
+
};
|
|
5854
|
+
}
|
|
5855
|
+
|
|
5856
|
+
function patchGLPrototype(prototype, type, cb, blockClass, blockSelector, mirror, win) {
|
|
5857
|
+
const handlers = [];
|
|
5858
|
+
const props = Object.getOwnPropertyNames(prototype);
|
|
5859
|
+
for (const prop of props) {
|
|
5860
|
+
if ([
|
|
5861
|
+
'isContextLost',
|
|
5862
|
+
'canvas',
|
|
5863
|
+
'drawingBufferWidth',
|
|
5864
|
+
'drawingBufferHeight',
|
|
5865
|
+
].includes(prop)) {
|
|
5866
|
+
continue;
|
|
5867
|
+
}
|
|
5868
|
+
try {
|
|
5869
|
+
if (typeof prototype[prop] !== 'function') {
|
|
5870
|
+
continue;
|
|
5871
|
+
}
|
|
5872
|
+
const restoreHandler = patch(prototype, prop, function (original) {
|
|
5873
|
+
return function (...args) {
|
|
5874
|
+
const result = original.apply(this, args);
|
|
5875
|
+
saveWebGLVar(result, win, this);
|
|
5876
|
+
if (!isBlocked(this.canvas, blockClass, blockSelector, true)) {
|
|
5877
|
+
const recordArgs = serializeArgs([...args], win, this);
|
|
5878
|
+
const mutation = {
|
|
5879
|
+
type,
|
|
5880
|
+
property: prop,
|
|
5881
|
+
args: recordArgs,
|
|
5882
|
+
};
|
|
5883
|
+
cb(this.canvas, mutation);
|
|
5884
|
+
}
|
|
5885
|
+
return result;
|
|
5886
|
+
};
|
|
5887
|
+
});
|
|
5888
|
+
handlers.push(restoreHandler);
|
|
5889
|
+
}
|
|
5890
|
+
catch (_a) {
|
|
5891
|
+
const hookHandler = hookSetter(prototype, prop, {
|
|
5892
|
+
set(v) {
|
|
5893
|
+
cb(this.canvas, {
|
|
5894
|
+
type,
|
|
5895
|
+
property: prop,
|
|
5896
|
+
args: [v],
|
|
5897
|
+
setter: true,
|
|
5898
|
+
});
|
|
5899
|
+
},
|
|
5900
|
+
});
|
|
5901
|
+
handlers.push(hookHandler);
|
|
5902
|
+
}
|
|
5903
|
+
}
|
|
5904
|
+
return handlers;
|
|
5905
|
+
}
|
|
5906
|
+
function initCanvasWebGLMutationObserver(cb, win, blockClass, blockSelector, mirror) {
|
|
5907
|
+
const handlers = [];
|
|
5908
|
+
handlers.push(...patchGLPrototype(win.WebGLRenderingContext.prototype, CanvasContext.WebGL, cb, blockClass, blockSelector, mirror, win));
|
|
5909
|
+
if (typeof win.WebGL2RenderingContext !== 'undefined') {
|
|
5910
|
+
handlers.push(...patchGLPrototype(win.WebGL2RenderingContext.prototype, CanvasContext.WebGL2, cb, blockClass, blockSelector, mirror, win));
|
|
5911
|
+
}
|
|
5912
|
+
return () => {
|
|
5913
|
+
handlers.forEach((h) => h());
|
|
5914
|
+
};
|
|
5915
|
+
}
|
|
5916
|
+
|
|
5917
|
+
var WorkerClass = null;
|
|
5918
|
+
|
|
5919
|
+
try {
|
|
5920
|
+
var WorkerThreads =
|
|
5921
|
+
typeof module !== 'undefined' && typeof module.require === 'function' && module.require('worker_threads') ||
|
|
5922
|
+
typeof __non_webpack_require__ === 'function' && __non_webpack_require__('worker_threads') ||
|
|
5923
|
+
typeof require === 'function' && require('worker_threads');
|
|
5924
|
+
WorkerClass = WorkerThreads.Worker;
|
|
5925
|
+
} catch(e) {} // eslint-disable-line
|
|
5926
|
+
|
|
5927
|
+
function decodeBase64$1(base64, enableUnicode) {
|
|
5928
|
+
return Buffer.from(base64, 'base64').toString('utf8');
|
|
5929
|
+
}
|
|
5930
|
+
|
|
5931
|
+
function createBase64WorkerFactory$2(base64, sourcemapArg, enableUnicodeArg) {
|
|
5932
|
+
var source = decodeBase64$1(base64);
|
|
5933
|
+
var start = source.indexOf('\n', 10) + 1;
|
|
5934
|
+
var body = source.substring(start) + ('');
|
|
5935
|
+
return function WorkerFactory(options) {
|
|
5936
|
+
return new WorkerClass(body, Object.assign({}, options, { eval: true }));
|
|
5937
|
+
};
|
|
5938
|
+
}
|
|
5939
|
+
|
|
5940
|
+
function decodeBase64(base64, enableUnicode) {
|
|
5941
|
+
var binaryString = atob(base64);
|
|
5942
|
+
return binaryString;
|
|
5943
|
+
}
|
|
5944
|
+
|
|
5945
|
+
function createURL(base64, sourcemapArg, enableUnicodeArg) {
|
|
5946
|
+
var source = decodeBase64(base64);
|
|
5947
|
+
var start = source.indexOf('\n', 10) + 1;
|
|
5948
|
+
var body = source.substring(start) + ('');
|
|
5949
|
+
var blob = new Blob([body], { type: 'application/javascript' });
|
|
5950
|
+
return URL.createObjectURL(blob);
|
|
5951
|
+
}
|
|
5952
|
+
|
|
5953
|
+
function createBase64WorkerFactory$1(base64, sourcemapArg, enableUnicodeArg) {
|
|
5954
|
+
var url;
|
|
5955
|
+
return function WorkerFactory(options) {
|
|
5956
|
+
url = url || createURL(base64);
|
|
5957
|
+
return new Worker(url, options);
|
|
5958
|
+
};
|
|
5959
|
+
}
|
|
5960
|
+
|
|
5961
|
+
var kIsNodeJS = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
|
|
5962
|
+
|
|
5963
|
+
function isNodeJS() {
|
|
5964
|
+
return kIsNodeJS;
|
|
5965
|
+
}
|
|
5966
|
+
|
|
5967
|
+
function createBase64WorkerFactory(base64, sourcemapArg, enableUnicodeArg) {
|
|
5968
|
+
if (isNodeJS()) {
|
|
5969
|
+
return createBase64WorkerFactory$2(base64);
|
|
5970
|
+
}
|
|
5971
|
+
return createBase64WorkerFactory$1(base64);
|
|
5972
|
+
}
|
|
5973
|
+
|
|
5974
|
+
var WorkerFactory = createBase64WorkerFactory('Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwooZnVuY3Rpb24gKCkgewogICAgJ3VzZSBzdHJpY3QnOwoKICAgIC8qISAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKg0KICAgIENvcHlyaWdodCAoYykgTWljcm9zb2Z0IENvcnBvcmF0aW9uLg0KDQogICAgUGVybWlzc2lvbiB0byB1c2UsIGNvcHksIG1vZGlmeSwgYW5kL29yIGRpc3RyaWJ1dGUgdGhpcyBzb2Z0d2FyZSBmb3IgYW55DQogICAgcHVycG9zZSB3aXRoIG9yIHdpdGhvdXQgZmVlIGlzIGhlcmVieSBncmFudGVkLg0KDQogICAgVEhFIFNPRlRXQVJFIElTIFBST1ZJREVEICJBUyBJUyIgQU5EIFRIRSBBVVRIT1IgRElTQ0xBSU1TIEFMTCBXQVJSQU5USUVTIFdJVEgNCiAgICBSRUdBUkQgVE8gVEhJUyBTT0ZUV0FSRSBJTkNMVURJTkcgQUxMIElNUExJRUQgV0FSUkFOVElFUyBPRiBNRVJDSEFOVEFCSUxJVFkNCiAgICBBTkQgRklUTkVTUy4gSU4gTk8gRVZFTlQgU0hBTEwgVEhFIEFVVEhPUiBCRSBMSUFCTEUgRk9SIEFOWSBTUEVDSUFMLCBESVJFQ1QsDQogICAgSU5ESVJFQ1QsIE9SIENPTlNFUVVFTlRJQUwgREFNQUdFUyBPUiBBTlkgREFNQUdFUyBXSEFUU09FVkVSIFJFU1VMVElORyBGUk9NDQogICAgTE9TUyBPRiBVU0UsIERBVEEgT1IgUFJPRklUUywgV0hFVEhFUiBJTiBBTiBBQ1RJT04gT0YgQ09OVFJBQ1QsIE5FR0xJR0VOQ0UgT1INCiAgICBPVEhFUiBUT1JUSU9VUyBBQ1RJT04sIEFSSVNJTkcgT1VUIE9GIE9SIElOIENPTk5FQ1RJT04gV0lUSCBUSEUgVVNFIE9SDQogICAgUEVSRk9STUFOQ0UgT0YgVEhJUyBTT0ZUV0FSRS4NCiAgICAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiAqLw0KDQogICAgZnVuY3Rpb24gX19hd2FpdGVyKHRoaXNBcmcsIF9hcmd1bWVudHMsIFAsIGdlbmVyYXRvcikgew0KICAgICAgICBmdW5jdGlvbiBhZG9wdCh2YWx1ZSkgeyByZXR1cm4gdmFsdWUgaW5zdGFuY2VvZiBQID8gdmFsdWUgOiBuZXcgUChmdW5jdGlvbiAocmVzb2x2ZSkgeyByZXNvbHZlKHZhbHVlKTsgfSk7IH0NCiAgICAgICAgcmV0dXJuIG5ldyAoUCB8fCAoUCA9IFByb21pc2UpKShmdW5jdGlvbiAocmVzb2x2ZSwgcmVqZWN0KSB7DQogICAgICAgICAgICBmdW5jdGlvbiBmdWxmaWxsZWQodmFsdWUpIHsgdHJ5IHsgc3RlcChnZW5lcmF0b3IubmV4dCh2YWx1ZSkpOyB9IGNhdGNoIChlKSB7IHJlamVjdChlKTsgfSB9DQogICAgICAgICAgICBmdW5jdGlvbiByZWplY3RlZCh2YWx1ZSkgeyB0cnkgeyBzdGVwKGdlbmVyYXRvclsidGhyb3ciXSh2YWx1ZSkpOyB9IGNhdGNoIChlKSB7IHJlamVjdChlKTsgfSB9DQogICAgICAgICAgICBmdW5jdGlvbiBzdGVwKHJlc3VsdCkgeyByZXN1bHQuZG9uZSA/IHJlc29sdmUocmVzdWx0LnZhbHVlKSA6IGFkb3B0KHJlc3VsdC52YWx1ZSkudGhlbihmdWxmaWxsZWQsIHJlamVjdGVkKTsgfQ0KICAgICAgICAgICAgc3RlcCgoZ2VuZXJhdG9yID0gZ2VuZXJhdG9yLmFwcGx5KHRoaXNBcmcsIF9hcmd1bWVudHMgfHwgW10pKS5uZXh0KCkpOw0KICAgICAgICB9KTsNCiAgICB9CgogICAgLyoKICAgICAqIGJhc2U2NC1hcnJheWJ1ZmZlciAxLjAuMSA8aHR0cHM6Ly9naXRodWIuY29tL25pa2xhc3ZoL2Jhc2U2NC1hcnJheWJ1ZmZlcj4KICAgICAqIENvcHlyaWdodCAoYykgMjAyMSBOaWtsYXMgdm9uIEhlcnR6ZW4gPGh0dHBzOi8vaGVydHplbi5jb20+CiAgICAgKiBSZWxlYXNlZCB1bmRlciBNSVQgTGljZW5zZQogICAgICovCiAgICB2YXIgY2hhcnMgPSAnQUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ejAxMjM0NTY3ODkrLyc7CiAgICAvLyBVc2UgYSBsb29rdXAgdGFibGUgdG8gZmluZCB0aGUgaW5kZXguCiAgICB2YXIgbG9va3VwID0gdHlwZW9mIFVpbnQ4QXJyYXkgPT09ICd1bmRlZmluZWQnID8gW10gOiBuZXcgVWludDhBcnJheSgyNTYpOwogICAgZm9yICh2YXIgaSA9IDA7IGkgPCBjaGFycy5sZW5ndGg7IGkrKykgewogICAgICAgIGxvb2t1cFtjaGFycy5jaGFyQ29kZUF0KGkpXSA9IGk7CiAgICB9CiAgICB2YXIgZW5jb2RlID0gZnVuY3Rpb24gKGFycmF5YnVmZmVyKSB7CiAgICAgICAgdmFyIGJ5dGVzID0gbmV3IFVpbnQ4QXJyYXkoYXJyYXlidWZmZXIpLCBpLCBsZW4gPSBieXRlcy5sZW5ndGgsIGJhc2U2NCA9ICcnOwogICAgICAgIGZvciAoaSA9IDA7IGkgPCBsZW47IGkgKz0gMykgewogICAgICAgICAgICBiYXNlNjQgKz0gY2hhcnNbYnl0ZXNbaV0gPj4gMl07CiAgICAgICAgICAgIGJhc2U2NCArPSBjaGFyc1soKGJ5dGVzW2ldICYgMykgPDwgNCkgfCAoYnl0ZXNbaSArIDFdID4+IDQpXTsKICAgICAgICAgICAgYmFzZTY0ICs9IGNoYXJzWygoYnl0ZXNbaSArIDFdICYgMTUpIDw8IDIpIHwgKGJ5dGVzW2kgKyAyXSA+PiA2KV07CiAgICAgICAgICAgIGJhc2U2NCArPSBjaGFyc1tieXRlc1tpICsgMl0gJiA2M107CiAgICAgICAgfQogICAgICAgIGlmIChsZW4gJSAzID09PSAyKSB7CiAgICAgICAgICAgIGJhc2U2NCA9IGJhc2U2NC5zdWJzdHJpbmcoMCwgYmFzZTY0Lmxlbmd0aCAtIDEpICsgJz0nOwogICAgICAgIH0KICAgICAgICBlbHNlIGlmIChsZW4gJSAzID09PSAxKSB7CiAgICAgICAgICAgIGJhc2U2NCA9IGJhc2U2NC5zdWJzdHJpbmcoMCwgYmFzZTY0Lmxlbmd0aCAtIDIpICsgJz09JzsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJhc2U2NDsKICAgIH07CgogICAgY29uc3QgbGFzdEJsb2JNYXAgPSBuZXcgTWFwKCk7DQogICAgY29uc3QgdHJhbnNwYXJlbnRCbG9iTWFwID0gbmV3IE1hcCgpOw0KICAgIGZ1bmN0aW9uIGdldFRyYW5zcGFyZW50QmxvYkZvcih3aWR0aCwgaGVpZ2h0LCBkYXRhVVJMT3B0aW9ucykgew0KICAgICAgICByZXR1cm4gX19hd2FpdGVyKHRoaXMsIHZvaWQgMCwgdm9pZCAwLCBmdW5jdGlvbiogKCkgew0KICAgICAgICAgICAgY29uc3QgaWQgPSBgJHt3aWR0aH0tJHtoZWlnaHR9YDsNCiAgICAgICAgICAgIGlmICgnT2Zmc2NyZWVuQ2FudmFzJyBpbiBnbG9iYWxUaGlzKSB7DQogICAgICAgICAgICAgICAgaWYgKHRyYW5zcGFyZW50QmxvYk1hcC5oYXMoaWQpKQ0KICAgICAgICAgICAgICAgICAgICByZXR1cm4gdHJhbnNwYXJlbnRCbG9iTWFwLmdldChpZCk7DQogICAgICAgICAgICAgICAgY29uc3Qgb2Zmc2NyZWVuID0gbmV3IE9mZnNjcmVlbkNhbnZhcyh3aWR0aCwgaGVpZ2h0KTsNCiAgICAgICAgICAgICAgICBvZmZzY3JlZW4uZ2V0Q29udGV4dCgnMmQnKTsNCiAgICAgICAgICAgICAgICBjb25zdCBibG9iID0geWllbGQgb2Zmc2NyZWVuLmNvbnZlcnRUb0Jsb2IoZGF0YVVSTE9wdGlvbnMpOw0KICAgICAgICAgICAgICAgIGNvbnN0IGFycmF5QnVmZmVyID0geWllbGQgYmxvYi5hcnJheUJ1ZmZlcigpOw0KICAgICAgICAgICAgICAgIGNvbnN0IGJhc2U2NCA9IGVuY29kZShhcnJheUJ1ZmZlcik7DQogICAgICAgICAgICAgICAgdHJhbnNwYXJlbnRCbG9iTWFwLnNldChpZCwgYmFzZTY0KTsNCiAgICAgICAgICAgICAgICByZXR1cm4gYmFzZTY0Ow0KICAgICAgICAgICAgfQ0KICAgICAgICAgICAgZWxzZSB7DQogICAgICAgICAgICAgICAgcmV0dXJuICcnOw0KICAgICAgICAgICAgfQ0KICAgICAgICB9KTsNCiAgICB9DQogICAgY29uc3Qgd29ya2VyID0gc2VsZjsNCiAgICB3b3JrZXIub25tZXNzYWdlID0gZnVuY3Rpb24gKGUpIHsNCiAgICAgICAgcmV0dXJuIF9fYXdhaXRlcih0aGlzLCB2b2lkIDAsIHZvaWQgMCwgZnVuY3Rpb24qICgpIHsNCiAgICAgICAgICAgIGlmICgnT2Zmc2NyZWVuQ2FudmFzJyBpbiBnbG9iYWxUaGlzKSB7DQogICAgICAgICAgICAgICAgY29uc3QgeyBpZCwgYml0bWFwLCB3aWR0aCwgaGVpZ2h0LCBkYXRhVVJMT3B0aW9ucyB9ID0gZS5kYXRhOw0KICAgICAgICAgICAgICAgIGNvbnN0IHRyYW5zcGFyZW50QmFzZTY0ID0gZ2V0VHJhbnNwYXJlbnRCbG9iRm9yKHdpZHRoLCBoZWlnaHQsIGRhdGFVUkxPcHRpb25zKTsNCiAgICAgICAgICAgICAgICBjb25zdCBvZmZzY3JlZW4gPSBuZXcgT2Zmc2NyZWVuQ2FudmFzKHdpZHRoLCBoZWlnaHQpOw0KICAgICAgICAgICAgICAgIGNvbnN0IGN0eCA9IG9mZnNjcmVlbi5nZXRDb250ZXh0KCcyZCcpOw0KICAgICAgICAgICAgICAgIGN0eC5kcmF3SW1hZ2UoYml0bWFwLCAwLCAwKTsNCiAgICAgICAgICAgICAgICBiaXRtYXAuY2xvc2UoKTsNCiAgICAgICAgICAgICAgICBjb25zdCBibG9iID0geWllbGQgb2Zmc2NyZWVuLmNvbnZlcnRUb0Jsb2IoZGF0YVVSTE9wdGlvbnMpOw0KICAgICAgICAgICAgICAgIGNvbnN0IHR5cGUgPSBibG9iLnR5cGU7DQogICAgICAgICAgICAgICAgY29uc3QgYXJyYXlCdWZmZXIgPSB5aWVsZCBibG9iLmFycmF5QnVmZmVyKCk7DQogICAgICAgICAgICAgICAgY29uc3QgYmFzZTY0ID0gZW5jb2RlKGFycmF5QnVmZmVyKTsNCiAgICAgICAgICAgICAgICBpZiAoIWxhc3RCbG9iTWFwLmhhcyhpZCkgJiYgKHlpZWxkIHRyYW5zcGFyZW50QmFzZTY0KSA9PT0gYmFzZTY0KSB7DQogICAgICAgICAgICAgICAgICAgIGxhc3RCbG9iTWFwLnNldChpZCwgYmFzZTY0KTsNCiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHdvcmtlci5wb3N0TWVzc2FnZSh7IGlkIH0pOw0KICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICBpZiAobGFzdEJsb2JNYXAuZ2V0KGlkKSA9PT0gYmFzZTY0KQ0KICAgICAgICAgICAgICAgICAgICByZXR1cm4gd29ya2VyLnBvc3RNZXNzYWdlKHsgaWQgfSk7DQogICAgICAgICAgICAgICAgd29ya2VyLnBvc3RNZXNzYWdlKHsNCiAgICAgICAgICAgICAgICAgICAgaWQsDQogICAgICAgICAgICAgICAgICAgIHR5cGUsDQogICAgICAgICAgICAgICAgICAgIGJhc2U2NCwNCiAgICAgICAgICAgICAgICAgICAgd2lkdGgsDQogICAgICAgICAgICAgICAgICAgIGhlaWdodCwNCiAgICAgICAgICAgICAgICB9KTsNCiAgICAgICAgICAgICAgICBsYXN0QmxvYk1hcC5zZXQoaWQsIGJhc2U2NCk7DQogICAgICAgICAgICB9DQogICAgICAgICAgICBlbHNlIHsNCiAgICAgICAgICAgICAgICByZXR1cm4gd29ya2VyLnBvc3RNZXNzYWdlKHsgaWQ6IGUuZGF0YS5pZCB9KTsNCiAgICAgICAgICAgIH0NCiAgICAgICAgfSk7DQogICAgfTsKCn0pKCk7Cgo=');
|
|
5975
|
+
|
|
5976
|
+
class CanvasManager {
|
|
5977
|
+
constructor(options) {
|
|
5978
|
+
this.pendingCanvasMutations = new Map();
|
|
5979
|
+
this.rafStamps = { latestId: 0, invokeId: null };
|
|
5980
|
+
this.frozen = false;
|
|
5981
|
+
this.locked = false;
|
|
5982
|
+
this.processMutation = (target, mutation) => {
|
|
5983
|
+
const newFrame = this.rafStamps.invokeId &&
|
|
5984
|
+
this.rafStamps.latestId !== this.rafStamps.invokeId;
|
|
5985
|
+
if (newFrame || !this.rafStamps.invokeId)
|
|
5986
|
+
this.rafStamps.invokeId = this.rafStamps.latestId;
|
|
5987
|
+
if (!this.pendingCanvasMutations.has(target)) {
|
|
5988
|
+
this.pendingCanvasMutations.set(target, []);
|
|
5989
|
+
}
|
|
5990
|
+
this.pendingCanvasMutations.get(target).push(mutation);
|
|
5991
|
+
};
|
|
5992
|
+
const { sampling = 'all', win, blockClass, blockSelector, recordCanvas, dataURLOptions, } = options;
|
|
5993
|
+
this.mutationCb = options.mutationCb;
|
|
5994
|
+
this.mirror = options.mirror;
|
|
5995
|
+
if (recordCanvas && sampling === 'all')
|
|
5996
|
+
this.initCanvasMutationObserver(win, blockClass, blockSelector);
|
|
5997
|
+
if (recordCanvas && typeof sampling === 'number')
|
|
5998
|
+
this.initCanvasFPSObserver(sampling, win, blockClass, blockSelector, {
|
|
5999
|
+
dataURLOptions,
|
|
6000
|
+
});
|
|
6001
|
+
}
|
|
6002
|
+
reset() {
|
|
6003
|
+
this.pendingCanvasMutations.clear();
|
|
6004
|
+
this.resetObservers && this.resetObservers();
|
|
6005
|
+
}
|
|
6006
|
+
freeze() {
|
|
6007
|
+
this.frozen = true;
|
|
6008
|
+
}
|
|
6009
|
+
unfreeze() {
|
|
6010
|
+
this.frozen = false;
|
|
6011
|
+
}
|
|
6012
|
+
lock() {
|
|
6013
|
+
this.locked = true;
|
|
6014
|
+
}
|
|
6015
|
+
unlock() {
|
|
6016
|
+
this.locked = false;
|
|
6017
|
+
}
|
|
6018
|
+
initCanvasFPSObserver(fps, win, blockClass, blockSelector, options) {
|
|
6019
|
+
const canvasContextReset = initCanvasContextObserver(win, blockClass, blockSelector);
|
|
6020
|
+
const snapshotInProgressMap = new Map();
|
|
6021
|
+
const worker = new WorkerFactory();
|
|
6022
|
+
worker.onmessage = (e) => {
|
|
6023
|
+
const { id } = e.data;
|
|
6024
|
+
snapshotInProgressMap.set(id, false);
|
|
6025
|
+
if (!('base64' in e.data))
|
|
6026
|
+
return;
|
|
6027
|
+
const { base64, type, width, height } = e.data;
|
|
6028
|
+
this.mutationCb({
|
|
6029
|
+
id,
|
|
6030
|
+
type: CanvasContext['2D'],
|
|
6031
|
+
commands: [
|
|
6032
|
+
{
|
|
6033
|
+
property: 'clearRect',
|
|
6034
|
+
args: [0, 0, width, height],
|
|
6035
|
+
},
|
|
6036
|
+
{
|
|
6037
|
+
property: 'drawImage',
|
|
6038
|
+
args: [
|
|
6039
|
+
{
|
|
6040
|
+
rr_type: 'ImageBitmap',
|
|
6041
|
+
args: [
|
|
6042
|
+
{
|
|
6043
|
+
rr_type: 'Blob',
|
|
6044
|
+
data: [{ rr_type: 'ArrayBuffer', base64 }],
|
|
6045
|
+
type,
|
|
6046
|
+
},
|
|
6047
|
+
],
|
|
6048
|
+
},
|
|
6049
|
+
0,
|
|
6050
|
+
0,
|
|
6051
|
+
],
|
|
6052
|
+
},
|
|
6053
|
+
],
|
|
6054
|
+
});
|
|
6055
|
+
};
|
|
6056
|
+
const timeBetweenSnapshots = 1000 / fps;
|
|
6057
|
+
let lastSnapshotTime = 0;
|
|
6058
|
+
let rafId;
|
|
6059
|
+
const getCanvas = () => {
|
|
6060
|
+
const matchedCanvas = [];
|
|
6061
|
+
win.document.querySelectorAll('canvas').forEach((canvas) => {
|
|
6062
|
+
if (!isBlocked(canvas, blockClass, blockSelector, true)) {
|
|
6063
|
+
matchedCanvas.push(canvas);
|
|
6064
|
+
}
|
|
6065
|
+
});
|
|
6066
|
+
return matchedCanvas;
|
|
6067
|
+
};
|
|
6068
|
+
const takeCanvasSnapshots = (timestamp) => {
|
|
6069
|
+
if (lastSnapshotTime &&
|
|
6070
|
+
timestamp - lastSnapshotTime < timeBetweenSnapshots) {
|
|
6071
|
+
rafId = requestAnimationFrame(takeCanvasSnapshots);
|
|
6072
|
+
return;
|
|
6073
|
+
}
|
|
6074
|
+
lastSnapshotTime = timestamp;
|
|
6075
|
+
getCanvas()
|
|
6076
|
+
.forEach((canvas) => __awaiter(this, void 0, void 0, function* () {
|
|
6077
|
+
var _a;
|
|
6078
|
+
const id = this.mirror.getId(canvas);
|
|
6079
|
+
if (snapshotInProgressMap.get(id))
|
|
6080
|
+
return;
|
|
6081
|
+
snapshotInProgressMap.set(id, true);
|
|
6082
|
+
if (['webgl', 'webgl2'].includes(canvas.__context)) {
|
|
6083
|
+
const context = canvas.getContext(canvas.__context);
|
|
6084
|
+
if (((_a = context === null || context === void 0 ? void 0 : context.getContextAttributes()) === null || _a === void 0 ? void 0 : _a.preserveDrawingBuffer) === false) {
|
|
6085
|
+
context === null || context === void 0 ? void 0 : context.clear(context.COLOR_BUFFER_BIT);
|
|
6086
|
+
}
|
|
6087
|
+
}
|
|
6088
|
+
const bitmap = yield createImageBitmap(canvas);
|
|
6089
|
+
worker.postMessage({
|
|
6090
|
+
id,
|
|
6091
|
+
bitmap,
|
|
6092
|
+
width: canvas.width,
|
|
6093
|
+
height: canvas.height,
|
|
6094
|
+
dataURLOptions: options.dataURLOptions,
|
|
6095
|
+
}, [bitmap]);
|
|
6096
|
+
}));
|
|
6097
|
+
rafId = requestAnimationFrame(takeCanvasSnapshots);
|
|
6098
|
+
};
|
|
6099
|
+
rafId = requestAnimationFrame(takeCanvasSnapshots);
|
|
6100
|
+
this.resetObservers = () => {
|
|
6101
|
+
canvasContextReset();
|
|
6102
|
+
cancelAnimationFrame(rafId);
|
|
6103
|
+
};
|
|
6104
|
+
}
|
|
6105
|
+
initCanvasMutationObserver(win, blockClass, blockSelector) {
|
|
6106
|
+
this.startRAFTimestamping();
|
|
6107
|
+
this.startPendingCanvasMutationFlusher();
|
|
6108
|
+
const canvasContextReset = initCanvasContextObserver(win, blockClass, blockSelector);
|
|
6109
|
+
const canvas2DReset = initCanvas2DMutationObserver(this.processMutation.bind(this), win, blockClass, blockSelector);
|
|
6110
|
+
const canvasWebGL1and2Reset = initCanvasWebGLMutationObserver(this.processMutation.bind(this), win, blockClass, blockSelector, this.mirror);
|
|
6111
|
+
this.resetObservers = () => {
|
|
6112
|
+
canvasContextReset();
|
|
6113
|
+
canvas2DReset();
|
|
6114
|
+
canvasWebGL1and2Reset();
|
|
6115
|
+
};
|
|
6116
|
+
}
|
|
6117
|
+
startPendingCanvasMutationFlusher() {
|
|
6118
|
+
requestAnimationFrame(() => this.flushPendingCanvasMutations());
|
|
6119
|
+
}
|
|
6120
|
+
startRAFTimestamping() {
|
|
6121
|
+
const setLatestRAFTimestamp = (timestamp) => {
|
|
6122
|
+
this.rafStamps.latestId = timestamp;
|
|
6123
|
+
requestAnimationFrame(setLatestRAFTimestamp);
|
|
6124
|
+
};
|
|
6125
|
+
requestAnimationFrame(setLatestRAFTimestamp);
|
|
6126
|
+
}
|
|
6127
|
+
flushPendingCanvasMutations() {
|
|
6128
|
+
this.pendingCanvasMutations.forEach((values, canvas) => {
|
|
6129
|
+
const id = this.mirror.getId(canvas);
|
|
6130
|
+
this.flushPendingCanvasMutationFor(canvas, id);
|
|
6131
|
+
});
|
|
6132
|
+
requestAnimationFrame(() => this.flushPendingCanvasMutations());
|
|
6133
|
+
}
|
|
6134
|
+
flushPendingCanvasMutationFor(canvas, id) {
|
|
6135
|
+
if (this.frozen || this.locked) {
|
|
6136
|
+
return;
|
|
6137
|
+
}
|
|
6138
|
+
const valuesWithType = this.pendingCanvasMutations.get(canvas);
|
|
6139
|
+
if (!valuesWithType || id === -1)
|
|
6140
|
+
return;
|
|
6141
|
+
const values = valuesWithType.map((value) => {
|
|
6142
|
+
const rest = __rest(value, ["type"]);
|
|
6143
|
+
return rest;
|
|
6144
|
+
});
|
|
6145
|
+
const { type } = valuesWithType[0];
|
|
6146
|
+
this.mutationCb({ id, type, commands: values });
|
|
6147
|
+
this.pendingCanvasMutations.delete(canvas);
|
|
6148
|
+
}
|
|
6149
|
+
}
|
|
6150
|
+
|
|
6151
|
+
class StylesheetManager {
|
|
6152
|
+
constructor(options) {
|
|
6153
|
+
this.trackedLinkElements = new WeakSet();
|
|
6154
|
+
this.styleMirror = new StyleSheetMirror();
|
|
6155
|
+
this.mutationCb = options.mutationCb;
|
|
6156
|
+
this.adoptedStyleSheetCb = options.adoptedStyleSheetCb;
|
|
6157
|
+
}
|
|
6158
|
+
attachLinkElement(linkEl, childSn) {
|
|
6159
|
+
if ('_cssText' in childSn.attributes)
|
|
6160
|
+
this.mutationCb({
|
|
6161
|
+
adds: [],
|
|
6162
|
+
removes: [],
|
|
6163
|
+
texts: [],
|
|
6164
|
+
attributes: [
|
|
6165
|
+
{
|
|
6166
|
+
id: childSn.id,
|
|
6167
|
+
attributes: childSn
|
|
6168
|
+
.attributes,
|
|
6169
|
+
},
|
|
6170
|
+
],
|
|
6171
|
+
});
|
|
6172
|
+
this.trackLinkElement(linkEl);
|
|
6173
|
+
}
|
|
6174
|
+
trackLinkElement(linkEl) {
|
|
6175
|
+
if (this.trackedLinkElements.has(linkEl))
|
|
6176
|
+
return;
|
|
6177
|
+
this.trackedLinkElements.add(linkEl);
|
|
6178
|
+
this.trackStylesheetInLinkElement(linkEl);
|
|
6179
|
+
}
|
|
6180
|
+
adoptStyleSheets(sheets, hostId) {
|
|
6181
|
+
if (sheets.length === 0)
|
|
6182
|
+
return;
|
|
6183
|
+
const adoptedStyleSheetData = {
|
|
6184
|
+
id: hostId,
|
|
6185
|
+
styleIds: [],
|
|
6186
|
+
};
|
|
6187
|
+
const styles = [];
|
|
6188
|
+
for (const sheet of sheets) {
|
|
6189
|
+
let styleId;
|
|
6190
|
+
if (!this.styleMirror.has(sheet)) {
|
|
6191
|
+
styleId = this.styleMirror.add(sheet);
|
|
6192
|
+
const rules = Array.from(sheet.rules || CSSRule);
|
|
6193
|
+
styles.push({
|
|
6194
|
+
styleId,
|
|
6195
|
+
rules: rules.map((r, index) => {
|
|
6196
|
+
return {
|
|
6197
|
+
rule: getCssRuleString(r),
|
|
6198
|
+
index,
|
|
6199
|
+
};
|
|
6200
|
+
}),
|
|
6201
|
+
});
|
|
6202
|
+
}
|
|
6203
|
+
else
|
|
6204
|
+
styleId = this.styleMirror.getId(sheet);
|
|
6205
|
+
adoptedStyleSheetData.styleIds.push(styleId);
|
|
6206
|
+
}
|
|
6207
|
+
if (styles.length > 0)
|
|
6208
|
+
adoptedStyleSheetData.styles = styles;
|
|
6209
|
+
this.adoptedStyleSheetCb(adoptedStyleSheetData);
|
|
6210
|
+
}
|
|
6211
|
+
reset() {
|
|
6212
|
+
this.styleMirror.reset();
|
|
6213
|
+
this.trackedLinkElements = new WeakSet();
|
|
6214
|
+
}
|
|
6215
|
+
trackStylesheetInLinkElement(linkEl) {
|
|
6216
|
+
}
|
|
6217
|
+
}
|
|
6218
|
+
|
|
6219
|
+
function wrapEvent(e) {
|
|
6220
|
+
return Object.assign(Object.assign({}, e), { timestamp: Date.now() });
|
|
6221
|
+
}
|
|
6222
|
+
let wrappedEmit;
|
|
6223
|
+
let takeFullSnapshot;
|
|
6224
|
+
let canvasManager;
|
|
6225
|
+
let recording = false;
|
|
6226
|
+
const mirror = createMirror();
|
|
6227
|
+
function record(options = {}) {
|
|
6228
|
+
const { emit, checkoutEveryNms, checkoutEveryNth, blockClass = 'rr-block', blockSelector = null, ignoreClass = 'rr-ignore', maskTextClass = 'rr-mask', maskTextSelector = null, inlineStylesheet = true, maskAllInputs, maskInputOptions: _maskInputOptions, slimDOMOptions: _slimDOMOptions, maskInputFn, maskTextFn, hooks, packFn, sampling = {}, dataURLOptions = {}, mousemoveWait, recordCanvas = false, recordCrossOriginIframes = false, userTriggeredOnInput = false, collectFonts = false, inlineImages = false, plugins, keepIframeSrcFn = () => false, ignoreCSSAttributes = new Set([]), } = options;
|
|
6229
|
+
const inEmittingFrame = recordCrossOriginIframes
|
|
6230
|
+
? window.parent === window
|
|
6231
|
+
: true;
|
|
6232
|
+
let passEmitsToParent = false;
|
|
6233
|
+
if (!inEmittingFrame) {
|
|
6234
|
+
try {
|
|
6235
|
+
window.parent.document;
|
|
6236
|
+
passEmitsToParent = false;
|
|
6237
|
+
}
|
|
6238
|
+
catch (e) {
|
|
6239
|
+
passEmitsToParent = true;
|
|
6240
|
+
}
|
|
6241
|
+
}
|
|
6242
|
+
if (inEmittingFrame && !emit) {
|
|
6243
|
+
throw new Error('emit function is required');
|
|
6244
|
+
}
|
|
6245
|
+
if (mousemoveWait !== undefined && sampling.mousemove === undefined) {
|
|
6246
|
+
sampling.mousemove = mousemoveWait;
|
|
6247
|
+
}
|
|
6248
|
+
mirror.reset();
|
|
6249
|
+
const maskInputOptions = maskAllInputs === true
|
|
6250
|
+
? {
|
|
6251
|
+
color: true,
|
|
6252
|
+
date: true,
|
|
6253
|
+
'datetime-local': true,
|
|
6254
|
+
email: true,
|
|
6255
|
+
month: true,
|
|
6256
|
+
number: true,
|
|
6257
|
+
range: true,
|
|
6258
|
+
search: true,
|
|
6259
|
+
tel: true,
|
|
6260
|
+
text: true,
|
|
6261
|
+
time: true,
|
|
6262
|
+
url: true,
|
|
6263
|
+
week: true,
|
|
6264
|
+
textarea: true,
|
|
6265
|
+
select: true,
|
|
6266
|
+
password: true,
|
|
6267
|
+
}
|
|
6268
|
+
: _maskInputOptions !== undefined
|
|
6269
|
+
? _maskInputOptions
|
|
6270
|
+
: { password: true };
|
|
6271
|
+
const slimDOMOptions = _slimDOMOptions === true || _slimDOMOptions === 'all'
|
|
6272
|
+
? {
|
|
6273
|
+
script: true,
|
|
6274
|
+
comment: true,
|
|
6275
|
+
headFavicon: true,
|
|
6276
|
+
headWhitespace: true,
|
|
6277
|
+
headMetaSocial: true,
|
|
6278
|
+
headMetaRobots: true,
|
|
6279
|
+
headMetaHttpEquiv: true,
|
|
6280
|
+
headMetaVerification: true,
|
|
6281
|
+
headMetaAuthorship: _slimDOMOptions === 'all',
|
|
6282
|
+
headMetaDescKeywords: _slimDOMOptions === 'all',
|
|
6283
|
+
}
|
|
6284
|
+
: _slimDOMOptions
|
|
6285
|
+
? _slimDOMOptions
|
|
6286
|
+
: {};
|
|
6287
|
+
polyfill();
|
|
6288
|
+
let lastFullSnapshotEvent;
|
|
6289
|
+
let incrementalSnapshotCount = 0;
|
|
6290
|
+
const eventProcessor = (e) => {
|
|
6291
|
+
for (const plugin of plugins || []) {
|
|
6292
|
+
if (plugin.eventProcessor) {
|
|
6293
|
+
e = plugin.eventProcessor(e);
|
|
6294
|
+
}
|
|
6295
|
+
}
|
|
6296
|
+
if (packFn) {
|
|
6297
|
+
e = packFn(e);
|
|
6298
|
+
}
|
|
6299
|
+
return e;
|
|
6300
|
+
};
|
|
6301
|
+
wrappedEmit = (e, isCheckout) => {
|
|
6302
|
+
var _a;
|
|
6303
|
+
if (((_a = mutationBuffers[0]) === null || _a === void 0 ? void 0 : _a.isFrozen()) &&
|
|
6304
|
+
e.type !== EventType.FullSnapshot &&
|
|
6305
|
+
!(e.type === EventType.IncrementalSnapshot &&
|
|
6306
|
+
e.data.source === IncrementalSource.Mutation)) {
|
|
6307
|
+
mutationBuffers.forEach((buf) => buf.unfreeze());
|
|
6308
|
+
}
|
|
6309
|
+
if (inEmittingFrame) {
|
|
6310
|
+
emit === null || emit === void 0 ? void 0 : emit(eventProcessor(e), isCheckout);
|
|
6311
|
+
}
|
|
6312
|
+
else if (passEmitsToParent) {
|
|
6313
|
+
const message = {
|
|
6314
|
+
type: 'rrweb',
|
|
6315
|
+
event: eventProcessor(e),
|
|
6316
|
+
isCheckout,
|
|
6317
|
+
};
|
|
6318
|
+
window.parent.postMessage(message, '*');
|
|
6319
|
+
}
|
|
6320
|
+
if (e.type === EventType.FullSnapshot) {
|
|
6321
|
+
lastFullSnapshotEvent = e;
|
|
6322
|
+
incrementalSnapshotCount = 0;
|
|
6323
|
+
}
|
|
6324
|
+
else if (e.type === EventType.IncrementalSnapshot) {
|
|
6325
|
+
if (e.data.source === IncrementalSource.Mutation &&
|
|
6326
|
+
e.data.isAttachIframe) {
|
|
6327
|
+
return;
|
|
6328
|
+
}
|
|
6329
|
+
incrementalSnapshotCount++;
|
|
6330
|
+
const exceedCount = checkoutEveryNth && incrementalSnapshotCount >= checkoutEveryNth;
|
|
6331
|
+
const exceedTime = checkoutEveryNms &&
|
|
6332
|
+
e.timestamp - lastFullSnapshotEvent.timestamp > checkoutEveryNms;
|
|
6333
|
+
if (exceedCount || exceedTime) {
|
|
6334
|
+
takeFullSnapshot(true);
|
|
6335
|
+
}
|
|
6336
|
+
}
|
|
6337
|
+
};
|
|
6338
|
+
const wrappedMutationEmit = (m) => {
|
|
6339
|
+
wrappedEmit(wrapEvent({
|
|
6340
|
+
type: EventType.IncrementalSnapshot,
|
|
6341
|
+
data: Object.assign({ source: IncrementalSource.Mutation }, m),
|
|
6342
|
+
}));
|
|
6343
|
+
};
|
|
6344
|
+
const wrappedScrollEmit = (p) => wrappedEmit(wrapEvent({
|
|
6345
|
+
type: EventType.IncrementalSnapshot,
|
|
6346
|
+
data: Object.assign({ source: IncrementalSource.Scroll }, p),
|
|
6347
|
+
}));
|
|
6348
|
+
const wrappedCanvasMutationEmit = (p) => wrappedEmit(wrapEvent({
|
|
6349
|
+
type: EventType.IncrementalSnapshot,
|
|
6350
|
+
data: Object.assign({ source: IncrementalSource.CanvasMutation }, p),
|
|
6351
|
+
}));
|
|
6352
|
+
const wrappedAdoptedStyleSheetEmit = (a) => wrappedEmit(wrapEvent({
|
|
6353
|
+
type: EventType.IncrementalSnapshot,
|
|
6354
|
+
data: Object.assign({ source: IncrementalSource.AdoptedStyleSheet }, a),
|
|
6355
|
+
}));
|
|
6356
|
+
const stylesheetManager = new StylesheetManager({
|
|
6357
|
+
mutationCb: wrappedMutationEmit,
|
|
6358
|
+
adoptedStyleSheetCb: wrappedAdoptedStyleSheetEmit,
|
|
6359
|
+
});
|
|
6360
|
+
const iframeManager = new IframeManager({
|
|
6361
|
+
mirror,
|
|
6362
|
+
mutationCb: wrappedMutationEmit,
|
|
6363
|
+
stylesheetManager: stylesheetManager,
|
|
6364
|
+
recordCrossOriginIframes,
|
|
6365
|
+
wrappedEmit,
|
|
6366
|
+
});
|
|
6367
|
+
for (const plugin of plugins || []) {
|
|
6368
|
+
if (plugin.getMirror)
|
|
6369
|
+
plugin.getMirror({
|
|
6370
|
+
nodeMirror: mirror,
|
|
6371
|
+
crossOriginIframeMirror: iframeManager.crossOriginIframeMirror,
|
|
6372
|
+
crossOriginIframeStyleMirror: iframeManager.crossOriginIframeStyleMirror,
|
|
6373
|
+
});
|
|
6374
|
+
}
|
|
6375
|
+
canvasManager = new CanvasManager({
|
|
6376
|
+
recordCanvas,
|
|
6377
|
+
mutationCb: wrappedCanvasMutationEmit,
|
|
6378
|
+
win: window,
|
|
6379
|
+
blockClass,
|
|
6380
|
+
blockSelector,
|
|
6381
|
+
mirror,
|
|
6382
|
+
sampling: sampling.canvas,
|
|
6383
|
+
dataURLOptions,
|
|
6384
|
+
});
|
|
6385
|
+
const shadowDomManager = new ShadowDomManager({
|
|
6386
|
+
mutationCb: wrappedMutationEmit,
|
|
6387
|
+
scrollCb: wrappedScrollEmit,
|
|
6388
|
+
bypassOptions: {
|
|
6389
|
+
blockClass,
|
|
6390
|
+
blockSelector,
|
|
6391
|
+
maskTextClass,
|
|
6392
|
+
maskTextSelector,
|
|
6393
|
+
inlineStylesheet,
|
|
6394
|
+
maskInputOptions,
|
|
6395
|
+
dataURLOptions,
|
|
6396
|
+
maskTextFn,
|
|
6397
|
+
maskInputFn,
|
|
6398
|
+
recordCanvas,
|
|
6399
|
+
inlineImages,
|
|
6400
|
+
sampling,
|
|
6401
|
+
slimDOMOptions,
|
|
6402
|
+
iframeManager,
|
|
6403
|
+
stylesheetManager,
|
|
6404
|
+
canvasManager,
|
|
6405
|
+
keepIframeSrcFn,
|
|
6406
|
+
},
|
|
6407
|
+
mirror,
|
|
6408
|
+
});
|
|
6409
|
+
takeFullSnapshot = (isCheckout = false) => {
|
|
6410
|
+
var _a, _b, _c, _d, _e, _f;
|
|
6411
|
+
wrappedEmit(wrapEvent({
|
|
6412
|
+
type: EventType.Meta,
|
|
6413
|
+
data: {
|
|
6414
|
+
href: window.location.href,
|
|
6415
|
+
width: getWindowWidth(),
|
|
6416
|
+
height: getWindowHeight(),
|
|
6417
|
+
},
|
|
6418
|
+
}), isCheckout);
|
|
6419
|
+
stylesheetManager.reset();
|
|
6420
|
+
mutationBuffers.forEach((buf) => buf.lock());
|
|
6421
|
+
const node = snapshot(document, {
|
|
6422
|
+
mirror,
|
|
6423
|
+
blockClass,
|
|
6424
|
+
blockSelector,
|
|
6425
|
+
maskTextClass,
|
|
6426
|
+
maskTextSelector,
|
|
6427
|
+
inlineStylesheet,
|
|
6428
|
+
maskAllInputs: maskInputOptions,
|
|
6429
|
+
maskTextFn,
|
|
6430
|
+
slimDOM: slimDOMOptions,
|
|
6431
|
+
dataURLOptions,
|
|
6432
|
+
recordCanvas,
|
|
6433
|
+
inlineImages,
|
|
6434
|
+
onSerialize: (n) => {
|
|
6435
|
+
if (isSerializedIframe(n, mirror)) {
|
|
6436
|
+
iframeManager.addIframe(n);
|
|
6437
|
+
}
|
|
6438
|
+
if (isSerializedStylesheet(n, mirror)) {
|
|
6439
|
+
stylesheetManager.trackLinkElement(n);
|
|
6440
|
+
}
|
|
6441
|
+
if (hasShadowRoot(n)) {
|
|
6442
|
+
shadowDomManager.addShadowRoot(n.shadowRoot, document);
|
|
6443
|
+
}
|
|
6444
|
+
},
|
|
6445
|
+
onIframeLoad: (iframe, childSn) => {
|
|
6446
|
+
iframeManager.attachIframe(iframe, childSn);
|
|
6447
|
+
shadowDomManager.observeAttachShadow(iframe);
|
|
6448
|
+
},
|
|
6449
|
+
onStylesheetLoad: (linkEl, childSn) => {
|
|
6450
|
+
stylesheetManager.attachLinkElement(linkEl, childSn);
|
|
6451
|
+
},
|
|
6452
|
+
keepIframeSrcFn,
|
|
6453
|
+
});
|
|
6454
|
+
if (!node) {
|
|
6455
|
+
return console.warn('Failed to snapshot the document');
|
|
6456
|
+
}
|
|
6457
|
+
wrappedEmit(wrapEvent({
|
|
6458
|
+
type: EventType.FullSnapshot,
|
|
6459
|
+
data: {
|
|
6460
|
+
node,
|
|
6461
|
+
initialOffset: {
|
|
6462
|
+
left: window.pageXOffset !== undefined
|
|
6463
|
+
? window.pageXOffset
|
|
6464
|
+
: (document === null || document === void 0 ? void 0 : document.documentElement.scrollLeft) ||
|
|
6465
|
+
((_b = (_a = document === null || document === void 0 ? void 0 : document.body) === null || _a === void 0 ? void 0 : _a.parentElement) === null || _b === void 0 ? void 0 : _b.scrollLeft) ||
|
|
6466
|
+
((_c = document === null || document === void 0 ? void 0 : document.body) === null || _c === void 0 ? void 0 : _c.scrollLeft) ||
|
|
6467
|
+
0,
|
|
6468
|
+
top: window.pageYOffset !== undefined
|
|
6469
|
+
? window.pageYOffset
|
|
6470
|
+
: (document === null || document === void 0 ? void 0 : document.documentElement.scrollTop) ||
|
|
6471
|
+
((_e = (_d = document === null || document === void 0 ? void 0 : document.body) === null || _d === void 0 ? void 0 : _d.parentElement) === null || _e === void 0 ? void 0 : _e.scrollTop) ||
|
|
6472
|
+
((_f = document === null || document === void 0 ? void 0 : document.body) === null || _f === void 0 ? void 0 : _f.scrollTop) ||
|
|
6473
|
+
0,
|
|
6474
|
+
},
|
|
6475
|
+
},
|
|
6476
|
+
}));
|
|
6477
|
+
mutationBuffers.forEach((buf) => buf.unlock());
|
|
6478
|
+
if (document.adoptedStyleSheets && document.adoptedStyleSheets.length > 0)
|
|
6479
|
+
stylesheetManager.adoptStyleSheets(document.adoptedStyleSheets, mirror.getId(document));
|
|
6480
|
+
};
|
|
6481
|
+
try {
|
|
6482
|
+
const handlers = [];
|
|
6483
|
+
handlers.push(on('DOMContentLoaded', () => {
|
|
6484
|
+
wrappedEmit(wrapEvent({
|
|
6485
|
+
type: EventType.DomContentLoaded,
|
|
6486
|
+
data: {},
|
|
6487
|
+
}));
|
|
6488
|
+
}));
|
|
6489
|
+
const observe = (doc) => {
|
|
6490
|
+
var _a;
|
|
6491
|
+
return initObservers({
|
|
6492
|
+
mutationCb: wrappedMutationEmit,
|
|
6493
|
+
mousemoveCb: (positions, source) => wrappedEmit(wrapEvent({
|
|
6494
|
+
type: EventType.IncrementalSnapshot,
|
|
6495
|
+
data: {
|
|
6496
|
+
source,
|
|
6497
|
+
positions,
|
|
6498
|
+
},
|
|
6499
|
+
})),
|
|
6500
|
+
mouseInteractionCb: (d) => wrappedEmit(wrapEvent({
|
|
6501
|
+
type: EventType.IncrementalSnapshot,
|
|
6502
|
+
data: Object.assign({ source: IncrementalSource.MouseInteraction }, d),
|
|
6503
|
+
})),
|
|
6504
|
+
scrollCb: wrappedScrollEmit,
|
|
6505
|
+
viewportResizeCb: (d) => wrappedEmit(wrapEvent({
|
|
6506
|
+
type: EventType.IncrementalSnapshot,
|
|
6507
|
+
data: Object.assign({ source: IncrementalSource.ViewportResize }, d),
|
|
6508
|
+
})),
|
|
6509
|
+
inputCb: (v) => wrappedEmit(wrapEvent({
|
|
6510
|
+
type: EventType.IncrementalSnapshot,
|
|
6511
|
+
data: Object.assign({ source: IncrementalSource.Input }, v),
|
|
6512
|
+
})),
|
|
6513
|
+
mediaInteractionCb: (p) => wrappedEmit(wrapEvent({
|
|
6514
|
+
type: EventType.IncrementalSnapshot,
|
|
6515
|
+
data: Object.assign({ source: IncrementalSource.MediaInteraction }, p),
|
|
6516
|
+
})),
|
|
6517
|
+
styleSheetRuleCb: (r) => wrappedEmit(wrapEvent({
|
|
6518
|
+
type: EventType.IncrementalSnapshot,
|
|
6519
|
+
data: Object.assign({ source: IncrementalSource.StyleSheetRule }, r),
|
|
6520
|
+
})),
|
|
6521
|
+
styleDeclarationCb: (r) => wrappedEmit(wrapEvent({
|
|
6522
|
+
type: EventType.IncrementalSnapshot,
|
|
6523
|
+
data: Object.assign({ source: IncrementalSource.StyleDeclaration }, r),
|
|
6524
|
+
})),
|
|
6525
|
+
canvasMutationCb: wrappedCanvasMutationEmit,
|
|
6526
|
+
fontCb: (p) => wrappedEmit(wrapEvent({
|
|
6527
|
+
type: EventType.IncrementalSnapshot,
|
|
6528
|
+
data: Object.assign({ source: IncrementalSource.Font }, p),
|
|
6529
|
+
})),
|
|
6530
|
+
selectionCb: (p) => {
|
|
6531
|
+
wrappedEmit(wrapEvent({
|
|
6532
|
+
type: EventType.IncrementalSnapshot,
|
|
6533
|
+
data: Object.assign({ source: IncrementalSource.Selection }, p),
|
|
6534
|
+
}));
|
|
6535
|
+
},
|
|
6536
|
+
blockClass,
|
|
6537
|
+
ignoreClass,
|
|
6538
|
+
maskTextClass,
|
|
6539
|
+
maskTextSelector,
|
|
6540
|
+
maskInputOptions,
|
|
6541
|
+
inlineStylesheet,
|
|
6542
|
+
sampling,
|
|
6543
|
+
recordCanvas,
|
|
6544
|
+
inlineImages,
|
|
6545
|
+
userTriggeredOnInput,
|
|
6546
|
+
collectFonts,
|
|
6547
|
+
doc,
|
|
6548
|
+
maskInputFn,
|
|
6549
|
+
maskTextFn,
|
|
6550
|
+
keepIframeSrcFn,
|
|
6551
|
+
blockSelector,
|
|
6552
|
+
slimDOMOptions,
|
|
6553
|
+
dataURLOptions,
|
|
6554
|
+
mirror,
|
|
6555
|
+
iframeManager,
|
|
6556
|
+
stylesheetManager,
|
|
6557
|
+
shadowDomManager,
|
|
6558
|
+
canvasManager,
|
|
6559
|
+
ignoreCSSAttributes,
|
|
6560
|
+
plugins: ((_a = plugins === null || plugins === void 0 ? void 0 : plugins.filter((p) => p.observer)) === null || _a === void 0 ? void 0 : _a.map((p) => ({
|
|
6561
|
+
observer: p.observer,
|
|
6562
|
+
options: p.options,
|
|
6563
|
+
callback: (payload) => wrappedEmit(wrapEvent({
|
|
6564
|
+
type: EventType.Plugin,
|
|
6565
|
+
data: {
|
|
6566
|
+
plugin: p.name,
|
|
6567
|
+
payload,
|
|
6568
|
+
},
|
|
6569
|
+
})),
|
|
6570
|
+
}))) || [],
|
|
6571
|
+
}, hooks);
|
|
6572
|
+
};
|
|
6573
|
+
iframeManager.addLoadListener((iframeEl) => {
|
|
6574
|
+
handlers.push(observe(iframeEl.contentDocument));
|
|
6575
|
+
});
|
|
6576
|
+
const init = () => {
|
|
6577
|
+
takeFullSnapshot();
|
|
6578
|
+
handlers.push(observe(document));
|
|
6579
|
+
recording = true;
|
|
6580
|
+
};
|
|
6581
|
+
if (document.readyState === 'interactive' ||
|
|
6582
|
+
document.readyState === 'complete') {
|
|
6583
|
+
init();
|
|
6584
|
+
}
|
|
6585
|
+
else {
|
|
6586
|
+
handlers.push(on('load', () => {
|
|
6587
|
+
wrappedEmit(wrapEvent({
|
|
6588
|
+
type: EventType.Load,
|
|
6589
|
+
data: {},
|
|
6590
|
+
}));
|
|
6591
|
+
init();
|
|
6592
|
+
}, window));
|
|
6593
|
+
}
|
|
6594
|
+
return () => {
|
|
6595
|
+
handlers.forEach((h) => h());
|
|
6596
|
+
recording = false;
|
|
6597
|
+
};
|
|
6598
|
+
}
|
|
6599
|
+
catch (error) {
|
|
6600
|
+
console.warn(error);
|
|
6601
|
+
}
|
|
6602
|
+
}
|
|
6603
|
+
record.addCustomEvent = (tag, payload) => {
|
|
6604
|
+
if (!recording) {
|
|
6605
|
+
throw new Error('please add custom event after start recording');
|
|
6606
|
+
}
|
|
6607
|
+
wrappedEmit(wrapEvent({
|
|
6608
|
+
type: EventType.Custom,
|
|
6609
|
+
data: {
|
|
6610
|
+
tag,
|
|
6611
|
+
payload,
|
|
6612
|
+
},
|
|
6613
|
+
}));
|
|
6614
|
+
};
|
|
6615
|
+
record.freezePage = () => {
|
|
6616
|
+
mutationBuffers.forEach((buf) => buf.freeze());
|
|
6617
|
+
};
|
|
6618
|
+
record.takeFullSnapshot = (isCheckout) => {
|
|
6619
|
+
if (!recording) {
|
|
6620
|
+
throw new Error('please take full snapshot after start recording');
|
|
6621
|
+
}
|
|
6622
|
+
takeFullSnapshot(isCheckout);
|
|
6623
|
+
};
|
|
6624
|
+
record.mirror = mirror;
|
|
6625
|
+
|
|
2717
6626
|
/**
|
|
2718
|
-
* Session Recording Module
|
|
2719
|
-
*
|
|
6627
|
+
* Session Recording Module with RRWeb Integration
|
|
6628
|
+
* Records user interactions exactly like Mixpanel does
|
|
2720
6629
|
*/
|
|
2721
|
-
const DEFAULT_CONFIG = {
|
|
6630
|
+
const DEFAULT_CONFIG$1 = {
|
|
2722
6631
|
enabled: true,
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
6632
|
+
maskAllInputs: true,
|
|
6633
|
+
maskInputOptions: {
|
|
6634
|
+
color: '#D1D5DB',
|
|
6635
|
+
textClass: 'masked-text',
|
|
6636
|
+
colorClass: 'masked-color',
|
|
6637
|
+
},
|
|
6638
|
+
// Mask sensitive inputs with asterisks like Mixpanel
|
|
6639
|
+
maskInputFn: (text, element) => {
|
|
6640
|
+
if (!element || !text)
|
|
6641
|
+
return text;
|
|
6642
|
+
const tagName = element.tagName?.toLowerCase();
|
|
6643
|
+
const inputType = element?.type?.toLowerCase();
|
|
6644
|
+
// Always mask passwords
|
|
6645
|
+
if (inputType === 'password') {
|
|
6646
|
+
return '*'.repeat(Math.min(text.length, 10));
|
|
6647
|
+
}
|
|
6648
|
+
// Mask credit card fields
|
|
6649
|
+
const inputElement = element;
|
|
6650
|
+
if (inputType === 'tel' && (inputElement.autocomplete?.includes('cc-') ||
|
|
6651
|
+
inputElement.name?.toLowerCase().includes('card') ||
|
|
6652
|
+
element.className?.toLowerCase().includes('card'))) {
|
|
6653
|
+
return '*'.repeat(Math.min(text.length, 16));
|
|
6654
|
+
}
|
|
6655
|
+
// Mask email if contains sensitive patterns
|
|
6656
|
+
if (inputType === 'email' || tagName === 'input') {
|
|
6657
|
+
const isSensitive = inputElement.name?.toLowerCase().includes('email') ||
|
|
6658
|
+
element.id?.toLowerCase().includes('email') ||
|
|
6659
|
+
inputElement.placeholder?.toLowerCase().includes('email');
|
|
6660
|
+
if (isSensitive) {
|
|
6661
|
+
const atIndex = text.indexOf('@');
|
|
6662
|
+
if (atIndex > 2) {
|
|
6663
|
+
return text.substring(0, 2) + '*'.repeat(atIndex - 2) + text.substring(atIndex);
|
|
6664
|
+
}
|
|
6665
|
+
}
|
|
6666
|
+
}
|
|
6667
|
+
// Mask other sensitive inputs
|
|
6668
|
+
const sensitivePatterns = ['ssn', 'social', 'security', 'tax', 'id', 'license'];
|
|
6669
|
+
const elementInfo = `${element.name || ''} ${element.id || ''} ${element.className || ''}`.toLowerCase();
|
|
6670
|
+
if (sensitivePatterns.some(pattern => elementInfo.includes(pattern))) {
|
|
6671
|
+
if (text.length <= 4) {
|
|
6672
|
+
return '*'.repeat(text.length);
|
|
6673
|
+
}
|
|
6674
|
+
return text.substring(0, 2) + '*'.repeat(text.length - 4) + text.substring(text.length - 2);
|
|
6675
|
+
}
|
|
6676
|
+
return text;
|
|
6677
|
+
},
|
|
6678
|
+
// Mask sensitive text content
|
|
6679
|
+
maskTextFn: (text, element) => {
|
|
6680
|
+
if (!element || !text)
|
|
6681
|
+
return text;
|
|
6682
|
+
// Check if element has sensitive data attributes or classes
|
|
6683
|
+
const sensitiveMarkers = ['data-sensitive', 'sensitive', 'private', 'confidential'];
|
|
6684
|
+
const elementClasses = element.className?.toLowerCase() || '';
|
|
6685
|
+
const elementAttrs = Array.from(element.attributes || [])
|
|
6686
|
+
.map(attr => attr.name.toLowerCase()).join(' ');
|
|
6687
|
+
if (sensitiveMarkers.some(marker => elementClasses.includes(marker) || elementAttrs.includes(marker))) {
|
|
6688
|
+
return '*'.repeat(Math.min(text.length, 20));
|
|
6689
|
+
}
|
|
6690
|
+
return text;
|
|
6691
|
+
},
|
|
6692
|
+
blockClass: 'cf-block',
|
|
6693
|
+
blockSelector: '.cf-block, [data-cf-block]',
|
|
6694
|
+
ignoreClass: 'cf-ignore',
|
|
6695
|
+
maskTextClass: 'cf-mask-text',
|
|
6696
|
+
maskTextSelector: '.cf-mask-text, [data-sensitive], .sensitive',
|
|
6697
|
+
maskAllText: false,
|
|
6698
|
+
slimDOMOptions: {
|
|
6699
|
+
script: true,
|
|
6700
|
+
comment: true,
|
|
6701
|
+
headFavicon: true,
|
|
6702
|
+
headWhitespace: true,
|
|
6703
|
+
headMetaDescKeywords: true,
|
|
6704
|
+
headMetaSocial: true,
|
|
6705
|
+
headMetaRobots: true,
|
|
6706
|
+
headMetaHttpEquiv: true,
|
|
6707
|
+
headMetaAuthorship: true,
|
|
6708
|
+
headMetaVerification: true,
|
|
6709
|
+
},
|
|
6710
|
+
recordCanvas: true,
|
|
6711
|
+
collectFonts: false,
|
|
6712
|
+
sampling: {
|
|
6713
|
+
mousemove: 50, // Sample every 50ms
|
|
6714
|
+
mouseInteraction: true,
|
|
6715
|
+
scroll: 150, // Sample every 150ms
|
|
6716
|
+
media: 800,
|
|
6717
|
+
input: 'last',
|
|
6718
|
+
},
|
|
2731
6719
|
};
|
|
2732
|
-
class
|
|
6720
|
+
class SessionRecordingRRWeb {
|
|
2733
6721
|
constructor(config = {}) {
|
|
2734
6722
|
this.events = [];
|
|
2735
6723
|
this.startTime = 0;
|
|
2736
6724
|
this.isRecording = false;
|
|
2737
|
-
this.
|
|
2738
|
-
this.
|
|
2739
|
-
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
6725
|
+
this.stopFn = null;
|
|
6726
|
+
this.recordingOptions = {};
|
|
6727
|
+
this.config = { ...DEFAULT_CONFIG$1, ...config };
|
|
2740
6728
|
this.sessionId = this.generateSessionId();
|
|
6729
|
+
this.setupRecordingOptions();
|
|
2741
6730
|
}
|
|
2742
6731
|
generateSessionId() {
|
|
2743
|
-
return `
|
|
6732
|
+
return `session_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;
|
|
6733
|
+
}
|
|
6734
|
+
setupRecordingOptions() {
|
|
6735
|
+
this.recordingOptions = {
|
|
6736
|
+
emit: (event) => {
|
|
6737
|
+
if (this.isRecording) {
|
|
6738
|
+
this.events.push(event);
|
|
6739
|
+
// Limit buffer size to prevent memory issues
|
|
6740
|
+
if (this.events.length > 50000) {
|
|
6741
|
+
this.events.splice(0, 10000); // Remove oldest 10k events
|
|
6742
|
+
console.warn('🎥 [SessionRecording] Event buffer full, removing old events');
|
|
6743
|
+
}
|
|
6744
|
+
}
|
|
6745
|
+
},
|
|
6746
|
+
maskInputOptions: this.config.maskInputOptions,
|
|
6747
|
+
maskInputFn: this.config.maskInputFn,
|
|
6748
|
+
maskTextFn: this.config.maskTextFn,
|
|
6749
|
+
blockClass: this.config.blockClass,
|
|
6750
|
+
blockSelector: this.config.blockSelector,
|
|
6751
|
+
ignoreClass: this.config.ignoreClass,
|
|
6752
|
+
maskTextClass: this.config.maskTextClass,
|
|
6753
|
+
maskTextSelector: this.config.maskTextSelector,
|
|
6754
|
+
maskAllInputs: this.config.maskAllInputs,
|
|
6755
|
+
maskAllText: this.config.maskAllText,
|
|
6756
|
+
slimDOMOptions: this.config.slimDOMOptions,
|
|
6757
|
+
recordCanvas: this.config.recordCanvas,
|
|
6758
|
+
collectFonts: this.config.collectFonts,
|
|
6759
|
+
sampling: this.config.sampling,
|
|
6760
|
+
plugins: this.config.plugins,
|
|
6761
|
+
};
|
|
2744
6762
|
}
|
|
2745
6763
|
/**
|
|
2746
|
-
* Start recording
|
|
6764
|
+
* Start recording using RRWeb
|
|
2747
6765
|
*/
|
|
2748
6766
|
start() {
|
|
2749
6767
|
if (this.isRecording || !this.config.enabled)
|
|
2750
6768
|
return;
|
|
2751
|
-
console.log(' [SessionRecording] Starting
|
|
6769
|
+
console.log('🎥 [SessionRecording] Starting RRWeb recording...', {
|
|
2752
6770
|
sessionId: this.sessionId,
|
|
2753
6771
|
config: this.config
|
|
2754
6772
|
});
|
|
2755
6773
|
this.isRecording = true;
|
|
2756
6774
|
this.startTime = Date.now();
|
|
2757
6775
|
this.events = [];
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
this.setupMouseTracking();
|
|
2763
|
-
console.log(' [SessionRecording] Mouse tracking enabled');
|
|
2764
|
-
}
|
|
2765
|
-
if (this.config.recordScroll) {
|
|
2766
|
-
this.setupScrollTracking();
|
|
2767
|
-
console.log(' [SessionRecording] Scroll tracking enabled');
|
|
2768
|
-
}
|
|
2769
|
-
if (this.config.recordInput) {
|
|
2770
|
-
this.setupInputTracking();
|
|
2771
|
-
console.log(' [SessionRecording] Input tracking enabled');
|
|
6776
|
+
try {
|
|
6777
|
+
// Start RRWeb recording
|
|
6778
|
+
this.stopFn = record(this.recordingOptions);
|
|
6779
|
+
console.log('🎥 [SessionRecording] RRWeb recording started successfully');
|
|
2772
6780
|
}
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
6781
|
+
catch (error) {
|
|
6782
|
+
console.error('🎥 [SessionRecording] Failed to start recording:', error);
|
|
6783
|
+
this.isRecording = false;
|
|
2776
6784
|
}
|
|
2777
|
-
// Track navigation
|
|
2778
|
-
this.setupNavigationTracking();
|
|
2779
|
-
// Track resize
|
|
2780
|
-
this.setupResizeTracking();
|
|
2781
|
-
console.log(' [SessionRecording] Session recording started successfully');
|
|
2782
|
-
// Auto-stop after max duration
|
|
2783
|
-
setTimeout(() => {
|
|
2784
|
-
if (this.isRecording) {
|
|
2785
|
-
this.stop();
|
|
2786
|
-
}
|
|
2787
|
-
}, this.config.maxDurationSeconds * 1000);
|
|
2788
6785
|
}
|
|
2789
6786
|
/**
|
|
2790
6787
|
* Stop recording
|
|
@@ -2792,16 +6789,15 @@ class SessionRecording {
|
|
|
2792
6789
|
stop() {
|
|
2793
6790
|
if (!this.isRecording)
|
|
2794
6791
|
return;
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
6792
|
+
console.log('🎥 [SessionRecording] Stopping recording...', {
|
|
6793
|
+
sessionId: this.sessionId,
|
|
6794
|
+
eventCount: this.events.length,
|
|
6795
|
+
duration: this.getDuration()
|
|
2799
6796
|
});
|
|
2800
|
-
this.
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
this.
|
|
2804
|
-
this.mutationObserver = null;
|
|
6797
|
+
this.isRecording = false;
|
|
6798
|
+
if (this.stopFn) {
|
|
6799
|
+
this.stopFn();
|
|
6800
|
+
this.stopFn = null;
|
|
2805
6801
|
}
|
|
2806
6802
|
}
|
|
2807
6803
|
/**
|
|
@@ -2811,18 +6807,24 @@ class SessionRecording {
|
|
|
2811
6807
|
return this.sessionId;
|
|
2812
6808
|
}
|
|
2813
6809
|
/**
|
|
2814
|
-
* Get recorded events
|
|
6810
|
+
* Get recorded events (RRWeb format)
|
|
2815
6811
|
*/
|
|
2816
6812
|
getEvents() {
|
|
2817
6813
|
return [...this.events];
|
|
2818
6814
|
}
|
|
2819
6815
|
/**
|
|
2820
|
-
* Get recording duration in
|
|
6816
|
+
* Get recording duration in milliseconds
|
|
2821
6817
|
*/
|
|
2822
|
-
|
|
6818
|
+
getDurationMs() {
|
|
2823
6819
|
if (!this.startTime)
|
|
2824
6820
|
return 0;
|
|
2825
|
-
return
|
|
6821
|
+
return Date.now() - this.startTime;
|
|
6822
|
+
}
|
|
6823
|
+
/**
|
|
6824
|
+
* Get recording duration in seconds
|
|
6825
|
+
*/
|
|
6826
|
+
getDuration() {
|
|
6827
|
+
return Math.round(this.getDurationMs() / 1000);
|
|
2826
6828
|
}
|
|
2827
6829
|
/**
|
|
2828
6830
|
* Clear events (for chunked uploads)
|
|
@@ -2831,13 +6833,26 @@ class SessionRecording {
|
|
|
2831
6833
|
this.events = [];
|
|
2832
6834
|
}
|
|
2833
6835
|
/**
|
|
2834
|
-
* Get
|
|
6836
|
+
* Get events since last clear (for incremental uploads)
|
|
6837
|
+
*/
|
|
6838
|
+
getEventsSinceLast(count = 1000) {
|
|
6839
|
+
if (this.events.length <= count) {
|
|
6840
|
+
const allEvents = [...this.events];
|
|
6841
|
+
this.clearEvents();
|
|
6842
|
+
return allEvents;
|
|
6843
|
+
}
|
|
6844
|
+
const batch = this.events.splice(0, count);
|
|
6845
|
+
return batch;
|
|
6846
|
+
}
|
|
6847
|
+
/**
|
|
6848
|
+
* Get recording data for submission (compatible with backend)
|
|
2835
6849
|
*/
|
|
2836
6850
|
getRecordingData() {
|
|
2837
6851
|
console.log('🎥 [SessionRecording] getRecordingData called:', {
|
|
2838
6852
|
eventCount: this.events.length,
|
|
2839
6853
|
sessionId: this.sessionId,
|
|
2840
6854
|
duration: this.getDuration(),
|
|
6855
|
+
durationMs: this.getDurationMs(),
|
|
2841
6856
|
isRecording: this.isRecording,
|
|
2842
6857
|
startTime: this.startTime
|
|
2843
6858
|
});
|
|
@@ -2848,290 +6863,87 @@ class SessionRecording {
|
|
|
2848
6863
|
const data = {
|
|
2849
6864
|
events: [...this.events],
|
|
2850
6865
|
sessionId: this.sessionId,
|
|
2851
|
-
duration: this.
|
|
6866
|
+
duration: this.getDurationMs(), // Return milliseconds for precision
|
|
2852
6867
|
};
|
|
2853
6868
|
console.log('🎥 [SessionRecording] Returning recording data:', {
|
|
2854
6869
|
eventCount: data.events.length,
|
|
2855
6870
|
duration: data.duration,
|
|
2856
|
-
|
|
2857
|
-
|
|
6871
|
+
firstEvent: data.events[0]?.type,
|
|
6872
|
+
lastEvent: data.events[data.events.length - 1]?.type,
|
|
6873
|
+
hasSnapshot: data.events.some(e => e.type === 2), // Meta event type for snapshot
|
|
6874
|
+
hasMutations: data.events.some(e => e.type === 3), // Mutation event
|
|
6875
|
+
hasMouseMoves: data.events.some(e => e.type === 3), // Mouse move event
|
|
2858
6876
|
});
|
|
2859
6877
|
return data;
|
|
2860
6878
|
}
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
this.
|
|
2866
|
-
type,
|
|
2867
|
-
timestamp: Date.now() - this.startTime,
|
|
2868
|
-
data,
|
|
2869
|
-
});
|
|
2870
|
-
// Limit event buffer size
|
|
2871
|
-
if (this.events.length > 10000) {
|
|
2872
|
-
this.events.shift();
|
|
2873
|
-
}
|
|
6879
|
+
/**
|
|
6880
|
+
* Check if currently recording
|
|
6881
|
+
*/
|
|
6882
|
+
isCurrentlyRecording() {
|
|
6883
|
+
return this.isRecording;
|
|
2874
6884
|
}
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
this.
|
|
2936
|
-
|
|
2937
|
-
setupInputTracking() {
|
|
2938
|
-
const handler = (e) => {
|
|
2939
|
-
const target = e.target;
|
|
2940
|
-
if (!target.tagName)
|
|
2941
|
-
return;
|
|
2942
|
-
const isSensitive = this.isSensitiveElement(target);
|
|
2943
|
-
this.addEvent('input', {
|
|
2944
|
-
selector: this.getElementSelector(target),
|
|
2945
|
-
value: isSensitive ? '********' : target.value?.substring(0, 100),
|
|
2946
|
-
type: target.type || 'text',
|
|
2947
|
-
});
|
|
2948
|
-
};
|
|
2949
|
-
document.addEventListener('input', handler, { passive: true });
|
|
2950
|
-
this.listeners.push({ element: document, event: 'input', handler });
|
|
2951
|
-
}
|
|
2952
|
-
setupMutationObserver() {
|
|
2953
|
-
this.mutationObserver = new MutationObserver((mutations) => {
|
|
2954
|
-
const changes = [];
|
|
2955
|
-
mutations.forEach((mutation) => {
|
|
2956
|
-
if (mutation.type === 'childList') {
|
|
2957
|
-
mutation.addedNodes.forEach((node) => {
|
|
2958
|
-
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
2959
|
-
changes.push({
|
|
2960
|
-
action: 'add',
|
|
2961
|
-
target: this.getElementSelector(mutation.target),
|
|
2962
|
-
html: this.sanitizeHTML(node.outerHTML || ''),
|
|
2963
|
-
});
|
|
2964
|
-
}
|
|
2965
|
-
});
|
|
2966
|
-
mutation.removedNodes.forEach((node) => {
|
|
2967
|
-
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
2968
|
-
changes.push({
|
|
2969
|
-
action: 'remove',
|
|
2970
|
-
target: this.getElementSelector(mutation.target),
|
|
2971
|
-
selector: this.getElementSelector(node),
|
|
2972
|
-
});
|
|
2973
|
-
}
|
|
2974
|
-
});
|
|
2975
|
-
}
|
|
2976
|
-
else if (mutation.type === 'attributes') {
|
|
2977
|
-
changes.push({
|
|
2978
|
-
action: 'attribute',
|
|
2979
|
-
target: this.getElementSelector(mutation.target),
|
|
2980
|
-
attribute: mutation.attributeName,
|
|
2981
|
-
value: mutation.target.getAttribute(mutation.attributeName),
|
|
2982
|
-
});
|
|
2983
|
-
}
|
|
2984
|
-
});
|
|
2985
|
-
if (changes.length > 0) {
|
|
2986
|
-
this.addEvent('mutation', { changes });
|
|
2987
|
-
}
|
|
2988
|
-
});
|
|
2989
|
-
this.mutationObserver.observe(document.body, {
|
|
2990
|
-
childList: true,
|
|
2991
|
-
subtree: true,
|
|
2992
|
-
attributes: true,
|
|
2993
|
-
attributeFilter: ['class', 'style', 'src', 'href'],
|
|
2994
|
-
});
|
|
2995
|
-
}
|
|
2996
|
-
setupNavigationTracking() {
|
|
2997
|
-
const handler = () => {
|
|
2998
|
-
this.addEvent('navigation', {
|
|
2999
|
-
url: window.location.href,
|
|
3000
|
-
title: document.title,
|
|
3001
|
-
});
|
|
3002
|
-
};
|
|
3003
|
-
window.addEventListener('popstate', handler);
|
|
3004
|
-
this.listeners.push({ element: window, event: 'popstate', handler });
|
|
3005
|
-
}
|
|
3006
|
-
setupResizeTracking() {
|
|
3007
|
-
let throttleTimer = null;
|
|
3008
|
-
const handler = () => {
|
|
3009
|
-
if (throttleTimer)
|
|
3010
|
-
return;
|
|
3011
|
-
throttleTimer = window.setTimeout(() => {
|
|
3012
|
-
throttleTimer = null;
|
|
3013
|
-
}, 200);
|
|
3014
|
-
this.addEvent('resize', {
|
|
3015
|
-
width: window.innerWidth,
|
|
3016
|
-
height: window.innerHeight,
|
|
3017
|
-
});
|
|
3018
|
-
};
|
|
3019
|
-
window.addEventListener('resize', handler, { passive: true });
|
|
3020
|
-
this.listeners.push({ element: window, event: 'resize', handler });
|
|
3021
|
-
}
|
|
3022
|
-
getElementSelector(element) {
|
|
3023
|
-
if (!element || !element.tagName)
|
|
3024
|
-
return '';
|
|
3025
|
-
const parts = [];
|
|
3026
|
-
let current = element;
|
|
3027
|
-
while (current && current.tagName !== 'HTML') {
|
|
3028
|
-
let selector = current.tagName.toLowerCase();
|
|
3029
|
-
if (current.id) {
|
|
3030
|
-
selector += `#${current.id}`;
|
|
3031
|
-
parts.unshift(selector);
|
|
3032
|
-
break;
|
|
3033
|
-
}
|
|
3034
|
-
else if (current.className && typeof current.className === 'string') {
|
|
3035
|
-
const classes = current.className.trim().split(/\s+/).slice(0, 2);
|
|
3036
|
-
if (classes.length > 0 && classes[0]) {
|
|
3037
|
-
selector += `.${classes.join('.')}`;
|
|
3038
|
-
}
|
|
3039
|
-
}
|
|
3040
|
-
parts.unshift(selector);
|
|
3041
|
-
current = current.parentElement;
|
|
3042
|
-
}
|
|
3043
|
-
return parts.slice(-4).join(' > ');
|
|
3044
|
-
}
|
|
3045
|
-
isSensitiveElement(element) {
|
|
3046
|
-
if (this.config.maskInputs) {
|
|
3047
|
-
const type = element.getAttribute('type');
|
|
3048
|
-
if (type === 'password' || type === 'credit-card')
|
|
3049
|
-
return true;
|
|
3050
|
-
}
|
|
3051
|
-
return this.config.maskSelectors.some((selector) => {
|
|
3052
|
-
try {
|
|
3053
|
-
return element.matches(selector);
|
|
3054
|
-
}
|
|
3055
|
-
catch {
|
|
3056
|
-
return false;
|
|
3057
|
-
}
|
|
3058
|
-
});
|
|
3059
|
-
}
|
|
3060
|
-
sanitizeHTML(html) {
|
|
3061
|
-
// Remove script contents
|
|
3062
|
-
html = html.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '<script></script>');
|
|
3063
|
-
// Mask sensitive inputs
|
|
3064
|
-
if (this.config.maskInputs) {
|
|
3065
|
-
html = html.replace(/(<input[^>]*type=["']password["'][^>]*value=["'])[^"']*["']/gi, '$1••••••••"');
|
|
3066
|
-
}
|
|
3067
|
-
// Truncate if too large
|
|
3068
|
-
if (html.length > 500000) {
|
|
3069
|
-
html = html.substring(0, 500000) + '<!-- truncated -->';
|
|
3070
|
-
}
|
|
3071
|
-
return html;
|
|
3072
|
-
}
|
|
3073
|
-
}
|
|
3074
|
-
|
|
3075
|
-
/**
|
|
3076
|
-
* CheckFlow Privacy Module Types
|
|
3077
|
-
* Configuration and types for automatic PII masking
|
|
3078
|
-
*/
|
|
3079
|
-
const DEFAULT_PRIVACY_CONFIG = {
|
|
3080
|
-
enabled: true,
|
|
3081
|
-
autoMask: {
|
|
3082
|
-
emails: true,
|
|
3083
|
-
creditCards: true,
|
|
3084
|
-
phoneNumbers: true,
|
|
3085
|
-
passwords: true,
|
|
3086
|
-
socialSecurity: true,
|
|
3087
|
-
ipAddresses: false,
|
|
3088
|
-
customPatterns: [],
|
|
3089
|
-
},
|
|
3090
|
-
excludeSelectors: [],
|
|
3091
|
-
includeSelectors: [],
|
|
3092
|
-
maskChar: '•',
|
|
3093
|
-
maskLength: 'preserve',
|
|
3094
|
-
fixedMaskLength: 8,
|
|
3095
|
-
};
|
|
3096
|
-
const SENSITIVE_INPUT_TYPES = [
|
|
3097
|
-
'password',
|
|
3098
|
-
'email',
|
|
3099
|
-
'tel',
|
|
3100
|
-
'credit-card',
|
|
3101
|
-
'cc-number',
|
|
3102
|
-
'cc-csc',
|
|
3103
|
-
'cc-exp',
|
|
3104
|
-
];
|
|
3105
|
-
const SENSITIVE_AUTOCOMPLETE_VALUES = [
|
|
3106
|
-
'cc-number',
|
|
3107
|
-
'cc-csc',
|
|
3108
|
-
'cc-exp',
|
|
3109
|
-
'cc-exp-month',
|
|
3110
|
-
'cc-exp-year',
|
|
3111
|
-
'cc-name',
|
|
3112
|
-
'cc-type',
|
|
3113
|
-
'new-password',
|
|
3114
|
-
'current-password',
|
|
3115
|
-
];
|
|
3116
|
-
|
|
3117
|
-
/**
|
|
3118
|
-
* CheckFlow Privacy Detector
|
|
3119
|
-
* Regex patterns for detecting PII (Personally Identifiable Information)
|
|
3120
|
-
*/
|
|
3121
|
-
const PATTERNS = {
|
|
3122
|
-
email: /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g,
|
|
3123
|
-
creditCard: /\b(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}|6(?:011|5[0-9]{2})[0-9]{12}|(?:2131|1800|35\d{3})\d{11})\b/g,
|
|
3124
|
-
creditCardSpaced: /\b(?:\d{4}[-\s]?){3}\d{4}\b/g,
|
|
3125
|
-
phone: /(?:\+?1[-.\s]?)?(?:\([0-9]{3}\)|[0-9]{3})[-.\s]?[0-9]{3}[-.\s]?[0-9]{4}\b/g,
|
|
3126
|
-
phoneFR: /(?:(?:\+|00)33|0)\s*[1-9](?:[\s.-]*\d{2}){4}/g,
|
|
3127
|
-
ssn: /\b\d{3}[-]?\d{2}[-]?\d{4}\b/g,
|
|
3128
|
-
ipv4: /\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/g,
|
|
3129
|
-
ipv6: /\b(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}\b/g,
|
|
3130
|
-
};
|
|
3131
|
-
class PrivacyDetector {
|
|
3132
|
-
constructor(customPatterns = []) {
|
|
3133
|
-
this.customPatterns = [];
|
|
3134
|
-
this.customPatterns = customPatterns;
|
|
6885
|
+
}
|
|
6886
|
+
|
|
6887
|
+
/**
|
|
6888
|
+
* CheckFlow Privacy Module Types
|
|
6889
|
+
* Configuration and types for automatic PII masking
|
|
6890
|
+
*/
|
|
6891
|
+
const DEFAULT_PRIVACY_CONFIG = {
|
|
6892
|
+
enabled: true,
|
|
6893
|
+
autoMask: {
|
|
6894
|
+
emails: true,
|
|
6895
|
+
creditCards: true,
|
|
6896
|
+
phoneNumbers: true,
|
|
6897
|
+
passwords: true,
|
|
6898
|
+
socialSecurity: true,
|
|
6899
|
+
ipAddresses: false,
|
|
6900
|
+
customPatterns: [],
|
|
6901
|
+
},
|
|
6902
|
+
excludeSelectors: [],
|
|
6903
|
+
includeSelectors: [],
|
|
6904
|
+
maskChar: '•',
|
|
6905
|
+
maskLength: 'preserve',
|
|
6906
|
+
fixedMaskLength: 8,
|
|
6907
|
+
};
|
|
6908
|
+
const SENSITIVE_INPUT_TYPES = [
|
|
6909
|
+
'password',
|
|
6910
|
+
'email',
|
|
6911
|
+
'tel',
|
|
6912
|
+
'credit-card',
|
|
6913
|
+
'cc-number',
|
|
6914
|
+
'cc-csc',
|
|
6915
|
+
'cc-exp',
|
|
6916
|
+
];
|
|
6917
|
+
const SENSITIVE_AUTOCOMPLETE_VALUES = [
|
|
6918
|
+
'cc-number',
|
|
6919
|
+
'cc-csc',
|
|
6920
|
+
'cc-exp',
|
|
6921
|
+
'cc-exp-month',
|
|
6922
|
+
'cc-exp-year',
|
|
6923
|
+
'cc-name',
|
|
6924
|
+
'cc-type',
|
|
6925
|
+
'new-password',
|
|
6926
|
+
'current-password',
|
|
6927
|
+
];
|
|
6928
|
+
|
|
6929
|
+
/**
|
|
6930
|
+
* CheckFlow Privacy Detector
|
|
6931
|
+
* Regex patterns for detecting PII (Personally Identifiable Information)
|
|
6932
|
+
*/
|
|
6933
|
+
const PATTERNS = {
|
|
6934
|
+
email: /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g,
|
|
6935
|
+
creditCard: /\b(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}|6(?:011|5[0-9]{2})[0-9]{12}|(?:2131|1800|35\d{3})\d{11})\b/g,
|
|
6936
|
+
creditCardSpaced: /\b(?:\d{4}[-\s]?){3}\d{4}\b/g,
|
|
6937
|
+
phone: /(?:\+?1[-.\s]?)?(?:\([0-9]{3}\)|[0-9]{3})[-.\s]?[0-9]{3}[-.\s]?[0-9]{4}\b/g,
|
|
6938
|
+
phoneFR: /(?:(?:\+|00)33|0)\s*[1-9](?:[\s.-]*\d{2}){4}/g,
|
|
6939
|
+
ssn: /\b\d{3}[-]?\d{2}[-]?\d{4}\b/g,
|
|
6940
|
+
ipv4: /\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/g,
|
|
6941
|
+
ipv6: /\b(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}\b/g,
|
|
6942
|
+
};
|
|
6943
|
+
class PrivacyDetector {
|
|
6944
|
+
constructor(customPatterns = []) {
|
|
6945
|
+
this.customPatterns = [];
|
|
6946
|
+
this.customPatterns = customPatterns;
|
|
3135
6947
|
}
|
|
3136
6948
|
/**
|
|
3137
6949
|
* Add a custom pattern
|
|
@@ -4276,7 +8088,7 @@ class CheckFlow {
|
|
|
4276
8088
|
}
|
|
4277
8089
|
// Start session recording
|
|
4278
8090
|
if (this.options.captureSessionRecording !== false) {
|
|
4279
|
-
this.sessionRecording = new
|
|
8091
|
+
this.sessionRecording = new SessionRecordingRRWeb();
|
|
4280
8092
|
this.sessionRecording.start();
|
|
4281
8093
|
this.log('Session recording started');
|
|
4282
8094
|
}
|
|
@@ -4561,6 +8373,364 @@ function createCheckFlow(apiKey, options) {
|
|
|
4561
8373
|
return new CheckFlow(apiKey, options).init();
|
|
4562
8374
|
}
|
|
4563
8375
|
|
|
8376
|
+
/**
|
|
8377
|
+
* Session Recording Module
|
|
8378
|
+
* Captures user interactions for replay
|
|
8379
|
+
*/
|
|
8380
|
+
const DEFAULT_CONFIG = {
|
|
8381
|
+
enabled: true,
|
|
8382
|
+
recordMouse: true,
|
|
8383
|
+
recordScroll: true,
|
|
8384
|
+
recordInput: true,
|
|
8385
|
+
recordMutations: true,
|
|
8386
|
+
maskInputs: true,
|
|
8387
|
+
maskSelectors: ['[type="password"]', '[data-sensitive]', '.sensitive'],
|
|
8388
|
+
maxDurationSeconds: 300,
|
|
8389
|
+
sampleRate: 1.0,
|
|
8390
|
+
};
|
|
8391
|
+
class SessionRecording {
|
|
8392
|
+
constructor(config = {}) {
|
|
8393
|
+
this.events = [];
|
|
8394
|
+
this.startTime = 0;
|
|
8395
|
+
this.isRecording = false;
|
|
8396
|
+
this.mutationObserver = null;
|
|
8397
|
+
this.listeners = [];
|
|
8398
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
8399
|
+
this.sessionId = this.generateSessionId();
|
|
8400
|
+
}
|
|
8401
|
+
generateSessionId() {
|
|
8402
|
+
return `sess_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;
|
|
8403
|
+
}
|
|
8404
|
+
/**
|
|
8405
|
+
* Start recording the session
|
|
8406
|
+
*/
|
|
8407
|
+
start() {
|
|
8408
|
+
if (this.isRecording || !this.config.enabled)
|
|
8409
|
+
return;
|
|
8410
|
+
console.log(' [SessionRecording] Starting session recording...', {
|
|
8411
|
+
sessionId: this.sessionId,
|
|
8412
|
+
config: this.config
|
|
8413
|
+
});
|
|
8414
|
+
this.isRecording = true;
|
|
8415
|
+
this.startTime = Date.now();
|
|
8416
|
+
this.events = [];
|
|
8417
|
+
// Record initial DOM snapshot
|
|
8418
|
+
this.recordSnapshot();
|
|
8419
|
+
// Setup event listeners
|
|
8420
|
+
if (this.config.recordMouse) {
|
|
8421
|
+
this.setupMouseTracking();
|
|
8422
|
+
console.log(' [SessionRecording] Mouse tracking enabled');
|
|
8423
|
+
}
|
|
8424
|
+
if (this.config.recordScroll) {
|
|
8425
|
+
this.setupScrollTracking();
|
|
8426
|
+
console.log(' [SessionRecording] Scroll tracking enabled');
|
|
8427
|
+
}
|
|
8428
|
+
if (this.config.recordInput) {
|
|
8429
|
+
this.setupInputTracking();
|
|
8430
|
+
console.log(' [SessionRecording] Input tracking enabled');
|
|
8431
|
+
}
|
|
8432
|
+
if (this.config.recordMutations) {
|
|
8433
|
+
this.setupMutationObserver();
|
|
8434
|
+
console.log(' [SessionRecording] Mutation observer enabled');
|
|
8435
|
+
}
|
|
8436
|
+
// Track navigation
|
|
8437
|
+
this.setupNavigationTracking();
|
|
8438
|
+
// Track resize
|
|
8439
|
+
this.setupResizeTracking();
|
|
8440
|
+
console.log(' [SessionRecording] Session recording started successfully');
|
|
8441
|
+
// Auto-stop after max duration
|
|
8442
|
+
setTimeout(() => {
|
|
8443
|
+
if (this.isRecording) {
|
|
8444
|
+
this.stop();
|
|
8445
|
+
}
|
|
8446
|
+
}, this.config.maxDurationSeconds * 1000);
|
|
8447
|
+
}
|
|
8448
|
+
/**
|
|
8449
|
+
* Stop recording
|
|
8450
|
+
*/
|
|
8451
|
+
stop() {
|
|
8452
|
+
if (!this.isRecording)
|
|
8453
|
+
return;
|
|
8454
|
+
this.isRecording = false;
|
|
8455
|
+
// Remove all event listeners
|
|
8456
|
+
this.listeners.forEach(({ element, event, handler }) => {
|
|
8457
|
+
element.removeEventListener(event, handler);
|
|
8458
|
+
});
|
|
8459
|
+
this.listeners = [];
|
|
8460
|
+
// Disconnect mutation observer
|
|
8461
|
+
if (this.mutationObserver) {
|
|
8462
|
+
this.mutationObserver.disconnect();
|
|
8463
|
+
this.mutationObserver = null;
|
|
8464
|
+
}
|
|
8465
|
+
}
|
|
8466
|
+
/**
|
|
8467
|
+
* Get session ID
|
|
8468
|
+
*/
|
|
8469
|
+
getSessionId() {
|
|
8470
|
+
return this.sessionId;
|
|
8471
|
+
}
|
|
8472
|
+
/**
|
|
8473
|
+
* Get recorded events
|
|
8474
|
+
*/
|
|
8475
|
+
getEvents() {
|
|
8476
|
+
return [...this.events];
|
|
8477
|
+
}
|
|
8478
|
+
/**
|
|
8479
|
+
* Get recording duration in seconds
|
|
8480
|
+
*/
|
|
8481
|
+
getDuration() {
|
|
8482
|
+
if (!this.startTime)
|
|
8483
|
+
return 0;
|
|
8484
|
+
return Math.round((Date.now() - this.startTime) / 1000);
|
|
8485
|
+
}
|
|
8486
|
+
/**
|
|
8487
|
+
* Clear events (for chunked uploads)
|
|
8488
|
+
*/
|
|
8489
|
+
clearEvents() {
|
|
8490
|
+
this.events = [];
|
|
8491
|
+
}
|
|
8492
|
+
/**
|
|
8493
|
+
* Get recording data for submission
|
|
8494
|
+
*/
|
|
8495
|
+
getRecordingData() {
|
|
8496
|
+
console.log('🎥 [SessionRecording] getRecordingData called:', {
|
|
8497
|
+
eventCount: this.events.length,
|
|
8498
|
+
sessionId: this.sessionId,
|
|
8499
|
+
duration: this.getDuration(),
|
|
8500
|
+
isRecording: this.isRecording,
|
|
8501
|
+
startTime: this.startTime
|
|
8502
|
+
});
|
|
8503
|
+
if (this.events.length === 0) {
|
|
8504
|
+
console.warn('🎥 [SessionRecording] No events to return');
|
|
8505
|
+
return null;
|
|
8506
|
+
}
|
|
8507
|
+
const data = {
|
|
8508
|
+
events: [...this.events],
|
|
8509
|
+
sessionId: this.sessionId,
|
|
8510
|
+
duration: this.getDuration(),
|
|
8511
|
+
};
|
|
8512
|
+
console.log('🎥 [SessionRecording] Returning recording data:', {
|
|
8513
|
+
eventCount: data.events.length,
|
|
8514
|
+
duration: data.duration,
|
|
8515
|
+
firstEventType: data.events[0]?.type,
|
|
8516
|
+
lastEventType: data.events[data.events.length - 1]?.type
|
|
8517
|
+
});
|
|
8518
|
+
return data;
|
|
8519
|
+
}
|
|
8520
|
+
addEvent(type, data) {
|
|
8521
|
+
// Sample rate filtering
|
|
8522
|
+
if (Math.random() > this.config.sampleRate)
|
|
8523
|
+
return;
|
|
8524
|
+
this.events.push({
|
|
8525
|
+
type,
|
|
8526
|
+
timestamp: Date.now() - this.startTime,
|
|
8527
|
+
data,
|
|
8528
|
+
});
|
|
8529
|
+
// Limit event buffer size
|
|
8530
|
+
if (this.events.length > 10000) {
|
|
8531
|
+
this.events.shift();
|
|
8532
|
+
}
|
|
8533
|
+
}
|
|
8534
|
+
recordSnapshot() {
|
|
8535
|
+
// Record initial page state
|
|
8536
|
+
this.addEvent('mutation', {
|
|
8537
|
+
action: 'snapshot',
|
|
8538
|
+
html: this.sanitizeHTML(document.documentElement.outerHTML),
|
|
8539
|
+
url: window.location.href,
|
|
8540
|
+
title: document.title,
|
|
8541
|
+
viewport: {
|
|
8542
|
+
width: window.innerWidth,
|
|
8543
|
+
height: window.innerHeight,
|
|
8544
|
+
},
|
|
8545
|
+
});
|
|
8546
|
+
}
|
|
8547
|
+
setupMouseTracking() {
|
|
8548
|
+
let lastX = 0, lastY = 0;
|
|
8549
|
+
let throttleTimer = null;
|
|
8550
|
+
const handler = (e) => {
|
|
8551
|
+
// Throttle to ~30fps
|
|
8552
|
+
if (throttleTimer)
|
|
8553
|
+
return;
|
|
8554
|
+
throttleTimer = window.setTimeout(() => {
|
|
8555
|
+
throttleTimer = null;
|
|
8556
|
+
}, 33);
|
|
8557
|
+
// Only record if position changed significantly
|
|
8558
|
+
if (Math.abs(e.clientX - lastX) > 5 || Math.abs(e.clientY - lastY) > 5) {
|
|
8559
|
+
lastX = e.clientX;
|
|
8560
|
+
lastY = e.clientY;
|
|
8561
|
+
this.addEvent('mouse', {
|
|
8562
|
+
action: 'move',
|
|
8563
|
+
x: e.clientX,
|
|
8564
|
+
y: e.clientY,
|
|
8565
|
+
});
|
|
8566
|
+
}
|
|
8567
|
+
};
|
|
8568
|
+
const clickHandler = (e) => {
|
|
8569
|
+
this.addEvent('mouse', {
|
|
8570
|
+
action: 'click',
|
|
8571
|
+
x: e.clientX,
|
|
8572
|
+
y: e.clientY,
|
|
8573
|
+
target: this.getElementSelector(e.target),
|
|
8574
|
+
});
|
|
8575
|
+
};
|
|
8576
|
+
document.addEventListener('mousemove', handler, { passive: true });
|
|
8577
|
+
document.addEventListener('click', clickHandler, { passive: true });
|
|
8578
|
+
this.listeners.push({ element: document, event: 'mousemove', handler: handler }, { element: document, event: 'click', handler: clickHandler });
|
|
8579
|
+
}
|
|
8580
|
+
setupScrollTracking() {
|
|
8581
|
+
let throttleTimer = null;
|
|
8582
|
+
const handler = () => {
|
|
8583
|
+
if (throttleTimer)
|
|
8584
|
+
return;
|
|
8585
|
+
throttleTimer = window.setTimeout(() => {
|
|
8586
|
+
throttleTimer = null;
|
|
8587
|
+
}, 100);
|
|
8588
|
+
this.addEvent('scroll', {
|
|
8589
|
+
x: window.scrollX,
|
|
8590
|
+
y: window.scrollY,
|
|
8591
|
+
});
|
|
8592
|
+
};
|
|
8593
|
+
window.addEventListener('scroll', handler, { passive: true });
|
|
8594
|
+
this.listeners.push({ element: window, event: 'scroll', handler });
|
|
8595
|
+
}
|
|
8596
|
+
setupInputTracking() {
|
|
8597
|
+
const handler = (e) => {
|
|
8598
|
+
const target = e.target;
|
|
8599
|
+
if (!target.tagName)
|
|
8600
|
+
return;
|
|
8601
|
+
const isSensitive = this.isSensitiveElement(target);
|
|
8602
|
+
this.addEvent('input', {
|
|
8603
|
+
selector: this.getElementSelector(target),
|
|
8604
|
+
value: isSensitive ? '********' : target.value?.substring(0, 100),
|
|
8605
|
+
type: target.type || 'text',
|
|
8606
|
+
});
|
|
8607
|
+
};
|
|
8608
|
+
document.addEventListener('input', handler, { passive: true });
|
|
8609
|
+
this.listeners.push({ element: document, event: 'input', handler });
|
|
8610
|
+
}
|
|
8611
|
+
setupMutationObserver() {
|
|
8612
|
+
this.mutationObserver = new MutationObserver((mutations) => {
|
|
8613
|
+
const changes = [];
|
|
8614
|
+
mutations.forEach((mutation) => {
|
|
8615
|
+
if (mutation.type === 'childList') {
|
|
8616
|
+
mutation.addedNodes.forEach((node) => {
|
|
8617
|
+
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
8618
|
+
changes.push({
|
|
8619
|
+
action: 'add',
|
|
8620
|
+
target: this.getElementSelector(mutation.target),
|
|
8621
|
+
html: this.sanitizeHTML(node.outerHTML || ''),
|
|
8622
|
+
});
|
|
8623
|
+
}
|
|
8624
|
+
});
|
|
8625
|
+
mutation.removedNodes.forEach((node) => {
|
|
8626
|
+
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
8627
|
+
changes.push({
|
|
8628
|
+
action: 'remove',
|
|
8629
|
+
target: this.getElementSelector(mutation.target),
|
|
8630
|
+
selector: this.getElementSelector(node),
|
|
8631
|
+
});
|
|
8632
|
+
}
|
|
8633
|
+
});
|
|
8634
|
+
}
|
|
8635
|
+
else if (mutation.type === 'attributes') {
|
|
8636
|
+
changes.push({
|
|
8637
|
+
action: 'attribute',
|
|
8638
|
+
target: this.getElementSelector(mutation.target),
|
|
8639
|
+
attribute: mutation.attributeName,
|
|
8640
|
+
value: mutation.target.getAttribute(mutation.attributeName),
|
|
8641
|
+
});
|
|
8642
|
+
}
|
|
8643
|
+
});
|
|
8644
|
+
if (changes.length > 0) {
|
|
8645
|
+
this.addEvent('mutation', { changes });
|
|
8646
|
+
}
|
|
8647
|
+
});
|
|
8648
|
+
this.mutationObserver.observe(document.body, {
|
|
8649
|
+
childList: true,
|
|
8650
|
+
subtree: true,
|
|
8651
|
+
attributes: true,
|
|
8652
|
+
attributeFilter: ['class', 'style', 'src', 'href'],
|
|
8653
|
+
});
|
|
8654
|
+
}
|
|
8655
|
+
setupNavigationTracking() {
|
|
8656
|
+
const handler = () => {
|
|
8657
|
+
this.addEvent('navigation', {
|
|
8658
|
+
url: window.location.href,
|
|
8659
|
+
title: document.title,
|
|
8660
|
+
});
|
|
8661
|
+
};
|
|
8662
|
+
window.addEventListener('popstate', handler);
|
|
8663
|
+
this.listeners.push({ element: window, event: 'popstate', handler });
|
|
8664
|
+
}
|
|
8665
|
+
setupResizeTracking() {
|
|
8666
|
+
let throttleTimer = null;
|
|
8667
|
+
const handler = () => {
|
|
8668
|
+
if (throttleTimer)
|
|
8669
|
+
return;
|
|
8670
|
+
throttleTimer = window.setTimeout(() => {
|
|
8671
|
+
throttleTimer = null;
|
|
8672
|
+
}, 200);
|
|
8673
|
+
this.addEvent('resize', {
|
|
8674
|
+
width: window.innerWidth,
|
|
8675
|
+
height: window.innerHeight,
|
|
8676
|
+
});
|
|
8677
|
+
};
|
|
8678
|
+
window.addEventListener('resize', handler, { passive: true });
|
|
8679
|
+
this.listeners.push({ element: window, event: 'resize', handler });
|
|
8680
|
+
}
|
|
8681
|
+
getElementSelector(element) {
|
|
8682
|
+
if (!element || !element.tagName)
|
|
8683
|
+
return '';
|
|
8684
|
+
const parts = [];
|
|
8685
|
+
let current = element;
|
|
8686
|
+
while (current && current.tagName !== 'HTML') {
|
|
8687
|
+
let selector = current.tagName.toLowerCase();
|
|
8688
|
+
if (current.id) {
|
|
8689
|
+
selector += `#${current.id}`;
|
|
8690
|
+
parts.unshift(selector);
|
|
8691
|
+
break;
|
|
8692
|
+
}
|
|
8693
|
+
else if (current.className && typeof current.className === 'string') {
|
|
8694
|
+
const classes = current.className.trim().split(/\s+/).slice(0, 2);
|
|
8695
|
+
if (classes.length > 0 && classes[0]) {
|
|
8696
|
+
selector += `.${classes.join('.')}`;
|
|
8697
|
+
}
|
|
8698
|
+
}
|
|
8699
|
+
parts.unshift(selector);
|
|
8700
|
+
current = current.parentElement;
|
|
8701
|
+
}
|
|
8702
|
+
return parts.slice(-4).join(' > ');
|
|
8703
|
+
}
|
|
8704
|
+
isSensitiveElement(element) {
|
|
8705
|
+
if (this.config.maskInputs) {
|
|
8706
|
+
const type = element.getAttribute('type');
|
|
8707
|
+
if (type === 'password' || type === 'credit-card')
|
|
8708
|
+
return true;
|
|
8709
|
+
}
|
|
8710
|
+
return this.config.maskSelectors.some((selector) => {
|
|
8711
|
+
try {
|
|
8712
|
+
return element.matches(selector);
|
|
8713
|
+
}
|
|
8714
|
+
catch {
|
|
8715
|
+
return false;
|
|
8716
|
+
}
|
|
8717
|
+
});
|
|
8718
|
+
}
|
|
8719
|
+
sanitizeHTML(html) {
|
|
8720
|
+
// Remove script contents
|
|
8721
|
+
html = html.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '<script></script>');
|
|
8722
|
+
// Mask sensitive inputs
|
|
8723
|
+
if (this.config.maskInputs) {
|
|
8724
|
+
html = html.replace(/(<input[^>]*type=["']password["'][^>]*value=["'])[^"']*["']/gi, '$1••••••••"');
|
|
8725
|
+
}
|
|
8726
|
+
// Truncate if too large
|
|
8727
|
+
if (html.length > 500000) {
|
|
8728
|
+
html = html.substring(0, 500000) + '<!-- truncated -->';
|
|
8729
|
+
}
|
|
8730
|
+
return html;
|
|
8731
|
+
}
|
|
8732
|
+
}
|
|
8733
|
+
|
|
4564
8734
|
const CheckFlowContext = createContext(null);
|
|
4565
8735
|
function CheckFlowProvider({ apiKey, options = {}, children }) {
|
|
4566
8736
|
const [checkflow, setCheckflow] = useState(null);
|