UNPKG

@coralogix/browser

Version:

Official Coralogix SDK for browsers

1,289 lines (1,285 loc) 243 kB
import { __values, __spreadArray, __read, __assign, __awaiter, __generator, __rest } from 'tslib'; import { c as cxSetTimeout, a as cxClearTimeout, g as getZoneJsOriginalDom, b as createCxMutationObserver, d as cxRequestAnimationFrame, e as cxCancelAnimationFrame, C as CxGlobal, S as SESSION_RECORDER_SEGMENTS_MAP, f as getSdkConfig, h as cxClearInterval, i as getNowTime, j as SESSION_RECORDING_NETWORK_ERR0R_MESSAGE, k as cxSetInterval, R as Request, l as SESSION_RECORDING_DEFAULT_HEADERS, m as SESSION_RECORDING_POSTFIX_URL, B as BATCH_TIME_DELAY, n as SESSION_RECORDER_KEY, o as SESSION_RECORDING_DEFAULT_ERROR_MESSAGE, M as MAX_BATCH_TIME_MS } from './index.esm2.js'; import '@opentelemetry/sdk-trace-base'; import '@opentelemetry/sdk-trace-web'; import '@opentelemetry/instrumentation'; import 'error-stack-parser'; import '@opentelemetry/instrumentation-fetch'; import '@opentelemetry/instrumentation-xml-http-request'; import 'web-vitals/attribution'; import '@opentelemetry/api'; import '@opentelemetry/propagator-b3'; import '@opentelemetry/propagator-aws-xray'; var EventType; (function (EventType) { EventType[EventType["DomContentLoaded"] = 0] = "DomContentLoaded"; EventType[EventType["Load"] = 1] = "Load"; EventType[EventType["FullSnapshot"] = 2] = "FullSnapshot"; EventType[EventType["IncrementalSnapshot"] = 3] = "IncrementalSnapshot"; EventType[EventType["Meta"] = 4] = "Meta"; EventType[EventType["Custom"] = 5] = "Custom"; EventType[EventType["Plugin"] = 6] = "Plugin"; })(EventType || (EventType = {})); var IncrementalSource; (function (IncrementalSource) { IncrementalSource[IncrementalSource["Mutation"] = 0] = "Mutation"; IncrementalSource[IncrementalSource["MouseMove"] = 1] = "MouseMove"; IncrementalSource[IncrementalSource["MouseInteraction"] = 2] = "MouseInteraction"; IncrementalSource[IncrementalSource["Scroll"] = 3] = "Scroll"; IncrementalSource[IncrementalSource["ViewportResize"] = 4] = "ViewportResize"; IncrementalSource[IncrementalSource["Input"] = 5] = "Input"; IncrementalSource[IncrementalSource["TouchMove"] = 6] = "TouchMove"; IncrementalSource[IncrementalSource["MediaInteraction"] = 7] = "MediaInteraction"; IncrementalSource[IncrementalSource["StyleSheetRule"] = 8] = "StyleSheetRule"; IncrementalSource[IncrementalSource["CanvasMutation"] = 9] = "CanvasMutation"; IncrementalSource[IncrementalSource["Font"] = 10] = "Font"; IncrementalSource[IncrementalSource["Log"] = 11] = "Log"; IncrementalSource[IncrementalSource["Drag"] = 12] = "Drag"; IncrementalSource[IncrementalSource["StyleDeclaration"] = 13] = "StyleDeclaration"; IncrementalSource[IncrementalSource["Selection"] = 14] = "Selection"; IncrementalSource[IncrementalSource["AdoptedStyleSheet"] = 15] = "AdoptedStyleSheet"; IncrementalSource[IncrementalSource["CustomElement"] = 16] = "CustomElement"; })(IncrementalSource || (IncrementalSource = {})); var MouseInteractions; (function (MouseInteractions) { MouseInteractions[MouseInteractions["MouseUp"] = 0] = "MouseUp"; MouseInteractions[MouseInteractions["MouseDown"] = 1] = "MouseDown"; MouseInteractions[MouseInteractions["Click"] = 2] = "Click"; MouseInteractions[MouseInteractions["ContextMenu"] = 3] = "ContextMenu"; MouseInteractions[MouseInteractions["DblClick"] = 4] = "DblClick"; MouseInteractions[MouseInteractions["Focus"] = 5] = "Focus"; MouseInteractions[MouseInteractions["Blur"] = 6] = "Blur"; MouseInteractions[MouseInteractions["TouchStart"] = 7] = "TouchStart"; MouseInteractions[MouseInteractions["TouchMove_Departed"] = 8] = "TouchMove_Departed"; MouseInteractions[MouseInteractions["TouchEnd"] = 9] = "TouchEnd"; MouseInteractions[MouseInteractions["TouchCancel"] = 10] = "TouchCancel"; })(MouseInteractions || (MouseInteractions = {})); var PointerTypes; (function (PointerTypes) { PointerTypes[PointerTypes["Mouse"] = 0] = "Mouse"; PointerTypes[PointerTypes["Pen"] = 1] = "Pen"; PointerTypes[PointerTypes["Touch"] = 2] = "Touch"; })(PointerTypes || (PointerTypes = {})); var CanvasContext; (function (CanvasContext) { CanvasContext[CanvasContext["2D"] = 0] = "2D"; CanvasContext[CanvasContext["WebGL"] = 1] = "WebGL"; CanvasContext[CanvasContext["WebGL2"] = 2] = "WebGL2"; })(CanvasContext || (CanvasContext = {})); var MediaInteractions; (function (MediaInteractions) { MediaInteractions[MediaInteractions["Play"] = 0] = "Play"; MediaInteractions[MediaInteractions["Pause"] = 1] = "Pause"; MediaInteractions[MediaInteractions["Seeked"] = 2] = "Seeked"; MediaInteractions[MediaInteractions["VolumeChange"] = 3] = "VolumeChange"; MediaInteractions[MediaInteractions["RateChange"] = 4] = "RateChange"; })(MediaInteractions || (MediaInteractions = {})); var NodeType; (function (NodeType) { NodeType[NodeType["Document"] = 0] = "Document"; NodeType[NodeType["DocumentType"] = 1] = "DocumentType"; NodeType[NodeType["Element"] = 2] = "Element"; NodeType[NodeType["Text"] = 3] = "Text"; NodeType[NodeType["CDATA"] = 4] = "CDATA"; NodeType[NodeType["Comment"] = 5] = "Comment"; })(NodeType || (NodeType = {})); var testableAccessors = { Node: [ 'childNodes', 'parentNode', 'parentElement', 'textContent', 'ownerDocument', ], ShadowRoot: ['host', 'styleSheets'], Element: ['shadowRoot', 'querySelector', 'querySelectorAll'], MutationObserver: [], }; var testableMethods = { Node: ['contains', 'getRootNode'], ShadowRoot: ['getSelection'], Element: [], MutationObserver: ['constructor'], }; var untaintedBasePrototype = {}; var isAngularZonePresent = function () { return !!globalThis.Zone; }; function getUntaintedPrototype(key) { if (untaintedBasePrototype[key]) return untaintedBasePrototype[key]; var defaultObj = globalThis[key]; var defaultPrototype = defaultObj.prototype; var accessorNames = key in testableAccessors ? testableAccessors[key] : undefined; var isUntaintedAccessors = Boolean(accessorNames && accessorNames.every(function (accessor) { var _a, _b; return Boolean((_b = (_a = Object.getOwnPropertyDescriptor(defaultPrototype, accessor)) === null || _a === void 0 ? void 0 : _a.get) === null || _b === void 0 ? void 0 : _b.toString().includes('[native code]')); })); var methodNames = key in testableMethods ? testableMethods[key] : undefined; var isUntaintedMethods = Boolean(methodNames && methodNames.every(function (method) { var _a; return typeof defaultPrototype[method] === 'function' && ((_a = defaultPrototype[method]) === null || _a === void 0 ? void 0 : _a.toString().includes('[native code]')); })); if (isUntaintedAccessors && isUntaintedMethods && !isAngularZonePresent()) { untaintedBasePrototype[key] = defaultObj.prototype; return defaultObj.prototype; } try { var iframeEl = document.createElement('iframe'); document.body.appendChild(iframeEl); var win = iframeEl.contentWindow; if (!win) return defaultObj.prototype; var untaintedObject = win[key] .prototype; document.body.removeChild(iframeEl); if (!untaintedObject) return defaultPrototype; return (untaintedBasePrototype[key] = untaintedObject); } catch (_a) { return defaultPrototype; } } var untaintedAccessorCache = {}; function getUntaintedAccessor(key, instance, accessor) { var _a; var cacheKey = "".concat(key, ".").concat(String(accessor)); if (untaintedAccessorCache[cacheKey]) return untaintedAccessorCache[cacheKey].call(instance); var untaintedPrototype = getUntaintedPrototype(key); var untaintedAccessor = (_a = Object.getOwnPropertyDescriptor(untaintedPrototype, accessor)) === null || _a === void 0 ? void 0 : _a.get; if (!untaintedAccessor) return instance[accessor]; untaintedAccessorCache[cacheKey] = untaintedAccessor; return untaintedAccessor.call(instance); } var untaintedMethodCache = {}; function getUntaintedMethod(key, instance, method) { var cacheKey = "".concat(key, ".").concat(String(method)); if (untaintedMethodCache[cacheKey]) return untaintedMethodCache[cacheKey].bind(instance); var untaintedPrototype = getUntaintedPrototype(key); var untaintedMethod = untaintedPrototype[method]; if (typeof untaintedMethod !== 'function') return instance[method]; untaintedMethodCache[cacheKey] = untaintedMethod; return untaintedMethod.bind(instance); } function ownerDocument(n) { return getUntaintedAccessor('Node', n, 'ownerDocument'); } function childNodes(n) { return getUntaintedAccessor('Node', n, 'childNodes'); } function parentNode(n) { return getUntaintedAccessor('Node', n, 'parentNode'); } function parentElement(n) { return getUntaintedAccessor('Node', n, 'parentElement'); } function textContent(n) { return getUntaintedAccessor('Node', n, 'textContent'); } function contains(n, other) { return getUntaintedMethod('Node', n, 'contains')(other); } function getRootNode(n) { return getUntaintedMethod('Node', n, 'getRootNode')(); } function host(n) { if (!n || !('host' in n)) return null; return getUntaintedAccessor('ShadowRoot', n, 'host'); } function styleSheets(n) { return n.styleSheets; } function shadowRoot(n) { if (!n || !('shadowRoot' in n)) return null; return getUntaintedAccessor('Element', n, 'shadowRoot'); } function querySelector(n, selectors) { return getUntaintedAccessor('Element', n, 'querySelector')(selectors); } function querySelectorAll(n, selectors) { return getUntaintedAccessor('Element', n, 'querySelectorAll')(selectors); } function mutationObserverCtor() { return getUntaintedPrototype('MutationObserver').constructor; } function patch(source, name, replacement) { try { if (!(name in source)) { return function () { }; } var original_1 = source[name]; var wrapped = replacement(original_1); if (typeof wrapped === 'function') { wrapped.prototype = wrapped.prototype || {}; Object.defineProperties(wrapped, { __rrweb_original__: { enumerable: false, value: original_1, }, }); } source[name] = wrapped; return function () { source[name] = original_1; }; } catch (_a) { return function () { }; } } var dom = { ownerDocument: ownerDocument, childNodes: childNodes, parentNode: parentNode, parentElement: parentElement, textContent: textContent, contains: contains, getRootNode: getRootNode, host: host, styleSheets: styleSheets, shadowRoot: shadowRoot, querySelector: querySelector, querySelectorAll: querySelectorAll, mutationObserver: mutationObserverCtor, patch: patch, }; function isElement(n) { return n.nodeType === n.ELEMENT_NODE; } function isShadowRoot(n) { var hostEl = (n && 'host' in n && 'mode' in n && dom.host(n)) || null; return Boolean(hostEl && 'shadowRoot' in hostEl && dom.shadowRoot(hostEl) === n); } function isNativeShadowDom(shadowRoot) { return Object.prototype.toString.call(shadowRoot) === '[object ShadowRoot]'; } function fixBrowserCompatibilityIssuesInCSS(cssText) { if (cssText.includes(' background-clip: text;') && !cssText.includes(' -webkit-background-clip: text;')) { cssText = cssText.replace(/\sbackground-clip:\s*text;/g, ' -webkit-background-clip: text; background-clip: text;'); } return cssText; } function escapeImportStatement(rule) { var cssText = rule.cssText; if (cssText.split('"').length < 3) return cssText; var statement = ['@import', "url(".concat(JSON.stringify(rule.href), ")")]; if (rule.layerName === '') { statement.push("layer"); } else if (rule.layerName) { statement.push("layer(".concat(rule.layerName, ")")); } if (rule.supportsText) { statement.push("supports(".concat(rule.supportsText, ")")); } if (rule.media.length) { statement.push(rule.media.mediaText); } return statement.join(' ') + ';'; } function stringifyStylesheet(s) { try { var rules = s.rules || s.cssRules; if (!rules) { return null; } var sheetHref_1 = s.href; if (!sheetHref_1 && s.ownerNode) { sheetHref_1 = s.ownerNode.baseURI; } var stringifiedRules = Array.from(rules, function (rule) { return stringifyRule(rule, sheetHref_1); }).join(''); return fixBrowserCompatibilityIssuesInCSS(stringifiedRules); } catch (error) { return null; } } function stringifyRule(rule, sheetHref) { if (isCSSImportRule(rule)) { var importStringified = void 0; try { importStringified = stringifyStylesheet(rule.styleSheet) || escapeImportStatement(rule); } catch (error) { importStringified = rule.cssText; } if (rule.styleSheet.href) { return absolutifyURLs(importStringified, rule.styleSheet.href); } return importStringified; } else { var ruleStringified = rule.cssText; if (isCSSStyleRule(rule) && rule.selectorText.includes(':')) { ruleStringified = fixSafariColons(ruleStringified); } if (sheetHref) { return absolutifyURLs(ruleStringified, sheetHref); } return ruleStringified; } } function fixSafariColons(cssStringified) { var regex = /(\[(?:[\w-]+)[^\\])(:(?:[\w-]+)\])/gm; return cssStringified.replace(regex, '$1\\$2'); } function isCSSImportRule(rule) { return 'styleSheet' in rule; } function isCSSStyleRule(rule) { return 'selectorText' in rule; } var Mirror = (function () { function Mirror() { this.idNodeMap = new Map(); this.nodeMetaMap = new WeakMap(); } Mirror.prototype.getId = function (n) { var _a; if (!n) return -1; var id = (_a = this.getMeta(n)) === null || _a === void 0 ? void 0 : _a.id; return id !== null && id !== void 0 ? id : -1; }; Mirror.prototype.getNode = function (id) { return this.idNodeMap.get(id) || null; }; Mirror.prototype.getIds = function () { return Array.from(this.idNodeMap.keys()); }; Mirror.prototype.getMeta = function (n) { return this.nodeMetaMap.get(n) || null; }; Mirror.prototype.removeNodeFromMap = function (n) { var _this = this; var id = this.getId(n); this.idNodeMap.delete(id); if (n.childNodes) { n.childNodes.forEach(function (childNode) { return _this.removeNodeFromMap(childNode); }); } }; Mirror.prototype.has = function (id) { return this.idNodeMap.has(id); }; Mirror.prototype.hasNode = function (node) { return this.nodeMetaMap.has(node); }; Mirror.prototype.add = function (n, meta) { var id = meta.id; this.idNodeMap.set(id, n); this.nodeMetaMap.set(n, meta); }; Mirror.prototype.replace = function (id, n) { var oldNode = this.getNode(id); if (oldNode) { var meta = this.nodeMetaMap.get(oldNode); if (meta) this.nodeMetaMap.set(n, meta); } this.idNodeMap.set(id, n); }; Mirror.prototype.reset = function () { this.idNodeMap = new Map(); this.nodeMetaMap = new WeakMap(); }; return Mirror; }()); function createMirror() { return new Mirror(); } function maskInputValue(_a) { var element = _a.element, maskInputOptions = _a.maskInputOptions, tagName = _a.tagName, type = _a.type, value = _a.value, maskInputFn = _a.maskInputFn; var text = value || ''; var actualType = type && toLowerCase(type); if (maskInputOptions[tagName.toLowerCase()] || (actualType && maskInputOptions[actualType])) { if (maskInputFn) { text = maskInputFn(text, element); } else { text = '*'.repeat(text.length); } } return text; } function toLowerCase(str) { return str.toLowerCase(); } var ORIGINAL_ATTRIBUTE_NAME = '__rrweb_original__'; function is2DCanvasBlank(canvas) { var ctx = canvas.getContext('2d'); if (!ctx) return true; var chunkSize = 50; for (var x = 0; x < canvas.width; x += chunkSize) { for (var y = 0; y < canvas.height; y += chunkSize) { var getImageData = ctx.getImageData; var originalGetImageData = ORIGINAL_ATTRIBUTE_NAME in getImageData ? getImageData[ORIGINAL_ATTRIBUTE_NAME] : getImageData; var pixelBuffer = new Uint32Array(originalGetImageData.call(ctx, x, y, Math.min(chunkSize, canvas.width - x), Math.min(chunkSize, canvas.height - y)).data.buffer); if (pixelBuffer.some(function (pixel) { return pixel !== 0; })) return false; } } return true; } function getInputType(element) { var type = element.type; return element.hasAttribute('data-rr-is-password') ? 'password' : type ? toLowerCase(type) : null; } function extractFileExtension(path, baseURL) { var _a; var url; try { url = new URL(path, baseURL !== null && baseURL !== void 0 ? baseURL : window.location.href); } catch (err) { return null; } var regex = /\.([0-9a-z]+)(?:$)/i; var match = url.pathname.match(regex); return (_a = match === null || match === void 0 ? void 0 : match[1]) !== null && _a !== void 0 ? _a : null; } function extractOrigin(url) { var origin = ''; if (url.indexOf('//') > -1) { origin = url.split('/').slice(0, 3).join('/'); } else { origin = url.split('/')[0]; } origin = origin.split('?')[0]; return origin; } var URL_IN_CSS_REF = /url\((?:(')([^']*)'|(")(.*?)"|([^)]*))\)/gm; var URL_PROTOCOL_MATCH = /^(?:[a-z+]+:)?\/\//i; var URL_WWW_MATCH = /^www\..*/i; var DATA_URI = /^(data:)([^,]*),(.*)/i; function absolutifyURLs(cssText, href) { return (cssText || '').replace(URL_IN_CSS_REF, function (origin, quote1, path1, quote2, path2, path3) { var e_1, _a; var filePath = path1 || path2 || path3; var maybeQuote = quote1 || quote2 || ''; if (!filePath) { return origin; } if (filePath[0] === '#') { return "url(".concat(maybeQuote).concat(filePath).concat(maybeQuote, ")"); } if (URL_PROTOCOL_MATCH.test(filePath) || URL_WWW_MATCH.test(filePath)) { return "url(".concat(maybeQuote).concat(filePath).concat(maybeQuote, ")"); } if (DATA_URI.test(filePath)) { return "url(".concat(maybeQuote).concat(filePath).concat(maybeQuote, ")"); } if (filePath[0] === '/') { return "url(".concat(maybeQuote).concat(extractOrigin(href) + filePath).concat(maybeQuote, ")"); } var stack = href.split('/'); var parts = filePath.split('/'); stack.pop(); try { for (var parts_1 = __values(parts), parts_1_1 = parts_1.next(); !parts_1_1.done; parts_1_1 = parts_1.next()) { var part = parts_1_1.value; if (part === '.') { continue; } else if (part === '..') { stack.pop(); } else { stack.push(part); } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (parts_1_1 && !parts_1_1.done && (_a = parts_1.return)) _a.call(parts_1); } finally { if (e_1) throw e_1.error; } } return "url(".concat(maybeQuote).concat(stack.join('/')).concat(maybeQuote, ")"); }); } function normalizeCssString(cssText, _testNoPxNorm) { if (_testNoPxNorm === void 0) { _testNoPxNorm = false; } if (_testNoPxNorm) { return cssText.replace(/(\/\*[^*]*\*\/)|[\s;]/g, ''); } else { return cssText.replace(/(\/\*[^*]*\*\/)|[\s;]/g, '').replace(/0px/g, '0'); } } function splitCssText(cssText, style, _testNoPxNorm) { if (_testNoPxNorm === void 0) { _testNoPxNorm = false; } var childNodes = Array.from(style.childNodes); var splits = []; var iterCount = 0; if (childNodes.length > 1 && cssText && typeof cssText === 'string') { var cssTextNorm = normalizeCssString(cssText, _testNoPxNorm); var normFactor = cssTextNorm.length / cssText.length; for (var i = 1; i < childNodes.length; i++) { if (childNodes[i].textContent && typeof childNodes[i].textContent === 'string') { var textContentNorm = normalizeCssString(childNodes[i].textContent, _testNoPxNorm); var jLimit = 100; var j = 3; for (; j < textContentNorm.length; j++) { if (textContentNorm[j].match(/[a-zA-Z0-9]/) || textContentNorm.indexOf(textContentNorm.substring(0, j), 1) !== -1) { continue; } break; } for (; j < textContentNorm.length; j++) { var startSubstring = textContentNorm.substring(0, j); var cssNormSplits = cssTextNorm.split(startSubstring); var splitNorm = -1; if (cssNormSplits.length === 2) { splitNorm = cssNormSplits[0].length; } else if (cssNormSplits.length > 2 && cssNormSplits[0] === '' && childNodes[i - 1].textContent !== '') { splitNorm = cssTextNorm.indexOf(startSubstring, 1); } else if (cssNormSplits.length === 1) { startSubstring = startSubstring.substring(0, startSubstring.length - 1); cssNormSplits = cssTextNorm.split(startSubstring); if (cssNormSplits.length <= 1) { splits.push(cssText); return splits; } j = jLimit + 1; } else if (j === textContentNorm.length - 1) { splitNorm = cssTextNorm.indexOf(startSubstring); } if (cssNormSplits.length >= 2 && j > jLimit) { var prevTextContent = childNodes[i - 1].textContent; if (prevTextContent && typeof prevTextContent === 'string') { var prevMinLength = normalizeCssString(prevTextContent).length; splitNorm = cssTextNorm.indexOf(startSubstring, prevMinLength); } if (splitNorm === -1) { splitNorm = cssNormSplits[0].length; } } if (splitNorm !== -1) { var k = Math.floor(splitNorm / normFactor); for (; k > 0 && k < cssText.length;) { iterCount += 1; if (iterCount > 50 * childNodes.length) { splits.push(cssText); return splits; } var normPart = normalizeCssString(cssText.substring(0, k), _testNoPxNorm); if (normPart.length === splitNorm) { splits.push(cssText.substring(0, k)); cssText = cssText.substring(k); cssTextNorm = cssTextNorm.substring(splitNorm); break; } else if (normPart.length < splitNorm) { k += Math.max(1, Math.floor((splitNorm - normPart.length) / normFactor)); } else { k -= Math.max(1, Math.floor((normPart.length - splitNorm) * normFactor)); } } break; } } } } } splits.push(cssText); return splits; } function markCssSplits(cssText, style) { return splitCssText(cssText, style).join('/* rr_split */'); } var _id = 1; var tagNameRegex = new RegExp('[^a-z0-9-_:]'); var IGNORED_NODE = -2; function genId() { return _id++; } function getValidTagName(element) { if (element instanceof HTMLFormElement) { return 'form'; } var processedTagName = toLowerCase(element.tagName); if (tagNameRegex.test(processedTagName)) { return 'div'; } return processedTagName; } var canvasService; var canvasCtx; var SRCSET_NOT_SPACES = /^[^ \t\n\r\u000c]+/; var SRCSET_COMMAS_OR_SPACES = /^[, \t\n\r\u000c]+/; function getAbsoluteSrcsetString(doc, attributeValue) { if (attributeValue.trim() === '') { return attributeValue; } var pos = 0; function collectCharacters(regEx) { var chars; var match = regEx.exec(attributeValue.substring(pos)); if (match) { chars = match[0]; pos += chars.length; return chars; } return ''; } var output = []; while (true) { collectCharacters(SRCSET_COMMAS_OR_SPACES); if (pos >= attributeValue.length) { break; } var url = collectCharacters(SRCSET_NOT_SPACES); if (url.slice(-1) === ',') { url = absoluteToDoc(doc, url.substring(0, url.length - 1)); output.push(url); } else { var descriptorsStr = ''; url = absoluteToDoc(doc, url); var inParens = false; while (true) { var c = attributeValue.charAt(pos); if (c === '') { output.push((url + descriptorsStr).trim()); break; } else if (!inParens) { if (c === ',') { pos += 1; output.push((url + descriptorsStr).trim()); break; } else if (c === '(') { inParens = true; } } else { if (c === ')') { inParens = false; } } descriptorsStr += c; pos += 1; } } } return output.join(', '); } var cachedDocument = new WeakMap(); function absoluteToDoc(doc, attributeValue) { if (!attributeValue || attributeValue.trim() === '') { return attributeValue; } return getHref(doc, attributeValue); } var SVG_NAMESPACE = 'http://www.w3.org/2000/svg'; function isSVGElement(el) { return Boolean(el.namespaceURI === SVG_NAMESPACE || el.tagName === 'svg' || el.ownerSVGElement); } function getHref(doc, customHref) { var a = cachedDocument.get(doc); if (!a) { a = doc.createElement('a'); cachedDocument.set(doc, a); } if (!customHref) { customHref = ''; } else if (customHref.startsWith('blob:') || customHref.startsWith('data:')) { return customHref; } a.setAttribute('href', customHref); return a.href; } function transformAttribute(doc, tagName, name, value) { if (!value) { return value; } if (name === 'src' || (name === 'href' && !(tagName === 'use' && value[0] === '#'))) { return absoluteToDoc(doc, value); } else if (name === 'xlink:href' && value[0] !== '#') { return absoluteToDoc(doc, value); } else if (name === 'background' && ['table', 'td', 'th'].includes(tagName)) { return absoluteToDoc(doc, value); } else if (name === 'srcset') { return getAbsoluteSrcsetString(doc, value); } else if (name === 'style') { return absolutifyURLs(value, getHref(doc)); } else if (tagName === 'object' && name === 'data') { return absoluteToDoc(doc, value); } return value; } function ignoreAttribute(tagName, name, _value) { return ['video', 'audio'].includes(tagName) && name === 'autoplay'; } function _isBlockedElement(element, blockClass, blockSelector) { try { if (typeof blockClass === 'string') { if (element.classList.contains(blockClass)) { return true; } } else { for (var eIndex = element.classList.length; eIndex--;) { var className = element.classList[eIndex]; if (blockClass.test(className)) { return true; } } } if (blockSelector) { return element.matches(blockSelector); } } catch (e) { } return false; } function classMatchesRegex(node, regex, checkAncestors) { if (!node) return false; if (node.nodeType !== node.ELEMENT_NODE) { if (!checkAncestors) return false; return classMatchesRegex(dom.parentNode(node), regex, checkAncestors); } for (var eIndex = node.classList.length; eIndex--;) { var className = node.classList[eIndex]; if (regex.test(className)) { return true; } } if (!checkAncestors) return false; return classMatchesRegex(dom.parentNode(node), regex, checkAncestors); } function needMaskingText(node, maskTextClass, maskTextSelector, checkAncestors) { var el; if (isElement(node)) { el = node; if (!dom.childNodes(el).length) { return false; } } else if (dom.parentElement(node) === null) { return false; } else { el = dom.parentElement(node); } try { if (typeof maskTextClass === 'string') { if (checkAncestors) { if (el.closest(".".concat(maskTextClass))) return true; } else { if (el.classList.contains(maskTextClass)) return true; } } else { if (classMatchesRegex(el, maskTextClass, checkAncestors)) return true; } if (maskTextSelector) { if (checkAncestors) { if (el.closest(maskTextSelector)) return true; } else { if (el.matches(maskTextSelector)) return true; } } } catch (e) { } return false; } function onceIframeLoaded(iframeEl, listener, iframeLoadTimeout) { var win = iframeEl.contentWindow; if (!win) { return; } var fired = false; var readyState; try { readyState = win.document.readyState; } catch (error) { return; } if (readyState !== 'complete') { var timer_1 = cxSetTimeout(function () { if (!fired) { listener(); fired = true; } }, iframeLoadTimeout); iframeEl.addEventListener('load', function () { cxClearTimeout(timer_1); fired = true; listener(); }); return; } var blankUrl = 'about:blank'; if (win.location.href !== blankUrl || iframeEl.src === blankUrl || iframeEl.src === '') { cxSetTimeout(listener, 0); return iframeEl.addEventListener('load', listener); } iframeEl.addEventListener('load', listener); } function onceStylesheetLoaded(link, listener, styleSheetLoadTimeout) { var fired = false; var styleSheetLoaded; try { styleSheetLoaded = link.sheet; } catch (error) { return; } if (styleSheetLoaded) return; var timer = cxSetTimeout(function () { if (!fired) { listener(); fired = true; } }, styleSheetLoadTimeout); link.addEventListener('load', function () { cxClearTimeout(timer); fired = true; listener(); }); } function serializeNode(n, options) { var doc = options.doc, mirror = options.mirror, blockClass = options.blockClass, blockSelector = options.blockSelector, needsMask = options.needsMask, 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, _d = options.cssCaptured, cssCaptured = _d === void 0 ? false : _d; var rootId = getRootId(doc, mirror); switch (n.nodeType) { case n.DOCUMENT_NODE: if (n.compatMode !== 'CSS1Compat') { return { type: NodeType.Document, childNodes: [], compatMode: n.compatMode, }; } else { return { type: NodeType.Document, childNodes: [], }; } case n.DOCUMENT_TYPE_NODE: return { type: NodeType.DocumentType, name: n.name, publicId: n.publicId, systemId: n.systemId, rootId: rootId, }; case n.ELEMENT_NODE: return serializeElementNode(n, { doc: doc, blockClass: blockClass, blockSelector: blockSelector, inlineStylesheet: inlineStylesheet, maskInputOptions: maskInputOptions, maskInputFn: maskInputFn, dataURLOptions: dataURLOptions, inlineImages: inlineImages, recordCanvas: recordCanvas, keepIframeSrcFn: keepIframeSrcFn, newlyAddedElement: newlyAddedElement, rootId: rootId, }); case n.TEXT_NODE: return serializeTextNode(n, { doc: doc, needsMask: needsMask, maskTextFn: maskTextFn, rootId: rootId, cssCaptured: cssCaptured, }); case n.CDATA_SECTION_NODE: return { type: NodeType.CDATA, textContent: '', rootId: rootId, }; case n.COMMENT_NODE: return { type: NodeType.Comment, textContent: dom.textContent(n) || '', rootId: rootId, }; default: return false; } } function getRootId(doc, mirror) { if (!mirror.hasNode(doc)) return undefined; var docId = mirror.getId(doc); return docId === 1 ? undefined : docId; } function serializeTextNode(n, options) { var needsMask = options.needsMask, maskTextFn = options.maskTextFn, rootId = options.rootId, cssCaptured = options.cssCaptured; var parent = dom.parentNode(n); var parentTagName = parent && parent.tagName; var textContent = ''; var isStyle = parentTagName === 'STYLE' ? true : undefined; var isScript = parentTagName === 'SCRIPT' ? true : undefined; if (isScript) { textContent = 'SCRIPT_PLACEHOLDER'; } else if (!cssCaptured) { textContent = dom.textContent(n); if (isStyle && textContent) { textContent = absolutifyURLs(textContent, getHref(options.doc)); } } if (!isStyle && !isScript && textContent && needsMask) { textContent = maskTextFn ? maskTextFn(textContent, dom.parentElement(n)) : textContent.replace(/[\S]/g, '*'); } return { type: NodeType.Text, textContent: textContent || '', rootId: rootId, }; } function serializeElementNode(n, options) { 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; var needBlock = _isBlockedElement(n, blockClass, blockSelector); var tagName = getValidTagName(n); var attributes = {}; var len = n.attributes.length; for (var i = 0; i < len; i++) { var attr = n.attributes[i]; if (!ignoreAttribute(tagName, attr.name, attr.value)) { attributes[attr.name] = transformAttribute(doc, tagName, toLowerCase(attr.name), attr.value); } } if (tagName === 'link' && inlineStylesheet) { var stylesheet = Array.from(doc.styleSheets).find(function (s) { return s.href === n.href; }); var cssText = null; if (stylesheet) { cssText = stringifyStylesheet(stylesheet); } if (cssText) { delete attributes['rel']; delete attributes['href']; attributes._cssText = cssText; } } if (tagName === 'style' && n.sheet) { var cssText = stringifyStylesheet(n.sheet); if (cssText) { if (n.childNodes.length > 1) { cssText = markCssSplits(cssText, n); } attributes._cssText = cssText; } } if (['input', 'textarea', 'select'].includes(tagName)) { var value = n.value; var checked = n.checked; if (attributes['type'] !== 'radio' && attributes['type'] !== 'checkbox' && attributes['type'] !== 'submit' && attributes['type'] !== 'button' && value) { attributes['value'] = maskInputValue({ element: n, type: getInputType(n), tagName: tagName, value: value, maskInputOptions: maskInputOptions, maskInputFn: maskInputFn, }); } else if (checked) { attributes['checked'] = checked; } } if (tagName === 'option') { if (n.selected && !maskInputOptions['select']) { attributes['selected'] = true; } else { delete attributes['selected']; } } if (tagName === 'dialog' && n.open) { attributes.rr_open_mode = n.matches('dialog:modal') ? 'modal' : 'non-modal'; } if (tagName === 'canvas' && recordCanvas) { if (n.__context === '2d') { if (!is2DCanvasBlank(n)) { attributes['rr_dataURL'] = n.toDataURL(dataURLOptions.type, dataURLOptions.quality); } } else if (!('__context' in n)) { var canvasDataURL = n.toDataURL(dataURLOptions.type, dataURLOptions.quality); var blankCanvas = doc.createElement('canvas'); blankCanvas.width = n.width; blankCanvas.height = n.height; var blankCanvasDataURL = blankCanvas.toDataURL(dataURLOptions.type, dataURLOptions.quality); if (canvasDataURL !== blankCanvasDataURL) { attributes['rr_dataURL'] = canvasDataURL; } } } if (tagName === 'img' && inlineImages) { if (!canvasService) { canvasService = doc.createElement('canvas'); canvasCtx = canvasService.getContext('2d'); } var image_1 = n; var imageSrc_1 = image_1.currentSrc || image_1.getAttribute('src') || '<unknown-src>'; var priorCrossOrigin_1 = image_1.crossOrigin; var recordInlineImage_1 = function () { image_1.removeEventListener('load', recordInlineImage_1); try { canvasService.width = image_1.naturalWidth; canvasService.height = image_1.naturalHeight; canvasCtx.drawImage(image_1, 0, 0); attributes['rr_dataURL'] = canvasService.toDataURL(dataURLOptions.type, dataURLOptions.quality); } catch (err) { if (image_1.crossOrigin !== 'anonymous') { image_1.crossOrigin = 'anonymous'; if (image_1.complete && image_1.naturalWidth !== 0) recordInlineImage_1(); else image_1.addEventListener('load', recordInlineImage_1); return; } else { console.warn("Cannot inline img src=".concat(imageSrc_1, "! Error: ").concat(err)); } } if (image_1.crossOrigin === 'anonymous') { priorCrossOrigin_1 ? (attributes['crossOrigin'] = priorCrossOrigin_1) : image_1.removeAttribute('crossorigin'); } }; if (image_1.complete && image_1.naturalWidth !== 0) recordInlineImage_1(); else image_1.addEventListener('load', recordInlineImage_1); } if (['audio', 'video'].includes(tagName)) { var mediaAttributes = attributes; mediaAttributes.rr_mediaState = n.paused ? 'paused' : 'played'; mediaAttributes.rr_mediaCurrentTime = n.currentTime; mediaAttributes.rr_mediaPlaybackRate = n.playbackRate; mediaAttributes.rr_mediaMuted = n.muted; mediaAttributes.rr_mediaLoop = n.loop; mediaAttributes.rr_mediaVolume = n.volume; } if (!newlyAddedElement) { if (n.scrollLeft) { attributes['rr_scrollLeft'] = n.scrollLeft; } if (n.scrollTop) { attributes['rr_scrollTop'] = n.scrollTop; } } if (needBlock) { var _d = n.getBoundingClientRect(), width = _d.width, height = _d.height; attributes = { class: attributes['class'], rr_width: "".concat(width, "px"), rr_height: "".concat(height, "px"), }; } if (tagName === 'iframe' && !keepIframeSrcFn(attributes['src'])) { if (!n.contentDocument) { attributes['rr_src'] = attributes['src']; } delete attributes['src']; } var isCustomElement; try { if (customElements.get(tagName)) isCustomElement = true; } catch (e) { } var isSVG = isSVGElement(n); return { type: NodeType.Element, tagName: isSVG ? n.tagName : tagName, attributes: attributes, childNodes: [], isSVG: isSVG || undefined, needBlock: needBlock, rootId: rootId, isCustom: isCustomElement, }; } function lowerIfExists(maybeAttr) { if (maybeAttr === undefined || maybeAttr === null) { return ''; } else { return maybeAttr.toLowerCase(); } } function slimDOMDefaults(_slimDOMOptions) { if (_slimDOMOptions === true || _slimDOMOptions === 'all') { return { script: true, comment: true, headFavicon: true, headWhitespace: true, headMetaSocial: true, headMetaRobots: true, headMetaHttpEquiv: true, headMetaVerification: true, headMetaAuthorship: _slimDOMOptions === 'all', headMetaDescKeywords: _slimDOMOptions === 'all', headTitleMutations: _slimDOMOptions === 'all', }; } else if (_slimDOMOptions) { return _slimDOMOptions; } return {}; } function slimDOMExcluded(sn, slimDOMOptions) { if (slimDOMOptions.comment && sn.type === NodeType.Comment) { return true; } else if (sn.type === NodeType.Element) { if (slimDOMOptions.script && (sn.tagName === 'script' || (sn.tagName === 'link' && ((sn.attributes['rel'] === 'preload' && sn.attributes['as'] === 'script') || sn.attributes['rel'] === 'modulepreload')) || (sn.tagName === 'link' && sn.attributes['rel'] === 'prefetch' && typeof sn.attributes['href'] === 'string' && extractFileExtension(sn.attributes['href']) === 'js'))) { return true; } else if (slimDOMOptions.headFavicon && ((sn.tagName === 'link' && sn.attributes['rel'] === 'shortcut icon') || (sn.tagName === 'meta' && (lowerIfExists(sn.attributes['name']).match(/^msapplication-tile(image|color)$/) || lowerIfExists(sn.attributes['name']) === 'application-name' || lowerIfExists(sn.attributes['rel']) === 'icon' || lowerIfExists(sn.attributes['rel']) === 'apple-touch-icon' || lowerIfExists(sn.attributes['rel']) === 'shortcut icon')))) { return true; } else if (sn.tagName === 'meta') { if (slimDOMOptions.headMetaDescKeywords && lowerIfExists(sn.attributes['name']).match(/^description|keywords$/)) { return true; } else if (slimDOMOptions.headMetaSocial && (lowerIfExists(sn.attributes['property']).match(/^(og|twitter|fb):/) || lowerIfExists(sn.attributes['name']).match(/^(og|twitter):/) || lowerIfExists(sn.attributes['name']) === 'pinterest')) { return true; } else if (slimDOMOptions.headMetaRobots && (lowerIfExists(sn.attributes['name']) === 'robots' || lowerIfExists(sn.attributes['name']) === 'googlebot' || lowerIfExists(sn.attributes['name']) === 'bingbot')) { return true; } else if (slimDOMOptions.headMetaHttpEquiv && sn.attributes['http-equiv'] !== undefined) { return true; } else if (slimDOMOptions.headMetaAuthorship && (lowerIfExists(sn.attributes['name']) === 'author' || lowerIfExists(sn.attributes['name']) === 'generator' || lowerIfExists(sn.attributes['name']) === 'framework' || lowerIfExists(sn.attributes['name']) === 'publisher' || lowerIfExists(sn.attributes['name']) === 'progid' || lowerIfExists(sn.attributes['property']).match(/^article:/) || lowerIfExists(sn.attributes['property']).match(/^product:/))) { return true; } else if (slimDOMOptions.headMetaVerification && (lowerIfExists(sn.attributes['name']) === 'google-site-verification' || lowerIfExists(sn.attributes['name']) === 'yandex-verification' || lowerIfExists(sn.attributes['name']) === 'csrf-token' || lowerIfExists(sn.attributes['name']) === 'p:domain_verify' || lowerIfExists(sn.attributes['name']) === 'verify-v1' || lowerIfExists(sn.attributes['name']) === 'verification' || lowerIfExists(sn.attributes['name']) === 'shopify-checkout-api-token')) { return true; } } } return false; } function serializeNodeWithId(n, options) { var e_1, _a, e_2, _b; var doc = options.doc, mirror = options.mirror, blockClass = options.blockClass, blockSelector = options.blockSelector, maskTextClass = options.maskTextClass, maskTextSelector = options.maskTextSelector, _c = options.skipChild, skipChild = _c === void 0 ? false : _c, _d = options.inlineStylesheet, inlineStylesheet = _d === void 0 ? true : _d, _e = options.maskInputOptions, maskInputOptions = _e === void 0 ? {} : _e, maskTextFn = options.maskTextFn, maskInputFn = options.maskInputFn, slimDOMOptions = options.slimDOMOptions, _f = options.dataURLOptions, dataURLOptions = _f === void 0 ? {} : _f, _g = options.inlineImages, inlineImages = _g === void 0 ? false : _g, _h = options.recordCanvas, recordCanvas = _h === void 0 ? false : _h, onSerialize = options.onSerialize, onIframeLoad = options.onIframeLoad, _j = options.iframeLoadTimeout, iframeLoadTimeout = _j === void 0 ? 5000 : _j, onStylesheetLoad = options.onStylesheetLoad, _k = options.stylesheetLoadTimeout, stylesheetLoadTimeout = _k === void 0 ? 5000 : _k, _l = options.keepIframeSrcFn, keepIframeSrcFn = _l === void 0 ? function () { return false; } : _l, _m = options.newlyAddedElement, newlyAddedElement = _m === void 0 ? fal