use-on-demand
Version:
1 lines • 4.04 kB
JavaScript
;exports.__esModule=true;exports.xX_init_LostErrorSentry=void 0;var LostError_Util=function(){function r(){this._errArr=[]}r.prototype.logLostError=function(){try{console.log("LostError_Util","注册监听成功");this.log_windowOnError();this.log_documentOnError();this.log_windowAddEvent_error();this.log_windowAddEvent_unhandledrejection()}catch(r){this._errArr.push(r)}};r.prototype.test=function(){Promise.reject(1);var r=document.createElement("img");r.src="123.jpg";document.body.appendChild(r);var o=document.createElement("script");o.src="123.jpg";document.body.appendChild(o)};r.prototype.uploadError=function(){console.log("上传错误");this._errArr.forEach(function(r){console.log("错误情况",JSON.stringify(r));window.Sentry.captureException(new Error(JSON.stringify(r)))});this._errArr=[]};r.prototype._handleDocumentOnErrorEvent=function(r,o){var e={type:o,url:r.filename,line:r.lineno,col:r.colno,evtRawStr:JSON.stringify(r)};return e};r.prototype._handleWindowAddEvent=function(r,o){var e,n,t;var i={type:o,url:r.filename,line:r.lineno,col:r.colno,stackMsg:JSON.stringify({error:{message:(e=r.error)===null||e===void 0?void 0:e.message,stack:(n=r.error)===null||n===void 0?void 0:n.stack},message:r.message}),evtRawStr:JSON.stringify(r)};var l=r===null||r===void 0?void 0:r.target;var s=(t=l===null||l===void 0?void 0:l.nodeName)===null||t===void 0?void 0:t.toLowerCase();if(s=="img"||s=="script"){var c=l.src;i.extra=s+" "+(l===null||l===void 0?void 0:l.className)+" "+c+" "+r.type+" "+(l===null||l===void 0?void 0:l.outerHTML)}return i};r.prototype.log_windowOnError=function(){var u=this;var r=function(l,s,c,a,d){setTimeout(function(){var r=a||window.event&&window.event.errorCharacter||0;var o={type:"window-onerror",url:s||"未知",line:c||-1234e-7,col:r,stackMsg:undefined,evtRawStr:JSON.stringify(l)};if(d&&d.stack){o.stackMsg=d.stack.toString()}else if(arguments.callee){var e=[];var n=arguments.callee.caller;var t=3;while(n&&--t>0){e.push(n.toString());if(n===n.caller){break}n=n.caller}var i=e.join(",");o.stackMsg=i}u._errArr.push(o)},0);return false};window.onerror=r};r.prototype.log_documentOnError=function(){var n=this;document.onerror=function(e){setTimeout(function(){console.error("检查此处!!!!!!");console.error("检查此处!!!!!!");console.error("检查此处!!!!!!");console.error("检查此处!!!!!!");console.error("检查此处!!!!!!");console.error("检查此处!!!!!!");var r=e;var o=n._handleDocumentOnErrorEvent(r,"document-onerror");n._errArr.push(o)},0)}};r.prototype.log_windowAddEvent_error=function(){var e=this;window.addEventListener("error",function(o){setTimeout(function(){console.log("错误",o);var r=e._handleWindowAddEvent(o,"window-add-event-error");e._errArr.push(r)},0)},true)};r.prototype.log_windowAddEvent_unhandledrejection=function(){var e=this;window.addEventListener("unhandledrejection",function(o){setTimeout(function(){console.log("错误",o);var r={type:"window-add-event-unhandledrejection",url:"未知",line:-.0141632,col:-.0141632,stackMsg:"栈信息: "+o.reason,evtRawStr:JSON.stringify(o)};e._errArr.push(r)},0)})};r.prototype.log_consoleError=function(){console.error=function(e){return function(r){function o(){}o();e.call(console,r)}}(console.error)};return r}();function xX_init_LostErrorSentry(n){var t=new LostError_Util;t.logLostError();window.$abc_errorLog=t;var i=false;var l=setInterval(function(){var r;if(!i&&window.Sentry){clearInterval(l);t.uploadError()}else{i=true;if(!window.Sentry){var o=document.createElement("script");o.crossOrigin=n.crossOrigin;o.onload=function(r){console.log("备灾脚本","远程脚本","加载成功");window.Sentry.init({dsn:n.dns,environment:n.envName});t.uploadError()};o.src=n.pureJsUrl;var e=document.getElementsByTagName("script")[0];(r=e===null||e===void 0?void 0:e.parentNode)===null||r===void 0?void 0:r.insertBefore(o,e)}else{t.uploadError()}}},1e4)}exports.xX_init_LostErrorSentry=xX_init_LostErrorSentry;