js-reporter
Version:
WEB前端监控日志上报JSSDK
1,299 lines (1,246 loc) • 279 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["wpkReporter"] = factory();
else
root["wpkReporter"] = factory();
})(window, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = "./src/index.ts");
/******/ })
/************************************************************************/
/******/ ({
/***/ "./src/index.ts":
/*!**********************!*\
!*** ./src/index.ts ***!
\**********************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var utils_1 = __webpack_require__(/*! ./utils */ "./src/utils/index.ts");
var config1 = {
sdk: {
BID: 'wpkreporter',
CID: 'jssdk',
WID_KEY: '__wpkreporterwid_',
},
env: {
BROWSER: 'browser',
NODEJS: 'nodejs',
WEEX: 'weex',
},
px: {
signKey: 'Uvn#08uefVdwe&c4',
addr: {
cn: 'http://127.0.0.1:7003/track/transformLog',
cn_https: 'https://px.effirst.com/api/v1/jssdk/upload',
intl: 'http://px-intl.ucweb.com/api/v1/jssdk/upload',
intl_https: 'https://px-intl.ucweb.com/api/v1/jssdk/upload',
},
confAddr: {
cn: 'http://px.effirst.com/api/v1/jconfig',
cn_https: 'https://px.effirst.com/api/v1/jconfig',
intl: 'http://px-intl.ucweb.com/api/v1/jconfig',
intl_https: 'https://px-intl.ucweb.com/api/v1/jconfig',
},
},
http: {
methods: {
GET: 'GET',
PUT: 'PUT',
POST: 'POST',
HEAD: 'HEAD',
DELETE: 'DELETE',
OPTIONS: 'OPTIONS',
CONNECT: 'OPTIONS',
TRACE: 'OPTIONS',
PATCH: 'OPTIONS',
},
protocols: {
HTTP: 'http:',
HTTPS: 'https:',
},
},
category: {
JSERR: 1,
API: 2,
JSFSPERF: 3,
RESLOADFAIL: 4,
FLOW: 5,
BKPG: 6,
HARLOG: 7,
},
navConn: {
types: {
BLUETOOTH: 'bluetooth',
CELLULAR: 'cellular',
ETHERNET: 'ethernet',
MIXED: 'mixed',
NONE: 'none',
OTHER: 'other',
UNKNOWN: 'unknown',
WIFI: 'wifi',
WIMAX: 'wimax',
},
effectiveTypes: {
'2G': '2g',
'3G': '3g',
'4G': '4g',
SLOW2G: 'slow-2g',
},
},
};
function wpkReporterEntry() {
var t = utils_1.envCheck();
var r = 'object' == typeof t && t + '' == '[object process]';
var o = 'function' == typeof callNative || 'function' == typeof nativeLog;
return o ? reportNative_5() : r ? reportNode_14() : reportBrowser_17(config1);
}
function reportNative_5(e, n) {
var r = n(1), o = n(13);
e.exports = function (e) {
var t = new r(e);
return t.initialize(o), t;
};
}
function reportNode_14() { }
function reportBrowser_17(config) {
var r = utils_1.core(config);
var o = utils_1.n18(config);
return function (customConfig) {
var t = new r(customConfig);
t.initialize(o);
return t;
};
}
var wpkReporter = wpkReporterEntry();
module.exports = wpkReporter;
/***/ }),
/***/ "./src/plugins/api.ts":
/*!****************************!*\
!*** ./src/plugins/api.ts ***!
\****************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function plugin_api(config) {
var r = config;
var o = r.sdk;
var i = r.http.methods;
var a = r.category;
var s = 2048;
var c = 121e3;
var u = function (e) {
return e >= 200 && e <= 299;
};
var l = function (e) {
return (-1 === e.indexOf('//arms-retcode') &&
-1 === e.indexOf('//wpk-gateway') &&
-1 === e.indexOf('//px.ucweb.com') &&
-1 === e.indexOf('//px.effirst.com') &&
-1 === e.indexOf('//px-intl.ucweb.com'));
};
var f = function (e, t) {
if (e.env === r.env.BROWSER && window) {
var n = e.toolKit.extend({
enable: !0,
sampleRate: 1,
}, t);
n.enable
? (e.logger.info('wpkinterfacePlugin已开启'),
'XMLHttpRequest' in window &&
(function (e, t) {
var n = window.XMLHttpRequest.prototype;
var r = n.open;
n.open = function (e, t) {
this.__reqCtx__ = {
method: e,
url: t || '',
start: Date.now(),
};
var n = [].slice.call(arguments);
r.apply(this, n);
};
var f = n.send;
n.send = function (n) {
var r = this;
function d() {
if (r.__reqCtx__ && 4 === r.readyState)
try {
var f = Date.now(), d = (r.responseURL || r.__reqCtx__.url).split('?'), p = d[0], h = d[1] || '', g = '';
r.__reqCtx__.method.toUpperCase() !== i.GET &&
n &&
(g = JSON.stringify(n));
var w = String(r.response), v = !0, m = {};
'function' == typeof t.errorFilter &&
((v = !!(m = t.errorFilter.call(this, {
url: p,
status: r.status,
response: w,
}))),
e.logger.warn('api errorFilter执行结果:', m)),
w.length > s && (w = '[response content too large]');
var _ = f - r.__reqCtx__.start;
if (v && _ < c && l(p)) {
var y = m.bizCode || r.status;
e.report({
category: a.API,
sampleRate: t.sampleRate,
w_res: p,
w_param: h,
w_body: u(y) || !t.withBody ? '' : g,
w_method: r.__reqCtx__.method,
w_rc: y,
w_rt: _,
w_resp: u(y) || !t.withResp ? '' : m.msg || w,
w_type: 16,
c1: m.traceId,
});
}
}
catch (t) {
e.reportError(t, {
bid: o.BID,
cid: o.CID,
category: a.JSERR,
sampleRate: 1,
});
}
}
if ('onreadystatechange' in r &&
'function' == typeof r.onreadystatechange) {
var p = r.onreadystatechange;
r.onreadystatechange = function () {
var e = [].slice.call(arguments);
d.apply(this, e), p.apply(this, e);
};
}
else
r.onreadystatechange = d;
var h = [].slice.call(arguments);
return f.apply(this, h);
};
})(e, n),
'fetch' in window &&
(function (e, t) {
var n = window.fetch;
window.fetch = function () {
var r = [].slice.call(arguments);
var f = i.GET;
r[1] && r[1].method && (f = r[1].method.toUpperCase());
var d = Date.now();
return n
.apply(this, r)
.then(function (n) {
try {
var p = Date.now(), h = (n.url || r[0]).split('?'), g = h[0], w = h[1] || '', v = '';
f !== i.GET &&
r[1] &&
r[1].body &&
(v = JSON.stringify(r[1].body)),
n
.clone()
.text()
.then(function (r) {
r = r || '';
var o = !0, i = {};
if (('function' == typeof t.errorFilter &&
((o = !!(i = t.errorFilter.call(this, {
url: g,
status: n.status,
response: r,
}))),
e.logger.warn('api errorFilter执行结果:', i)),
(r =
r.length > s
? '[response content too large]'
: r),
o && p - d < c && l(g))) {
var h = i.bizCode || n.status;
e.report({
category: a.API,
sampleRate: t.sampleRate,
w_res: g,
w_param: w,
w_body: u(h) || !t.withBody ? '' : v,
w_method: f,
w_rc: h,
w_rt: p - d,
w_resp: u(h) || !t.withResp ? '' : i.msg || r,
w_type: 16,
c1: i.traceId,
});
}
});
}
catch (t) {
e.reportError(t, {
bid: o.BID,
cid: o.CID,
category: a.JSERR,
sampleRate: 1,
});
}
return n;
})
.catch(function (t) {
throw (e.reportError(t, {
category: a.JSERR,
}),
t);
});
};
})(e, n))
: e.logger.info('wpkinterfacePlugin已关闭');
}
};
f.prototype.pluginId = 'api';
return f;
}
exports.default = plugin_api;
/***/ }),
/***/ "./src/plugins/flow.ts":
/*!*****************************!*\
!*** ./src/plugins/flow.ts ***!
\*****************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var router_1 = __importDefault(__webpack_require__(/*! ./router */ "./src/plugins/router.ts"));
function plugin_flow(config) {
var r = config.env, o = function (e) {
var t;
return ((e
? (t = e.replace(/^#\/?/, '')) && 'string' == typeof t
? t.replace(/^(https?:)?\/\//, '').replace(/\?.*$/, '')
: ''
: '') || '[index]');
}, i = function (e, t) {
if (((t = t || {}), e.env === r.BROWSER && window))
if (e.toolKit.extend({
enable: !0,
}, t).enable) {
e.logger.info('wpkflowPlugin已开启');
var i, a, s = function () {
e.reportFlow();
};
e.toolKit.onListen(window, 'load', s, !0),
e.spa &&
(router_1.default.apply(this, [config]),
(i = function (t) {
o(location.hash) &&
((e._sid = e.toolKit.uuid()), e.reportFlow());
}),
(a = function (t) {
o(t.detail) && ((e._sid = e.toolKit.uuid()), e.reportFlow());
}),
e.toolKit.onListen(window, 'hashchange', i),
e.toolKit.onListen(window, 'historystatechange', a)),
e.toolKit.onListen(window, 'beforeunload', function () {
e.toolKit.offListen(window, 'load');
e.toolKit.offListen(window, 'hashchange');
e.toolKit.offListen(window, 'historystatechange');
s = i = a = null;
});
}
else
e.logger.info('wpkflowPlugin已关闭');
};
i.prototype.pluginId = 'flow';
return i;
}
exports.default = plugin_flow;
/***/ }),
/***/ "./src/plugins/gerror.ts":
/*!*******************************!*\
!*** ./src/plugins/gerror.ts ***!
\*******************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function plugin_gerror(config) {
var r;
var o;
var i = config, a = i.env, s = i.category;
var c = function (e) {
return 'function' == typeof e;
}, u = function (e) {
var t = -1;
switch (e.tagName.toLowerCase()) {
case 'img':
t = 1;
break;
case 'link':
e.rel && 'stylesheet' === e.rel.toLowerCase() && (t = 2);
break;
case 'script':
t = 3;
break;
case 'video':
t = 11;
}
return t;
}, l = {}, f = function (e, t, n, r) {
e.addEventListener
? e.addEventListener(t, n, r || !1)
: ((l['on' + t] = function () {
return n.call(e, window.event);
}),
e.attachEvent('on' + t, l['on' + t]));
}, d = function (e, t) {
var n = e.id ? '#' + e.id : '', r = e.className ? '.' + e.className.split(' ').join('.') : '', o = e.tagName.toLowerCase();
return e.parentNode && e.parentNode.tagName && t - 1 != 0
? d(e.parentNode, t - 1) + ' > ' + o.toLowerCase() + n + r
: o + n + r;
}, p = function (e, t, n, i, a, u) {
if (r)
try {
r.call(this, t, n, i, a, u);
}
catch (u) { }
if ((/^script error\.?$/i.test(t) && (t = 'Script error'),
o.ignoreScriptError && 'Script error' === t))
e.logger.warn('配置了ignoreScriptError,本次异常将不上报');
else if (!c(o.jsErrFilter) || o.jsErrFilter.call(this, event)) {
if (null != u) {
var l = (u.stack || '').split('\n');
l.shift();
var f = {
w_msg: t,
w_file: n || '',
w_line: i || '',
w_col: a || '',
stack: l.join('\n'),
category: s.JSERR,
sampleRate: o.jsErrSampleRate,
};
e.report(f);
}
}
else
e.logger.warn('jserrFilter 返回false,本次日志将不上报, event: ', event);
};
var h = function (e, t) {
var n = window;
n && e.env === a.BROWSER
? (e.logger.info('wpkglobalerrorPlugin已开启'),
!1 !==
(o = e.toolKit.extend({
jsErrSampleRate: 1,
resErrSampleRate: 1,
}, t)).jsErr
? ((r = n.onerror),
(n.onerror = function (t, n, r, o, i) {
p(e, t, n, r, o, i);
}),
f(n, 'unhandledrejection', function (t) {
var n = t.type;
'string' == typeof t.reason
? (n = t.reason)
: 'object' == typeof t.reason &&
t.reason.message &&
(n = t.reason.message),
p(e, n, null, null, null, t.reason);
}))
: e.logger.warn('js异常监控已关闭'),
o.resErr
? f(n, 'error', function (t) {
!(function (e, t) {
if (!t.target.tagName ||
t.message ||
t.filename ||
t.lineno ||
t.colno) {
e.logger.warn('非资源获取问题,跳出处理, event: ', t);
}
else if (!c(o.resErrFilter) ||
o.resErrFilter.call(this, t)) {
var n = t.target.src || t.target.href;
e.report({
category: s.RESLOADFAIL,
sampleRate: o.resErrSampleRate,
msg: n + ' 加载失败',
w_res: n,
w_type: u(t.target),
w_xpath: d(t.target, 5),
});
}
else
e.logger.warn('reserrFilter 返回false,本次日志将不上报, event: ', t);
})(e, t);
}, !0)
: e.logger.warn('资源加载异常监控已关闭'))
: e.logger.warn('全局错误监控插件不支持非浏览器环境');
};
h.prototype.pluginId = 'gerror';
return h;
}
exports.default = plugin_gerror;
/***/ }),
/***/ "./src/plugins/index.ts":
/*!******************************!*\
!*** ./src/plugins/index.ts ***!
\******************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var api_1 = __webpack_require__(/*! ./api */ "./src/plugins/api.ts");
exports.api = api_1.default;
var flow_1 = __webpack_require__(/*! ./flow */ "./src/plugins/flow.ts");
exports.flow = flow_1.default;
var gerror_1 = __webpack_require__(/*! ./gerror */ "./src/plugins/gerror.ts");
exports.gerror = gerror_1.default;
var perf_1 = __webpack_require__(/*! ./perf */ "./src/plugins/perf.ts");
exports.perf = perf_1.default;
var router_1 = __webpack_require__(/*! ./router */ "./src/plugins/router.ts");
exports.router = router_1.default;
var ucparam_1 = __webpack_require__(/*! ./ucparam */ "./src/plugins/ucparam.ts");
exports.ucparam = ucparam_1.default;
/***/ }),
/***/ "./src/plugins/perf.ts":
/*!*****************************!*\
!*** ./src/plugins/perf.ts ***!
\*****************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function plugin_perf(e, t, config) {
var r, o = config.env, i = config.category, a = [
'navigationStart',
'unloadEventStart',
'unloadEventEnd',
'redirectStart',
'redirectEnd',
'fetchStart',
'domainLookupStart',
'domainLookupEnd',
'connectStart',
'secureConnectionStart',
'connectEnd',
'requestStart',
'responseStart',
'responseEnd',
'domLoading',
'domInteractive',
'domContentLoadedEventStart',
'domContentLoadedEventEnd',
'domComplete',
'loadEventStart',
'loadEventEnd',
'msFirstPaint',
], s = ['navigate', 'reload', 'back_forward'], c = function (e) {
var t, n = e[a[5]];
if (1 === e._ver) {
var r;
if (window.chrome && window.chrome.loadTimes)
r = 1e3 * window.chrome.loadTimes().firstPaintTime;
else
r = e.msFirstPaint ? e.msFirstPaint : e[a[13]];
if (!r)
return -1;
t = r >= n ? parseFloat((r - n).toFixed(2)) : -1;
}
else
2 === e._ver && ((t = e[a[13]] - n), (t = parseFloat(t.toFixed(2))));
return t;
}, u = function (e, t) {
var n, r, o, i = {};
for (var s in t)
(o = 0),
(n = e[a[t[s][0]]]),
(r = e[a[t[s][1]]]),
n > 0 && r > 0 && (o = parseFloat((r - n).toFixed(2))),
(i[s] = o);
return i;
}, l = function (e, t) {
var n = window;
if (((r =
n.performance ||
n.webkitPerformance ||
n.msPerformance ||
n.mozPerformance),
e.env === o.BROWSER && r && r.timing)) {
t = t || {};
var a = e.toolKit.extend({
enable: !0,
sampleRate: 1,
}, t);
if (a.enable) {
e.logger.info('wpkperformancePlugin已开启');
var l = r.timing || {}, f = 1;
if ('function' == typeof n.PerformanceNavigationTiming)
try {
var d = r.getEntriesByType('navigation')[0];
d && ((l = d), (f = 2));
}
catch (e) { }
(l._ver = f),
(function (e, t, n, r) {
e.addEventListener
? e.addEventListener(t, n, r || !1)
: e.attachEvent('on' + t, n);
})(window, 'load', function () {
/loaded|complete/.test(document.readyState) &&
setTimeout(function () {
var t = e.toolKit.extend((function (e) {
return u(e, {
w_unload: [1, 2],
w_redirect: [3, 4],
w_appcache: [5, 6],
w_dns: [6, 7],
w_tcp: [8, 10],
w_ssl: [9, 10],
w_ttfb: [11, 12],
w_contentdownload: [12, 13],
w_domparsing: [13, 15],
w_res: [17, 19],
});
})(l), (function (e) {
var t = u(e, {
w_firstbyte: [5, 12],
w_tti: [5, 15],
w_domready: [5, 17],
w_load: [5, 19],
w_total: [5, 20],
});
return (t.w_fpt = c(e)), t;
})(l));
for (var n in t)
if (t[n] < 0 || t[n] > 6e4)
return void e.logger.warn('性能数据异常:', n, t[n]);
var o = e.toolKit.extend(t, (function (e) {
var t, n = r.navigation || {}, o = -1, i = -1, a = -1;
return (1 === e._ver
? (t = s[n.type] || 'other')
: 2 === e._ver &&
((o = e.encodedBodySize),
(i = e.decodedBodySize),
(a = e.transferSize),
(t = e.type)),
{
w_enbdsize: o,
w_debdsize: i,
w_transize: a,
w_navtype: t,
});
})(l), a, {
category: i.JSFSPERF,
});
e.report(o);
});
});
}
else
e.logger.info('wpkperformancePlugin已关闭');
}
else
e.logger.warn('基础性能插件仅支持浏览器环境');
};
l.prototype.pluginId = 'perf';
return l;
}
exports.default = plugin_perf;
/***/ }),
/***/ "./src/plugins/router.ts":
/*!*******************************!*\
!*** ./src/plugins/router.ts ***!
\*******************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function plugin_router(config) {
var n = window.history || {}, r = window.document;
var o = function (e, t) {
var n;
window.CustomEvent
? (n = new CustomEvent(e, {
detail: t,
}))
: ((n = r.createEvent('HTMLEvents')).initEvent(e, !1, !0),
(n.detail = t)),
window.dispatchEvent(n);
}, i = function (e) {
return e && 'string' == typeof e
? e.replace(/^(https?:)?\/\//, '').replace(/\?.*$/, '')
: '';
}, a = function (e) {
var t = n[e];
'function' == typeof t &&
((n[e] = function (e, r, a) {
var s = location.href, c = t.call(n, e, r, a);
if (!a || 'string' != typeof a)
return c;
if (a === s)
return c;
try {
var u = s.split('#'), l = a.split('#'), f = i(u[0]), d = i(l[0]), p = u[1] && u[1].replace(/^\/?(.*)/, '$1'), h = l[1] && l[1].replace(/^\/?(.*)/, '$1');
f !== d
? o('historystatechange', d)
: p !== h && o('historystatechange', h);
}
catch (e) { }
return c;
}),
(n[e].toString = e + '() { [native code] }'));
};
return function () {
a('pushState'), a('replateState');
};
}
exports.default = plugin_router;
/***/ }),
/***/ "./src/plugins/ucparam.ts":
/*!********************************!*\
!*** ./src/plugins/ucparam.ts ***!
\********************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function plugin_ucparam(config) {
var r = config.env;
var o = function (e, t) {
if (((t = t || {}),
-1 !== [r.BROWSER, r.WEEX].indexOf(e.env) &&
t.params &&
'string' == typeof t.params)) {
e.logger.info('wpkucparamPlugin已开启');
for (var n = t.params, o = ['pr', 've', 'os', 'fr', 'nw'], i = 0; i < 5; i++) {
var a = o[i];
-1 === n.indexOf(a) && (n += a);
}
try {
ucapi.biz.ucparams({
params: n,
success: function (t) {
e.uc_param = t || '';
},
});
}
catch (t) {
e.logger.error('get uc_param_str error: ', t), (e.uc_param_str = n);
}
}
};
o.prototype.pluginId = 'ucparam';
return o;
}
exports.default = plugin_ucparam;
/***/ }),
/***/ "./src/utils/core.ts":
/*!***************************!*\
!*** ./src/utils/core.ts ***!
\***************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var utilsTool_1 = __webpack_require__(/*! ./utilsTool */ "./src/utils/utilsTool.ts");
var plugins_1 = __webpack_require__(/*! ../plugins */ "./src/plugins/index.ts");
function core(config) {
var r = utilsTool_1.utilsTool();
var o = config;
var i = o.px;
var a = o.category;
function s(e) {
if (!(this instanceof s)) {
return new s(e);
}
e = e || {};
this._init = !1;
this.toolKit = r(e);
if (e.addr && typeof e.addr == 'object') {
this.toolKit.extend(o.px.addr, e.addr || {});
}
this.logger = this.toolKit.logger;
this.debug = e.debug || !1;
!0 === e.debug &&
this.logger.warn('[wpk] now in debug mode, you can see log details');
this._plugins = e.plugins || [];
this.bid = e.bid;
this.cid = e.cid;
this.uid = e.uid;
this.rel = e.rel;
this.spa = e.spa || !1;
this.delay = !1 !== e.delay;
this.cluster = e.cluster || 'cn';
this.sampleRate = e.sampleRate;
this.ignoreScriptError = !1 !== e.ignoreScriptError;
this.onlyCustom = e.onlyCustom || !1;
this.beforeSend = e.beforeSend || null;
this.checkHidden = !1 !== e.checkHidden;
this._waitingQueue = [];
}
function c(e) {
var t = i.confAddr[e.cluster + (e.isHttps ? '_https' : '')], n = i.signKey;
(e._startTime = Date.now()),
(e._dying = !0),
e.toolKit.dynamicConf(e.bid, e.VERSION, t, n, function (t) {
(e._dying = !1), (e._dyConf = t), e.logger.warn('jconfig come back');
});
}
s.prototype = {
VERSION: '0.6.2',
initialize: function (e) {
(this.env = e.env),
e.root.location &&
-1 !== e.root.location.search.indexOf('wpkReporterDebug=true') &&
(this.debug = !0),
(this.send = e.send),
(this.getWid = e.getWid),
(this.isHttps = e.isHttps),
e.bindUnloadEvent(this);
},
ready: function () {
return this._init;
},
setConfig: function (e) {
return this.toolKit.isObject(e) && this.toolKit.extend(this, e), this;
},
getConfig: function () {
return o;
},
report: function (e) {
if (('string' == typeof e &&
(e = {
category: a.JSERR,
msg: e,
}),
e.sampleRate || (e.sampleRate = 1),
this.toolKit.canReport(e.sampleRate || this.sampleRate))) {
if (this.ready()) {
var t;
if ('function' == typeof this.beforeSend) {
try {
t = this.beforeSend(e);
}
catch (e) {
this.logger.error('exec beforeSend failed for:', e);
}
if (!1 === t)
return void this.logger.warn('beforeSend func return false');
'object' == typeof t && (e = t);
}
var n = this.toolKit.getMetas(), r = e.bid || this.bid || n.wpkBid, o = e.cid || this.cid || n.wpkCid, s = e.rel || this.rel || n.wpkRel;
this.toolKit.isFunction(s) && (s = s());
var u = e.uid || this.uid;
if ((this.toolKit.isFunction(u) && (u = u()),
u || (u = this.getWid()),
this.toolKit.extend(e, {
w_bid: r,
w_cid: o,
w_rel: s,
w_spa: this.spa,
w_tm: this.toolKit.timestamp(),
w_cnt: 1,
uid: u,
type: this.toolKit.categoryToType(e.category),
sdk_ver: this.VERSION,
log_src: 'jssdk',
uc_param: this.uc_param || '',
wid: this.wid,
}),
this._dyConf && Date.now() < this._dyConf.expireAt)) {
var l = void 0 !== this._dyConf[e.type]
? this._dyConf[e.type]
: this._dyConf.all;
if (void 0 !== l && !this.toolKit.canReport(l))
return void this.logger.warn('由于「动态配置」采样率控制,本条日志最终未上报,类型: ', e.type, ' 采样率: ', l);
}
else
!this._dying &&
Date.now() - this._startTime >= 18e5 &&
(this.logger.warn('syncing dynamic config'), c(this));
var f = {
app: r,
cp: 'none',
de: 4,
seq: this.toolKit.generateSeq(),
tm: this.toolKit.timestamp(!0),
ud: e.uid,
ver: e.w_rel,
type: e.type,
sver: e.sdk_ver,
};
f.sign = this.toolKit.computeSign(f, i.signKey);
var d = i.addr[this.cluster + (this.isHttps ? '_https' : '')], p = this.toolKit.objToQueryString(f);
this.toolKit.cutStr(e, ['c1', 'c2', 'c3', 'c4', 'c5'], 128),
this.send(d, p, e);
}
else
this._waitingQueue.push(e),
this.logger.warn('sdk未完成初始化,数据已缓存');
return this;
}
this.logger.warn('由于采样率控制,本条日志最终未上报,采样率: ', e.sampleRate || this.sampleRate);
},
reportFlow: function (e) {
return ((e = e || {}),
this.report(this.toolKit.extend(e || {}, {
category: a.FLOW,
sampleRate: 1,
})),
this);
},
reportError: function (e, t) {
return this.toolKit.isError(e)
? (((t = t || {}).category = a.JSERR),
(t.w_msg = e.toString()),
(t.stack = this.toolKit.parseErrorStack(e)),
(t.w_file = e.filename || ''),
(t.w_line = e.lineno || ''),
(t.w_col = e.colno || ''),
this.report(t),
this)
: this.report(e, t);
},
reportApiError: function (e, t) {
return (e &&
(this.toolKit.isObject(e.queryString) &&
(e.queryString = this.toolKit.objToQueryString(e.queryString)),
this.report(this.toolKit.extend(t || {}, {
msg: e.msg || '',
w_res: e.url,
w_method: e.method,
w_param: e.queryString,
w_body: JSON.stringify(e.body),
w_resp: e.response,
w_rc: e.status,
w_rt: e.spent || '',
c1: e.c1,
c2: e.c2,
c3: e.c3,
c4: e.c4,
c5: e.c5,
}, {
category: a.API,
w_type: 16,
}))),
this);
},
diagnose: function () {
this.ready()
? this.bid
? (this.sampleRate ||
this.logger.warn('没有设置采样率参数sampleRate,将使用默认采样率'),
this.report({
_diagnose: !0,
}))
: this.logger.warn('缺少bid参数,请确认是否已正确设置')
: this.logger.warn('wpkReporter尚未初始化,请确保已调用 install 方法');
},
addPlugin: function (e, t) {
return (this._plugins.push([e, t]),
'function' == typeof e &&
this._init &&
e.apply(this, [this, t, this.getConfig()]),
this);
},
install: function () {
c(this);
var e = plugins_1.flow.apply(this, [this.getConfig()]);
var t = this._plugins.length;
var r = false;
for (var o = 0; o < t; o++) {
var i = this._plugins[o];
var a = i[0];
var s = i[1];
a + '' == e + '' && (r = !0),
a.apply(this, [this, s, this.getConfig()]);
}
return ((this.wid = this.getWid()),
(this._sid = this.toolKit.uuid()),
(this._init = !0),
(0 !== t && r) ||
(this.toolKit.logger.info('没有设置Flow,内置开启'),
this.addPlugin(e)),
this);
},
installAll: function () {
var e = [
[
plugins_1.gerror.apply(this, [this.getConfig()]),
{
resErr: !0,
},
],
[plugins_1.api.apply(this, [this.getConfig()])],
[plugins_1.perf],
[plugins_1.flow.apply(this, [this.getConfig()])],
[
plugins_1.ucparam,
{
params: 'prveosfrnw',
},
],
];
var t = this._plugins.length;
if (0 === t)
this._plugins = e;
else {
var r = [];
var o = e.length;
for (var i = 0; i < o; i++) {
var a = e[i];
for (var s = 0; s < t; s++) {
if (a[0].prototype.pluginId === this._plugins[s][0].prototype.pluginId) {
a = this._plugins[s];
break;
}
}
r.push(a);
}
this._plugins = r;
}
return this.install();
},
uninstall: function () {
return (this._plugins = []), (this._init = !1), this;
},
};
return s;
}
exports.core = core;
/***/ }),
/***/ "./src/utils/envCheck.ts":
/*!*******************************!*\
!*** ./src/utils/envCheck.ts ***!
\*******************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function envCheck() {
var n, r, o = {};
function i() {
throw new Error('setTimeout has not been defined');
}
function a() {
throw new Error('clearTimeout has not been defined');
}
function s(e) {
if (n === setTimeout)
return setTimeout(e, 0);
if ((n === i || !n) && setTimeout)
return (n = setTimeout), setTimeout(e, 0);
try {
return n(e, 0);
}
catch (t) {
try {
return n.call(null, e, 0);
}
catch (t) {
return n.call(this, e, 0);
}
}
}
!(function () {
try {
n = 'function' == typeof setTimeout ? setTimeout : i;
}
catch (e) {
n = i;
}
try {
r = 'function' == typeof clearTimeout ? clearTimeout : a;
}
catch (e) {
r = a;
}
})();
var c, u = [], l = !1, f = -1;
function d() {
l &&
c &&
((l = !1), c.length ? (u = c.concat(u)) : (f = -1), u.length && p());
}
function p() {
if (!l) {
var e = s(d);
l = !0;
for (var t = u.length; t;) {
for (c = u, u = []; ++f < t;)
c && c[f].run();
(f = -1), (t = u.length);
}
(c = null),
(l = !1),
(function (e) {
if (r === clearTimeout)
return clearTimeout(e);
if ((r === a || !r) && clearTimeout)
return (r = clearTimeout), clearTimeout(e);
try {
r(e);
}
catch (t) {
try {
return r.call(null, e);
}
catch (t) {
return r.call(this, e);
}
}
})(e);
}
}
function h(e, t) {
(this.fun = e), (this.array = t);
}
function g() { }
(o.nextTick = function (e) {
var t = new Array(arguments.length - 1);
if (arguments.length > 1)
for (var n = 1; n < arguments.length; n++)
t[n - 1] = arguments[n];
u.push(new h(e, t)), 1 !== u.length || l || s(p);
}),
(h.prototype.run = function () {
this.fun.apply(null, this.array);
}),
(o.title = 'browser'),
(o.browser = !0),
(o.env = {}),
(o.argv = []),
(o.version = ''),
(o.versions = {}),
(o.on = g),
(o.addListener = g),
(o.once = g),
(o.off = g),
(o.removeListener = g),
(o.removeAllListeners = g),
(o.emit = g),
(o.prependListener = g),
(o.prependOnceListener = g),
(o.listeners = function (e) {
return [];
}),
(o.binding = function (e) {
throw new Error('process.binding is not supported');
}),
(o.cwd = function () {
return '/';
}),
(o.chdir = function (e) {
throw new Error('process.chdir is not supported');
}),
(o.umask = function () {
return 0;
});
return o;
}
exports.envCheck = envCheck;
/***/ }),
/***/ "./src/utils/index.ts":
/*!****************************!*\
!*** ./src/utils/index.ts ***!
\****************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(__webpack_require__(/*! ./envCheck */ "./src/utils/envCheck.ts"));
__export(__webpack_require__(/*! ./n18 */ "./src/utils/n18.ts"));
__export(__webpack_require__(/*! ./stringTools */ "./src/utils/stringTools.ts"));
__export(__webpack_require__(/*! ./utilsTool */ "./src/utils/utilsTool.ts"));
__export(__webpack_require__(/*!