UNPKG

@log-reporting/core

Version:
1 lines 100 kB
function getGlobalThis(){return"undefined"!=typeof window?window:{}}function getGlobalSupport(){return _global.__log_reporting__=_global.__log_reporting__||{},_global.__log_reporting__}let _global=getGlobalThis(),_support=getGlobalSupport(),_log=console.log;class Logger{constructor(){}log(e,t){_log(`%c${e}%c `+t,"color: #fff;font-weight: blod;letter-spacing:2px;padding: 3px 5px;background-color: #73767a;border-radius: 3px;","color: #909399;font-weight: blod;letter-spacing:2px;padding: 3px 5px;")}info(e,t){_log(`%c${e}%c `+t,"color: #fff;font-weight: blod;letter-spacing:2px;padding: 3px 5px;background-color: #337ecc;border-radius: 3px;","color: #409EFF;font-weight: blod;letter-spacing:2px;padding: 3px 5px;")}warn(e,t){_log(`%c${e}%c `+t,"color: #fff;font-weight: blod;letter-spacing:2px;padding: 3px 5px;background-color: #b88230;border-radius: 3px;","color: #E6A23C;font-weight: blod;letter-spacing:2px;padding: 3px 5px;")}error(e,t){_log(`%c${e}%c `+t,"color: #fff;font-weight: blod;letter-spacing:2px;padding: 3px 5px;background-color: #c45656;border-radius: 3px;","color: #F56C6C;font-weight: blod;letter-spacing:2px;padding: 3px 5px;")}success(e,t){_log(`%c${e}%c `+t,"color: #fff;font-weight: blod;letter-spacing:2px;padding: 3px 5px;background-color: #529b2e;border-radius: 3px;","color: #67C23A;font-weight: blod;letter-spacing:2px;padding: 3px 5px;")}}let logger=new Logger;function verifyBase(e){return!(!e.dsn||"string"!=typeof e.dsn)||(logger.error("dsn参数错误","dsn地址应该为 [字符串], 例如: https://www.wangxiaoze.wang"),!1)}function isKeyValid(e,t){return Object.prototype.hasOwnProperty.call(t,e)}function on$1(e,t,r,o=!1){e.addEventListener(t,r,o)}function getNavigation(e){var{domainLookupEnd:e,domainLookupStart:t,connectEnd:r,connectStart:o,secureConnectionStart:n,responseStart:a,requestStart:s,domInteractive:i,domComplete:l,loadEventEnd:c,loadEventStart:d,fetchStart:u}=e;return{dns:e-t,tcp:r-o,ssl:n,ttfb:a-s,render:null!=i?i:0,dom:null!=l?l:0,load:(null!=c?c:0)-(null!=d?d:0),total:(null!=c?c:0)-(null!=u?u:0)}}function getParams(e){var t,r,o={};for([t,r]of new URLSearchParams(e).entries())o[t]=r;return o}logger.log,logger,logger,logger,logger;class BaseInfo{constructor(e){this.options=e}}let baseInfo;function initBaseOptions(e){baseInfo=new BaseInfo(e),_support.baseInfo=baseInfo}var EVENT_TYPES,ERROR_TYPES;(e=>{e.ERROR="error",e.UNHANDLEDREJECTION="unhandledrejection",e.CONSOLE_ERROR="consoleError",e.XHR="xhr",e.FETCH="fetch",e.PV="pv",e.EXPOSURE="exposure"})(EVENT_TYPES=EVENT_TYPES||{}),(e=>{e.JS="js_error",e.PROMISE="promise_error",e.CONSOLE_ERROR="console_error",e.XHR="xhr_error",e.FETCH="fetch_error"})(ERROR_TYPES=ERROR_TYPES||{});class EventBus{constructor(){this._eventMap=new Map}static getInstance(){return this._instance||(this._instance=new EventBus),this._instance}on(e,t){this._eventMap.has(e)||this._eventMap.set(e,[]),null!=(e=this._eventMap.get(e))&&e.push(t)}emit(e,...t){this._eventMap.has(e)&&null!=(e=this._eventMap.get(e))&&e.forEach(e=>{e(...t)})}off(r,o){var e;this._eventMap.has(r)&&null!=(e=this._eventMap.get(r))&&e.forEach((e,t)=>{e===o&&null!=(e=this._eventMap.get(r))&&e.splice(t,1)})}once(r,o){var e;this._eventMap.has(r)&&null!=(e=this._eventMap.get(r))&&e.forEach((e,t)=>{e===o&&null!=(e=this._eventMap.get(r))&&e.splice(t,1)})}}let eventBus=_support.eventBus||(_support.eventBus=EventBus.getInstance());function support(e){return e in navigator?navigator[e]:"该浏览器不支持!"}function getNavigator(){return{platform:support("platform"),appName:support("appName"),appVersion:support("appVersion"),appCodeName:support("appCodeName"),vendor:support("vendor"),userAgent:support("userAgent"),onLine:support("onLine"),language:support("language"),product:support("product"),productSub:support("productSub"),windowWidth:window.screen.width,windowHeight:window.screen.height,colorDepth:window.screen.colorDepth}}function getDefaultExportFromCjs(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var lzString={exports:{}},lzStringExports=(lzString.exports,(e=>{I=String.fromCharCode,r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",n={};var I,r,o,n,s,t=s={compressToBase64:function(e){if(null==e)return"";var t=s._compress(e,6,function(e){return r.charAt(e)});switch(t.length%4){default:case 0:return t;case 1:return t+"===";case 2:return t+"==";case 3:return t+"="}},decompressFromBase64:function(t){return null==t?"":""==t?null:s._decompress(t.length,32,function(e){return a(r,t.charAt(e))})},compressToUTF16:function(e){return null==e?"":s._compress(e,15,function(e){return I(e+32)})+" "},decompressFromUTF16:function(t){return null==t?"":""==t?null:s._decompress(t.length,16384,function(e){return t.charCodeAt(e)-32})},compressToUint8Array:function(e){for(var t=s.compress(e),r=new Uint8Array(2*t.length),o=0,n=t.length;o<n;o++){var a=t.charCodeAt(o);r[2*o]=a>>>8,r[2*o+1]=a%256}return r},decompressFromUint8Array:function(e){if(null==e)return s.decompress(e);for(var t=new Array(e.length/2),r=0,o=t.length;r<o;r++)t[r]=256*e[2*r]+e[2*r+1];var n=[];return t.forEach(function(e){n.push(I(e))}),s.decompress(n.join(""))},compressToEncodedURIComponent:function(e){return null==e?"":s._compress(e,6,function(e){return o.charAt(e)})},decompressFromEncodedURIComponent:function(t){return null==t?"":""==t?null:(t=t.replace(/ /g,"+"),s._decompress(t.length,32,function(e){return a(o,t.charAt(e))}))},compress:function(e){return s._compress(e,16,function(e){return I(e)})},_compress:function(e,t,r){if(null==e)return"";for(var o,n,a,s,i={},l={},c="",d=2,u=3,p=2,g=[],h=0,m=0,f=0;f<e.length;f+=1)if(a=e.charAt(f),Object.prototype.hasOwnProperty.call(i,a)||(i[a]=u++,l[a]=!0),s=c+a,Object.prototype.hasOwnProperty.call(i,s))c=s;else{if(Object.prototype.hasOwnProperty.call(l,c)){if(c.charCodeAt(0)<256){for(o=0;o<p;o++)h<<=1,m==t-1?(m=0,g.push(r(h)),h=0):m++;for(n=c.charCodeAt(0),o=0;o<8;o++)h=h<<1|1&n,m==t-1?(m=0,g.push(r(h)),h=0):m++,n>>=1}else{for(n=1,o=0;o<p;o++)h=h<<1|n,m==t-1?(m=0,g.push(r(h)),h=0):m++,n=0;for(n=c.charCodeAt(0),o=0;o<16;o++)h=h<<1|1&n,m==t-1?(m=0,g.push(r(h)),h=0):m++,n>>=1}0==--d&&(d=Math.pow(2,p),p++),delete l[c]}else for(n=i[c],o=0;o<p;o++)h=h<<1|1&n,m==t-1?(m=0,g.push(r(h)),h=0):m++,n>>=1;0==--d&&(d=Math.pow(2,p),p++),i[s]=u++,c=String(a)}if(""!==c){if(Object.prototype.hasOwnProperty.call(l,c)){if(c.charCodeAt(0)<256){for(o=0;o<p;o++)h<<=1,m==t-1?(m=0,g.push(r(h)),h=0):m++;for(n=c.charCodeAt(0),o=0;o<8;o++)h=h<<1|1&n,m==t-1?(m=0,g.push(r(h)),h=0):m++,n>>=1}else{for(n=1,o=0;o<p;o++)h=h<<1|n,m==t-1?(m=0,g.push(r(h)),h=0):m++,n=0;for(n=c.charCodeAt(0),o=0;o<16;o++)h=h<<1|1&n,m==t-1?(m=0,g.push(r(h)),h=0):m++,n>>=1}0==--d&&(d=Math.pow(2,p),p++),delete l[c]}else for(n=i[c],o=0;o<p;o++)h=h<<1|1&n,m==t-1?(m=0,g.push(r(h)),h=0):m++,n>>=1;0==--d&&(d=Math.pow(2,p),p++)}for(n=2,o=0;o<p;o++)h=h<<1|1&n,m==t-1?(m=0,g.push(r(h)),h=0):m++,n>>=1;for(;;){if(h<<=1,m==t-1){g.push(r(h));break}m++}return g.join("")},decompress:function(t){return null==t?"":""==t?null:s._decompress(t.length,32768,function(e){return t.charCodeAt(e)})},_decompress:function(e,t,r){for(var o,n,a,s,i,l,c=[],d=4,u=4,p=3,g="",h=[],m={val:r(0),position:t,index:1},f=0;f<3;f+=1)c[f]=f;for(n=0,s=Math.pow(2,2),i=1;i!=s;)a=m.val&m.position,m.position>>=1,0==m.position&&(m.position=t,m.val=r(m.index++)),n|=(0<a?1:0)*i,i<<=1;switch(n){case 0:for(n=0,s=Math.pow(2,8),i=1;i!=s;)a=m.val&m.position,m.position>>=1,0==m.position&&(m.position=t,m.val=r(m.index++)),n|=(0<a?1:0)*i,i<<=1;l=I(n);break;case 1:for(n=0,s=Math.pow(2,16),i=1;i!=s;)a=m.val&m.position,m.position>>=1,0==m.position&&(m.position=t,m.val=r(m.index++)),n|=(0<a?1:0)*i,i<<=1;l=I(n);break;case 2:return""}for(o=c[3]=l,h.push(l);;){if(e<m.index)return"";for(n=0,s=Math.pow(2,p),i=1;i!=s;)a=m.val&m.position,m.position>>=1,0==m.position&&(m.position=t,m.val=r(m.index++)),n|=(0<a?1:0)*i,i<<=1;switch(l=n){case 0:for(n=0,s=Math.pow(2,8),i=1;i!=s;)a=m.val&m.position,m.position>>=1,0==m.position&&(m.position=t,m.val=r(m.index++)),n|=(0<a?1:0)*i,i<<=1;c[u++]=I(n),l=u-1,d--;break;case 1:for(n=0,s=Math.pow(2,16),i=1;i!=s;)a=m.val&m.position,m.position>>=1,0==m.position&&(m.position=t,m.val=r(m.index++)),n|=(0<a?1:0)*i,i<<=1;c[u++]=I(n),l=u-1,d--;break;case 2:return h.join("")}if(0==d&&(d=Math.pow(2,p),p++),c[l])g=c[l];else{if(l!==u)return null;g=o+o.charAt(0)}h.push(g),c[u++]=o+g.charAt(0),o=g,0==--d&&(d=Math.pow(2,p),p++)}}};function a(e,t){if(!n[e]){n[e]={};for(var r=0;r<e.length;r++)n[e][e.charAt(r)]=r}return n[e][t]}null!=e?e.exports=t:"undefined"!=typeof angular&&null!=angular&&angular.module("LZString",[]).factory("LZString",function(){return t})})(lzString),lzString.exports),lz=getDefaultExportFromCjs(lzStringExports);let version$1="3.7.7",VERSION=version$1,_hasBuffer="function"==typeof Buffer,_TD="function"==typeof TextDecoder?new TextDecoder:void 0,_TE="function"==typeof TextEncoder?new TextEncoder:void 0,b64ch="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",b64chs=Array.prototype.slice.call(b64ch),b64tab=(e=>{let r={};return e.forEach((e,t)=>r[e]=t),r})(b64chs),b64re=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/,_fromCC=String.fromCharCode.bind(String),_U8Afrom="function"==typeof Uint8Array.from?Uint8Array.from.bind(Uint8Array):e=>new Uint8Array(Array.prototype.slice.call(e,0)),_mkUriSafe=e=>e.replace(/=/g,"").replace(/[+\/]/g,e=>"+"==e?"-":"_"),_tidyB64=e=>e.replace(/[^A-Za-z0-9\+\/]/g,""),btoaPolyfill=t=>{let r,o,n,a,s="";var e=t.length%3;for(let e=0;e<t.length;){if(255<(o=t.charCodeAt(e++))||255<(n=t.charCodeAt(e++))||255<(a=t.charCodeAt(e++)))throw new TypeError("invalid character found");r=o<<16|n<<8|a,s+=b64chs[r>>18&63]+b64chs[r>>12&63]+b64chs[r>>6&63]+b64chs[63&r]}return e?s.slice(0,e-3)+"===".substring(e):s},_btoa="function"==typeof btoa?e=>btoa(e):_hasBuffer?e=>Buffer.from(e,"binary").toString("base64"):btoaPolyfill,_fromUint8Array=_hasBuffer?e=>Buffer.from(e).toString("base64"):r=>{var o=[];for(let e=0,t=r.length;e<t;e+=4096)o.push(_fromCC.apply(null,r.subarray(e,e+4096)));return _btoa(o.join(""))},fromUint8Array=(e,t=!1)=>t?_mkUriSafe(_fromUint8Array(e)):_fromUint8Array(e),cb_utob=e=>{var t;return e.length<2?(t=e.charCodeAt(0))<128?e:t<2048?_fromCC(192|t>>>6)+_fromCC(128|63&t):_fromCC(224|t>>>12&15)+_fromCC(128|t>>>6&63)+_fromCC(128|63&t):(t=65536+1024*(e.charCodeAt(0)-55296)+(e.charCodeAt(1)-56320),_fromCC(240|t>>>18&7)+_fromCC(128|t>>>12&63)+_fromCC(128|t>>>6&63)+_fromCC(128|63&t))},re_utob=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,utob=e=>e.replace(re_utob,cb_utob),_encode=_hasBuffer?e=>Buffer.from(e,"utf8").toString("base64"):_TE?e=>_fromUint8Array(_TE.encode(e)):e=>_btoa(utob(e)),encode$1=(e,t=!1)=>t?_mkUriSafe(_encode(e)):_encode(e),encodeURI=e=>encode$1(e,!0),re_btou=/[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g,cb_btou=e=>{switch(e.length){case 4:var t=((7&e.charCodeAt(0))<<18|(63&e.charCodeAt(1))<<12|(63&e.charCodeAt(2))<<6|63&e.charCodeAt(3))-65536;return _fromCC(55296+(t>>>10))+_fromCC(56320+(1023&t));case 3:return _fromCC((15&e.charCodeAt(0))<<12|(63&e.charCodeAt(1))<<6|63&e.charCodeAt(2));default:return _fromCC((31&e.charCodeAt(0))<<6|63&e.charCodeAt(1))}},btou=e=>e.replace(re_btou,cb_btou),atobPolyfill=t=>{if(t=t.replace(/\s+/g,""),!b64re.test(t))throw new TypeError("malformed base64.");t+="==".slice(2-(3&t.length));let r,o="",n,a;for(let e=0;e<t.length;)r=b64tab[t.charAt(e++)]<<18|b64tab[t.charAt(e++)]<<12|(n=b64tab[t.charAt(e++)])<<6|(a=b64tab[t.charAt(e++)]),o+=64===n?_fromCC(r>>16&255):64===a?_fromCC(r>>16&255,r>>8&255):_fromCC(r>>16&255,r>>8&255,255&r);return o},_atob="function"==typeof atob?e=>atob(_tidyB64(e)):_hasBuffer?e=>Buffer.from(e,"base64").toString("binary"):atobPolyfill,_toUint8Array=_hasBuffer?e=>_U8Afrom(Buffer.from(e,"base64")):e=>_U8Afrom(_atob(e).split("").map(e=>e.charCodeAt(0))),toUint8Array=e=>_toUint8Array(_unURI(e)),_decode=_hasBuffer?e=>Buffer.from(e,"base64").toString("utf8"):_TD?e=>_TD.decode(_toUint8Array(e)):e=>btou(_atob(e)),_unURI=e=>_tidyB64(e.replace(/[-_]/g,e=>"-"==e?"+":"/")),decode=e=>_decode(_unURI(e)),isValid=e=>"string"==typeof e&&(e=e.replace(/\s+/g,"").replace(/={0,2}$/,""),!/[^\s0-9a-zA-Z\+/]/.test(e)||!/[^\s0-9a-zA-Z\-_]/.test(e)),_noEnum=e=>({value:e,enumerable:!1,writable:!0,configurable:!0}),extendString=function(){var e=(e,t)=>Object.defineProperty(String.prototype,e,_noEnum(t));e("fromBase64",function(){return decode(this)}),e("toBase64",function(e){return encode$1(this,e)}),e("toBase64URI",function(){return encode$1(this,!0)}),e("toBase64URL",function(){return encode$1(this,!0)}),e("toUint8Array",function(){return toUint8Array(this)})},extendUint8Array=function(){var e=(e,t)=>Object.defineProperty(Uint8Array.prototype,e,_noEnum(t));e("toBase64",function(e){return fromUint8Array(this,e)}),e("toBase64URI",function(){return fromUint8Array(this,!0)}),e("toBase64URL",function(){return fromUint8Array(this,!0)})},extendBuiltins=()=>{extendString(),extendUint8Array()},gBase64={version:version$1,VERSION:VERSION,atob:_atob,atobPolyfill:atobPolyfill,btoa:_btoa,btoaPolyfill:btoaPolyfill,fromBase64:decode,toBase64:encode$1,encode:encode$1,encodeURI:encodeURI,encodeURL:encodeURI,utob:utob,btou:btou,decode:decode,isValid:isValid,fromUint8Array:fromUint8Array,toUint8Array:toUint8Array,extendString:extendString,extendUint8Array:extendUint8Array,extendBuiltins:extendBuiltins};function encryptFun(e,t){var e=JSON.stringify(e),r=_support.baseInfo.options.encryptMethod;return"lz"===r?lz.compress(e):gBase64.encode(e)}function decryptionFun(e,t){var r=_support.baseInfo.options.encryptMethod;return"lz"===r?lz.decompress(e):gBase64.decode(e)}function sendBeacon(t,r){return new Promise(e=>{navigator.sendBeacon(t,r),e(!0)})}function sendXhr(r,o){return new Promise(e=>{let t=new XMLHttpRequest;t.open("post",r,!0),t.setRequestHeader("Content-Type","application/json"),t.send(o),e(!0),t.onreadystatechange=function(){4===t.readyState&&e(!0)}})}function sendReport(e,n){if(_support.baseInfo.options.isReport){e={appId:_support.baseInfo.options.appId,baseInfo:Object.assign({title:document.title,url:location.href,date:Date.now()},getNavigator()),reportInfo:Object.assign({eventId:e,snapshot:encryptFun(_support.record.snapshot,"snapshot")},n)};let t=_support.baseInfo.options.dsn,r=null!=(n=_support.baseInfo.options.method)?n:"beacon",o=JSON.stringify(e);return new Promise(e=>{switch(r){case"beacon":sendBeacon(t,o).then(()=>{e({type:"xhr",success:!0})});break;case"xhr":sendXhr(t,o).then(()=>{e({type:"xhr",success:!0})});break;default:logger.warn("上报方式不支持:","上报方式只支持 'beacon' 和 'xhr'")}})}}function initPushError(){for(var e in EVENT_TYPES)isKeyValid(e,EVENT_TYPES)&&pushFun(e)}function pushFun(e){if(isKeyValid(e,EVENT_TYPES)){var t=EVENT_TYPES[e];switch(t){case EVENT_TYPES.ERROR:pushError(t);break;case EVENT_TYPES.CONSOLE_ERROR:pushConsole(t);break;case EVENT_TYPES.UNHANDLEDREJECTION:pushUnhandledrejection(t);break;case EVENT_TYPES.XHR:pushXhr(t);break;case EVENT_TYPES.FETCH:pushFetch(t)}}}function pushError(t){eventBus.on(t,e=>{_support.baseInfo.options.isDebug&&logger.error("js逻辑错误:",JSON.stringify(e)),sendReport(t,e)})}function pushConsole(t){eventBus.on(t,e=>{_support.baseInfo.options.isDebug&&logger.info("console错误:",JSON.stringify(e)),sendReport(t,e)})}function pushUnhandledrejection(t){eventBus.on(t,e=>{_support.baseInfo.options.isDebug&&logger.error("Promise错误:",JSON.stringify(e)),sendReport(t,e)})}function pushXhr(t){"XMLHttpRequest"in _global&&eventBus.on(t,e=>{_support.baseInfo.options.isDebug&&logger.error("xhr接口错误:",JSON.stringify(e)),sendReport(t,e)})}function pushFetch(t){"fetch"in _global&&eventBus.on(t,e=>{_support.baseInfo.options.isDebug&&logger.error("fetch接口错误:",JSON.stringify(e)),sendReport(t,e)})}let lastEvent;function getErrorEle(){return lastEvent}function formatStack(e,t=1){return(e||"").split("\n").slice(t).map(e=>e.replace(/^\s+at\s+/g,"")).join("~~")}function getErrorStackLine(e){var t={errorMessage:"",time:Date.now(),colno:0,lineno:0,stackMessage:"",fileName:""};try{var r,o,n,a,s=/http[s]?:\/\/[^:]+(:\d+)?\/([^:]+):(\d+):(\d+)/,i=formatStack(e.stack).split("~~")[1];return i?(r=i.match(s))?(o=r[2],n=parseInt(r[3],10),a=parseInt(r[4],10),{errorMessage:e.message,time:Date.now(),colno:a,lineno:n,stackMessage:formatStack(e.stack),fileName:o}):t:t}catch(e){return t}}function getErrorElInfo(e){var t,e=e||getErrorEle();let r={};return r=e?{pointerId:e.pointerId,pointerType:e.pointerType,timeStamp:e.timeStamp,type:e.type,layerX:e.x,layerY:e.y,nodeName:null!=(t=e.nodeName)?t:e.target.nodeName,nodeType:null!=(t=e.nodeType)?t:e.target.nodeType,textContent:null!=(t=e.textContent)?t:e.target.textContent,className:null!=(t=e.className)?t:e.target.className,elId:null!=(t=e.id)?t:e.target.id}:r}function getError(e){var t=getErrorStackLine(e);let r;return r=t.stackMessage?t:{errorMessage:e.error?e.error.message:"",stackMessage:formatStack(null==(t=e.error)?void 0:t.stack),lineno:e.lineno,colno:e.colno,fileName:e.filename,time:Date.now()},Object.assign(Object.assign({bubbles:e.bubbles,eventType:e.type,isTrusted:e.isTrusted},r),{time:Date.now(),timeStamp:Math.round(e.timeStamp),el:getErrorElInfo()})}function getPromiseError(e){let t,r,o=0,n=0,a="";var s,i=e.reason;return"string"==typeof i?t=i:"object"==typeof i&&(t=i.message,i.stack&&(s=i.stack.match(/at\s+(.+):(\d+):(\d+)/),r=s[1],n=s[2],o=s[3]),a=formatStack(i.stack)),Object.assign(Object.assign({},getError(e)),{errorMessage:t,stackMessage:a,fileName:r,lineno:Number(n),colno:Number(o)})}function getXhrError(e,t){return Object.assign(Object.assign({},getError(e)),{questOptions:t})}function getFetchError(e,t={}){return Object.assign({questOptions:e,el:getErrorElInfo()},t)}function initReWrite(){for(var e in EVENT_TYPES)isKeyValid(e,EVENT_TYPES)&&reWriteFun(e)}function reWriteFun(e){if(isKeyValid(e,EVENT_TYPES)){var t=EVENT_TYPES[e];switch(t){case EVENT_TYPES.ERROR:listenError(t);break;case EVENT_TYPES.CONSOLE_ERROR:listenConsole(t);break;case EVENT_TYPES.UNHANDLEDREJECTION:listenUnhandledrejection(t);break;case EVENT_TYPES.XHR:listenXhr(t);break;case EVENT_TYPES.FETCH:listenFetch(t)}}}function listenError(t){_support.baseInfo.options.isError&&on$1(_global,t,e=>eventBus.emit(t,Object.assign({errorType:ERROR_TYPES.JS},getError(e))),!0)}function listenConsole(o){if(_support.baseInfo.options.isConsoleError){let r=console.error;console.error=function(...e){var t=e.map(e=>"string"==typeof e?e:JSON.stringify(e)).join(" "),t=new Error(t);eventBus.emit(o,Object.assign({errorType:ERROR_TYPES.CONSOLE_ERROR},getErrorStackLine(t))),r.apply(console,e)}}}function listenUnhandledrejection(t){_support.baseInfo.options.isError&&on$1(_global,t,e=>eventBus.emit(t,Object.assign({errorType:ERROR_TYPES.PROMISE},getPromiseError(e))))}function listenXhr(s){if(_support.baseInfo.options.isXhr&&"XMLHttpRequest"in _global){let n={},a=XMLHttpRequest.prototype.send,r=XMLHttpRequest.prototype.open;XMLHttpRequest.prototype.open=function(e,t){return n.method=e,n.url=t,r.call(this,e,t,!0)},XMLHttpRequest.prototype.send=function(e){var t;["get","delete"].includes(n.method.toLowerCase())&&n.url&&-1!==n.url.indexOf("?")&&(t=null==(t=n.url)?void 0:t.substring(n.url.indexOf("?")+1),n.params=getParams(t));let r=()=>({method:n.method.toLowerCase(),url:n.url||"",status:this.status,params:"string"==typeof(e||n.params)?e||n.params:JSON.stringify(e||n.params),message:this.statusText}),o={errorType:ERROR_TYPES.XHR};return this.addEventListener("readystatechange",e=>{4===this.readyState&&(this.status<200||300<=this.status)&&eventBus.emit(s,Object.assign(Object.assign({},o),getXhrError(e,r())))}),this.addEventListener("error",e=>{eventBus.emit(s,Object.assign(Object.assign({},o),getXhrError(e,r())))},!1),this.addEventListener("abort",e=>{eventBus.emit(s,Object.assign(Object.assign({},o),getXhrError(e,r())))},!1),a.call(this,e)}}}function listenFetch(s){if(_support.baseInfo.options.isXhr&&"fetch"in _global){let o=_global.fetch,n={},a={errorType:ERROR_TYPES.FETCH};_global.fetch=function(e,t={}){var{method:r="GET"}=t||{method:"GET"},r=(n.method=r.toLowerCase(),n.url=e.toString(),["get","delete"].includes(n.method.toLowerCase())&&n.url&&(r=null==(r=n.url)?void 0:r.substring(n.url.indexOf("?")+1),n.params=getParams(r)),["post","put"].includes(n.method.toLowerCase())&&(n.params=JSON.stringify(t.body||{})),o(e,t));return r.then(t=>{(t.status<200||300<=t.status)&&t.text().then(()=>{var e={method:n.method.toLowerCase(),url:n.url||"",status:t.status,params:n.params||{},message:t.statusText};eventBus.emit(s,Object.assign(Object.assign({},a),getFetchError(e)))})},e=>{var t={method:n.method.toLowerCase(),url:n.url||"",status:500,params:n.params||{},message:"请求失败"};eventBus.emit(s,Object.assign(Object.assign({},a),getFetchError(t,getErrorStackLine(e))))}),r}}}["click","touchstart","mousedown","keydown","mouseover"].forEach(e=>{document.addEventListener(e,e=>{lastEvent=e},{capture:!0,passive:!0})});var NodeType,name="@log-reporting/core",version="1.0.8",description="前端日志上报SDK",homepage="https://github.com/wangxiaoze-view/log-repeorting#readme",main$1="./dist/index.cjs",module$1="./dist/index.mjs",types="./dist/types/index.d.ts",unpkg="./dist/index.iife.min.js",jsdelivr="./dist/index.iife.min.js",sideEffects=!1,exports={".":{import:"./dist/index.mjs",require:"./dist/index.cjs",types:"./dist/index.d.ts"}},files=["dist","*.d.ts"],license="MIT",repository={type:"git",url:"git+https://github.com/wangxiaoze-view/log-repeorting.git",directory:"packages/core"},author="王小泽 <wangze@anbangke.com>",keywords=["log","log-repeorting","rollup","rrweb","typescript","埋点","日志","采集"],publishConfig={registry:"https://registry.npmjs.org/"},bugs={url:"https://github.com/wangxiaoze-view/log-repeorting/issues"},dependencies={"@types/crypto-js":"^4.2.2","js-base64":"^3.7.7","lz-string":"^1.5.0",rrweb:"^2.0.0-alpha.4"},devDependencies={"@rrweb/types":"2.0.0-alpha.17"},pck={name:name,version:version,description:description,homepage:homepage,main:main$1,module:module$1,types:types,unpkg:unpkg,jsdelivr:jsdelivr,sideEffects:sideEffects,exports:exports,files:files,license:license,repository:repository,author:author,keywords:keywords,publishConfig:publishConfig,bugs:bugs,dependencies:dependencies,devDependencies:devDependencies};class PerformanceClass{constructor(e){this.data=e}}let performance;function initPerformanceOptions(e){var t;null!=(t=null==(t=_support.baseInfo)?void 0:t.options)&&t.isPerformance&&(performance=new PerformanceClass(e),_support.performance=performance)}class Reource{constructor(e){this.data=e}}let reource;function initReourceOptions(e){var t;null!=(t=null==(t=_support.baseInfo)?void 0:t.options)&&t.isResource&&(reource=new Reource(e),_support.reource=reource)}function initPerformance(){var e=new PerformanceObserver(()=>{}),e=(e.observe({type:"navigation",buffered:!0}),e.observe({type:"resource",buffered:!0}),e.takeRecords()),t=e.find(e=>"navigation"===e.entryType),t=(t&&initPerformanceOptions(getNavigation(t)),e.filter(e=>"resource"===e.entryType));initReourceOptions(t)}function isElement(e){return e.nodeType===e.ELEMENT_NODE}function isShadowRoot(e){var t=null==e?void 0:e.host;return Boolean((null==t?void 0:t.shadowRoot)===e)}function isNativeShadowDom(e){return"[object ShadowRoot]"===Object.prototype.toString.call(e)}function fixBrowserCompatibilityIssuesInCSS(e){return e=e.includes(" background-clip: text;")&&!e.includes(" -webkit-background-clip: text;")?e.replace(" background-clip: text;"," -webkit-background-clip: text; background-clip: text;"):e}function getCssRulesString(e){try{var t=e.rules||e.cssRules;return t?fixBrowserCompatibilityIssuesInCSS(Array.from(t).map(getCssRuleString).join("")):null}catch(e){return null}}function getCssRuleString(e){var t=e.cssText;if(isCSSImportRule(e))try{t=getCssRulesString(e.styleSheet)||t}catch(e){}return t}function isCSSImportRule(e){return"styleSheet"in e}(e=>{e[e.Document=0]="Document",e[e.DocumentType=1]="DocumentType",e[e.Element=2]="Element",e[e.Text=3]="Text",e[e.CDATA=4]="CDATA",e[e.Comment=5]="Comment"})(NodeType=NodeType||{});var Mirror=(()=>{function e(){this.idNodeMap=new Map,this.nodeMetaMap=new WeakMap}return e.prototype.getId=function(e){return e&&null!=(e=null==(e=this.getMeta(e))?void 0:e.id)?e:-1},e.prototype.getNode=function(e){return this.idNodeMap.get(e)||null},e.prototype.getIds=function(){return Array.from(this.idNodeMap.keys())},e.prototype.getMeta=function(e){return this.nodeMetaMap.get(e)||null},e.prototype.removeNodeFromMap=function(e){var t=this,r=this.getId(e);this.idNodeMap.delete(r),e.childNodes&&e.childNodes.forEach(function(e){return t.removeNodeFromMap(e)})},e.prototype.has=function(e){return this.idNodeMap.has(e)},e.prototype.hasNode=function(e){return this.nodeMetaMap.has(e)},e.prototype.add=function(e,t){var r=t.id;this.idNodeMap.set(r,e),this.nodeMetaMap.set(e,t)},e.prototype.replace=function(e,t){var r=this.getNode(e);r&&(r=this.nodeMetaMap.get(r))&&this.nodeMetaMap.set(t,r),this.idNodeMap.set(e,t)},e.prototype.reset=function(){this.idNodeMap=new Map,this.nodeMetaMap=new WeakMap},e})();function createMirror(){return new Mirror}function maskInputValue(e){var t=e.maskInputOptions,r=e.tagName,o=e.type,n=e.maskInputFn,e=e.value||"";return e=t[r.toLowerCase()]||t[o]?n?n(e):"*".repeat(e.length):e}var ORIGINAL_ATTRIBUTE_NAME="__rrweb_original__";function is2DCanvasBlank(e){var t=e.getContext("2d");if(t)for(var r=0;r<e.width;r+=50)for(var o=0;o<e.height;o+=50){var n=t.getImageData,n=ORIGINAL_ATTRIBUTE_NAME in n?n[ORIGINAL_ATTRIBUTE_NAME]:n;if(new Uint32Array(n.call(t,r,o,Math.min(50,e.width-r),Math.min(50,e.height-o)).data.buffer).some(function(e){return 0!==e}))return!1}return!0}var canvasService,canvasCtx,_id=1,tagNameRegex=new RegExp("[^a-z0-9-_:]"),IGNORED_NODE=-2;function genId(){return _id++}function getValidTagName(e){return e instanceof HTMLFormElement?"form":(e=e.tagName.toLowerCase().trim(),tagNameRegex.test(e)?"div":e)}function stringifyStyleSheet(e){return e.cssRules?Array.from(e.cssRules).map(function(e){return e.cssText||""}).join(""):""}function extractOrigin(e){return(-1<e.indexOf("//")?e.split("/").slice(0,3).join("/"):e.split("/")[0]).split("?")[0]}var URL_IN_CSS_REF=/url\((?:(')([^']*)'|(")(.*?)"|([^)]*))\)/gm,RELATIVE_PATH=/^(?!www\.|(?:http|ftp)s?:\/\/|[A-Za-z]:\\|\/\/|#).*/,DATA_URI=/^(data:)([^,]*),(.*)/i;function absoluteToStylesheet(e,d){return(e||"").replace(URL_IN_CSS_REF,function(e,t,r,o,n,a){r=r||n||a,n=t||o||"";if(!r)return e;if(!RELATIVE_PATH.test(r))return"url(".concat(n).concat(r).concat(n,")");if(DATA_URI.test(r))return"url(".concat(n).concat(r).concat(n,")");if("/"===r[0])return"url(".concat(n).concat(extractOrigin(d)+r).concat(n,")");var s=d.split("/"),a=r.split("/");s.pop();for(var i=0,l=a;i<l.length;i++){var c=l[i];"."!==c&&(".."===c?s.pop():s.push(c))}return"url(".concat(n).concat(s.join("/")).concat(n,")")})}var SRCSET_NOT_SPACES=/^[^ \t\n\r\u000c]+/,SRCSET_COMMAS_OR_SPACES=/^[, \t\n\r\u000c]+/;function getAbsoluteSrcsetString(e,t){if(""===t.trim())return t;var r=0;function o(e){var e=e.exec(t.substring(r));return e?(e=e[0],r+=e.length,e):""}for(var n=[];o(SRCSET_COMMAS_OR_SPACES),!(r>=t.length);)if(","===(s=o(SRCSET_NOT_SPACES)).slice(-1))s=absoluteToDoc(e,s.substring(0,s.length-1)),n.push(s);else for(var a="",s=absoluteToDoc(e,s),i=!1;;){var l=t.charAt(r);if(""===l){n.push((s+a).trim());break}if(i)")"===l&&(i=!1);else{if(","===l){r+=1,n.push((s+a).trim());break}"("===l&&(i=!0)}a+=l,r+=1}return n.join(", ")}function absoluteToDoc(e,t){return t&&""!==t.trim()?((e=e.createElement("a")).href=t,e.href):t}function isSVGElement(e){return Boolean("svg"===e.tagName||e.ownerSVGElement)}function getHref(){var e=document.createElement("a");return e.href="",e.href}function transformAttribute(e,t,r,o){return"src"!==r&&("href"!==r||!o||"use"===t&&"#"===o[0])&&!("xlink:href"===r&&o&&"#"!==o[0]||"background"===r&&o&&("table"===t||"td"===t||"th"===t))?"srcset"===r&&o?getAbsoluteSrcsetString(e,o):"style"===r&&o?absoluteToStylesheet(o,getHref()):"object"===t&&"data"===r&&o?absoluteToDoc(e,o):o:absoluteToDoc(e,o)}function _isBlockedElement(e,t,r){if("string"==typeof t){if(e.classList.contains(t))return!0}else for(var o=e.classList.length;o--;){var n=e.classList[o];if(t.test(n))return!0}return!!r&&e.matches(r)}function classMatchesRegex(e,t,r){if(!e)return!1;if(e.nodeType!==e.ELEMENT_NODE)return!!r&&classMatchesRegex(e.parentNode,t,r);for(var o=e.classList.length;o--;){var n=e.classList[o];if(t.test(n))return!0}return!!r&&classMatchesRegex(e.parentNode,t,r)}function needMaskingText(e,t,r){e=e.nodeType===e.ELEMENT_NODE?e:e.parentElement;if(null!==e){if("string"==typeof t){if(e.classList.contains(t))return!0;if(e.closest(".".concat(t)))return!0}else if(classMatchesRegex(e,t,!0))return!0;if(r){if(e.matches(r))return!0;if(e.closest(r))return!0}}return!1}function onceIframeLoaded(e,t,r){var o=e.contentWindow;if(o){var n,a,s=!1;try{a=o.document.readyState}catch(e){return}if("complete"===a)return o.location.href!==(a="about:blank")||e.src===a||""===e.src?(setTimeout(t,0),e.addEventListener("load",t)):void e.addEventListener("load",t);n=setTimeout(function(){s||(t(),s=!0)},r),e.addEventListener("load",function(){clearTimeout(n),s=!0,t()})}}function onceStylesheetLoaded(e,t,r){var o,n,a=!1;try{o=e.sheet}catch(e){return}o||(n=setTimeout(function(){a||(t(),a=!0)},r),e.addEventListener("load",function(){clearTimeout(n),a=!0,t()}))}function serializeNode(e,t){var r=t.doc,o=t.blockClass,n=t.blockSelector,a=t.maskTextClass,s=t.maskTextSelector,i=t.inlineStylesheet,l=t.maskInputOptions,c=void 0===l?{}:l,d=t.maskTextFn,u=t.maskInputFn,l=t.dataURLOptions,p=void 0===l?{}:l,g=t.inlineImages,h=t.recordCanvas,m=t.keepIframeSrcFn,l=t.newlyAddedElement,f=void 0!==l&&l,I=getRootId(r,t.mirror);switch(e.nodeType){case e.DOCUMENT_NODE:return"CSS1Compat"!==e.compatMode?{type:NodeType.Document,childNodes:[],compatMode:e.compatMode}:{type:NodeType.Document,childNodes:[]};case e.DOCUMENT_TYPE_NODE:return{type:NodeType.DocumentType,name:e.name,publicId:e.publicId,systemId:e.systemId,rootId:I};case e.ELEMENT_NODE:return serializeElementNode(e,{doc:r,blockClass:o,blockSelector:n,inlineStylesheet:i,maskInputOptions:c,maskInputFn:u,dataURLOptions:p,inlineImages:g,recordCanvas:h,keepIframeSrcFn:m,newlyAddedElement:f,rootId:I});case e.TEXT_NODE:return serializeTextNode(e,{maskTextClass:a,maskTextSelector:s,maskTextFn:d,rootId:I});case e.CDATA_SECTION_NODE:return{type:NodeType.CDATA,textContent:"",rootId:I};case e.COMMENT_NODE:return{type:NodeType.Comment,textContent:e.textContent||"",rootId:I};default:return!1}}function getRootId(e,t){return!t.hasNode(e)||1===(t=t.getId(e))?void 0:t}function serializeTextNode(t,e){var r,o=e.maskTextClass,n=e.maskTextSelector,a=e.maskTextFn,e=e.rootId,s=t.parentNode&&t.parentNode.tagName,i=t.textContent,l="STYLE"===s||void 0,s="SCRIPT"===s||void 0;if(l&&i){try{t.nextSibling||t.previousSibling||null!=(r=t.parentNode.sheet)&&r.cssRules&&(i=stringifyStyleSheet(t.parentNode.sheet))}catch(e){console.warn("Cannot get CSS styles from text's parentNode. Error: ".concat(e),t)}i=absoluteToStylesheet(i,getHref())}return s&&(i="SCRIPT_PLACEHOLDER"),!l&&!s&&i&&needMaskingText(t,o,n)&&(i=a?a(i):i.replace(/[\S]/g,"*")),{type:NodeType.Text,textContent:i||"",isStyle:l,rootId:e}}function serializeElementNode(t,e){for(var r,o,n,a=e.doc,s=e.inlineStylesheet,i=e.maskInputOptions,i=void 0===i?{}:i,l=e.maskInputFn,c=e.dataURLOptions,d=void 0===c?{}:c,c=e.inlineImages,u=e.recordCanvas,p=e.keepIframeSrcFn,g=e.newlyAddedElement,g=void 0!==g&&g,h=e.rootId,e=_isBlockedElement(t,e.blockClass,e.blockSelector),m=getValidTagName(t),f={},I=t.attributes.length,C=0;C<I;C++){var y=t.attributes[C];f[y.name]=transformAttribute(a,m,y.name,y.value)}return"link"===m&&s&&(n=null,n=(s=Array.from(a.styleSheets).find(function(e){return e.href===t.href}))?getCssRulesString(s):n)&&(delete f.rel,delete f.href,f._cssText=absoluteToStylesheet(n,s.href)),"style"===m&&t.sheet&&!(t.innerText||t.textContent||"").trim().length&&(n=getCssRulesString(t.sheet))&&(f._cssText=absoluteToStylesheet(n,getHref())),"input"!==m&&"textarea"!==m&&"select"!==m||(s=t.value,n=t.checked,"radio"!==f.type&&"checkbox"!==f.type&&"submit"!==f.type&&"button"!==f.type&&s?f.value=maskInputValue({type:f.type,tagName:m,value:s,maskInputOptions:i,maskInputFn:l}):n&&(f.checked=n)),"option"===m&&(t.selected&&!i.select?f.selected=!0:delete f.selected),"canvas"===m&&u&&("2d"===t.__context?is2DCanvasBlank(t)||(f.rr_dataURL=t.toDataURL(d.type,d.quality)):"__context"in t||(s=t.toDataURL(d.type,d.quality),(l=document.createElement("canvas")).width=t.width,l.height=t.height,s!==l.toDataURL(d.type,d.quality)&&(f.rr_dataURL=s))),"img"===m&&c&&(canvasService||(canvasService=a.createElement("canvas"),canvasCtx=canvasService.getContext("2d")),o=(r=t).crossOrigin,r.crossOrigin="anonymous",n=function(){try{canvasService.width=r.naturalWidth,canvasService.height=r.naturalHeight,canvasCtx.drawImage(r,0,0),f.rr_dataURL=canvasService.toDataURL(d.type,d.quality)}catch(e){console.warn("Cannot inline img src=".concat(r.currentSrc,"! Error: ").concat(e))}o?f.crossOrigin=o:r.removeAttribute("crossorigin")},r.complete&&0!==r.naturalWidth?n():r.onload=n),"audio"!==m&&"video"!==m||(f.rr_mediaState=t.paused?"paused":"played",f.rr_mediaCurrentTime=t.currentTime),g||(t.scrollLeft&&(f.rr_scrollLeft=t.scrollLeft),t.scrollTop&&(f.rr_scrollTop=t.scrollTop)),e&&(u=(i=t.getBoundingClientRect()).width,l=i.height,f={class:f.class,rr_width:"".concat(u,"px"),rr_height:"".concat(l,"px")}),"iframe"!==m||p(f.src)||(t.contentDocument||(f.rr_src=f.src),delete f.src),{type:NodeType.Element,tagName:m,attributes:f,childNodes:[],isSVG:isSVGElement(t)||void 0,needBlock:e,rootId:h}}function lowerIfExists(e){return void 0===e?"":e.toLowerCase()}function slimDOMExcluded(e,t){if(t.comment&&e.type===NodeType.Comment)return!0;if(e.type===NodeType.Element){if(t.script&&("script"===e.tagName||"link"===e.tagName&&"preload"===e.attributes.rel&&"script"===e.attributes.as||"link"===e.tagName&&"prefetch"===e.attributes.rel&&"string"==typeof e.attributes.href&&e.attributes.href.endsWith(".js")))return!0;if(t.headFavicon&&("link"===e.tagName&&"shortcut icon"===e.attributes.rel||"meta"===e.tagName&&(lowerIfExists(e.attributes.name).match(/^msapplication-tile(image|color)$/)||"application-name"===lowerIfExists(e.attributes.name)||"icon"===lowerIfExists(e.attributes.rel)||"apple-touch-icon"===lowerIfExists(e.attributes.rel)||"shortcut icon"===lowerIfExists(e.attributes.rel))))return!0;if("meta"===e.tagName){if(t.headMetaDescKeywords&&lowerIfExists(e.attributes.name).match(/^description|keywords$/))return!0;if(t.headMetaSocial&&(lowerIfExists(e.attributes.property).match(/^(og|twitter|fb):/)||lowerIfExists(e.attributes.name).match(/^(og|twitter):/)||"pinterest"===lowerIfExists(e.attributes.name)))return!0;if(t.headMetaRobots&&("robots"===lowerIfExists(e.attributes.name)||"googlebot"===lowerIfExists(e.attributes.name)||"bingbot"===lowerIfExists(e.attributes.name)))return!0;if(t.headMetaHttpEquiv&&void 0!==e.attributes["http-equiv"])return!0;if(t.headMetaAuthorship&&("author"===lowerIfExists(e.attributes.name)||"generator"===lowerIfExists(e.attributes.name)||"framework"===lowerIfExists(e.attributes.name)||"publisher"===lowerIfExists(e.attributes.name)||"progid"===lowerIfExists(e.attributes.name)||lowerIfExists(e.attributes.property).match(/^article:/)||lowerIfExists(e.attributes.property).match(/^product:/)))return!0;if(t.headMetaVerification&&("google-site-verification"===lowerIfExists(e.attributes.name)||"yandex-verification"===lowerIfExists(e.attributes.name)||"csrf-token"===lowerIfExists(e.attributes.name)||"p:domain_verify"===lowerIfExists(e.attributes.name)||"verify-v1"===lowerIfExists(e.attributes.name)||"verification"===lowerIfExists(e.attributes.name)||"shopify-checkout-api-token"===lowerIfExists(e.attributes.name)))return!0}}return!1}function serializeNodeWithId(t,e){var r=e.doc,o=e.mirror,n=e.blockClass,a=e.blockSelector,s=e.maskTextClass,i=e.maskTextSelector,l=e.skipChild,l=void 0!==l&&l,c=e.inlineStylesheet,d=void 0===c||c,c=e.maskInputOptions,u=void 0===c?{}:c,p=e.maskTextFn,g=e.maskInputFn,h=e.slimDOMOptions,c=e.dataURLOptions,m=void 0===c?{}:c,c=e.inlineImages,f=void 0!==c&&c,c=e.recordCanvas,I=void 0!==c&&c,C=e.onSerialize,y=e.onIframeLoad,c=e.iframeLoadTimeout,S=void 0===c?5e3:c,b=e.onStylesheetLoad,c=e.stylesheetLoadTimeout,v=void 0===c?5e3:c,c=e.keepIframeSrcFn,A=void 0===c?function(){return!1}:c,c=e.newlyAddedElement,e=e.preserveWhiteSpace,E=void 0===e||e,e=serializeNode(t,{doc:r,mirror:o,blockClass:n,blockSelector:a,maskTextClass:s,maskTextSelector:i,inlineStylesheet:d,maskInputOptions:u,maskTextFn:p,maskInputFn:g,dataURLOptions:m,inlineImages:f,recordCanvas:I,keepIframeSrcFn:A,newlyAddedElement:void 0!==c&&c});if(!e)return console.warn(t,"not serialized"),null;var c=o.hasNode(t)?o.getId(t):slimDOMExcluded(e,h)||!E&&e.type===NodeType.Text&&!e.isStyle&&!e.textContent.replace(/^\s+|\s+$/gm,"").length?IGNORED_NODE:genId(),w=Object.assign(e,{id:c});if(o.add(t,w),c===IGNORED_NODE)return null;C&&C(t);e=!l;if(w.type===NodeType.Element&&(e=e&&!w.needBlock,delete w.needBlock,c=t.shadowRoot)&&isNativeShadowDom(c)&&(w.isShadowHost=!0),(w.type===NodeType.Document||w.type===NodeType.Element)&&e){h.headWhitespace&&w.type===NodeType.Element&&"head"===w.tagName&&(E=!1);for(var k={doc:r,mirror:o,blockClass:n,blockSelector:a,maskTextClass:s,maskTextSelector:i,skipChild:l,inlineStylesheet:d,maskInputOptions:u,maskTextFn:p,maskInputFn:g,slimDOMOptions:h,dataURLOptions:m,inlineImages:f,recordCanvas:I,preserveWhiteSpace:E,onSerialize:C,onIframeLoad:y,iframeLoadTimeout:S,onStylesheetLoad:b,stylesheetLoadTimeout:v,keepIframeSrcFn:A},T=0,R=Array.from(t.childNodes);T<R.length;T++)(M=serializeNodeWithId(R[T],k))&&w.childNodes.push(M);if(isElement(t)&&t.shadowRoot)for(var M,N=0,_=Array.from(t.shadowRoot.childNodes);N<_.length;N++)(M=serializeNodeWithId(_[N],k))&&(isNativeShadowDom(t.shadowRoot)&&(M.isShadow=!0),w.childNodes.push(M))}return t.parentNode&&isShadowRoot(t.parentNode)&&isNativeShadowDom(t.parentNode)&&(w.isShadow=!0),w.type===NodeType.Element&&"iframe"===w.tagName&&onceIframeLoaded(t,function(){var e=t.contentDocument;e&&y&&(e=serializeNodeWithId(e,{doc:e,mirror:o,blockClass:n,blockSelector:a,maskTextClass:s,maskTextSelector:i,skipChild:!1,inlineStylesheet:d,maskInputOptions:u,maskTextFn:p,maskInputFn:g,slimDOMOptions:h,dataURLOptions:m,inlineImages:f,recordCanvas:I,preserveWhiteSpace:E,onSerialize:C,onIframeLoad:y,iframeLoadTimeout:S,onStylesheetLoad:b,stylesheetLoadTimeout:v,keepIframeSrcFn:A}))&&y(t,e)},S),w.type===NodeType.Element&&"link"===w.tagName&&"stylesheet"===w.attributes.rel&&onceStylesheetLoaded(t,function(){var e;b&&(e=serializeNodeWithId(t,{doc:r,mirror:o,blockClass:n,blockSelector:a,maskTextClass:s,maskTextSelector:i,skipChild:!1,inlineStylesheet:d,maskInputOptions:u,maskTextFn:p,maskInputFn:g,slimDOMOptions:h,dataURLOptions:m,inlineImages:f,recordCanvas:I,preserveWhiteSpace:E,onSerialize:C,onIframeLoad:y,iframeLoadTimeout:S,onStylesheetLoad:b,stylesheetLoadTimeout:v,keepIframeSrcFn:A}))&&b(t,e)},v),w}function snapshot(e,t){var t=t||{},r=t.mirror,r=void 0===r?new Mirror:r,o=t.blockClass,n=t.blockSelector,a=t.maskTextClass,s=t.maskTextSelector,i=t.inlineStylesheet,l=t.inlineImages,c=t.recordCanvas,d=t.maskAllInputs,d=void 0!==d&&d,u=t.slimDOM,u=void 0!==u&&u,p=t.keepIframeSrcFn;return serializeNodeWithId(e,{doc:e,mirror:r,blockClass:void 0===o?"rr-block":o,blockSelector:void 0===n?null:n,maskTextClass:void 0===a?"rr-mask":a,maskTextSelector:void 0===s?null:s,skipChild:!1,inlineStylesheet:void 0===i||i,maskInputOptions:!0===d?{color:!0,date:!0,"datetime-local":!0,email:!0,month:!0,number:!0,range:!0,search:!0,tel:!0,text:!0,time:!0,url:!0,week:!0,textarea:!0,select:!0,password:!0}:!1===d?{password:!0}:d,maskTextFn:t.maskTextFn,maskInputFn:t.maskInputFn,slimDOMOptions:!0===u||"all"===u?{script:!0,comment:!0,headFavicon:!0,headWhitespace:!0,headMetaDescKeywords:"all"===u,headMetaSocial:!0,headMetaRobots:!0,headMetaHttpEquiv:!0,headMetaAuthorship:!0,headMetaVerification:!0}:!1===u?{}:u,dataURLOptions:t.dataURLOptions,inlineImages:void 0!==l&&l,recordCanvas:void 0!==c&&c,preserveWhiteSpace:t.preserveWhiteSpace,onSerialize:t.onSerialize,onIframeLoad:t.onIframeLoad,iframeLoadTimeout:t.iframeLoadTimeout,onStylesheetLoad:t.onStylesheetLoad,stylesheetLoadTimeout:t.stylesheetLoadTimeout,keepIframeSrcFn:void 0===p?function(){return!1}:p,newlyAddedElement:!1})}function on(e,t,r=document){let o={capture:!0,passive:!0};return r.addEventListener(e,t,o),()=>r.removeEventListener(e,t,o)}let DEPARTED_MIRROR_ACCESS_WARNING="Please stop import mirror directly. Instead of that,\r\nnow you can use replayer.getMirror() to access the mirror instance of a replayer,\r\nor you can use record.mirror to access the mirror instance during recording.",_mirror={map:{},getId(){return console.error(DEPARTED_MIRROR_ACCESS_WARNING),-1},getNode(){return console.error(DEPARTED_MIRROR_ACCESS_WARNING),null},removeNodeFromMap(){console.error(DEPARTED_MIRROR_ACCESS_WARNING)},has(){return console.error(DEPARTED_MIRROR_ACCESS_WARNING),!1},reset(){console.error(DEPARTED_MIRROR_ACCESS_WARNING)}};function throttle(n,a,s={}){let i=null,l=0;return function(...e){var t=Date.now(),r=(l||!1!==s.leading||(l=t),a-(t-l));let o=this;r<=0||a<r?(i&&(clearTimeout(i),i=null),l=t,n.apply(o,e)):i||!1===s.trailing||(i=setTimeout(()=>{l=!1===s.leading?0:Date.now(),i=null,n.apply(o,e)},r))}}function hookSetter(e,t,r,o,n=window){let a=n.Object.getOwnPropertyDescriptor(e,t);return n.Object.defineProperty(e,t,o?r:{set(e){setTimeout(()=>{r.set.call(this,e)},0),a&&a.set&&a.set.call(this,e)}}),()=>hookSetter(e,t,a||{},!0)}function patch(t,r,o){try{if(!(r in t))return()=>{};let e=t[r];var n=o(e);return"function"==typeof n&&(n.prototype=n.prototype||{},Object.defineProperties(n,{__rrweb_original__:{enumerable:!1,value:e}})),t[r]=n,()=>{t[r]=e}}catch(e){return()=>{}}}function getWindowHeight(){return window.innerHeight||document.documentElement&&document.documentElement.clientHeight||document.body&&document.body.clientHeight}function getWindowWidth(){return window.innerWidth||document.documentElement&&document.documentElement.clientWidth||document.body&&document.body.clientWidth}function isBlocked(e,t,r,o){if(e){var n=e.nodeType===e.ELEMENT_NODE?e:e.parentElement;if(n){if("string"==typeof t){if(n.classList.contains(t))return!0;if(o&&null!==n.closest("."+t))return!0}else if(classMatchesRegex(n,t,o))return!0;if(r){if(e.matches(r))return!0;if(o&&null!==n.closest(r))return!0}}}return!1}function isSerialized(e,t){return-1!==t.getId(e)}function isIgnored(e,t){return t.getId(e)===IGNORED_NODE}function isAncestorRemoved(e,t){var r;return!isShadowRoot(e)&&(r=t.getId(e),!t.has(r)||(!e.parentNode||e.parentNode.nodeType!==e.DOCUMENT_NODE)&&(!e.parentNode||isAncestorRemoved(e.parentNode,t)))}function isTouchEvent(e){return Boolean(e.changedTouches)}function polyfill(e=window){"NodeList"in e&&!e.NodeList.prototype.forEach&&(e.NodeList.prototype.forEach=Array.prototype.forEach),"DOMTokenList"in e&&!e.DOMTokenList.prototype.forEach&&(e.DOMTokenList.prototype.forEach=Array.prototype.forEach),Node.prototype.contains||(Node.prototype.contains=(...e)=>{let t=e[0];if(!(0 in e))throw new TypeError("1 argument is required");do{if(this===t)return!0}while(t=t&&t.parentNode);return!1})}function isSerializedIframe(e,t){return Boolean("IFRAME"===e.nodeName&&t.getMeta(e))}function isSerializedStylesheet(e,t){return Boolean("LINK"===e.nodeName&&e.nodeType===e.ELEMENT_NODE&&e.getAttribute&&"stylesheet"===e.getAttribute("rel")&&t.getMeta(e))}function hasShadowRoot(e){return Boolean(null==e?void 0:e.shadowRoot)}"undefined"!=typeof window&&window.Proxy&&window.Reflect&&(_mirror=new Proxy(_mirror,{get(e,t,r){return"map"===t&&console.error(DEPARTED_MIRROR_ACCESS_WARNING),Reflect.get(e,t,r)}}));class StyleSheetMirror{constructor(){this.id=1,this.styleIDMap=new WeakMap,this.idStyleMap=new Map}getId(e){return null!=(e=this.styleIDMap.get(e))?e:-1}has(e){return this.styleIDMap.has(e)}add(e,t){if(this.has(e))return this.getId(e);let r;return r=void 0===t?this.id++:t,this.styleIDMap.set(e,r),this.idStyleMap.set(r,e),r}getStyle(e){return this.idStyleMap.get(e)||null}reset(){this.styleIDMap=new WeakMap,this.idStyleMap=new Map,this.id=1}generateId(){return this.id++}}var EventType=(e=>(e[e.DomContentLoaded=0]="DomContentLoaded",e[e.Load=1]="Load",e[e.FullSnapshot=2]="FullSnapshot",e[e.IncrementalSnapshot=3]="IncrementalSnapshot",e[e.Meta=4]="Meta",e[e.Custom=5]="Custom",e[e.Plugin=6]="Plugin",e))(EventType||{}),IncrementalSource=(e=>(e[e.Mutation=0]="Mutation",e[e.MouseMove=1]="MouseMove",e[e.MouseInteraction=2]="MouseInteraction",e[e.Scroll=3]="Scroll",e[e.ViewportResize=4]="ViewportResize",e[e.Input=5]="Input",e[e.TouchMove=6]="TouchMove",e[e.MediaInteraction=7]="MediaInteraction",e[e.StyleSheetRule=8]="StyleSheetRule",e[e.CanvasMutation=9]="CanvasMutation",e[e.Font=10]="Font",e[e.Log=11]="Log",e[e.Drag=12]="Drag",e[e.StyleDeclaration=13]="StyleDeclaration",e[e.Selection=14]="Selection",e[e.AdoptedStyleSheet=15]="AdoptedStyleSheet",e))(IncrementalSource||{}),MouseInteractions=(e=>(e[e.MouseUp=0]="MouseUp",e[e.MouseDown=1]="MouseDown",e[e.Click=2]="Click",e[e.ContextMenu=3]="ContextMenu",e[e.DblClick=4]="DblClick",e[e.Focus=5]="Focus",e[e.Blur=6]="Blur",e[e.TouchStart=7]="TouchStart",e[e.TouchMove_Departed=8]="TouchMove_Departed",e[e.TouchEnd=9]="TouchEnd",e[e.TouchCancel=10]="TouchCancel",e))(MouseInteractions||{}),CanvasContext=(e=>(e[e["2D"]=0]="2D",e[e.WebGL=1]="WebGL",e[e.WebGL2=2]="WebGL2",e))(CanvasContext||{});function isNodeInLinkedList(e){return"__ln"in e}class DoubleLinkedList{constructor(){this.length=0,this.head=null}get(t){if(t>=this.length)throw new Error("Position outside of list range");let r=this.head;for(let e=0;e<t;e++)r=(null==r?void 0:r.next)||null;return r}addNode(e){var t,r={value:e,previous:null,next:null};e.__ln=r,e.previousSibling&&isNodeInLinkedList(e.previousSibling)?(t=e.previousSibling.__ln.next,r.next=t,r.previous=e.previousSibling.__ln,e.previousSibling.__ln.next=r,t&&(t.previous=r)):e.nextSibling&&isNodeInLinkedList(e.nextSibling)&&e.nextSibling.__ln.previous?(t=e.nextSibling.__ln.previous,r.previous=t,r.next=e.nextSibling.__ln,e.nextSibling.__ln.previous=r,t&&(t.next=r)):(this.head&&(this.head.previous=r),r.next=this.head,this.head=r),this.length++}removeNode(e){var t=e.__ln;this.head&&(t.previous?(t.previous.next=t.next,t.next&&(t.next.previous=t.previous)):(this.head=t.next,this.head&&(this.head.previous=null)),e.__ln&&delete e.__ln,this.length--)}}let moveKey=(e,t)=>e+"@"+t;class MutationBuffer{constructor(){this.frozen=!1,this.locked=!1,this.texts=[],this.attributes=[],this.removes=[],this.mapRemoves=[],this.movedMap={},this.addedSet=new Set,this.movedSet=new Set,this.droppedSet=new Set,this.processMutations=e=>{e.forEach(this.processMutation),this.emit()},this.emit=()=>{if(!this.frozen&&!this.locked){let d=[],u=new DoubleLinkedList,p=e=>{let t=e,r=IGNORED_NODE;for(;r===IGNORED_NODE;)t=t&&t.nextSibling,r=t&&this.mirror.getId(t);return r};for(var t,r,o,n,a=t=>{let e,r,o,n,a=null,s=a=(null==(r=null==(e=t.getRootNode)?void 0:e.call(t))?void 0:r.nodeType)===Node.DOCUMENT_FRAGMENT_NODE&&t.getRootNode().host?t.getRootNode().host:a;for(;(null==(n=null==(o=null==s?void 0:s.getRootNode)?void 0:o.call(s))?void 0:n.nodeType)===Node.DOCUMENT_FRAGMENT_NODE&&s.getRootNode().host;)s=s.getRootNode().host;var i,l,c=!(this.doc.contains(t)||s&&this.doc.contains(s));if(t.parentNode&&!c)return c=isShadowRoot(t.parentNode)?this.mirror.getId(a):this.mirror.getId(t.parentNode),i=p(t),-1===c||-1===i?u.addNode(t):void((l=serializeNodeWithId(t,{doc:this.doc,mirror:this.mirror,blockClass:this.blockClass,blockSelector:this.blockSelector,maskTextClass:this.maskTextClass,maskTextSelector:this.maskTextSelector,skipChild:!0,newlyAddedElement:!0,inlineStylesheet:this.inlineStylesheet,maskInputOptions:this.maskInputOptions,maskTextFn:this.maskTextFn,maskInputFn:this.maskInputFn,slimDOMOptions:this.slimDOMOptions,dataURLOptions:this.dataURLOptions,recordCanvas:this.recordCanvas,inlineImages:this.inlineImages,onSerialize:e=>{isSerializedIframe(e,this.mirror)&&this.iframeManager.addIframe(e),isSerializedStylesheet(e,this.mirror)&&this.stylesheetManager.trackLinkElement(e),hasShadowRoot(t)&&this.shadowDomManager.addShadowRoot(t.shadowRoot,this.doc)},onIframeLoad:(e,t)=>{this.iframeManager.attachIframe(e,t),this.shadowDomManager.observeAttachShadow(e)},onStylesheetLoad:(e,t)=>{this.stylesheetManager.attachLinkElement(e,t)}}))&&d.push({parentId:c,nextId:i,node:l}))};this.mapRemoves.length;)this.mirror.removeNodeFromMap(this.mapRemoves.shift());for(t of Array.from(this.movedSet.values()))isParentRemoved(this.removes,t,this.mirror)&&!this.movedSet.has(t.parentNode)||a(t);for(r of Array.from(this.addedSet.values()))!isAncestorInSet(this.droppedSet,r)&&!isParentRemoved(this.removes,r,this.mirror)||isAncestorInSet(this.movedSet,r)?a(r):this.droppedSet.add(r);let e=null;for(;u.length;){let t=null;if(!(t=e&&(o=this.mirror.getId(e.value.parentNode),n=p(e.value),-1!==o)&&-1!==n?e:t))for(let e=u.length-1;0<=e;e--){var s=u.get(e);if(s){var i=this.mirror.getId(s.value.parentNode),l=p(s.value);if(-1!==l){if(-1!==i){t=s;break}l=s.value;if(l.parentNode&&l.parentNode.nodeType===Node.DOCUMENT_FRAGMENT_NODE){i=l.parentNode.host;if(-1!==this.mirror.getId(i)){t=s;break}}}}}if(!t){for(;u.head;)u.removeNode(u.head.value);break}e=t.previous,u.removeNode(t.value),a(t.value)}var c={texts:this.texts.map(e=>({id:this.mirror.getId(e.node),value:e.value})).filter(e=>this.mirror.has(e.id)),attributes:this.attributes.map(e=>({id:this.mirror.getId(e.node),attributes:e.attributes})).filter(e=>this.mirror.has(e.id)),removes:this.removes,adds:d};(c.texts.length||c.attributes.length||c.removes.length||c.adds.length)&&(this.texts=