spy-client 2.1.14 → 2.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/head/base.d.ts +2 -1
- package/dist/lib/spyHeadInterface.d.ts +8 -0
- package/dist/spy-client-basic.d.ts +14 -0
- package/dist/spy-client-basic.esm.js +6 -2
- package/dist/spy-client-basic.iife.js +6 -2
- package/dist/spy-client-basic.js +6 -2
- package/dist/spy-client-basic.mjs +6 -2
- package/dist/spy-client.esm.js +6 -2
- package/dist/spy-client.iife.js +6 -2
- package/dist/spy-client.js +6 -2
- package/dist/spy-client.mjs +6 -2
- package/dist/spy-head.js +9 -6
- package/dist/spy-head.min.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/head/base.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @file 资源、JS、白屏监控的基础
|
|
3
3
|
* @author kaivean
|
|
4
4
|
*/
|
|
5
|
-
import { SpyHeadConf } from '../lib/spyHeadInterface';
|
|
5
|
+
import { SpyHeadConf, SpyHeadUpdateConf } from '../lib/spyHeadInterface';
|
|
6
6
|
interface SendObj {
|
|
7
7
|
type?: 'perf' | 'except' | 'dist' | 'count';
|
|
8
8
|
group: string;
|
|
@@ -19,6 +19,7 @@ declare const _default: {
|
|
|
19
19
|
observerDestroy(): void;
|
|
20
20
|
entryMap: any;
|
|
21
21
|
init(conf: SpyHeadConf): void;
|
|
22
|
+
update(conf: SpyHeadUpdateConf): void;
|
|
22
23
|
addError(obj: SendObj): void;
|
|
23
24
|
send(obj: SendObj, isSend?: boolean, logServer?: string): void;
|
|
24
25
|
};
|
|
@@ -26,3 +26,11 @@ export interface SpyHeadConf {
|
|
|
26
26
|
resourceError: ErrorConf;
|
|
27
27
|
whiteScreenError: WhiteScreenErrorConf;
|
|
28
28
|
}
|
|
29
|
+
export interface SpyHeadUpdateConf {
|
|
30
|
+
pid?: string;
|
|
31
|
+
lid?: string;
|
|
32
|
+
logServer?: string;
|
|
33
|
+
jsError?: ErrorConf;
|
|
34
|
+
resourceError?: ErrorConf;
|
|
35
|
+
whiteScreenError?: WhiteScreenErrorConf;
|
|
36
|
+
}
|
|
@@ -24,6 +24,10 @@ interface Option {
|
|
|
24
24
|
* 日志服务器,默认是webb服务器,尾部需要加?
|
|
25
25
|
*/
|
|
26
26
|
logServer?: string;
|
|
27
|
+
/**
|
|
28
|
+
* log ID
|
|
29
|
+
*/
|
|
30
|
+
lid?: string;
|
|
27
31
|
}
|
|
28
32
|
interface ErrorInfo {
|
|
29
33
|
/**
|
|
@@ -48,6 +52,10 @@ interface ErrorOption {
|
|
|
48
52
|
* 抽样,默认是 1,取值从[0, 1],该抽样会覆盖实例初始化时的抽样配置
|
|
49
53
|
*/
|
|
50
54
|
sample?: number;
|
|
55
|
+
/**
|
|
56
|
+
* log ID
|
|
57
|
+
*/
|
|
58
|
+
lid?: string;
|
|
51
59
|
/**
|
|
52
60
|
* 业务拓展信息
|
|
53
61
|
*/
|
|
@@ -97,6 +105,12 @@ export default class SpyClient {
|
|
|
97
105
|
[propName: string]: number;
|
|
98
106
|
};
|
|
99
107
|
clearAllMark(): void;
|
|
108
|
+
/**
|
|
109
|
+
* sendPost能以post请求发送,可以承接多个日志项,上报内容size可以提升,但没有前端校验
|
|
110
|
+
* send(data, true) 也能以post请求发送,但是会有严格校验
|
|
111
|
+
* 要求:发送的多条日志必须是同一个pid,同一类型type,同一分组group
|
|
112
|
+
* @param data 日志项或者日志项数组
|
|
113
|
+
*/
|
|
100
114
|
sendPost(data: any): void;
|
|
101
115
|
protected request(url: string, data?: any): void;
|
|
102
116
|
protected fetch(url: string, data: any): void;
|
|
@@ -251,8 +251,12 @@ var SpyClient = /** @class */ (function () {
|
|
|
251
251
|
SpyClient.prototype.clearAllMark = function () {
|
|
252
252
|
this.markCache = {};
|
|
253
253
|
};
|
|
254
|
-
|
|
255
|
-
|
|
254
|
+
/**
|
|
255
|
+
* sendPost能以post请求发送,可以承接多个日志项,上报内容size可以提升,但没有前端校验
|
|
256
|
+
* send(data, true) 也能以post请求发送,但是会有严格校验
|
|
257
|
+
* 要求:发送的多条日志必须是同一个pid,同一类型type,同一分组group
|
|
258
|
+
* @param data 日志项或者日志项数组
|
|
259
|
+
*/
|
|
256
260
|
SpyClient.prototype.sendPost = function (data) {
|
|
257
261
|
var logItems = isArray(data) ? data : [data];
|
|
258
262
|
var first = logItems[0];
|
|
@@ -254,8 +254,12 @@ var SpyClient = (function () {
|
|
|
254
254
|
SpyClient.prototype.clearAllMark = function () {
|
|
255
255
|
this.markCache = {};
|
|
256
256
|
};
|
|
257
|
-
|
|
258
|
-
|
|
257
|
+
/**
|
|
258
|
+
* sendPost能以post请求发送,可以承接多个日志项,上报内容size可以提升,但没有前端校验
|
|
259
|
+
* send(data, true) 也能以post请求发送,但是会有严格校验
|
|
260
|
+
* 要求:发送的多条日志必须是同一个pid,同一类型type,同一分组group
|
|
261
|
+
* @param data 日志项或者日志项数组
|
|
262
|
+
*/
|
|
259
263
|
SpyClient.prototype.sendPost = function (data) {
|
|
260
264
|
var logItems = isArray(data) ? data : [data];
|
|
261
265
|
var first = logItems[0];
|
package/dist/spy-client-basic.js
CHANGED
|
@@ -257,8 +257,12 @@
|
|
|
257
257
|
SpyClient.prototype.clearAllMark = function () {
|
|
258
258
|
this.markCache = {};
|
|
259
259
|
};
|
|
260
|
-
|
|
261
|
-
|
|
260
|
+
/**
|
|
261
|
+
* sendPost能以post请求发送,可以承接多个日志项,上报内容size可以提升,但没有前端校验
|
|
262
|
+
* send(data, true) 也能以post请求发送,但是会有严格校验
|
|
263
|
+
* 要求:发送的多条日志必须是同一个pid,同一类型type,同一分组group
|
|
264
|
+
* @param data 日志项或者日志项数组
|
|
265
|
+
*/
|
|
262
266
|
SpyClient.prototype.sendPost = function (data) {
|
|
263
267
|
var logItems = isArray(data) ? data : [data];
|
|
264
268
|
var first = logItems[0];
|
|
@@ -251,8 +251,12 @@ var SpyClient = /** @class */ (function () {
|
|
|
251
251
|
SpyClient.prototype.clearAllMark = function () {
|
|
252
252
|
this.markCache = {};
|
|
253
253
|
};
|
|
254
|
-
|
|
255
|
-
|
|
254
|
+
/**
|
|
255
|
+
* sendPost能以post请求发送,可以承接多个日志项,上报内容size可以提升,但没有前端校验
|
|
256
|
+
* send(data, true) 也能以post请求发送,但是会有严格校验
|
|
257
|
+
* 要求:发送的多条日志必须是同一个pid,同一类型type,同一分组group
|
|
258
|
+
* @param data 日志项或者日志项数组
|
|
259
|
+
*/
|
|
256
260
|
SpyClient.prototype.sendPost = function (data) {
|
|
257
261
|
var logItems = isArray(data) ? data : [data];
|
|
258
262
|
var first = logItems[0];
|
package/dist/spy-client.esm.js
CHANGED
|
@@ -361,8 +361,12 @@ var SpyClient$1 = /** @class */ (function () {
|
|
|
361
361
|
SpyClient.prototype.clearAllMark = function () {
|
|
362
362
|
this.markCache = {};
|
|
363
363
|
};
|
|
364
|
-
|
|
365
|
-
|
|
364
|
+
/**
|
|
365
|
+
* sendPost能以post请求发送,可以承接多个日志项,上报内容size可以提升,但没有前端校验
|
|
366
|
+
* send(data, true) 也能以post请求发送,但是会有严格校验
|
|
367
|
+
* 要求:发送的多条日志必须是同一个pid,同一类型type,同一分组group
|
|
368
|
+
* @param data 日志项或者日志项数组
|
|
369
|
+
*/
|
|
366
370
|
SpyClient.prototype.sendPost = function (data) {
|
|
367
371
|
var logItems = isArray(data) ? data : [data];
|
|
368
372
|
var first = logItems[0];
|
package/dist/spy-client.iife.js
CHANGED
|
@@ -364,8 +364,12 @@ var SpyClient = (function () {
|
|
|
364
364
|
SpyClient.prototype.clearAllMark = function () {
|
|
365
365
|
this.markCache = {};
|
|
366
366
|
};
|
|
367
|
-
|
|
368
|
-
|
|
367
|
+
/**
|
|
368
|
+
* sendPost能以post请求发送,可以承接多个日志项,上报内容size可以提升,但没有前端校验
|
|
369
|
+
* send(data, true) 也能以post请求发送,但是会有严格校验
|
|
370
|
+
* 要求:发送的多条日志必须是同一个pid,同一类型type,同一分组group
|
|
371
|
+
* @param data 日志项或者日志项数组
|
|
372
|
+
*/
|
|
369
373
|
SpyClient.prototype.sendPost = function (data) {
|
|
370
374
|
var logItems = isArray(data) ? data : [data];
|
|
371
375
|
var first = logItems[0];
|
package/dist/spy-client.js
CHANGED
|
@@ -367,8 +367,12 @@
|
|
|
367
367
|
SpyClient.prototype.clearAllMark = function () {
|
|
368
368
|
this.markCache = {};
|
|
369
369
|
};
|
|
370
|
-
|
|
371
|
-
|
|
370
|
+
/**
|
|
371
|
+
* sendPost能以post请求发送,可以承接多个日志项,上报内容size可以提升,但没有前端校验
|
|
372
|
+
* send(data, true) 也能以post请求发送,但是会有严格校验
|
|
373
|
+
* 要求:发送的多条日志必须是同一个pid,同一类型type,同一分组group
|
|
374
|
+
* @param data 日志项或者日志项数组
|
|
375
|
+
*/
|
|
372
376
|
SpyClient.prototype.sendPost = function (data) {
|
|
373
377
|
var logItems = isArray(data) ? data : [data];
|
|
374
378
|
var first = logItems[0];
|
package/dist/spy-client.mjs
CHANGED
|
@@ -361,8 +361,12 @@ var SpyClient$1 = /** @class */ (function () {
|
|
|
361
361
|
SpyClient.prototype.clearAllMark = function () {
|
|
362
362
|
this.markCache = {};
|
|
363
363
|
};
|
|
364
|
-
|
|
365
|
-
|
|
364
|
+
/**
|
|
365
|
+
* sendPost能以post请求发送,可以承接多个日志项,上报内容size可以提升,但没有前端校验
|
|
366
|
+
* send(data, true) 也能以post请求发送,但是会有严格校验
|
|
367
|
+
* 要求:发送的多条日志必须是同一个pid,同一类型type,同一分组group
|
|
368
|
+
* @param data 日志项或者日志项数组
|
|
369
|
+
*/
|
|
366
370
|
SpyClient.prototype.sendPost = function (data) {
|
|
367
371
|
var logItems = isArray(data) ? data : [data];
|
|
368
372
|
var first = logItems[0];
|
package/dist/spy-head.js
CHANGED
|
@@ -92,6 +92,9 @@
|
|
|
92
92
|
init: function (conf) {
|
|
93
93
|
this.conf = conf;
|
|
94
94
|
},
|
|
95
|
+
update: function (conf) {
|
|
96
|
+
this.conf = Object.assign(this.conf, conf || {});
|
|
97
|
+
},
|
|
95
98
|
addError: function (obj) {
|
|
96
99
|
// 有些错误一下出现很多次,都聚合都一个错误,加上次数
|
|
97
100
|
if (this.winerrors.length > 0) {
|
|
@@ -148,12 +151,12 @@
|
|
|
148
151
|
var info = obj.info;
|
|
149
152
|
var srcElement = event.srcElement;
|
|
150
153
|
// 设备信息
|
|
151
|
-
|
|
152
|
-
info.downlink = dataConnection.downlink; // 网站下载速度 M/s
|
|
153
|
-
info.effectiveType = dataConnection.effectiveType; // 网络类型
|
|
154
|
-
info.rtt = dataConnection.rtt; // 网络往返时间 ms
|
|
155
|
-
info.deviceMemory = navigator.deviceMemory || 0;
|
|
156
|
-
info.hardwareConcurrency = navigator.hardwareConcurrency || 0;
|
|
154
|
+
// const dataConnection = navigator.connection || {};
|
|
155
|
+
// info.downlink = dataConnection.downlink; // 网站下载速度 M/s
|
|
156
|
+
// info.effectiveType = dataConnection.effectiveType; // 网络类型
|
|
157
|
+
// info.rtt = dataConnection.rtt; // 网络往返时间 ms
|
|
158
|
+
// info.deviceMemory = navigator.deviceMemory || 0;
|
|
159
|
+
// info.hardwareConcurrency = navigator.hardwareConcurrency || 0;
|
|
157
160
|
// JS错误
|
|
158
161
|
if (srcElement === window) {
|
|
159
162
|
obj.group = jsError.group;
|
package/dist/spy-head.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
((e,n)=>{"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).__spyHead=n()})(this,function(){function
|
|
1
|
+
((e,n)=>{"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).__spyHead=n()})(this,function(){function y(e){var n,r=(e=>{if(URL&&e)try{var n=new URL(e);if(void 0!==n.host)return{protocol:n.protocol,host:n.host,pathname:n.pathname,ext:""}}catch(e){console.error(e)}})(e),e=(r||((n=document.createElement("a")).href=e,r={protocol:n.protocol,host:n.host||location.host,pathname:n.pathname,ext:""}),r.pathname.split("."));return r.ext=e[e.length-1],r}function n(e){return+e.toFixed(1)}var E={conf:{},winerrors:[],errorDestroy:function(){},observerDestroy:function(){},entryMap:{},init:function(e){this.conf=e},update:function(e){this.conf=Object.assign(this.conf,e||{})},addError:function(e){if(0<this.winerrors.length){var n=this.winerrors[this.winerrors.length-1];if(e.info.msg===n.info.msg)return void(n.info.count+=n.info.count||0)}this.winerrors.length<1e3&&this.winerrors.push(e)},send:function(e,n,r){var t,o=this.conf;e.type=e.type||"except",e.pid=o.pid,e.lid=o.lid,e.ts=Date.now(),this.addError(e),this.interceptor&&this.interceptor(e),!1!==n&&(r=r||o.logServer,n="".concat(r,"?pid=").concat(e.pid,"&lid=").concat(e.lid,"&ts=").concat(e.ts)+"&type=".concat(e.type,"&group=").concat(e.group,"&info=").concat(encodeURIComponent(JSON.stringify(e.info))),e.dim&&(n+="&dim="+encodeURIComponent(JSON.stringify(e.dim))),(t=new Image).src=n,t.onload=t.onerror=function(){t=null})}};function r(e){var h=e.resourceError||{},l=e.jsError||{},m=Math.random()<(l.sample||0),g=Math.random()<(h.sample||0),w=E.winerrors,v=0;function n(e){try{var n=e.target,r={info:{},dim:{},group:""},t=r.info,o=e.srcElement;if(o===window){r.group=l.group;for(var i,s=e.error||e.reason||{},a=(t.msg=e.message||s.message||"",t.file=e.filename,t.ln=e.lineno,t.col=e.colno,t.stack=(s.stack||"").split("\n").slice(0,3).join("\n"),-1!==t.msg.indexOf("MODULE_TIMEOUT")&&(i=t.msg.match(/^.*Hang:(.*); Miss:(.*)/))&&i[2]&&(t.msg="MODULE_TIMEOUT for miss:"+i[2]),[]),c=0;c<w.length;c++){var d=w[c],f=1<d.info.count?"(".concat(d.info.count,")"):"";a.push(f+d.info.msg)}t.hisErrors=a.join("----");var p=!0;!1!==(p=l.handler?l.handler(r):p)&&E.send(r,m)}else{r.group=h.group,r.dim.type=o.tagName.toLowerCase();var u=o.src||o.href||"";-1<u.indexOf("/mwb2.gif?")||(t.msg=u||"unknown load eror",r.dim.host=y(u).host,n&&"IMG"===n.tagName&&(t.xpath=(e=>{if(!e)return{xpath:""};for(var n=[];e&&1===e.nodeType&&e!==e.parentNode;){var r=e.tagName.toLowerCase();if(e.getAttribute("id")?r+="[#"+e.getAttribute("id")+"]":e.classList&&e.classList.length&&(r+="[."+e.classList[e.classList.length-1]+"]"),n.push(r),e===document.body)break;e=e.parentNode}return{xpath:n.join("<")}})(n).xpath),v&&(t.hisErrCount=v),!(p=!0)!==(p=h.handler?h.handler(r):p)&&E.send(r,g),v++)}}catch(e){console.error(e)}}window.addEventListener("error",n,!0),window.addEventListener("unhandledrejection",n,!0),E.errorDestroy=function(){window.removeEventListener("error",n,!0),window.removeEventListener("unhandledrejection",n,!0),E.winerrors=[]}}function t(e){var t=e.whiteScreenError||{},o=t.handler,i=t.selector,s=t.subSelector,e=t.timeout||6e3,a=Math.random()<(t.sample||0);function c(){var e;return!!window.performance&&(e={wait:n((e=window.performance.timing).domainLookupStart-(e.navigationStart||e.fetchStart||e.startTime)),dns:n(e.domainLookupEnd-e.domainLookupStart),connect:n(e.connectEnd-e.connectStart),req:n(e.responseStart-e.requestStart),res:n(e.responseEnd-e.responseStart)},"&wait=".concat(e.wait)+"&dns=".concat(e.dns)+"&connect=".concat(e.connect)+"&requestTime=".concat(e.req)+"&resoneTime=".concat(e.res))}i&&setTimeout(function(){var e,n,r;(r=document.querySelector(i))&&r.querySelector(s)&&!(r.clientHeight<2*window.innerHeight/3)||(r=!0,!((n={group:t.group,info:{msg:"",netTime:c(),hisErrors:(()=>{if(!E.winerrors)return!1;for(var e=E.winerrors,n=[],r=0;r<e.length;r++){var t=(e[r].info.stack||"").split("\n")[0];n.push("(".concat(r,")").concat(t||e[r].info.msg))}return n.join(";;")})(),deviceInfo:(e={},n=navigator.connection||{},e.downlink=n.downlink,e.effectiveType=n.effectiveType,e.rtt=n.rtt,e.deviceMemory=navigator.deviceMemory||0,e.hardwareConcurrency=navigator.hardwareConcurrency||0,e)}}).info.msg="WhiteScren Error")!==(r=o?o(n):r)&&n.info.msg&&E&&E.send(n,a))},e)}return E.init=function(e){if(e.logServer||(e.logServer="https://sp1.baidu.com/5b1ZeDe5KgQFm2e88IuM_a/mwb2.gif"),r(this.conf=e),window.PerformanceObserver){var n=new window.PerformanceObserver(function(e){for(var n=E.entryMap,r=e.getEntries(),t=0;t<r.length;t++){var o=r[t];n[o.entryType]||(n[o.entryType]=[]),n[o.entryType].push(o)}});E.observerDestroy=function(){n.disconnect()};try{n.observe({entryTypes:["longtask","layout-shift","first-input","largest-contentful-paint"]})}catch(e){}}t(e)},window.__spyclientConf&&E.init(window.__spyclientConf),window.__spyHead=window.__spyHead||E,E});
|