var itraceJserrorPlugin=function(){"use strict";function r(e,n){return r=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(r,e){return r.__proto__=e,r},r(e,n)}var e;(e={}).ZH="cn",e.QUARK="quark",e.INTL="intl";var n=function(r){return r[r.JSERR=1]="JSERR",r[r.API=2]="API",r[r.PERF=3]="PERF",r[r.RESERR=4]="RESERR",r[r.PVUV=5]="PVUV",r[r.BKPG=6]="BKPG",r[r.LONGTASK=8]="LONGTASK",r[r.INPD=15]="INPD",r[r.NODERES=16]="NODERES",r[r.PGERROR=17]="PGERROR",r[r.BLOCK=18]="BLOCK",r[r.PERFNEXT=1e3]="PERFNEXT",r[r.MAINDOC=1e5]="MAINDOC",r[r.RESTIMING=100001]="RESTIMING",r}({});!function(r){r.JSERR="jserr",r.API="api",r.PERF="jsfsperf",r.RESERR="resloadfail",r.PVUV="flow",r.BKPG="bkpg",r.CUSTOM="jssdkidx",r.INPD="inputdelay",r.LONGTASK="longtask",r.NODERES="nodres",r.PGERROR="pgerror",r.BLOCK="h5block"}({});var t=function(r){r=r||{},this.id=r.id,this.sampleRate=r.sampleRate,this.forceEnable=r.forceEnable};function o(){for(var r=arguments.length<=0?void 0:arguments[0],e=1,n=arguments.length;e<n;e++){var t=e<0||arguments.length<=e?void 0:arguments[e];for(var o in t)l(t,o)&&(r[o]=t[o])}return r}function i(r,e,n,t,o){void 0===t&&(t=!1),void 0===o&&(o=!1),r.addEventListener?r.addEventListener(e,function i(a){o&&r.removeEventListener(e,i,t),n.call(this,a)},t):r.attachEvent&&r.attachEvent("on"+e,function i(a){o&&r.detachEvent(e,i,t),n.call(this,a)})}function a(){return"undefined"!=typeof window?window:"object"==typeof self&&self instanceof WorkerGlobalScope?self:null}!function(r){r.ZH="cn",r.QUARK="quark",r.INTL="intl"}({}),function(r){r[r.JSERR=1]="JSERR",r[r.API=2]="API",r[r.PERF=3]="PERF",r[r.RESERR=4]="RESERR",r[r.PVUV=5]="PVUV",r[r.BKPG=6]="BKPG",r[r.LONGTASK=8]="LONGTASK",r[r.INPD=15]="INPD",r[r.NODERES=16]="NODERES",r[r.PGERROR=17]="PGERROR",r[r.BLOCK=18]="BLOCK",r[r.PERFNEXT=1e3]="PERFNEXT",r[r.MAINDOC=1e5]="MAINDOC",r[r.RESTIMING=100001]="RESTIMING"}({}),function(r){r.JSERR="jserr",r.API="api",r.PERF="jsfsperf",r.RESERR="resloadfail",r.PVUV="flow",r.BKPG="bkpg",r.CUSTOM="jssdkidx",r.INPD="inputdelay",r.LONGTASK="longtask",r.NODERES="nodres",r.PGERROR="pgerror",r.BLOCK="h5block"}({}),"undefined"!=typeof navigator&&(navigator.userAgent||"").toLowerCase();var l=function(r,e){return Object.prototype.hasOwnProperty.call(r,e)},s=function(e){function t(r){var n;return(n=e.call(this,r)||this).reporter=null,n.pluginVer="2.0.10",n.ignoreScriptError=!1!==r.ignoreScriptError,n}!function(e,n){e.prototype=Object.create(n.prototype),e.prototype.constructor=e,r(e,n)}(t,e);var l=t.prototype;return l.init=function(r){this.reporter=r,this.listenError(),this.listenUnHandleRejection()},l.listenError=function(){var r=this,e=a();null!==e?i(e,"error",function(e){if(function(r){var e=r.target;return!(e&&e.tagName)||r.message||r.filename||r.lineno||r.colno}(e)){var n=e.message||"unknown",t=e.error||{};if("script error."===n.toLowerCase()){if(r.ignoreScriptError)return;n="Script error",t={}}r.reportError(n,e.filename,e.lineno,e.colno,t)}}):this.reporter.print("global this is null ignore jserror plugin")},l.listenUnHandleRejection=function(){var r=this,e=a();null!==e?i(e,"unhandledrejection",function(e){var n=e.type;"string"==typeof e.reason?n=e.reason:e.reason&&"object"==typeof e.reason&&e.reason.message&&(n=e.reason.message),r.reportError(n,null,null,null,e.reason||e.type,{evtType:"unhandledrejection"})}):this.reporter.print("global this is null ignore jserror plugin")},l.reportError=function(r,e,t,i,a,l){if(null!=a){var s=(a.stack||"").split("\n");s.shift();var R={w_msg:r,w_file:e,w_col:i,w_line:t,stack:s.join("\n"),error:a};l&&o(R,l),o(R,{category:n.JSERR,sampleRate:this.sampleRate,pluginVer:this.pluginVer}),this.reporter.report(R)}},t}(t);return s.pluginId="iTraceJSErrorPlugin",s}();
var itraceInterfacePlugin=function(){"use strict";function e(t,r){return e=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},e(t,r)}var t;(t={}).ZH="cn",t.QUARK="quark",t.INTL="intl";var r=function(e){return e[e.JSERR=1]="JSERR",e[e.API=2]="API",e[e.PERF=3]="PERF",e[e.RESERR=4]="RESERR",e[e.PVUV=5]="PVUV",e[e.BKPG=6]="BKPG",e[e.LONGTASK=8]="LONGTASK",e[e.INPD=15]="INPD",e[e.NODERES=16]="NODERES",e[e.PGERROR=17]="PGERROR",e[e.BLOCK=18]="BLOCK",e[e.PERFNEXT=1e3]="PERFNEXT",e[e.MAINDOC=1e5]="MAINDOC",e[e.RESTIMING=100001]="RESTIMING",e}({});!function(e){e.JSERR="jserr",e.API="api",e.PERF="jsfsperf",e.RESERR="resloadfail",e.PVUV="flow",e.BKPG="bkpg",e.CUSTOM="jssdkidx",e.INPD="inputdelay",e.LONGTASK="longtask",e.NODERES="nodres",e.PGERROR="pgerror",e.BLOCK="h5block"}({});var n=function(e){e=e||{},this.id=e.id,this.sampleRate=e.sampleRate,this.forceEnable=e.forceEnable};function o(){for(var e=arguments.length<=0?void 0:arguments[0],t=1,r=arguments.length;t<r;t++){var n=t<0||arguments.length<=t?void 0:arguments[t];for(var o in n)a(n,o)&&(e[o]=n[o])}return e}function s(e,t){for(var r,n=e.length,o=0;o<n;o++)r=e[o],t.call(this,r,o,e)}!function(e){e.ZH="cn",e.QUARK="quark",e.INTL="intl"}({}),function(e){e[e.JSERR=1]="JSERR",e[e.API=2]="API",e[e.PERF=3]="PERF",e[e.RESERR=4]="RESERR",e[e.PVUV=5]="PVUV",e[e.BKPG=6]="BKPG",e[e.LONGTASK=8]="LONGTASK",e[e.INPD=15]="INPD",e[e.NODERES=16]="NODERES",e[e.PGERROR=17]="PGERROR",e[e.BLOCK=18]="BLOCK",e[e.PERFNEXT=1e3]="PERFNEXT",e[e.MAINDOC=1e5]="MAINDOC",e[e.RESTIMING=100001]="RESTIMING"}({}),function(e){e.JSERR="jserr",e.API="api",e.PERF="jsfsperf",e.RESERR="resloadfail",e.PVUV="flow",e.BKPG="bkpg",e.CUSTOM="jssdkidx",e.INPD="inputdelay",e.LONGTASK="longtask",e.NODERES="nodres",e.PGERROR="pgerror",e.BLOCK="h5block"}({}),"undefined"!=typeof navigator&&(navigator.userAgent||"").toLowerCase();var a=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)};function i(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return p(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?p(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}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 p(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}var c=/(text)|(json)|(xml)/,d=location.origin,l=function(e){return!e||(0===e.indexOf(d)||!/^(\/\/|http:|https:).*/.test(e))},u=function(t){function n(e){var r;return(r=t.call(this,e)||this).pluginVer="2.1.13",r.opts=e,r.opts.enableXHR=!1!==e.enableXHR,r.opts.enableFetch=!1!==e.enableFetch,r.opts.enableMtop=!0===e.enableMtop,r.opts.enableTrace=!0===e.enableTrace,r}!function(t,r){t.prototype=Object.create(r.prototype),t.prototype.constructor=t,e(t,r)}(n,t);var a=n.prototype;return a.init=function(e){this.reporter=e,this.opts.enableXHR&&this.hookXHR(),this.opts.enableFetch&&this.hookFetch(),this.opts.enableMtop&&this.hookMtop(),this.opts.enableCorsTrace=this.opts.enableCorsTrace||function(){return!1},this.opts.requestHeaders=o(this.opts.requestHeaders||{},{"x-wpk-reqid":function(){return function(e){var t=Date.now();"undefined"!=typeof window&&window.performance&&"function"==typeof window.performance.now&&(t+=performance.now());var r="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var r=(t+16*Math.random())%16|0;return t=Math.floor(t/16),("x"===e?r:11&r).toString(16)});return!1===e?r.replace(/-/g,""):r}(!1)},"x-wpk-bid":function(){return e.bid}})},a.hookXHR=function(){var e=this,t=window.XMLHttpRequest.prototype,r=t.open,n=t.send,o=t.setRequestHeader;t.open=function(t,n){this.__reqCtx__={method:t||"GET",url:n||"",start:Date.now(),headers:{}};var o=[].slice.call(arguments);r.apply(this,o);var a=this;e.opts.enableTrace&&(l(n)||e.opts.enableCorsTrace&&e.opts.enableCorsTrace(n))?(e.reporter.print("shoot the trace rule, setting req header",n),s(Object.getOwnPropertyNames(e.opts.requestHeaders),function(t){var r=e.opts.requestHeaders[t]();a.setRequestHeader(t,r)})):e.reporter.print("not shoot the trace rule, setting req header",n)},t.setRequestHeader=function(e,t){var r=[].slice.call(arguments);o.apply(this,r),this.__reqCtx__&&(this.__reqCtx__.headers||(this.__reqCtx__.headers={}),this.__reqCtx__.headers[e]=t)},t.send=function(t){var r=this;function o(){if(!r.__reqCtx__||4===r.readyState)try{var n=Date.now(),o=(r.responseURL||e.transReqUrl(r.__reqCtx__.url)).split("?"),s=o[0],a=o[1]||"",i=e.opts.withReqBody&&"GET"!==r.__reqCtx__.method.toUpperCase()&&t?JSON.stringify(t):void 0,p=e.opts.withReqHeader&&(r.__reqCtx__.headers||{}),d=e.transferXhrRspHeader(r.getAllResponseHeaders())||{},l=r.getResponseHeader("Content-Type")||"",u=e.opts.withRespBody&&c.test(l)?e._readXhrResponseAsStr(r):void 0,h=n-r.__reqCtx__.start;e.sendData({w_res:s,w_param:a,w_method:r.__reqCtx__.method,w_rc:r.status,w_rt:h,w_body:i,w_resp:u,w_hd:JSON.stringify(p),w_trace_reqid:d&&d["x-wpk-reqid"]||p&&p["x-wpk-reqid"]||void 0,w_rshd:e.opts.withRespHeader?JSON.stringify(d):null,w_trace_serverid:d["x-wpk-serverid"]||void 0,w_type:16,msg:e.isReqSuccess(r.status)?void 0:r.statusText})}catch(t){e.reportPluginError(t)}}if("onreadystatechange"in r&&"function"==typeof r.onreadystatechange){var s=r.onreadystatechange;r.onreadystatechange=function(){var e=[].slice.call(arguments);o.apply(this,e),s.apply(this,e)}}else r.onreadystatechange=o;var a=[].slice.call(arguments);return n.apply(this,a)}},a._readXhrResponseAsStr=function(e){try{if(["text",""].includes(e.responseType))return e.responseText;if("arraybuffer"===e.responseType)return new TextDecoder("utf-8").decode(e.response)}catch(e){this.reporter.print("response as string error",e)}},a.hookFetch=function(){var e=this,t="undefined"!=typeof window?window:"object"==typeof self&&self instanceof WorkerGlobalScope?self:null;if(null!==t){var r=t.fetch;t.fetch=function(n,o){var a,i,p,d,u,h=Date.now(),f=!1;if("string"==typeof n)p=n,i=(null==(u=o)||null==(u=u.method)?void 0:u.toUpperCase())||"GET";else if(n instanceof URL){var R;p=n.toString(),i=(null==(R=o)||null==(R=R.method)?void 0:R.toUpperCase())||"GET"}else{var w;p=n.url||"",i=(null==(w=n.method)?void 0:w.toUpperCase())||"GET",f=!0}e.opts.enableTrace&&(l(p)||e.opts.enableCorsTrace&&e.opts.enableCorsTrace(p))?(e.reporter.print("shoot the trace rule, setting req header",p),f?d=n.headers:(void 0===o?o={headers:new Headers}:void 0===o.headers&&(o.headers=new Headers),d=o.headers),s(Object.getOwnPropertyNames(e.opts.requestHeaders),function(t){"function"==typeof d.set?d.set(t,e.opts.requestHeaders[t]()):d[t]=e.opts.requestHeaders[t]()})):e.reporter.print("not shoot the trace rule, setting req header",p),e.opts.withReqHeader&&!d&&(d=f?n.headers:"object"==typeof o?o.headers:void 0);var y={};try{if(d instanceof Headers)d.forEach(function(e,t){y[t]=e});else if(d&&"object"==typeof d)for(var g=0,_=Object.entries(d);g<_.length;g++){var v=_[g];y[v[0]]=v[1]}}catch(t){e.reporter.print(t),e.reporter.reportJSError(t,{bid:"itrace-next",msg:"fetch api header error"})}var x=e.opts.withReqBody&&null!=(a=o)&&a.body?JSON.stringify(o.body):void 0;return r.call(t,n,o).then(function(t){try{var r=e.transferFetchRespHeaders(t.headers)||{},n=e.buildFetchBaseLog(t.url||p,i,t.status,h,y,x,t.statusText,r),o=(t.headers.get("content-type")||"").toLowerCase();c.test(o)&&e.opts.withRespBody?t.clone().text().then(function(t){n.w_resp=t||"",e.sendData(n)}):e.sendData(n)}catch(t){e.reportPluginError(t)}return t}).catch(function(t){var r=e.buildFetchBaseLog(p,i,-1,h,y,x,t.message,void 0);throw e.sendData(r),t})}}else this.reporter.print("global this is null ignore hook fetch")},a.buildFetchBaseLog=function(e,t,r,n,o,s,a,i){var p=Date.now(),c=this.transReqUrl(e).split("?"),d=c.length>1?c[1]:"",l=c[0],u=this.opts.withReqHeader?o:void 0;return{w_res:l,w_param:d,w_body:s,w_method:t,w_rc:r,w_rt:p-n,w_hd:JSON.stringify(u),w_trace_reqid:i&&i["x-wpk-reqid"]||o&&o["x-wpk-reqid"]||void 0,w_rshd:this.opts.withRespHeader?JSON.stringify(i):void 0,w_trace_serverid:i&&i["x-wpk-serverid"]||void 0,w_type:17,msg:a}},a.transReqUrl=function(e){try{if(e.startsWith("/"))return new URL(e,location.href).href}catch(e){}return e},a.hookMtop=function(){var e,t=this;null!=(e=window)&&null!=(e=e.lib)&&null!=(e=e.mtop)&&e.middlewares&&(this.reporter.print("init mtop middlewares"),window.lib.mtop.middlewares.push(function(e){var r=this.params,n=this.options,o=Date.now();return e().then(function(){try{if(t.opts.enableXHR&&n.H5Request&&(n.getJSON||n.postJSON))return;var e=n.retJson||{},s=Date.now()-o,a=e.code||200,i=r.type,p=r.api,c=function(e){var t=[];for(var r in e)t.push(r+"="+e[r]);return t.join("&")}(n.querystring),d=t.opts.withReqBody&&n.postdata&&n.postdata.data?JSON.stringify(n.postdata.data):null,l=t.opts.withRespBody?JSON.stringify(e.data||{}):void 0,u="",h=e.ret;h instanceof Array&&(h=h.join(",")),-1===h.indexOf("SUCCESS")&&(u=h);var f={w_res:p,w_param:c,w_body:d,w_method:i,w_rc:a,w_rt:s,w_resp:l,w_type:100,msg:u};t.sendData(f)}catch(e){t.reportPluginError(e)}})}))},a.sendData=function(e){var t=e.w_res||"",n=e.w_rt||0;!0!==this.opts.onlyForTrace?this.whiteList(t)&&n<121e3?(o(e,{category:r.API,sampleRate:this.opts.sampleRate,pluginVer:this.pluginVer}),this.reporter.report(e)):this.reporter.print("api addr in black list or rt over limit ignore this log item"):this.reporter.print("in uccore. ignore this interface log item")},a.transferXhrRspHeader=function(e){try{var t=function(e){return e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")}(e||"").split(/[\r\n]+/);if(t.length>0){var r={};return s(t,function(e){var t=e.split(": "),n=t.shift()||"";r[n]=t.join(": ")}),r}}catch(e){}},a.transferFetchRespHeaders=function(e){try{if(!e)return{};for(var t,r={},n=i(e);!(t=n()).done;){var o=t.value;r[o[0]]=o[1]}return r}catch(e){return{}}},a.isReqSuccess=function(e){return e>=200&&e<=299},a.reportPluginError=function(e){},a.whiteList=function(e){return-1===e.indexOf("//arms-retcode")&&-1===e.indexOf("//retcode.taobao.com")&&-1===e.indexOf("aliyuncs.com/r.png")&&-1===e.indexOf("//mdap.alipay.com/loggw")&&-1===e.indexOf("//wpk-gateway")&&-1===e.indexOf("//px.wpk.quark.cn")&&-1===e.indexOf("//px.ucweb.com")&&-1===e.indexOf("//px.effirst.com")&&-1===e.indexOf("//px-intl.ucweb.com")&&-1===e.indexOf("//gm.mmstat.com/arms.1.1")&&-1===e.indexOf("//gm.mmstat.com/arms.1.2")&&-1===e.indexOf("//g.alicdn.com/alilog")&&-1===e.indexOf("//log.m.sm.cn/0.gif")},n}(n);return u.pluginId="iTraceInterfacePlugin",u}();
