humanbehavior-js 0.0.1
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/cjs/index.js +4810 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/react/index.js +218 -0
- package/dist/cjs/react/index.js.map +1 -0
- package/dist/esm/index.js +4801 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/react/index.js +215 -0
- package/dist/esm/react/index.js.map +1 -0
- package/dist/index.min.js +16 -0
- package/dist/index.min.js.map +1 -0
- package/dist/types/index.d.ts +63 -0
- package/dist/types/react/index.d.ts +19 -0
- package/index.d.ts +2 -0
- package/index.js +3 -0
- package/package.json +71 -0
- package/react.d.ts +2 -0
- package/react.js +2 -0
- package/readme.md +57 -0
|
@@ -0,0 +1,4801 @@
|
|
|
1
|
+
/******************************************************************************
|
|
2
|
+
Copyright (c) Microsoft Corporation.
|
|
3
|
+
|
|
4
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
+
purpose with or without fee is hereby granted.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
9
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
11
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
12
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
14
|
+
***************************************************************************** */
|
|
15
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
var __assign = function() {
|
|
19
|
+
__assign = Object.assign || function __assign(t) {
|
|
20
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
21
|
+
s = arguments[i];
|
|
22
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
function __awaiter$1(thisArg, _arguments, P, generator) {
|
|
30
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
31
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
32
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
33
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
34
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
35
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function __generator(thisArg, body) {
|
|
40
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
41
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
42
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
43
|
+
function step(op) {
|
|
44
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
45
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
46
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
47
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
48
|
+
switch (op[0]) {
|
|
49
|
+
case 0: case 1: t = op; break;
|
|
50
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
51
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
52
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
53
|
+
default:
|
|
54
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
55
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
56
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
57
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
58
|
+
if (t[2]) _.ops.pop();
|
|
59
|
+
_.trys.pop(); continue;
|
|
60
|
+
}
|
|
61
|
+
op = body.call(thisArg, _);
|
|
62
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
63
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function __spreadArray(to, from, pack) {
|
|
68
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
69
|
+
if (ar || !(i in from)) {
|
|
70
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
71
|
+
ar[i] = from[i];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
78
|
+
var e = new Error(message);
|
|
79
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
var NodeType;
|
|
83
|
+
(function (NodeType) {
|
|
84
|
+
NodeType[NodeType["Document"] = 0] = "Document";
|
|
85
|
+
NodeType[NodeType["DocumentType"] = 1] = "DocumentType";
|
|
86
|
+
NodeType[NodeType["Element"] = 2] = "Element";
|
|
87
|
+
NodeType[NodeType["Text"] = 3] = "Text";
|
|
88
|
+
NodeType[NodeType["CDATA"] = 4] = "CDATA";
|
|
89
|
+
NodeType[NodeType["Comment"] = 5] = "Comment";
|
|
90
|
+
})(NodeType || (NodeType = {}));
|
|
91
|
+
|
|
92
|
+
function isElement(n) {
|
|
93
|
+
return n.nodeType === n.ELEMENT_NODE;
|
|
94
|
+
}
|
|
95
|
+
function isShadowRoot(n) {
|
|
96
|
+
var host = n === null || n === void 0 ? void 0 : n.host;
|
|
97
|
+
return Boolean((host === null || host === void 0 ? void 0 : host.shadowRoot) === n);
|
|
98
|
+
}
|
|
99
|
+
function isNativeShadowDom(shadowRoot) {
|
|
100
|
+
return Object.prototype.toString.call(shadowRoot) === '[object ShadowRoot]';
|
|
101
|
+
}
|
|
102
|
+
function fixBrowserCompatibilityIssuesInCSS(cssText) {
|
|
103
|
+
if (cssText.includes(' background-clip: text;') &&
|
|
104
|
+
!cssText.includes(' -webkit-background-clip: text;')) {
|
|
105
|
+
cssText = cssText.replace(' background-clip: text;', ' -webkit-background-clip: text; background-clip: text;');
|
|
106
|
+
}
|
|
107
|
+
return cssText;
|
|
108
|
+
}
|
|
109
|
+
function getCssRulesString(s) {
|
|
110
|
+
try {
|
|
111
|
+
var rules = s.rules || s.cssRules;
|
|
112
|
+
return rules
|
|
113
|
+
? fixBrowserCompatibilityIssuesInCSS(Array.from(rules).map(getCssRuleString).join(''))
|
|
114
|
+
: null;
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function getCssRuleString(rule) {
|
|
121
|
+
var cssStringified = rule.cssText;
|
|
122
|
+
if (isCSSImportRule(rule)) {
|
|
123
|
+
try {
|
|
124
|
+
cssStringified = getCssRulesString(rule.styleSheet) || cssStringified;
|
|
125
|
+
}
|
|
126
|
+
catch (_a) {
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return cssStringified;
|
|
130
|
+
}
|
|
131
|
+
function isCSSImportRule(rule) {
|
|
132
|
+
return 'styleSheet' in rule;
|
|
133
|
+
}
|
|
134
|
+
var Mirror = (function () {
|
|
135
|
+
function Mirror() {
|
|
136
|
+
this.idNodeMap = new Map();
|
|
137
|
+
this.nodeMetaMap = new WeakMap();
|
|
138
|
+
}
|
|
139
|
+
Mirror.prototype.getId = function (n) {
|
|
140
|
+
var _a;
|
|
141
|
+
if (!n)
|
|
142
|
+
return -1;
|
|
143
|
+
var id = (_a = this.getMeta(n)) === null || _a === void 0 ? void 0 : _a.id;
|
|
144
|
+
return id !== null && id !== void 0 ? id : -1;
|
|
145
|
+
};
|
|
146
|
+
Mirror.prototype.getNode = function (id) {
|
|
147
|
+
return this.idNodeMap.get(id) || null;
|
|
148
|
+
};
|
|
149
|
+
Mirror.prototype.getIds = function () {
|
|
150
|
+
return Array.from(this.idNodeMap.keys());
|
|
151
|
+
};
|
|
152
|
+
Mirror.prototype.getMeta = function (n) {
|
|
153
|
+
return this.nodeMetaMap.get(n) || null;
|
|
154
|
+
};
|
|
155
|
+
Mirror.prototype.removeNodeFromMap = function (n) {
|
|
156
|
+
var _this = this;
|
|
157
|
+
var id = this.getId(n);
|
|
158
|
+
this.idNodeMap["delete"](id);
|
|
159
|
+
if (n.childNodes) {
|
|
160
|
+
n.childNodes.forEach(function (childNode) {
|
|
161
|
+
return _this.removeNodeFromMap(childNode);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
Mirror.prototype.has = function (id) {
|
|
166
|
+
return this.idNodeMap.has(id);
|
|
167
|
+
};
|
|
168
|
+
Mirror.prototype.hasNode = function (node) {
|
|
169
|
+
return this.nodeMetaMap.has(node);
|
|
170
|
+
};
|
|
171
|
+
Mirror.prototype.add = function (n, meta) {
|
|
172
|
+
var id = meta.id;
|
|
173
|
+
this.idNodeMap.set(id, n);
|
|
174
|
+
this.nodeMetaMap.set(n, meta);
|
|
175
|
+
};
|
|
176
|
+
Mirror.prototype.replace = function (id, n) {
|
|
177
|
+
var oldNode = this.getNode(id);
|
|
178
|
+
if (oldNode) {
|
|
179
|
+
var meta = this.nodeMetaMap.get(oldNode);
|
|
180
|
+
if (meta)
|
|
181
|
+
this.nodeMetaMap.set(n, meta);
|
|
182
|
+
}
|
|
183
|
+
this.idNodeMap.set(id, n);
|
|
184
|
+
};
|
|
185
|
+
Mirror.prototype.reset = function () {
|
|
186
|
+
this.idNodeMap = new Map();
|
|
187
|
+
this.nodeMetaMap = new WeakMap();
|
|
188
|
+
};
|
|
189
|
+
return Mirror;
|
|
190
|
+
}());
|
|
191
|
+
function createMirror() {
|
|
192
|
+
return new Mirror();
|
|
193
|
+
}
|
|
194
|
+
function maskInputValue(_a) {
|
|
195
|
+
var maskInputOptions = _a.maskInputOptions, tagName = _a.tagName, type = _a.type, value = _a.value, maskInputFn = _a.maskInputFn;
|
|
196
|
+
var text = value || '';
|
|
197
|
+
if (maskInputOptions[tagName.toLowerCase()] ||
|
|
198
|
+
maskInputOptions[type]) {
|
|
199
|
+
if (maskInputFn) {
|
|
200
|
+
text = maskInputFn(text);
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
text = '*'.repeat(text.length);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return text;
|
|
207
|
+
}
|
|
208
|
+
var ORIGINAL_ATTRIBUTE_NAME = '__rrweb_original__';
|
|
209
|
+
function is2DCanvasBlank(canvas) {
|
|
210
|
+
var ctx = canvas.getContext('2d');
|
|
211
|
+
if (!ctx)
|
|
212
|
+
return true;
|
|
213
|
+
var chunkSize = 50;
|
|
214
|
+
for (var x = 0; x < canvas.width; x += chunkSize) {
|
|
215
|
+
for (var y = 0; y < canvas.height; y += chunkSize) {
|
|
216
|
+
var getImageData = ctx.getImageData;
|
|
217
|
+
var originalGetImageData = ORIGINAL_ATTRIBUTE_NAME in getImageData
|
|
218
|
+
? getImageData[ORIGINAL_ATTRIBUTE_NAME]
|
|
219
|
+
: getImageData;
|
|
220
|
+
var pixelBuffer = new Uint32Array(originalGetImageData.call(ctx, x, y, Math.min(chunkSize, canvas.width - x), Math.min(chunkSize, canvas.height - y)).data.buffer);
|
|
221
|
+
if (pixelBuffer.some(function (pixel) { return pixel !== 0; }))
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return true;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
var _id = 1;
|
|
229
|
+
var tagNameRegex = new RegExp('[^a-z0-9-_:]');
|
|
230
|
+
var IGNORED_NODE = -2;
|
|
231
|
+
function genId() {
|
|
232
|
+
return _id++;
|
|
233
|
+
}
|
|
234
|
+
function getValidTagName(element) {
|
|
235
|
+
if (element instanceof HTMLFormElement) {
|
|
236
|
+
return 'form';
|
|
237
|
+
}
|
|
238
|
+
var processedTagName = element.tagName.toLowerCase().trim();
|
|
239
|
+
if (tagNameRegex.test(processedTagName)) {
|
|
240
|
+
return 'div';
|
|
241
|
+
}
|
|
242
|
+
return processedTagName;
|
|
243
|
+
}
|
|
244
|
+
function stringifyStyleSheet(sheet) {
|
|
245
|
+
return sheet.cssRules
|
|
246
|
+
? Array.from(sheet.cssRules)
|
|
247
|
+
.map(function (rule) { return rule.cssText || ''; })
|
|
248
|
+
.join('')
|
|
249
|
+
: '';
|
|
250
|
+
}
|
|
251
|
+
function extractOrigin(url) {
|
|
252
|
+
var origin = '';
|
|
253
|
+
if (url.indexOf('//') > -1) {
|
|
254
|
+
origin = url.split('/').slice(0, 3).join('/');
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
origin = url.split('/')[0];
|
|
258
|
+
}
|
|
259
|
+
origin = origin.split('?')[0];
|
|
260
|
+
return origin;
|
|
261
|
+
}
|
|
262
|
+
var canvasService;
|
|
263
|
+
var canvasCtx;
|
|
264
|
+
var URL_IN_CSS_REF = /url\((?:(')([^']*)'|(")(.*?)"|([^)]*))\)/gm;
|
|
265
|
+
var RELATIVE_PATH = /^(?!www\.|(?:http|ftp)s?:\/\/|[A-Za-z]:\\|\/\/|#).*/;
|
|
266
|
+
var DATA_URI = /^(data:)([^,]*),(.*)/i;
|
|
267
|
+
function absoluteToStylesheet(cssText, href) {
|
|
268
|
+
return (cssText || '').replace(URL_IN_CSS_REF, function (origin, quote1, path1, quote2, path2, path3) {
|
|
269
|
+
var filePath = path1 || path2 || path3;
|
|
270
|
+
var maybeQuote = quote1 || quote2 || '';
|
|
271
|
+
if (!filePath) {
|
|
272
|
+
return origin;
|
|
273
|
+
}
|
|
274
|
+
if (!RELATIVE_PATH.test(filePath)) {
|
|
275
|
+
return "url(".concat(maybeQuote).concat(filePath).concat(maybeQuote, ")");
|
|
276
|
+
}
|
|
277
|
+
if (DATA_URI.test(filePath)) {
|
|
278
|
+
return "url(".concat(maybeQuote).concat(filePath).concat(maybeQuote, ")");
|
|
279
|
+
}
|
|
280
|
+
if (filePath[0] === '/') {
|
|
281
|
+
return "url(".concat(maybeQuote).concat(extractOrigin(href) + filePath).concat(maybeQuote, ")");
|
|
282
|
+
}
|
|
283
|
+
var stack = href.split('/');
|
|
284
|
+
var parts = filePath.split('/');
|
|
285
|
+
stack.pop();
|
|
286
|
+
for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
|
|
287
|
+
var part = parts_1[_i];
|
|
288
|
+
if (part === '.') {
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
else if (part === '..') {
|
|
292
|
+
stack.pop();
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
stack.push(part);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return "url(".concat(maybeQuote).concat(stack.join('/')).concat(maybeQuote, ")");
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
var SRCSET_NOT_SPACES = /^[^ \t\n\r\u000c]+/;
|
|
302
|
+
var SRCSET_COMMAS_OR_SPACES = /^[, \t\n\r\u000c]+/;
|
|
303
|
+
function getAbsoluteSrcsetString(doc, attributeValue) {
|
|
304
|
+
if (attributeValue.trim() === '') {
|
|
305
|
+
return attributeValue;
|
|
306
|
+
}
|
|
307
|
+
var pos = 0;
|
|
308
|
+
function collectCharacters(regEx) {
|
|
309
|
+
var chars;
|
|
310
|
+
var match = regEx.exec(attributeValue.substring(pos));
|
|
311
|
+
if (match) {
|
|
312
|
+
chars = match[0];
|
|
313
|
+
pos += chars.length;
|
|
314
|
+
return chars;
|
|
315
|
+
}
|
|
316
|
+
return '';
|
|
317
|
+
}
|
|
318
|
+
var output = [];
|
|
319
|
+
while (true) {
|
|
320
|
+
collectCharacters(SRCSET_COMMAS_OR_SPACES);
|
|
321
|
+
if (pos >= attributeValue.length) {
|
|
322
|
+
break;
|
|
323
|
+
}
|
|
324
|
+
var url = collectCharacters(SRCSET_NOT_SPACES);
|
|
325
|
+
if (url.slice(-1) === ',') {
|
|
326
|
+
url = absoluteToDoc(doc, url.substring(0, url.length - 1));
|
|
327
|
+
output.push(url);
|
|
328
|
+
}
|
|
329
|
+
else {
|
|
330
|
+
var descriptorsStr = '';
|
|
331
|
+
url = absoluteToDoc(doc, url);
|
|
332
|
+
var inParens = false;
|
|
333
|
+
while (true) {
|
|
334
|
+
var c = attributeValue.charAt(pos);
|
|
335
|
+
if (c === '') {
|
|
336
|
+
output.push((url + descriptorsStr).trim());
|
|
337
|
+
break;
|
|
338
|
+
}
|
|
339
|
+
else if (!inParens) {
|
|
340
|
+
if (c === ',') {
|
|
341
|
+
pos += 1;
|
|
342
|
+
output.push((url + descriptorsStr).trim());
|
|
343
|
+
break;
|
|
344
|
+
}
|
|
345
|
+
else if (c === '(') {
|
|
346
|
+
inParens = true;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
else {
|
|
350
|
+
if (c === ')') {
|
|
351
|
+
inParens = false;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
descriptorsStr += c;
|
|
355
|
+
pos += 1;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
return output.join(', ');
|
|
360
|
+
}
|
|
361
|
+
function absoluteToDoc(doc, attributeValue) {
|
|
362
|
+
if (!attributeValue || attributeValue.trim() === '') {
|
|
363
|
+
return attributeValue;
|
|
364
|
+
}
|
|
365
|
+
var a = doc.createElement('a');
|
|
366
|
+
a.href = attributeValue;
|
|
367
|
+
return a.href;
|
|
368
|
+
}
|
|
369
|
+
function isSVGElement(el) {
|
|
370
|
+
return Boolean(el.tagName === 'svg' || el.ownerSVGElement);
|
|
371
|
+
}
|
|
372
|
+
function getHref() {
|
|
373
|
+
var a = document.createElement('a');
|
|
374
|
+
a.href = '';
|
|
375
|
+
return a.href;
|
|
376
|
+
}
|
|
377
|
+
function transformAttribute(doc, tagName, name, value) {
|
|
378
|
+
if (name === 'src' ||
|
|
379
|
+
(name === 'href' && value && !(tagName === 'use' && value[0] === '#'))) {
|
|
380
|
+
return absoluteToDoc(doc, value);
|
|
381
|
+
}
|
|
382
|
+
else if (name === 'xlink:href' && value && value[0] !== '#') {
|
|
383
|
+
return absoluteToDoc(doc, value);
|
|
384
|
+
}
|
|
385
|
+
else if (name === 'background' &&
|
|
386
|
+
value &&
|
|
387
|
+
(tagName === 'table' || tagName === 'td' || tagName === 'th')) {
|
|
388
|
+
return absoluteToDoc(doc, value);
|
|
389
|
+
}
|
|
390
|
+
else if (name === 'srcset' && value) {
|
|
391
|
+
return getAbsoluteSrcsetString(doc, value);
|
|
392
|
+
}
|
|
393
|
+
else if (name === 'style' && value) {
|
|
394
|
+
return absoluteToStylesheet(value, getHref());
|
|
395
|
+
}
|
|
396
|
+
else if (tagName === 'object' && name === 'data' && value) {
|
|
397
|
+
return absoluteToDoc(doc, value);
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
return value;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
function _isBlockedElement(element, blockClass, blockSelector) {
|
|
404
|
+
if (typeof blockClass === 'string') {
|
|
405
|
+
if (element.classList.contains(blockClass)) {
|
|
406
|
+
return true;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
for (var eIndex = element.classList.length; eIndex--;) {
|
|
411
|
+
var className = element.classList[eIndex];
|
|
412
|
+
if (blockClass.test(className)) {
|
|
413
|
+
return true;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
if (blockSelector) {
|
|
418
|
+
return element.matches(blockSelector);
|
|
419
|
+
}
|
|
420
|
+
return false;
|
|
421
|
+
}
|
|
422
|
+
function classMatchesRegex(node, regex, checkAncestors) {
|
|
423
|
+
if (!node)
|
|
424
|
+
return false;
|
|
425
|
+
if (node.nodeType !== node.ELEMENT_NODE) {
|
|
426
|
+
if (!checkAncestors)
|
|
427
|
+
return false;
|
|
428
|
+
return classMatchesRegex(node.parentNode, regex, checkAncestors);
|
|
429
|
+
}
|
|
430
|
+
for (var eIndex = node.classList.length; eIndex--;) {
|
|
431
|
+
var className = node.classList[eIndex];
|
|
432
|
+
if (regex.test(className)) {
|
|
433
|
+
return true;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
if (!checkAncestors)
|
|
437
|
+
return false;
|
|
438
|
+
return classMatchesRegex(node.parentNode, regex, checkAncestors);
|
|
439
|
+
}
|
|
440
|
+
function needMaskingText(node, maskTextClass, maskTextSelector) {
|
|
441
|
+
var el = node.nodeType === node.ELEMENT_NODE
|
|
442
|
+
? node
|
|
443
|
+
: node.parentElement;
|
|
444
|
+
if (el === null)
|
|
445
|
+
return false;
|
|
446
|
+
if (typeof maskTextClass === 'string') {
|
|
447
|
+
if (el.classList.contains(maskTextClass))
|
|
448
|
+
return true;
|
|
449
|
+
if (el.closest(".".concat(maskTextClass)))
|
|
450
|
+
return true;
|
|
451
|
+
}
|
|
452
|
+
else {
|
|
453
|
+
if (classMatchesRegex(el, maskTextClass, true))
|
|
454
|
+
return true;
|
|
455
|
+
}
|
|
456
|
+
if (maskTextSelector) {
|
|
457
|
+
if (el.matches(maskTextSelector))
|
|
458
|
+
return true;
|
|
459
|
+
if (el.closest(maskTextSelector))
|
|
460
|
+
return true;
|
|
461
|
+
}
|
|
462
|
+
return false;
|
|
463
|
+
}
|
|
464
|
+
function onceIframeLoaded(iframeEl, listener, iframeLoadTimeout) {
|
|
465
|
+
var win = iframeEl.contentWindow;
|
|
466
|
+
if (!win) {
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
var fired = false;
|
|
470
|
+
var readyState;
|
|
471
|
+
try {
|
|
472
|
+
readyState = win.document.readyState;
|
|
473
|
+
}
|
|
474
|
+
catch (error) {
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
if (readyState !== 'complete') {
|
|
478
|
+
var timer_1 = setTimeout(function () {
|
|
479
|
+
if (!fired) {
|
|
480
|
+
listener();
|
|
481
|
+
fired = true;
|
|
482
|
+
}
|
|
483
|
+
}, iframeLoadTimeout);
|
|
484
|
+
iframeEl.addEventListener('load', function () {
|
|
485
|
+
clearTimeout(timer_1);
|
|
486
|
+
fired = true;
|
|
487
|
+
listener();
|
|
488
|
+
});
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
var blankUrl = 'about:blank';
|
|
492
|
+
if (win.location.href !== blankUrl ||
|
|
493
|
+
iframeEl.src === blankUrl ||
|
|
494
|
+
iframeEl.src === '') {
|
|
495
|
+
setTimeout(listener, 0);
|
|
496
|
+
return iframeEl.addEventListener('load', listener);
|
|
497
|
+
}
|
|
498
|
+
iframeEl.addEventListener('load', listener);
|
|
499
|
+
}
|
|
500
|
+
function onceStylesheetLoaded(link, listener, styleSheetLoadTimeout) {
|
|
501
|
+
var fired = false;
|
|
502
|
+
var styleSheetLoaded;
|
|
503
|
+
try {
|
|
504
|
+
styleSheetLoaded = link.sheet;
|
|
505
|
+
}
|
|
506
|
+
catch (error) {
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
if (styleSheetLoaded)
|
|
510
|
+
return;
|
|
511
|
+
var timer = setTimeout(function () {
|
|
512
|
+
if (!fired) {
|
|
513
|
+
listener();
|
|
514
|
+
fired = true;
|
|
515
|
+
}
|
|
516
|
+
}, styleSheetLoadTimeout);
|
|
517
|
+
link.addEventListener('load', function () {
|
|
518
|
+
clearTimeout(timer);
|
|
519
|
+
fired = true;
|
|
520
|
+
listener();
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
function serializeNode(n, options) {
|
|
524
|
+
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;
|
|
525
|
+
var rootId = getRootId(doc, mirror);
|
|
526
|
+
switch (n.nodeType) {
|
|
527
|
+
case n.DOCUMENT_NODE:
|
|
528
|
+
if (n.compatMode !== 'CSS1Compat') {
|
|
529
|
+
return {
|
|
530
|
+
type: NodeType.Document,
|
|
531
|
+
childNodes: [],
|
|
532
|
+
compatMode: n.compatMode
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
else {
|
|
536
|
+
return {
|
|
537
|
+
type: NodeType.Document,
|
|
538
|
+
childNodes: []
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
case n.DOCUMENT_TYPE_NODE:
|
|
542
|
+
return {
|
|
543
|
+
type: NodeType.DocumentType,
|
|
544
|
+
name: n.name,
|
|
545
|
+
publicId: n.publicId,
|
|
546
|
+
systemId: n.systemId,
|
|
547
|
+
rootId: rootId
|
|
548
|
+
};
|
|
549
|
+
case n.ELEMENT_NODE:
|
|
550
|
+
return serializeElementNode(n, {
|
|
551
|
+
doc: doc,
|
|
552
|
+
blockClass: blockClass,
|
|
553
|
+
blockSelector: blockSelector,
|
|
554
|
+
inlineStylesheet: inlineStylesheet,
|
|
555
|
+
maskInputOptions: maskInputOptions,
|
|
556
|
+
maskInputFn: maskInputFn,
|
|
557
|
+
dataURLOptions: dataURLOptions,
|
|
558
|
+
inlineImages: inlineImages,
|
|
559
|
+
recordCanvas: recordCanvas,
|
|
560
|
+
keepIframeSrcFn: keepIframeSrcFn,
|
|
561
|
+
newlyAddedElement: newlyAddedElement,
|
|
562
|
+
rootId: rootId
|
|
563
|
+
});
|
|
564
|
+
case n.TEXT_NODE:
|
|
565
|
+
return serializeTextNode(n, {
|
|
566
|
+
maskTextClass: maskTextClass,
|
|
567
|
+
maskTextSelector: maskTextSelector,
|
|
568
|
+
maskTextFn: maskTextFn,
|
|
569
|
+
rootId: rootId
|
|
570
|
+
});
|
|
571
|
+
case n.CDATA_SECTION_NODE:
|
|
572
|
+
return {
|
|
573
|
+
type: NodeType.CDATA,
|
|
574
|
+
textContent: '',
|
|
575
|
+
rootId: rootId
|
|
576
|
+
};
|
|
577
|
+
case n.COMMENT_NODE:
|
|
578
|
+
return {
|
|
579
|
+
type: NodeType.Comment,
|
|
580
|
+
textContent: n.textContent || '',
|
|
581
|
+
rootId: rootId
|
|
582
|
+
};
|
|
583
|
+
default:
|
|
584
|
+
return false;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
function getRootId(doc, mirror) {
|
|
588
|
+
if (!mirror.hasNode(doc))
|
|
589
|
+
return undefined;
|
|
590
|
+
var docId = mirror.getId(doc);
|
|
591
|
+
return docId === 1 ? undefined : docId;
|
|
592
|
+
}
|
|
593
|
+
function serializeTextNode(n, options) {
|
|
594
|
+
var _a;
|
|
595
|
+
var maskTextClass = options.maskTextClass, maskTextSelector = options.maskTextSelector, maskTextFn = options.maskTextFn, rootId = options.rootId;
|
|
596
|
+
var parentTagName = n.parentNode && n.parentNode.tagName;
|
|
597
|
+
var textContent = n.textContent;
|
|
598
|
+
var isStyle = parentTagName === 'STYLE' ? true : undefined;
|
|
599
|
+
var isScript = parentTagName === 'SCRIPT' ? true : undefined;
|
|
600
|
+
if (isStyle && textContent) {
|
|
601
|
+
try {
|
|
602
|
+
if (n.nextSibling || n.previousSibling) {
|
|
603
|
+
}
|
|
604
|
+
else if ((_a = n.parentNode.sheet) === null || _a === void 0 ? void 0 : _a.cssRules) {
|
|
605
|
+
textContent = stringifyStyleSheet(n.parentNode.sheet);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
catch (err) {
|
|
609
|
+
console.warn("Cannot get CSS styles from text's parentNode. Error: ".concat(err), n);
|
|
610
|
+
}
|
|
611
|
+
textContent = absoluteToStylesheet(textContent, getHref());
|
|
612
|
+
}
|
|
613
|
+
if (isScript) {
|
|
614
|
+
textContent = 'SCRIPT_PLACEHOLDER';
|
|
615
|
+
}
|
|
616
|
+
if (!isStyle &&
|
|
617
|
+
!isScript &&
|
|
618
|
+
textContent &&
|
|
619
|
+
needMaskingText(n, maskTextClass, maskTextSelector)) {
|
|
620
|
+
textContent = maskTextFn
|
|
621
|
+
? maskTextFn(textContent)
|
|
622
|
+
: textContent.replace(/[\S]/g, '*');
|
|
623
|
+
}
|
|
624
|
+
return {
|
|
625
|
+
type: NodeType.Text,
|
|
626
|
+
textContent: textContent || '',
|
|
627
|
+
isStyle: isStyle,
|
|
628
|
+
rootId: rootId
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
function serializeElementNode(n, options) {
|
|
632
|
+
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;
|
|
633
|
+
var needBlock = _isBlockedElement(n, blockClass, blockSelector);
|
|
634
|
+
var tagName = getValidTagName(n);
|
|
635
|
+
var attributes = {};
|
|
636
|
+
var len = n.attributes.length;
|
|
637
|
+
for (var i = 0; i < len; i++) {
|
|
638
|
+
var attr = n.attributes[i];
|
|
639
|
+
attributes[attr.name] = transformAttribute(doc, tagName, attr.name, attr.value);
|
|
640
|
+
}
|
|
641
|
+
if (tagName === 'link' && inlineStylesheet) {
|
|
642
|
+
var stylesheet = Array.from(doc.styleSheets).find(function (s) {
|
|
643
|
+
return s.href === n.href;
|
|
644
|
+
});
|
|
645
|
+
var cssText = null;
|
|
646
|
+
if (stylesheet) {
|
|
647
|
+
cssText = getCssRulesString(stylesheet);
|
|
648
|
+
}
|
|
649
|
+
if (cssText) {
|
|
650
|
+
delete attributes.rel;
|
|
651
|
+
delete attributes.href;
|
|
652
|
+
attributes._cssText = absoluteToStylesheet(cssText, stylesheet.href);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
if (tagName === 'style' &&
|
|
656
|
+
n.sheet &&
|
|
657
|
+
!(n.innerText || n.textContent || '').trim().length) {
|
|
658
|
+
var cssText = getCssRulesString(n.sheet);
|
|
659
|
+
if (cssText) {
|
|
660
|
+
attributes._cssText = absoluteToStylesheet(cssText, getHref());
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
if (tagName === 'input' || tagName === 'textarea' || tagName === 'select') {
|
|
664
|
+
var value = n.value;
|
|
665
|
+
var checked = n.checked;
|
|
666
|
+
if (attributes.type !== 'radio' &&
|
|
667
|
+
attributes.type !== 'checkbox' &&
|
|
668
|
+
attributes.type !== 'submit' &&
|
|
669
|
+
attributes.type !== 'button' &&
|
|
670
|
+
value) {
|
|
671
|
+
attributes.value = maskInputValue({
|
|
672
|
+
type: attributes.type,
|
|
673
|
+
tagName: tagName,
|
|
674
|
+
value: value,
|
|
675
|
+
maskInputOptions: maskInputOptions,
|
|
676
|
+
maskInputFn: maskInputFn
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
else if (checked) {
|
|
680
|
+
attributes.checked = checked;
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
if (tagName === 'option') {
|
|
684
|
+
if (n.selected && !maskInputOptions['select']) {
|
|
685
|
+
attributes.selected = true;
|
|
686
|
+
}
|
|
687
|
+
else {
|
|
688
|
+
delete attributes.selected;
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
if (tagName === 'canvas' && recordCanvas) {
|
|
692
|
+
if (n.__context === '2d') {
|
|
693
|
+
if (!is2DCanvasBlank(n)) {
|
|
694
|
+
attributes.rr_dataURL = n.toDataURL(dataURLOptions.type, dataURLOptions.quality);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
else if (!('__context' in n)) {
|
|
698
|
+
var canvasDataURL = n.toDataURL(dataURLOptions.type, dataURLOptions.quality);
|
|
699
|
+
var blankCanvas = document.createElement('canvas');
|
|
700
|
+
blankCanvas.width = n.width;
|
|
701
|
+
blankCanvas.height = n.height;
|
|
702
|
+
var blankCanvasDataURL = blankCanvas.toDataURL(dataURLOptions.type, dataURLOptions.quality);
|
|
703
|
+
if (canvasDataURL !== blankCanvasDataURL) {
|
|
704
|
+
attributes.rr_dataURL = canvasDataURL;
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
if (tagName === 'img' && inlineImages) {
|
|
709
|
+
if (!canvasService) {
|
|
710
|
+
canvasService = doc.createElement('canvas');
|
|
711
|
+
canvasCtx = canvasService.getContext('2d');
|
|
712
|
+
}
|
|
713
|
+
var image_1 = n;
|
|
714
|
+
var oldValue_1 = image_1.crossOrigin;
|
|
715
|
+
image_1.crossOrigin = 'anonymous';
|
|
716
|
+
var recordInlineImage = function () {
|
|
717
|
+
try {
|
|
718
|
+
canvasService.width = image_1.naturalWidth;
|
|
719
|
+
canvasService.height = image_1.naturalHeight;
|
|
720
|
+
canvasCtx.drawImage(image_1, 0, 0);
|
|
721
|
+
attributes.rr_dataURL = canvasService.toDataURL(dataURLOptions.type, dataURLOptions.quality);
|
|
722
|
+
}
|
|
723
|
+
catch (err) {
|
|
724
|
+
console.warn("Cannot inline img src=".concat(image_1.currentSrc, "! Error: ").concat(err));
|
|
725
|
+
}
|
|
726
|
+
oldValue_1
|
|
727
|
+
? (attributes.crossOrigin = oldValue_1)
|
|
728
|
+
: image_1.removeAttribute('crossorigin');
|
|
729
|
+
};
|
|
730
|
+
if (image_1.complete && image_1.naturalWidth !== 0)
|
|
731
|
+
recordInlineImage();
|
|
732
|
+
else
|
|
733
|
+
image_1.onload = recordInlineImage;
|
|
734
|
+
}
|
|
735
|
+
if (tagName === 'audio' || tagName === 'video') {
|
|
736
|
+
attributes.rr_mediaState = n.paused
|
|
737
|
+
? 'paused'
|
|
738
|
+
: 'played';
|
|
739
|
+
attributes.rr_mediaCurrentTime = n.currentTime;
|
|
740
|
+
}
|
|
741
|
+
if (!newlyAddedElement) {
|
|
742
|
+
if (n.scrollLeft) {
|
|
743
|
+
attributes.rr_scrollLeft = n.scrollLeft;
|
|
744
|
+
}
|
|
745
|
+
if (n.scrollTop) {
|
|
746
|
+
attributes.rr_scrollTop = n.scrollTop;
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
if (needBlock) {
|
|
750
|
+
var _d = n.getBoundingClientRect(), width = _d.width, height = _d.height;
|
|
751
|
+
attributes = {
|
|
752
|
+
"class": attributes["class"],
|
|
753
|
+
rr_width: "".concat(width, "px"),
|
|
754
|
+
rr_height: "".concat(height, "px")
|
|
755
|
+
};
|
|
756
|
+
}
|
|
757
|
+
if (tagName === 'iframe' && !keepIframeSrcFn(attributes.src)) {
|
|
758
|
+
if (!n.contentDocument) {
|
|
759
|
+
attributes.rr_src = attributes.src;
|
|
760
|
+
}
|
|
761
|
+
delete attributes.src;
|
|
762
|
+
}
|
|
763
|
+
return {
|
|
764
|
+
type: NodeType.Element,
|
|
765
|
+
tagName: tagName,
|
|
766
|
+
attributes: attributes,
|
|
767
|
+
childNodes: [],
|
|
768
|
+
isSVG: isSVGElement(n) || undefined,
|
|
769
|
+
needBlock: needBlock,
|
|
770
|
+
rootId: rootId
|
|
771
|
+
};
|
|
772
|
+
}
|
|
773
|
+
function lowerIfExists(maybeAttr) {
|
|
774
|
+
if (maybeAttr === undefined) {
|
|
775
|
+
return '';
|
|
776
|
+
}
|
|
777
|
+
else {
|
|
778
|
+
return maybeAttr.toLowerCase();
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
function slimDOMExcluded(sn, slimDOMOptions) {
|
|
782
|
+
if (slimDOMOptions.comment && sn.type === NodeType.Comment) {
|
|
783
|
+
return true;
|
|
784
|
+
}
|
|
785
|
+
else if (sn.type === NodeType.Element) {
|
|
786
|
+
if (slimDOMOptions.script &&
|
|
787
|
+
(sn.tagName === 'script' ||
|
|
788
|
+
(sn.tagName === 'link' &&
|
|
789
|
+
sn.attributes.rel === 'preload' &&
|
|
790
|
+
sn.attributes.as === 'script') ||
|
|
791
|
+
(sn.tagName === 'link' &&
|
|
792
|
+
sn.attributes.rel === 'prefetch' &&
|
|
793
|
+
typeof sn.attributes.href === 'string' &&
|
|
794
|
+
sn.attributes.href.endsWith('.js')))) {
|
|
795
|
+
return true;
|
|
796
|
+
}
|
|
797
|
+
else if (slimDOMOptions.headFavicon &&
|
|
798
|
+
((sn.tagName === 'link' && sn.attributes.rel === 'shortcut icon') ||
|
|
799
|
+
(sn.tagName === 'meta' &&
|
|
800
|
+
(lowerIfExists(sn.attributes.name).match(/^msapplication-tile(image|color)$/) ||
|
|
801
|
+
lowerIfExists(sn.attributes.name) === 'application-name' ||
|
|
802
|
+
lowerIfExists(sn.attributes.rel) === 'icon' ||
|
|
803
|
+
lowerIfExists(sn.attributes.rel) === 'apple-touch-icon' ||
|
|
804
|
+
lowerIfExists(sn.attributes.rel) === 'shortcut icon')))) {
|
|
805
|
+
return true;
|
|
806
|
+
}
|
|
807
|
+
else if (sn.tagName === 'meta') {
|
|
808
|
+
if (slimDOMOptions.headMetaDescKeywords &&
|
|
809
|
+
lowerIfExists(sn.attributes.name).match(/^description|keywords$/)) {
|
|
810
|
+
return true;
|
|
811
|
+
}
|
|
812
|
+
else if (slimDOMOptions.headMetaSocial &&
|
|
813
|
+
(lowerIfExists(sn.attributes.property).match(/^(og|twitter|fb):/) ||
|
|
814
|
+
lowerIfExists(sn.attributes.name).match(/^(og|twitter):/) ||
|
|
815
|
+
lowerIfExists(sn.attributes.name) === 'pinterest')) {
|
|
816
|
+
return true;
|
|
817
|
+
}
|
|
818
|
+
else if (slimDOMOptions.headMetaRobots &&
|
|
819
|
+
(lowerIfExists(sn.attributes.name) === 'robots' ||
|
|
820
|
+
lowerIfExists(sn.attributes.name) === 'googlebot' ||
|
|
821
|
+
lowerIfExists(sn.attributes.name) === 'bingbot')) {
|
|
822
|
+
return true;
|
|
823
|
+
}
|
|
824
|
+
else if (slimDOMOptions.headMetaHttpEquiv &&
|
|
825
|
+
sn.attributes['http-equiv'] !== undefined) {
|
|
826
|
+
return true;
|
|
827
|
+
}
|
|
828
|
+
else if (slimDOMOptions.headMetaAuthorship &&
|
|
829
|
+
(lowerIfExists(sn.attributes.name) === 'author' ||
|
|
830
|
+
lowerIfExists(sn.attributes.name) === 'generator' ||
|
|
831
|
+
lowerIfExists(sn.attributes.name) === 'framework' ||
|
|
832
|
+
lowerIfExists(sn.attributes.name) === 'publisher' ||
|
|
833
|
+
lowerIfExists(sn.attributes.name) === 'progid' ||
|
|
834
|
+
lowerIfExists(sn.attributes.property).match(/^article:/) ||
|
|
835
|
+
lowerIfExists(sn.attributes.property).match(/^product:/))) {
|
|
836
|
+
return true;
|
|
837
|
+
}
|
|
838
|
+
else if (slimDOMOptions.headMetaVerification &&
|
|
839
|
+
(lowerIfExists(sn.attributes.name) === 'google-site-verification' ||
|
|
840
|
+
lowerIfExists(sn.attributes.name) === 'yandex-verification' ||
|
|
841
|
+
lowerIfExists(sn.attributes.name) === 'csrf-token' ||
|
|
842
|
+
lowerIfExists(sn.attributes.name) === 'p:domain_verify' ||
|
|
843
|
+
lowerIfExists(sn.attributes.name) === 'verify-v1' ||
|
|
844
|
+
lowerIfExists(sn.attributes.name) === 'verification' ||
|
|
845
|
+
lowerIfExists(sn.attributes.name) === 'shopify-checkout-api-token')) {
|
|
846
|
+
return true;
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
return false;
|
|
851
|
+
}
|
|
852
|
+
function serializeNodeWithId(n, options) {
|
|
853
|
+
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;
|
|
854
|
+
var _l = options.preserveWhiteSpace, preserveWhiteSpace = _l === void 0 ? true : _l;
|
|
855
|
+
var _serializedNode = serializeNode(n, {
|
|
856
|
+
doc: doc,
|
|
857
|
+
mirror: mirror,
|
|
858
|
+
blockClass: blockClass,
|
|
859
|
+
blockSelector: blockSelector,
|
|
860
|
+
maskTextClass: maskTextClass,
|
|
861
|
+
maskTextSelector: maskTextSelector,
|
|
862
|
+
inlineStylesheet: inlineStylesheet,
|
|
863
|
+
maskInputOptions: maskInputOptions,
|
|
864
|
+
maskTextFn: maskTextFn,
|
|
865
|
+
maskInputFn: maskInputFn,
|
|
866
|
+
dataURLOptions: dataURLOptions,
|
|
867
|
+
inlineImages: inlineImages,
|
|
868
|
+
recordCanvas: recordCanvas,
|
|
869
|
+
keepIframeSrcFn: keepIframeSrcFn,
|
|
870
|
+
newlyAddedElement: newlyAddedElement
|
|
871
|
+
});
|
|
872
|
+
if (!_serializedNode) {
|
|
873
|
+
console.warn(n, 'not serialized');
|
|
874
|
+
return null;
|
|
875
|
+
}
|
|
876
|
+
var id;
|
|
877
|
+
if (mirror.hasNode(n)) {
|
|
878
|
+
id = mirror.getId(n);
|
|
879
|
+
}
|
|
880
|
+
else if (slimDOMExcluded(_serializedNode, slimDOMOptions) ||
|
|
881
|
+
(!preserveWhiteSpace &&
|
|
882
|
+
_serializedNode.type === NodeType.Text &&
|
|
883
|
+
!_serializedNode.isStyle &&
|
|
884
|
+
!_serializedNode.textContent.replace(/^\s+|\s+$/gm, '').length)) {
|
|
885
|
+
id = IGNORED_NODE;
|
|
886
|
+
}
|
|
887
|
+
else {
|
|
888
|
+
id = genId();
|
|
889
|
+
}
|
|
890
|
+
var serializedNode = Object.assign(_serializedNode, { id: id });
|
|
891
|
+
mirror.add(n, serializedNode);
|
|
892
|
+
if (id === IGNORED_NODE) {
|
|
893
|
+
return null;
|
|
894
|
+
}
|
|
895
|
+
if (onSerialize) {
|
|
896
|
+
onSerialize(n);
|
|
897
|
+
}
|
|
898
|
+
var recordChild = !skipChild;
|
|
899
|
+
if (serializedNode.type === NodeType.Element) {
|
|
900
|
+
recordChild = recordChild && !serializedNode.needBlock;
|
|
901
|
+
delete serializedNode.needBlock;
|
|
902
|
+
var shadowRoot = n.shadowRoot;
|
|
903
|
+
if (shadowRoot && isNativeShadowDom(shadowRoot))
|
|
904
|
+
serializedNode.isShadowHost = true;
|
|
905
|
+
}
|
|
906
|
+
if ((serializedNode.type === NodeType.Document ||
|
|
907
|
+
serializedNode.type === NodeType.Element) &&
|
|
908
|
+
recordChild) {
|
|
909
|
+
if (slimDOMOptions.headWhitespace &&
|
|
910
|
+
serializedNode.type === NodeType.Element &&
|
|
911
|
+
serializedNode.tagName === 'head') {
|
|
912
|
+
preserveWhiteSpace = false;
|
|
913
|
+
}
|
|
914
|
+
var bypassOptions = {
|
|
915
|
+
doc: doc,
|
|
916
|
+
mirror: mirror,
|
|
917
|
+
blockClass: blockClass,
|
|
918
|
+
blockSelector: blockSelector,
|
|
919
|
+
maskTextClass: maskTextClass,
|
|
920
|
+
maskTextSelector: maskTextSelector,
|
|
921
|
+
skipChild: skipChild,
|
|
922
|
+
inlineStylesheet: inlineStylesheet,
|
|
923
|
+
maskInputOptions: maskInputOptions,
|
|
924
|
+
maskTextFn: maskTextFn,
|
|
925
|
+
maskInputFn: maskInputFn,
|
|
926
|
+
slimDOMOptions: slimDOMOptions,
|
|
927
|
+
dataURLOptions: dataURLOptions,
|
|
928
|
+
inlineImages: inlineImages,
|
|
929
|
+
recordCanvas: recordCanvas,
|
|
930
|
+
preserveWhiteSpace: preserveWhiteSpace,
|
|
931
|
+
onSerialize: onSerialize,
|
|
932
|
+
onIframeLoad: onIframeLoad,
|
|
933
|
+
iframeLoadTimeout: iframeLoadTimeout,
|
|
934
|
+
onStylesheetLoad: onStylesheetLoad,
|
|
935
|
+
stylesheetLoadTimeout: stylesheetLoadTimeout,
|
|
936
|
+
keepIframeSrcFn: keepIframeSrcFn
|
|
937
|
+
};
|
|
938
|
+
for (var _i = 0, _m = Array.from(n.childNodes); _i < _m.length; _i++) {
|
|
939
|
+
var childN = _m[_i];
|
|
940
|
+
var serializedChildNode = serializeNodeWithId(childN, bypassOptions);
|
|
941
|
+
if (serializedChildNode) {
|
|
942
|
+
serializedNode.childNodes.push(serializedChildNode);
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
if (isElement(n) && n.shadowRoot) {
|
|
946
|
+
for (var _o = 0, _p = Array.from(n.shadowRoot.childNodes); _o < _p.length; _o++) {
|
|
947
|
+
var childN = _p[_o];
|
|
948
|
+
var serializedChildNode = serializeNodeWithId(childN, bypassOptions);
|
|
949
|
+
if (serializedChildNode) {
|
|
950
|
+
isNativeShadowDom(n.shadowRoot) &&
|
|
951
|
+
(serializedChildNode.isShadow = true);
|
|
952
|
+
serializedNode.childNodes.push(serializedChildNode);
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
if (n.parentNode &&
|
|
958
|
+
isShadowRoot(n.parentNode) &&
|
|
959
|
+
isNativeShadowDom(n.parentNode)) {
|
|
960
|
+
serializedNode.isShadow = true;
|
|
961
|
+
}
|
|
962
|
+
if (serializedNode.type === NodeType.Element &&
|
|
963
|
+
serializedNode.tagName === 'iframe') {
|
|
964
|
+
onceIframeLoaded(n, function () {
|
|
965
|
+
var iframeDoc = n.contentDocument;
|
|
966
|
+
if (iframeDoc && onIframeLoad) {
|
|
967
|
+
var serializedIframeNode = serializeNodeWithId(iframeDoc, {
|
|
968
|
+
doc: iframeDoc,
|
|
969
|
+
mirror: mirror,
|
|
970
|
+
blockClass: blockClass,
|
|
971
|
+
blockSelector: blockSelector,
|
|
972
|
+
maskTextClass: maskTextClass,
|
|
973
|
+
maskTextSelector: maskTextSelector,
|
|
974
|
+
skipChild: false,
|
|
975
|
+
inlineStylesheet: inlineStylesheet,
|
|
976
|
+
maskInputOptions: maskInputOptions,
|
|
977
|
+
maskTextFn: maskTextFn,
|
|
978
|
+
maskInputFn: maskInputFn,
|
|
979
|
+
slimDOMOptions: slimDOMOptions,
|
|
980
|
+
dataURLOptions: dataURLOptions,
|
|
981
|
+
inlineImages: inlineImages,
|
|
982
|
+
recordCanvas: recordCanvas,
|
|
983
|
+
preserveWhiteSpace: preserveWhiteSpace,
|
|
984
|
+
onSerialize: onSerialize,
|
|
985
|
+
onIframeLoad: onIframeLoad,
|
|
986
|
+
iframeLoadTimeout: iframeLoadTimeout,
|
|
987
|
+
onStylesheetLoad: onStylesheetLoad,
|
|
988
|
+
stylesheetLoadTimeout: stylesheetLoadTimeout,
|
|
989
|
+
keepIframeSrcFn: keepIframeSrcFn
|
|
990
|
+
});
|
|
991
|
+
if (serializedIframeNode) {
|
|
992
|
+
onIframeLoad(n, serializedIframeNode);
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
}, iframeLoadTimeout);
|
|
996
|
+
}
|
|
997
|
+
if (serializedNode.type === NodeType.Element &&
|
|
998
|
+
serializedNode.tagName === 'link' &&
|
|
999
|
+
serializedNode.attributes.rel === 'stylesheet') {
|
|
1000
|
+
onceStylesheetLoaded(n, function () {
|
|
1001
|
+
if (onStylesheetLoad) {
|
|
1002
|
+
var serializedLinkNode = serializeNodeWithId(n, {
|
|
1003
|
+
doc: doc,
|
|
1004
|
+
mirror: mirror,
|
|
1005
|
+
blockClass: blockClass,
|
|
1006
|
+
blockSelector: blockSelector,
|
|
1007
|
+
maskTextClass: maskTextClass,
|
|
1008
|
+
maskTextSelector: maskTextSelector,
|
|
1009
|
+
skipChild: false,
|
|
1010
|
+
inlineStylesheet: inlineStylesheet,
|
|
1011
|
+
maskInputOptions: maskInputOptions,
|
|
1012
|
+
maskTextFn: maskTextFn,
|
|
1013
|
+
maskInputFn: maskInputFn,
|
|
1014
|
+
slimDOMOptions: slimDOMOptions,
|
|
1015
|
+
dataURLOptions: dataURLOptions,
|
|
1016
|
+
inlineImages: inlineImages,
|
|
1017
|
+
recordCanvas: recordCanvas,
|
|
1018
|
+
preserveWhiteSpace: preserveWhiteSpace,
|
|
1019
|
+
onSerialize: onSerialize,
|
|
1020
|
+
onIframeLoad: onIframeLoad,
|
|
1021
|
+
iframeLoadTimeout: iframeLoadTimeout,
|
|
1022
|
+
onStylesheetLoad: onStylesheetLoad,
|
|
1023
|
+
stylesheetLoadTimeout: stylesheetLoadTimeout,
|
|
1024
|
+
keepIframeSrcFn: keepIframeSrcFn
|
|
1025
|
+
});
|
|
1026
|
+
if (serializedLinkNode) {
|
|
1027
|
+
onStylesheetLoad(n, serializedLinkNode);
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
}, stylesheetLoadTimeout);
|
|
1031
|
+
}
|
|
1032
|
+
return serializedNode;
|
|
1033
|
+
}
|
|
1034
|
+
function snapshot(n, options) {
|
|
1035
|
+
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;
|
|
1036
|
+
var maskInputOptions = maskAllInputs === true
|
|
1037
|
+
? {
|
|
1038
|
+
color: true,
|
|
1039
|
+
date: true,
|
|
1040
|
+
'datetime-local': true,
|
|
1041
|
+
email: true,
|
|
1042
|
+
month: true,
|
|
1043
|
+
number: true,
|
|
1044
|
+
range: true,
|
|
1045
|
+
search: true,
|
|
1046
|
+
tel: true,
|
|
1047
|
+
text: true,
|
|
1048
|
+
time: true,
|
|
1049
|
+
url: true,
|
|
1050
|
+
week: true,
|
|
1051
|
+
textarea: true,
|
|
1052
|
+
select: true,
|
|
1053
|
+
password: true
|
|
1054
|
+
}
|
|
1055
|
+
: maskAllInputs === false
|
|
1056
|
+
? {
|
|
1057
|
+
password: true
|
|
1058
|
+
}
|
|
1059
|
+
: maskAllInputs;
|
|
1060
|
+
var slimDOMOptions = slimDOM === true || slimDOM === 'all'
|
|
1061
|
+
?
|
|
1062
|
+
{
|
|
1063
|
+
script: true,
|
|
1064
|
+
comment: true,
|
|
1065
|
+
headFavicon: true,
|
|
1066
|
+
headWhitespace: true,
|
|
1067
|
+
headMetaDescKeywords: slimDOM === 'all',
|
|
1068
|
+
headMetaSocial: true,
|
|
1069
|
+
headMetaRobots: true,
|
|
1070
|
+
headMetaHttpEquiv: true,
|
|
1071
|
+
headMetaAuthorship: true,
|
|
1072
|
+
headMetaVerification: true
|
|
1073
|
+
}
|
|
1074
|
+
: slimDOM === false
|
|
1075
|
+
? {}
|
|
1076
|
+
: slimDOM;
|
|
1077
|
+
return serializeNodeWithId(n, {
|
|
1078
|
+
doc: n,
|
|
1079
|
+
mirror: mirror,
|
|
1080
|
+
blockClass: blockClass,
|
|
1081
|
+
blockSelector: blockSelector,
|
|
1082
|
+
maskTextClass: maskTextClass,
|
|
1083
|
+
maskTextSelector: maskTextSelector,
|
|
1084
|
+
skipChild: false,
|
|
1085
|
+
inlineStylesheet: inlineStylesheet,
|
|
1086
|
+
maskInputOptions: maskInputOptions,
|
|
1087
|
+
maskTextFn: maskTextFn,
|
|
1088
|
+
maskInputFn: maskInputFn,
|
|
1089
|
+
slimDOMOptions: slimDOMOptions,
|
|
1090
|
+
dataURLOptions: dataURLOptions,
|
|
1091
|
+
inlineImages: inlineImages,
|
|
1092
|
+
recordCanvas: recordCanvas,
|
|
1093
|
+
preserveWhiteSpace: preserveWhiteSpace,
|
|
1094
|
+
onSerialize: onSerialize,
|
|
1095
|
+
onIframeLoad: onIframeLoad,
|
|
1096
|
+
iframeLoadTimeout: iframeLoadTimeout,
|
|
1097
|
+
onStylesheetLoad: onStylesheetLoad,
|
|
1098
|
+
stylesheetLoadTimeout: stylesheetLoadTimeout,
|
|
1099
|
+
keepIframeSrcFn: keepIframeSrcFn,
|
|
1100
|
+
newlyAddedElement: false
|
|
1101
|
+
});
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
function on(type, fn, target = document) {
|
|
1105
|
+
const options = { capture: true, passive: true };
|
|
1106
|
+
target.addEventListener(type, fn, options);
|
|
1107
|
+
return () => target.removeEventListener(type, fn, options);
|
|
1108
|
+
}
|
|
1109
|
+
const DEPARTED_MIRROR_ACCESS_WARNING = 'Please stop import mirror directly. Instead of that,' +
|
|
1110
|
+
'\r\n' +
|
|
1111
|
+
'now you can use replayer.getMirror() to access the mirror instance of a replayer,' +
|
|
1112
|
+
'\r\n' +
|
|
1113
|
+
'or you can use record.mirror to access the mirror instance during recording.';
|
|
1114
|
+
let _mirror = {
|
|
1115
|
+
map: {},
|
|
1116
|
+
getId() {
|
|
1117
|
+
console.error(DEPARTED_MIRROR_ACCESS_WARNING);
|
|
1118
|
+
return -1;
|
|
1119
|
+
},
|
|
1120
|
+
getNode() {
|
|
1121
|
+
console.error(DEPARTED_MIRROR_ACCESS_WARNING);
|
|
1122
|
+
return null;
|
|
1123
|
+
},
|
|
1124
|
+
removeNodeFromMap() {
|
|
1125
|
+
console.error(DEPARTED_MIRROR_ACCESS_WARNING);
|
|
1126
|
+
},
|
|
1127
|
+
has() {
|
|
1128
|
+
console.error(DEPARTED_MIRROR_ACCESS_WARNING);
|
|
1129
|
+
return false;
|
|
1130
|
+
},
|
|
1131
|
+
reset() {
|
|
1132
|
+
console.error(DEPARTED_MIRROR_ACCESS_WARNING);
|
|
1133
|
+
},
|
|
1134
|
+
};
|
|
1135
|
+
if (typeof window !== 'undefined' && window.Proxy && window.Reflect) {
|
|
1136
|
+
_mirror = new Proxy(_mirror, {
|
|
1137
|
+
get(target, prop, receiver) {
|
|
1138
|
+
if (prop === 'map') {
|
|
1139
|
+
console.error(DEPARTED_MIRROR_ACCESS_WARNING);
|
|
1140
|
+
}
|
|
1141
|
+
return Reflect.get(target, prop, receiver);
|
|
1142
|
+
},
|
|
1143
|
+
});
|
|
1144
|
+
}
|
|
1145
|
+
function throttle(func, wait, options = {}) {
|
|
1146
|
+
let timeout = null;
|
|
1147
|
+
let previous = 0;
|
|
1148
|
+
return function (...args) {
|
|
1149
|
+
const now = Date.now();
|
|
1150
|
+
if (!previous && options.leading === false) {
|
|
1151
|
+
previous = now;
|
|
1152
|
+
}
|
|
1153
|
+
const remaining = wait - (now - previous);
|
|
1154
|
+
const context = this;
|
|
1155
|
+
if (remaining <= 0 || remaining > wait) {
|
|
1156
|
+
if (timeout) {
|
|
1157
|
+
clearTimeout(timeout);
|
|
1158
|
+
timeout = null;
|
|
1159
|
+
}
|
|
1160
|
+
previous = now;
|
|
1161
|
+
func.apply(context, args);
|
|
1162
|
+
}
|
|
1163
|
+
else if (!timeout && options.trailing !== false) {
|
|
1164
|
+
timeout = setTimeout(() => {
|
|
1165
|
+
previous = options.leading === false ? 0 : Date.now();
|
|
1166
|
+
timeout = null;
|
|
1167
|
+
func.apply(context, args);
|
|
1168
|
+
}, remaining);
|
|
1169
|
+
}
|
|
1170
|
+
};
|
|
1171
|
+
}
|
|
1172
|
+
function hookSetter(target, key, d, isRevoked, win = window) {
|
|
1173
|
+
const original = win.Object.getOwnPropertyDescriptor(target, key);
|
|
1174
|
+
win.Object.defineProperty(target, key, isRevoked
|
|
1175
|
+
? d
|
|
1176
|
+
: {
|
|
1177
|
+
set(value) {
|
|
1178
|
+
setTimeout(() => {
|
|
1179
|
+
d.set.call(this, value);
|
|
1180
|
+
}, 0);
|
|
1181
|
+
if (original && original.set) {
|
|
1182
|
+
original.set.call(this, value);
|
|
1183
|
+
}
|
|
1184
|
+
},
|
|
1185
|
+
});
|
|
1186
|
+
return () => hookSetter(target, key, original || {}, true);
|
|
1187
|
+
}
|
|
1188
|
+
function patch(source, name, replacement) {
|
|
1189
|
+
try {
|
|
1190
|
+
if (!(name in source)) {
|
|
1191
|
+
return () => {
|
|
1192
|
+
};
|
|
1193
|
+
}
|
|
1194
|
+
const original = source[name];
|
|
1195
|
+
const wrapped = replacement(original);
|
|
1196
|
+
if (typeof wrapped === 'function') {
|
|
1197
|
+
wrapped.prototype = wrapped.prototype || {};
|
|
1198
|
+
Object.defineProperties(wrapped, {
|
|
1199
|
+
__rrweb_original__: {
|
|
1200
|
+
enumerable: false,
|
|
1201
|
+
value: original,
|
|
1202
|
+
},
|
|
1203
|
+
});
|
|
1204
|
+
}
|
|
1205
|
+
source[name] = wrapped;
|
|
1206
|
+
return () => {
|
|
1207
|
+
source[name] = original;
|
|
1208
|
+
};
|
|
1209
|
+
}
|
|
1210
|
+
catch (_a) {
|
|
1211
|
+
return () => {
|
|
1212
|
+
};
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
function getWindowHeight() {
|
|
1216
|
+
return (window.innerHeight ||
|
|
1217
|
+
(document.documentElement && document.documentElement.clientHeight) ||
|
|
1218
|
+
(document.body && document.body.clientHeight));
|
|
1219
|
+
}
|
|
1220
|
+
function getWindowWidth() {
|
|
1221
|
+
return (window.innerWidth ||
|
|
1222
|
+
(document.documentElement && document.documentElement.clientWidth) ||
|
|
1223
|
+
(document.body && document.body.clientWidth));
|
|
1224
|
+
}
|
|
1225
|
+
function isBlocked(node, blockClass, blockSelector, checkAncestors) {
|
|
1226
|
+
if (!node) {
|
|
1227
|
+
return false;
|
|
1228
|
+
}
|
|
1229
|
+
const el = node.nodeType === node.ELEMENT_NODE
|
|
1230
|
+
? node
|
|
1231
|
+
: node.parentElement;
|
|
1232
|
+
if (!el)
|
|
1233
|
+
return false;
|
|
1234
|
+
if (typeof blockClass === 'string') {
|
|
1235
|
+
if (el.classList.contains(blockClass))
|
|
1236
|
+
return true;
|
|
1237
|
+
if (checkAncestors && el.closest('.' + blockClass) !== null)
|
|
1238
|
+
return true;
|
|
1239
|
+
}
|
|
1240
|
+
else {
|
|
1241
|
+
if (classMatchesRegex(el, blockClass, checkAncestors))
|
|
1242
|
+
return true;
|
|
1243
|
+
}
|
|
1244
|
+
if (blockSelector) {
|
|
1245
|
+
if (node.matches(blockSelector))
|
|
1246
|
+
return true;
|
|
1247
|
+
if (checkAncestors && el.closest(blockSelector) !== null)
|
|
1248
|
+
return true;
|
|
1249
|
+
}
|
|
1250
|
+
return false;
|
|
1251
|
+
}
|
|
1252
|
+
function isSerialized(n, mirror) {
|
|
1253
|
+
return mirror.getId(n) !== -1;
|
|
1254
|
+
}
|
|
1255
|
+
function isIgnored(n, mirror) {
|
|
1256
|
+
return mirror.getId(n) === IGNORED_NODE;
|
|
1257
|
+
}
|
|
1258
|
+
function isAncestorRemoved(target, mirror) {
|
|
1259
|
+
if (isShadowRoot(target)) {
|
|
1260
|
+
return false;
|
|
1261
|
+
}
|
|
1262
|
+
const id = mirror.getId(target);
|
|
1263
|
+
if (!mirror.has(id)) {
|
|
1264
|
+
return true;
|
|
1265
|
+
}
|
|
1266
|
+
if (target.parentNode &&
|
|
1267
|
+
target.parentNode.nodeType === target.DOCUMENT_NODE) {
|
|
1268
|
+
return false;
|
|
1269
|
+
}
|
|
1270
|
+
if (!target.parentNode) {
|
|
1271
|
+
return true;
|
|
1272
|
+
}
|
|
1273
|
+
return isAncestorRemoved(target.parentNode, mirror);
|
|
1274
|
+
}
|
|
1275
|
+
function isTouchEvent(event) {
|
|
1276
|
+
return Boolean(event.changedTouches);
|
|
1277
|
+
}
|
|
1278
|
+
function polyfill(win = window) {
|
|
1279
|
+
if ('NodeList' in win && !win.NodeList.prototype.forEach) {
|
|
1280
|
+
win.NodeList.prototype.forEach = Array.prototype
|
|
1281
|
+
.forEach;
|
|
1282
|
+
}
|
|
1283
|
+
if ('DOMTokenList' in win && !win.DOMTokenList.prototype.forEach) {
|
|
1284
|
+
win.DOMTokenList.prototype.forEach = Array.prototype
|
|
1285
|
+
.forEach;
|
|
1286
|
+
}
|
|
1287
|
+
if (!Node.prototype.contains) {
|
|
1288
|
+
Node.prototype.contains = (...args) => {
|
|
1289
|
+
let node = args[0];
|
|
1290
|
+
if (!(0 in args)) {
|
|
1291
|
+
throw new TypeError('1 argument is required');
|
|
1292
|
+
}
|
|
1293
|
+
do {
|
|
1294
|
+
if (this === node) {
|
|
1295
|
+
return true;
|
|
1296
|
+
}
|
|
1297
|
+
} while ((node = node && node.parentNode));
|
|
1298
|
+
return false;
|
|
1299
|
+
};
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
function isSerializedIframe(n, mirror) {
|
|
1303
|
+
return Boolean(n.nodeName === 'IFRAME' && mirror.getMeta(n));
|
|
1304
|
+
}
|
|
1305
|
+
function isSerializedStylesheet(n, mirror) {
|
|
1306
|
+
return Boolean(n.nodeName === 'LINK' &&
|
|
1307
|
+
n.nodeType === n.ELEMENT_NODE &&
|
|
1308
|
+
n.getAttribute &&
|
|
1309
|
+
n.getAttribute('rel') === 'stylesheet' &&
|
|
1310
|
+
mirror.getMeta(n));
|
|
1311
|
+
}
|
|
1312
|
+
function hasShadowRoot(n) {
|
|
1313
|
+
return Boolean(n === null || n === void 0 ? void 0 : n.shadowRoot);
|
|
1314
|
+
}
|
|
1315
|
+
class StyleSheetMirror {
|
|
1316
|
+
constructor() {
|
|
1317
|
+
this.id = 1;
|
|
1318
|
+
this.styleIDMap = new WeakMap();
|
|
1319
|
+
this.idStyleMap = new Map();
|
|
1320
|
+
}
|
|
1321
|
+
getId(stylesheet) {
|
|
1322
|
+
var _a;
|
|
1323
|
+
return (_a = this.styleIDMap.get(stylesheet)) !== null && _a !== void 0 ? _a : -1;
|
|
1324
|
+
}
|
|
1325
|
+
has(stylesheet) {
|
|
1326
|
+
return this.styleIDMap.has(stylesheet);
|
|
1327
|
+
}
|
|
1328
|
+
add(stylesheet, id) {
|
|
1329
|
+
if (this.has(stylesheet))
|
|
1330
|
+
return this.getId(stylesheet);
|
|
1331
|
+
let newId;
|
|
1332
|
+
if (id === undefined) {
|
|
1333
|
+
newId = this.id++;
|
|
1334
|
+
}
|
|
1335
|
+
else
|
|
1336
|
+
newId = id;
|
|
1337
|
+
this.styleIDMap.set(stylesheet, newId);
|
|
1338
|
+
this.idStyleMap.set(newId, stylesheet);
|
|
1339
|
+
return newId;
|
|
1340
|
+
}
|
|
1341
|
+
getStyle(id) {
|
|
1342
|
+
return this.idStyleMap.get(id) || null;
|
|
1343
|
+
}
|
|
1344
|
+
reset() {
|
|
1345
|
+
this.styleIDMap = new WeakMap();
|
|
1346
|
+
this.idStyleMap = new Map();
|
|
1347
|
+
this.id = 1;
|
|
1348
|
+
}
|
|
1349
|
+
generateId() {
|
|
1350
|
+
return this.id++;
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
|
|
1354
|
+
var EventType = /* @__PURE__ */ ((EventType2) => {
|
|
1355
|
+
EventType2[EventType2["DomContentLoaded"] = 0] = "DomContentLoaded";
|
|
1356
|
+
EventType2[EventType2["Load"] = 1] = "Load";
|
|
1357
|
+
EventType2[EventType2["FullSnapshot"] = 2] = "FullSnapshot";
|
|
1358
|
+
EventType2[EventType2["IncrementalSnapshot"] = 3] = "IncrementalSnapshot";
|
|
1359
|
+
EventType2[EventType2["Meta"] = 4] = "Meta";
|
|
1360
|
+
EventType2[EventType2["Custom"] = 5] = "Custom";
|
|
1361
|
+
EventType2[EventType2["Plugin"] = 6] = "Plugin";
|
|
1362
|
+
return EventType2;
|
|
1363
|
+
})(EventType || {});
|
|
1364
|
+
var IncrementalSource = /* @__PURE__ */ ((IncrementalSource2) => {
|
|
1365
|
+
IncrementalSource2[IncrementalSource2["Mutation"] = 0] = "Mutation";
|
|
1366
|
+
IncrementalSource2[IncrementalSource2["MouseMove"] = 1] = "MouseMove";
|
|
1367
|
+
IncrementalSource2[IncrementalSource2["MouseInteraction"] = 2] = "MouseInteraction";
|
|
1368
|
+
IncrementalSource2[IncrementalSource2["Scroll"] = 3] = "Scroll";
|
|
1369
|
+
IncrementalSource2[IncrementalSource2["ViewportResize"] = 4] = "ViewportResize";
|
|
1370
|
+
IncrementalSource2[IncrementalSource2["Input"] = 5] = "Input";
|
|
1371
|
+
IncrementalSource2[IncrementalSource2["TouchMove"] = 6] = "TouchMove";
|
|
1372
|
+
IncrementalSource2[IncrementalSource2["MediaInteraction"] = 7] = "MediaInteraction";
|
|
1373
|
+
IncrementalSource2[IncrementalSource2["StyleSheetRule"] = 8] = "StyleSheetRule";
|
|
1374
|
+
IncrementalSource2[IncrementalSource2["CanvasMutation"] = 9] = "CanvasMutation";
|
|
1375
|
+
IncrementalSource2[IncrementalSource2["Font"] = 10] = "Font";
|
|
1376
|
+
IncrementalSource2[IncrementalSource2["Log"] = 11] = "Log";
|
|
1377
|
+
IncrementalSource2[IncrementalSource2["Drag"] = 12] = "Drag";
|
|
1378
|
+
IncrementalSource2[IncrementalSource2["StyleDeclaration"] = 13] = "StyleDeclaration";
|
|
1379
|
+
IncrementalSource2[IncrementalSource2["Selection"] = 14] = "Selection";
|
|
1380
|
+
IncrementalSource2[IncrementalSource2["AdoptedStyleSheet"] = 15] = "AdoptedStyleSheet";
|
|
1381
|
+
return IncrementalSource2;
|
|
1382
|
+
})(IncrementalSource || {});
|
|
1383
|
+
var MouseInteractions = /* @__PURE__ */ ((MouseInteractions2) => {
|
|
1384
|
+
MouseInteractions2[MouseInteractions2["MouseUp"] = 0] = "MouseUp";
|
|
1385
|
+
MouseInteractions2[MouseInteractions2["MouseDown"] = 1] = "MouseDown";
|
|
1386
|
+
MouseInteractions2[MouseInteractions2["Click"] = 2] = "Click";
|
|
1387
|
+
MouseInteractions2[MouseInteractions2["ContextMenu"] = 3] = "ContextMenu";
|
|
1388
|
+
MouseInteractions2[MouseInteractions2["DblClick"] = 4] = "DblClick";
|
|
1389
|
+
MouseInteractions2[MouseInteractions2["Focus"] = 5] = "Focus";
|
|
1390
|
+
MouseInteractions2[MouseInteractions2["Blur"] = 6] = "Blur";
|
|
1391
|
+
MouseInteractions2[MouseInteractions2["TouchStart"] = 7] = "TouchStart";
|
|
1392
|
+
MouseInteractions2[MouseInteractions2["TouchMove_Departed"] = 8] = "TouchMove_Departed";
|
|
1393
|
+
MouseInteractions2[MouseInteractions2["TouchEnd"] = 9] = "TouchEnd";
|
|
1394
|
+
MouseInteractions2[MouseInteractions2["TouchCancel"] = 10] = "TouchCancel";
|
|
1395
|
+
return MouseInteractions2;
|
|
1396
|
+
})(MouseInteractions || {});
|
|
1397
|
+
var CanvasContext = /* @__PURE__ */ ((CanvasContext2) => {
|
|
1398
|
+
CanvasContext2[CanvasContext2["2D"] = 0] = "2D";
|
|
1399
|
+
CanvasContext2[CanvasContext2["WebGL"] = 1] = "WebGL";
|
|
1400
|
+
CanvasContext2[CanvasContext2["WebGL2"] = 2] = "WebGL2";
|
|
1401
|
+
return CanvasContext2;
|
|
1402
|
+
})(CanvasContext || {});
|
|
1403
|
+
|
|
1404
|
+
function isNodeInLinkedList(n) {
|
|
1405
|
+
return '__ln' in n;
|
|
1406
|
+
}
|
|
1407
|
+
class DoubleLinkedList {
|
|
1408
|
+
constructor() {
|
|
1409
|
+
this.length = 0;
|
|
1410
|
+
this.head = null;
|
|
1411
|
+
}
|
|
1412
|
+
get(position) {
|
|
1413
|
+
if (position >= this.length) {
|
|
1414
|
+
throw new Error('Position outside of list range');
|
|
1415
|
+
}
|
|
1416
|
+
let current = this.head;
|
|
1417
|
+
for (let index = 0; index < position; index++) {
|
|
1418
|
+
current = (current === null || current === void 0 ? void 0 : current.next) || null;
|
|
1419
|
+
}
|
|
1420
|
+
return current;
|
|
1421
|
+
}
|
|
1422
|
+
addNode(n) {
|
|
1423
|
+
const node = {
|
|
1424
|
+
value: n,
|
|
1425
|
+
previous: null,
|
|
1426
|
+
next: null,
|
|
1427
|
+
};
|
|
1428
|
+
n.__ln = node;
|
|
1429
|
+
if (n.previousSibling && isNodeInLinkedList(n.previousSibling)) {
|
|
1430
|
+
const current = n.previousSibling.__ln.next;
|
|
1431
|
+
node.next = current;
|
|
1432
|
+
node.previous = n.previousSibling.__ln;
|
|
1433
|
+
n.previousSibling.__ln.next = node;
|
|
1434
|
+
if (current) {
|
|
1435
|
+
current.previous = node;
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
else if (n.nextSibling &&
|
|
1439
|
+
isNodeInLinkedList(n.nextSibling) &&
|
|
1440
|
+
n.nextSibling.__ln.previous) {
|
|
1441
|
+
const current = n.nextSibling.__ln.previous;
|
|
1442
|
+
node.previous = current;
|
|
1443
|
+
node.next = n.nextSibling.__ln;
|
|
1444
|
+
n.nextSibling.__ln.previous = node;
|
|
1445
|
+
if (current) {
|
|
1446
|
+
current.next = node;
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
else {
|
|
1450
|
+
if (this.head) {
|
|
1451
|
+
this.head.previous = node;
|
|
1452
|
+
}
|
|
1453
|
+
node.next = this.head;
|
|
1454
|
+
this.head = node;
|
|
1455
|
+
}
|
|
1456
|
+
this.length++;
|
|
1457
|
+
}
|
|
1458
|
+
removeNode(n) {
|
|
1459
|
+
const current = n.__ln;
|
|
1460
|
+
if (!this.head) {
|
|
1461
|
+
return;
|
|
1462
|
+
}
|
|
1463
|
+
if (!current.previous) {
|
|
1464
|
+
this.head = current.next;
|
|
1465
|
+
if (this.head) {
|
|
1466
|
+
this.head.previous = null;
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
else {
|
|
1470
|
+
current.previous.next = current.next;
|
|
1471
|
+
if (current.next) {
|
|
1472
|
+
current.next.previous = current.previous;
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
if (n.__ln) {
|
|
1476
|
+
delete n.__ln;
|
|
1477
|
+
}
|
|
1478
|
+
this.length--;
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
const moveKey = (id, parentId) => `${id}@${parentId}`;
|
|
1482
|
+
class MutationBuffer {
|
|
1483
|
+
constructor() {
|
|
1484
|
+
this.frozen = false;
|
|
1485
|
+
this.locked = false;
|
|
1486
|
+
this.texts = [];
|
|
1487
|
+
this.attributes = [];
|
|
1488
|
+
this.removes = [];
|
|
1489
|
+
this.mapRemoves = [];
|
|
1490
|
+
this.movedMap = {};
|
|
1491
|
+
this.addedSet = new Set();
|
|
1492
|
+
this.movedSet = new Set();
|
|
1493
|
+
this.droppedSet = new Set();
|
|
1494
|
+
this.processMutations = (mutations) => {
|
|
1495
|
+
mutations.forEach(this.processMutation);
|
|
1496
|
+
this.emit();
|
|
1497
|
+
};
|
|
1498
|
+
this.emit = () => {
|
|
1499
|
+
if (this.frozen || this.locked) {
|
|
1500
|
+
return;
|
|
1501
|
+
}
|
|
1502
|
+
const adds = [];
|
|
1503
|
+
const addList = new DoubleLinkedList();
|
|
1504
|
+
const getNextId = (n) => {
|
|
1505
|
+
let ns = n;
|
|
1506
|
+
let nextId = IGNORED_NODE;
|
|
1507
|
+
while (nextId === IGNORED_NODE) {
|
|
1508
|
+
ns = ns && ns.nextSibling;
|
|
1509
|
+
nextId = ns && this.mirror.getId(ns);
|
|
1510
|
+
}
|
|
1511
|
+
return nextId;
|
|
1512
|
+
};
|
|
1513
|
+
const pushAdd = (n) => {
|
|
1514
|
+
var _a, _b, _c, _d;
|
|
1515
|
+
let shadowHost = null;
|
|
1516
|
+
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 &&
|
|
1517
|
+
n.getRootNode().host)
|
|
1518
|
+
shadowHost = n.getRootNode().host;
|
|
1519
|
+
let rootShadowHost = shadowHost;
|
|
1520
|
+
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) ===
|
|
1521
|
+
Node.DOCUMENT_FRAGMENT_NODE &&
|
|
1522
|
+
rootShadowHost.getRootNode().host)
|
|
1523
|
+
rootShadowHost = rootShadowHost.getRootNode().host;
|
|
1524
|
+
const notInDoc = !this.doc.contains(n) &&
|
|
1525
|
+
(!rootShadowHost || !this.doc.contains(rootShadowHost));
|
|
1526
|
+
if (!n.parentNode || notInDoc) {
|
|
1527
|
+
return;
|
|
1528
|
+
}
|
|
1529
|
+
const parentId = isShadowRoot(n.parentNode)
|
|
1530
|
+
? this.mirror.getId(shadowHost)
|
|
1531
|
+
: this.mirror.getId(n.parentNode);
|
|
1532
|
+
const nextId = getNextId(n);
|
|
1533
|
+
if (parentId === -1 || nextId === -1) {
|
|
1534
|
+
return addList.addNode(n);
|
|
1535
|
+
}
|
|
1536
|
+
const sn = serializeNodeWithId(n, {
|
|
1537
|
+
doc: this.doc,
|
|
1538
|
+
mirror: this.mirror,
|
|
1539
|
+
blockClass: this.blockClass,
|
|
1540
|
+
blockSelector: this.blockSelector,
|
|
1541
|
+
maskTextClass: this.maskTextClass,
|
|
1542
|
+
maskTextSelector: this.maskTextSelector,
|
|
1543
|
+
skipChild: true,
|
|
1544
|
+
newlyAddedElement: true,
|
|
1545
|
+
inlineStylesheet: this.inlineStylesheet,
|
|
1546
|
+
maskInputOptions: this.maskInputOptions,
|
|
1547
|
+
maskTextFn: this.maskTextFn,
|
|
1548
|
+
maskInputFn: this.maskInputFn,
|
|
1549
|
+
slimDOMOptions: this.slimDOMOptions,
|
|
1550
|
+
dataURLOptions: this.dataURLOptions,
|
|
1551
|
+
recordCanvas: this.recordCanvas,
|
|
1552
|
+
inlineImages: this.inlineImages,
|
|
1553
|
+
onSerialize: (currentN) => {
|
|
1554
|
+
if (isSerializedIframe(currentN, this.mirror)) {
|
|
1555
|
+
this.iframeManager.addIframe(currentN);
|
|
1556
|
+
}
|
|
1557
|
+
if (isSerializedStylesheet(currentN, this.mirror)) {
|
|
1558
|
+
this.stylesheetManager.trackLinkElement(currentN);
|
|
1559
|
+
}
|
|
1560
|
+
if (hasShadowRoot(n)) {
|
|
1561
|
+
this.shadowDomManager.addShadowRoot(n.shadowRoot, this.doc);
|
|
1562
|
+
}
|
|
1563
|
+
},
|
|
1564
|
+
onIframeLoad: (iframe, childSn) => {
|
|
1565
|
+
this.iframeManager.attachIframe(iframe, childSn);
|
|
1566
|
+
this.shadowDomManager.observeAttachShadow(iframe);
|
|
1567
|
+
},
|
|
1568
|
+
onStylesheetLoad: (link, childSn) => {
|
|
1569
|
+
this.stylesheetManager.attachLinkElement(link, childSn);
|
|
1570
|
+
},
|
|
1571
|
+
});
|
|
1572
|
+
if (sn) {
|
|
1573
|
+
adds.push({
|
|
1574
|
+
parentId,
|
|
1575
|
+
nextId,
|
|
1576
|
+
node: sn,
|
|
1577
|
+
});
|
|
1578
|
+
}
|
|
1579
|
+
};
|
|
1580
|
+
while (this.mapRemoves.length) {
|
|
1581
|
+
this.mirror.removeNodeFromMap(this.mapRemoves.shift());
|
|
1582
|
+
}
|
|
1583
|
+
for (const n of Array.from(this.movedSet.values())) {
|
|
1584
|
+
if (isParentRemoved(this.removes, n, this.mirror) &&
|
|
1585
|
+
!this.movedSet.has(n.parentNode)) {
|
|
1586
|
+
continue;
|
|
1587
|
+
}
|
|
1588
|
+
pushAdd(n);
|
|
1589
|
+
}
|
|
1590
|
+
for (const n of Array.from(this.addedSet.values())) {
|
|
1591
|
+
if (!isAncestorInSet(this.droppedSet, n) &&
|
|
1592
|
+
!isParentRemoved(this.removes, n, this.mirror)) {
|
|
1593
|
+
pushAdd(n);
|
|
1594
|
+
}
|
|
1595
|
+
else if (isAncestorInSet(this.movedSet, n)) {
|
|
1596
|
+
pushAdd(n);
|
|
1597
|
+
}
|
|
1598
|
+
else {
|
|
1599
|
+
this.droppedSet.add(n);
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
let candidate = null;
|
|
1603
|
+
while (addList.length) {
|
|
1604
|
+
let node = null;
|
|
1605
|
+
if (candidate) {
|
|
1606
|
+
const parentId = this.mirror.getId(candidate.value.parentNode);
|
|
1607
|
+
const nextId = getNextId(candidate.value);
|
|
1608
|
+
if (parentId !== -1 && nextId !== -1) {
|
|
1609
|
+
node = candidate;
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
if (!node) {
|
|
1613
|
+
for (let index = addList.length - 1; index >= 0; index--) {
|
|
1614
|
+
const _node = addList.get(index);
|
|
1615
|
+
if (_node) {
|
|
1616
|
+
const parentId = this.mirror.getId(_node.value.parentNode);
|
|
1617
|
+
const nextId = getNextId(_node.value);
|
|
1618
|
+
if (nextId === -1)
|
|
1619
|
+
continue;
|
|
1620
|
+
else if (parentId !== -1) {
|
|
1621
|
+
node = _node;
|
|
1622
|
+
break;
|
|
1623
|
+
}
|
|
1624
|
+
else {
|
|
1625
|
+
const unhandledNode = _node.value;
|
|
1626
|
+
if (unhandledNode.parentNode &&
|
|
1627
|
+
unhandledNode.parentNode.nodeType ===
|
|
1628
|
+
Node.DOCUMENT_FRAGMENT_NODE) {
|
|
1629
|
+
const shadowHost = unhandledNode.parentNode
|
|
1630
|
+
.host;
|
|
1631
|
+
const parentId = this.mirror.getId(shadowHost);
|
|
1632
|
+
if (parentId !== -1) {
|
|
1633
|
+
node = _node;
|
|
1634
|
+
break;
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
if (!node) {
|
|
1642
|
+
while (addList.head) {
|
|
1643
|
+
addList.removeNode(addList.head.value);
|
|
1644
|
+
}
|
|
1645
|
+
break;
|
|
1646
|
+
}
|
|
1647
|
+
candidate = node.previous;
|
|
1648
|
+
addList.removeNode(node.value);
|
|
1649
|
+
pushAdd(node.value);
|
|
1650
|
+
}
|
|
1651
|
+
const payload = {
|
|
1652
|
+
texts: this.texts
|
|
1653
|
+
.map((text) => ({
|
|
1654
|
+
id: this.mirror.getId(text.node),
|
|
1655
|
+
value: text.value,
|
|
1656
|
+
}))
|
|
1657
|
+
.filter((text) => this.mirror.has(text.id)),
|
|
1658
|
+
attributes: this.attributes
|
|
1659
|
+
.map((attribute) => ({
|
|
1660
|
+
id: this.mirror.getId(attribute.node),
|
|
1661
|
+
attributes: attribute.attributes,
|
|
1662
|
+
}))
|
|
1663
|
+
.filter((attribute) => this.mirror.has(attribute.id)),
|
|
1664
|
+
removes: this.removes,
|
|
1665
|
+
adds,
|
|
1666
|
+
};
|
|
1667
|
+
if (!payload.texts.length &&
|
|
1668
|
+
!payload.attributes.length &&
|
|
1669
|
+
!payload.removes.length &&
|
|
1670
|
+
!payload.adds.length) {
|
|
1671
|
+
return;
|
|
1672
|
+
}
|
|
1673
|
+
this.texts = [];
|
|
1674
|
+
this.attributes = [];
|
|
1675
|
+
this.removes = [];
|
|
1676
|
+
this.addedSet = new Set();
|
|
1677
|
+
this.movedSet = new Set();
|
|
1678
|
+
this.droppedSet = new Set();
|
|
1679
|
+
this.movedMap = {};
|
|
1680
|
+
this.mutationCb(payload);
|
|
1681
|
+
};
|
|
1682
|
+
this.processMutation = (m) => {
|
|
1683
|
+
if (isIgnored(m.target, this.mirror)) {
|
|
1684
|
+
return;
|
|
1685
|
+
}
|
|
1686
|
+
switch (m.type) {
|
|
1687
|
+
case 'characterData': {
|
|
1688
|
+
const value = m.target.textContent;
|
|
1689
|
+
if (!isBlocked(m.target, this.blockClass, this.blockSelector, false) &&
|
|
1690
|
+
value !== m.oldValue) {
|
|
1691
|
+
this.texts.push({
|
|
1692
|
+
value: needMaskingText(m.target, this.maskTextClass, this.maskTextSelector) && value
|
|
1693
|
+
? this.maskTextFn
|
|
1694
|
+
? this.maskTextFn(value)
|
|
1695
|
+
: value.replace(/[\S]/g, '*')
|
|
1696
|
+
: value,
|
|
1697
|
+
node: m.target,
|
|
1698
|
+
});
|
|
1699
|
+
}
|
|
1700
|
+
break;
|
|
1701
|
+
}
|
|
1702
|
+
case 'attributes': {
|
|
1703
|
+
const target = m.target;
|
|
1704
|
+
let value = m.target.getAttribute(m.attributeName);
|
|
1705
|
+
if (m.attributeName === 'value') {
|
|
1706
|
+
value = maskInputValue({
|
|
1707
|
+
maskInputOptions: this.maskInputOptions,
|
|
1708
|
+
tagName: m.target.tagName,
|
|
1709
|
+
type: m.target.getAttribute('type'),
|
|
1710
|
+
value,
|
|
1711
|
+
maskInputFn: this.maskInputFn,
|
|
1712
|
+
});
|
|
1713
|
+
}
|
|
1714
|
+
if (isBlocked(m.target, this.blockClass, this.blockSelector, false) ||
|
|
1715
|
+
value === m.oldValue) {
|
|
1716
|
+
return;
|
|
1717
|
+
}
|
|
1718
|
+
let item = this.attributes.find((a) => a.node === m.target);
|
|
1719
|
+
if (target.tagName === 'IFRAME' &&
|
|
1720
|
+
m.attributeName === 'src' &&
|
|
1721
|
+
!this.keepIframeSrcFn(value)) {
|
|
1722
|
+
if (!target.contentDocument) {
|
|
1723
|
+
m.attributeName = 'rr_src';
|
|
1724
|
+
}
|
|
1725
|
+
else {
|
|
1726
|
+
return;
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
if (!item) {
|
|
1730
|
+
item = {
|
|
1731
|
+
node: m.target,
|
|
1732
|
+
attributes: {},
|
|
1733
|
+
};
|
|
1734
|
+
this.attributes.push(item);
|
|
1735
|
+
}
|
|
1736
|
+
if (m.attributeName === 'style') {
|
|
1737
|
+
const old = this.doc.createElement('span');
|
|
1738
|
+
if (m.oldValue) {
|
|
1739
|
+
old.setAttribute('style', m.oldValue);
|
|
1740
|
+
}
|
|
1741
|
+
if (item.attributes.style === undefined ||
|
|
1742
|
+
item.attributes.style === null) {
|
|
1743
|
+
item.attributes.style = {};
|
|
1744
|
+
}
|
|
1745
|
+
const styleObj = item.attributes.style;
|
|
1746
|
+
for (const pname of Array.from(target.style)) {
|
|
1747
|
+
const newValue = target.style.getPropertyValue(pname);
|
|
1748
|
+
const newPriority = target.style.getPropertyPriority(pname);
|
|
1749
|
+
if (newValue !== old.style.getPropertyValue(pname) ||
|
|
1750
|
+
newPriority !== old.style.getPropertyPriority(pname)) {
|
|
1751
|
+
if (newPriority === '') {
|
|
1752
|
+
styleObj[pname] = newValue;
|
|
1753
|
+
}
|
|
1754
|
+
else {
|
|
1755
|
+
styleObj[pname] = [newValue, newPriority];
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1759
|
+
for (const pname of Array.from(old.style)) {
|
|
1760
|
+
if (target.style.getPropertyValue(pname) === '') {
|
|
1761
|
+
styleObj[pname] = false;
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
else {
|
|
1766
|
+
item.attributes[m.attributeName] = transformAttribute(this.doc, target.tagName, m.attributeName, value);
|
|
1767
|
+
}
|
|
1768
|
+
break;
|
|
1769
|
+
}
|
|
1770
|
+
case 'childList': {
|
|
1771
|
+
if (isBlocked(m.target, this.blockClass, this.blockSelector, true))
|
|
1772
|
+
return;
|
|
1773
|
+
m.addedNodes.forEach((n) => this.genAdds(n, m.target));
|
|
1774
|
+
m.removedNodes.forEach((n) => {
|
|
1775
|
+
const nodeId = this.mirror.getId(n);
|
|
1776
|
+
const parentId = isShadowRoot(m.target)
|
|
1777
|
+
? this.mirror.getId(m.target.host)
|
|
1778
|
+
: this.mirror.getId(m.target);
|
|
1779
|
+
if (isBlocked(m.target, this.blockClass, this.blockSelector, false) ||
|
|
1780
|
+
isIgnored(n, this.mirror) ||
|
|
1781
|
+
!isSerialized(n, this.mirror)) {
|
|
1782
|
+
return;
|
|
1783
|
+
}
|
|
1784
|
+
if (this.addedSet.has(n)) {
|
|
1785
|
+
deepDelete(this.addedSet, n);
|
|
1786
|
+
this.droppedSet.add(n);
|
|
1787
|
+
}
|
|
1788
|
+
else if (this.addedSet.has(m.target) && nodeId === -1) ;
|
|
1789
|
+
else if (isAncestorRemoved(m.target, this.mirror)) ;
|
|
1790
|
+
else if (this.movedSet.has(n) &&
|
|
1791
|
+
this.movedMap[moveKey(nodeId, parentId)]) {
|
|
1792
|
+
deepDelete(this.movedSet, n);
|
|
1793
|
+
}
|
|
1794
|
+
else {
|
|
1795
|
+
this.removes.push({
|
|
1796
|
+
parentId,
|
|
1797
|
+
id: nodeId,
|
|
1798
|
+
isShadow: isShadowRoot(m.target) && isNativeShadowDom(m.target)
|
|
1799
|
+
? true
|
|
1800
|
+
: undefined,
|
|
1801
|
+
});
|
|
1802
|
+
}
|
|
1803
|
+
this.mapRemoves.push(n);
|
|
1804
|
+
});
|
|
1805
|
+
break;
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
};
|
|
1809
|
+
this.genAdds = (n, target) => {
|
|
1810
|
+
if (this.mirror.hasNode(n)) {
|
|
1811
|
+
if (isIgnored(n, this.mirror)) {
|
|
1812
|
+
return;
|
|
1813
|
+
}
|
|
1814
|
+
this.movedSet.add(n);
|
|
1815
|
+
let targetId = null;
|
|
1816
|
+
if (target && this.mirror.hasNode(target)) {
|
|
1817
|
+
targetId = this.mirror.getId(target);
|
|
1818
|
+
}
|
|
1819
|
+
if (targetId && targetId !== -1) {
|
|
1820
|
+
this.movedMap[moveKey(this.mirror.getId(n), targetId)] = true;
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
else {
|
|
1824
|
+
this.addedSet.add(n);
|
|
1825
|
+
this.droppedSet.delete(n);
|
|
1826
|
+
}
|
|
1827
|
+
if (!isBlocked(n, this.blockClass, this.blockSelector, false))
|
|
1828
|
+
n.childNodes.forEach((childN) => this.genAdds(childN));
|
|
1829
|
+
};
|
|
1830
|
+
}
|
|
1831
|
+
init(options) {
|
|
1832
|
+
[
|
|
1833
|
+
'mutationCb',
|
|
1834
|
+
'blockClass',
|
|
1835
|
+
'blockSelector',
|
|
1836
|
+
'maskTextClass',
|
|
1837
|
+
'maskTextSelector',
|
|
1838
|
+
'inlineStylesheet',
|
|
1839
|
+
'maskInputOptions',
|
|
1840
|
+
'maskTextFn',
|
|
1841
|
+
'maskInputFn',
|
|
1842
|
+
'keepIframeSrcFn',
|
|
1843
|
+
'recordCanvas',
|
|
1844
|
+
'inlineImages',
|
|
1845
|
+
'slimDOMOptions',
|
|
1846
|
+
'dataURLOptions',
|
|
1847
|
+
'doc',
|
|
1848
|
+
'mirror',
|
|
1849
|
+
'iframeManager',
|
|
1850
|
+
'stylesheetManager',
|
|
1851
|
+
'shadowDomManager',
|
|
1852
|
+
'canvasManager',
|
|
1853
|
+
].forEach((key) => {
|
|
1854
|
+
this[key] = options[key];
|
|
1855
|
+
});
|
|
1856
|
+
}
|
|
1857
|
+
freeze() {
|
|
1858
|
+
this.frozen = true;
|
|
1859
|
+
this.canvasManager.freeze();
|
|
1860
|
+
}
|
|
1861
|
+
unfreeze() {
|
|
1862
|
+
this.frozen = false;
|
|
1863
|
+
this.canvasManager.unfreeze();
|
|
1864
|
+
this.emit();
|
|
1865
|
+
}
|
|
1866
|
+
isFrozen() {
|
|
1867
|
+
return this.frozen;
|
|
1868
|
+
}
|
|
1869
|
+
lock() {
|
|
1870
|
+
this.locked = true;
|
|
1871
|
+
this.canvasManager.lock();
|
|
1872
|
+
}
|
|
1873
|
+
unlock() {
|
|
1874
|
+
this.locked = false;
|
|
1875
|
+
this.canvasManager.unlock();
|
|
1876
|
+
this.emit();
|
|
1877
|
+
}
|
|
1878
|
+
reset() {
|
|
1879
|
+
this.shadowDomManager.reset();
|
|
1880
|
+
this.canvasManager.reset();
|
|
1881
|
+
}
|
|
1882
|
+
}
|
|
1883
|
+
function deepDelete(addsSet, n) {
|
|
1884
|
+
addsSet.delete(n);
|
|
1885
|
+
n.childNodes.forEach((childN) => deepDelete(addsSet, childN));
|
|
1886
|
+
}
|
|
1887
|
+
function isParentRemoved(removes, n, mirror) {
|
|
1888
|
+
if (removes.length === 0)
|
|
1889
|
+
return false;
|
|
1890
|
+
return _isParentRemoved(removes, n, mirror);
|
|
1891
|
+
}
|
|
1892
|
+
function _isParentRemoved(removes, n, mirror) {
|
|
1893
|
+
const { parentNode } = n;
|
|
1894
|
+
if (!parentNode) {
|
|
1895
|
+
return false;
|
|
1896
|
+
}
|
|
1897
|
+
const parentId = mirror.getId(parentNode);
|
|
1898
|
+
if (removes.some((r) => r.id === parentId)) {
|
|
1899
|
+
return true;
|
|
1900
|
+
}
|
|
1901
|
+
return _isParentRemoved(removes, parentNode, mirror);
|
|
1902
|
+
}
|
|
1903
|
+
function isAncestorInSet(set, n) {
|
|
1904
|
+
if (set.size === 0)
|
|
1905
|
+
return false;
|
|
1906
|
+
return _isAncestorInSet(set, n);
|
|
1907
|
+
}
|
|
1908
|
+
function _isAncestorInSet(set, n) {
|
|
1909
|
+
const { parentNode } = n;
|
|
1910
|
+
if (!parentNode) {
|
|
1911
|
+
return false;
|
|
1912
|
+
}
|
|
1913
|
+
if (set.has(parentNode)) {
|
|
1914
|
+
return true;
|
|
1915
|
+
}
|
|
1916
|
+
return _isAncestorInSet(set, parentNode);
|
|
1917
|
+
}
|
|
1918
|
+
|
|
1919
|
+
const mutationBuffers = [];
|
|
1920
|
+
const isCSSGroupingRuleSupported = typeof CSSGroupingRule !== 'undefined';
|
|
1921
|
+
const isCSSMediaRuleSupported = typeof CSSMediaRule !== 'undefined';
|
|
1922
|
+
const isCSSSupportsRuleSupported = typeof CSSSupportsRule !== 'undefined';
|
|
1923
|
+
const isCSSConditionRuleSupported = typeof CSSConditionRule !== 'undefined';
|
|
1924
|
+
function getEventTarget(event) {
|
|
1925
|
+
try {
|
|
1926
|
+
if ('composedPath' in event) {
|
|
1927
|
+
const path = event.composedPath();
|
|
1928
|
+
if (path.length) {
|
|
1929
|
+
return path[0];
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
else if ('path' in event && event.path.length) {
|
|
1933
|
+
return event.path[0];
|
|
1934
|
+
}
|
|
1935
|
+
return event.target;
|
|
1936
|
+
}
|
|
1937
|
+
catch (_a) {
|
|
1938
|
+
return event.target;
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
function initMutationObserver(options, rootEl) {
|
|
1942
|
+
var _a, _b;
|
|
1943
|
+
const mutationBuffer = new MutationBuffer();
|
|
1944
|
+
mutationBuffers.push(mutationBuffer);
|
|
1945
|
+
mutationBuffer.init(options);
|
|
1946
|
+
let mutationObserverCtor = window.MutationObserver ||
|
|
1947
|
+
window.__rrMutationObserver;
|
|
1948
|
+
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');
|
|
1949
|
+
if (angularZoneSymbol &&
|
|
1950
|
+
window[angularZoneSymbol]) {
|
|
1951
|
+
mutationObserverCtor = window[angularZoneSymbol];
|
|
1952
|
+
}
|
|
1953
|
+
const observer = new mutationObserverCtor(mutationBuffer.processMutations.bind(mutationBuffer));
|
|
1954
|
+
observer.observe(rootEl, {
|
|
1955
|
+
attributes: true,
|
|
1956
|
+
attributeOldValue: true,
|
|
1957
|
+
characterData: true,
|
|
1958
|
+
characterDataOldValue: true,
|
|
1959
|
+
childList: true,
|
|
1960
|
+
subtree: true,
|
|
1961
|
+
});
|
|
1962
|
+
return observer;
|
|
1963
|
+
}
|
|
1964
|
+
function initMoveObserver({ mousemoveCb, sampling, doc, mirror, }) {
|
|
1965
|
+
if (sampling.mousemove === false) {
|
|
1966
|
+
return () => {
|
|
1967
|
+
};
|
|
1968
|
+
}
|
|
1969
|
+
const threshold = typeof sampling.mousemove === 'number' ? sampling.mousemove : 50;
|
|
1970
|
+
const callbackThreshold = typeof sampling.mousemoveCallback === 'number'
|
|
1971
|
+
? sampling.mousemoveCallback
|
|
1972
|
+
: 500;
|
|
1973
|
+
let positions = [];
|
|
1974
|
+
let timeBaseline;
|
|
1975
|
+
const wrappedCb = throttle((source) => {
|
|
1976
|
+
const totalOffset = Date.now() - timeBaseline;
|
|
1977
|
+
mousemoveCb(positions.map((p) => {
|
|
1978
|
+
p.timeOffset -= totalOffset;
|
|
1979
|
+
return p;
|
|
1980
|
+
}), source);
|
|
1981
|
+
positions = [];
|
|
1982
|
+
timeBaseline = null;
|
|
1983
|
+
}, callbackThreshold);
|
|
1984
|
+
const updatePosition = throttle((evt) => {
|
|
1985
|
+
const target = getEventTarget(evt);
|
|
1986
|
+
const { clientX, clientY } = isTouchEvent(evt)
|
|
1987
|
+
? evt.changedTouches[0]
|
|
1988
|
+
: evt;
|
|
1989
|
+
if (!timeBaseline) {
|
|
1990
|
+
timeBaseline = Date.now();
|
|
1991
|
+
}
|
|
1992
|
+
positions.push({
|
|
1993
|
+
x: clientX,
|
|
1994
|
+
y: clientY,
|
|
1995
|
+
id: mirror.getId(target),
|
|
1996
|
+
timeOffset: Date.now() - timeBaseline,
|
|
1997
|
+
});
|
|
1998
|
+
wrappedCb(typeof DragEvent !== 'undefined' && evt instanceof DragEvent
|
|
1999
|
+
? IncrementalSource.Drag
|
|
2000
|
+
: evt instanceof MouseEvent
|
|
2001
|
+
? IncrementalSource.MouseMove
|
|
2002
|
+
: IncrementalSource.TouchMove);
|
|
2003
|
+
}, threshold, {
|
|
2004
|
+
trailing: false,
|
|
2005
|
+
});
|
|
2006
|
+
const handlers = [
|
|
2007
|
+
on('mousemove', updatePosition, doc),
|
|
2008
|
+
on('touchmove', updatePosition, doc),
|
|
2009
|
+
on('drag', updatePosition, doc),
|
|
2010
|
+
];
|
|
2011
|
+
return () => {
|
|
2012
|
+
handlers.forEach((h) => h());
|
|
2013
|
+
};
|
|
2014
|
+
}
|
|
2015
|
+
function initMouseInteractionObserver({ mouseInteractionCb, doc, mirror, blockClass, blockSelector, sampling, }) {
|
|
2016
|
+
if (sampling.mouseInteraction === false) {
|
|
2017
|
+
return () => {
|
|
2018
|
+
};
|
|
2019
|
+
}
|
|
2020
|
+
const disableMap = sampling.mouseInteraction === true ||
|
|
2021
|
+
sampling.mouseInteraction === undefined
|
|
2022
|
+
? {}
|
|
2023
|
+
: sampling.mouseInteraction;
|
|
2024
|
+
const handlers = [];
|
|
2025
|
+
const getHandler = (eventKey) => {
|
|
2026
|
+
return (event) => {
|
|
2027
|
+
const target = getEventTarget(event);
|
|
2028
|
+
if (isBlocked(target, blockClass, blockSelector, true)) {
|
|
2029
|
+
return;
|
|
2030
|
+
}
|
|
2031
|
+
const e = isTouchEvent(event) ? event.changedTouches[0] : event;
|
|
2032
|
+
if (!e) {
|
|
2033
|
+
return;
|
|
2034
|
+
}
|
|
2035
|
+
const id = mirror.getId(target);
|
|
2036
|
+
const { clientX, clientY } = e;
|
|
2037
|
+
mouseInteractionCb({
|
|
2038
|
+
type: MouseInteractions[eventKey],
|
|
2039
|
+
id,
|
|
2040
|
+
x: clientX,
|
|
2041
|
+
y: clientY,
|
|
2042
|
+
});
|
|
2043
|
+
};
|
|
2044
|
+
};
|
|
2045
|
+
Object.keys(MouseInteractions)
|
|
2046
|
+
.filter((key) => Number.isNaN(Number(key)) &&
|
|
2047
|
+
!key.endsWith('_Departed') &&
|
|
2048
|
+
disableMap[key] !== false)
|
|
2049
|
+
.forEach((eventKey) => {
|
|
2050
|
+
const eventName = eventKey.toLowerCase();
|
|
2051
|
+
const handler = getHandler(eventKey);
|
|
2052
|
+
handlers.push(on(eventName, handler, doc));
|
|
2053
|
+
});
|
|
2054
|
+
return () => {
|
|
2055
|
+
handlers.forEach((h) => h());
|
|
2056
|
+
};
|
|
2057
|
+
}
|
|
2058
|
+
function initScrollObserver({ scrollCb, doc, mirror, blockClass, blockSelector, sampling, }) {
|
|
2059
|
+
const updatePosition = throttle((evt) => {
|
|
2060
|
+
const target = getEventTarget(evt);
|
|
2061
|
+
if (!target || isBlocked(target, blockClass, blockSelector, true)) {
|
|
2062
|
+
return;
|
|
2063
|
+
}
|
|
2064
|
+
const id = mirror.getId(target);
|
|
2065
|
+
if (target === doc) {
|
|
2066
|
+
const scrollEl = (doc.scrollingElement || doc.documentElement);
|
|
2067
|
+
scrollCb({
|
|
2068
|
+
id,
|
|
2069
|
+
x: scrollEl.scrollLeft,
|
|
2070
|
+
y: scrollEl.scrollTop,
|
|
2071
|
+
});
|
|
2072
|
+
}
|
|
2073
|
+
else {
|
|
2074
|
+
scrollCb({
|
|
2075
|
+
id,
|
|
2076
|
+
x: target.scrollLeft,
|
|
2077
|
+
y: target.scrollTop,
|
|
2078
|
+
});
|
|
2079
|
+
}
|
|
2080
|
+
}, sampling.scroll || 100);
|
|
2081
|
+
return on('scroll', updatePosition, doc);
|
|
2082
|
+
}
|
|
2083
|
+
function initViewportResizeObserver({ viewportResizeCb, }) {
|
|
2084
|
+
let lastH = -1;
|
|
2085
|
+
let lastW = -1;
|
|
2086
|
+
const updateDimension = throttle(() => {
|
|
2087
|
+
const height = getWindowHeight();
|
|
2088
|
+
const width = getWindowWidth();
|
|
2089
|
+
if (lastH !== height || lastW !== width) {
|
|
2090
|
+
viewportResizeCb({
|
|
2091
|
+
width: Number(width),
|
|
2092
|
+
height: Number(height),
|
|
2093
|
+
});
|
|
2094
|
+
lastH = height;
|
|
2095
|
+
lastW = width;
|
|
2096
|
+
}
|
|
2097
|
+
}, 200);
|
|
2098
|
+
return on('resize', updateDimension, window);
|
|
2099
|
+
}
|
|
2100
|
+
function wrapEventWithUserTriggeredFlag(v, enable) {
|
|
2101
|
+
const value = Object.assign({}, v);
|
|
2102
|
+
if (!enable)
|
|
2103
|
+
delete value.userTriggered;
|
|
2104
|
+
return value;
|
|
2105
|
+
}
|
|
2106
|
+
const INPUT_TAGS = ['INPUT', 'TEXTAREA', 'SELECT'];
|
|
2107
|
+
const lastInputValueMap = new WeakMap();
|
|
2108
|
+
function initInputObserver({ inputCb, doc, mirror, blockClass, blockSelector, ignoreClass, maskInputOptions, maskInputFn, sampling, userTriggeredOnInput, }) {
|
|
2109
|
+
function eventHandler(event) {
|
|
2110
|
+
let target = getEventTarget(event);
|
|
2111
|
+
const userTriggered = event.isTrusted;
|
|
2112
|
+
if (target && target.tagName === 'OPTION')
|
|
2113
|
+
target = target.parentElement;
|
|
2114
|
+
if (!target ||
|
|
2115
|
+
!target.tagName ||
|
|
2116
|
+
INPUT_TAGS.indexOf(target.tagName) < 0 ||
|
|
2117
|
+
isBlocked(target, blockClass, blockSelector, true)) {
|
|
2118
|
+
return;
|
|
2119
|
+
}
|
|
2120
|
+
const type = target.type;
|
|
2121
|
+
if (target.classList.contains(ignoreClass)) {
|
|
2122
|
+
return;
|
|
2123
|
+
}
|
|
2124
|
+
let text = target.value;
|
|
2125
|
+
let isChecked = false;
|
|
2126
|
+
if (type === 'radio' || type === 'checkbox') {
|
|
2127
|
+
isChecked = target.checked;
|
|
2128
|
+
}
|
|
2129
|
+
else if (maskInputOptions[target.tagName.toLowerCase()] ||
|
|
2130
|
+
maskInputOptions[type]) {
|
|
2131
|
+
text = maskInputValue({
|
|
2132
|
+
maskInputOptions,
|
|
2133
|
+
tagName: target.tagName,
|
|
2134
|
+
type,
|
|
2135
|
+
value: text,
|
|
2136
|
+
maskInputFn,
|
|
2137
|
+
});
|
|
2138
|
+
}
|
|
2139
|
+
cbWithDedup(target, wrapEventWithUserTriggeredFlag({ text, isChecked, userTriggered }, userTriggeredOnInput));
|
|
2140
|
+
const name = target.name;
|
|
2141
|
+
if (type === 'radio' && name && isChecked) {
|
|
2142
|
+
doc
|
|
2143
|
+
.querySelectorAll(`input[type="radio"][name="${name}"]`)
|
|
2144
|
+
.forEach((el) => {
|
|
2145
|
+
if (el !== target) {
|
|
2146
|
+
cbWithDedup(el, wrapEventWithUserTriggeredFlag({
|
|
2147
|
+
text: el.value,
|
|
2148
|
+
isChecked: !isChecked,
|
|
2149
|
+
userTriggered: false,
|
|
2150
|
+
}, userTriggeredOnInput));
|
|
2151
|
+
}
|
|
2152
|
+
});
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
function cbWithDedup(target, v) {
|
|
2156
|
+
const lastInputValue = lastInputValueMap.get(target);
|
|
2157
|
+
if (!lastInputValue ||
|
|
2158
|
+
lastInputValue.text !== v.text ||
|
|
2159
|
+
lastInputValue.isChecked !== v.isChecked) {
|
|
2160
|
+
lastInputValueMap.set(target, v);
|
|
2161
|
+
const id = mirror.getId(target);
|
|
2162
|
+
inputCb(Object.assign(Object.assign({}, v), { id }));
|
|
2163
|
+
}
|
|
2164
|
+
}
|
|
2165
|
+
const events = sampling.input === 'last' ? ['change'] : ['input', 'change'];
|
|
2166
|
+
const handlers = events.map((eventName) => on(eventName, eventHandler, doc));
|
|
2167
|
+
const currentWindow = doc.defaultView;
|
|
2168
|
+
if (!currentWindow) {
|
|
2169
|
+
return () => {
|
|
2170
|
+
handlers.forEach((h) => h());
|
|
2171
|
+
};
|
|
2172
|
+
}
|
|
2173
|
+
const propertyDescriptor = currentWindow.Object.getOwnPropertyDescriptor(currentWindow.HTMLInputElement.prototype, 'value');
|
|
2174
|
+
const hookProperties = [
|
|
2175
|
+
[currentWindow.HTMLInputElement.prototype, 'value'],
|
|
2176
|
+
[currentWindow.HTMLInputElement.prototype, 'checked'],
|
|
2177
|
+
[currentWindow.HTMLSelectElement.prototype, 'value'],
|
|
2178
|
+
[currentWindow.HTMLTextAreaElement.prototype, 'value'],
|
|
2179
|
+
[currentWindow.HTMLSelectElement.prototype, 'selectedIndex'],
|
|
2180
|
+
[currentWindow.HTMLOptionElement.prototype, 'selected'],
|
|
2181
|
+
];
|
|
2182
|
+
if (propertyDescriptor && propertyDescriptor.set) {
|
|
2183
|
+
handlers.push(...hookProperties.map((p) => hookSetter(p[0], p[1], {
|
|
2184
|
+
set() {
|
|
2185
|
+
eventHandler({ target: this });
|
|
2186
|
+
},
|
|
2187
|
+
}, false, currentWindow)));
|
|
2188
|
+
}
|
|
2189
|
+
return () => {
|
|
2190
|
+
handlers.forEach((h) => h());
|
|
2191
|
+
};
|
|
2192
|
+
}
|
|
2193
|
+
function getNestedCSSRulePositions(rule) {
|
|
2194
|
+
const positions = [];
|
|
2195
|
+
function recurse(childRule, pos) {
|
|
2196
|
+
if ((isCSSGroupingRuleSupported &&
|
|
2197
|
+
childRule.parentRule instanceof CSSGroupingRule) ||
|
|
2198
|
+
(isCSSMediaRuleSupported &&
|
|
2199
|
+
childRule.parentRule instanceof CSSMediaRule) ||
|
|
2200
|
+
(isCSSSupportsRuleSupported &&
|
|
2201
|
+
childRule.parentRule instanceof CSSSupportsRule) ||
|
|
2202
|
+
(isCSSConditionRuleSupported &&
|
|
2203
|
+
childRule.parentRule instanceof CSSConditionRule)) {
|
|
2204
|
+
const rules = Array.from(childRule.parentRule.cssRules);
|
|
2205
|
+
const index = rules.indexOf(childRule);
|
|
2206
|
+
pos.unshift(index);
|
|
2207
|
+
}
|
|
2208
|
+
else if (childRule.parentStyleSheet) {
|
|
2209
|
+
const rules = Array.from(childRule.parentStyleSheet.cssRules);
|
|
2210
|
+
const index = rules.indexOf(childRule);
|
|
2211
|
+
pos.unshift(index);
|
|
2212
|
+
}
|
|
2213
|
+
return pos;
|
|
2214
|
+
}
|
|
2215
|
+
return recurse(rule, positions);
|
|
2216
|
+
}
|
|
2217
|
+
function getIdAndStyleId(sheet, mirror, styleMirror) {
|
|
2218
|
+
let id, styleId;
|
|
2219
|
+
if (!sheet)
|
|
2220
|
+
return {};
|
|
2221
|
+
if (sheet.ownerNode)
|
|
2222
|
+
id = mirror.getId(sheet.ownerNode);
|
|
2223
|
+
else
|
|
2224
|
+
styleId = styleMirror.getId(sheet);
|
|
2225
|
+
return {
|
|
2226
|
+
styleId,
|
|
2227
|
+
id,
|
|
2228
|
+
};
|
|
2229
|
+
}
|
|
2230
|
+
function initStyleSheetObserver({ styleSheetRuleCb, mirror, stylesheetManager }, { win }) {
|
|
2231
|
+
const insertRule = win.CSSStyleSheet.prototype.insertRule;
|
|
2232
|
+
win.CSSStyleSheet.prototype.insertRule = function (rule, index) {
|
|
2233
|
+
const { id, styleId } = getIdAndStyleId(this, mirror, stylesheetManager.styleMirror);
|
|
2234
|
+
if ((id && id !== -1) || (styleId && styleId !== -1)) {
|
|
2235
|
+
styleSheetRuleCb({
|
|
2236
|
+
id,
|
|
2237
|
+
styleId,
|
|
2238
|
+
adds: [{ rule, index }],
|
|
2239
|
+
});
|
|
2240
|
+
}
|
|
2241
|
+
return insertRule.apply(this, [rule, index]);
|
|
2242
|
+
};
|
|
2243
|
+
const deleteRule = win.CSSStyleSheet.prototype.deleteRule;
|
|
2244
|
+
win.CSSStyleSheet.prototype.deleteRule = function (index) {
|
|
2245
|
+
const { id, styleId } = getIdAndStyleId(this, mirror, stylesheetManager.styleMirror);
|
|
2246
|
+
if ((id && id !== -1) || (styleId && styleId !== -1)) {
|
|
2247
|
+
styleSheetRuleCb({
|
|
2248
|
+
id,
|
|
2249
|
+
styleId,
|
|
2250
|
+
removes: [{ index }],
|
|
2251
|
+
});
|
|
2252
|
+
}
|
|
2253
|
+
return deleteRule.apply(this, [index]);
|
|
2254
|
+
};
|
|
2255
|
+
let replace;
|
|
2256
|
+
if (win.CSSStyleSheet.prototype.replace) {
|
|
2257
|
+
replace = win.CSSStyleSheet.prototype.replace;
|
|
2258
|
+
win.CSSStyleSheet.prototype.replace = function (text) {
|
|
2259
|
+
const { id, styleId } = getIdAndStyleId(this, mirror, stylesheetManager.styleMirror);
|
|
2260
|
+
if ((id && id !== -1) || (styleId && styleId !== -1)) {
|
|
2261
|
+
styleSheetRuleCb({
|
|
2262
|
+
id,
|
|
2263
|
+
styleId,
|
|
2264
|
+
replace: text,
|
|
2265
|
+
});
|
|
2266
|
+
}
|
|
2267
|
+
return replace.apply(this, [text]);
|
|
2268
|
+
};
|
|
2269
|
+
}
|
|
2270
|
+
let replaceSync;
|
|
2271
|
+
if (win.CSSStyleSheet.prototype.replaceSync) {
|
|
2272
|
+
replaceSync = win.CSSStyleSheet.prototype.replaceSync;
|
|
2273
|
+
win.CSSStyleSheet.prototype.replaceSync = function (text) {
|
|
2274
|
+
const { id, styleId } = getIdAndStyleId(this, mirror, stylesheetManager.styleMirror);
|
|
2275
|
+
if ((id && id !== -1) || (styleId && styleId !== -1)) {
|
|
2276
|
+
styleSheetRuleCb({
|
|
2277
|
+
id,
|
|
2278
|
+
styleId,
|
|
2279
|
+
replaceSync: text,
|
|
2280
|
+
});
|
|
2281
|
+
}
|
|
2282
|
+
return replaceSync.apply(this, [text]);
|
|
2283
|
+
};
|
|
2284
|
+
}
|
|
2285
|
+
const supportedNestedCSSRuleTypes = {};
|
|
2286
|
+
if (isCSSGroupingRuleSupported) {
|
|
2287
|
+
supportedNestedCSSRuleTypes.CSSGroupingRule = win.CSSGroupingRule;
|
|
2288
|
+
}
|
|
2289
|
+
else {
|
|
2290
|
+
if (isCSSMediaRuleSupported) {
|
|
2291
|
+
supportedNestedCSSRuleTypes.CSSMediaRule = win.CSSMediaRule;
|
|
2292
|
+
}
|
|
2293
|
+
if (isCSSConditionRuleSupported) {
|
|
2294
|
+
supportedNestedCSSRuleTypes.CSSConditionRule = win.CSSConditionRule;
|
|
2295
|
+
}
|
|
2296
|
+
if (isCSSSupportsRuleSupported) {
|
|
2297
|
+
supportedNestedCSSRuleTypes.CSSSupportsRule = win.CSSSupportsRule;
|
|
2298
|
+
}
|
|
2299
|
+
}
|
|
2300
|
+
const unmodifiedFunctions = {};
|
|
2301
|
+
Object.entries(supportedNestedCSSRuleTypes).forEach(([typeKey, type]) => {
|
|
2302
|
+
unmodifiedFunctions[typeKey] = {
|
|
2303
|
+
insertRule: type.prototype.insertRule,
|
|
2304
|
+
deleteRule: type.prototype.deleteRule,
|
|
2305
|
+
};
|
|
2306
|
+
type.prototype.insertRule = function (rule, index) {
|
|
2307
|
+
const { id, styleId } = getIdAndStyleId(this.parentStyleSheet, mirror, stylesheetManager.styleMirror);
|
|
2308
|
+
if ((id && id !== -1) || (styleId && styleId !== -1)) {
|
|
2309
|
+
styleSheetRuleCb({
|
|
2310
|
+
id,
|
|
2311
|
+
styleId,
|
|
2312
|
+
adds: [
|
|
2313
|
+
{
|
|
2314
|
+
rule,
|
|
2315
|
+
index: [
|
|
2316
|
+
...getNestedCSSRulePositions(this),
|
|
2317
|
+
index || 0,
|
|
2318
|
+
],
|
|
2319
|
+
},
|
|
2320
|
+
],
|
|
2321
|
+
});
|
|
2322
|
+
}
|
|
2323
|
+
return unmodifiedFunctions[typeKey].insertRule.apply(this, [rule, index]);
|
|
2324
|
+
};
|
|
2325
|
+
type.prototype.deleteRule = function (index) {
|
|
2326
|
+
const { id, styleId } = getIdAndStyleId(this.parentStyleSheet, mirror, stylesheetManager.styleMirror);
|
|
2327
|
+
if ((id && id !== -1) || (styleId && styleId !== -1)) {
|
|
2328
|
+
styleSheetRuleCb({
|
|
2329
|
+
id,
|
|
2330
|
+
styleId,
|
|
2331
|
+
removes: [
|
|
2332
|
+
{ index: [...getNestedCSSRulePositions(this), index] },
|
|
2333
|
+
],
|
|
2334
|
+
});
|
|
2335
|
+
}
|
|
2336
|
+
return unmodifiedFunctions[typeKey].deleteRule.apply(this, [index]);
|
|
2337
|
+
};
|
|
2338
|
+
});
|
|
2339
|
+
return () => {
|
|
2340
|
+
win.CSSStyleSheet.prototype.insertRule = insertRule;
|
|
2341
|
+
win.CSSStyleSheet.prototype.deleteRule = deleteRule;
|
|
2342
|
+
replace && (win.CSSStyleSheet.prototype.replace = replace);
|
|
2343
|
+
replaceSync && (win.CSSStyleSheet.prototype.replaceSync = replaceSync);
|
|
2344
|
+
Object.entries(supportedNestedCSSRuleTypes).forEach(([typeKey, type]) => {
|
|
2345
|
+
type.prototype.insertRule = unmodifiedFunctions[typeKey].insertRule;
|
|
2346
|
+
type.prototype.deleteRule = unmodifiedFunctions[typeKey].deleteRule;
|
|
2347
|
+
});
|
|
2348
|
+
};
|
|
2349
|
+
}
|
|
2350
|
+
function initAdoptedStyleSheetObserver({ mirror, stylesheetManager, }, host) {
|
|
2351
|
+
var _a, _b, _c;
|
|
2352
|
+
let hostId = null;
|
|
2353
|
+
if (host.nodeName === '#document')
|
|
2354
|
+
hostId = mirror.getId(host);
|
|
2355
|
+
else
|
|
2356
|
+
hostId = mirror.getId(host.host);
|
|
2357
|
+
const patchTarget = host.nodeName === '#document'
|
|
2358
|
+
? (_a = host.defaultView) === null || _a === void 0 ? void 0 : _a.Document
|
|
2359
|
+
: (_c = (_b = host.ownerDocument) === null || _b === void 0 ? void 0 : _b.defaultView) === null || _c === void 0 ? void 0 : _c.ShadowRoot;
|
|
2360
|
+
const originalPropertyDescriptor = Object.getOwnPropertyDescriptor(patchTarget === null || patchTarget === void 0 ? void 0 : patchTarget.prototype, 'adoptedStyleSheets');
|
|
2361
|
+
if (hostId === null ||
|
|
2362
|
+
hostId === -1 ||
|
|
2363
|
+
!patchTarget ||
|
|
2364
|
+
!originalPropertyDescriptor)
|
|
2365
|
+
return () => {
|
|
2366
|
+
};
|
|
2367
|
+
Object.defineProperty(host, 'adoptedStyleSheets', {
|
|
2368
|
+
configurable: originalPropertyDescriptor.configurable,
|
|
2369
|
+
enumerable: originalPropertyDescriptor.enumerable,
|
|
2370
|
+
get() {
|
|
2371
|
+
var _a;
|
|
2372
|
+
return (_a = originalPropertyDescriptor.get) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
2373
|
+
},
|
|
2374
|
+
set(sheets) {
|
|
2375
|
+
var _a;
|
|
2376
|
+
const result = (_a = originalPropertyDescriptor.set) === null || _a === void 0 ? void 0 : _a.call(this, sheets);
|
|
2377
|
+
if (hostId !== null && hostId !== -1) {
|
|
2378
|
+
try {
|
|
2379
|
+
stylesheetManager.adoptStyleSheets(sheets, hostId);
|
|
2380
|
+
}
|
|
2381
|
+
catch (e) {
|
|
2382
|
+
}
|
|
2383
|
+
}
|
|
2384
|
+
return result;
|
|
2385
|
+
},
|
|
2386
|
+
});
|
|
2387
|
+
return () => {
|
|
2388
|
+
Object.defineProperty(host, 'adoptedStyleSheets', {
|
|
2389
|
+
configurable: originalPropertyDescriptor.configurable,
|
|
2390
|
+
enumerable: originalPropertyDescriptor.enumerable,
|
|
2391
|
+
get: originalPropertyDescriptor.get,
|
|
2392
|
+
set: originalPropertyDescriptor.set,
|
|
2393
|
+
});
|
|
2394
|
+
};
|
|
2395
|
+
}
|
|
2396
|
+
function initStyleDeclarationObserver({ styleDeclarationCb, mirror, ignoreCSSAttributes, stylesheetManager, }, { win }) {
|
|
2397
|
+
const setProperty = win.CSSStyleDeclaration.prototype.setProperty;
|
|
2398
|
+
win.CSSStyleDeclaration.prototype.setProperty = function (property, value, priority) {
|
|
2399
|
+
var _a;
|
|
2400
|
+
if (ignoreCSSAttributes.has(property)) {
|
|
2401
|
+
return setProperty.apply(this, [property, value, priority]);
|
|
2402
|
+
}
|
|
2403
|
+
const { id, styleId } = getIdAndStyleId((_a = this.parentRule) === null || _a === void 0 ? void 0 : _a.parentStyleSheet, mirror, stylesheetManager.styleMirror);
|
|
2404
|
+
if ((id && id !== -1) || (styleId && styleId !== -1)) {
|
|
2405
|
+
styleDeclarationCb({
|
|
2406
|
+
id,
|
|
2407
|
+
styleId,
|
|
2408
|
+
set: {
|
|
2409
|
+
property,
|
|
2410
|
+
value,
|
|
2411
|
+
priority,
|
|
2412
|
+
},
|
|
2413
|
+
index: getNestedCSSRulePositions(this.parentRule),
|
|
2414
|
+
});
|
|
2415
|
+
}
|
|
2416
|
+
return setProperty.apply(this, [property, value, priority]);
|
|
2417
|
+
};
|
|
2418
|
+
const removeProperty = win.CSSStyleDeclaration.prototype.removeProperty;
|
|
2419
|
+
win.CSSStyleDeclaration.prototype.removeProperty = function (property) {
|
|
2420
|
+
var _a;
|
|
2421
|
+
if (ignoreCSSAttributes.has(property)) {
|
|
2422
|
+
return removeProperty.apply(this, [property]);
|
|
2423
|
+
}
|
|
2424
|
+
const { id, styleId } = getIdAndStyleId((_a = this.parentRule) === null || _a === void 0 ? void 0 : _a.parentStyleSheet, mirror, stylesheetManager.styleMirror);
|
|
2425
|
+
if ((id && id !== -1) || (styleId && styleId !== -1)) {
|
|
2426
|
+
styleDeclarationCb({
|
|
2427
|
+
id,
|
|
2428
|
+
styleId,
|
|
2429
|
+
remove: {
|
|
2430
|
+
property,
|
|
2431
|
+
},
|
|
2432
|
+
index: getNestedCSSRulePositions(this.parentRule),
|
|
2433
|
+
});
|
|
2434
|
+
}
|
|
2435
|
+
return removeProperty.apply(this, [property]);
|
|
2436
|
+
};
|
|
2437
|
+
return () => {
|
|
2438
|
+
win.CSSStyleDeclaration.prototype.setProperty = setProperty;
|
|
2439
|
+
win.CSSStyleDeclaration.prototype.removeProperty = removeProperty;
|
|
2440
|
+
};
|
|
2441
|
+
}
|
|
2442
|
+
function initMediaInteractionObserver({ mediaInteractionCb, blockClass, blockSelector, mirror, sampling, }) {
|
|
2443
|
+
const handler = (type) => throttle((event) => {
|
|
2444
|
+
const target = getEventTarget(event);
|
|
2445
|
+
if (!target ||
|
|
2446
|
+
isBlocked(target, blockClass, blockSelector, true)) {
|
|
2447
|
+
return;
|
|
2448
|
+
}
|
|
2449
|
+
const { currentTime, volume, muted, playbackRate, } = target;
|
|
2450
|
+
mediaInteractionCb({
|
|
2451
|
+
type,
|
|
2452
|
+
id: mirror.getId(target),
|
|
2453
|
+
currentTime,
|
|
2454
|
+
volume,
|
|
2455
|
+
muted,
|
|
2456
|
+
playbackRate,
|
|
2457
|
+
});
|
|
2458
|
+
}, sampling.media || 500);
|
|
2459
|
+
const handlers = [
|
|
2460
|
+
on('play', handler(0)),
|
|
2461
|
+
on('pause', handler(1)),
|
|
2462
|
+
on('seeked', handler(2)),
|
|
2463
|
+
on('volumechange', handler(3)),
|
|
2464
|
+
on('ratechange', handler(4)),
|
|
2465
|
+
];
|
|
2466
|
+
return () => {
|
|
2467
|
+
handlers.forEach((h) => h());
|
|
2468
|
+
};
|
|
2469
|
+
}
|
|
2470
|
+
function initFontObserver({ fontCb, doc }) {
|
|
2471
|
+
const win = doc.defaultView;
|
|
2472
|
+
if (!win) {
|
|
2473
|
+
return () => {
|
|
2474
|
+
};
|
|
2475
|
+
}
|
|
2476
|
+
const handlers = [];
|
|
2477
|
+
const fontMap = new WeakMap();
|
|
2478
|
+
const originalFontFace = win.FontFace;
|
|
2479
|
+
win.FontFace = function FontFace(family, source, descriptors) {
|
|
2480
|
+
const fontFace = new originalFontFace(family, source, descriptors);
|
|
2481
|
+
fontMap.set(fontFace, {
|
|
2482
|
+
family,
|
|
2483
|
+
buffer: typeof source !== 'string',
|
|
2484
|
+
descriptors,
|
|
2485
|
+
fontSource: typeof source === 'string'
|
|
2486
|
+
? source
|
|
2487
|
+
: JSON.stringify(Array.from(new Uint8Array(source))),
|
|
2488
|
+
});
|
|
2489
|
+
return fontFace;
|
|
2490
|
+
};
|
|
2491
|
+
const restoreHandler = patch(doc.fonts, 'add', function (original) {
|
|
2492
|
+
return function (fontFace) {
|
|
2493
|
+
setTimeout(() => {
|
|
2494
|
+
const p = fontMap.get(fontFace);
|
|
2495
|
+
if (p) {
|
|
2496
|
+
fontCb(p);
|
|
2497
|
+
fontMap.delete(fontFace);
|
|
2498
|
+
}
|
|
2499
|
+
}, 0);
|
|
2500
|
+
return original.apply(this, [fontFace]);
|
|
2501
|
+
};
|
|
2502
|
+
});
|
|
2503
|
+
handlers.push(() => {
|
|
2504
|
+
win.FontFace = originalFontFace;
|
|
2505
|
+
});
|
|
2506
|
+
handlers.push(restoreHandler);
|
|
2507
|
+
return () => {
|
|
2508
|
+
handlers.forEach((h) => h());
|
|
2509
|
+
};
|
|
2510
|
+
}
|
|
2511
|
+
function initSelectionObserver(param) {
|
|
2512
|
+
const { doc, mirror, blockClass, blockSelector, selectionCb } = param;
|
|
2513
|
+
let collapsed = true;
|
|
2514
|
+
const updateSelection = () => {
|
|
2515
|
+
const selection = doc.getSelection();
|
|
2516
|
+
if (!selection || (collapsed && (selection === null || selection === void 0 ? void 0 : selection.isCollapsed)))
|
|
2517
|
+
return;
|
|
2518
|
+
collapsed = selection.isCollapsed || false;
|
|
2519
|
+
const ranges = [];
|
|
2520
|
+
const count = selection.rangeCount || 0;
|
|
2521
|
+
for (let i = 0; i < count; i++) {
|
|
2522
|
+
const range = selection.getRangeAt(i);
|
|
2523
|
+
const { startContainer, startOffset, endContainer, endOffset } = range;
|
|
2524
|
+
const blocked = isBlocked(startContainer, blockClass, blockSelector, true) ||
|
|
2525
|
+
isBlocked(endContainer, blockClass, blockSelector, true);
|
|
2526
|
+
if (blocked)
|
|
2527
|
+
continue;
|
|
2528
|
+
ranges.push({
|
|
2529
|
+
start: mirror.getId(startContainer),
|
|
2530
|
+
startOffset,
|
|
2531
|
+
end: mirror.getId(endContainer),
|
|
2532
|
+
endOffset,
|
|
2533
|
+
});
|
|
2534
|
+
}
|
|
2535
|
+
selectionCb({ ranges });
|
|
2536
|
+
};
|
|
2537
|
+
updateSelection();
|
|
2538
|
+
return on('selectionchange', updateSelection);
|
|
2539
|
+
}
|
|
2540
|
+
function mergeHooks(o, hooks) {
|
|
2541
|
+
const { mutationCb, mousemoveCb, mouseInteractionCb, scrollCb, viewportResizeCb, inputCb, mediaInteractionCb, styleSheetRuleCb, styleDeclarationCb, canvasMutationCb, fontCb, selectionCb, } = o;
|
|
2542
|
+
o.mutationCb = (...p) => {
|
|
2543
|
+
if (hooks.mutation) {
|
|
2544
|
+
hooks.mutation(...p);
|
|
2545
|
+
}
|
|
2546
|
+
mutationCb(...p);
|
|
2547
|
+
};
|
|
2548
|
+
o.mousemoveCb = (...p) => {
|
|
2549
|
+
if (hooks.mousemove) {
|
|
2550
|
+
hooks.mousemove(...p);
|
|
2551
|
+
}
|
|
2552
|
+
mousemoveCb(...p);
|
|
2553
|
+
};
|
|
2554
|
+
o.mouseInteractionCb = (...p) => {
|
|
2555
|
+
if (hooks.mouseInteraction) {
|
|
2556
|
+
hooks.mouseInteraction(...p);
|
|
2557
|
+
}
|
|
2558
|
+
mouseInteractionCb(...p);
|
|
2559
|
+
};
|
|
2560
|
+
o.scrollCb = (...p) => {
|
|
2561
|
+
if (hooks.scroll) {
|
|
2562
|
+
hooks.scroll(...p);
|
|
2563
|
+
}
|
|
2564
|
+
scrollCb(...p);
|
|
2565
|
+
};
|
|
2566
|
+
o.viewportResizeCb = (...p) => {
|
|
2567
|
+
if (hooks.viewportResize) {
|
|
2568
|
+
hooks.viewportResize(...p);
|
|
2569
|
+
}
|
|
2570
|
+
viewportResizeCb(...p);
|
|
2571
|
+
};
|
|
2572
|
+
o.inputCb = (...p) => {
|
|
2573
|
+
if (hooks.input) {
|
|
2574
|
+
hooks.input(...p);
|
|
2575
|
+
}
|
|
2576
|
+
inputCb(...p);
|
|
2577
|
+
};
|
|
2578
|
+
o.mediaInteractionCb = (...p) => {
|
|
2579
|
+
if (hooks.mediaInteaction) {
|
|
2580
|
+
hooks.mediaInteaction(...p);
|
|
2581
|
+
}
|
|
2582
|
+
mediaInteractionCb(...p);
|
|
2583
|
+
};
|
|
2584
|
+
o.styleSheetRuleCb = (...p) => {
|
|
2585
|
+
if (hooks.styleSheetRule) {
|
|
2586
|
+
hooks.styleSheetRule(...p);
|
|
2587
|
+
}
|
|
2588
|
+
styleSheetRuleCb(...p);
|
|
2589
|
+
};
|
|
2590
|
+
o.styleDeclarationCb = (...p) => {
|
|
2591
|
+
if (hooks.styleDeclaration) {
|
|
2592
|
+
hooks.styleDeclaration(...p);
|
|
2593
|
+
}
|
|
2594
|
+
styleDeclarationCb(...p);
|
|
2595
|
+
};
|
|
2596
|
+
o.canvasMutationCb = (...p) => {
|
|
2597
|
+
if (hooks.canvasMutation) {
|
|
2598
|
+
hooks.canvasMutation(...p);
|
|
2599
|
+
}
|
|
2600
|
+
canvasMutationCb(...p);
|
|
2601
|
+
};
|
|
2602
|
+
o.fontCb = (...p) => {
|
|
2603
|
+
if (hooks.font) {
|
|
2604
|
+
hooks.font(...p);
|
|
2605
|
+
}
|
|
2606
|
+
fontCb(...p);
|
|
2607
|
+
};
|
|
2608
|
+
o.selectionCb = (...p) => {
|
|
2609
|
+
if (hooks.selection) {
|
|
2610
|
+
hooks.selection(...p);
|
|
2611
|
+
}
|
|
2612
|
+
selectionCb(...p);
|
|
2613
|
+
};
|
|
2614
|
+
}
|
|
2615
|
+
function initObservers(o, hooks = {}) {
|
|
2616
|
+
const currentWindow = o.doc.defaultView;
|
|
2617
|
+
if (!currentWindow) {
|
|
2618
|
+
return () => {
|
|
2619
|
+
};
|
|
2620
|
+
}
|
|
2621
|
+
mergeHooks(o, hooks);
|
|
2622
|
+
const mutationObserver = initMutationObserver(o, o.doc);
|
|
2623
|
+
const mousemoveHandler = initMoveObserver(o);
|
|
2624
|
+
const mouseInteractionHandler = initMouseInteractionObserver(o);
|
|
2625
|
+
const scrollHandler = initScrollObserver(o);
|
|
2626
|
+
const viewportResizeHandler = initViewportResizeObserver(o);
|
|
2627
|
+
const inputHandler = initInputObserver(o);
|
|
2628
|
+
const mediaInteractionHandler = initMediaInteractionObserver(o);
|
|
2629
|
+
const styleSheetObserver = initStyleSheetObserver(o, { win: currentWindow });
|
|
2630
|
+
const adoptedStyleSheetObserver = initAdoptedStyleSheetObserver(o, o.doc);
|
|
2631
|
+
const styleDeclarationObserver = initStyleDeclarationObserver(o, {
|
|
2632
|
+
win: currentWindow,
|
|
2633
|
+
});
|
|
2634
|
+
const fontObserver = o.collectFonts
|
|
2635
|
+
? initFontObserver(o)
|
|
2636
|
+
: () => {
|
|
2637
|
+
};
|
|
2638
|
+
const selectionObserver = initSelectionObserver(o);
|
|
2639
|
+
const pluginHandlers = [];
|
|
2640
|
+
for (const plugin of o.plugins) {
|
|
2641
|
+
pluginHandlers.push(plugin.observer(plugin.callback, currentWindow, plugin.options));
|
|
2642
|
+
}
|
|
2643
|
+
return () => {
|
|
2644
|
+
mutationBuffers.forEach((b) => b.reset());
|
|
2645
|
+
mutationObserver.disconnect();
|
|
2646
|
+
mousemoveHandler();
|
|
2647
|
+
mouseInteractionHandler();
|
|
2648
|
+
scrollHandler();
|
|
2649
|
+
viewportResizeHandler();
|
|
2650
|
+
inputHandler();
|
|
2651
|
+
mediaInteractionHandler();
|
|
2652
|
+
styleSheetObserver();
|
|
2653
|
+
adoptedStyleSheetObserver();
|
|
2654
|
+
styleDeclarationObserver();
|
|
2655
|
+
fontObserver();
|
|
2656
|
+
selectionObserver();
|
|
2657
|
+
pluginHandlers.forEach((h) => h());
|
|
2658
|
+
};
|
|
2659
|
+
}
|
|
2660
|
+
|
|
2661
|
+
class CrossOriginIframeMirror {
|
|
2662
|
+
constructor(generateIdFn) {
|
|
2663
|
+
this.generateIdFn = generateIdFn;
|
|
2664
|
+
this.iframeIdToRemoteIdMap = new WeakMap();
|
|
2665
|
+
this.iframeRemoteIdToIdMap = new WeakMap();
|
|
2666
|
+
}
|
|
2667
|
+
getId(iframe, remoteId, idToRemoteMap, remoteToIdMap) {
|
|
2668
|
+
const idToRemoteIdMap = idToRemoteMap || this.getIdToRemoteIdMap(iframe);
|
|
2669
|
+
const remoteIdToIdMap = remoteToIdMap || this.getRemoteIdToIdMap(iframe);
|
|
2670
|
+
let id = idToRemoteIdMap.get(remoteId);
|
|
2671
|
+
if (!id) {
|
|
2672
|
+
id = this.generateIdFn();
|
|
2673
|
+
idToRemoteIdMap.set(remoteId, id);
|
|
2674
|
+
remoteIdToIdMap.set(id, remoteId);
|
|
2675
|
+
}
|
|
2676
|
+
return id;
|
|
2677
|
+
}
|
|
2678
|
+
getIds(iframe, remoteId) {
|
|
2679
|
+
const idToRemoteIdMap = this.getIdToRemoteIdMap(iframe);
|
|
2680
|
+
const remoteIdToIdMap = this.getRemoteIdToIdMap(iframe);
|
|
2681
|
+
return remoteId.map((id) => this.getId(iframe, id, idToRemoteIdMap, remoteIdToIdMap));
|
|
2682
|
+
}
|
|
2683
|
+
getRemoteId(iframe, id, map) {
|
|
2684
|
+
const remoteIdToIdMap = map || this.getRemoteIdToIdMap(iframe);
|
|
2685
|
+
if (typeof id !== 'number')
|
|
2686
|
+
return id;
|
|
2687
|
+
const remoteId = remoteIdToIdMap.get(id);
|
|
2688
|
+
if (!remoteId)
|
|
2689
|
+
return -1;
|
|
2690
|
+
return remoteId;
|
|
2691
|
+
}
|
|
2692
|
+
getRemoteIds(iframe, ids) {
|
|
2693
|
+
const remoteIdToIdMap = this.getRemoteIdToIdMap(iframe);
|
|
2694
|
+
return ids.map((id) => this.getRemoteId(iframe, id, remoteIdToIdMap));
|
|
2695
|
+
}
|
|
2696
|
+
reset(iframe) {
|
|
2697
|
+
if (!iframe) {
|
|
2698
|
+
this.iframeIdToRemoteIdMap = new WeakMap();
|
|
2699
|
+
this.iframeRemoteIdToIdMap = new WeakMap();
|
|
2700
|
+
return;
|
|
2701
|
+
}
|
|
2702
|
+
this.iframeIdToRemoteIdMap.delete(iframe);
|
|
2703
|
+
this.iframeRemoteIdToIdMap.delete(iframe);
|
|
2704
|
+
}
|
|
2705
|
+
getIdToRemoteIdMap(iframe) {
|
|
2706
|
+
let idToRemoteIdMap = this.iframeIdToRemoteIdMap.get(iframe);
|
|
2707
|
+
if (!idToRemoteIdMap) {
|
|
2708
|
+
idToRemoteIdMap = new Map();
|
|
2709
|
+
this.iframeIdToRemoteIdMap.set(iframe, idToRemoteIdMap);
|
|
2710
|
+
}
|
|
2711
|
+
return idToRemoteIdMap;
|
|
2712
|
+
}
|
|
2713
|
+
getRemoteIdToIdMap(iframe) {
|
|
2714
|
+
let remoteIdToIdMap = this.iframeRemoteIdToIdMap.get(iframe);
|
|
2715
|
+
if (!remoteIdToIdMap) {
|
|
2716
|
+
remoteIdToIdMap = new Map();
|
|
2717
|
+
this.iframeRemoteIdToIdMap.set(iframe, remoteIdToIdMap);
|
|
2718
|
+
}
|
|
2719
|
+
return remoteIdToIdMap;
|
|
2720
|
+
}
|
|
2721
|
+
}
|
|
2722
|
+
|
|
2723
|
+
class IframeManager {
|
|
2724
|
+
constructor(options) {
|
|
2725
|
+
this.iframes = new WeakMap();
|
|
2726
|
+
this.crossOriginIframeMap = new WeakMap();
|
|
2727
|
+
this.crossOriginIframeMirror = new CrossOriginIframeMirror(genId);
|
|
2728
|
+
this.mutationCb = options.mutationCb;
|
|
2729
|
+
this.wrappedEmit = options.wrappedEmit;
|
|
2730
|
+
this.stylesheetManager = options.stylesheetManager;
|
|
2731
|
+
this.recordCrossOriginIframes = options.recordCrossOriginIframes;
|
|
2732
|
+
this.crossOriginIframeStyleMirror = new CrossOriginIframeMirror(this.stylesheetManager.styleMirror.generateId.bind(this.stylesheetManager.styleMirror));
|
|
2733
|
+
this.mirror = options.mirror;
|
|
2734
|
+
if (this.recordCrossOriginIframes) {
|
|
2735
|
+
window.addEventListener('message', this.handleMessage.bind(this));
|
|
2736
|
+
}
|
|
2737
|
+
}
|
|
2738
|
+
addIframe(iframeEl) {
|
|
2739
|
+
this.iframes.set(iframeEl, true);
|
|
2740
|
+
if (iframeEl.contentWindow)
|
|
2741
|
+
this.crossOriginIframeMap.set(iframeEl.contentWindow, iframeEl);
|
|
2742
|
+
}
|
|
2743
|
+
addLoadListener(cb) {
|
|
2744
|
+
this.loadListener = cb;
|
|
2745
|
+
}
|
|
2746
|
+
attachIframe(iframeEl, childSn) {
|
|
2747
|
+
var _a;
|
|
2748
|
+
this.mutationCb({
|
|
2749
|
+
adds: [
|
|
2750
|
+
{
|
|
2751
|
+
parentId: this.mirror.getId(iframeEl),
|
|
2752
|
+
nextId: null,
|
|
2753
|
+
node: childSn,
|
|
2754
|
+
},
|
|
2755
|
+
],
|
|
2756
|
+
removes: [],
|
|
2757
|
+
texts: [],
|
|
2758
|
+
attributes: [],
|
|
2759
|
+
isAttachIframe: true,
|
|
2760
|
+
});
|
|
2761
|
+
(_a = this.loadListener) === null || _a === void 0 ? void 0 : _a.call(this, iframeEl);
|
|
2762
|
+
if (iframeEl.contentDocument &&
|
|
2763
|
+
iframeEl.contentDocument.adoptedStyleSheets &&
|
|
2764
|
+
iframeEl.contentDocument.adoptedStyleSheets.length > 0)
|
|
2765
|
+
this.stylesheetManager.adoptStyleSheets(iframeEl.contentDocument.adoptedStyleSheets, this.mirror.getId(iframeEl.contentDocument));
|
|
2766
|
+
}
|
|
2767
|
+
handleMessage(message) {
|
|
2768
|
+
if (message.data.type === 'rrweb') {
|
|
2769
|
+
const iframeSourceWindow = message.source;
|
|
2770
|
+
if (!iframeSourceWindow)
|
|
2771
|
+
return;
|
|
2772
|
+
const iframeEl = this.crossOriginIframeMap.get(message.source);
|
|
2773
|
+
if (!iframeEl)
|
|
2774
|
+
return;
|
|
2775
|
+
const transformedEvent = this.transformCrossOriginEvent(iframeEl, message.data.event);
|
|
2776
|
+
if (transformedEvent)
|
|
2777
|
+
this.wrappedEmit(transformedEvent, message.data.isCheckout);
|
|
2778
|
+
}
|
|
2779
|
+
}
|
|
2780
|
+
transformCrossOriginEvent(iframeEl, e) {
|
|
2781
|
+
var _a;
|
|
2782
|
+
switch (e.type) {
|
|
2783
|
+
case EventType.FullSnapshot: {
|
|
2784
|
+
this.crossOriginIframeMirror.reset(iframeEl);
|
|
2785
|
+
this.crossOriginIframeStyleMirror.reset(iframeEl);
|
|
2786
|
+
this.replaceIdOnNode(e.data.node, iframeEl);
|
|
2787
|
+
return {
|
|
2788
|
+
timestamp: e.timestamp,
|
|
2789
|
+
type: EventType.IncrementalSnapshot,
|
|
2790
|
+
data: {
|
|
2791
|
+
source: IncrementalSource.Mutation,
|
|
2792
|
+
adds: [
|
|
2793
|
+
{
|
|
2794
|
+
parentId: this.mirror.getId(iframeEl),
|
|
2795
|
+
nextId: null,
|
|
2796
|
+
node: e.data.node,
|
|
2797
|
+
},
|
|
2798
|
+
],
|
|
2799
|
+
removes: [],
|
|
2800
|
+
texts: [],
|
|
2801
|
+
attributes: [],
|
|
2802
|
+
isAttachIframe: true,
|
|
2803
|
+
},
|
|
2804
|
+
};
|
|
2805
|
+
}
|
|
2806
|
+
case EventType.Meta:
|
|
2807
|
+
case EventType.Load:
|
|
2808
|
+
case EventType.DomContentLoaded: {
|
|
2809
|
+
return false;
|
|
2810
|
+
}
|
|
2811
|
+
case EventType.Plugin: {
|
|
2812
|
+
return e;
|
|
2813
|
+
}
|
|
2814
|
+
case EventType.Custom: {
|
|
2815
|
+
this.replaceIds(e.data.payload, iframeEl, ['id', 'parentId', 'previousId', 'nextId']);
|
|
2816
|
+
return e;
|
|
2817
|
+
}
|
|
2818
|
+
case EventType.IncrementalSnapshot: {
|
|
2819
|
+
switch (e.data.source) {
|
|
2820
|
+
case IncrementalSource.Mutation: {
|
|
2821
|
+
e.data.adds.forEach((n) => {
|
|
2822
|
+
this.replaceIds(n, iframeEl, [
|
|
2823
|
+
'parentId',
|
|
2824
|
+
'nextId',
|
|
2825
|
+
'previousId',
|
|
2826
|
+
]);
|
|
2827
|
+
this.replaceIdOnNode(n.node, iframeEl);
|
|
2828
|
+
});
|
|
2829
|
+
e.data.removes.forEach((n) => {
|
|
2830
|
+
this.replaceIds(n, iframeEl, ['parentId', 'id']);
|
|
2831
|
+
});
|
|
2832
|
+
e.data.attributes.forEach((n) => {
|
|
2833
|
+
this.replaceIds(n, iframeEl, ['id']);
|
|
2834
|
+
});
|
|
2835
|
+
e.data.texts.forEach((n) => {
|
|
2836
|
+
this.replaceIds(n, iframeEl, ['id']);
|
|
2837
|
+
});
|
|
2838
|
+
return e;
|
|
2839
|
+
}
|
|
2840
|
+
case IncrementalSource.Drag:
|
|
2841
|
+
case IncrementalSource.TouchMove:
|
|
2842
|
+
case IncrementalSource.MouseMove: {
|
|
2843
|
+
e.data.positions.forEach((p) => {
|
|
2844
|
+
this.replaceIds(p, iframeEl, ['id']);
|
|
2845
|
+
});
|
|
2846
|
+
return e;
|
|
2847
|
+
}
|
|
2848
|
+
case IncrementalSource.ViewportResize: {
|
|
2849
|
+
return false;
|
|
2850
|
+
}
|
|
2851
|
+
case IncrementalSource.MediaInteraction:
|
|
2852
|
+
case IncrementalSource.MouseInteraction:
|
|
2853
|
+
case IncrementalSource.Scroll:
|
|
2854
|
+
case IncrementalSource.CanvasMutation:
|
|
2855
|
+
case IncrementalSource.Input: {
|
|
2856
|
+
this.replaceIds(e.data, iframeEl, ['id']);
|
|
2857
|
+
return e;
|
|
2858
|
+
}
|
|
2859
|
+
case IncrementalSource.StyleSheetRule:
|
|
2860
|
+
case IncrementalSource.StyleDeclaration: {
|
|
2861
|
+
this.replaceIds(e.data, iframeEl, ['id']);
|
|
2862
|
+
this.replaceStyleIds(e.data, iframeEl, ['styleId']);
|
|
2863
|
+
return e;
|
|
2864
|
+
}
|
|
2865
|
+
case IncrementalSource.Font: {
|
|
2866
|
+
return e;
|
|
2867
|
+
}
|
|
2868
|
+
case IncrementalSource.Selection: {
|
|
2869
|
+
e.data.ranges.forEach((range) => {
|
|
2870
|
+
this.replaceIds(range, iframeEl, ['start', 'end']);
|
|
2871
|
+
});
|
|
2872
|
+
return e;
|
|
2873
|
+
}
|
|
2874
|
+
case IncrementalSource.AdoptedStyleSheet: {
|
|
2875
|
+
this.replaceIds(e.data, iframeEl, ['id']);
|
|
2876
|
+
this.replaceStyleIds(e.data, iframeEl, ['styleIds']);
|
|
2877
|
+
(_a = e.data.styles) === null || _a === void 0 ? void 0 : _a.forEach((style) => {
|
|
2878
|
+
this.replaceStyleIds(style, iframeEl, ['styleId']);
|
|
2879
|
+
});
|
|
2880
|
+
return e;
|
|
2881
|
+
}
|
|
2882
|
+
}
|
|
2883
|
+
}
|
|
2884
|
+
}
|
|
2885
|
+
}
|
|
2886
|
+
replace(iframeMirror, obj, iframeEl, keys) {
|
|
2887
|
+
for (const key of keys) {
|
|
2888
|
+
if (!Array.isArray(obj[key]) && typeof obj[key] !== 'number')
|
|
2889
|
+
continue;
|
|
2890
|
+
if (Array.isArray(obj[key])) {
|
|
2891
|
+
obj[key] = iframeMirror.getIds(iframeEl, obj[key]);
|
|
2892
|
+
}
|
|
2893
|
+
else {
|
|
2894
|
+
obj[key] = iframeMirror.getId(iframeEl, obj[key]);
|
|
2895
|
+
}
|
|
2896
|
+
}
|
|
2897
|
+
return obj;
|
|
2898
|
+
}
|
|
2899
|
+
replaceIds(obj, iframeEl, keys) {
|
|
2900
|
+
return this.replace(this.crossOriginIframeMirror, obj, iframeEl, keys);
|
|
2901
|
+
}
|
|
2902
|
+
replaceStyleIds(obj, iframeEl, keys) {
|
|
2903
|
+
return this.replace(this.crossOriginIframeStyleMirror, obj, iframeEl, keys);
|
|
2904
|
+
}
|
|
2905
|
+
replaceIdOnNode(node, iframeEl) {
|
|
2906
|
+
this.replaceIds(node, iframeEl, ['id']);
|
|
2907
|
+
if ('childNodes' in node) {
|
|
2908
|
+
node.childNodes.forEach((child) => {
|
|
2909
|
+
this.replaceIdOnNode(child, iframeEl);
|
|
2910
|
+
});
|
|
2911
|
+
}
|
|
2912
|
+
}
|
|
2913
|
+
}
|
|
2914
|
+
|
|
2915
|
+
class ShadowDomManager {
|
|
2916
|
+
constructor(options) {
|
|
2917
|
+
this.shadowDoms = new WeakSet();
|
|
2918
|
+
this.restorePatches = [];
|
|
2919
|
+
this.mutationCb = options.mutationCb;
|
|
2920
|
+
this.scrollCb = options.scrollCb;
|
|
2921
|
+
this.bypassOptions = options.bypassOptions;
|
|
2922
|
+
this.mirror = options.mirror;
|
|
2923
|
+
const manager = this;
|
|
2924
|
+
this.restorePatches.push(patch(Element.prototype, 'attachShadow', function (original) {
|
|
2925
|
+
return function (option) {
|
|
2926
|
+
const shadowRoot = original.call(this, option);
|
|
2927
|
+
if (this.shadowRoot)
|
|
2928
|
+
manager.addShadowRoot(this.shadowRoot, this.ownerDocument);
|
|
2929
|
+
return shadowRoot;
|
|
2930
|
+
};
|
|
2931
|
+
}));
|
|
2932
|
+
}
|
|
2933
|
+
addShadowRoot(shadowRoot, doc) {
|
|
2934
|
+
if (!isNativeShadowDom(shadowRoot))
|
|
2935
|
+
return;
|
|
2936
|
+
if (this.shadowDoms.has(shadowRoot))
|
|
2937
|
+
return;
|
|
2938
|
+
this.shadowDoms.add(shadowRoot);
|
|
2939
|
+
initMutationObserver(Object.assign(Object.assign({}, this.bypassOptions), { doc, mutationCb: this.mutationCb, mirror: this.mirror, shadowDomManager: this }), shadowRoot);
|
|
2940
|
+
initScrollObserver(Object.assign(Object.assign({}, this.bypassOptions), { scrollCb: this.scrollCb, doc: shadowRoot, mirror: this.mirror }));
|
|
2941
|
+
setTimeout(() => {
|
|
2942
|
+
if (shadowRoot.adoptedStyleSheets &&
|
|
2943
|
+
shadowRoot.adoptedStyleSheets.length > 0)
|
|
2944
|
+
this.bypassOptions.stylesheetManager.adoptStyleSheets(shadowRoot.adoptedStyleSheets, this.mirror.getId(shadowRoot.host));
|
|
2945
|
+
initAdoptedStyleSheetObserver({
|
|
2946
|
+
mirror: this.mirror,
|
|
2947
|
+
stylesheetManager: this.bypassOptions.stylesheetManager,
|
|
2948
|
+
}, shadowRoot);
|
|
2949
|
+
}, 0);
|
|
2950
|
+
}
|
|
2951
|
+
observeAttachShadow(iframeElement) {
|
|
2952
|
+
if (iframeElement.contentWindow) {
|
|
2953
|
+
const manager = this;
|
|
2954
|
+
this.restorePatches.push(patch(iframeElement.contentWindow.HTMLElement.prototype, 'attachShadow', function (original) {
|
|
2955
|
+
return function (option) {
|
|
2956
|
+
const shadowRoot = original.call(this, option);
|
|
2957
|
+
if (this.shadowRoot)
|
|
2958
|
+
manager.addShadowRoot(this.shadowRoot, iframeElement.contentDocument);
|
|
2959
|
+
return shadowRoot;
|
|
2960
|
+
};
|
|
2961
|
+
}));
|
|
2962
|
+
}
|
|
2963
|
+
}
|
|
2964
|
+
reset() {
|
|
2965
|
+
this.restorePatches.forEach((restorePatch) => restorePatch());
|
|
2966
|
+
this.shadowDoms = new WeakSet();
|
|
2967
|
+
}
|
|
2968
|
+
}
|
|
2969
|
+
|
|
2970
|
+
/*! *****************************************************************************
|
|
2971
|
+
Copyright (c) Microsoft Corporation.
|
|
2972
|
+
|
|
2973
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
2974
|
+
purpose with or without fee is hereby granted.
|
|
2975
|
+
|
|
2976
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
2977
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
2978
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
2979
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
2980
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
2981
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
2982
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
2983
|
+
***************************************************************************** */
|
|
2984
|
+
|
|
2985
|
+
function __rest(s, e) {
|
|
2986
|
+
var t = {};
|
|
2987
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
2988
|
+
t[p] = s[p];
|
|
2989
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
2990
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
2991
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
2992
|
+
t[p[i]] = s[p[i]];
|
|
2993
|
+
}
|
|
2994
|
+
return t;
|
|
2995
|
+
}
|
|
2996
|
+
|
|
2997
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
2998
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
2999
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
3000
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
3001
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
3002
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
3003
|
+
step((generator = generator.apply(thisArg, [])).next());
|
|
3004
|
+
});
|
|
3005
|
+
}
|
|
3006
|
+
|
|
3007
|
+
/*
|
|
3008
|
+
* base64-arraybuffer 1.0.1 <https://github.com/niklasvh/base64-arraybuffer>
|
|
3009
|
+
* Copyright (c) 2021 Niklas von Hertzen <https://hertzen.com>
|
|
3010
|
+
* Released under MIT License
|
|
3011
|
+
*/
|
|
3012
|
+
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
3013
|
+
// Use a lookup table to find the index.
|
|
3014
|
+
var lookup = typeof Uint8Array === 'undefined' ? [] : new Uint8Array(256);
|
|
3015
|
+
for (var i = 0; i < chars.length; i++) {
|
|
3016
|
+
lookup[chars.charCodeAt(i)] = i;
|
|
3017
|
+
}
|
|
3018
|
+
var encode = function (arraybuffer) {
|
|
3019
|
+
var bytes = new Uint8Array(arraybuffer), i, len = bytes.length, base64 = '';
|
|
3020
|
+
for (i = 0; i < len; i += 3) {
|
|
3021
|
+
base64 += chars[bytes[i] >> 2];
|
|
3022
|
+
base64 += chars[((bytes[i] & 3) << 4) | (bytes[i + 1] >> 4)];
|
|
3023
|
+
base64 += chars[((bytes[i + 1] & 15) << 2) | (bytes[i + 2] >> 6)];
|
|
3024
|
+
base64 += chars[bytes[i + 2] & 63];
|
|
3025
|
+
}
|
|
3026
|
+
if (len % 3 === 2) {
|
|
3027
|
+
base64 = base64.substring(0, base64.length - 1) + '=';
|
|
3028
|
+
}
|
|
3029
|
+
else if (len % 3 === 1) {
|
|
3030
|
+
base64 = base64.substring(0, base64.length - 2) + '==';
|
|
3031
|
+
}
|
|
3032
|
+
return base64;
|
|
3033
|
+
};
|
|
3034
|
+
|
|
3035
|
+
const canvasVarMap = new Map();
|
|
3036
|
+
function variableListFor(ctx, ctor) {
|
|
3037
|
+
let contextMap = canvasVarMap.get(ctx);
|
|
3038
|
+
if (!contextMap) {
|
|
3039
|
+
contextMap = new Map();
|
|
3040
|
+
canvasVarMap.set(ctx, contextMap);
|
|
3041
|
+
}
|
|
3042
|
+
if (!contextMap.has(ctor)) {
|
|
3043
|
+
contextMap.set(ctor, []);
|
|
3044
|
+
}
|
|
3045
|
+
return contextMap.get(ctor);
|
|
3046
|
+
}
|
|
3047
|
+
const saveWebGLVar = (value, win, ctx) => {
|
|
3048
|
+
if (!value ||
|
|
3049
|
+
!(isInstanceOfWebGLObject(value, win) || typeof value === 'object'))
|
|
3050
|
+
return;
|
|
3051
|
+
const name = value.constructor.name;
|
|
3052
|
+
const list = variableListFor(ctx, name);
|
|
3053
|
+
let index = list.indexOf(value);
|
|
3054
|
+
if (index === -1) {
|
|
3055
|
+
index = list.length;
|
|
3056
|
+
list.push(value);
|
|
3057
|
+
}
|
|
3058
|
+
return index;
|
|
3059
|
+
};
|
|
3060
|
+
function serializeArg(value, win, ctx) {
|
|
3061
|
+
if (value instanceof Array) {
|
|
3062
|
+
return value.map((arg) => serializeArg(arg, win, ctx));
|
|
3063
|
+
}
|
|
3064
|
+
else if (value === null) {
|
|
3065
|
+
return value;
|
|
3066
|
+
}
|
|
3067
|
+
else if (value instanceof Float32Array ||
|
|
3068
|
+
value instanceof Float64Array ||
|
|
3069
|
+
value instanceof Int32Array ||
|
|
3070
|
+
value instanceof Uint32Array ||
|
|
3071
|
+
value instanceof Uint8Array ||
|
|
3072
|
+
value instanceof Uint16Array ||
|
|
3073
|
+
value instanceof Int16Array ||
|
|
3074
|
+
value instanceof Int8Array ||
|
|
3075
|
+
value instanceof Uint8ClampedArray) {
|
|
3076
|
+
const name = value.constructor.name;
|
|
3077
|
+
return {
|
|
3078
|
+
rr_type: name,
|
|
3079
|
+
args: [Object.values(value)],
|
|
3080
|
+
};
|
|
3081
|
+
}
|
|
3082
|
+
else if (value instanceof ArrayBuffer) {
|
|
3083
|
+
const name = value.constructor.name;
|
|
3084
|
+
const base64 = encode(value);
|
|
3085
|
+
return {
|
|
3086
|
+
rr_type: name,
|
|
3087
|
+
base64,
|
|
3088
|
+
};
|
|
3089
|
+
}
|
|
3090
|
+
else if (value instanceof DataView) {
|
|
3091
|
+
const name = value.constructor.name;
|
|
3092
|
+
return {
|
|
3093
|
+
rr_type: name,
|
|
3094
|
+
args: [
|
|
3095
|
+
serializeArg(value.buffer, win, ctx),
|
|
3096
|
+
value.byteOffset,
|
|
3097
|
+
value.byteLength,
|
|
3098
|
+
],
|
|
3099
|
+
};
|
|
3100
|
+
}
|
|
3101
|
+
else if (value instanceof HTMLImageElement) {
|
|
3102
|
+
const name = value.constructor.name;
|
|
3103
|
+
const { src } = value;
|
|
3104
|
+
return {
|
|
3105
|
+
rr_type: name,
|
|
3106
|
+
src,
|
|
3107
|
+
};
|
|
3108
|
+
}
|
|
3109
|
+
else if (value instanceof HTMLCanvasElement) {
|
|
3110
|
+
const name = 'HTMLImageElement';
|
|
3111
|
+
const src = value.toDataURL();
|
|
3112
|
+
return {
|
|
3113
|
+
rr_type: name,
|
|
3114
|
+
src,
|
|
3115
|
+
};
|
|
3116
|
+
}
|
|
3117
|
+
else if (value instanceof ImageData) {
|
|
3118
|
+
const name = value.constructor.name;
|
|
3119
|
+
return {
|
|
3120
|
+
rr_type: name,
|
|
3121
|
+
args: [serializeArg(value.data, win, ctx), value.width, value.height],
|
|
3122
|
+
};
|
|
3123
|
+
}
|
|
3124
|
+
else if (isInstanceOfWebGLObject(value, win) || typeof value === 'object') {
|
|
3125
|
+
const name = value.constructor.name;
|
|
3126
|
+
const index = saveWebGLVar(value, win, ctx);
|
|
3127
|
+
return {
|
|
3128
|
+
rr_type: name,
|
|
3129
|
+
index: index,
|
|
3130
|
+
};
|
|
3131
|
+
}
|
|
3132
|
+
return value;
|
|
3133
|
+
}
|
|
3134
|
+
const serializeArgs = (args, win, ctx) => {
|
|
3135
|
+
return [...args].map((arg) => serializeArg(arg, win, ctx));
|
|
3136
|
+
};
|
|
3137
|
+
const isInstanceOfWebGLObject = (value, win) => {
|
|
3138
|
+
const webGLConstructorNames = [
|
|
3139
|
+
'WebGLActiveInfo',
|
|
3140
|
+
'WebGLBuffer',
|
|
3141
|
+
'WebGLFramebuffer',
|
|
3142
|
+
'WebGLProgram',
|
|
3143
|
+
'WebGLRenderbuffer',
|
|
3144
|
+
'WebGLShader',
|
|
3145
|
+
'WebGLShaderPrecisionFormat',
|
|
3146
|
+
'WebGLTexture',
|
|
3147
|
+
'WebGLUniformLocation',
|
|
3148
|
+
'WebGLVertexArrayObject',
|
|
3149
|
+
'WebGLVertexArrayObjectOES',
|
|
3150
|
+
];
|
|
3151
|
+
const supportedWebGLConstructorNames = webGLConstructorNames.filter((name) => typeof win[name] === 'function');
|
|
3152
|
+
return Boolean(supportedWebGLConstructorNames.find((name) => value instanceof win[name]));
|
|
3153
|
+
};
|
|
3154
|
+
|
|
3155
|
+
function initCanvas2DMutationObserver(cb, win, blockClass, blockSelector) {
|
|
3156
|
+
const handlers = [];
|
|
3157
|
+
const props2D = Object.getOwnPropertyNames(win.CanvasRenderingContext2D.prototype);
|
|
3158
|
+
for (const prop of props2D) {
|
|
3159
|
+
try {
|
|
3160
|
+
if (typeof win.CanvasRenderingContext2D.prototype[prop] !== 'function') {
|
|
3161
|
+
continue;
|
|
3162
|
+
}
|
|
3163
|
+
const restoreHandler = patch(win.CanvasRenderingContext2D.prototype, prop, function (original) {
|
|
3164
|
+
return function (...args) {
|
|
3165
|
+
if (!isBlocked(this.canvas, blockClass, blockSelector, true)) {
|
|
3166
|
+
setTimeout(() => {
|
|
3167
|
+
const recordArgs = serializeArgs([...args], win, this);
|
|
3168
|
+
cb(this.canvas, {
|
|
3169
|
+
type: CanvasContext['2D'],
|
|
3170
|
+
property: prop,
|
|
3171
|
+
args: recordArgs,
|
|
3172
|
+
});
|
|
3173
|
+
}, 0);
|
|
3174
|
+
}
|
|
3175
|
+
return original.apply(this, args);
|
|
3176
|
+
};
|
|
3177
|
+
});
|
|
3178
|
+
handlers.push(restoreHandler);
|
|
3179
|
+
}
|
|
3180
|
+
catch (_a) {
|
|
3181
|
+
const hookHandler = hookSetter(win.CanvasRenderingContext2D.prototype, prop, {
|
|
3182
|
+
set(v) {
|
|
3183
|
+
cb(this.canvas, {
|
|
3184
|
+
type: CanvasContext['2D'],
|
|
3185
|
+
property: prop,
|
|
3186
|
+
args: [v],
|
|
3187
|
+
setter: true,
|
|
3188
|
+
});
|
|
3189
|
+
},
|
|
3190
|
+
});
|
|
3191
|
+
handlers.push(hookHandler);
|
|
3192
|
+
}
|
|
3193
|
+
}
|
|
3194
|
+
return () => {
|
|
3195
|
+
handlers.forEach((h) => h());
|
|
3196
|
+
};
|
|
3197
|
+
}
|
|
3198
|
+
|
|
3199
|
+
function initCanvasContextObserver(win, blockClass, blockSelector) {
|
|
3200
|
+
const handlers = [];
|
|
3201
|
+
try {
|
|
3202
|
+
const restoreHandler = patch(win.HTMLCanvasElement.prototype, 'getContext', function (original) {
|
|
3203
|
+
return function (contextType, ...args) {
|
|
3204
|
+
if (!isBlocked(this, blockClass, blockSelector, true)) {
|
|
3205
|
+
if (!('__context' in this))
|
|
3206
|
+
this.__context = contextType;
|
|
3207
|
+
}
|
|
3208
|
+
return original.apply(this, [contextType, ...args]);
|
|
3209
|
+
};
|
|
3210
|
+
});
|
|
3211
|
+
handlers.push(restoreHandler);
|
|
3212
|
+
}
|
|
3213
|
+
catch (_a) {
|
|
3214
|
+
console.error('failed to patch HTMLCanvasElement.prototype.getContext');
|
|
3215
|
+
}
|
|
3216
|
+
return () => {
|
|
3217
|
+
handlers.forEach((h) => h());
|
|
3218
|
+
};
|
|
3219
|
+
}
|
|
3220
|
+
|
|
3221
|
+
function patchGLPrototype(prototype, type, cb, blockClass, blockSelector, mirror, win) {
|
|
3222
|
+
const handlers = [];
|
|
3223
|
+
const props = Object.getOwnPropertyNames(prototype);
|
|
3224
|
+
for (const prop of props) {
|
|
3225
|
+
if ([
|
|
3226
|
+
'isContextLost',
|
|
3227
|
+
'canvas',
|
|
3228
|
+
'drawingBufferWidth',
|
|
3229
|
+
'drawingBufferHeight',
|
|
3230
|
+
].includes(prop)) {
|
|
3231
|
+
continue;
|
|
3232
|
+
}
|
|
3233
|
+
try {
|
|
3234
|
+
if (typeof prototype[prop] !== 'function') {
|
|
3235
|
+
continue;
|
|
3236
|
+
}
|
|
3237
|
+
const restoreHandler = patch(prototype, prop, function (original) {
|
|
3238
|
+
return function (...args) {
|
|
3239
|
+
const result = original.apply(this, args);
|
|
3240
|
+
saveWebGLVar(result, win, this);
|
|
3241
|
+
if (!isBlocked(this.canvas, blockClass, blockSelector, true)) {
|
|
3242
|
+
const recordArgs = serializeArgs([...args], win, this);
|
|
3243
|
+
const mutation = {
|
|
3244
|
+
type,
|
|
3245
|
+
property: prop,
|
|
3246
|
+
args: recordArgs,
|
|
3247
|
+
};
|
|
3248
|
+
cb(this.canvas, mutation);
|
|
3249
|
+
}
|
|
3250
|
+
return result;
|
|
3251
|
+
};
|
|
3252
|
+
});
|
|
3253
|
+
handlers.push(restoreHandler);
|
|
3254
|
+
}
|
|
3255
|
+
catch (_a) {
|
|
3256
|
+
const hookHandler = hookSetter(prototype, prop, {
|
|
3257
|
+
set(v) {
|
|
3258
|
+
cb(this.canvas, {
|
|
3259
|
+
type,
|
|
3260
|
+
property: prop,
|
|
3261
|
+
args: [v],
|
|
3262
|
+
setter: true,
|
|
3263
|
+
});
|
|
3264
|
+
},
|
|
3265
|
+
});
|
|
3266
|
+
handlers.push(hookHandler);
|
|
3267
|
+
}
|
|
3268
|
+
}
|
|
3269
|
+
return handlers;
|
|
3270
|
+
}
|
|
3271
|
+
function initCanvasWebGLMutationObserver(cb, win, blockClass, blockSelector, mirror) {
|
|
3272
|
+
const handlers = [];
|
|
3273
|
+
handlers.push(...patchGLPrototype(win.WebGLRenderingContext.prototype, CanvasContext.WebGL, cb, blockClass, blockSelector, mirror, win));
|
|
3274
|
+
if (typeof win.WebGL2RenderingContext !== 'undefined') {
|
|
3275
|
+
handlers.push(...patchGLPrototype(win.WebGL2RenderingContext.prototype, CanvasContext.WebGL2, cb, blockClass, blockSelector, mirror, win));
|
|
3276
|
+
}
|
|
3277
|
+
return () => {
|
|
3278
|
+
handlers.forEach((h) => h());
|
|
3279
|
+
};
|
|
3280
|
+
}
|
|
3281
|
+
|
|
3282
|
+
var WorkerClass = null;
|
|
3283
|
+
|
|
3284
|
+
try {
|
|
3285
|
+
var WorkerThreads =
|
|
3286
|
+
typeof module !== 'undefined' && typeof module.require === 'function' && module.require('worker_threads') ||
|
|
3287
|
+
typeof __non_webpack_require__ === 'function' && __non_webpack_require__('worker_threads') ||
|
|
3288
|
+
typeof require === 'function' && require('worker_threads');
|
|
3289
|
+
WorkerClass = WorkerThreads.Worker;
|
|
3290
|
+
} catch(e) {} // eslint-disable-line
|
|
3291
|
+
|
|
3292
|
+
function decodeBase64$1(base64, enableUnicode) {
|
|
3293
|
+
return Buffer.from(base64, 'base64').toString('utf8');
|
|
3294
|
+
}
|
|
3295
|
+
|
|
3296
|
+
function createBase64WorkerFactory$2(base64, sourcemapArg, enableUnicodeArg) {
|
|
3297
|
+
var source = decodeBase64$1(base64);
|
|
3298
|
+
var start = source.indexOf('\n', 10) + 1;
|
|
3299
|
+
var body = source.substring(start) + ('');
|
|
3300
|
+
return function WorkerFactory(options) {
|
|
3301
|
+
return new WorkerClass(body, Object.assign({}, options, { eval: true }));
|
|
3302
|
+
};
|
|
3303
|
+
}
|
|
3304
|
+
|
|
3305
|
+
function decodeBase64(base64, enableUnicode) {
|
|
3306
|
+
var binaryString = atob(base64);
|
|
3307
|
+
return binaryString;
|
|
3308
|
+
}
|
|
3309
|
+
|
|
3310
|
+
function createURL(base64, sourcemapArg, enableUnicodeArg) {
|
|
3311
|
+
var source = decodeBase64(base64);
|
|
3312
|
+
var start = source.indexOf('\n', 10) + 1;
|
|
3313
|
+
var body = source.substring(start) + ('');
|
|
3314
|
+
var blob = new Blob([body], { type: 'application/javascript' });
|
|
3315
|
+
return URL.createObjectURL(blob);
|
|
3316
|
+
}
|
|
3317
|
+
|
|
3318
|
+
function createBase64WorkerFactory$1(base64, sourcemapArg, enableUnicodeArg) {
|
|
3319
|
+
var url;
|
|
3320
|
+
return function WorkerFactory(options) {
|
|
3321
|
+
url = url || createURL(base64);
|
|
3322
|
+
return new Worker(url, options);
|
|
3323
|
+
};
|
|
3324
|
+
}
|
|
3325
|
+
|
|
3326
|
+
var kIsNodeJS = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
|
|
3327
|
+
|
|
3328
|
+
function isNodeJS() {
|
|
3329
|
+
return kIsNodeJS;
|
|
3330
|
+
}
|
|
3331
|
+
|
|
3332
|
+
function createBase64WorkerFactory(base64, sourcemapArg, enableUnicodeArg) {
|
|
3333
|
+
if (isNodeJS()) {
|
|
3334
|
+
return createBase64WorkerFactory$2(base64);
|
|
3335
|
+
}
|
|
3336
|
+
return createBase64WorkerFactory$1(base64);
|
|
3337
|
+
}
|
|
3338
|
+
|
|
3339
|
+
var WorkerFactory = createBase64WorkerFactory('Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwooZnVuY3Rpb24gKCkgewogICAgJ3VzZSBzdHJpY3QnOwoKICAgIC8qISAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKg0KICAgIENvcHlyaWdodCAoYykgTWljcm9zb2Z0IENvcnBvcmF0aW9uLg0KDQogICAgUGVybWlzc2lvbiB0byB1c2UsIGNvcHksIG1vZGlmeSwgYW5kL29yIGRpc3RyaWJ1dGUgdGhpcyBzb2Z0d2FyZSBmb3IgYW55DQogICAgcHVycG9zZSB3aXRoIG9yIHdpdGhvdXQgZmVlIGlzIGhlcmVieSBncmFudGVkLg0KDQogICAgVEhFIFNPRlRXQVJFIElTIFBST1ZJREVEICJBUyBJUyIgQU5EIFRIRSBBVVRIT1IgRElTQ0xBSU1TIEFMTCBXQVJSQU5USUVTIFdJVEgNCiAgICBSRUdBUkQgVE8gVEhJUyBTT0ZUV0FSRSBJTkNMVURJTkcgQUxMIElNUExJRUQgV0FSUkFOVElFUyBPRiBNRVJDSEFOVEFCSUxJVFkNCiAgICBBTkQgRklUTkVTUy4gSU4gTk8gRVZFTlQgU0hBTEwgVEhFIEFVVEhPUiBCRSBMSUFCTEUgRk9SIEFOWSBTUEVDSUFMLCBESVJFQ1QsDQogICAgSU5ESVJFQ1QsIE9SIENPTlNFUVVFTlRJQUwgREFNQUdFUyBPUiBBTlkgREFNQUdFUyBXSEFUU09FVkVSIFJFU1VMVElORyBGUk9NDQogICAgTE9TUyBPRiBVU0UsIERBVEEgT1IgUFJPRklUUywgV0hFVEhFUiBJTiBBTiBBQ1RJT04gT0YgQ09OVFJBQ1QsIE5FR0xJR0VOQ0UgT1INCiAgICBPVEhFUiBUT1JUSU9VUyBBQ1RJT04sIEFSSVNJTkcgT1VUIE9GIE9SIElOIENPTk5FQ1RJT04gV0lUSCBUSEUgVVNFIE9SDQogICAgUEVSRk9STUFOQ0UgT0YgVEhJUyBTT0ZUV0FSRS4NCiAgICAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiAqLw0KDQogICAgZnVuY3Rpb24gX19hd2FpdGVyKHRoaXNBcmcsIF9hcmd1bWVudHMsIFAsIGdlbmVyYXRvcikgew0KICAgICAgICBmdW5jdGlvbiBhZG9wdCh2YWx1ZSkgeyByZXR1cm4gdmFsdWUgaW5zdGFuY2VvZiBQID8gdmFsdWUgOiBuZXcgUChmdW5jdGlvbiAocmVzb2x2ZSkgeyByZXNvbHZlKHZhbHVlKTsgfSk7IH0NCiAgICAgICAgcmV0dXJuIG5ldyAoUCB8fCAoUCA9IFByb21pc2UpKShmdW5jdGlvbiAocmVzb2x2ZSwgcmVqZWN0KSB7DQogICAgICAgICAgICBmdW5jdGlvbiBmdWxmaWxsZWQodmFsdWUpIHsgdHJ5IHsgc3RlcChnZW5lcmF0b3IubmV4dCh2YWx1ZSkpOyB9IGNhdGNoIChlKSB7IHJlamVjdChlKTsgfSB9DQogICAgICAgICAgICBmdW5jdGlvbiByZWplY3RlZCh2YWx1ZSkgeyB0cnkgeyBzdGVwKGdlbmVyYXRvclsidGhyb3ciXSh2YWx1ZSkpOyB9IGNhdGNoIChlKSB7IHJlamVjdChlKTsgfSB9DQogICAgICAgICAgICBmdW5jdGlvbiBzdGVwKHJlc3VsdCkgeyByZXN1bHQuZG9uZSA/IHJlc29sdmUocmVzdWx0LnZhbHVlKSA6IGFkb3B0KHJlc3VsdC52YWx1ZSkudGhlbihmdWxmaWxsZWQsIHJlamVjdGVkKTsgfQ0KICAgICAgICAgICAgc3RlcCgoZ2VuZXJhdG9yID0gZ2VuZXJhdG9yLmFwcGx5KHRoaXNBcmcsIF9hcmd1bWVudHMgfHwgW10pKS5uZXh0KCkpOw0KICAgICAgICB9KTsNCiAgICB9CgogICAgLyoKICAgICAqIGJhc2U2NC1hcnJheWJ1ZmZlciAxLjAuMSA8aHR0cHM6Ly9naXRodWIuY29tL25pa2xhc3ZoL2Jhc2U2NC1hcnJheWJ1ZmZlcj4KICAgICAqIENvcHlyaWdodCAoYykgMjAyMSBOaWtsYXMgdm9uIEhlcnR6ZW4gPGh0dHBzOi8vaGVydHplbi5jb20+CiAgICAgKiBSZWxlYXNlZCB1bmRlciBNSVQgTGljZW5zZQogICAgICovCiAgICB2YXIgY2hhcnMgPSAnQUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ejAxMjM0NTY3ODkrLyc7CiAgICAvLyBVc2UgYSBsb29rdXAgdGFibGUgdG8gZmluZCB0aGUgaW5kZXguCiAgICB2YXIgbG9va3VwID0gdHlwZW9mIFVpbnQ4QXJyYXkgPT09ICd1bmRlZmluZWQnID8gW10gOiBuZXcgVWludDhBcnJheSgyNTYpOwogICAgZm9yICh2YXIgaSA9IDA7IGkgPCBjaGFycy5sZW5ndGg7IGkrKykgewogICAgICAgIGxvb2t1cFtjaGFycy5jaGFyQ29kZUF0KGkpXSA9IGk7CiAgICB9CiAgICB2YXIgZW5jb2RlID0gZnVuY3Rpb24gKGFycmF5YnVmZmVyKSB7CiAgICAgICAgdmFyIGJ5dGVzID0gbmV3IFVpbnQ4QXJyYXkoYXJyYXlidWZmZXIpLCBpLCBsZW4gPSBieXRlcy5sZW5ndGgsIGJhc2U2NCA9ICcnOwogICAgICAgIGZvciAoaSA9IDA7IGkgPCBsZW47IGkgKz0gMykgewogICAgICAgICAgICBiYXNlNjQgKz0gY2hhcnNbYnl0ZXNbaV0gPj4gMl07CiAgICAgICAgICAgIGJhc2U2NCArPSBjaGFyc1soKGJ5dGVzW2ldICYgMykgPDwgNCkgfCAoYnl0ZXNbaSArIDFdID4+IDQpXTsKICAgICAgICAgICAgYmFzZTY0ICs9IGNoYXJzWygoYnl0ZXNbaSArIDFdICYgMTUpIDw8IDIpIHwgKGJ5dGVzW2kgKyAyXSA+PiA2KV07CiAgICAgICAgICAgIGJhc2U2NCArPSBjaGFyc1tieXRlc1tpICsgMl0gJiA2M107CiAgICAgICAgfQogICAgICAgIGlmIChsZW4gJSAzID09PSAyKSB7CiAgICAgICAgICAgIGJhc2U2NCA9IGJhc2U2NC5zdWJzdHJpbmcoMCwgYmFzZTY0Lmxlbmd0aCAtIDEpICsgJz0nOwogICAgICAgIH0KICAgICAgICBlbHNlIGlmIChsZW4gJSAzID09PSAxKSB7CiAgICAgICAgICAgIGJhc2U2NCA9IGJhc2U2NC5zdWJzdHJpbmcoMCwgYmFzZTY0Lmxlbmd0aCAtIDIpICsgJz09JzsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJhc2U2NDsKICAgIH07CgogICAgY29uc3QgbGFzdEJsb2JNYXAgPSBuZXcgTWFwKCk7DQogICAgY29uc3QgdHJhbnNwYXJlbnRCbG9iTWFwID0gbmV3IE1hcCgpOw0KICAgIGZ1bmN0aW9uIGdldFRyYW5zcGFyZW50QmxvYkZvcih3aWR0aCwgaGVpZ2h0LCBkYXRhVVJMT3B0aW9ucykgew0KICAgICAgICByZXR1cm4gX19hd2FpdGVyKHRoaXMsIHZvaWQgMCwgdm9pZCAwLCBmdW5jdGlvbiogKCkgew0KICAgICAgICAgICAgY29uc3QgaWQgPSBgJHt3aWR0aH0tJHtoZWlnaHR9YDsNCiAgICAgICAgICAgIGlmICgnT2Zmc2NyZWVuQ2FudmFzJyBpbiBnbG9iYWxUaGlzKSB7DQogICAgICAgICAgICAgICAgaWYgKHRyYW5zcGFyZW50QmxvYk1hcC5oYXMoaWQpKQ0KICAgICAgICAgICAgICAgICAgICByZXR1cm4gdHJhbnNwYXJlbnRCbG9iTWFwLmdldChpZCk7DQogICAgICAgICAgICAgICAgY29uc3Qgb2Zmc2NyZWVuID0gbmV3IE9mZnNjcmVlbkNhbnZhcyh3aWR0aCwgaGVpZ2h0KTsNCiAgICAgICAgICAgICAgICBvZmZzY3JlZW4uZ2V0Q29udGV4dCgnMmQnKTsNCiAgICAgICAgICAgICAgICBjb25zdCBibG9iID0geWllbGQgb2Zmc2NyZWVuLmNvbnZlcnRUb0Jsb2IoZGF0YVVSTE9wdGlvbnMpOw0KICAgICAgICAgICAgICAgIGNvbnN0IGFycmF5QnVmZmVyID0geWllbGQgYmxvYi5hcnJheUJ1ZmZlcigpOw0KICAgICAgICAgICAgICAgIGNvbnN0IGJhc2U2NCA9IGVuY29kZShhcnJheUJ1ZmZlcik7DQogICAgICAgICAgICAgICAgdHJhbnNwYXJlbnRCbG9iTWFwLnNldChpZCwgYmFzZTY0KTsNCiAgICAgICAgICAgICAgICByZXR1cm4gYmFzZTY0Ow0KICAgICAgICAgICAgfQ0KICAgICAgICAgICAgZWxzZSB7DQogICAgICAgICAgICAgICAgcmV0dXJuICcnOw0KICAgICAgICAgICAgfQ0KICAgICAgICB9KTsNCiAgICB9DQogICAgY29uc3Qgd29ya2VyID0gc2VsZjsNCiAgICB3b3JrZXIub25tZXNzYWdlID0gZnVuY3Rpb24gKGUpIHsNCiAgICAgICAgcmV0dXJuIF9fYXdhaXRlcih0aGlzLCB2b2lkIDAsIHZvaWQgMCwgZnVuY3Rpb24qICgpIHsNCiAgICAgICAgICAgIGlmICgnT2Zmc2NyZWVuQ2FudmFzJyBpbiBnbG9iYWxUaGlzKSB7DQogICAgICAgICAgICAgICAgY29uc3QgeyBpZCwgYml0bWFwLCB3aWR0aCwgaGVpZ2h0LCBkYXRhVVJMT3B0aW9ucyB9ID0gZS5kYXRhOw0KICAgICAgICAgICAgICAgIGNvbnN0IHRyYW5zcGFyZW50QmFzZTY0ID0gZ2V0VHJhbnNwYXJlbnRCbG9iRm9yKHdpZHRoLCBoZWlnaHQsIGRhdGFVUkxPcHRpb25zKTsNCiAgICAgICAgICAgICAgICBjb25zdCBvZmZzY3JlZW4gPSBuZXcgT2Zmc2NyZWVuQ2FudmFzKHdpZHRoLCBoZWlnaHQpOw0KICAgICAgICAgICAgICAgIGNvbnN0IGN0eCA9IG9mZnNjcmVlbi5nZXRDb250ZXh0KCcyZCcpOw0KICAgICAgICAgICAgICAgIGN0eC5kcmF3SW1hZ2UoYml0bWFwLCAwLCAwKTsNCiAgICAgICAgICAgICAgICBiaXRtYXAuY2xvc2UoKTsNCiAgICAgICAgICAgICAgICBjb25zdCBibG9iID0geWllbGQgb2Zmc2NyZWVuLmNvbnZlcnRUb0Jsb2IoZGF0YVVSTE9wdGlvbnMpOw0KICAgICAgICAgICAgICAgIGNvbnN0IHR5cGUgPSBibG9iLnR5cGU7DQogICAgICAgICAgICAgICAgY29uc3QgYXJyYXlCdWZmZXIgPSB5aWVsZCBibG9iLmFycmF5QnVmZmVyKCk7DQogICAgICAgICAgICAgICAgY29uc3QgYmFzZTY0ID0gZW5jb2RlKGFycmF5QnVmZmVyKTsNCiAgICAgICAgICAgICAgICBpZiAoIWxhc3RCbG9iTWFwLmhhcyhpZCkgJiYgKHlpZWxkIHRyYW5zcGFyZW50QmFzZTY0KSA9PT0gYmFzZTY0KSB7DQogICAgICAgICAgICAgICAgICAgIGxhc3RCbG9iTWFwLnNldChpZCwgYmFzZTY0KTsNCiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHdvcmtlci5wb3N0TWVzc2FnZSh7IGlkIH0pOw0KICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICBpZiAobGFzdEJsb2JNYXAuZ2V0KGlkKSA9PT0gYmFzZTY0KQ0KICAgICAgICAgICAgICAgICAgICByZXR1cm4gd29ya2VyLnBvc3RNZXNzYWdlKHsgaWQgfSk7DQogICAgICAgICAgICAgICAgd29ya2VyLnBvc3RNZXNzYWdlKHsNCiAgICAgICAgICAgICAgICAgICAgaWQsDQogICAgICAgICAgICAgICAgICAgIHR5cGUsDQogICAgICAgICAgICAgICAgICAgIGJhc2U2NCwNCiAgICAgICAgICAgICAgICAgICAgd2lkdGgsDQogICAgICAgICAgICAgICAgICAgIGhlaWdodCwNCiAgICAgICAgICAgICAgICB9KTsNCiAgICAgICAgICAgICAgICBsYXN0QmxvYk1hcC5zZXQoaWQsIGJhc2U2NCk7DQogICAgICAgICAgICB9DQogICAgICAgICAgICBlbHNlIHsNCiAgICAgICAgICAgICAgICByZXR1cm4gd29ya2VyLnBvc3RNZXNzYWdlKHsgaWQ6IGUuZGF0YS5pZCB9KTsNCiAgICAgICAgICAgIH0NCiAgICAgICAgfSk7DQogICAgfTsKCn0pKCk7Cgo=');
|
|
3340
|
+
|
|
3341
|
+
class CanvasManager {
|
|
3342
|
+
constructor(options) {
|
|
3343
|
+
this.pendingCanvasMutations = new Map();
|
|
3344
|
+
this.rafStamps = { latestId: 0, invokeId: null };
|
|
3345
|
+
this.frozen = false;
|
|
3346
|
+
this.locked = false;
|
|
3347
|
+
this.processMutation = (target, mutation) => {
|
|
3348
|
+
const newFrame = this.rafStamps.invokeId &&
|
|
3349
|
+
this.rafStamps.latestId !== this.rafStamps.invokeId;
|
|
3350
|
+
if (newFrame || !this.rafStamps.invokeId)
|
|
3351
|
+
this.rafStamps.invokeId = this.rafStamps.latestId;
|
|
3352
|
+
if (!this.pendingCanvasMutations.has(target)) {
|
|
3353
|
+
this.pendingCanvasMutations.set(target, []);
|
|
3354
|
+
}
|
|
3355
|
+
this.pendingCanvasMutations.get(target).push(mutation);
|
|
3356
|
+
};
|
|
3357
|
+
const { sampling = 'all', win, blockClass, blockSelector, recordCanvas, dataURLOptions, } = options;
|
|
3358
|
+
this.mutationCb = options.mutationCb;
|
|
3359
|
+
this.mirror = options.mirror;
|
|
3360
|
+
if (recordCanvas && sampling === 'all')
|
|
3361
|
+
this.initCanvasMutationObserver(win, blockClass, blockSelector);
|
|
3362
|
+
if (recordCanvas && typeof sampling === 'number')
|
|
3363
|
+
this.initCanvasFPSObserver(sampling, win, blockClass, blockSelector, {
|
|
3364
|
+
dataURLOptions,
|
|
3365
|
+
});
|
|
3366
|
+
}
|
|
3367
|
+
reset() {
|
|
3368
|
+
this.pendingCanvasMutations.clear();
|
|
3369
|
+
this.resetObservers && this.resetObservers();
|
|
3370
|
+
}
|
|
3371
|
+
freeze() {
|
|
3372
|
+
this.frozen = true;
|
|
3373
|
+
}
|
|
3374
|
+
unfreeze() {
|
|
3375
|
+
this.frozen = false;
|
|
3376
|
+
}
|
|
3377
|
+
lock() {
|
|
3378
|
+
this.locked = true;
|
|
3379
|
+
}
|
|
3380
|
+
unlock() {
|
|
3381
|
+
this.locked = false;
|
|
3382
|
+
}
|
|
3383
|
+
initCanvasFPSObserver(fps, win, blockClass, blockSelector, options) {
|
|
3384
|
+
const canvasContextReset = initCanvasContextObserver(win, blockClass, blockSelector);
|
|
3385
|
+
const snapshotInProgressMap = new Map();
|
|
3386
|
+
const worker = new WorkerFactory();
|
|
3387
|
+
worker.onmessage = (e) => {
|
|
3388
|
+
const { id } = e.data;
|
|
3389
|
+
snapshotInProgressMap.set(id, false);
|
|
3390
|
+
if (!('base64' in e.data))
|
|
3391
|
+
return;
|
|
3392
|
+
const { base64, type, width, height } = e.data;
|
|
3393
|
+
this.mutationCb({
|
|
3394
|
+
id,
|
|
3395
|
+
type: CanvasContext['2D'],
|
|
3396
|
+
commands: [
|
|
3397
|
+
{
|
|
3398
|
+
property: 'clearRect',
|
|
3399
|
+
args: [0, 0, width, height],
|
|
3400
|
+
},
|
|
3401
|
+
{
|
|
3402
|
+
property: 'drawImage',
|
|
3403
|
+
args: [
|
|
3404
|
+
{
|
|
3405
|
+
rr_type: 'ImageBitmap',
|
|
3406
|
+
args: [
|
|
3407
|
+
{
|
|
3408
|
+
rr_type: 'Blob',
|
|
3409
|
+
data: [{ rr_type: 'ArrayBuffer', base64 }],
|
|
3410
|
+
type,
|
|
3411
|
+
},
|
|
3412
|
+
],
|
|
3413
|
+
},
|
|
3414
|
+
0,
|
|
3415
|
+
0,
|
|
3416
|
+
],
|
|
3417
|
+
},
|
|
3418
|
+
],
|
|
3419
|
+
});
|
|
3420
|
+
};
|
|
3421
|
+
const timeBetweenSnapshots = 1000 / fps;
|
|
3422
|
+
let lastSnapshotTime = 0;
|
|
3423
|
+
let rafId;
|
|
3424
|
+
const getCanvas = () => {
|
|
3425
|
+
const matchedCanvas = [];
|
|
3426
|
+
win.document.querySelectorAll('canvas').forEach((canvas) => {
|
|
3427
|
+
if (!isBlocked(canvas, blockClass, blockSelector, true)) {
|
|
3428
|
+
matchedCanvas.push(canvas);
|
|
3429
|
+
}
|
|
3430
|
+
});
|
|
3431
|
+
return matchedCanvas;
|
|
3432
|
+
};
|
|
3433
|
+
const takeCanvasSnapshots = (timestamp) => {
|
|
3434
|
+
if (lastSnapshotTime &&
|
|
3435
|
+
timestamp - lastSnapshotTime < timeBetweenSnapshots) {
|
|
3436
|
+
rafId = requestAnimationFrame(takeCanvasSnapshots);
|
|
3437
|
+
return;
|
|
3438
|
+
}
|
|
3439
|
+
lastSnapshotTime = timestamp;
|
|
3440
|
+
getCanvas()
|
|
3441
|
+
.forEach((canvas) => __awaiter(this, void 0, void 0, function* () {
|
|
3442
|
+
var _a;
|
|
3443
|
+
const id = this.mirror.getId(canvas);
|
|
3444
|
+
if (snapshotInProgressMap.get(id))
|
|
3445
|
+
return;
|
|
3446
|
+
snapshotInProgressMap.set(id, true);
|
|
3447
|
+
if (['webgl', 'webgl2'].includes(canvas.__context)) {
|
|
3448
|
+
const context = canvas.getContext(canvas.__context);
|
|
3449
|
+
if (((_a = context === null || context === void 0 ? void 0 : context.getContextAttributes()) === null || _a === void 0 ? void 0 : _a.preserveDrawingBuffer) === false) {
|
|
3450
|
+
context === null || context === void 0 ? void 0 : context.clear(context.COLOR_BUFFER_BIT);
|
|
3451
|
+
}
|
|
3452
|
+
}
|
|
3453
|
+
const bitmap = yield createImageBitmap(canvas);
|
|
3454
|
+
worker.postMessage({
|
|
3455
|
+
id,
|
|
3456
|
+
bitmap,
|
|
3457
|
+
width: canvas.width,
|
|
3458
|
+
height: canvas.height,
|
|
3459
|
+
dataURLOptions: options.dataURLOptions,
|
|
3460
|
+
}, [bitmap]);
|
|
3461
|
+
}));
|
|
3462
|
+
rafId = requestAnimationFrame(takeCanvasSnapshots);
|
|
3463
|
+
};
|
|
3464
|
+
rafId = requestAnimationFrame(takeCanvasSnapshots);
|
|
3465
|
+
this.resetObservers = () => {
|
|
3466
|
+
canvasContextReset();
|
|
3467
|
+
cancelAnimationFrame(rafId);
|
|
3468
|
+
};
|
|
3469
|
+
}
|
|
3470
|
+
initCanvasMutationObserver(win, blockClass, blockSelector) {
|
|
3471
|
+
this.startRAFTimestamping();
|
|
3472
|
+
this.startPendingCanvasMutationFlusher();
|
|
3473
|
+
const canvasContextReset = initCanvasContextObserver(win, blockClass, blockSelector);
|
|
3474
|
+
const canvas2DReset = initCanvas2DMutationObserver(this.processMutation.bind(this), win, blockClass, blockSelector);
|
|
3475
|
+
const canvasWebGL1and2Reset = initCanvasWebGLMutationObserver(this.processMutation.bind(this), win, blockClass, blockSelector, this.mirror);
|
|
3476
|
+
this.resetObservers = () => {
|
|
3477
|
+
canvasContextReset();
|
|
3478
|
+
canvas2DReset();
|
|
3479
|
+
canvasWebGL1and2Reset();
|
|
3480
|
+
};
|
|
3481
|
+
}
|
|
3482
|
+
startPendingCanvasMutationFlusher() {
|
|
3483
|
+
requestAnimationFrame(() => this.flushPendingCanvasMutations());
|
|
3484
|
+
}
|
|
3485
|
+
startRAFTimestamping() {
|
|
3486
|
+
const setLatestRAFTimestamp = (timestamp) => {
|
|
3487
|
+
this.rafStamps.latestId = timestamp;
|
|
3488
|
+
requestAnimationFrame(setLatestRAFTimestamp);
|
|
3489
|
+
};
|
|
3490
|
+
requestAnimationFrame(setLatestRAFTimestamp);
|
|
3491
|
+
}
|
|
3492
|
+
flushPendingCanvasMutations() {
|
|
3493
|
+
this.pendingCanvasMutations.forEach((values, canvas) => {
|
|
3494
|
+
const id = this.mirror.getId(canvas);
|
|
3495
|
+
this.flushPendingCanvasMutationFor(canvas, id);
|
|
3496
|
+
});
|
|
3497
|
+
requestAnimationFrame(() => this.flushPendingCanvasMutations());
|
|
3498
|
+
}
|
|
3499
|
+
flushPendingCanvasMutationFor(canvas, id) {
|
|
3500
|
+
if (this.frozen || this.locked) {
|
|
3501
|
+
return;
|
|
3502
|
+
}
|
|
3503
|
+
const valuesWithType = this.pendingCanvasMutations.get(canvas);
|
|
3504
|
+
if (!valuesWithType || id === -1)
|
|
3505
|
+
return;
|
|
3506
|
+
const values = valuesWithType.map((value) => {
|
|
3507
|
+
const rest = __rest(value, ["type"]);
|
|
3508
|
+
return rest;
|
|
3509
|
+
});
|
|
3510
|
+
const { type } = valuesWithType[0];
|
|
3511
|
+
this.mutationCb({ id, type, commands: values });
|
|
3512
|
+
this.pendingCanvasMutations.delete(canvas);
|
|
3513
|
+
}
|
|
3514
|
+
}
|
|
3515
|
+
|
|
3516
|
+
class StylesheetManager {
|
|
3517
|
+
constructor(options) {
|
|
3518
|
+
this.trackedLinkElements = new WeakSet();
|
|
3519
|
+
this.styleMirror = new StyleSheetMirror();
|
|
3520
|
+
this.mutationCb = options.mutationCb;
|
|
3521
|
+
this.adoptedStyleSheetCb = options.adoptedStyleSheetCb;
|
|
3522
|
+
}
|
|
3523
|
+
attachLinkElement(linkEl, childSn) {
|
|
3524
|
+
if ('_cssText' in childSn.attributes)
|
|
3525
|
+
this.mutationCb({
|
|
3526
|
+
adds: [],
|
|
3527
|
+
removes: [],
|
|
3528
|
+
texts: [],
|
|
3529
|
+
attributes: [
|
|
3530
|
+
{
|
|
3531
|
+
id: childSn.id,
|
|
3532
|
+
attributes: childSn
|
|
3533
|
+
.attributes,
|
|
3534
|
+
},
|
|
3535
|
+
],
|
|
3536
|
+
});
|
|
3537
|
+
this.trackLinkElement(linkEl);
|
|
3538
|
+
}
|
|
3539
|
+
trackLinkElement(linkEl) {
|
|
3540
|
+
if (this.trackedLinkElements.has(linkEl))
|
|
3541
|
+
return;
|
|
3542
|
+
this.trackedLinkElements.add(linkEl);
|
|
3543
|
+
this.trackStylesheetInLinkElement(linkEl);
|
|
3544
|
+
}
|
|
3545
|
+
adoptStyleSheets(sheets, hostId) {
|
|
3546
|
+
if (sheets.length === 0)
|
|
3547
|
+
return;
|
|
3548
|
+
const adoptedStyleSheetData = {
|
|
3549
|
+
id: hostId,
|
|
3550
|
+
styleIds: [],
|
|
3551
|
+
};
|
|
3552
|
+
const styles = [];
|
|
3553
|
+
for (const sheet of sheets) {
|
|
3554
|
+
let styleId;
|
|
3555
|
+
if (!this.styleMirror.has(sheet)) {
|
|
3556
|
+
styleId = this.styleMirror.add(sheet);
|
|
3557
|
+
const rules = Array.from(sheet.rules || CSSRule);
|
|
3558
|
+
styles.push({
|
|
3559
|
+
styleId,
|
|
3560
|
+
rules: rules.map((r, index) => {
|
|
3561
|
+
return {
|
|
3562
|
+
rule: getCssRuleString(r),
|
|
3563
|
+
index,
|
|
3564
|
+
};
|
|
3565
|
+
}),
|
|
3566
|
+
});
|
|
3567
|
+
}
|
|
3568
|
+
else
|
|
3569
|
+
styleId = this.styleMirror.getId(sheet);
|
|
3570
|
+
adoptedStyleSheetData.styleIds.push(styleId);
|
|
3571
|
+
}
|
|
3572
|
+
if (styles.length > 0)
|
|
3573
|
+
adoptedStyleSheetData.styles = styles;
|
|
3574
|
+
this.adoptedStyleSheetCb(adoptedStyleSheetData);
|
|
3575
|
+
}
|
|
3576
|
+
reset() {
|
|
3577
|
+
this.styleMirror.reset();
|
|
3578
|
+
this.trackedLinkElements = new WeakSet();
|
|
3579
|
+
}
|
|
3580
|
+
trackStylesheetInLinkElement(linkEl) {
|
|
3581
|
+
}
|
|
3582
|
+
}
|
|
3583
|
+
|
|
3584
|
+
function wrapEvent(e) {
|
|
3585
|
+
return Object.assign(Object.assign({}, e), { timestamp: Date.now() });
|
|
3586
|
+
}
|
|
3587
|
+
let wrappedEmit;
|
|
3588
|
+
let takeFullSnapshot;
|
|
3589
|
+
let canvasManager;
|
|
3590
|
+
let recording = false;
|
|
3591
|
+
const mirror = createMirror();
|
|
3592
|
+
function record(options = {}) {
|
|
3593
|
+
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;
|
|
3594
|
+
const inEmittingFrame = recordCrossOriginIframes
|
|
3595
|
+
? window.parent === window
|
|
3596
|
+
: true;
|
|
3597
|
+
let passEmitsToParent = false;
|
|
3598
|
+
if (!inEmittingFrame) {
|
|
3599
|
+
try {
|
|
3600
|
+
window.parent.document;
|
|
3601
|
+
passEmitsToParent = false;
|
|
3602
|
+
}
|
|
3603
|
+
catch (e) {
|
|
3604
|
+
passEmitsToParent = true;
|
|
3605
|
+
}
|
|
3606
|
+
}
|
|
3607
|
+
if (inEmittingFrame && !emit) {
|
|
3608
|
+
throw new Error('emit function is required');
|
|
3609
|
+
}
|
|
3610
|
+
if (mousemoveWait !== undefined && sampling.mousemove === undefined) {
|
|
3611
|
+
sampling.mousemove = mousemoveWait;
|
|
3612
|
+
}
|
|
3613
|
+
mirror.reset();
|
|
3614
|
+
const maskInputOptions = maskAllInputs === true
|
|
3615
|
+
? {
|
|
3616
|
+
color: true,
|
|
3617
|
+
date: true,
|
|
3618
|
+
'datetime-local': true,
|
|
3619
|
+
email: true,
|
|
3620
|
+
month: true,
|
|
3621
|
+
number: true,
|
|
3622
|
+
range: true,
|
|
3623
|
+
search: true,
|
|
3624
|
+
tel: true,
|
|
3625
|
+
text: true,
|
|
3626
|
+
time: true,
|
|
3627
|
+
url: true,
|
|
3628
|
+
week: true,
|
|
3629
|
+
textarea: true,
|
|
3630
|
+
select: true,
|
|
3631
|
+
password: true,
|
|
3632
|
+
}
|
|
3633
|
+
: _maskInputOptions !== undefined
|
|
3634
|
+
? _maskInputOptions
|
|
3635
|
+
: { password: true };
|
|
3636
|
+
const slimDOMOptions = _slimDOMOptions === true || _slimDOMOptions === 'all'
|
|
3637
|
+
? {
|
|
3638
|
+
script: true,
|
|
3639
|
+
comment: true,
|
|
3640
|
+
headFavicon: true,
|
|
3641
|
+
headWhitespace: true,
|
|
3642
|
+
headMetaSocial: true,
|
|
3643
|
+
headMetaRobots: true,
|
|
3644
|
+
headMetaHttpEquiv: true,
|
|
3645
|
+
headMetaVerification: true,
|
|
3646
|
+
headMetaAuthorship: _slimDOMOptions === 'all',
|
|
3647
|
+
headMetaDescKeywords: _slimDOMOptions === 'all',
|
|
3648
|
+
}
|
|
3649
|
+
: _slimDOMOptions
|
|
3650
|
+
? _slimDOMOptions
|
|
3651
|
+
: {};
|
|
3652
|
+
polyfill();
|
|
3653
|
+
let lastFullSnapshotEvent;
|
|
3654
|
+
let incrementalSnapshotCount = 0;
|
|
3655
|
+
const eventProcessor = (e) => {
|
|
3656
|
+
for (const plugin of plugins || []) {
|
|
3657
|
+
if (plugin.eventProcessor) {
|
|
3658
|
+
e = plugin.eventProcessor(e);
|
|
3659
|
+
}
|
|
3660
|
+
}
|
|
3661
|
+
if (packFn) {
|
|
3662
|
+
e = packFn(e);
|
|
3663
|
+
}
|
|
3664
|
+
return e;
|
|
3665
|
+
};
|
|
3666
|
+
wrappedEmit = (e, isCheckout) => {
|
|
3667
|
+
var _a;
|
|
3668
|
+
if (((_a = mutationBuffers[0]) === null || _a === void 0 ? void 0 : _a.isFrozen()) &&
|
|
3669
|
+
e.type !== EventType.FullSnapshot &&
|
|
3670
|
+
!(e.type === EventType.IncrementalSnapshot &&
|
|
3671
|
+
e.data.source === IncrementalSource.Mutation)) {
|
|
3672
|
+
mutationBuffers.forEach((buf) => buf.unfreeze());
|
|
3673
|
+
}
|
|
3674
|
+
if (inEmittingFrame) {
|
|
3675
|
+
emit === null || emit === void 0 ? void 0 : emit(eventProcessor(e), isCheckout);
|
|
3676
|
+
}
|
|
3677
|
+
else if (passEmitsToParent) {
|
|
3678
|
+
const message = {
|
|
3679
|
+
type: 'rrweb',
|
|
3680
|
+
event: eventProcessor(e),
|
|
3681
|
+
isCheckout,
|
|
3682
|
+
};
|
|
3683
|
+
window.parent.postMessage(message, '*');
|
|
3684
|
+
}
|
|
3685
|
+
if (e.type === EventType.FullSnapshot) {
|
|
3686
|
+
lastFullSnapshotEvent = e;
|
|
3687
|
+
incrementalSnapshotCount = 0;
|
|
3688
|
+
}
|
|
3689
|
+
else if (e.type === EventType.IncrementalSnapshot) {
|
|
3690
|
+
if (e.data.source === IncrementalSource.Mutation &&
|
|
3691
|
+
e.data.isAttachIframe) {
|
|
3692
|
+
return;
|
|
3693
|
+
}
|
|
3694
|
+
incrementalSnapshotCount++;
|
|
3695
|
+
const exceedCount = checkoutEveryNth && incrementalSnapshotCount >= checkoutEveryNth;
|
|
3696
|
+
const exceedTime = checkoutEveryNms &&
|
|
3697
|
+
e.timestamp - lastFullSnapshotEvent.timestamp > checkoutEveryNms;
|
|
3698
|
+
if (exceedCount || exceedTime) {
|
|
3699
|
+
takeFullSnapshot(true);
|
|
3700
|
+
}
|
|
3701
|
+
}
|
|
3702
|
+
};
|
|
3703
|
+
const wrappedMutationEmit = (m) => {
|
|
3704
|
+
wrappedEmit(wrapEvent({
|
|
3705
|
+
type: EventType.IncrementalSnapshot,
|
|
3706
|
+
data: Object.assign({ source: IncrementalSource.Mutation }, m),
|
|
3707
|
+
}));
|
|
3708
|
+
};
|
|
3709
|
+
const wrappedScrollEmit = (p) => wrappedEmit(wrapEvent({
|
|
3710
|
+
type: EventType.IncrementalSnapshot,
|
|
3711
|
+
data: Object.assign({ source: IncrementalSource.Scroll }, p),
|
|
3712
|
+
}));
|
|
3713
|
+
const wrappedCanvasMutationEmit = (p) => wrappedEmit(wrapEvent({
|
|
3714
|
+
type: EventType.IncrementalSnapshot,
|
|
3715
|
+
data: Object.assign({ source: IncrementalSource.CanvasMutation }, p),
|
|
3716
|
+
}));
|
|
3717
|
+
const wrappedAdoptedStyleSheetEmit = (a) => wrappedEmit(wrapEvent({
|
|
3718
|
+
type: EventType.IncrementalSnapshot,
|
|
3719
|
+
data: Object.assign({ source: IncrementalSource.AdoptedStyleSheet }, a),
|
|
3720
|
+
}));
|
|
3721
|
+
const stylesheetManager = new StylesheetManager({
|
|
3722
|
+
mutationCb: wrappedMutationEmit,
|
|
3723
|
+
adoptedStyleSheetCb: wrappedAdoptedStyleSheetEmit,
|
|
3724
|
+
});
|
|
3725
|
+
const iframeManager = new IframeManager({
|
|
3726
|
+
mirror,
|
|
3727
|
+
mutationCb: wrappedMutationEmit,
|
|
3728
|
+
stylesheetManager: stylesheetManager,
|
|
3729
|
+
recordCrossOriginIframes,
|
|
3730
|
+
wrappedEmit,
|
|
3731
|
+
});
|
|
3732
|
+
for (const plugin of plugins || []) {
|
|
3733
|
+
if (plugin.getMirror)
|
|
3734
|
+
plugin.getMirror({
|
|
3735
|
+
nodeMirror: mirror,
|
|
3736
|
+
crossOriginIframeMirror: iframeManager.crossOriginIframeMirror,
|
|
3737
|
+
crossOriginIframeStyleMirror: iframeManager.crossOriginIframeStyleMirror,
|
|
3738
|
+
});
|
|
3739
|
+
}
|
|
3740
|
+
canvasManager = new CanvasManager({
|
|
3741
|
+
recordCanvas,
|
|
3742
|
+
mutationCb: wrappedCanvasMutationEmit,
|
|
3743
|
+
win: window,
|
|
3744
|
+
blockClass,
|
|
3745
|
+
blockSelector,
|
|
3746
|
+
mirror,
|
|
3747
|
+
sampling: sampling.canvas,
|
|
3748
|
+
dataURLOptions,
|
|
3749
|
+
});
|
|
3750
|
+
const shadowDomManager = new ShadowDomManager({
|
|
3751
|
+
mutationCb: wrappedMutationEmit,
|
|
3752
|
+
scrollCb: wrappedScrollEmit,
|
|
3753
|
+
bypassOptions: {
|
|
3754
|
+
blockClass,
|
|
3755
|
+
blockSelector,
|
|
3756
|
+
maskTextClass,
|
|
3757
|
+
maskTextSelector,
|
|
3758
|
+
inlineStylesheet,
|
|
3759
|
+
maskInputOptions,
|
|
3760
|
+
dataURLOptions,
|
|
3761
|
+
maskTextFn,
|
|
3762
|
+
maskInputFn,
|
|
3763
|
+
recordCanvas,
|
|
3764
|
+
inlineImages,
|
|
3765
|
+
sampling,
|
|
3766
|
+
slimDOMOptions,
|
|
3767
|
+
iframeManager,
|
|
3768
|
+
stylesheetManager,
|
|
3769
|
+
canvasManager,
|
|
3770
|
+
keepIframeSrcFn,
|
|
3771
|
+
},
|
|
3772
|
+
mirror,
|
|
3773
|
+
});
|
|
3774
|
+
takeFullSnapshot = (isCheckout = false) => {
|
|
3775
|
+
var _a, _b, _c, _d, _e, _f;
|
|
3776
|
+
wrappedEmit(wrapEvent({
|
|
3777
|
+
type: EventType.Meta,
|
|
3778
|
+
data: {
|
|
3779
|
+
href: window.location.href,
|
|
3780
|
+
width: getWindowWidth(),
|
|
3781
|
+
height: getWindowHeight(),
|
|
3782
|
+
},
|
|
3783
|
+
}), isCheckout);
|
|
3784
|
+
stylesheetManager.reset();
|
|
3785
|
+
mutationBuffers.forEach((buf) => buf.lock());
|
|
3786
|
+
const node = snapshot(document, {
|
|
3787
|
+
mirror,
|
|
3788
|
+
blockClass,
|
|
3789
|
+
blockSelector,
|
|
3790
|
+
maskTextClass,
|
|
3791
|
+
maskTextSelector,
|
|
3792
|
+
inlineStylesheet,
|
|
3793
|
+
maskAllInputs: maskInputOptions,
|
|
3794
|
+
maskTextFn,
|
|
3795
|
+
slimDOM: slimDOMOptions,
|
|
3796
|
+
dataURLOptions,
|
|
3797
|
+
recordCanvas,
|
|
3798
|
+
inlineImages,
|
|
3799
|
+
onSerialize: (n) => {
|
|
3800
|
+
if (isSerializedIframe(n, mirror)) {
|
|
3801
|
+
iframeManager.addIframe(n);
|
|
3802
|
+
}
|
|
3803
|
+
if (isSerializedStylesheet(n, mirror)) {
|
|
3804
|
+
stylesheetManager.trackLinkElement(n);
|
|
3805
|
+
}
|
|
3806
|
+
if (hasShadowRoot(n)) {
|
|
3807
|
+
shadowDomManager.addShadowRoot(n.shadowRoot, document);
|
|
3808
|
+
}
|
|
3809
|
+
},
|
|
3810
|
+
onIframeLoad: (iframe, childSn) => {
|
|
3811
|
+
iframeManager.attachIframe(iframe, childSn);
|
|
3812
|
+
shadowDomManager.observeAttachShadow(iframe);
|
|
3813
|
+
},
|
|
3814
|
+
onStylesheetLoad: (linkEl, childSn) => {
|
|
3815
|
+
stylesheetManager.attachLinkElement(linkEl, childSn);
|
|
3816
|
+
},
|
|
3817
|
+
keepIframeSrcFn,
|
|
3818
|
+
});
|
|
3819
|
+
if (!node) {
|
|
3820
|
+
return console.warn('Failed to snapshot the document');
|
|
3821
|
+
}
|
|
3822
|
+
wrappedEmit(wrapEvent({
|
|
3823
|
+
type: EventType.FullSnapshot,
|
|
3824
|
+
data: {
|
|
3825
|
+
node,
|
|
3826
|
+
initialOffset: {
|
|
3827
|
+
left: window.pageXOffset !== undefined
|
|
3828
|
+
? window.pageXOffset
|
|
3829
|
+
: (document === null || document === void 0 ? void 0 : document.documentElement.scrollLeft) ||
|
|
3830
|
+
((_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) ||
|
|
3831
|
+
((_c = document === null || document === void 0 ? void 0 : document.body) === null || _c === void 0 ? void 0 : _c.scrollLeft) ||
|
|
3832
|
+
0,
|
|
3833
|
+
top: window.pageYOffset !== undefined
|
|
3834
|
+
? window.pageYOffset
|
|
3835
|
+
: (document === null || document === void 0 ? void 0 : document.documentElement.scrollTop) ||
|
|
3836
|
+
((_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) ||
|
|
3837
|
+
((_f = document === null || document === void 0 ? void 0 : document.body) === null || _f === void 0 ? void 0 : _f.scrollTop) ||
|
|
3838
|
+
0,
|
|
3839
|
+
},
|
|
3840
|
+
},
|
|
3841
|
+
}));
|
|
3842
|
+
mutationBuffers.forEach((buf) => buf.unlock());
|
|
3843
|
+
if (document.adoptedStyleSheets && document.adoptedStyleSheets.length > 0)
|
|
3844
|
+
stylesheetManager.adoptStyleSheets(document.adoptedStyleSheets, mirror.getId(document));
|
|
3845
|
+
};
|
|
3846
|
+
try {
|
|
3847
|
+
const handlers = [];
|
|
3848
|
+
handlers.push(on('DOMContentLoaded', () => {
|
|
3849
|
+
wrappedEmit(wrapEvent({
|
|
3850
|
+
type: EventType.DomContentLoaded,
|
|
3851
|
+
data: {},
|
|
3852
|
+
}));
|
|
3853
|
+
}));
|
|
3854
|
+
const observe = (doc) => {
|
|
3855
|
+
var _a;
|
|
3856
|
+
return initObservers({
|
|
3857
|
+
mutationCb: wrappedMutationEmit,
|
|
3858
|
+
mousemoveCb: (positions, source) => wrappedEmit(wrapEvent({
|
|
3859
|
+
type: EventType.IncrementalSnapshot,
|
|
3860
|
+
data: {
|
|
3861
|
+
source,
|
|
3862
|
+
positions,
|
|
3863
|
+
},
|
|
3864
|
+
})),
|
|
3865
|
+
mouseInteractionCb: (d) => wrappedEmit(wrapEvent({
|
|
3866
|
+
type: EventType.IncrementalSnapshot,
|
|
3867
|
+
data: Object.assign({ source: IncrementalSource.MouseInteraction }, d),
|
|
3868
|
+
})),
|
|
3869
|
+
scrollCb: wrappedScrollEmit,
|
|
3870
|
+
viewportResizeCb: (d) => wrappedEmit(wrapEvent({
|
|
3871
|
+
type: EventType.IncrementalSnapshot,
|
|
3872
|
+
data: Object.assign({ source: IncrementalSource.ViewportResize }, d),
|
|
3873
|
+
})),
|
|
3874
|
+
inputCb: (v) => wrappedEmit(wrapEvent({
|
|
3875
|
+
type: EventType.IncrementalSnapshot,
|
|
3876
|
+
data: Object.assign({ source: IncrementalSource.Input }, v),
|
|
3877
|
+
})),
|
|
3878
|
+
mediaInteractionCb: (p) => wrappedEmit(wrapEvent({
|
|
3879
|
+
type: EventType.IncrementalSnapshot,
|
|
3880
|
+
data: Object.assign({ source: IncrementalSource.MediaInteraction }, p),
|
|
3881
|
+
})),
|
|
3882
|
+
styleSheetRuleCb: (r) => wrappedEmit(wrapEvent({
|
|
3883
|
+
type: EventType.IncrementalSnapshot,
|
|
3884
|
+
data: Object.assign({ source: IncrementalSource.StyleSheetRule }, r),
|
|
3885
|
+
})),
|
|
3886
|
+
styleDeclarationCb: (r) => wrappedEmit(wrapEvent({
|
|
3887
|
+
type: EventType.IncrementalSnapshot,
|
|
3888
|
+
data: Object.assign({ source: IncrementalSource.StyleDeclaration }, r),
|
|
3889
|
+
})),
|
|
3890
|
+
canvasMutationCb: wrappedCanvasMutationEmit,
|
|
3891
|
+
fontCb: (p) => wrappedEmit(wrapEvent({
|
|
3892
|
+
type: EventType.IncrementalSnapshot,
|
|
3893
|
+
data: Object.assign({ source: IncrementalSource.Font }, p),
|
|
3894
|
+
})),
|
|
3895
|
+
selectionCb: (p) => {
|
|
3896
|
+
wrappedEmit(wrapEvent({
|
|
3897
|
+
type: EventType.IncrementalSnapshot,
|
|
3898
|
+
data: Object.assign({ source: IncrementalSource.Selection }, p),
|
|
3899
|
+
}));
|
|
3900
|
+
},
|
|
3901
|
+
blockClass,
|
|
3902
|
+
ignoreClass,
|
|
3903
|
+
maskTextClass,
|
|
3904
|
+
maskTextSelector,
|
|
3905
|
+
maskInputOptions,
|
|
3906
|
+
inlineStylesheet,
|
|
3907
|
+
sampling,
|
|
3908
|
+
recordCanvas,
|
|
3909
|
+
inlineImages,
|
|
3910
|
+
userTriggeredOnInput,
|
|
3911
|
+
collectFonts,
|
|
3912
|
+
doc,
|
|
3913
|
+
maskInputFn,
|
|
3914
|
+
maskTextFn,
|
|
3915
|
+
keepIframeSrcFn,
|
|
3916
|
+
blockSelector,
|
|
3917
|
+
slimDOMOptions,
|
|
3918
|
+
dataURLOptions,
|
|
3919
|
+
mirror,
|
|
3920
|
+
iframeManager,
|
|
3921
|
+
stylesheetManager,
|
|
3922
|
+
shadowDomManager,
|
|
3923
|
+
canvasManager,
|
|
3924
|
+
ignoreCSSAttributes,
|
|
3925
|
+
plugins: ((_a = plugins === null || plugins === void 0 ? void 0 : plugins.filter((p) => p.observer)) === null || _a === void 0 ? void 0 : _a.map((p) => ({
|
|
3926
|
+
observer: p.observer,
|
|
3927
|
+
options: p.options,
|
|
3928
|
+
callback: (payload) => wrappedEmit(wrapEvent({
|
|
3929
|
+
type: EventType.Plugin,
|
|
3930
|
+
data: {
|
|
3931
|
+
plugin: p.name,
|
|
3932
|
+
payload,
|
|
3933
|
+
},
|
|
3934
|
+
})),
|
|
3935
|
+
}))) || [],
|
|
3936
|
+
}, hooks);
|
|
3937
|
+
};
|
|
3938
|
+
iframeManager.addLoadListener((iframeEl) => {
|
|
3939
|
+
handlers.push(observe(iframeEl.contentDocument));
|
|
3940
|
+
});
|
|
3941
|
+
const init = () => {
|
|
3942
|
+
takeFullSnapshot();
|
|
3943
|
+
handlers.push(observe(document));
|
|
3944
|
+
recording = true;
|
|
3945
|
+
};
|
|
3946
|
+
if (document.readyState === 'interactive' ||
|
|
3947
|
+
document.readyState === 'complete') {
|
|
3948
|
+
init();
|
|
3949
|
+
}
|
|
3950
|
+
else {
|
|
3951
|
+
handlers.push(on('load', () => {
|
|
3952
|
+
wrappedEmit(wrapEvent({
|
|
3953
|
+
type: EventType.Load,
|
|
3954
|
+
data: {},
|
|
3955
|
+
}));
|
|
3956
|
+
init();
|
|
3957
|
+
}, window));
|
|
3958
|
+
}
|
|
3959
|
+
return () => {
|
|
3960
|
+
handlers.forEach((h) => h());
|
|
3961
|
+
recording = false;
|
|
3962
|
+
};
|
|
3963
|
+
}
|
|
3964
|
+
catch (error) {
|
|
3965
|
+
console.warn(error);
|
|
3966
|
+
}
|
|
3967
|
+
}
|
|
3968
|
+
record.addCustomEvent = (tag, payload) => {
|
|
3969
|
+
if (!recording) {
|
|
3970
|
+
throw new Error('please add custom event after start recording');
|
|
3971
|
+
}
|
|
3972
|
+
wrappedEmit(wrapEvent({
|
|
3973
|
+
type: EventType.Custom,
|
|
3974
|
+
data: {
|
|
3975
|
+
tag,
|
|
3976
|
+
payload,
|
|
3977
|
+
},
|
|
3978
|
+
}));
|
|
3979
|
+
};
|
|
3980
|
+
record.freezePage = () => {
|
|
3981
|
+
mutationBuffers.forEach((buf) => buf.freeze());
|
|
3982
|
+
};
|
|
3983
|
+
record.takeFullSnapshot = (isCheckout) => {
|
|
3984
|
+
if (!recording) {
|
|
3985
|
+
throw new Error('please take full snapshot after start recording');
|
|
3986
|
+
}
|
|
3987
|
+
takeFullSnapshot(isCheckout);
|
|
3988
|
+
};
|
|
3989
|
+
record.mirror = mirror;
|
|
3990
|
+
|
|
3991
|
+
const byteToHex = [];
|
|
3992
|
+
for (let i = 0; i < 256; ++i) {
|
|
3993
|
+
byteToHex.push((i + 0x100).toString(16).slice(1));
|
|
3994
|
+
}
|
|
3995
|
+
function unsafeStringify(arr, offset = 0) {
|
|
3996
|
+
return (byteToHex[arr[offset + 0]] +
|
|
3997
|
+
byteToHex[arr[offset + 1]] +
|
|
3998
|
+
byteToHex[arr[offset + 2]] +
|
|
3999
|
+
byteToHex[arr[offset + 3]] +
|
|
4000
|
+
'-' +
|
|
4001
|
+
byteToHex[arr[offset + 4]] +
|
|
4002
|
+
byteToHex[arr[offset + 5]] +
|
|
4003
|
+
'-' +
|
|
4004
|
+
byteToHex[arr[offset + 6]] +
|
|
4005
|
+
byteToHex[arr[offset + 7]] +
|
|
4006
|
+
'-' +
|
|
4007
|
+
byteToHex[arr[offset + 8]] +
|
|
4008
|
+
byteToHex[arr[offset + 9]] +
|
|
4009
|
+
'-' +
|
|
4010
|
+
byteToHex[arr[offset + 10]] +
|
|
4011
|
+
byteToHex[arr[offset + 11]] +
|
|
4012
|
+
byteToHex[arr[offset + 12]] +
|
|
4013
|
+
byteToHex[arr[offset + 13]] +
|
|
4014
|
+
byteToHex[arr[offset + 14]] +
|
|
4015
|
+
byteToHex[arr[offset + 15]]).toLowerCase();
|
|
4016
|
+
}
|
|
4017
|
+
|
|
4018
|
+
let getRandomValues;
|
|
4019
|
+
const rnds8 = new Uint8Array(16);
|
|
4020
|
+
function rng() {
|
|
4021
|
+
if (!getRandomValues) {
|
|
4022
|
+
if (typeof crypto === 'undefined' || !crypto.getRandomValues) {
|
|
4023
|
+
throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
|
|
4024
|
+
}
|
|
4025
|
+
getRandomValues = crypto.getRandomValues.bind(crypto);
|
|
4026
|
+
}
|
|
4027
|
+
return getRandomValues(rnds8);
|
|
4028
|
+
}
|
|
4029
|
+
|
|
4030
|
+
const _state = {};
|
|
4031
|
+
function v1(options, buf, offset) {
|
|
4032
|
+
let bytes;
|
|
4033
|
+
{
|
|
4034
|
+
const now = Date.now();
|
|
4035
|
+
const rnds = rng();
|
|
4036
|
+
updateV1State(_state, now, rnds);
|
|
4037
|
+
bytes = v1Bytes(rnds, _state.msecs, _state.nsecs, _state.clockseq, _state.node, buf, offset);
|
|
4038
|
+
}
|
|
4039
|
+
return buf ?? unsafeStringify(bytes);
|
|
4040
|
+
}
|
|
4041
|
+
function updateV1State(state, now, rnds) {
|
|
4042
|
+
state.msecs ??= -Infinity;
|
|
4043
|
+
state.nsecs ??= 0;
|
|
4044
|
+
if (now === state.msecs) {
|
|
4045
|
+
state.nsecs++;
|
|
4046
|
+
if (state.nsecs >= 10000) {
|
|
4047
|
+
state.node = undefined;
|
|
4048
|
+
state.nsecs = 0;
|
|
4049
|
+
}
|
|
4050
|
+
}
|
|
4051
|
+
else if (now > state.msecs) {
|
|
4052
|
+
state.nsecs = 0;
|
|
4053
|
+
}
|
|
4054
|
+
else if (now < state.msecs) {
|
|
4055
|
+
state.node = undefined;
|
|
4056
|
+
}
|
|
4057
|
+
if (!state.node) {
|
|
4058
|
+
state.node = rnds.slice(10, 16);
|
|
4059
|
+
state.node[0] |= 0x01;
|
|
4060
|
+
state.clockseq = ((rnds[8] << 8) | rnds[9]) & 0x3fff;
|
|
4061
|
+
}
|
|
4062
|
+
state.msecs = now;
|
|
4063
|
+
return state;
|
|
4064
|
+
}
|
|
4065
|
+
function v1Bytes(rnds, msecs, nsecs, clockseq, node, buf, offset = 0) {
|
|
4066
|
+
if (rnds.length < 16) {
|
|
4067
|
+
throw new Error('Random bytes length must be >= 16');
|
|
4068
|
+
}
|
|
4069
|
+
if (!buf) {
|
|
4070
|
+
buf = new Uint8Array(16);
|
|
4071
|
+
offset = 0;
|
|
4072
|
+
}
|
|
4073
|
+
else {
|
|
4074
|
+
if (offset < 0 || offset + 16 > buf.length) {
|
|
4075
|
+
throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
|
|
4076
|
+
}
|
|
4077
|
+
}
|
|
4078
|
+
msecs ??= Date.now();
|
|
4079
|
+
nsecs ??= 0;
|
|
4080
|
+
clockseq ??= ((rnds[8] << 8) | rnds[9]) & 0x3fff;
|
|
4081
|
+
node ??= rnds.slice(10, 16);
|
|
4082
|
+
msecs += 12219292800000;
|
|
4083
|
+
const tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000;
|
|
4084
|
+
buf[offset++] = (tl >>> 24) & 0xff;
|
|
4085
|
+
buf[offset++] = (tl >>> 16) & 0xff;
|
|
4086
|
+
buf[offset++] = (tl >>> 8) & 0xff;
|
|
4087
|
+
buf[offset++] = tl & 0xff;
|
|
4088
|
+
const tmh = ((msecs / 0x100000000) * 10000) & 0xfffffff;
|
|
4089
|
+
buf[offset++] = (tmh >>> 8) & 0xff;
|
|
4090
|
+
buf[offset++] = tmh & 0xff;
|
|
4091
|
+
buf[offset++] = ((tmh >>> 24) & 0xf) | 0x10;
|
|
4092
|
+
buf[offset++] = (tmh >>> 16) & 0xff;
|
|
4093
|
+
buf[offset++] = (clockseq >>> 8) | 0x80;
|
|
4094
|
+
buf[offset++] = clockseq & 0xff;
|
|
4095
|
+
for (let n = 0; n < 6; ++n) {
|
|
4096
|
+
buf[offset++] = node[n];
|
|
4097
|
+
}
|
|
4098
|
+
return buf;
|
|
4099
|
+
}
|
|
4100
|
+
|
|
4101
|
+
var INGESTION_URL = process.env.HUMAN_BEHAVIOR_INGESTION_URL || "http://localhost:9000"; // for development
|
|
4102
|
+
var MAX_CHUNK_SIZE_BYTES = 1024 * 1024 * 10; // 10MB chunk size
|
|
4103
|
+
function isChunkSizeExceeded(currentChunk, newEvent, sessionId) {
|
|
4104
|
+
var nextChunkSize = new TextEncoder().encode(JSON.stringify({
|
|
4105
|
+
sessionId: sessionId,
|
|
4106
|
+
events: __spreadArray(__spreadArray([], currentChunk, true), [newEvent], false)
|
|
4107
|
+
})).length;
|
|
4108
|
+
return nextChunkSize > MAX_CHUNK_SIZE_BYTES;
|
|
4109
|
+
}
|
|
4110
|
+
function validateSingleEventSize(event, sessionId) {
|
|
4111
|
+
var singleEventSize = new TextEncoder().encode(JSON.stringify({
|
|
4112
|
+
sessionId: sessionId,
|
|
4113
|
+
events: [event]
|
|
4114
|
+
})).length;
|
|
4115
|
+
if (singleEventSize > MAX_CHUNK_SIZE_BYTES) {
|
|
4116
|
+
throw new Error("Single event size (".concat(singleEventSize, " bytes) exceeds maximum chunk size (").concat(MAX_CHUNK_SIZE_BYTES, " bytes)"));
|
|
4117
|
+
}
|
|
4118
|
+
}
|
|
4119
|
+
var HumanBehaviorAPI = /** @class */ (function () {
|
|
4120
|
+
function HumanBehaviorAPI(_a) {
|
|
4121
|
+
var apiKey = _a.apiKey;
|
|
4122
|
+
this.apiKey = apiKey;
|
|
4123
|
+
this.baseUrl = INGESTION_URL;
|
|
4124
|
+
}
|
|
4125
|
+
HumanBehaviorAPI.prototype.init = function (sessionId, userId) {
|
|
4126
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
4127
|
+
var response, responseJson;
|
|
4128
|
+
return __generator(this, function (_a) {
|
|
4129
|
+
switch (_a.label) {
|
|
4130
|
+
case 0: return [4 /*yield*/, fetch("".concat(this.baseUrl, "/api/ingestion/init"), {
|
|
4131
|
+
method: 'POST',
|
|
4132
|
+
headers: {
|
|
4133
|
+
'Content-Type': 'application/json',
|
|
4134
|
+
'Authorization': "Bearer ".concat(this.apiKey)
|
|
4135
|
+
},
|
|
4136
|
+
body: JSON.stringify({
|
|
4137
|
+
sessionId: sessionId,
|
|
4138
|
+
endUserId: userId
|
|
4139
|
+
})
|
|
4140
|
+
})];
|
|
4141
|
+
case 1:
|
|
4142
|
+
response = _a.sent();
|
|
4143
|
+
if (!response.ok) {
|
|
4144
|
+
throw new Error("Failed to initialize ingestion: ".concat(response.statusText));
|
|
4145
|
+
}
|
|
4146
|
+
return [4 /*yield*/, response.json()];
|
|
4147
|
+
case 2:
|
|
4148
|
+
responseJson = _a.sent();
|
|
4149
|
+
return [2 /*return*/, {
|
|
4150
|
+
sessionId: responseJson.sessionId,
|
|
4151
|
+
endUserId: responseJson.endUserId
|
|
4152
|
+
}];
|
|
4153
|
+
}
|
|
4154
|
+
});
|
|
4155
|
+
});
|
|
4156
|
+
};
|
|
4157
|
+
HumanBehaviorAPI.prototype.sendEvents = function (events, sessionId, userId) {
|
|
4158
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
4159
|
+
var response;
|
|
4160
|
+
return __generator(this, function (_a) {
|
|
4161
|
+
switch (_a.label) {
|
|
4162
|
+
case 0: return [4 /*yield*/, fetch("".concat(this.baseUrl, "/api/ingestion/events"), {
|
|
4163
|
+
method: 'POST',
|
|
4164
|
+
headers: {
|
|
4165
|
+
'Content-Type': 'application/json',
|
|
4166
|
+
'Authorization': "Bearer ".concat(this.apiKey)
|
|
4167
|
+
},
|
|
4168
|
+
body: JSON.stringify({
|
|
4169
|
+
sessionId: sessionId,
|
|
4170
|
+
events: events,
|
|
4171
|
+
endUserId: userId
|
|
4172
|
+
})
|
|
4173
|
+
})];
|
|
4174
|
+
case 1:
|
|
4175
|
+
response = _a.sent();
|
|
4176
|
+
if (!response.ok) {
|
|
4177
|
+
throw new Error("Failed to send events: ".concat(response.statusText));
|
|
4178
|
+
}
|
|
4179
|
+
return [2 /*return*/];
|
|
4180
|
+
}
|
|
4181
|
+
});
|
|
4182
|
+
});
|
|
4183
|
+
};
|
|
4184
|
+
HumanBehaviorAPI.prototype.sendEventsChunked = function (events, sessionId) {
|
|
4185
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
4186
|
+
var results, currentChunk, _i, events_1, event_1, response, _a, _b, response, _c, _d, error_1;
|
|
4187
|
+
return __generator(this, function (_e) {
|
|
4188
|
+
switch (_e.label) {
|
|
4189
|
+
case 0:
|
|
4190
|
+
_e.trys.push([0, 11, , 12]);
|
|
4191
|
+
results = [];
|
|
4192
|
+
currentChunk = [];
|
|
4193
|
+
_i = 0, events_1 = events;
|
|
4194
|
+
_e.label = 1;
|
|
4195
|
+
case 1:
|
|
4196
|
+
if (!(_i < events_1.length)) return [3 /*break*/, 7];
|
|
4197
|
+
event_1 = events_1[_i];
|
|
4198
|
+
if (!isChunkSizeExceeded(currentChunk, event_1, sessionId)) return [3 /*break*/, 5];
|
|
4199
|
+
if (!(currentChunk.length > 0)) return [3 /*break*/, 4];
|
|
4200
|
+
return [4 /*yield*/, fetch("".concat(this.baseUrl, "/api/ingestion/events"), {
|
|
4201
|
+
method: 'POST',
|
|
4202
|
+
headers: {
|
|
4203
|
+
'Content-Type': 'application/json',
|
|
4204
|
+
'Authorization': "Bearer ".concat(this.apiKey)
|
|
4205
|
+
},
|
|
4206
|
+
body: JSON.stringify({
|
|
4207
|
+
sessionId: sessionId,
|
|
4208
|
+
events: currentChunk
|
|
4209
|
+
})
|
|
4210
|
+
})];
|
|
4211
|
+
case 2:
|
|
4212
|
+
response = _e.sent();
|
|
4213
|
+
if (!response.ok) {
|
|
4214
|
+
throw new Error("Failed to send events: ".concat(response.statusText));
|
|
4215
|
+
}
|
|
4216
|
+
_b = (_a = results).push;
|
|
4217
|
+
return [4 /*yield*/, response.json()];
|
|
4218
|
+
case 3:
|
|
4219
|
+
_b.apply(_a, [_e.sent()]);
|
|
4220
|
+
currentChunk = [];
|
|
4221
|
+
_e.label = 4;
|
|
4222
|
+
case 4:
|
|
4223
|
+
// Validate single event size
|
|
4224
|
+
validateSingleEventSize(event_1, sessionId);
|
|
4225
|
+
// Start new chunk with this event
|
|
4226
|
+
currentChunk = [event_1];
|
|
4227
|
+
return [3 /*break*/, 6];
|
|
4228
|
+
case 5:
|
|
4229
|
+
// Add event to current chunk
|
|
4230
|
+
currentChunk.push(event_1);
|
|
4231
|
+
_e.label = 6;
|
|
4232
|
+
case 6:
|
|
4233
|
+
_i++;
|
|
4234
|
+
return [3 /*break*/, 1];
|
|
4235
|
+
case 7:
|
|
4236
|
+
if (!(currentChunk.length > 0)) return [3 /*break*/, 10];
|
|
4237
|
+
return [4 /*yield*/, fetch("".concat(this.baseUrl, "/api/ingestion/events"), {
|
|
4238
|
+
method: 'POST',
|
|
4239
|
+
headers: {
|
|
4240
|
+
'Content-Type': 'application/json',
|
|
4241
|
+
'Authorization': "Bearer ".concat(this.apiKey)
|
|
4242
|
+
},
|
|
4243
|
+
body: JSON.stringify({
|
|
4244
|
+
sessionId: sessionId,
|
|
4245
|
+
events: currentChunk
|
|
4246
|
+
})
|
|
4247
|
+
})];
|
|
4248
|
+
case 8:
|
|
4249
|
+
response = _e.sent();
|
|
4250
|
+
if (!response.ok) {
|
|
4251
|
+
throw new Error("Failed to send events: ".concat(response.statusText));
|
|
4252
|
+
}
|
|
4253
|
+
_d = (_c = results).push;
|
|
4254
|
+
return [4 /*yield*/, response.json()];
|
|
4255
|
+
case 9:
|
|
4256
|
+
_d.apply(_c, [_e.sent()]);
|
|
4257
|
+
_e.label = 10;
|
|
4258
|
+
case 10: return [2 /*return*/, results.flat()];
|
|
4259
|
+
case 11:
|
|
4260
|
+
error_1 = _e.sent();
|
|
4261
|
+
console.error('Error sending events:', error_1);
|
|
4262
|
+
throw error_1;
|
|
4263
|
+
case 12: return [2 /*return*/];
|
|
4264
|
+
}
|
|
4265
|
+
});
|
|
4266
|
+
});
|
|
4267
|
+
};
|
|
4268
|
+
HumanBehaviorAPI.prototype.sendUserData = function (userId, userData, sessionId) {
|
|
4269
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
4270
|
+
var response, error_2;
|
|
4271
|
+
return __generator(this, function (_a) {
|
|
4272
|
+
switch (_a.label) {
|
|
4273
|
+
case 0:
|
|
4274
|
+
_a.trys.push([0, 3, , 4]);
|
|
4275
|
+
return [4 /*yield*/, fetch("".concat(this.baseUrl, "/api/ingestion/user"), {
|
|
4276
|
+
method: 'POST',
|
|
4277
|
+
headers: {
|
|
4278
|
+
'Content-Type': 'application/json',
|
|
4279
|
+
'Authorization': "Bearer ".concat(this.apiKey)
|
|
4280
|
+
},
|
|
4281
|
+
body: JSON.stringify({
|
|
4282
|
+
userId: userId,
|
|
4283
|
+
userAttributes: userData,
|
|
4284
|
+
sessionId: sessionId
|
|
4285
|
+
})
|
|
4286
|
+
})];
|
|
4287
|
+
case 1:
|
|
4288
|
+
response = _a.sent();
|
|
4289
|
+
if (!response.ok) {
|
|
4290
|
+
throw new Error("Failed to send user data: ".concat(response.statusText, " with API key: ").concat(this.apiKey));
|
|
4291
|
+
}
|
|
4292
|
+
return [4 /*yield*/, response.json()];
|
|
4293
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
4294
|
+
case 3:
|
|
4295
|
+
error_2 = _a.sent();
|
|
4296
|
+
console.error('Error sending user data:', error_2);
|
|
4297
|
+
throw error_2;
|
|
4298
|
+
case 4: return [2 /*return*/];
|
|
4299
|
+
}
|
|
4300
|
+
});
|
|
4301
|
+
});
|
|
4302
|
+
};
|
|
4303
|
+
HumanBehaviorAPI.prototype.sendSessionComplete = function (sessionId) {
|
|
4304
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
4305
|
+
var response;
|
|
4306
|
+
return __generator(this, function (_a) {
|
|
4307
|
+
switch (_a.label) {
|
|
4308
|
+
case 0: return [4 /*yield*/, fetch("".concat(this.baseUrl, "/api/ingestion/sessionComplete"), {
|
|
4309
|
+
method: 'POST',
|
|
4310
|
+
headers: {
|
|
4311
|
+
'Content-Type': 'application/json',
|
|
4312
|
+
'Authorization': "Bearer ".concat(this.apiKey)
|
|
4313
|
+
},
|
|
4314
|
+
body: JSON.stringify({ sessionId: sessionId })
|
|
4315
|
+
})];
|
|
4316
|
+
case 1:
|
|
4317
|
+
response = _a.sent();
|
|
4318
|
+
if (!response.ok) {
|
|
4319
|
+
throw new Error("Failed to send session complete: ".concat(response.statusText));
|
|
4320
|
+
}
|
|
4321
|
+
return [2 /*return*/];
|
|
4322
|
+
}
|
|
4323
|
+
});
|
|
4324
|
+
});
|
|
4325
|
+
};
|
|
4326
|
+
HumanBehaviorAPI.prototype.sendCustomEvent = function (eventName, eventProperties, sessionId) {
|
|
4327
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
4328
|
+
var maxRetries, retryCount, response, error_3;
|
|
4329
|
+
return __generator(this, function (_a) {
|
|
4330
|
+
switch (_a.label) {
|
|
4331
|
+
case 0:
|
|
4332
|
+
maxRetries = 3;
|
|
4333
|
+
retryCount = 0;
|
|
4334
|
+
_a.label = 1;
|
|
4335
|
+
case 1:
|
|
4336
|
+
if (!(retryCount < maxRetries)) return [3 /*break*/, 8];
|
|
4337
|
+
_a.label = 2;
|
|
4338
|
+
case 2:
|
|
4339
|
+
_a.trys.push([2, 5, , 7]);
|
|
4340
|
+
return [4 /*yield*/, fetch("".concat(this.baseUrl, "/api/ingestion/customEvent"), {
|
|
4341
|
+
method: 'POST',
|
|
4342
|
+
headers: {
|
|
4343
|
+
'Content-Type': 'application/json',
|
|
4344
|
+
'Authorization': "Bearer ".concat(this.apiKey)
|
|
4345
|
+
},
|
|
4346
|
+
body: JSON.stringify({
|
|
4347
|
+
name: eventName,
|
|
4348
|
+
properties: eventProperties,
|
|
4349
|
+
sessionId: sessionId,
|
|
4350
|
+
timestamp: new Date().toISOString()
|
|
4351
|
+
})
|
|
4352
|
+
})];
|
|
4353
|
+
case 3:
|
|
4354
|
+
response = _a.sent();
|
|
4355
|
+
if (!response.ok) {
|
|
4356
|
+
throw new Error("Failed to send custom event: ".concat(response.statusText));
|
|
4357
|
+
}
|
|
4358
|
+
return [4 /*yield*/, response.json()];
|
|
4359
|
+
case 4: return [2 /*return*/, _a.sent()];
|
|
4360
|
+
case 5:
|
|
4361
|
+
error_3 = _a.sent();
|
|
4362
|
+
retryCount++;
|
|
4363
|
+
if (retryCount === maxRetries) {
|
|
4364
|
+
console.error('Error sending custom event after max retries:', error_3);
|
|
4365
|
+
throw error_3;
|
|
4366
|
+
}
|
|
4367
|
+
// Exponential backoff
|
|
4368
|
+
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, Math.pow(2, retryCount) * 1000); })];
|
|
4369
|
+
case 6:
|
|
4370
|
+
// Exponential backoff
|
|
4371
|
+
_a.sent();
|
|
4372
|
+
return [3 /*break*/, 7];
|
|
4373
|
+
case 7: return [3 /*break*/, 1];
|
|
4374
|
+
case 8: return [2 /*return*/];
|
|
4375
|
+
}
|
|
4376
|
+
});
|
|
4377
|
+
});
|
|
4378
|
+
};
|
|
4379
|
+
HumanBehaviorAPI.prototype.sendCustomEvents = function (events, sessionId) {
|
|
4380
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
4381
|
+
var maxRetries, retryCount, response, error_4;
|
|
4382
|
+
return __generator(this, function (_a) {
|
|
4383
|
+
switch (_a.label) {
|
|
4384
|
+
case 0:
|
|
4385
|
+
maxRetries = 3;
|
|
4386
|
+
retryCount = 0;
|
|
4387
|
+
_a.label = 1;
|
|
4388
|
+
case 1:
|
|
4389
|
+
if (!(retryCount < maxRetries)) return [3 /*break*/, 8];
|
|
4390
|
+
_a.label = 2;
|
|
4391
|
+
case 2:
|
|
4392
|
+
_a.trys.push([2, 5, , 7]);
|
|
4393
|
+
return [4 /*yield*/, fetch("".concat(this.baseUrl, "/api/ingestion/customEvent/batch"), {
|
|
4394
|
+
method: 'POST',
|
|
4395
|
+
headers: {
|
|
4396
|
+
'Content-Type': 'application/json',
|
|
4397
|
+
'Authorization': "Bearer ".concat(this.apiKey)
|
|
4398
|
+
},
|
|
4399
|
+
body: JSON.stringify({
|
|
4400
|
+
events: events.map(function (event) { return (__assign(__assign({}, event), { sessionId: sessionId })); })
|
|
4401
|
+
})
|
|
4402
|
+
})];
|
|
4403
|
+
case 3:
|
|
4404
|
+
response = _a.sent();
|
|
4405
|
+
if (!response.ok) {
|
|
4406
|
+
throw new Error("Failed to send custom events: ".concat(response.statusText));
|
|
4407
|
+
}
|
|
4408
|
+
return [4 /*yield*/, response.json()];
|
|
4409
|
+
case 4: return [2 /*return*/, _a.sent()];
|
|
4410
|
+
case 5:
|
|
4411
|
+
error_4 = _a.sent();
|
|
4412
|
+
retryCount++;
|
|
4413
|
+
if (retryCount === maxRetries) {
|
|
4414
|
+
console.error('Error sending custom events after max retries:', error_4);
|
|
4415
|
+
throw error_4;
|
|
4416
|
+
}
|
|
4417
|
+
// Exponential backoff
|
|
4418
|
+
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, Math.pow(2, retryCount) * 1000); })];
|
|
4419
|
+
case 6:
|
|
4420
|
+
// Exponential backoff
|
|
4421
|
+
_a.sent();
|
|
4422
|
+
return [3 /*break*/, 7];
|
|
4423
|
+
case 7: return [3 /*break*/, 1];
|
|
4424
|
+
case 8: return [2 /*return*/];
|
|
4425
|
+
}
|
|
4426
|
+
});
|
|
4427
|
+
});
|
|
4428
|
+
};
|
|
4429
|
+
HumanBehaviorAPI.prototype.sendBeaconEvents = function (events, sessionId, isSessionComplete) {
|
|
4430
|
+
if (isSessionComplete === void 0) { isSessionComplete = false; }
|
|
4431
|
+
var data = new URLSearchParams();
|
|
4432
|
+
data.append('events', encodeURIComponent(JSON.stringify(events)));
|
|
4433
|
+
data.append('sessionId', encodeURIComponent(sessionId));
|
|
4434
|
+
data.append('timestamp', encodeURIComponent(Date.now().toString()));
|
|
4435
|
+
data.append('apiKey', encodeURIComponent(this.apiKey));
|
|
4436
|
+
if (isSessionComplete) {
|
|
4437
|
+
console.log('Session complete beacon sending');
|
|
4438
|
+
localStorage.setItem('koalaware_session_complete', Date.now().toString());
|
|
4439
|
+
data.append('sessionComplete', encodeURIComponent('true'));
|
|
4440
|
+
}
|
|
4441
|
+
navigator.sendBeacon("".concat(this.baseUrl, "/api/ingestion/events"), data);
|
|
4442
|
+
// KoalawareTracker.logToStorage(`Sending events beacon: ${this.baseUrl}/api/ingestion/events`);
|
|
4443
|
+
// KoalawareTracker.logToStorage(`Events beacon success: ${success}`);
|
|
4444
|
+
};
|
|
4445
|
+
HumanBehaviorAPI.prototype.sendBeaconSessionComplete = function (sessionId) {
|
|
4446
|
+
var data = new URLSearchParams();
|
|
4447
|
+
data.append('sessionId', sessionId);
|
|
4448
|
+
data.append('apiKey', this.apiKey);
|
|
4449
|
+
data.append('sessionComplete', 'true');
|
|
4450
|
+
navigator.sendBeacon("".concat(this.baseUrl, "/api/ingestion/sessionComplete"), data);
|
|
4451
|
+
// KoalawareTracker.logToStorage(`Sending completion beacon: ${this.baseUrl}/api/ingestion/sessionComplete`);
|
|
4452
|
+
// KoalawareTracker.logToStorage(`Complete beacon success: ${success}`);
|
|
4453
|
+
};
|
|
4454
|
+
HumanBehaviorAPI.prototype.sendBeaconCustomEvent = function (eventName, eventProperties, sessionId) {
|
|
4455
|
+
var data = new URLSearchParams();
|
|
4456
|
+
data.append('name', encodeURIComponent(eventName));
|
|
4457
|
+
data.append('properties', encodeURIComponent(JSON.stringify(eventProperties)));
|
|
4458
|
+
data.append('sessionId', encodeURIComponent(sessionId));
|
|
4459
|
+
data.append('timestamp', encodeURIComponent(new Date().toISOString()));
|
|
4460
|
+
data.append('apiKey', encodeURIComponent(this.apiKey));
|
|
4461
|
+
return navigator.sendBeacon("".concat(this.baseUrl, "/api/ingestion/customEvent"), data);
|
|
4462
|
+
};
|
|
4463
|
+
HumanBehaviorAPI.prototype.sendBeaconCustomEvents = function (events, sessionId) {
|
|
4464
|
+
var data = new URLSearchParams();
|
|
4465
|
+
data.append('events', encodeURIComponent(JSON.stringify(events.map(function (event) { return (__assign(__assign({}, event), { sessionId: sessionId })); }))));
|
|
4466
|
+
data.append('apiKey', encodeURIComponent(this.apiKey));
|
|
4467
|
+
return navigator.sendBeacon("".concat(this.baseUrl, "/api/ingestion/customEvent/batch"), data);
|
|
4468
|
+
};
|
|
4469
|
+
return HumanBehaviorAPI;
|
|
4470
|
+
}());
|
|
4471
|
+
|
|
4472
|
+
// Check if we're in a browser environment
|
|
4473
|
+
var isBrowser = typeof window !== 'undefined';
|
|
4474
|
+
var HumanBehaviorTracker = /** @class */ (function () {
|
|
4475
|
+
function HumanBehaviorTracker(apiKey) {
|
|
4476
|
+
this.eventIngestionQueue = [];
|
|
4477
|
+
this.queueSizeBytes = 0;
|
|
4478
|
+
this.rejectedEvents = [];
|
|
4479
|
+
this.isProcessingRejectedEvents = false;
|
|
4480
|
+
this.userProperties = {};
|
|
4481
|
+
this.isProcessing = false;
|
|
4482
|
+
this.flushInterval = null;
|
|
4483
|
+
this.FLUSH_INTERVAL_MS = 5000; // Flush every 5 seconds
|
|
4484
|
+
this.endUserId = null;
|
|
4485
|
+
this.initialized = false;
|
|
4486
|
+
this.initializationPromise = null;
|
|
4487
|
+
this.api = new HumanBehaviorAPI({
|
|
4488
|
+
apiKey: apiKey,
|
|
4489
|
+
});
|
|
4490
|
+
this.apiKey = apiKey;
|
|
4491
|
+
// Check for existing session ID and last activity time in localStorage
|
|
4492
|
+
var existingSessionId = isBrowser ? localStorage.getItem('human_behavior_session_id') : null;
|
|
4493
|
+
var lastActivity = isBrowser ? localStorage.getItem('human_behavior_last_activity') : null;
|
|
4494
|
+
// If we have a last activity time, check if it's within 30 minutes
|
|
4495
|
+
var thirtyMinutesAgo = Date.now() - (30 * 60 * 1000);
|
|
4496
|
+
var shouldUseExistingSession = lastActivity && parseInt(lastActivity) > thirtyMinutesAgo;
|
|
4497
|
+
this.sessionId = (existingSessionId && shouldUseExistingSession) ? existingSessionId : v1();
|
|
4498
|
+
// Store the session ID if it's new
|
|
4499
|
+
if ((!existingSessionId || !shouldUseExistingSession) && isBrowser) {
|
|
4500
|
+
localStorage.setItem('human_behavior_session_id', this.sessionId);
|
|
4501
|
+
}
|
|
4502
|
+
// Start initialization immediately
|
|
4503
|
+
this.initializationPromise = this.init();
|
|
4504
|
+
}
|
|
4505
|
+
HumanBehaviorTracker.prototype.init = function () {
|
|
4506
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
4507
|
+
var userId, _a, sessionId, endUserId, error_1;
|
|
4508
|
+
return __generator(this, function (_b) {
|
|
4509
|
+
switch (_b.label) {
|
|
4510
|
+
case 0:
|
|
4511
|
+
_b.trys.push([0, 2, , 3]);
|
|
4512
|
+
userId = this.getCookie("human_behavior_end_user_id_".concat(this.apiKey));
|
|
4513
|
+
return [4 /*yield*/, this.api.init(this.sessionId, userId)];
|
|
4514
|
+
case 1:
|
|
4515
|
+
_a = _b.sent(), sessionId = _a.sessionId, endUserId = _a.endUserId;
|
|
4516
|
+
this.sessionId = sessionId;
|
|
4517
|
+
this.endUserId = endUserId;
|
|
4518
|
+
this.setCookie("human_behavior_end_user_id_".concat(this.apiKey), endUserId, 365);
|
|
4519
|
+
// Only setup browser-specific handlers when in browser environment
|
|
4520
|
+
if (isBrowser) {
|
|
4521
|
+
this.setupPageUnloadHandler();
|
|
4522
|
+
this.start();
|
|
4523
|
+
this.processRejectedEvents();
|
|
4524
|
+
}
|
|
4525
|
+
else {
|
|
4526
|
+
console.warn('HumanBehaviorTracker initialized in a non-browser environment. Session tracking is disabled.');
|
|
4527
|
+
}
|
|
4528
|
+
this.initialized = true;
|
|
4529
|
+
console.log('HumanBehaviorTracker initialized');
|
|
4530
|
+
return [3 /*break*/, 3];
|
|
4531
|
+
case 2:
|
|
4532
|
+
error_1 = _b.sent();
|
|
4533
|
+
console.error('Failed to initialize HumanBehaviorTracker:', error_1);
|
|
4534
|
+
throw error_1;
|
|
4535
|
+
case 3: return [2 /*return*/];
|
|
4536
|
+
}
|
|
4537
|
+
});
|
|
4538
|
+
});
|
|
4539
|
+
};
|
|
4540
|
+
HumanBehaviorTracker.prototype.ensureInitialized = function () {
|
|
4541
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
4542
|
+
return __generator(this, function (_a) {
|
|
4543
|
+
switch (_a.label) {
|
|
4544
|
+
case 0:
|
|
4545
|
+
if (!this.initializationPromise) {
|
|
4546
|
+
throw new Error('HumanBehaviorTracker initialization failed');
|
|
4547
|
+
}
|
|
4548
|
+
return [4 /*yield*/, this.initializationPromise];
|
|
4549
|
+
case 1:
|
|
4550
|
+
_a.sent();
|
|
4551
|
+
return [2 /*return*/];
|
|
4552
|
+
}
|
|
4553
|
+
});
|
|
4554
|
+
});
|
|
4555
|
+
};
|
|
4556
|
+
HumanBehaviorTracker.logToStorage = function (message) {
|
|
4557
|
+
try {
|
|
4558
|
+
var logs = JSON.parse(localStorage.getItem('human_behavior_logs') || '[]');
|
|
4559
|
+
logs.push("".concat(new Date().toISOString(), ": ").concat(message));
|
|
4560
|
+
localStorage.setItem('human_behavior_logs', JSON.stringify(logs));
|
|
4561
|
+
}
|
|
4562
|
+
catch (e) {
|
|
4563
|
+
console.error('Failed to log to storage:', e);
|
|
4564
|
+
}
|
|
4565
|
+
};
|
|
4566
|
+
HumanBehaviorTracker.prototype.setupPageUnloadHandler = function () {
|
|
4567
|
+
var _this = this;
|
|
4568
|
+
if (!isBrowser)
|
|
4569
|
+
return;
|
|
4570
|
+
console.log('Setting up page unload handler');
|
|
4571
|
+
// Handle visibility changes for sending events
|
|
4572
|
+
window.addEventListener('visibilitychange', function () {
|
|
4573
|
+
// Only send events when page becomes hidden
|
|
4574
|
+
if (document.visibilityState === 'hidden') {
|
|
4575
|
+
console.log('Page hidden - sending pending events');
|
|
4576
|
+
_this.api.sendBeaconEvents(_this.eventIngestionQueue, _this.sessionId);
|
|
4577
|
+
}
|
|
4578
|
+
});
|
|
4579
|
+
// Handle actual page unload/close
|
|
4580
|
+
window.addEventListener('beforeunload', function () {
|
|
4581
|
+
// Update last activity time
|
|
4582
|
+
localStorage.setItem('human_behavior_last_activity', Date.now().toString());
|
|
4583
|
+
// Send final events
|
|
4584
|
+
_this.api.sendBeaconEvents(_this.eventIngestionQueue, _this.sessionId);
|
|
4585
|
+
});
|
|
4586
|
+
// Update activity timestamp periodically
|
|
4587
|
+
setInterval(function () {
|
|
4588
|
+
localStorage.setItem('human_behavior_last_activity', Date.now().toString());
|
|
4589
|
+
}, 60000); // Update every minute
|
|
4590
|
+
};
|
|
4591
|
+
HumanBehaviorTracker.prototype.viewLogs = function () {
|
|
4592
|
+
try {
|
|
4593
|
+
var logs = JSON.parse(localStorage.getItem('human_behavior_logs') || '[]');
|
|
4594
|
+
console.log('HumanBehavior Logs:', logs);
|
|
4595
|
+
localStorage.removeItem('human_behavior_logs'); // Clear logs after viewing
|
|
4596
|
+
}
|
|
4597
|
+
catch (e) {
|
|
4598
|
+
console.error('Failed to read logs:', e);
|
|
4599
|
+
}
|
|
4600
|
+
};
|
|
4601
|
+
HumanBehaviorTracker.prototype.identifyUser = function (userProperties) {
|
|
4602
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
4603
|
+
return __generator(this, function (_a) {
|
|
4604
|
+
switch (_a.label) {
|
|
4605
|
+
case 0: return [4 /*yield*/, this.ensureInitialized()];
|
|
4606
|
+
case 1:
|
|
4607
|
+
_a.sent();
|
|
4608
|
+
this.userProperties = userProperties;
|
|
4609
|
+
return [4 /*yield*/, this.api.sendUserData(this.endUserId, userProperties, this.sessionId)];
|
|
4610
|
+
case 2:
|
|
4611
|
+
_a.sent();
|
|
4612
|
+
return [2 /*return*/];
|
|
4613
|
+
}
|
|
4614
|
+
});
|
|
4615
|
+
});
|
|
4616
|
+
};
|
|
4617
|
+
HumanBehaviorTracker.prototype.customEvent = function (eventName_1) {
|
|
4618
|
+
return __awaiter$1(this, arguments, void 0, function (eventName, eventProperties) {
|
|
4619
|
+
if (eventProperties === void 0) { eventProperties = {}; }
|
|
4620
|
+
return __generator(this, function (_a) {
|
|
4621
|
+
switch (_a.label) {
|
|
4622
|
+
case 0: return [4 /*yield*/, this.ensureInitialized()];
|
|
4623
|
+
case 1:
|
|
4624
|
+
_a.sent();
|
|
4625
|
+
this.api.sendBeaconCustomEvent(eventName, eventProperties, this.sessionId);
|
|
4626
|
+
return [2 /*return*/];
|
|
4627
|
+
}
|
|
4628
|
+
});
|
|
4629
|
+
});
|
|
4630
|
+
};
|
|
4631
|
+
HumanBehaviorTracker.prototype.start = function () {
|
|
4632
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
4633
|
+
var _this = this;
|
|
4634
|
+
return __generator(this, function (_a) {
|
|
4635
|
+
switch (_a.label) {
|
|
4636
|
+
case 0: return [4 /*yield*/, this.ensureInitialized()];
|
|
4637
|
+
case 1:
|
|
4638
|
+
_a.sent();
|
|
4639
|
+
if (!isBrowser)
|
|
4640
|
+
return [2 /*return*/];
|
|
4641
|
+
// Start periodic flushing
|
|
4642
|
+
this.flushInterval = window.setInterval(function () {
|
|
4643
|
+
_this.flush();
|
|
4644
|
+
}, this.FLUSH_INTERVAL_MS);
|
|
4645
|
+
// Start recording
|
|
4646
|
+
record({
|
|
4647
|
+
emit: function (event) {
|
|
4648
|
+
_this.addEvent(event);
|
|
4649
|
+
},
|
|
4650
|
+
});
|
|
4651
|
+
return [2 /*return*/];
|
|
4652
|
+
}
|
|
4653
|
+
});
|
|
4654
|
+
});
|
|
4655
|
+
};
|
|
4656
|
+
HumanBehaviorTracker.prototype.stop = function () {
|
|
4657
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
4658
|
+
return __generator(this, function (_a) {
|
|
4659
|
+
switch (_a.label) {
|
|
4660
|
+
case 0: return [4 /*yield*/, this.ensureInitialized()];
|
|
4661
|
+
case 1:
|
|
4662
|
+
_a.sent();
|
|
4663
|
+
if (!isBrowser)
|
|
4664
|
+
return [2 /*return*/];
|
|
4665
|
+
if (this.flushInterval) {
|
|
4666
|
+
clearInterval(this.flushInterval);
|
|
4667
|
+
this.flushInterval = null;
|
|
4668
|
+
}
|
|
4669
|
+
return [2 /*return*/];
|
|
4670
|
+
}
|
|
4671
|
+
});
|
|
4672
|
+
});
|
|
4673
|
+
};
|
|
4674
|
+
HumanBehaviorTracker.prototype.addEvent = function (event) {
|
|
4675
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
4676
|
+
var eventSize;
|
|
4677
|
+
return __generator(this, function (_a) {
|
|
4678
|
+
switch (_a.label) {
|
|
4679
|
+
case 0: return [4 /*yield*/, this.ensureInitialized()];
|
|
4680
|
+
case 1:
|
|
4681
|
+
_a.sent();
|
|
4682
|
+
eventSize = new TextEncoder().encode(JSON.stringify(event)).length;
|
|
4683
|
+
this.eventIngestionQueue.push(event);
|
|
4684
|
+
this.queueSizeBytes += eventSize;
|
|
4685
|
+
return [2 /*return*/];
|
|
4686
|
+
}
|
|
4687
|
+
});
|
|
4688
|
+
});
|
|
4689
|
+
};
|
|
4690
|
+
HumanBehaviorTracker.prototype.processRejectedEvents = function () {
|
|
4691
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
4692
|
+
var newSessionId;
|
|
4693
|
+
return __generator(this, function (_a) {
|
|
4694
|
+
if (this.isProcessingRejectedEvents || this.rejectedEvents.length === 0)
|
|
4695
|
+
return [2 /*return*/];
|
|
4696
|
+
this.isProcessingRejectedEvents = true;
|
|
4697
|
+
try {
|
|
4698
|
+
newSessionId = v1();
|
|
4699
|
+
if (isBrowser) {
|
|
4700
|
+
localStorage.setItem('human_behavior_session_id', newSessionId);
|
|
4701
|
+
}
|
|
4702
|
+
// Try to send rejected events with new session ID using beacon
|
|
4703
|
+
// sendBeacon returns true if the request was queued successfully
|
|
4704
|
+
this.api.sendBeaconEvents(this.rejectedEvents, newSessionId);
|
|
4705
|
+
// Clear rejected events and update session ID
|
|
4706
|
+
// Note: We can't verify if the beacon data was actually sent,
|
|
4707
|
+
// but we clear the events to prevent duplicate sending attempts
|
|
4708
|
+
this.rejectedEvents = [];
|
|
4709
|
+
this.sessionId = newSessionId;
|
|
4710
|
+
}
|
|
4711
|
+
catch (error) {
|
|
4712
|
+
console.error('Failed to process rejected events:', error);
|
|
4713
|
+
}
|
|
4714
|
+
finally {
|
|
4715
|
+
this.isProcessingRejectedEvents = false;
|
|
4716
|
+
}
|
|
4717
|
+
return [2 /*return*/];
|
|
4718
|
+
});
|
|
4719
|
+
});
|
|
4720
|
+
};
|
|
4721
|
+
HumanBehaviorTracker.prototype.flush = function () {
|
|
4722
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
4723
|
+
var eventsToProcess, error_2;
|
|
4724
|
+
var _a;
|
|
4725
|
+
var _b;
|
|
4726
|
+
return __generator(this, function (_c) {
|
|
4727
|
+
switch (_c.label) {
|
|
4728
|
+
case 0:
|
|
4729
|
+
// Prevent concurrent flushes
|
|
4730
|
+
if (this.isProcessing || !this.initialized) {
|
|
4731
|
+
return [2 /*return*/];
|
|
4732
|
+
}
|
|
4733
|
+
this.isProcessing = true;
|
|
4734
|
+
_c.label = 1;
|
|
4735
|
+
case 1:
|
|
4736
|
+
_c.trys.push([1, , 6, 7]);
|
|
4737
|
+
eventsToProcess = this.eventIngestionQueue;
|
|
4738
|
+
this.eventIngestionQueue = [];
|
|
4739
|
+
this.queueSizeBytes = 0;
|
|
4740
|
+
if (!(eventsToProcess.length > 0)) return [3 /*break*/, 5];
|
|
4741
|
+
console.log('Flushing events:', eventsToProcess);
|
|
4742
|
+
_c.label = 2;
|
|
4743
|
+
case 2:
|
|
4744
|
+
_c.trys.push([2, 4, , 5]);
|
|
4745
|
+
return [4 /*yield*/, this.api.sendEvents(eventsToProcess, this.sessionId, this.endUserId)];
|
|
4746
|
+
case 3:
|
|
4747
|
+
_c.sent();
|
|
4748
|
+
return [3 /*break*/, 5];
|
|
4749
|
+
case 4:
|
|
4750
|
+
error_2 = _c.sent();
|
|
4751
|
+
// If we get a 400 error, store events for retry
|
|
4752
|
+
if ((_b = error_2.message) === null || _b === void 0 ? void 0 : _b.includes('ERROR: Session already completed')) {
|
|
4753
|
+
console.log('Session expired, storing events for retry');
|
|
4754
|
+
(_a = this.rejectedEvents).push.apply(_a, eventsToProcess);
|
|
4755
|
+
this.processRejectedEvents();
|
|
4756
|
+
}
|
|
4757
|
+
else {
|
|
4758
|
+
throw error_2;
|
|
4759
|
+
}
|
|
4760
|
+
return [3 /*break*/, 5];
|
|
4761
|
+
case 5: return [3 /*break*/, 7];
|
|
4762
|
+
case 6:
|
|
4763
|
+
this.isProcessing = false;
|
|
4764
|
+
return [7 /*endfinally*/];
|
|
4765
|
+
case 7: return [2 /*return*/];
|
|
4766
|
+
}
|
|
4767
|
+
});
|
|
4768
|
+
});
|
|
4769
|
+
};
|
|
4770
|
+
// Add helper methods for cookie management
|
|
4771
|
+
HumanBehaviorTracker.prototype.setCookie = function (name, value, daysToExpire) {
|
|
4772
|
+
if (!isBrowser)
|
|
4773
|
+
return;
|
|
4774
|
+
var date = new Date();
|
|
4775
|
+
date.setTime(date.getTime() + (daysToExpire * 24 * 60 * 60 * 1000));
|
|
4776
|
+
var expires = "expires=".concat(date.toUTCString());
|
|
4777
|
+
document.cookie = "".concat(name, "=").concat(value, ";").concat(expires, ";path=/;SameSite=Lax");
|
|
4778
|
+
};
|
|
4779
|
+
HumanBehaviorTracker.prototype.getCookie = function (name) {
|
|
4780
|
+
if (!isBrowser)
|
|
4781
|
+
return null;
|
|
4782
|
+
var nameEQ = name + "=";
|
|
4783
|
+
var ca = document.cookie.split(';');
|
|
4784
|
+
for (var i = 0; i < ca.length; i++) {
|
|
4785
|
+
var c = ca[i];
|
|
4786
|
+
while (c.charAt(0) === ' ')
|
|
4787
|
+
c = c.substring(1, c.length);
|
|
4788
|
+
if (c.indexOf(nameEQ) === 0)
|
|
4789
|
+
return c.substring(nameEQ.length, c.length);
|
|
4790
|
+
}
|
|
4791
|
+
return null;
|
|
4792
|
+
};
|
|
4793
|
+
return HumanBehaviorTracker;
|
|
4794
|
+
}());
|
|
4795
|
+
// Only expose to window object in browser environments
|
|
4796
|
+
if (isBrowser) {
|
|
4797
|
+
window.HumanBehaviorTracker = HumanBehaviorTracker;
|
|
4798
|
+
}
|
|
4799
|
+
|
|
4800
|
+
export { HumanBehaviorAPI, HumanBehaviorTracker, MAX_CHUNK_SIZE_BYTES, HumanBehaviorTracker as default, isChunkSizeExceeded, validateSingleEventSize };
|
|
4801
|
+
//# sourceMappingURL=index.js.map
|