UNPKG

mixpanel-browser

Version:

The official Mixpanel JavaScript browser client library

1,310 lines (1,309 loc) 842 kB
// since es6 imports are static and we run unit tests from the console, window won't be defined when importing this file var win; if (typeof(window) === 'undefined') { var loc = { hostname: '' }; win = { crypto: {randomUUID: function() {throw Error('unsupported');}}, navigator: { userAgent: '', onLine: true }, document: { createElement: function() { return {}; }, location: loc, referrer: '' }, screen: { width: 0, height: 0 }, location: loc, addEventListener: function() {}, removeEventListener: function() {} }; } else { win = window; } function _array_like_to_array(arr, len) { if (len == null || len > arr.length) len = arr.length; for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; return arr2; } function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _async_to_generator(fn) { return function() { var self = this, args = arguments; return new Promise(function(resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } function _construct(Parent, args, Class) { if (_is_native_reflect_construct()) { _construct = Reflect.construct; } else { _construct = function construct(Parent, args, Class) { var a = [ null ]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _set_prototype_of(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); } function _defineProperties(target, props) { for(var i = 0; i < props.length; i++){ var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _create_class(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); return Constructor; } function _extends() { _extends = Object.assign || function(target) { for(var i = 1; i < arguments.length; i++){ var source = arguments[i]; for(var key in source){ if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } function _get_prototype_of(o) { _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _get_prototype_of(o); } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _set_prototype_of(subClass, superClass); } function _instanceof(left, right) { if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) { return !!right[Symbol.hasInstance](left); } else { return left instanceof right; } } function _is_native_function(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; } function _object_without_properties_loose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for(i = 0; i < sourceKeys.length; i++){ key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } function _set_prototype_of(o, p) { _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _set_prototype_of(o, p); } function _type_of(obj) { "@swc/helpers - typeof"; return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; } function _unsupported_iterable_to_array(o, minLen) { if (!o) return; if (typeof o === "string") return _array_like_to_array(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen); } function _wrap_native_super(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrap_native_super = function wrapNativeSuper(Class) { if (Class === null || !_is_native_function(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _get_prototype_of(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _set_prototype_of(Wrapper, Class); }; return _wrap_native_super(Class); } function _is_native_reflect_construct() { try { var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {})); } catch (_) {} return (_is_native_reflect_construct = function() { return !!result; })(); } function _create_for_of_iterator_helper_loose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike) { if (it) o = it; var i = 0; return function() { if (i >= o.length) { return { done: true }; } return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _ts_generator(thisArg, body) { var f, y, t, g, _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function(v) { return step([ n, v ]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while(_)try { 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; if (y = 0, t) op = [ op[0] & 2, t.value ]; switch(op[0]){ case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [ 0 ]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [ 6, e ]; y = 0; } finally{ f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } } function _ts_values(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function() { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); } var __defProp = Object.defineProperty; var __defNormalProp = function(obj, key, value) { return key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value: value }) : obj[key] = value; }; var __publicField = function(obj, key, value) { return __defNormalProp(obj, (typeof key === "undefined" ? "undefined" : _type_of(key)) !== "symbol" ? key + "" : key, value); }; var _a; var __defProp$1 = Object.defineProperty; var __defNormalProp$1 = function(obj, key, value) { return key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value: value }) : obj[key] = value; }; var __publicField$1 = function(obj, key, value) { return __defNormalProp$1(obj, (typeof key === "undefined" ? "undefined" : _type_of(key)) !== "symbol" ? key + "" : key, value); }; var NodeType$3 = /* @__PURE__ */ function(NodeType2) { NodeType2[NodeType2["Document"] = 0] = "Document"; NodeType2[NodeType2["DocumentType"] = 1] = "DocumentType"; NodeType2[NodeType2["Element"] = 2] = "Element"; NodeType2[NodeType2["Text"] = 3] = "Text"; NodeType2[NodeType2["CDATA"] = 4] = "CDATA"; NodeType2[NodeType2["Comment"] = 5] = "Comment"; return NodeType2; }(NodeType$3 || {}); var testableAccessors$1 = { Node: [ "childNodes", "parentNode", "parentElement", "textContent" ], ShadowRoot: [ "host", "styleSheets" ], Element: [ "shadowRoot", "querySelector", "querySelectorAll" ], MutationObserver: [] }; var testableMethods$1 = { Node: [ "contains", "getRootNode" ], ShadowRoot: [ "getSelection" ], Element: [], MutationObserver: [ "constructor" ] }; var untaintedBasePrototype$1 = {}; var isAngularZonePresent$1 = function() { return !!globalThis.Zone; }; function getUntaintedPrototype$1(key) { if (untaintedBasePrototype$1[key]) return untaintedBasePrototype$1[key]; var defaultObj = globalThis[key]; var defaultPrototype = defaultObj.prototype; var accessorNames = key in testableAccessors$1 ? testableAccessors$1[key] : void 0; var isUntaintedAccessors = Boolean(accessorNames && // @ts-expect-error 2345 accessorNames.every(function(accessor) { var _a2, _b; return Boolean((_b = (_a2 = Object.getOwnPropertyDescriptor(defaultPrototype, accessor)) == null ? void 0 : _a2.get) == null ? void 0 : _b.toString().includes("[native code]")); })); var methodNames = key in testableMethods$1 ? testableMethods$1[key] : void 0; var isUntaintedMethods = Boolean(methodNames && methodNames.every(// @ts-expect-error 2345 function(method) { var _a2; return typeof defaultPrototype[method] === "function" && ((_a2 = defaultPrototype[method]) == null ? void 0 : _a2.toString().includes("[native code]")); })); if (isUntaintedAccessors && isUntaintedMethods && !isAngularZonePresent$1()) { untaintedBasePrototype$1[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$1[key] = untaintedObject; } catch (e) { return defaultPrototype; } } var untaintedAccessorCache$1 = {}; function getUntaintedAccessor$1(key, instance, accessor) { var _a2; var cacheKey = key + "." + String(accessor); if (untaintedAccessorCache$1[cacheKey]) return untaintedAccessorCache$1[cacheKey].call(instance); var untaintedPrototype = getUntaintedPrototype$1(key); var untaintedAccessor = (_a2 = Object.getOwnPropertyDescriptor(untaintedPrototype, accessor)) == null ? void 0 : _a2.get; if (!untaintedAccessor) return instance[accessor]; untaintedAccessorCache$1[cacheKey] = untaintedAccessor; return untaintedAccessor.call(instance); } var untaintedMethodCache$1 = {}; function getUntaintedMethod$1(key, instance, method) { var cacheKey = key + "." + String(method); if (untaintedMethodCache$1[cacheKey]) return untaintedMethodCache$1[cacheKey].bind(instance); var untaintedPrototype = getUntaintedPrototype$1(key); var untaintedMethod = untaintedPrototype[method]; if (typeof untaintedMethod !== "function") return instance[method]; untaintedMethodCache$1[cacheKey] = untaintedMethod; return untaintedMethod.bind(instance); } function childNodes$1(n2) { return getUntaintedAccessor$1("Node", n2, "childNodes"); } function parentNode$1(n2) { return getUntaintedAccessor$1("Node", n2, "parentNode"); } function parentElement$1(n2) { return getUntaintedAccessor$1("Node", n2, "parentElement"); } function textContent$1(n2) { return getUntaintedAccessor$1("Node", n2, "textContent"); } function contains$1(n2, other) { return getUntaintedMethod$1("Node", n2, "contains")(other); } function getRootNode$1(n2) { return getUntaintedMethod$1("Node", n2, "getRootNode")(); } function host$1(n2) { if (!n2 || !("host" in n2)) return null; return getUntaintedAccessor$1("ShadowRoot", n2, "host"); } function styleSheets$1(n2) { return n2.styleSheets; } function shadowRoot$1(n2) { if (!n2 || !("shadowRoot" in n2)) return null; return getUntaintedAccessor$1("Element", n2, "shadowRoot"); } function querySelector$1(n2, selectors) { return getUntaintedAccessor$1("Element", n2, "querySelector")(selectors); } function querySelectorAll$1(n2, selectors) { return getUntaintedAccessor$1("Element", n2, "querySelectorAll")(selectors); } function mutationObserverCtor$1() { return getUntaintedPrototype$1("MutationObserver").constructor; } var index$1 = { childNodes: childNodes$1, parentNode: parentNode$1, parentElement: parentElement$1, textContent: textContent$1, contains: contains$1, getRootNode: getRootNode$1, host: host$1, styleSheets: styleSheets$1, shadowRoot: shadowRoot$1, querySelector: querySelector$1, querySelectorAll: querySelectorAll$1, mutationObserver: mutationObserverCtor$1 }; function isElement(n2) { return n2.nodeType === n2.ELEMENT_NODE; } function isShadowRoot(n2) { var hostEl = // anchor and textarea elements also have a `host` property // but only shadow roots have a `mode` property n2 && "host" in n2 && "mode" in n2 && index$1.host(n2) || null; return Boolean(hostEl && "shadowRoot" in hostEl && index$1.shadowRoot(hostEl) === n2); } function isNativeShadowDom(shadowRoot2) { return Object.prototype.toString.call(shadowRoot2) === "[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(rule2) { var cssText = rule2.cssText; if (cssText.split('"').length < 3) return cssText; var statement = [ "@import", "url(" + JSON.stringify(rule2.href) + ")" ]; if (rule2.layerName === "") { statement.push("layer"); } else if (rule2.layerName) { statement.push("layer(" + rule2.layerName + ")"); } if (rule2.supportsText) { statement.push("supports(" + rule2.supportsText + ")"); } if (rule2.media.length) { statement.push(rule2.media.mediaText); } return statement.join(" ") + ";"; } function stringifyStylesheet(s2) { try { var rules2 = s2.rules || s2.cssRules; if (!rules2) { return null; } var sheetHref = s2.href; if (!sheetHref && s2.ownerNode && s2.ownerNode.ownerDocument) { sheetHref = s2.ownerNode.ownerDocument.location.href; } var stringifiedRules = Array.from(rules2, function(rule2) { return stringifyRule(rule2, sheetHref); }).join(""); return fixBrowserCompatibilityIssuesInCSS(stringifiedRules); } catch (error) { return null; } } function stringifyRule(rule2, sheetHref) { if (isCSSImportRule(rule2)) { var importStringified; try { importStringified = // we can access the imported stylesheet rules directly stringifyStylesheet(rule2.styleSheet) || // work around browser issues with the raw string `@import url(...)` statement escapeImportStatement(rule2); } catch (error) { importStringified = rule2.cssText; } if (rule2.styleSheet.href) { return absolutifyURLs(importStringified, rule2.styleSheet.href); } return importStringified; } else { var ruleStringified = rule2.cssText; if (isCSSStyleRule(rule2) && rule2.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(rule2) { return "styleSheet" in rule2; } function isCSSStyleRule(rule2) { return "selectorText" in rule2; } var Mirror = /*#__PURE__*/ function() { function Mirror() { __publicField$1(this, "idNodeMap", /* @__PURE__ */ new Map()); __publicField$1(this, "nodeMetaMap", /* @__PURE__ */ new WeakMap()); } var _proto = Mirror.prototype; _proto.getId = function getId(n2) { var _a2; if (!n2) return -1; var id = (_a2 = this.getMeta(n2)) == null ? void 0 : _a2.id; return id != null ? id : -1; }; _proto.getNode = function getNode(id) { return this.idNodeMap.get(id) || null; }; _proto.getIds = function getIds() { return Array.from(this.idNodeMap.keys()); }; _proto.getMeta = function getMeta(n2) { return this.nodeMetaMap.get(n2) || null; }; // removes the node from idNodeMap // doesn't remove the node from nodeMetaMap _proto.removeNodeFromMap = function removeNodeFromMap(n2) { var _this = this; var id = this.getId(n2); this.idNodeMap.delete(id); if (n2.childNodes) { n2.childNodes.forEach(function(childNode) { return _this.removeNodeFromMap(childNode); }); } }; _proto.has = function has(id) { return this.idNodeMap.has(id); }; _proto.hasNode = function hasNode(node2) { return this.nodeMetaMap.has(node2); }; _proto.add = function add(n2, meta) { var id = meta.id; this.idNodeMap.set(id, n2); this.nodeMetaMap.set(n2, meta); }; _proto.replace = function replace(id, n2) { var oldNode = this.getNode(id); if (oldNode) { var meta = this.nodeMetaMap.get(oldNode); if (meta) this.nodeMetaMap.set(n2, meta); } this.idNodeMap.set(id, n2); }; _proto.reset = function reset() { this.idNodeMap = /* @__PURE__ */ new Map(); this.nodeMetaMap = /* @__PURE__ */ new WeakMap(); }; return Mirror; }(); function createMirror$2() { return new Mirror(); } function maskInputValue(param) { var element = param.element, maskInputOptions = param.maskInputOptions, tagName = param.tagName, type = param.type, value = param.value, maskInputFn = param.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 x2 = 0; x2 < canvas.width; x2 += 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(// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access originalGetImageData.call(ctx, x2, y, Math.min(chunkSize, canvas.width - x2), 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 ? // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion toLowerCase(type) : null; } function extractFileExtension(path, baseURL) { var url; try { url = new URL(path, baseURL != null ? baseURL : window.location.href); } catch (err) { return null; } var regex = /\.([0-9a-z]+)(?:$)/i; var match = url.pathname.match(regex); var _ref; return (_ref = match == null ? void 0 : match[1]) != null ? _ref : 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 filePath = path1 || path2 || path3; var maybeQuote = quote1 || quote2 || ""; if (!filePath) { return origin; } if (URL_PROTOCOL_MATCH.test(filePath) || URL_WWW_MATCH.test(filePath)) { return "url(" + maybeQuote + filePath + maybeQuote + ")"; } if (DATA_URI.test(filePath)) { return "url(" + maybeQuote + filePath + maybeQuote + ")"; } if (filePath[0] === "/") { return "url(" + maybeQuote + (extractOrigin(href) + filePath) + maybeQuote + ")"; } var stack = href.split("/"); var parts = filePath.split("/"); stack.pop(); for(var _iterator = _create_for_of_iterator_helper_loose(parts), _step; !(_step = _iterator()).done;){ var part = _step.value; if (part === ".") { continue; } else if (part === "..") { stack.pop(); } else { stack.push(part); } } return "url(" + maybeQuote + stack.join("/") + maybeQuote + ")"; }); } function normalizeCssString(cssText) { return cssText.replace(/(\/\*[^*]*\*\/)|[\s;]/g, ""); } function splitCssText(cssText, style) { var childNodes2 = Array.from(style.childNodes); var splits = []; if (childNodes2.length > 1 && cssText && typeof cssText === "string") { var cssTextNorm = normalizeCssString(cssText); for(var i2 = 1; i2 < childNodes2.length; i2++){ if (childNodes2[i2].textContent && typeof childNodes2[i2].textContent === "string") { var textContentNorm = normalizeCssString(childNodes2[i2].textContent); for(var j = 3; j < textContentNorm.length; j++){ var bit = textContentNorm.substring(0, j); if (cssTextNorm.split(bit).length === 2) { var splitNorm = cssTextNorm.indexOf(bit); for(var k = splitNorm; k < cssText.length; k++){ if (normalizeCssString(cssText.substring(0, k)).length === splitNorm) { splits.push(cssText.substring(0, k)); cssText = cssText.substring(k); break; } } 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$1(element) { if (_instanceof(element, 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 chars2; var match = regEx.exec(attributeValue.substring(pos)); if (match) { chars2 = match[0]; pos += chars2.length; return chars2; } 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 c2 = attributeValue.charAt(pos); if (c2 === "") { output.push((url + descriptorsStr).trim()); break; } else if (!inParens) { if (c2 === ",") { pos += 1; output.push((url + descriptorsStr).trim()); break; } else if (c2 === "(") { inParens = true; } } else { if (c2 === ")") { inParens = false; } } descriptorsStr += c2; pos += 1; } } } return output.join(", "); } var cachedDocument = /* @__PURE__ */ new WeakMap(); function absoluteToDoc(doc, attributeValue) { if (!attributeValue || attributeValue.trim() === "") { return attributeValue; } return getHref(doc, attributeValue); } function isSVGElement(el) { return Boolean(el.tagName === "svg" || el.ownerSVGElement); } function getHref(doc, customHref) { var a2 = cachedDocument.get(doc); if (!a2) { a2 = doc.createElement("a"); cachedDocument.set(doc, a2); } if (!customHref) { customHref = ""; } else if (customHref.startsWith("blob:") || customHref.startsWith("data:")) { return customHref; } a2.setAttribute("href", customHref); return a2.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" && (tagName === "table" || tagName === "td" || tagName === "th")) { 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 (tagName === "video" || tagName === "audio") && 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 (e2) {} return false; } function classMatchesRegex(node2, regex, checkAncestors) { if (!node2) return false; if (node2.nodeType !== node2.ELEMENT_NODE) { if (!checkAncestors) return false; return classMatchesRegex(index$1.parentNode(node2), regex, checkAncestors); } for(var eIndex = node2.classList.length; eIndex--;){ var className = node2.classList[eIndex]; if (regex.test(className)) { return true; } } if (!checkAncestors) return false; return classMatchesRegex(index$1.parentNode(node2), regex, checkAncestors); } function needMaskingText(node2, maskTextClass, maskTextSelector, checkAncestors) { var el; if (isElement(node2)) { el = node2; if (!index$1.childNodes(el).length) { return false; } } else if (index$1.parentElement(node2) === null) { return false; } else { el = index$1.parentElement(node2); } try { if (typeof maskTextClass === "string") { if (checkAncestors) { if (el.closest("." + 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 (e2) {} 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 = setTimeout(function() { if (!fired) { listener(); fired = true; } }, iframeLoadTimeout); iframeEl.addEventListener("load", function() { clearTimeout(timer); fired = true; listener(); }); return; } var blankUrl = "about:blank"; if (win.location.href !== blankUrl || iframeEl.src === blankUrl || iframeEl.src === "") { setTimeout(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 = setTimeout(function() { if (!fired) { listener(); fired = true; } }, styleSheetLoadTimeout); link.addEventListener("load", function() { clearTimeout(timer); fired = true; listener(); }); } function serializeNode(n2, options) { var doc = options.doc, mirror2 = options.mirror, blockClass = options.blockClass, blockSelector = options.blockSelector, needsMask = options.needsMask, inlineStylesheet = options.inlineStylesheet, _options_maskInputOptions = options.maskInputOptions, maskInputOptions = _options_maskInputOptions === void 0 ? {} : _options_maskInputOptions, maskTextFn = options.maskTextFn, maskInputFn = options.maskInputFn, _options_dataURLOptions = options.dataURLOptions, dataURLOptions = _options_dataURLOptions === void 0 ? {} : _options_dataURLOptions, inlineImages = options.inlineImages, recordCanvas = options.recordCanvas, keepIframeSrcFn = options.keepIframeSrcFn, _options_newlyAddedElement = options.newlyAddedElement, newlyAddedElement = _options_newlyAddedElement === void 0 ? false : _options_newlyAddedElement, _options_cssCaptured = options.cssCaptured, cssCaptured = _options_cssCaptured === void 0 ? false : _options_cssCaptured; var rootId = getRootId(doc, mirror2); switch(n2.nodeType){ case n2.DOCUMENT_NODE: if (n2.compatMode !== "CSS1Compat") { return { type: NodeType$3.Document, childNodes: [], compatMode: n2.compatMode }; } else { return { type: NodeType$3.Document, childNodes: [] }; } case n2.DOCUMENT_TYPE_NODE: return { type: NodeType$3.DocumentType, name: n2.name, publicId: n2.publicId, systemId: n2.systemId, rootId: rootId }; case n2.ELEMENT_NODE: return serializeElementNode(n2, { 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 n2.TEXT_NODE: return serializeTextNode(n2, { doc: doc, needsMask: needsMask, maskTextFn: maskTextFn, rootId: rootId, cssCaptured: cssCaptured }); case n2.CDATA_SECTION_NODE: return { type: NodeType$3.CDATA, textContent: "", rootId: rootId }; case n2.COMMENT_NODE: return { type: NodeType$3.Comment, textContent: index$1.textContent(n2) || "", rootId: rootId }; default: return false; } } function getRootId(doc, mirror2) { if (!mirror2.hasNode(doc)) return void 0; var docId = mirror2.getId(doc); return docId === 1 ? void 0 : docId; } function serializeTextNode(n2, options) { var needsMask = options.needsMask, maskTextFn = options.maskTextFn, rootId = options.rootId, cssCaptured = options.cssCaptured; var parent = index$1.parentNode(n2); var parentTagName = parent && parent.tagName; var textContent2 = ""; var isStyle = parentTagName === "STYLE" ? true : void 0; var isScript = parentTagName === "SCRIPT" ? true : void 0; if (isScript) { textContent2 = "SCRIPT_PLACEHOLDER"; } else if (!cssCaptured) { textContent2 = index$1.textContent(n2); if (isStyle && textContent2) { textContent2 = absolutifyURLs(textContent2, getHref(options.doc)); } } if (!isStyle && !isScript && textContent2 && needsMask) { textContent2 = maskTextFn ? maskTextFn(textContent2, index$1.parentElement(n2)) : textContent2.replace(/[\S]/g, "*"); } return { type: NodeType$3.Text, textContent: textContent2 || "", rootId: rootId }; } function serializeElementNode(n2, options) { var doc = options.doc, blockClass = options.blockClass, blockSelector = options.blockSelector, inlineStylesheet = options.inlineStylesheet, _options_maskInputOptions = options.maskInputOptions, maskInputOptions = _options_maskInputOptions === void 0 ? {} : _options_maskInputOptions, maskInputFn = options.maskInputFn, _options_dataURLOptions = options.dataURLOptions, dataURLOptions = _options_dataURLOptions === void 0 ? {} : _options_dataURLOptions, inlineImages = options.inlineImages, recordCanvas = options.recordCanvas, keepIframeSrcFn = options.keepIframeSrcFn, _options_newlyAddedElement = options.newlyAddedElement, newlyAddedElement = _options_newlyAddedElement === void 0 ? false : _options_newlyAddedElement, rootId = options.rootId; var needBlock = _isBlockedElement(n2, blockClass, blockSelector); var tagName = getValidTagName$1(n2); var attributes = {}; var len = n2.attributes.length; for(var i2 = 0; i2 < len; i2++){ var attr = n2.attributes[i2]; 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(s2) { return s2.href === n2.href; }); var cssText = null; if (stylesheet) { cssText = stringifyStylesheet(stylesheet); } if (cssText) { delete attributes.rel; delete attributes.href; attributes._cssText = cssText; } } if (tagName === "style" && n2.sheet) { var cssText1 = stringifyStylesheet(n2.sheet); if (cssText1) { if (n2.childNodes.length > 1) { cssText1 = markCssSplits(cssText1, n2); } attributes._cssText = cssText1; } } if (tagName === "input" || tagName === "textarea" || tagName === "select") { var value = n2.value; var checked = n2.checked; if (attributes.type !== "radio" && attributes.type !== "checkbox" && attributes.type !== "submit" && attributes.type !== "button" && value) { attributes.value = maskInputValue({ element: n2, type: getInputType(n2), tagName: tagName, value: value, maskInputOptions: maskInputOptions, maskInputFn: maskInputFn }); } else if (checked) { attributes.checked = checked; } } if (tagName === "option") { if (n2.selected && !maskInputOptions["select"]) { attributes.selected = true; } else { delete attributes.selected; } } if (tagName === "dialog" && n2.open) { attributes.rr_open_mode = n2.matches("dialog:modal") ? "modal" : "non-modal"; } if (tagName === "canvas" && recordCanvas) { if (n2.__context === "2d") { if (!is2DCanvasBlank(n2)) { attributes.rr_dataURL = n2.toDataURL(dataURLOptions.type, dataURLOptions.quality); } } else if (!("__context" in n2)) { var canvasDataURL = n2.toDataURL(dataURLOptions.type, dataURLOptions.quality); var blankCanvas = doc.createElement("canvas"); blankCanvas.width = n2.width; blankCanvas.height = n2.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 = n2; var imageSrc = image.currentSrc || image.getAttribute("src") || "<unknown-src>"; var priorCrossOrigin = image.crossOrigin; var recordInlineImage = function() { image.removeEventListener("load", recordInlineImage); try { canvasService.width = image.naturalWidth; canvasService.height = image.naturalHeight; canvasCtx.drawImage(image, 0, 0); attributes.rr_dataURL = canvasService.toDataURL(dataURLOptions.type, dataURLOptions.quality); } catch (err) { if (image.crossOrigin !== "anonymous") { image.crossOrigin = "anonymous"; if (image.complete && image.naturalWidth !== 0) recordInlineImage(); else image.addEventListener("load", recordInlineImage); return; } else { console.warn("Cannot inline img src=" + imageSrc + "! Error: " + err); } } if (image.crossOrigin === "anonymous") { priorCrossOrigin ? attributes.crossOrigin = priorCrossOrigin : image.removeAttribute("crossorigin"); } }; if (image.complete && image.naturalWidth !== 0) recordInlineImage(); else image.addEventListener("load", recordInlineImage); } if (tagName === "audio" || tagName === "video") { var mediaAttributes = attributes; mediaAttributes.rr_mediaState = n2.paused ? "paused" : "played"; mediaAttributes.rr_mediaCurrentTime = n2.currentTime; mediaAttributes.rr_mediaPlaybackRate = n2.playbackRate; mediaAttributes.rr_mediaMuted = n2.muted; mediaAttributes.rr_mediaLoop = n2.loop; mediaAttributes.rr_mediaVolume = n2.volume; } if (!newlyAddedElement) { if (n2.scrollLeft) { attributes.rr_scrollLeft = n2.scrollLeft; } if (n2.scrollTop) { attributes.rr_scrollTop = n2.scrollTop; } } if (needBlock) { var _n2_getBoundingClientRect = n2.getBoundingClientRect(), width = _n2_getBoundingClientRect.width, height = _n2_getBoundingClientRect.height; attributes = { class: attributes.class, rr_width: "" + width + "px", rr_height: "" + height + "px" }; } if (tagName === "iframe" && !keepIframeSrcFn(attributes.src)) { if (!n2.contentDocument) { attributes.rr_src = attributes.src; } delete attributes.src; } var isCustomElement; try { if (customElements.get(tagName)) isCustomElement = true; } catch (e2) {} return { type: NodeType$3.Element, tagName: tagName, attributes: attributes, childNodes: [], isSVG: isSVGElement(n2) || void 0, needBlock: needBlock, rootId: rootId, isCustom: isCustomElement }; } function lowerIfExists(maybeAttr) { if (maybeAttr === void 0 || maybeAttr === null) { return ""; } else { return maybeAttr.toLowerCase(); } } function slimDOMExcluded(sn, slimDOMOptions) { if (slimDOMOptions.comment && sn.type === NodeType$3.Comment) { return true; } else if (sn.type === NodeType$3.Element) { if (slimDOMOptions.script && // script tag (sn.tagName === "script" || // (module)preload link sn.tagName === "link" && (sn.attributes.rel === "preload" || sn.attributes.rel === "modulepreload") && sn.attributes.as === "script" || // prefetch link 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):/) || // og = opengraph (facebook) 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"] !== void 0) { 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(n2, options) { var doc = options.doc, mirror2 = options.mirror, blockClass = options.blockClass, blockSelector = options.blockSelector, maskTextClass = options.maskTextClass, maskTextSelector = options.maskT