spy-client 2.1.4 → 2.1.7
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 -3
- package/coverage/Chrome 96.0.4664.55 (Mac OS 10.15.7)/html/basicSpec.ts.html +1 -1
- package/coverage/Chrome 96.0.4664.55 (Mac OS 10.15.7)/html/checkSpec.ts.html +1 -1
- package/coverage/Chrome 96.0.4664.55 (Mac OS 10.15.7)/html/headSpec.ts.html +1 -1
- package/coverage/Chrome 96.0.4664.55 (Mac OS 10.15.7)/html/index.html +1 -1
- package/coverage/Chrome 96.0.4664.55 (Mac OS 10.15.7)/html/markSpec.ts.html +1 -1
- package/coverage/Chrome 96.0.4664.55 (Mac OS 10.15.7)/html/metricSpec.ts.html +1 -1
- package/dist/spy-client-basic.d.ts +3 -2
- package/dist/spy-client-basic.esm.js +41 -39
- package/dist/spy-client-basic.iife.js +41 -39
- package/dist/spy-client-basic.iife.min.js +1 -1
- package/dist/spy-client-basic.js +41 -39
- package/dist/spy-client-basic.min.js +1 -1
- package/dist/spy-client-basic.mjs +41 -39
- package/dist/spy-client.esm.js +41 -39
- package/dist/spy-client.iife.js +41 -39
- package/dist/spy-client.iife.min.js +1 -1
- package/dist/spy-client.js +41 -39
- package/dist/spy-client.min.js +1 -1
- package/dist/spy-client.mjs +41 -39
- package/package.json +1 -1
- package/src/spy-client-basic.ts +47 -47
package/README.md
CHANGED
|
@@ -18,13 +18,13 @@ CDN方式
|
|
|
18
18
|
|
|
19
19
|
```html
|
|
20
20
|
<!--增强版SDK-->
|
|
21
|
-
<script src="https://code.bdstatic.com/npm/spy-client@2.1.
|
|
21
|
+
<script src="https://code.bdstatic.com/npm/spy-client@2.1.4/dist/spy-client.min.js" type="text/javascript"></script>
|
|
22
22
|
|
|
23
23
|
<!--增强版SDK spy-head-->
|
|
24
|
-
<script src="https://code.bdstatic.com/npm/spy-client@2.1.
|
|
24
|
+
<script src="https://code.bdstatic.com/npm/spy-client@2.1.4/dist/spy-head.min.js" type="text/javascript"></script>
|
|
25
25
|
|
|
26
26
|
<!--基础版SDK-->
|
|
27
|
-
<script src="https://code.bdstatic.com/npm/spy-client@2.1.
|
|
27
|
+
<script src="https://code.bdstatic.com/npm/spy-client@2.1.4/dist/spy-client-basic.min.js" type="text/javascript"></script>
|
|
28
28
|
|
|
29
29
|
```
|
|
30
30
|
|
|
@@ -724,7 +724,7 @@ describe('基本发送功能', () => {
|
|
|
724
724
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
725
725
|
Code coverage generated by
|
|
726
726
|
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
|
727
|
-
at
|
|
727
|
+
at Mon Dec 06 2021 22:09:47 GMT+0800 (中国标准时间)
|
|
728
728
|
</div>
|
|
729
729
|
</div>
|
|
730
730
|
<script src="prettify.js"></script>
|
|
@@ -463,7 +463,7 @@ describe('问题检测能力', () => {
|
|
|
463
463
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
464
464
|
Code coverage generated by
|
|
465
465
|
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
|
466
|
-
at
|
|
466
|
+
at Mon Dec 06 2021 22:09:47 GMT+0800 (中国标准时间)
|
|
467
467
|
</div>
|
|
468
468
|
</div>
|
|
469
469
|
<script src="prettify.js"></script>
|
|
@@ -679,7 +679,7 @@ describe('spy-head', async () => {
|
|
|
679
679
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
680
680
|
Code coverage generated by
|
|
681
681
|
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
|
682
|
-
at
|
|
682
|
+
at Mon Dec 06 2021 22:09:47 GMT+0800 (中国标准时间)
|
|
683
683
|
</div>
|
|
684
684
|
</div>
|
|
685
685
|
<script src="prettify.js"></script>
|
|
@@ -155,7 +155,7 @@
|
|
|
155
155
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
156
156
|
Code coverage generated by
|
|
157
157
|
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
|
158
|
-
at
|
|
158
|
+
at Mon Dec 06 2021 22:09:47 GMT+0800 (中国标准时间)
|
|
159
159
|
</div>
|
|
160
160
|
</div>
|
|
161
161
|
<script src="prettify.js"></script>
|
|
@@ -268,7 +268,7 @@ describe('mark', async () => {
|
|
|
268
268
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
269
269
|
Code coverage generated by
|
|
270
270
|
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
|
271
|
-
at
|
|
271
|
+
at Mon Dec 06 2021 22:09:47 GMT+0800 (中国标准时间)
|
|
272
272
|
</div>
|
|
273
273
|
</div>
|
|
274
274
|
<script src="prettify.js"></script>
|
|
@@ -961,7 +961,7 @@ describe('metric', async () => {
|
|
|
961
961
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
962
962
|
Code coverage generated by
|
|
963
963
|
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
|
964
|
-
at
|
|
964
|
+
at Mon Dec 06 2021 22:09:47 GMT+0800 (中国标准时间)
|
|
965
965
|
</div>
|
|
966
966
|
</div>
|
|
967
967
|
<script src="prettify.js"></script>
|
|
@@ -61,8 +61,6 @@ export default class SpyClient {
|
|
|
61
61
|
markCache: any;
|
|
62
62
|
option: SpyClientInnerOption;
|
|
63
63
|
constructor(option: SpyClientOption);
|
|
64
|
-
fetch(url: string, data: any): void;
|
|
65
|
-
sendPost(data: any): void;
|
|
66
64
|
handle(logItem: any): any;
|
|
67
65
|
send(data: any, post?: boolean): void;
|
|
68
66
|
check(query: any): boolean;
|
|
@@ -99,5 +97,8 @@ export default class SpyClient {
|
|
|
99
97
|
[propName: string]: number;
|
|
100
98
|
};
|
|
101
99
|
clearAllMark(): void;
|
|
100
|
+
sendPost(data: any): void;
|
|
101
|
+
protected request(url: string, data?: any): void;
|
|
102
|
+
protected fetch(url: string, data: any): void;
|
|
102
103
|
}
|
|
103
104
|
export {};
|
|
@@ -64,35 +64,6 @@ var SpyClient = /** @class */ (function () {
|
|
|
64
64
|
logServer: option.logServer || defaultLogServer,
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
|
-
SpyClient.prototype.fetch = function (url, data) {
|
|
68
|
-
if (!window.fetch) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
fetch(url, {
|
|
72
|
-
method: 'POST',
|
|
73
|
-
credentials: 'include',
|
|
74
|
-
headers: {
|
|
75
|
-
'Content-Type': 'application/json',
|
|
76
|
-
},
|
|
77
|
-
body: JSON.stringify(data),
|
|
78
|
-
});
|
|
79
|
-
};
|
|
80
|
-
SpyClient.prototype.sendPost = function (data) {
|
|
81
|
-
var logItems = isArray(data) ? data : [data];
|
|
82
|
-
var first = logItems[0];
|
|
83
|
-
// 需要在页面暴漏出来pid等基本信息,方式调试查看基本信息与兼容目前的监控
|
|
84
|
-
var query = {
|
|
85
|
-
pid: first.pid,
|
|
86
|
-
type: first.type,
|
|
87
|
-
group: first.group,
|
|
88
|
-
};
|
|
89
|
-
var url = this.option.logServer + stringify(query);
|
|
90
|
-
if (!(!isLtIos14
|
|
91
|
-
&& navigator.sendBeacon
|
|
92
|
-
&& navigator.sendBeacon(url, JSON.stringify(data)))) {
|
|
93
|
-
this.fetch(url, data);
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
67
|
SpyClient.prototype.handle = function (logItem) {
|
|
97
68
|
if (!this.check(logItem)) {
|
|
98
69
|
return;
|
|
@@ -134,16 +105,7 @@ var SpyClient = /** @class */ (function () {
|
|
|
134
105
|
continue;
|
|
135
106
|
}
|
|
136
107
|
var url = this.option.logServer + stringify(logItem);
|
|
137
|
-
|
|
138
|
-
// 但是ios有些问题:在webkit浏览内核环境下,beacon requests的请求方式存在证书验证的bug,发送失败但返回正确.
|
|
139
|
-
// 修复说明在如下链接中:https://bugs.webkit.org/show_bug.cgi?id=193508
|
|
140
|
-
// 但是目前为止,在iOS12.2版本中该问题依旧存在
|
|
141
|
-
// 2021-11-11: 发现ios 14可以送,故小于14的不发送
|
|
142
|
-
if (!(!isLtIos14
|
|
143
|
-
&& navigator.sendBeacon
|
|
144
|
-
&& navigator.sendBeacon(url))) {
|
|
145
|
-
(new Image()).src = url;
|
|
146
|
-
}
|
|
108
|
+
this.request(url);
|
|
147
109
|
}
|
|
148
110
|
if (post) {
|
|
149
111
|
this.sendPost(postData);
|
|
@@ -288,6 +250,46 @@ var SpyClient = /** @class */ (function () {
|
|
|
288
250
|
SpyClient.prototype.clearAllMark = function () {
|
|
289
251
|
this.markCache = {};
|
|
290
252
|
};
|
|
253
|
+
// send(data, true) 也能以post发送,但是会有严格校验
|
|
254
|
+
// sendPost能以post发送,但没有校验
|
|
255
|
+
SpyClient.prototype.sendPost = function (data) {
|
|
256
|
+
var logItems = isArray(data) ? data : [data];
|
|
257
|
+
var first = logItems[0];
|
|
258
|
+
// 需要在页面暴漏出来pid等基本信息,方式调试查看基本信息与兼容目前的监控
|
|
259
|
+
var query = {
|
|
260
|
+
pid: first.pid,
|
|
261
|
+
type: first.type,
|
|
262
|
+
group: first.group,
|
|
263
|
+
};
|
|
264
|
+
var url = this.option.logServer + stringify(query);
|
|
265
|
+
this.request(url, data);
|
|
266
|
+
};
|
|
267
|
+
// 有data时,意味着要用post发送请求
|
|
268
|
+
SpyClient.prototype.request = function (url, data) {
|
|
269
|
+
if (!(!isLtIos14
|
|
270
|
+
&& navigator.sendBeacon
|
|
271
|
+
&& navigator.sendBeacon(url, data ? JSON.stringify(data) : undefined))) {
|
|
272
|
+
if (data) {
|
|
273
|
+
this.fetch(url, data);
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
(new Image()).src = url;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
SpyClient.prototype.fetch = function (url, data) {
|
|
281
|
+
if (!window.fetch) {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
fetch(url, {
|
|
285
|
+
method: 'POST',
|
|
286
|
+
credentials: 'include',
|
|
287
|
+
headers: {
|
|
288
|
+
'Content-Type': 'application/json',
|
|
289
|
+
},
|
|
290
|
+
body: JSON.stringify(data),
|
|
291
|
+
});
|
|
292
|
+
};
|
|
291
293
|
return SpyClient;
|
|
292
294
|
}());
|
|
293
295
|
|
|
@@ -67,35 +67,6 @@ var SpyClient = (function () {
|
|
|
67
67
|
logServer: option.logServer || defaultLogServer,
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
|
-
SpyClient.prototype.fetch = function (url, data) {
|
|
71
|
-
if (!window.fetch) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
fetch(url, {
|
|
75
|
-
method: 'POST',
|
|
76
|
-
credentials: 'include',
|
|
77
|
-
headers: {
|
|
78
|
-
'Content-Type': 'application/json',
|
|
79
|
-
},
|
|
80
|
-
body: JSON.stringify(data),
|
|
81
|
-
});
|
|
82
|
-
};
|
|
83
|
-
SpyClient.prototype.sendPost = function (data) {
|
|
84
|
-
var logItems = isArray(data) ? data : [data];
|
|
85
|
-
var first = logItems[0];
|
|
86
|
-
// 需要在页面暴漏出来pid等基本信息,方式调试查看基本信息与兼容目前的监控
|
|
87
|
-
var query = {
|
|
88
|
-
pid: first.pid,
|
|
89
|
-
type: first.type,
|
|
90
|
-
group: first.group,
|
|
91
|
-
};
|
|
92
|
-
var url = this.option.logServer + stringify(query);
|
|
93
|
-
if (!(!isLtIos14
|
|
94
|
-
&& navigator.sendBeacon
|
|
95
|
-
&& navigator.sendBeacon(url, JSON.stringify(data)))) {
|
|
96
|
-
this.fetch(url, data);
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
70
|
SpyClient.prototype.handle = function (logItem) {
|
|
100
71
|
if (!this.check(logItem)) {
|
|
101
72
|
return;
|
|
@@ -137,16 +108,7 @@ var SpyClient = (function () {
|
|
|
137
108
|
continue;
|
|
138
109
|
}
|
|
139
110
|
var url = this.option.logServer + stringify(logItem);
|
|
140
|
-
|
|
141
|
-
// 但是ios有些问题:在webkit浏览内核环境下,beacon requests的请求方式存在证书验证的bug,发送失败但返回正确.
|
|
142
|
-
// 修复说明在如下链接中:https://bugs.webkit.org/show_bug.cgi?id=193508
|
|
143
|
-
// 但是目前为止,在iOS12.2版本中该问题依旧存在
|
|
144
|
-
// 2021-11-11: 发现ios 14可以送,故小于14的不发送
|
|
145
|
-
if (!(!isLtIos14
|
|
146
|
-
&& navigator.sendBeacon
|
|
147
|
-
&& navigator.sendBeacon(url))) {
|
|
148
|
-
(new Image()).src = url;
|
|
149
|
-
}
|
|
111
|
+
this.request(url);
|
|
150
112
|
}
|
|
151
113
|
if (post) {
|
|
152
114
|
this.sendPost(postData);
|
|
@@ -291,6 +253,46 @@ var SpyClient = (function () {
|
|
|
291
253
|
SpyClient.prototype.clearAllMark = function () {
|
|
292
254
|
this.markCache = {};
|
|
293
255
|
};
|
|
256
|
+
// send(data, true) 也能以post发送,但是会有严格校验
|
|
257
|
+
// sendPost能以post发送,但没有校验
|
|
258
|
+
SpyClient.prototype.sendPost = function (data) {
|
|
259
|
+
var logItems = isArray(data) ? data : [data];
|
|
260
|
+
var first = logItems[0];
|
|
261
|
+
// 需要在页面暴漏出来pid等基本信息,方式调试查看基本信息与兼容目前的监控
|
|
262
|
+
var query = {
|
|
263
|
+
pid: first.pid,
|
|
264
|
+
type: first.type,
|
|
265
|
+
group: first.group,
|
|
266
|
+
};
|
|
267
|
+
var url = this.option.logServer + stringify(query);
|
|
268
|
+
this.request(url, data);
|
|
269
|
+
};
|
|
270
|
+
// 有data时,意味着要用post发送请求
|
|
271
|
+
SpyClient.prototype.request = function (url, data) {
|
|
272
|
+
if (!(!isLtIos14
|
|
273
|
+
&& navigator.sendBeacon
|
|
274
|
+
&& navigator.sendBeacon(url, data ? JSON.stringify(data) : undefined))) {
|
|
275
|
+
if (data) {
|
|
276
|
+
this.fetch(url, data);
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
(new Image()).src = url;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
SpyClient.prototype.fetch = function (url, data) {
|
|
284
|
+
if (!window.fetch) {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
fetch(url, {
|
|
288
|
+
method: 'POST',
|
|
289
|
+
credentials: 'include',
|
|
290
|
+
headers: {
|
|
291
|
+
'Content-Type': 'application/json',
|
|
292
|
+
},
|
|
293
|
+
body: JSON.stringify(data),
|
|
294
|
+
});
|
|
295
|
+
};
|
|
294
296
|
return SpyClient;
|
|
295
297
|
}());
|
|
296
298
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var SpyClient=function(){"use strict";function o(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return(Object.assign||function(t){for(var e=void 0,n=1,o=arguments.length;n<o;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,t)}var t=navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/),
|
|
1
|
+
var SpyClient=function(){"use strict";function o(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return(Object.assign||function(t){for(var e=void 0,n=1,o=arguments.length;n<o;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,t)}var t=navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/),n=t&&t[2]&&+t[2]<14;function u(t){console.error("[SpyClient_log]"+t)}function a(n){return Object.keys(n).map(function(t){var e=n[t];return void 0===e?e="":"string"!=typeof e&&(e=JSON.stringify(e)),encodeURIComponent(t)+"="+encodeURIComponent(e)}).join("&")}function p(t){return"[object Array]"===Object.prototype.toString.call(t)}function e(t){if(this.sample={},this.markCache={},!t.pid)throw new Error("pid is required");this.option={pid:t.pid,lid:t.lid,check:!1!==t.check,sample:t.sample,localCache:t.localCache,logServer:t.logServer||"https://sp1.baidu.com/5b1ZeDe5KgQFm2e88IuM_a/mwb2.gif?"}}return e.prototype.handle=function(t){if(this.check(t)){if(t=o({pid:this.option.pid,lid:this.option.lid,ts:Date.now(),group:"common"},t),this.option.localCache&&this.option.localCache.addLog(t),"number"==typeof t.sample){if(Math.random()>t.sample)return}else if("number"==typeof this.option.sample&&Math.random()>this.option.sample)return;return delete t.sample,t}},e.prototype.send=function(t,e){void 0===e&&(e=!1);for(var n=[],o=0,r=p(t)?t:[t];o<r.length;o++){var i=r[o];if((i=this.handle(i))&&(n.push(i),!e)){var s=this.option.logServer+a(i);this.request(s)}}e&&this.sendPost(n)},e.prototype.check=function(t){if(!this.option.check)return!0;var e=["perf","except","dist","count"];if(-1===e.indexOf(t.type))return u("type only is one of "+e.join(", ")),!1;if(t.group&&30<t.group.length)return u("group length execeeds 30"),!1;var n=/^[a-zA-Z0-9-_]{0,30}$/;if("except"===t.type){if("string"!=typeof t.info.msg||!t.info.msg.length)return u("info.msg field must be not empty and is String"),!1}else for(var o=0,r=Object.keys(t.info);o<r.length;o++){var i=r[o];if(!n.test(i))return u("info."+i+" is unexpected. Length must be not more than 30. Supported chars: a-zA-Z0-9-_"),!1;var s=t.info[i];if("dist"===t.type){if(30<s.length)return u("info."+i+" value length execeeds 30 when type == 'dist'"),!1}else if("number"!=typeof s)return u("info."+i+" value must be number"),!1}if(t.dim)for(var a=0,p=Object.keys(t.dim);a<p.length;a++){var c=p[a];if(!n.test(c))return u("dim key ["+c+"] is unexpected. Length must be not more than 30. Supported chars: a-zA-Z0-9-_"),!1;var h=t.dim[c];if(!/^[a-zA-Z0-9\-_\*\.\s\/#\+@\&\u4e00-\u9fa5]{0,30}$/.test(h))return u("dim."+c+" value ["+h+"] is unexpected. Length must be not more than 30. Supported chars: a-zA-Z0-9-_*. /#+@& and Chinese"),!1}return!0},e.prototype.sendPerf=function(t){this.send(o({type:"perf"},t))},e.prototype.sendExcept=function(t){this.send(o({type:"except"},t))},e.prototype.sendDist=function(t){this.send(o({type:"dist"},t))},e.prototype.sendCount=function(t){this.send(o({type:"count"},t))},e.prototype.sendExceptForError=function(t,e){var n=o({},e);n.info=o({},e.info||{},{msg:t.message,stack:t.stack}),this.sendExcept(n)},e.prototype.startMark=function(t){this.markCache[t]={start:Date.now()}},e.prototype.endMark=function(t){return this.markCache[t]?(this.markCache[t].total=Date.now()-this.markCache[t].start,this.markCache[t].total):0},e.prototype.clearMark=function(t){this.markCache[t]&&delete this.markCache[t]},e.prototype.getAllMark=function(){for(var t={},e=0,n=Object.keys(this.markCache);e<n.length;e++){var o=n[e];t[o]=this.markCache[o].total}return t},e.prototype.clearAllMark=function(){this.markCache={}},e.prototype.sendPost=function(t){var e=(p(t)?t:[t])[0],n={pid:e.pid,type:e.type,group:e.group},o=this.option.logServer+a(n);this.request(o,t)},e.prototype.request=function(t,e){!n&&navigator.sendBeacon&&navigator.sendBeacon(t,e?JSON.stringify(e):void 0)||(e?this.fetch(t,e):(new Image).src=t)},e.prototype.fetch=function(t,e){window.fetch&&fetch(t,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})},e}();
|
package/dist/spy-client-basic.js
CHANGED
|
@@ -70,35 +70,6 @@
|
|
|
70
70
|
logServer: option.logServer || defaultLogServer,
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
|
-
SpyClient.prototype.fetch = function (url, data) {
|
|
74
|
-
if (!window.fetch) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
fetch(url, {
|
|
78
|
-
method: 'POST',
|
|
79
|
-
credentials: 'include',
|
|
80
|
-
headers: {
|
|
81
|
-
'Content-Type': 'application/json',
|
|
82
|
-
},
|
|
83
|
-
body: JSON.stringify(data),
|
|
84
|
-
});
|
|
85
|
-
};
|
|
86
|
-
SpyClient.prototype.sendPost = function (data) {
|
|
87
|
-
var logItems = isArray(data) ? data : [data];
|
|
88
|
-
var first = logItems[0];
|
|
89
|
-
// 需要在页面暴漏出来pid等基本信息,方式调试查看基本信息与兼容目前的监控
|
|
90
|
-
var query = {
|
|
91
|
-
pid: first.pid,
|
|
92
|
-
type: first.type,
|
|
93
|
-
group: first.group,
|
|
94
|
-
};
|
|
95
|
-
var url = this.option.logServer + stringify(query);
|
|
96
|
-
if (!(!isLtIos14
|
|
97
|
-
&& navigator.sendBeacon
|
|
98
|
-
&& navigator.sendBeacon(url, JSON.stringify(data)))) {
|
|
99
|
-
this.fetch(url, data);
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
73
|
SpyClient.prototype.handle = function (logItem) {
|
|
103
74
|
if (!this.check(logItem)) {
|
|
104
75
|
return;
|
|
@@ -140,16 +111,7 @@
|
|
|
140
111
|
continue;
|
|
141
112
|
}
|
|
142
113
|
var url = this.option.logServer + stringify(logItem);
|
|
143
|
-
|
|
144
|
-
// 但是ios有些问题:在webkit浏览内核环境下,beacon requests的请求方式存在证书验证的bug,发送失败但返回正确.
|
|
145
|
-
// 修复说明在如下链接中:https://bugs.webkit.org/show_bug.cgi?id=193508
|
|
146
|
-
// 但是目前为止,在iOS12.2版本中该问题依旧存在
|
|
147
|
-
// 2021-11-11: 发现ios 14可以送,故小于14的不发送
|
|
148
|
-
if (!(!isLtIos14
|
|
149
|
-
&& navigator.sendBeacon
|
|
150
|
-
&& navigator.sendBeacon(url))) {
|
|
151
|
-
(new Image()).src = url;
|
|
152
|
-
}
|
|
114
|
+
this.request(url);
|
|
153
115
|
}
|
|
154
116
|
if (post) {
|
|
155
117
|
this.sendPost(postData);
|
|
@@ -294,6 +256,46 @@
|
|
|
294
256
|
SpyClient.prototype.clearAllMark = function () {
|
|
295
257
|
this.markCache = {};
|
|
296
258
|
};
|
|
259
|
+
// send(data, true) 也能以post发送,但是会有严格校验
|
|
260
|
+
// sendPost能以post发送,但没有校验
|
|
261
|
+
SpyClient.prototype.sendPost = function (data) {
|
|
262
|
+
var logItems = isArray(data) ? data : [data];
|
|
263
|
+
var first = logItems[0];
|
|
264
|
+
// 需要在页面暴漏出来pid等基本信息,方式调试查看基本信息与兼容目前的监控
|
|
265
|
+
var query = {
|
|
266
|
+
pid: first.pid,
|
|
267
|
+
type: first.type,
|
|
268
|
+
group: first.group,
|
|
269
|
+
};
|
|
270
|
+
var url = this.option.logServer + stringify(query);
|
|
271
|
+
this.request(url, data);
|
|
272
|
+
};
|
|
273
|
+
// 有data时,意味着要用post发送请求
|
|
274
|
+
SpyClient.prototype.request = function (url, data) {
|
|
275
|
+
if (!(!isLtIos14
|
|
276
|
+
&& navigator.sendBeacon
|
|
277
|
+
&& navigator.sendBeacon(url, data ? JSON.stringify(data) : undefined))) {
|
|
278
|
+
if (data) {
|
|
279
|
+
this.fetch(url, data);
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
(new Image()).src = url;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
SpyClient.prototype.fetch = function (url, data) {
|
|
287
|
+
if (!window.fetch) {
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
fetch(url, {
|
|
291
|
+
method: 'POST',
|
|
292
|
+
credentials: 'include',
|
|
293
|
+
headers: {
|
|
294
|
+
'Content-Type': 'application/json',
|
|
295
|
+
},
|
|
296
|
+
body: JSON.stringify(data),
|
|
297
|
+
});
|
|
298
|
+
};
|
|
297
299
|
return SpyClient;
|
|
298
300
|
}());
|
|
299
301
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).SpyClient=t()}(this,function(){"use strict";function o(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return(Object.assign||function(e){for(var t=void 0,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,e)}var e=navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/),
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).SpyClient=t()}(this,function(){"use strict";function o(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return(Object.assign||function(e){for(var t=void 0,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,e)}var e=navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/),n=e&&e[2]&&+e[2]<14;function f(e){console.error("[SpyClient_log]"+e)}function a(n){return Object.keys(n).map(function(e){var t=n[e];return void 0===t?t="":"string"!=typeof t&&(t=JSON.stringify(t)),encodeURIComponent(e)+"="+encodeURIComponent(t)}).join("&")}function p(e){return"[object Array]"===Object.prototype.toString.call(e)}function t(e){if(this.sample={},this.markCache={},!e.pid)throw new Error("pid is required");this.option={pid:e.pid,lid:e.lid,check:!1!==e.check,sample:e.sample,localCache:e.localCache,logServer:e.logServer||"https://sp1.baidu.com/5b1ZeDe5KgQFm2e88IuM_a/mwb2.gif?"}}return t.prototype.handle=function(e){if(this.check(e)){if(e=o({pid:this.option.pid,lid:this.option.lid,ts:Date.now(),group:"common"},e),this.option.localCache&&this.option.localCache.addLog(e),"number"==typeof e.sample){if(Math.random()>e.sample)return}else if("number"==typeof this.option.sample&&Math.random()>this.option.sample)return;return delete e.sample,e}},t.prototype.send=function(e,t){void 0===t&&(t=!1);for(var n=[],o=0,r=p(e)?e:[e];o<r.length;o++){var i=r[o];if((i=this.handle(i))&&(n.push(i),!t)){var s=this.option.logServer+a(i);this.request(s)}}t&&this.sendPost(n)},t.prototype.check=function(e){if(!this.option.check)return!0;var t=["perf","except","dist","count"];if(-1===t.indexOf(e.type))return f("type only is one of "+t.join(", ")),!1;if(e.group&&30<e.group.length)return f("group length execeeds 30"),!1;var n=/^[a-zA-Z0-9-_]{0,30}$/;if("except"===e.type){if("string"!=typeof e.info.msg||!e.info.msg.length)return f("info.msg field must be not empty and is String"),!1}else for(var o=0,r=Object.keys(e.info);o<r.length;o++){var i=r[o];if(!n.test(i))return f("info."+i+" is unexpected. Length must be not more than 30. Supported chars: a-zA-Z0-9-_"),!1;var s=e.info[i];if("dist"===e.type){if(30<s.length)return f("info."+i+" value length execeeds 30 when type == 'dist'"),!1}else if("number"!=typeof s)return f("info."+i+" value must be number"),!1}if(e.dim)for(var a=0,p=Object.keys(e.dim);a<p.length;a++){var c=p[a];if(!n.test(c))return f("dim key ["+c+"] is unexpected. Length must be not more than 30. Supported chars: a-zA-Z0-9-_"),!1;var h=e.dim[c];if(!/^[a-zA-Z0-9\-_\*\.\s\/#\+@\&\u4e00-\u9fa5]{0,30}$/.test(h))return f("dim."+c+" value ["+h+"] is unexpected. Length must be not more than 30. Supported chars: a-zA-Z0-9-_*. /#+@& and Chinese"),!1}return!0},t.prototype.sendPerf=function(e){this.send(o({type:"perf"},e))},t.prototype.sendExcept=function(e){this.send(o({type:"except"},e))},t.prototype.sendDist=function(e){this.send(o({type:"dist"},e))},t.prototype.sendCount=function(e){this.send(o({type:"count"},e))},t.prototype.sendExceptForError=function(e,t){var n=o({},t);n.info=o({},t.info||{},{msg:e.message,stack:e.stack}),this.sendExcept(n)},t.prototype.startMark=function(e){this.markCache[e]={start:Date.now()}},t.prototype.endMark=function(e){return this.markCache[e]?(this.markCache[e].total=Date.now()-this.markCache[e].start,this.markCache[e].total):0},t.prototype.clearMark=function(e){this.markCache[e]&&delete this.markCache[e]},t.prototype.getAllMark=function(){for(var e={},t=0,n=Object.keys(this.markCache);t<n.length;t++){var o=n[t];e[o]=this.markCache[o].total}return e},t.prototype.clearAllMark=function(){this.markCache={}},t.prototype.sendPost=function(e){var t=(p(e)?e:[e])[0],n={pid:t.pid,type:t.type,group:t.group},o=this.option.logServer+a(n);this.request(o,e)},t.prototype.request=function(e,t){!n&&navigator.sendBeacon&&navigator.sendBeacon(e,t?JSON.stringify(t):void 0)||(t?this.fetch(e,t):(new Image).src=e)},t.prototype.fetch=function(e,t){window.fetch&&fetch(e,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})},t});
|
|
@@ -64,35 +64,6 @@ var SpyClient = /** @class */ (function () {
|
|
|
64
64
|
logServer: option.logServer || defaultLogServer,
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
|
-
SpyClient.prototype.fetch = function (url, data) {
|
|
68
|
-
if (!window.fetch) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
fetch(url, {
|
|
72
|
-
method: 'POST',
|
|
73
|
-
credentials: 'include',
|
|
74
|
-
headers: {
|
|
75
|
-
'Content-Type': 'application/json',
|
|
76
|
-
},
|
|
77
|
-
body: JSON.stringify(data),
|
|
78
|
-
});
|
|
79
|
-
};
|
|
80
|
-
SpyClient.prototype.sendPost = function (data) {
|
|
81
|
-
var logItems = isArray(data) ? data : [data];
|
|
82
|
-
var first = logItems[0];
|
|
83
|
-
// 需要在页面暴漏出来pid等基本信息,方式调试查看基本信息与兼容目前的监控
|
|
84
|
-
var query = {
|
|
85
|
-
pid: first.pid,
|
|
86
|
-
type: first.type,
|
|
87
|
-
group: first.group,
|
|
88
|
-
};
|
|
89
|
-
var url = this.option.logServer + stringify(query);
|
|
90
|
-
if (!(!isLtIos14
|
|
91
|
-
&& navigator.sendBeacon
|
|
92
|
-
&& navigator.sendBeacon(url, JSON.stringify(data)))) {
|
|
93
|
-
this.fetch(url, data);
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
67
|
SpyClient.prototype.handle = function (logItem) {
|
|
97
68
|
if (!this.check(logItem)) {
|
|
98
69
|
return;
|
|
@@ -134,16 +105,7 @@ var SpyClient = /** @class */ (function () {
|
|
|
134
105
|
continue;
|
|
135
106
|
}
|
|
136
107
|
var url = this.option.logServer + stringify(logItem);
|
|
137
|
-
|
|
138
|
-
// 但是ios有些问题:在webkit浏览内核环境下,beacon requests的请求方式存在证书验证的bug,发送失败但返回正确.
|
|
139
|
-
// 修复说明在如下链接中:https://bugs.webkit.org/show_bug.cgi?id=193508
|
|
140
|
-
// 但是目前为止,在iOS12.2版本中该问题依旧存在
|
|
141
|
-
// 2021-11-11: 发现ios 14可以送,故小于14的不发送
|
|
142
|
-
if (!(!isLtIos14
|
|
143
|
-
&& navigator.sendBeacon
|
|
144
|
-
&& navigator.sendBeacon(url))) {
|
|
145
|
-
(new Image()).src = url;
|
|
146
|
-
}
|
|
108
|
+
this.request(url);
|
|
147
109
|
}
|
|
148
110
|
if (post) {
|
|
149
111
|
this.sendPost(postData);
|
|
@@ -288,6 +250,46 @@ var SpyClient = /** @class */ (function () {
|
|
|
288
250
|
SpyClient.prototype.clearAllMark = function () {
|
|
289
251
|
this.markCache = {};
|
|
290
252
|
};
|
|
253
|
+
// send(data, true) 也能以post发送,但是会有严格校验
|
|
254
|
+
// sendPost能以post发送,但没有校验
|
|
255
|
+
SpyClient.prototype.sendPost = function (data) {
|
|
256
|
+
var logItems = isArray(data) ? data : [data];
|
|
257
|
+
var first = logItems[0];
|
|
258
|
+
// 需要在页面暴漏出来pid等基本信息,方式调试查看基本信息与兼容目前的监控
|
|
259
|
+
var query = {
|
|
260
|
+
pid: first.pid,
|
|
261
|
+
type: first.type,
|
|
262
|
+
group: first.group,
|
|
263
|
+
};
|
|
264
|
+
var url = this.option.logServer + stringify(query);
|
|
265
|
+
this.request(url, data);
|
|
266
|
+
};
|
|
267
|
+
// 有data时,意味着要用post发送请求
|
|
268
|
+
SpyClient.prototype.request = function (url, data) {
|
|
269
|
+
if (!(!isLtIos14
|
|
270
|
+
&& navigator.sendBeacon
|
|
271
|
+
&& navigator.sendBeacon(url, data ? JSON.stringify(data) : undefined))) {
|
|
272
|
+
if (data) {
|
|
273
|
+
this.fetch(url, data);
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
(new Image()).src = url;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
SpyClient.prototype.fetch = function (url, data) {
|
|
281
|
+
if (!window.fetch) {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
fetch(url, {
|
|
285
|
+
method: 'POST',
|
|
286
|
+
credentials: 'include',
|
|
287
|
+
headers: {
|
|
288
|
+
'Content-Type': 'application/json',
|
|
289
|
+
},
|
|
290
|
+
body: JSON.stringify(data),
|
|
291
|
+
});
|
|
292
|
+
};
|
|
291
293
|
return SpyClient;
|
|
292
294
|
}());
|
|
293
295
|
|
package/dist/spy-client.esm.js
CHANGED
|
@@ -169,35 +169,6 @@ var SpyClient$1 = /** @class */ (function () {
|
|
|
169
169
|
logServer: option.logServer || defaultLogServer,
|
|
170
170
|
};
|
|
171
171
|
}
|
|
172
|
-
SpyClient.prototype.fetch = function (url, data) {
|
|
173
|
-
if (!window.fetch) {
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
fetch(url, {
|
|
177
|
-
method: 'POST',
|
|
178
|
-
credentials: 'include',
|
|
179
|
-
headers: {
|
|
180
|
-
'Content-Type': 'application/json',
|
|
181
|
-
},
|
|
182
|
-
body: JSON.stringify(data),
|
|
183
|
-
});
|
|
184
|
-
};
|
|
185
|
-
SpyClient.prototype.sendPost = function (data) {
|
|
186
|
-
var logItems = isArray(data) ? data : [data];
|
|
187
|
-
var first = logItems[0];
|
|
188
|
-
// 需要在页面暴漏出来pid等基本信息,方式调试查看基本信息与兼容目前的监控
|
|
189
|
-
var query = {
|
|
190
|
-
pid: first.pid,
|
|
191
|
-
type: first.type,
|
|
192
|
-
group: first.group,
|
|
193
|
-
};
|
|
194
|
-
var url = this.option.logServer + stringify(query);
|
|
195
|
-
if (!(!isLtIos14
|
|
196
|
-
&& navigator.sendBeacon
|
|
197
|
-
&& navigator.sendBeacon(url, JSON.stringify(data)))) {
|
|
198
|
-
this.fetch(url, data);
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
172
|
SpyClient.prototype.handle = function (logItem) {
|
|
202
173
|
if (!this.check(logItem)) {
|
|
203
174
|
return;
|
|
@@ -239,16 +210,7 @@ var SpyClient$1 = /** @class */ (function () {
|
|
|
239
210
|
continue;
|
|
240
211
|
}
|
|
241
212
|
var url = this.option.logServer + stringify(logItem);
|
|
242
|
-
|
|
243
|
-
// 但是ios有些问题:在webkit浏览内核环境下,beacon requests的请求方式存在证书验证的bug,发送失败但返回正确.
|
|
244
|
-
// 修复说明在如下链接中:https://bugs.webkit.org/show_bug.cgi?id=193508
|
|
245
|
-
// 但是目前为止,在iOS12.2版本中该问题依旧存在
|
|
246
|
-
// 2021-11-11: 发现ios 14可以送,故小于14的不发送
|
|
247
|
-
if (!(!isLtIos14
|
|
248
|
-
&& navigator.sendBeacon
|
|
249
|
-
&& navigator.sendBeacon(url))) {
|
|
250
|
-
(new Image()).src = url;
|
|
251
|
-
}
|
|
213
|
+
this.request(url);
|
|
252
214
|
}
|
|
253
215
|
if (post) {
|
|
254
216
|
this.sendPost(postData);
|
|
@@ -393,6 +355,46 @@ var SpyClient$1 = /** @class */ (function () {
|
|
|
393
355
|
SpyClient.prototype.clearAllMark = function () {
|
|
394
356
|
this.markCache = {};
|
|
395
357
|
};
|
|
358
|
+
// send(data, true) 也能以post发送,但是会有严格校验
|
|
359
|
+
// sendPost能以post发送,但没有校验
|
|
360
|
+
SpyClient.prototype.sendPost = function (data) {
|
|
361
|
+
var logItems = isArray(data) ? data : [data];
|
|
362
|
+
var first = logItems[0];
|
|
363
|
+
// 需要在页面暴漏出来pid等基本信息,方式调试查看基本信息与兼容目前的监控
|
|
364
|
+
var query = {
|
|
365
|
+
pid: first.pid,
|
|
366
|
+
type: first.type,
|
|
367
|
+
group: first.group,
|
|
368
|
+
};
|
|
369
|
+
var url = this.option.logServer + stringify(query);
|
|
370
|
+
this.request(url, data);
|
|
371
|
+
};
|
|
372
|
+
// 有data时,意味着要用post发送请求
|
|
373
|
+
SpyClient.prototype.request = function (url, data) {
|
|
374
|
+
if (!(!isLtIos14
|
|
375
|
+
&& navigator.sendBeacon
|
|
376
|
+
&& navigator.sendBeacon(url, data ? JSON.stringify(data) : undefined))) {
|
|
377
|
+
if (data) {
|
|
378
|
+
this.fetch(url, data);
|
|
379
|
+
}
|
|
380
|
+
else {
|
|
381
|
+
(new Image()).src = url;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
SpyClient.prototype.fetch = function (url, data) {
|
|
386
|
+
if (!window.fetch) {
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
fetch(url, {
|
|
390
|
+
method: 'POST',
|
|
391
|
+
credentials: 'include',
|
|
392
|
+
headers: {
|
|
393
|
+
'Content-Type': 'application/json',
|
|
394
|
+
},
|
|
395
|
+
body: JSON.stringify(data),
|
|
396
|
+
});
|
|
397
|
+
};
|
|
396
398
|
return SpyClient;
|
|
397
399
|
}());
|
|
398
400
|
|