UNPKG

rrweb

Version:
14 lines (13 loc) 7.44 kB
var rrwebConsoleRecord=function(O){"use strict";var L;(function(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"})(L||(L={}));const g=`Please stop import mirror directly. Instead of that,\r now you can use replayer.getMirror() to access the mirror instance of a replayer,\r or you can use record.mirror to access the mirror instance during recording.`;let E={map:{},getId(){return console.error(g),-1},getNode(){return console.error(g),null},removeNodeFromMap(){console.error(g)},has(){return console.error(g),!1},reset(){console.error(g)}};typeof window<"u"&&window.Proxy&&window.Reflect&&(E=new Proxy(E,{get(e,r,n){return r==="map"&&console.error(g),Reflect.get(e,r,n)}}));function j(e,r,n){try{if(!(r in e))return()=>{};const t=e[r],i=n(t);return typeof i=="function"&&(i.prototype=i.prototype||{},Object.defineProperties(i,{__rrweb_original__:{enumerable:!1,value:t}})),e[r]=i,()=>{e[r]=t}}catch{return()=>{}}}/[1-9][0-9]{12}/.test(Date.now().toString());class N{constructor(r){this.fileName=r.fileName||"",this.functionName=r.functionName||"",this.lineNumber=r.lineNumber,this.columnNumber=r.columnNumber}toString(){const r=this.lineNumber||"",n=this.columnNumber||"";return this.functionName?`${this.functionName} (${this.fileName}:${r}:${n})`:`${this.fileName}:${r}:${n}`}}const C=/(^|@)\S+:\d+/,$=/^\s*at .*(\S+:\d+|\(native\))/m,T=/^(eval@)?(\[native code])?$/,b={parse:function(e){return e?typeof e.stacktrace<"u"||typeof e["opera#sourceloc"]<"u"?this.parseOpera(e):e.stack&&e.stack.match($)?this.parseV8OrIE(e):e.stack?this.parseFFOrSafari(e):(console.warn("[console-record-plugin]: Failed to parse error object:",e),[]):[]},extractLocation:function(e){if(e.indexOf(":")===-1)return[e];const r=/(.+?)(?::(\d+))?(?::(\d+))?$/.exec(e.replace(/[()]/g,""));if(!r)throw new Error(`Cannot parse given url: ${e}`);return[r[1],r[2]||void 0,r[3]||void 0]},parseV8OrIE:function(e){return e.stack.split(` `).filter(function(r){return!!r.match($)},this).map(function(r){r.indexOf("(eval ")>-1&&(r=r.replace(/eval code/g,"eval").replace(/(\(eval at [^()]*)|(\),.*$)/g,""));let n=r.replace(/^\s+/,"").replace(/\(eval code/g,"(");const t=n.match(/ (\((.+):(\d+):(\d+)\)$)/);n=t?n.replace(t[0],""):n;const i=n.split(/\s+/).slice(1),s=this.extractLocation(t?t[1]:i.pop()),a=i.join(" ")||void 0,c=["eval","<anonymous>"].indexOf(s[0])>-1?void 0:s[0];return new N({functionName:a,fileName:c,lineNumber:s[1],columnNumber:s[2]})},this)},parseFFOrSafari:function(e){return e.stack.split(` `).filter(function(r){return!r.match(T)},this).map(function(r){if(r.indexOf(" > eval")>-1&&(r=r.replace(/ line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g,":$1")),r.indexOf("@")===-1&&r.indexOf(":")===-1)return new N({functionName:r});{const n=/((.*".+"[^@]*)?[^@]*)(?:@)/,t=r.match(n),i=t&&t[1]?t[1]:void 0,s=this.extractLocation(r.replace(n,""));return new N({functionName:i,fileName:s[0],lineNumber:s[1],columnNumber:s[2]})}},this)},parseOpera:function(e){return!e.stacktrace||e.message.indexOf(` `)>-1&&e.message.split(` `).length>e.stacktrace.split(` `).length?this.parseOpera9(e):e.stack?this.parseOpera11(e):this.parseOpera10(e)},parseOpera9:function(e){const r=/Line (\d+).*script (?:in )?(\S+)/i,n=e.message.split(` `),t=[];for(let i=2,s=n.length;i<s;i+=2){const a=r.exec(n[i]);a&&t.push(new N({fileName:a[2],lineNumber:parseFloat(a[1])}))}return t},parseOpera10:function(e){const r=/Line (\d+).*script (?:in )?(\S+)(?:: In function (\S+))?$/i,n=e.stacktrace.split(` `),t=[];for(let i=0,s=n.length;i<s;i+=2){const a=r.exec(n[i]);a&&t.push(new N({functionName:a[3]||void 0,fileName:a[2],lineNumber:parseFloat(a[1])}))}return t},parseOpera11:function(e){return e.stack.split(` `).filter(function(r){return!!r.match(C)&&!r.match(/^Error created at/)},this).map(function(r){const n=r.split("@"),t=this.extractLocation(n.pop()),i=(n.shift()||"").replace(/<anonymous function(: (\w+))?>/,"$2").replace(/\([^)]*\)/g,"")||void 0;return new N({functionName:i,fileName:t[0],lineNumber:t[1],columnNumber:t[2]})},this)}};function P(e){if(!e||!e.outerHTML)return"";let r="";for(;e.parentElement;){let n=e.localName;if(!n)break;n=n.toLowerCase();const t=e.parentElement,i=[];if(t.children&&t.children.length>0)for(let s=0;s<t.children.length;s++){const a=t.children[s];a.localName&&a.localName.toLowerCase&&a.localName.toLowerCase()===n&&i.push(a)}i.length>1&&(n+=`:eq(${i.indexOf(e)})`),r=n+(r?">"+r:""),e=t}return r}function w(e){return Object.prototype.toString.call(e)==="[object Object]"}function x(e,r){if(r===0)return!0;const n=Object.keys(e);for(const t of n)if(w(e[t])&&x(e[t],r-1))return!0;return!1}function y(e,r){const n={numOfKeysLimit:50,depthOfLimit:4};Object.assign(n,r);const t=[],i=[];return JSON.stringify(e,function(c,o){if(t.length>0){const p=t.indexOf(this);~p?t.splice(p+1):t.push(this),~p?i.splice(p,1/0,c):i.push(c),~t.indexOf(o)&&(t[0]===o?o="[Circular ~]":o="[Circular ~."+i.slice(0,t.indexOf(o)).join(".")+"]")}else t.push(o);if(o===null)return o;if(o===void 0)return"undefined";if(s(o))return a(o);if(typeof o=="bigint")return o.toString()+"n";if(o instanceof Event){const p={};for(const l in o){const u=o[l];Array.isArray(u)?p[l]=P(u.length?u[0]:null):p[l]=u}return p}else{if(o instanceof Node)return o instanceof HTMLElement?o?o.outerHTML:"":o.nodeName;if(o instanceof Error)return o.stack?o.stack+` End of stack for Error object`:o.name+": "+o.message}return o});function s(c){return!!(w(c)&&Object.keys(c).length>n.numOfKeysLimit||typeof c=="function"||w(c)&&x(c,n.depthOfLimit))}function a(c){let o=c.toString();return n.stringLengthLimit&&o.length>n.stringLengthLimit&&(o=`${o.slice(0,n.stringLengthLimit)}...`),o}}const k={level:["assert","clear","count","countReset","debug","dir","dirxml","error","group","groupCollapsed","groupEnd","info","log","table","time","timeEnd","timeLog","trace","warn"],lengthThreshold:1e3,logger:"console"};function _(e,r,n){const t=n?Object.assign({},k,n):k,i=t.logger;if(!i)return()=>{};let s;typeof i=="string"?s=r[i]:s=i;let a=0,c=!1;const o=[];if(t.level.includes("error")){const l=m=>{const f=m.message,d=m.error,v=b.parse(d).map(A=>A.toString()),h=[y(f,t.stringifyOptions)];e({level:"error",trace:v,payload:h})};r.addEventListener("error",l),o.push(()=>{r.removeEventListener("error",l)});const u=m=>{let f,d;m.reason instanceof Error?(f=m.reason,d=[y(`Uncaught (in promise) ${f.name}: ${f.message}`,t.stringifyOptions)]):(f=new Error,d=[y("Uncaught (in promise)",t.stringifyOptions),y(m.reason,t.stringifyOptions)]);const v=b.parse(f).map(h=>h.toString());e({level:"error",trace:v,payload:d})};r.addEventListener("unhandledrejection",u),o.push(()=>{r.removeEventListener("unhandledrejection",u)})}for(const l of t.level)o.push(p(s,l));return()=>{o.forEach(l=>l())};function p(l,u){return l[u]?j(l,u,m=>(...f)=>{if(m.apply(this,f),!c){c=!0;try{const d=b.parse(new Error).map(h=>h.toString()).splice(1),v=f.map(h=>y(h,t.stringifyOptions));a++,a<t.lengthThreshold?e({level:u,trace:d,payload:v}):a===t.lengthThreshold&&e({level:"warn",trace:[],payload:[y("The number of log records reached the threshold.")]})}catch(d){m("rrweb logger error:",d,...f)}finally{c=!1}}}):()=>{}}}const S="rrweb/console@1",F=e=>({name:S,observer:_,options:e});return O.PLUGIN_NAME=S,O.getRecordConsolePlugin=F,Object.defineProperty(O,"__esModule",{value:!0}),O}({}); //# sourceMappingURL=console-record.min.js.map