spy-client 2.1.12 → 2.1.14
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 +1 -1
- package/dist/head/base.d.ts +1 -1
- package/dist/lib/interface.d.ts +13 -13
- package/dist/spy-client-basic.esm.js +6 -6
- package/dist/spy-client-basic.iife.js +7 -7
- package/dist/spy-client-basic.iife.min.js +1 -1
- package/dist/spy-client-basic.js +8 -8
- package/dist/spy-client-basic.min.js +1 -1
- package/dist/spy-client-basic.mjs +6 -6
- package/dist/spy-client.esm.js +16 -16
- package/dist/spy-client.iife.js +17 -17
- package/dist/spy-client.iife.min.js +1 -1
- package/dist/spy-client.js +18 -18
- package/dist/spy-client.min.js +1 -1
- package/dist/spy-client.mjs +16 -16
- package/dist/spy-head.js +13 -12
- package/dist/spy-head.min.js +1 -1
- package/dist/spy-local-cache.js +12 -12
- package/dist/spy-local-cache.min.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/head/base.d.ts
CHANGED
|
@@ -20,6 +20,6 @@ declare const _default: {
|
|
|
20
20
|
entryMap: any;
|
|
21
21
|
init(conf: SpyHeadConf): void;
|
|
22
22
|
addError(obj: SendObj): void;
|
|
23
|
-
send(obj: SendObj, isSend?: boolean
|
|
23
|
+
send(obj: SendObj, isSend?: boolean, logServer?: string): void;
|
|
24
24
|
};
|
|
25
25
|
export default _default;
|
package/dist/lib/interface.d.ts
CHANGED
|
@@ -32,11 +32,11 @@ export declare class Module {
|
|
|
32
32
|
export interface FIDMetric {
|
|
33
33
|
fid: number;
|
|
34
34
|
}
|
|
35
|
-
export
|
|
35
|
+
export type FIDCB = (metric: FIDMetric) => void;
|
|
36
36
|
export interface LCPMetric {
|
|
37
37
|
lcp: number;
|
|
38
38
|
}
|
|
39
|
-
export
|
|
39
|
+
export type LCPCB = (metric: LCPMetric) => void;
|
|
40
40
|
export declare enum ResType {
|
|
41
41
|
JS = "js",
|
|
42
42
|
CSS = "css",
|
|
@@ -78,7 +78,7 @@ export interface ResourceHostMetric {
|
|
|
78
78
|
hostCacheRate: number;
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
|
-
export
|
|
81
|
+
export type ResourceCB = (metric: ResourceMetric, hostMetric: ResourceHostMetric) => void;
|
|
82
82
|
export interface ResourceErrorInfo {
|
|
83
83
|
msg: string;
|
|
84
84
|
xpath: string;
|
|
@@ -86,7 +86,7 @@ export interface ResourceErrorInfo {
|
|
|
86
86
|
type: string;
|
|
87
87
|
dur?: number;
|
|
88
88
|
}
|
|
89
|
-
export
|
|
89
|
+
export type ResourceErrorCB = (info: ResourceErrorInfo) => void;
|
|
90
90
|
export interface TimingMetric {
|
|
91
91
|
dns: number;
|
|
92
92
|
tcp: number;
|
|
@@ -101,11 +101,11 @@ export interface TimingMetric {
|
|
|
101
101
|
t7FirstPaint?: number;
|
|
102
102
|
t7FirstScreen?: number;
|
|
103
103
|
}
|
|
104
|
-
export
|
|
104
|
+
export type TimingCB = (metric: TimingMetric) => void;
|
|
105
105
|
export interface TTIMetric {
|
|
106
106
|
tti: number;
|
|
107
107
|
}
|
|
108
|
-
export
|
|
108
|
+
export type TTICB = (metric: TTIMetric) => void;
|
|
109
109
|
export interface TTIOption {
|
|
110
110
|
interval?: number;
|
|
111
111
|
filterRequest?: (entry: PerformanceEntry) => boolean;
|
|
@@ -113,14 +113,14 @@ export interface TTIOption {
|
|
|
113
113
|
export interface LayoutShiftMetric {
|
|
114
114
|
layoutShift: number;
|
|
115
115
|
}
|
|
116
|
-
export
|
|
116
|
+
export type LayoutShiftCB = (metric: LayoutShiftMetric) => void;
|
|
117
117
|
export interface MemoryMetric {
|
|
118
118
|
usedJSHeapSize: number;
|
|
119
119
|
totalJSHeapSize: number;
|
|
120
120
|
jsHeapSizeLimit: number;
|
|
121
121
|
usedJSHeapRate: number;
|
|
122
122
|
}
|
|
123
|
-
export
|
|
123
|
+
export type MemoryCB = (metric: MemoryMetric) => void;
|
|
124
124
|
export interface NavigatorInfoMetric {
|
|
125
125
|
downlink?: number;
|
|
126
126
|
effectiveType?: '2g' | '3g' | '4g' | 'slow-2g';
|
|
@@ -129,7 +129,7 @@ export interface NavigatorInfoMetric {
|
|
|
129
129
|
deviceMemory?: number;
|
|
130
130
|
hardwareConcurrency?: number;
|
|
131
131
|
}
|
|
132
|
-
export
|
|
132
|
+
export type NavigatorInfoCB = (metric: NavigatorInfoMetric) => void;
|
|
133
133
|
export interface FSPLongtaskMetric {
|
|
134
134
|
fspLongtaskTime: number;
|
|
135
135
|
fspTBT: number;
|
|
@@ -137,7 +137,7 @@ export interface FSPLongtaskMetric {
|
|
|
137
137
|
fspLongtaskRate: number;
|
|
138
138
|
fspLongtaskNum: number;
|
|
139
139
|
}
|
|
140
|
-
export
|
|
140
|
+
export type FSPLongtaskCB = (metric: FSPLongtaskMetric) => void;
|
|
141
141
|
export interface LCPLongtaskMetric {
|
|
142
142
|
lcpLongtaskTime: number;
|
|
143
143
|
lcpTBT: number;
|
|
@@ -145,7 +145,7 @@ export interface LCPLongtaskMetric {
|
|
|
145
145
|
lcpLongtaskRate: number;
|
|
146
146
|
lcpLongtaskNum: number;
|
|
147
147
|
}
|
|
148
|
-
export
|
|
148
|
+
export type LCPLongtaskCB = (metric: LCPLongtaskMetric) => void;
|
|
149
149
|
export interface LoadLongtaskMetric {
|
|
150
150
|
loadLongtaskTime: number;
|
|
151
151
|
loadTBT: number;
|
|
@@ -153,7 +153,7 @@ export interface LoadLongtaskMetric {
|
|
|
153
153
|
loadLongtaskRate: number;
|
|
154
154
|
loadLongtaskNum: number;
|
|
155
155
|
}
|
|
156
|
-
export
|
|
156
|
+
export type LoadLongtaskCB = (metric: LoadLongtaskMetric) => void;
|
|
157
157
|
export interface PageLongtaskMetric {
|
|
158
158
|
pageLongtaskTime: number;
|
|
159
159
|
pageTBT: number;
|
|
@@ -164,7 +164,7 @@ export interface PageLongtaskMetric {
|
|
|
164
164
|
pageIframeLongtaskRate: number;
|
|
165
165
|
pageIframeLongtaskNum: number;
|
|
166
166
|
}
|
|
167
|
-
export
|
|
167
|
+
export type PageLongtaskCB = (metric: PageLongtaskMetric) => void;
|
|
168
168
|
export interface ResOption {
|
|
169
169
|
ignorePaths?: string[];
|
|
170
170
|
trigger?: 'load' | 'leave';
|
|
@@ -31,7 +31,7 @@ var defaultLogServer = 'https://sp1.baidu.com/5b1ZeDe5KgQFm2e88IuM_a/mwb2.gif?';
|
|
|
31
31
|
var ver = navigator && navigator.userAgent ? navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/) : '';
|
|
32
32
|
var isLtIos14 = ver && ver[2] && (+ver[2] < 14);
|
|
33
33
|
function err(msg) {
|
|
34
|
-
console.error("[SpyClient_log]"
|
|
34
|
+
console.error("[SpyClient_log]".concat(msg));
|
|
35
35
|
// throw new Error(msg);
|
|
36
36
|
}
|
|
37
37
|
function stringify(obj) {
|
|
@@ -136,7 +136,7 @@ var SpyClient = /** @class */ (function () {
|
|
|
136
136
|
for (var _i = 0, _a = Object.keys(query.info); _i < _a.length; _i++) {
|
|
137
137
|
var infoKey = _a[_i];
|
|
138
138
|
if (!simpleReg.test(infoKey)) {
|
|
139
|
-
err("info."
|
|
139
|
+
err("info.".concat(infoKey, " is unexpected. ")
|
|
140
140
|
+ 'Length must be not more than 30. '
|
|
141
141
|
+ 'Supported chars: a-zA-Z0-9-_');
|
|
142
142
|
return false;
|
|
@@ -144,12 +144,12 @@ var SpyClient = /** @class */ (function () {
|
|
|
144
144
|
var infoVal = query.info[infoKey];
|
|
145
145
|
if (query.type === 'dist') {
|
|
146
146
|
if (infoVal.length > 30) {
|
|
147
|
-
err("info."
|
|
147
|
+
err("info.".concat(infoKey, " value length execeeds 30 when type == 'dist'"));
|
|
148
148
|
return false;
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
else if (typeof infoVal !== 'number') {
|
|
152
|
-
err("info."
|
|
152
|
+
err("info.".concat(infoKey, " value must be number"));
|
|
153
153
|
return false;
|
|
154
154
|
}
|
|
155
155
|
}
|
|
@@ -158,14 +158,14 @@ var SpyClient = /** @class */ (function () {
|
|
|
158
158
|
for (var _b = 0, _c = Object.keys(query.dim); _b < _c.length; _b++) {
|
|
159
159
|
var dimKey = _c[_b];
|
|
160
160
|
if (!simpleReg.test(dimKey)) {
|
|
161
|
-
err("dim key ["
|
|
161
|
+
err("dim key [".concat(dimKey, "] is unexpected. ")
|
|
162
162
|
+ 'Length must be not more than 30. '
|
|
163
163
|
+ 'Supported chars: a-zA-Z0-9-_');
|
|
164
164
|
return false;
|
|
165
165
|
}
|
|
166
166
|
var dimVal = query.dim[dimKey];
|
|
167
167
|
if (!/^[a-zA-Z0-9\-_\*\.\s\/#\+@\&\u4e00-\u9fa5]{0,30}$/.test(dimVal)) {
|
|
168
|
-
err("dim."
|
|
168
|
+
err("dim.".concat(dimKey, " value [").concat(dimVal, "] is unexpected. ")
|
|
169
169
|
+ 'Length must be not more than 30. '
|
|
170
170
|
+ 'Supported chars: a-zA-Z0-9-_*. /#+@& and Chinese');
|
|
171
171
|
return false;
|
|
@@ -34,7 +34,7 @@ var SpyClient = (function () {
|
|
|
34
34
|
var ver = navigator && navigator.userAgent ? navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/) : '';
|
|
35
35
|
var isLtIos14 = ver && ver[2] && (+ver[2] < 14);
|
|
36
36
|
function err(msg) {
|
|
37
|
-
console.error("[SpyClient_log]"
|
|
37
|
+
console.error("[SpyClient_log]".concat(msg));
|
|
38
38
|
// throw new Error(msg);
|
|
39
39
|
}
|
|
40
40
|
function stringify(obj) {
|
|
@@ -139,7 +139,7 @@ var SpyClient = (function () {
|
|
|
139
139
|
for (var _i = 0, _a = Object.keys(query.info); _i < _a.length; _i++) {
|
|
140
140
|
var infoKey = _a[_i];
|
|
141
141
|
if (!simpleReg.test(infoKey)) {
|
|
142
|
-
err("info."
|
|
142
|
+
err("info.".concat(infoKey, " is unexpected. ")
|
|
143
143
|
+ 'Length must be not more than 30. '
|
|
144
144
|
+ 'Supported chars: a-zA-Z0-9-_');
|
|
145
145
|
return false;
|
|
@@ -147,12 +147,12 @@ var SpyClient = (function () {
|
|
|
147
147
|
var infoVal = query.info[infoKey];
|
|
148
148
|
if (query.type === 'dist') {
|
|
149
149
|
if (infoVal.length > 30) {
|
|
150
|
-
err("info."
|
|
150
|
+
err("info.".concat(infoKey, " value length execeeds 30 when type == 'dist'"));
|
|
151
151
|
return false;
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
154
|
else if (typeof infoVal !== 'number') {
|
|
155
|
-
err("info."
|
|
155
|
+
err("info.".concat(infoKey, " value must be number"));
|
|
156
156
|
return false;
|
|
157
157
|
}
|
|
158
158
|
}
|
|
@@ -161,14 +161,14 @@ var SpyClient = (function () {
|
|
|
161
161
|
for (var _b = 0, _c = Object.keys(query.dim); _b < _c.length; _b++) {
|
|
162
162
|
var dimKey = _c[_b];
|
|
163
163
|
if (!simpleReg.test(dimKey)) {
|
|
164
|
-
err("dim key ["
|
|
164
|
+
err("dim key [".concat(dimKey, "] is unexpected. ")
|
|
165
165
|
+ 'Length must be not more than 30. '
|
|
166
166
|
+ 'Supported chars: a-zA-Z0-9-_');
|
|
167
167
|
return false;
|
|
168
168
|
}
|
|
169
169
|
var dimVal = query.dim[dimKey];
|
|
170
170
|
if (!/^[a-zA-Z0-9\-_\*\.\s\/#\+@\&\u4e00-\u9fa5]{0,30}$/.test(dimVal)) {
|
|
171
|
-
err("dim."
|
|
171
|
+
err("dim.".concat(dimKey, " value [").concat(dimVal, "] is unexpected. ")
|
|
172
172
|
+ 'Length must be not more than 30. '
|
|
173
173
|
+ 'Supported chars: a-zA-Z0-9-_*. /#+@& and Chinese');
|
|
174
174
|
return false;
|
|
@@ -301,4 +301,4 @@ var SpyClient = (function () {
|
|
|
301
301
|
|
|
302
302
|
return SpyClient;
|
|
303
303
|
|
|
304
|
-
}()
|
|
304
|
+
})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var SpyClient=
|
|
1
|
+
var SpyClient=(()=>{function o(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return(Object.assign||function(t){for(var e,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&&navigator.userAgent?navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/):"",n=t&&t[2]&&+t[2]<14;function u(t){console.error("[SpyClient_log]".concat(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 s(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=s(t)?t:[t];o<r.length;o++){var i=r[o];(i=this.handle(i))&&(n.push(i),e||(i=this.option.logServer+a(i),this.request(i)))}e&&this.sendPost(n)},e.prototype.check=function(t){if(this.option.check){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.".concat(i," is unexpected. ")+"Length must be not more than 30. Supported chars: a-zA-Z0-9-_"),!1;var a=t.info[i];if("dist"===t.type){if(30<a.length)return u("info.".concat(i," value length execeeds 30 when type == 'dist'")),!1}else if("number"!=typeof a)return u("info.".concat(i," value must be number")),!1}if(t.dim)for(var s=0,p=Object.keys(t.dim);s<p.length;s++){var c=p[s];if(!n.test(c))return u("dim key [".concat(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.".concat(c," value [").concat(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=(s(t)?t:[t])[0],e={pid:e.pid,type:e.type,group:e.group},e=this.option.logServer+a(e);this.request(e,t)},e.prototype.request=function(t,e){!n&&navigator&&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){fetch?fetch(t,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}):u("Global fetch method doesn't exist")},e})();
|
package/dist/spy-client-basic.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(factory) :
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.SpyClient = factory());
|
|
5
|
-
}(this, (function () { 'use strict';
|
|
5
|
+
})(this, (function () { 'use strict';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @file utils
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
var ver = navigator && navigator.userAgent ? navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/) : '';
|
|
38
38
|
var isLtIos14 = ver && ver[2] && (+ver[2] < 14);
|
|
39
39
|
function err(msg) {
|
|
40
|
-
console.error("[SpyClient_log]"
|
|
40
|
+
console.error("[SpyClient_log]".concat(msg));
|
|
41
41
|
// throw new Error(msg);
|
|
42
42
|
}
|
|
43
43
|
function stringify(obj) {
|
|
@@ -142,7 +142,7 @@
|
|
|
142
142
|
for (var _i = 0, _a = Object.keys(query.info); _i < _a.length; _i++) {
|
|
143
143
|
var infoKey = _a[_i];
|
|
144
144
|
if (!simpleReg.test(infoKey)) {
|
|
145
|
-
err("info."
|
|
145
|
+
err("info.".concat(infoKey, " is unexpected. ")
|
|
146
146
|
+ 'Length must be not more than 30. '
|
|
147
147
|
+ 'Supported chars: a-zA-Z0-9-_');
|
|
148
148
|
return false;
|
|
@@ -150,12 +150,12 @@
|
|
|
150
150
|
var infoVal = query.info[infoKey];
|
|
151
151
|
if (query.type === 'dist') {
|
|
152
152
|
if (infoVal.length > 30) {
|
|
153
|
-
err("info."
|
|
153
|
+
err("info.".concat(infoKey, " value length execeeds 30 when type == 'dist'"));
|
|
154
154
|
return false;
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
157
|
else if (typeof infoVal !== 'number') {
|
|
158
|
-
err("info."
|
|
158
|
+
err("info.".concat(infoKey, " value must be number"));
|
|
159
159
|
return false;
|
|
160
160
|
}
|
|
161
161
|
}
|
|
@@ -164,14 +164,14 @@
|
|
|
164
164
|
for (var _b = 0, _c = Object.keys(query.dim); _b < _c.length; _b++) {
|
|
165
165
|
var dimKey = _c[_b];
|
|
166
166
|
if (!simpleReg.test(dimKey)) {
|
|
167
|
-
err("dim key ["
|
|
167
|
+
err("dim key [".concat(dimKey, "] is unexpected. ")
|
|
168
168
|
+ 'Length must be not more than 30. '
|
|
169
169
|
+ 'Supported chars: a-zA-Z0-9-_');
|
|
170
170
|
return false;
|
|
171
171
|
}
|
|
172
172
|
var dimVal = query.dim[dimKey];
|
|
173
173
|
if (!/^[a-zA-Z0-9\-_\*\.\s\/#\+@\&\u4e00-\u9fa5]{0,30}$/.test(dimVal)) {
|
|
174
|
-
err("dim."
|
|
174
|
+
err("dim.".concat(dimKey, " value [").concat(dimVal, "] is unexpected. ")
|
|
175
175
|
+ 'Length must be not more than 30. '
|
|
176
176
|
+ 'Supported chars: a-zA-Z0-9-_*. /#+@& and Chinese');
|
|
177
177
|
return false;
|
|
@@ -304,4 +304,4 @@
|
|
|
304
304
|
|
|
305
305
|
return SpyClient;
|
|
306
306
|
|
|
307
|
-
}))
|
|
307
|
+
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
((t,e)=>{"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).SpyClient=e()})(this,function(){function o(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return(Object.assign||function(t){for(var e,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&&navigator.userAgent?navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/):"",n=t&&t[2]&&+t[2]<14;function f(t){console.error("[SpyClient_log]".concat(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 s(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=s(t)?t:[t];o<r.length;o++){var i=r[o];(i=this.handle(i))&&(n.push(i),e||(i=this.option.logServer+a(i),this.request(i)))}e&&this.sendPost(n)},e.prototype.check=function(t){if(this.option.check){var e=["perf","except","dist","count"];if(-1===e.indexOf(t.type))return f("type only is one of "+e.join(", ")),!1;if(t.group&&30<t.group.length)return f("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 f("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 f("info.".concat(i," is unexpected. ")+"Length must be not more than 30. Supported chars: a-zA-Z0-9-_"),!1;var a=t.info[i];if("dist"===t.type){if(30<a.length)return f("info.".concat(i," value length execeeds 30 when type == 'dist'")),!1}else if("number"!=typeof a)return f("info.".concat(i," value must be number")),!1}if(t.dim)for(var s=0,p=Object.keys(t.dim);s<p.length;s++){var c=p[s];if(!n.test(c))return f("dim key [".concat(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 f("dim.".concat(c," value [").concat(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=(s(t)?t:[t])[0],e={pid:e.pid,type:e.type,group:e.group},e=this.option.logServer+a(e);this.request(e,t)},e.prototype.request=function(t,e){!n&&navigator&&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){fetch?fetch(t,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}):f("Global fetch method doesn't exist")},e});
|
|
@@ -31,7 +31,7 @@ var defaultLogServer = 'https://sp1.baidu.com/5b1ZeDe5KgQFm2e88IuM_a/mwb2.gif?';
|
|
|
31
31
|
var ver = navigator && navigator.userAgent ? navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/) : '';
|
|
32
32
|
var isLtIos14 = ver && ver[2] && (+ver[2] < 14);
|
|
33
33
|
function err(msg) {
|
|
34
|
-
console.error("[SpyClient_log]"
|
|
34
|
+
console.error("[SpyClient_log]".concat(msg));
|
|
35
35
|
// throw new Error(msg);
|
|
36
36
|
}
|
|
37
37
|
function stringify(obj) {
|
|
@@ -136,7 +136,7 @@ var SpyClient = /** @class */ (function () {
|
|
|
136
136
|
for (var _i = 0, _a = Object.keys(query.info); _i < _a.length; _i++) {
|
|
137
137
|
var infoKey = _a[_i];
|
|
138
138
|
if (!simpleReg.test(infoKey)) {
|
|
139
|
-
err("info."
|
|
139
|
+
err("info.".concat(infoKey, " is unexpected. ")
|
|
140
140
|
+ 'Length must be not more than 30. '
|
|
141
141
|
+ 'Supported chars: a-zA-Z0-9-_');
|
|
142
142
|
return false;
|
|
@@ -144,12 +144,12 @@ var SpyClient = /** @class */ (function () {
|
|
|
144
144
|
var infoVal = query.info[infoKey];
|
|
145
145
|
if (query.type === 'dist') {
|
|
146
146
|
if (infoVal.length > 30) {
|
|
147
|
-
err("info."
|
|
147
|
+
err("info.".concat(infoKey, " value length execeeds 30 when type == 'dist'"));
|
|
148
148
|
return false;
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
else if (typeof infoVal !== 'number') {
|
|
152
|
-
err("info."
|
|
152
|
+
err("info.".concat(infoKey, " value must be number"));
|
|
153
153
|
return false;
|
|
154
154
|
}
|
|
155
155
|
}
|
|
@@ -158,14 +158,14 @@ var SpyClient = /** @class */ (function () {
|
|
|
158
158
|
for (var _b = 0, _c = Object.keys(query.dim); _b < _c.length; _b++) {
|
|
159
159
|
var dimKey = _c[_b];
|
|
160
160
|
if (!simpleReg.test(dimKey)) {
|
|
161
|
-
err("dim key ["
|
|
161
|
+
err("dim key [".concat(dimKey, "] is unexpected. ")
|
|
162
162
|
+ 'Length must be not more than 30. '
|
|
163
163
|
+ 'Supported chars: a-zA-Z0-9-_');
|
|
164
164
|
return false;
|
|
165
165
|
}
|
|
166
166
|
var dimVal = query.dim[dimKey];
|
|
167
167
|
if (!/^[a-zA-Z0-9\-_\*\.\s\/#\+@\&\u4e00-\u9fa5]{0,30}$/.test(dimVal)) {
|
|
168
|
-
err("dim."
|
|
168
|
+
err("dim.".concat(dimKey, " value [").concat(dimVal, "] is unexpected. ")
|
|
169
169
|
+ 'Length must be not more than 30. '
|
|
170
170
|
+ 'Supported chars: a-zA-Z0-9-_*. /#+@& and Chinese');
|
|
171
171
|
return false;
|
package/dist/spy-client.esm.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/*! *****************************************************************************
|
|
2
|
-
Copyright (c) Microsoft Corporation.
|
|
3
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
4
|
-
this file except in compliance with the License. You may obtain a copy of the
|
|
5
|
-
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
2
|
+
Copyright (c) Microsoft Corporation.
|
|
6
3
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
10
|
-
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
4
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
+
purpose with or without fee is hereby granted.
|
|
11
6
|
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
9
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
11
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
12
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
14
14
|
***************************************************************************** */
|
|
15
15
|
/* global Reflect, Promise */
|
|
16
16
|
|
|
@@ -141,7 +141,7 @@ var defaultLogServer = 'https://sp1.baidu.com/5b1ZeDe5KgQFm2e88IuM_a/mwb2.gif?';
|
|
|
141
141
|
var ver = navigator && navigator.userAgent ? navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/) : '';
|
|
142
142
|
var isLtIos14 = ver && ver[2] && (+ver[2] < 14);
|
|
143
143
|
function err(msg) {
|
|
144
|
-
console.error("[SpyClient_log]"
|
|
144
|
+
console.error("[SpyClient_log]".concat(msg));
|
|
145
145
|
// throw new Error(msg);
|
|
146
146
|
}
|
|
147
147
|
function stringify(obj) {
|
|
@@ -246,7 +246,7 @@ var SpyClient$1 = /** @class */ (function () {
|
|
|
246
246
|
for (var _i = 0, _a = Object.keys(query.info); _i < _a.length; _i++) {
|
|
247
247
|
var infoKey = _a[_i];
|
|
248
248
|
if (!simpleReg.test(infoKey)) {
|
|
249
|
-
err("info."
|
|
249
|
+
err("info.".concat(infoKey, " is unexpected. ")
|
|
250
250
|
+ 'Length must be not more than 30. '
|
|
251
251
|
+ 'Supported chars: a-zA-Z0-9-_');
|
|
252
252
|
return false;
|
|
@@ -254,12 +254,12 @@ var SpyClient$1 = /** @class */ (function () {
|
|
|
254
254
|
var infoVal = query.info[infoKey];
|
|
255
255
|
if (query.type === 'dist') {
|
|
256
256
|
if (infoVal.length > 30) {
|
|
257
|
-
err("info."
|
|
257
|
+
err("info.".concat(infoKey, " value length execeeds 30 when type == 'dist'"));
|
|
258
258
|
return false;
|
|
259
259
|
}
|
|
260
260
|
}
|
|
261
261
|
else if (typeof infoVal !== 'number') {
|
|
262
|
-
err("info."
|
|
262
|
+
err("info.".concat(infoKey, " value must be number"));
|
|
263
263
|
return false;
|
|
264
264
|
}
|
|
265
265
|
}
|
|
@@ -268,14 +268,14 @@ var SpyClient$1 = /** @class */ (function () {
|
|
|
268
268
|
for (var _b = 0, _c = Object.keys(query.dim); _b < _c.length; _b++) {
|
|
269
269
|
var dimKey = _c[_b];
|
|
270
270
|
if (!simpleReg.test(dimKey)) {
|
|
271
|
-
err("dim key ["
|
|
271
|
+
err("dim key [".concat(dimKey, "] is unexpected. ")
|
|
272
272
|
+ 'Length must be not more than 30. '
|
|
273
273
|
+ 'Supported chars: a-zA-Z0-9-_');
|
|
274
274
|
return false;
|
|
275
275
|
}
|
|
276
276
|
var dimVal = query.dim[dimKey];
|
|
277
277
|
if (!/^[a-zA-Z0-9\-_\*\.\s\/#\+@\&\u4e00-\u9fa5]{0,30}$/.test(dimVal)) {
|
|
278
|
-
err("dim."
|
|
278
|
+
err("dim.".concat(dimKey, " value [").concat(dimVal, "] is unexpected. ")
|
|
279
279
|
+ 'Length must be not more than 30. '
|
|
280
280
|
+ 'Supported chars: a-zA-Z0-9-_*. /#+@& and Chinese');
|
|
281
281
|
return false;
|
package/dist/spy-client.iife.js
CHANGED
|
@@ -2,18 +2,18 @@ var SpyClient = (function () {
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
/*! *****************************************************************************
|
|
5
|
-
Copyright (c) Microsoft Corporation.
|
|
6
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
7
|
-
this file except in compliance with the License. You may obtain a copy of the
|
|
8
|
-
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
5
|
+
Copyright (c) Microsoft Corporation.
|
|
9
6
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
13
|
-
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
7
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
8
|
+
purpose with or without fee is hereby granted.
|
|
14
9
|
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
11
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
12
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
13
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
14
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
15
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
16
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
17
17
|
***************************************************************************** */
|
|
18
18
|
/* global Reflect, Promise */
|
|
19
19
|
|
|
@@ -144,7 +144,7 @@ var SpyClient = (function () {
|
|
|
144
144
|
var ver = navigator && navigator.userAgent ? navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/) : '';
|
|
145
145
|
var isLtIos14 = ver && ver[2] && (+ver[2] < 14);
|
|
146
146
|
function err(msg) {
|
|
147
|
-
console.error("[SpyClient_log]"
|
|
147
|
+
console.error("[SpyClient_log]".concat(msg));
|
|
148
148
|
// throw new Error(msg);
|
|
149
149
|
}
|
|
150
150
|
function stringify(obj) {
|
|
@@ -249,7 +249,7 @@ var SpyClient = (function () {
|
|
|
249
249
|
for (var _i = 0, _a = Object.keys(query.info); _i < _a.length; _i++) {
|
|
250
250
|
var infoKey = _a[_i];
|
|
251
251
|
if (!simpleReg.test(infoKey)) {
|
|
252
|
-
err("info."
|
|
252
|
+
err("info.".concat(infoKey, " is unexpected. ")
|
|
253
253
|
+ 'Length must be not more than 30. '
|
|
254
254
|
+ 'Supported chars: a-zA-Z0-9-_');
|
|
255
255
|
return false;
|
|
@@ -257,12 +257,12 @@ var SpyClient = (function () {
|
|
|
257
257
|
var infoVal = query.info[infoKey];
|
|
258
258
|
if (query.type === 'dist') {
|
|
259
259
|
if (infoVal.length > 30) {
|
|
260
|
-
err("info."
|
|
260
|
+
err("info.".concat(infoKey, " value length execeeds 30 when type == 'dist'"));
|
|
261
261
|
return false;
|
|
262
262
|
}
|
|
263
263
|
}
|
|
264
264
|
else if (typeof infoVal !== 'number') {
|
|
265
|
-
err("info."
|
|
265
|
+
err("info.".concat(infoKey, " value must be number"));
|
|
266
266
|
return false;
|
|
267
267
|
}
|
|
268
268
|
}
|
|
@@ -271,14 +271,14 @@ var SpyClient = (function () {
|
|
|
271
271
|
for (var _b = 0, _c = Object.keys(query.dim); _b < _c.length; _b++) {
|
|
272
272
|
var dimKey = _c[_b];
|
|
273
273
|
if (!simpleReg.test(dimKey)) {
|
|
274
|
-
err("dim key ["
|
|
274
|
+
err("dim key [".concat(dimKey, "] is unexpected. ")
|
|
275
275
|
+ 'Length must be not more than 30. '
|
|
276
276
|
+ 'Supported chars: a-zA-Z0-9-_');
|
|
277
277
|
return false;
|
|
278
278
|
}
|
|
279
279
|
var dimVal = query.dim[dimKey];
|
|
280
280
|
if (!/^[a-zA-Z0-9\-_\*\.\s\/#\+@\&\u4e00-\u9fa5]{0,30}$/.test(dimVal)) {
|
|
281
|
-
err("dim."
|
|
281
|
+
err("dim.".concat(dimKey, " value [").concat(dimVal, "] is unexpected. ")
|
|
282
282
|
+ 'Length must be not more than 30. '
|
|
283
283
|
+ 'Supported chars: a-zA-Z0-9-_*. /#+@& and Chinese');
|
|
284
284
|
return false;
|
|
@@ -1487,4 +1487,4 @@ var SpyClient = (function () {
|
|
|
1487
1487
|
|
|
1488
1488
|
return SpyClient;
|
|
1489
1489
|
|
|
1490
|
-
}()
|
|
1490
|
+
})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var SpyClient=function(){"use strict";var i=function(t,e){return(i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])})(t,e)};var u=function(){return(u=Object.assign||function(t){for(var e,i=1,o=arguments.length;i<o;i++)for(var n in e=arguments[i])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}).apply(this,arguments)};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,i=1,o=arguments.length;i<o;i++)for(var n in e=arguments[i])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}).apply(this,t)}function r(t){var e=function(t){if(URL&&t)try{var e=new URL(t);if(void 0!==e.host)return{protocol:e.protocol,host:e.host,pathname:e.pathname,ext:""}}catch(t){console.error(t)}}(t);if(!e){var i=document.createElement("a");i.href=t,e={protocol:i.protocol,host:i.host||location.host,pathname:i.pathname,ext:""}}var o=e.pathname.split(".");return e.ext=o[o.length-1],e}function f(t){return+t.toFixed(1)}function d(t){if(!t)return{xpath:""};for(var e=[];t&&1===t.nodeType&&t!==t.parentNode;){var i=t.tagName.toLowerCase();if(t.getAttribute("id")?i+="[#"+t.getAttribute("id")+"]":t.classList&&t.classList.length&&(i+="[."+t.classList[t.classList.length-1]+"]"),e.push(i),t===document.body)break;t=t.parentNode}return{xpath:e.join("<")}}var t=navigator&&navigator.userAgent?navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/):"",n=t&&t[2]&&+t[2]<14;function l(t){console.error("[SpyClient_log]"+t)}function a(i){return Object.keys(i).map(function(t){var e=i[t];return void 0===e?e="":"string"!=typeof e&&(e=JSON.stringify(e)),encodeURIComponent(t)+"="+encodeURIComponent(e)}).join("&")}function c(t){return"[object Array]"===Object.prototype.toString.call(t)}var e=(s.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}},s.prototype.send=function(t,e){void 0===e&&(e=!1);for(var i=[],o=0,n=c(t)?t:[t];o<n.length;o++){var r=n[o];if((r=this.handle(r))&&(i.push(r),!e)){var s=this.option.logServer+a(r);this.request(s)}}e&&this.sendPost(i)},s.prototype.check=function(t){if(!this.option.check)return!0;var e=["perf","except","dist","count"];if(-1===e.indexOf(t.type))return l("type only is one of "+e.join(", ")),!1;if(t.group&&30<t.group.length)return l("group length execeeds 30"),!1;var i=/^[a-zA-Z0-9-_]{0,30}$/;if("except"===t.type){if("string"!=typeof t.info.msg||!t.info.msg.length)return l("info.msg field must be not empty and is String"),!1}else for(var o=0,n=Object.keys(t.info);o<n.length;o++){var r=n[o];if(!i.test(r))return l("info."+r+" is unexpected. Length must be not more than 30. Supported chars: a-zA-Z0-9-_"),!1;var s=t.info[r];if("dist"===t.type){if(30<s.length)return l("info."+r+" value length execeeds 30 when type == 'dist'"),!1}else if("number"!=typeof s)return l("info."+r+" value must be number"),!1}if(t.dim)for(var a=0,c=Object.keys(t.dim);a<c.length;a++){var h=c[a];if(!i.test(h))return l("dim key ["+h+"] is unexpected. Length must be not more than 30. Supported chars: a-zA-Z0-9-_"),!1;var p=t.dim[h];if(!/^[a-zA-Z0-9\-_\*\.\s\/#\+@\&\u4e00-\u9fa5]{0,30}$/.test(p))return l("dim."+h+" value ["+p+"] is unexpected. Length must be not more than 30. Supported chars: a-zA-Z0-9-_*. /#+@& and Chinese"),!1}return!0},s.prototype.sendPerf=function(t){this.send(o({type:"perf"},t))},s.prototype.sendExcept=function(t){this.send(o({type:"except"},t))},s.prototype.sendDist=function(t){this.send(o({type:"dist"},t))},s.prototype.sendCount=function(t){this.send(o({type:"count"},t))},s.prototype.sendExceptForError=function(t,e){var i=o({},e);i.info=o({},e.info||{},{msg:t.message,stack:t.stack}),this.sendExcept(i)},s.prototype.startMark=function(t){this.markCache[t]={start:Date.now()}},s.prototype.endMark=function(t){return this.markCache[t]?(this.markCache[t].total=Date.now()-this.markCache[t].start,this.markCache[t].total):0},s.prototype.clearMark=function(t){this.markCache[t]&&delete this.markCache[t]},s.prototype.getAllMark=function(){for(var t={},e=0,i=Object.keys(this.markCache);e<i.length;e++){var o=i[e];t[o]=this.markCache[o].total}return t},s.prototype.clearAllMark=function(){this.markCache={}},s.prototype.sendPost=function(t){var e=(c(t)?t:[t])[0],i={pid:e.pid,type:e.type,group:e.group},o=this.option.logServer+a(i);this.request(o,t)},s.prototype.request=function(t,e){!n&&navigator&&navigator.sendBeacon&&navigator.sendBeacon(t,e?JSON.stringify(e):void 0)||(e?this.fetch(t,e):(new Image).src=t)},s.prototype.fetch=function(t,e){fetch?fetch(t,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}):l("Global fetch method doesn't exist")},s);function s(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?"}}var h=window.__spyHead,p="first-input",g=(m.prototype.listenFID=function(t){this.cb=t,this.callCB()},m.prototype.callCB=function(){void 0!==this.finalValue&&this.cb&&this.cb({fid:this.finalValue})},m.prototype.destroy=function(){this.observer&&this.observer.disconnect(),this.observer=null},m.prototype.handle=function(t){var e=t.pop();e&&(this.finalValue=e.duration,this.callCB(),this.destroy())},m);function m(){var e=this;if(this.observer=null,window.PerformanceObserver){h&&h.entryMap&&h.entryMap[p]&&this.handle(h.entryMap[p]);try{this.observer=new PerformanceObserver(function(t){e.handle(t.getEntries())}),this.observer.observe({entryTypes:[p]})}catch(t){}}}var v=window.__spyHead,y="layout-shift",b=(k.prototype.listenLayoutShift=function(t){this.cb=t},k.prototype.leave=function(){this.onceLeave||(this.onceLeave=!0,this.observer&&this.observer.takeRecords&&this.observer.takeRecords(),this.finalValue=this.value,this.callCB(),this.destroy())},k.prototype.callCB=function(){void 0!==this.finalValue&&this.cb&&this.cb({layoutShift:this.finalValue})},k.prototype.destroy=function(){this.observer&&this.observer.disconnect(),this.observer=null},k.prototype.handle=function(t){var e=this;t.map(function(t){t.hadRecentInput||(e.value=(e.value||0)+(t.value||0))})},k);function k(){var e=this;if(this.observer=null,this.onceLeave=!1,window.PerformanceObserver){v&&v.entryMap&&v.entryMap[y]&&this.handle(v.entryMap[y]);try{this.observer=new PerformanceObserver(function(t){e.handle(t.getEntries())}),this.observer.observe({entryTypes:[y]})}catch(t){}}}var L={};function S(t){return L[t]}var w=window.__spyHead,T="largest-contentful-paint",C=(O.prototype.listenLCP=function(t){this.cb=t,this.callCB()},O.prototype.callCB=function(){this.finalValue&&this.cb&&this.cb({lcp:this.finalValue})},O.prototype.load=function(){this.observer&&this.observer.takeRecords&&this.observer.takeRecords(),this.finalValue=this.value,function(t,e){L[t]=e}("lcp",this.value),this.callCB(),this.destroy()},O.prototype.destroy=function(){this.observer&&this.observer.disconnect(),this.observer=null},O.prototype.handle=function(t){var e=this;t.map(function(t){e.value=t.renderTime||t.loadTime})},O);function O(){var e=this;if(this.observer=null,window.PerformanceObserver){w&&w.entryMap&&w.entryMap[T]&&this.handle(w.entryMap[T]);try{this.observer=new PerformanceObserver(function(t){e.handle(t.getEntries())}),this.observer.observe({entryTypes:[T]})}catch(t){}}}function B(t){return t.name.indexOf(".gif?")<0}var R=(I.prototype.check=function(){return window.PerformanceObserver&&performance&&performance.timing&&performance.timing.navigationStart},I.prototype.listenTTI=function(t,e){this.check()&&(this.observeLongtask(2e4),this.cb=t,(e=e||{}).interval&&(this.interval=e.interval),e.filterRequest&&(this.filterRequest=e.filterRequest))},I.prototype.load=function(){this.check()&&(this.ttiTimer=setInterval(this.ttiCheck,this.interval))},I.prototype.ttiCheck=function(){if(this.cb){var t=performance.now();if(!(t-this.lastLongTask<this.interval)){var e=this.getNetworkSilenceAt();if(!1!==e&&!(t-e<this.interval)){clearTimeout(this.ttiTimer);var i=this.lastLongTask;i=i||performance.timing.domContentLoadedEventEnd-performance.timing.navigationStart,this.stopObserveLongTask(),this.cb({tti:i})}}}},I.prototype.observerCallback=function(t){var e=t.getEntries(),i=e[e.length-1];this.lastLongTask=i.startTime+i.duration},I.prototype.stopObserveLongTask=function(){this.observer&&(this.observer.disconnect(),this.observer=null),this.stopLongTaskTimeoutId&&clearTimeout(this.stopLongTaskTimeoutId)},I.prototype.getNetworkSilenceAt=function(){for(var t=0,e=0,i=performance.getEntriesByType("resource").filter(this.filterRequest);e<i.length;e++){var o=i[e];if(!o.responseEnd)return!1;o.responseEnd>t&&(t=o.responseEnd)}return t},I.prototype.observeLongtask=function(t){this.stopObserveLongTask();try{this.observer=new PerformanceObserver(this.observerCallback),this.observer.observe({entryTypes:["longtask"]}),this.stopLongTaskTimeoutId=setTimeout(this.stopObserveLongTask,t)}catch(t){}},I);function I(){this.lastLongTask=0,this.observer=null,this.interval=5e3,this.filterRequest=B,this.observerCallback=this.observerCallback.bind(this),this.ttiCheck=this.ttiCheck.bind(this)}var z,E,P,j,x=(H.prototype.listenTiming=function(t){window.performance&&window.performance.timing&&(this.cb=t)},H.prototype.load=function(){var t=this;setTimeout(function(){t.cb&&t.cb(t.getMetric())},500)},H.prototype.getMetric=function(){var r={},t=window.performance.timing,e=t.navigationStart;if(r.dns=t.domainLookupEnd-t.domainLookupStart,r.tcp=t.connectEnd-t.connectStart,r.request=t.responseStart-t.requestStart,r.response=t.responseEnd-t.responseStart,r.parseHtml=t.domInteractive-t.domLoading,r.domReady=t.domContentLoadedEventEnd-e,r.loadEventHandle=t.loadEventEnd-t.loadEventStart,r.load=t.loadEventEnd-e,performance.getEntriesByType){var i=performance.getEntriesByType("paint");i&&i.length&&i.forEach(function(t){var e=t.name,i=t.duration,o=t.startTime,n=Math.ceil(i+o);"first-paint"===e&&(r.fp=n),"first-contentful-paint"===e&&(r.fcp=n)})}return t.domFirstPaint&&(r.t7FirstPaint=t.domFirstPaint-e),t.domFirstScreenPaint&&(r.t7FirstScreen=t.domFirstScreenPaint-e),r},H);function H(){}(E=z=z||{}).JS="js",E.CSS="css",E.IMG="img",E.FONT="font",(j=P=P||{})[j.ttf=0]="ttf",j[j.eot=1]="eot",j[j.woff=2]="woff",j[j.woff2=3]="woff2";var M=["/mwb2.gif"];function N(t,e){for(var i=0,o=e;i<o.length;i++){var n=o[i];if(-1<t.indexOf(n))return!0}return!1}function _(t){return+t.toFixed(1)}var q=(F.prototype.check=function(){return performance&&performance.getEntriesByType},F.prototype.listenResource=function(t,e){void 0===e&&(e={}),this.check()&&(this.resOption=o(this.resOption,e),this.trigger=this.resOption.trigger,this.cb=t)},F.prototype.listenBigImg=function(t,e){void 0===e&&(e={}),this.check()&&(this.bigImgOption=o(this.bigImgOption,e),this.trigger=this.bigImgOption.trigger,this.bigImgCB=t)},F.prototype.listenHttpResource=function(t,e){void 0===e&&(e={}),this.check()&&(this.httpResOption=o(this.httpResOption,e),this.trigger=this.httpResOption.trigger,this.httpResCB=t)},F.prototype.listenSlowResource=function(t,e){void 0===e&&(e={}),this.check()&&(this.slowOption=o(this.slowOption,e),this.trigger=this.slowOption.trigger,this.slowResCB=t)},F.prototype.report=function(){var l=this,t=this.getMetric();if(t){var e=t.metric,i=t.hostMetric;this.cb&&this.cb(e,i)}this.bigImgCB&&"function"==typeof window.requestIdleCallback&&Object.keys(this.bigImgList).length&&window.requestIdleCallback(function(){for(var t=0,e=Object.keys(l.bigImgList);t<e.length;t++)for(var i=e[t],o=0,n=l.bigImgList[i];o<n.length;o++){var r=n[o],s=r.timing,a=r.type;try{var c=document.body.querySelector('img[src="'+s.name+'"]');l.bigImgCB({msg:s.name,dur:s.duration,xpath:d(c).xpath,host:i,type:a})}catch(t){console.error(t)}}}),this.httpResCB&&"function"==typeof window.requestIdleCallback&&Object.keys(this.httpResList).length&&window.requestIdleCallback(function(){for(var t=0,e=Object.keys(l.httpResList);t<e.length;t++)for(var i=e[t],o=0,n=l.httpResList[i];o<n.length;o++){var r=n[o],s=r.timing,a=r.type;try{var c=document.body.querySelector('[src="'+s.name+'"]');l.httpResCB({msg:s.name,dur:s.duration,xpath:d(c).xpath,host:i,type:a})}catch(t){console.error(t)}}}),this.slowResCB&&"function"==typeof window.requestIdleCallback&&Object.keys(this.slowList).length&&window.requestIdleCallback(function(){for(var t=0,e=Object.keys(l.slowList);t<e.length;t++)for(var i=e[t],o=0,n=l.slowList[i];o<n.length;o++){var r=n[o],s=r.timing,a=r.type;try{var c=document.body.querySelector('[src="'+s.name+'"]'),h={wait:f((p=s).domainLookupStart-(p.navigationStart||p.fetchStart||p.startTime)),dns:f(p.domainLookupEnd-p.domainLookupStart),connect:f(p.connectEnd-p.connectStart),req:f(p.responseStart-p.requestStart),res:f(p.responseEnd-p.responseStart)};l.slowResCB(u(u({},h),{dur:s.duration,msg:s.name,xpath:d(c).xpath,host:i,type:a}))}catch(t){console.error(t)}}var p})},F.prototype.load=function(){var t=this;"load"===this.trigger&&this.check()&&setTimeout(function(){t.report()},500)},F.prototype.leave=function(){"leave"===this.trigger&&this.report()},F.prototype.push=function(t,e,i,o){N(o.pathname,this.resOption.ignorePaths||[])||(e.push(i),this.pushWithHost(t,this.hostList,i,o)),N(o.pathname,this.slowOption.ignorePaths||[])||i.duration>this.slowOption.threshold&&this.pushWithHost(t,this.slowList,i,o)},F.prototype.pushWithHost=function(t,e,i,o){var n=o.host;e[n]||(e[n]=[]),e[n].push({timing:i,type:t})},F.prototype.collectHttpResInHttps=function(t,e,i){"https:"!==location.protocol||0!==e.name.indexOf("http://")||N(i.pathname,this.httpResOption.ignorePaths||[])||this.pushWithHost(t,this.httpResList,e,i)},F.prototype.addScript=function(t,e){"js"===e.ext&&0!==t.decodedBodySize&&this.push("js",this.jsList,t,e)},F.prototype.addResFromCss=function(t,e){e.ext&&P.hasOwnProperty(e.ext)?this.push("font",this.fontList,t,e):this.addImg(t,e)},F.prototype.addLink=function(t,e){"css"===e.ext?this.push("css",this.cssList,t,e):"js"===e.ext&&this.push("js",this.jsList,t,e)},F.prototype.addImg=function(t,e){this.push("img",this.imgList,t,e),t.decodedBodySize>(this.bigImgOption.maxSize||0)&&!N(e.pathname,this.bigImgOption.ignorePaths||[])&&this.pushWithHost("img",this.bigImgList,t,e)},F.prototype.handleTimings=function(t){for(var e=t.length,i=0;i<e;i++){var o=t[i],n=r(o.name);if(!N(n.pathname,M))switch(t[i].initiatorType){case"script":this.addScript(o,n);break;case"css":this.addResFromCss(o,n);break;case"img":this.addImg(o,n);break;case"link":this.addLink(o,n);break;case"audio":this.collectHttpResInHttps("audio",o,n);break;case"video":this.collectHttpResInHttps("video",o,n)}}},F.prototype.getNumAndSize=function(t,e){var i={},o=t+"Num",n=t+"Size",r=t+"TransferSize",s=t+"CacheRate",a=t+"Duration";i[o]=0,i[n]=0;var c=i[r]=0;if(e.forEach(function(t){i[o]++,i[n]+=t.decodedBodySize/1024,i[r]+=t.transferSize/1024,c+=t.duration}),i[a]=_(0<i[o]?c/i[o]:0),i[n]){var h=i[n]-i[r];i[s]=_(0<=h?100*h/i[n]:0)}return i[n]=_(i[n]),i[r]=_(i[r]),i},F.prototype.getMetric=function(){var t=performance.getEntriesByType("navigation")[0],e=performance.getEntriesByType("resource");if(t&&e&&e.length){this.handleTimings(e);var i=u(u(u(u({},this.getNumAndSize(z.JS,this.jsList)),this.getNumAndSize(z.CSS,this.cssList)),this.getNumAndSize(z.IMG,this.imgList)),this.getNumAndSize(z.FONT,this.fontList)),o=t;i.docSize=_(o.decodedBodySize/1024),i.docTransferSize=_(o.transferSize/1024),i.headerSize=_((o.transferSize-o.encodedBodySize||0)/1024),i.allSize=_(i.docSize+i.jsSize+i.cssSize+i.imgSize+i.fontSize),i.allTransferSize=_(i.docTransferSize+i.jsTransferSize+i.cssTransferSize+i.imgTransferSize+i.fontTransferSize);for(var n={},r=0,s=Object.keys(this.hostList);r<s.length;r++){var a=s[r],c=this.hostList[a].map(function(t){return t.timing});n[a]=this.getNumAndSize("host",c)}return{metric:i,hostMetric:n}}},F);function F(){this.trigger="load",this.jsList=[],this.cssList=[],this.imgList=[],this.fontList=[],this.hostList={},this.bigImgList={},this.httpResList={},this.slowList={},this.resOption={ignorePaths:[],trigger:"load"},this.bigImgOption={ignorePaths:[],maxSize:153600,trigger:"load"},this.httpResOption={ignorePaths:[],trigger:"load"},this.slowOption={ignorePaths:[],trigger:"load",threshold:1e3}}var A=null;window.performance&&window.performance.memory&&(A=window.performance.memory);var D=(J.prototype.listenMemory=function(t){this.cb=t},J.prototype.leave=function(){if(!this.onceLeave&&A){this.onceLeave=!0;var t=window.performance.memory;if(t.usedJSHeapSize===A.usedJSHeapSize&&t.totalJSHeapSize===A.totalJSHeapSize)return;var e=window.performance.memory;this.cb&&this.cb({usedJSHeapSize:e.usedJSHeapSize/1024,totalJSHeapSize:e.totalJSHeapSize/1024,jsHeapSizeLimit:e.jsHeapSizeLimit/1024,usedJSHeapRate:100*e.usedJSHeapSize/e.totalJSHeapSize})}},J);function J(){this.onceLeave=!1}var V=(Z.prototype.getNavigatorInfo=function(){var t={},e=navigator.connection;return"object"==typeof e&&(t={downlink:e.downlink,effectiveType:e.effectiveType,rtt:e.rtt,saveData:!!e.saveData}),navigator.deviceMemory&&(t.deviceMemory=navigator.deviceMemory),navigator.hardwareConcurrency&&(t.hardwareConcurrency=navigator.deviceMemory),t},Z.prototype.load=function(){},Z);function Z(){}var W,U,G,$=window.__spyHead,K="longtask",Q=(X.prototype.check=function(){return window.PerformanceObserver&&performance&&performance.timing&&performance.timing.navigationStart},X.prototype.listenFSPLongTask=function(t){this.check()&&(this.fspCB=t)},X.prototype.listenLCPLongTask=function(t){this.check()&&(this.lcpCB=t)},X.prototype.listenLoadLongTask=function(t){this.check()&&(this.loadCB=t)},X.prototype.listenPageLongTask=function(t){this.check()&&(this.pageCB=t)},X.prototype.load=function(){var i=this;if(this.check()){var o=this.getStatData(Date.now());setTimeout(function(){if(i.loadCB&&i.loadCB({loadLongtaskTime:o.time,loadTBT:o.tbt,loadTotalTime:o.totalTime,loadLongtaskRate:o.rate,loadLongtaskNum:o.num}),performance.timing&&performance.timing.domFirstScreenPaint){var t=i.getStatData(performance.timing.domFirstScreenPaint);i.fspCB&&i.fspCB({fspLongtaskTime:t.time,fspTBT:t.tbt,fspTotalTime:t.totalTime,fspLongtaskRate:t.rate,fspLongtaskNum:t.num})}if(S("lcp")){var e=i.getStatData(performance.timing.navigationStart+S("lcp"));i.lcpCB&&i.lcpCB({lcpLongtaskTime:e.time,lcpTBT:e.tbt,lcpTotalTime:e.totalTime,lcpLongtaskRate:e.rate,lcpLongtaskNum:e.num})}},200)}},X.prototype.leave=function(){if(!this.onceLeave){this.onceLeave=!0;var t=this.getStatData(Date.now());this.pageCB&&this.pageCB({pageLongtaskTime:t.time,pageTBT:t.tbt,pageTotalTime:t.totalTime,pageLongtaskRate:t.rate,pageLongtaskNum:t.num,pageIframeLongtaskTime:t.iframeTime,pageIframeLongtaskRate:t.iframeRate,pageIframeLongtaskNum:t.iframeNum})}},X.prototype.destroy=function(){this.lts=[],this.observer&&this.observer.disconnect(),this.observer=null},X.prototype.getStatData=function(t){for(var e=performance.timing.navigationStart,i=0,o=0,n=0,r=0,s=0,a={},c=0;c<this.lts.length;c++){var h=this.lts[c],p=h.duration;if(e+h.startTime+p<t&&(i+=p,o+=0<p-50?p-50:0,n++,h.attribution&&h.attribution[0])){var l=h.attribution[0].containerSrc;l&&l!==location.href&&(a[l]||(a[l]=[]),a[l].push(p),r+=p,s++)}}var u=t-e;return{num:n,time:i,tbt:o,totalTime:u,rate:100*i/u,iframeTime:r,iframeNum:s,iframeRate:100*r/u,iframeLongtasks:a}},X);function X(){var e=this;this.lts=[],this.observer=null,this.onceLeave=!1,$&&$.entryMap&&$.entryMap[K]&&(this.lts=this.lts.concat($.entryMap[K]));try{this.observer=new PerformanceObserver(function(t){e.lts=e.lts.concat(t.getEntries())}),this.observer.observe({entryTypes:[K]})}catch(t){}}function Y(){this.constructor=W}function tt(t){var e=G.call(this,t)||this;return e.modules=[],e.register(new g),e.register(new C),e.register(new b),e.register(new R),e.register(new x),e.register(new q),e.register(new D),e.register(new V),e.register(new Q),e.visibilitychangeCB=e.visibilitychangeCB.bind(e),e.load=e.load.bind(e),e.leave=e.leave.bind(e),"complete"===document.readyState?e.load():window.addEventListener("load",e.load),document.addEventListener("visibilitychange",e.visibilitychangeCB),window.addEventListener("beforeunload",e.leave,!1),window.addEventListener("unload",e.leave,!1),e.handleHead(),e}return i(W=tt,U=G=e),void(W.prototype=null===U?Object.create(U):(Y.prototype=U.prototype,new Y)),tt.prototype.handleHead=function(){var e=this;if(this.option.localCache){var t=window.__spyHead;if(t&&t.winerrors){for(var i=0;i<t.winerrors.length;i++){var o=t.winerrors[i];this.option.localCache.addLog(o)}t.interceptor=function(t){e.option.localCache.addLog(t)}}}},tt.prototype.listenFID=function(t){this.invoke("listenFID",t)},tt.prototype.listenLayoutShift=function(t){this.invoke("listenLayoutShift",t)},tt.prototype.listenLCP=function(t){this.invoke("listenLCP",t)},tt.prototype.listenFSPLongTask=function(t){this.invoke("listenFSPLongTask",t)},tt.prototype.listenLCPLongTask=function(t){this.invoke("listenLCPLongTask",t)},tt.prototype.listenLoadLongTask=function(t){this.invoke("listenLoadLongTask",t)},tt.prototype.listenPageLongTask=function(t){this.invoke("listenPageLongTask",t)},tt.prototype.listenMemory=function(t){this.invoke("listenMemory",t)},tt.prototype.getNavigatorInfo=function(){return this.invoke("getNavigatorInfo")},tt.prototype.listenResource=function(t,e){this.invoke("listenResource",t,e)},tt.prototype.listenBigImg=function(t,e){this.invoke("listenBigImg",t,e)},tt.prototype.listenHttpResource=function(t,e){this.invoke("listenHttpResource",t,e)},tt.prototype.listenSlowResource=function(t,e){this.invoke("listenSlowResource",t,e)},tt.prototype.listenTiming=function(t){this.invoke("listenTiming",t)},tt.prototype.listenTTI=function(t,e){this.invoke("listenTTI",t,e)},tt.prototype.invoke=function(t,e,i){for(var o=0;o<this.modules.length;o++){var n=this.modules[o];if("function"==typeof n[t])return n[t].apply(n,[e,i])}console.error("no method",t)},tt.prototype.register=function(t){this.modules.push(t)},tt.prototype.load=function(){for(var t=0;t<this.modules.length;t++){var e=this.modules[t];e.load&&e.load()}},tt.prototype.leave=function(){for(var t=0;t<this.modules.length;t++){var e=this.modules[t];e.leave&&e.leave()}},tt.prototype.destroy=function(){for(var t=0;t<this.modules.length;t++){var e=this.modules[t];e.destroy&&e.destroy()}document.removeEventListener("visibilitychange",this.visibilitychangeCB),window.removeEventListener("load",this.load),window.removeEventListener("beforeunload",this.leave),window.removeEventListener("unload",this.destroy)},tt.prototype.visibilitychangeCB=function(){"hidden"===document.visibilityState&&this.leave()},tt}();
|
|
1
|
+
var SpyClient=(()=>{var i=function(t,e){return(i=Object.setPrototypeOf||({__proto__:[]}instanceof Array?function(t,e){t.__proto__=e}:function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])}))(t,e)},l=function(){return(l=Object.assign||function(t){for(var e,i=1,o=arguments.length;i<o;i++)for(var n in e=arguments[i])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}).apply(this,arguments)};function o(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return(Object.assign||function(t){for(var e,i=1,o=arguments.length;i<o;i++)for(var n in e=arguments[i])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}).apply(this,t)}function M(t){var e,i=(t=>{if(URL&&t)try{var e=new URL(t);if(void 0!==e.host)return{protocol:e.protocol,host:e.host,pathname:e.pathname,ext:""}}catch(t){console.error(t)}})(t),t=(i||((e=document.createElement("a")).href=t,i={protocol:e.protocol,host:e.host||location.host,pathname:e.pathname,ext:""}),i.pathname.split("."));return i.ext=t[t.length-1],i}function u(t){return+t.toFixed(1)}function d(t){if(!t)return{xpath:""};for(var e=[];t&&1===t.nodeType&&t!==t.parentNode;){var i=t.tagName.toLowerCase();if(t.getAttribute("id")?i+="[#"+t.getAttribute("id")+"]":t.classList&&t.classList.length&&(i+="[."+t.classList[t.classList.length-1]+"]"),e.push(i),t===document.body)break;t=t.parentNode}return{xpath:e.join("<")}}var t=navigator&&navigator.userAgent?navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/):"",N=t&&t[2]&&+t[2]<14;function f(t){console.error("[SpyClient_log]".concat(t))}function s(i){return Object.keys(i).map(function(t){var e=i[t];return void 0===e?e="":"string"!=typeof e&&(e=JSON.stringify(e)),encodeURIComponent(t)+"="+encodeURIComponent(e)}).join("&")}function a(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?"}}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 i=[],o=0,n=a(t)?t:[t];o<n.length;o++){var r=n[o];(r=this.handle(r))&&(i.push(r),e||(r=this.option.logServer+s(r),this.request(r)))}e&&this.sendPost(i)},e.prototype.check=function(t){if(this.option.check){var e=["perf","except","dist","count"];if(-1===e.indexOf(t.type))return f("type only is one of "+e.join(", ")),!1;if(t.group&&30<t.group.length)return f("group length execeeds 30"),!1;var i=/^[a-zA-Z0-9-_]{0,30}$/;if("except"===t.type){if("string"!=typeof t.info.msg||!t.info.msg.length)return f("info.msg field must be not empty and is String"),!1}else for(var o=0,n=Object.keys(t.info);o<n.length;o++){var r=n[o];if(!i.test(r))return f("info.".concat(r," is unexpected. ")+"Length must be not more than 30. Supported chars: a-zA-Z0-9-_"),!1;var s=t.info[r];if("dist"===t.type){if(30<s.length)return f("info.".concat(r," value length execeeds 30 when type == 'dist'")),!1}else if("number"!=typeof s)return f("info.".concat(r," value must be number")),!1}if(t.dim)for(var a=0,c=Object.keys(t.dim);a<c.length;a++){var h=c[a];if(!i.test(h))return f("dim key [".concat(h,"] is unexpected. ")+"Length must be not more than 30. Supported chars: a-zA-Z0-9-_"),!1;var p=t.dim[h];if(!/^[a-zA-Z0-9\-_\*\.\s\/#\+@\&\u4e00-\u9fa5]{0,30}$/.test(p))return f("dim.".concat(h," value [").concat(p,"] 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 i=o({},e);i.info=o({},e.info||{},{msg:t.message,stack:t.stack}),this.sendExcept(i)},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,i=Object.keys(this.markCache);e<i.length;e++){var o=i[e];t[o]=this.markCache[o].total}return t},e.prototype.clearAllMark=function(){this.markCache={}},e.prototype.sendPost=function(t){var e=(a(t)?t:[t])[0],e={pid:e.pid,type:e.type,group:e.group},e=this.option.logServer+s(e);this.request(e,t)},e.prototype.request=function(t,e){!N&&navigator&&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){fetch?fetch(t,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}):f("Global fetch method doesn't exist")},t=e;var n=window.__spyHead,r="first-input",_=(c.prototype.listenFID=function(t){this.cb=t,this.callCB()},c.prototype.callCB=function(){void 0!==this.finalValue&&this.cb&&this.cb({fid:this.finalValue})},c.prototype.destroy=function(){this.observer&&this.observer.disconnect(),this.observer=null},c.prototype.handle=function(t){t=t.pop();t&&(this.finalValue=t.duration,this.callCB(),this.destroy())},c);function c(){var e=this;if(this.observer=null,window.PerformanceObserver){n&&n.entryMap&&n.entryMap[r]&&this.handle(n.entryMap[r]);try{this.observer=new PerformanceObserver(function(t){e.handle(t.getEntries())}),this.observer.observe({entryTypes:[r]})}catch(t){}}}var h=window.__spyHead,p="layout-shift",q=(g.prototype.listenLayoutShift=function(t){this.cb=t},g.prototype.leave=function(){this.onceLeave||(this.onceLeave=!0,this.observer&&this.observer.takeRecords&&this.observer.takeRecords(),this.finalValue=this.value,this.callCB(),this.destroy())},g.prototype.callCB=function(){void 0!==this.finalValue&&this.cb&&this.cb({layoutShift:this.finalValue})},g.prototype.destroy=function(){this.observer&&this.observer.disconnect(),this.observer=null},g.prototype.handle=function(t){var e=this;t.map(function(t){t.hadRecentInput||(e.value=(e.value||0)+(t.value||0))})},g);function g(){var e=this;if(this.observer=null,this.onceLeave=!1,window.PerformanceObserver){h&&h.entryMap&&h.entryMap[p]&&this.handle(h.entryMap[p]);try{this.observer=new PerformanceObserver(function(t){e.handle(t.getEntries())}),this.observer.observe({entryTypes:[p]})}catch(t){}}}var m={},v=window.__spyHead,y="largest-contentful-paint",F=(b.prototype.listenLCP=function(t){this.cb=t,this.callCB()},b.prototype.callCB=function(){this.finalValue&&this.cb&&this.cb({lcp:this.finalValue})},b.prototype.load=function(){var t,e;this.observer&&this.observer.takeRecords&&this.observer.takeRecords(),this.finalValue=this.value,t="lcp",e=this.value,m[t]=e,this.callCB(),this.destroy()},b.prototype.destroy=function(){this.observer&&this.observer.disconnect(),this.observer=null},b.prototype.handle=function(t){var e=this;t.map(function(t){e.value=t.renderTime||t.loadTime})},b);function b(){var e=this;if(this.observer=null,window.PerformanceObserver){v&&v.entryMap&&v.entryMap[y]&&this.handle(v.entryMap[y]);try{this.observer=new PerformanceObserver(function(t){e.handle(t.getEntries())}),this.observer.observe({entryTypes:[y]})}catch(t){}}}function A(t){return t.name.indexOf(".gif?")<0}k.prototype.check=function(){return window.PerformanceObserver&&performance&&performance.timing&&performance.timing.navigationStart},k.prototype.listenTTI=function(t,e){this.check()&&(this.observeLongtask(2e4),this.cb=t,(e=e||{}).interval&&(this.interval=e.interval),e.filterRequest)&&(this.filterRequest=e.filterRequest)},k.prototype.load=function(){this.check()&&(this.ttiTimer=setInterval(this.ttiCheck,this.interval))},k.prototype.ttiCheck=function(){var t,e;!this.cb||(e=performance.now())-this.lastLongTask<this.interval||!1===(t=this.getNetworkSilenceAt())||e-t<this.interval||(clearTimeout(this.ttiTimer),e=(e=this.lastLongTask)||performance.timing.domContentLoadedEventEnd-performance.timing.navigationStart,this.stopObserveLongTask(),this.cb({tti:e}))},k.prototype.observerCallback=function(t){t=t.getEntries(),t=t[t.length-1];this.lastLongTask=t.startTime+t.duration},k.prototype.stopObserveLongTask=function(){this.observer&&(this.observer.disconnect(),this.observer=null),this.stopLongTaskTimeoutId&&clearTimeout(this.stopLongTaskTimeoutId)},k.prototype.getNetworkSilenceAt=function(){for(var t=0,e=0,i=performance.getEntriesByType("resource").filter(this.filterRequest);e<i.length;e++){var o=i[e];if(!o.responseEnd)return!1;t<o.responseEnd&&(t=o.responseEnd)}return t},k.prototype.observeLongtask=function(t){this.stopObserveLongTask();try{this.observer=new PerformanceObserver(this.observerCallback),this.observer.observe({entryTypes:["longtask"]}),this.stopLongTaskTimeoutId=setTimeout(this.stopObserveLongTask,t)}catch(t){}};var D=k;function k(){this.lastLongTask=0,this.observer=null,this.interval=5e3,this.filterRequest=A,this.observerCallback=this.observerCallback.bind(this),this.ttiCheck=this.ttiCheck.bind(this)}w.prototype.listenTiming=function(t){window.performance&&window.performance.timing&&(this.cb=t)},w.prototype.load=function(){var t=this;setTimeout(function(){t.cb&&t.cb(t.getMetric())},500)},w.prototype.getMetric=function(){var t,i={},e=window.performance.timing,o=e.navigationStart;return i.dns=e.domainLookupEnd-e.domainLookupStart,i.tcp=e.connectEnd-e.connectStart,i.request=e.responseStart-e.requestStart,i.response=e.responseEnd-e.responseStart,i.parseHtml=e.domInteractive-e.domLoading,i.domReady=e.domContentLoadedEventEnd-o,i.loadEventHandle=e.loadEventEnd-e.loadEventStart,i.load=e.loadEventEnd-o,performance.getEntriesByType&&(t=performance.getEntriesByType("paint"))&&t.length&&t.forEach(function(t){var e=t.name,t=Math.ceil(t.duration+t.startTime);"first-paint"===e&&(i.fp=t),"first-contentful-paint"===e&&(i.fcp=t)}),e.domFirstPaint&&(i.t7FirstPaint=e.domFirstPaint-o),e.domFirstScreenPaint&&(i.t7FirstScreen=e.domFirstScreenPaint-o),i};var L,S,J=w;function w(){}(E=L=L||{}).JS="js",E.CSS="css",E.IMG="img",E.FONT="font",(E=S=S||{})[E.ttf=0]="ttf",E[E.eot=1]="eot",E[E.woff=2]="woff",E[E.woff2=3]="woff2";var V=["/mwb2.gif"];function T(t,e){for(var i=0,o=e;i<o.length;i++){var n=o[i];if(-1<t.indexOf(n))return 1}}function C(t){return+t.toFixed(1)}O.prototype.check=function(){return performance&&performance.getEntriesByType},O.prototype.listenResource=function(t,e){void 0===e&&(e={}),this.check()&&(this.resOption=o(this.resOption,e),this.trigger=this.resOption.trigger,this.cb=t)},O.prototype.listenBigImg=function(t,e){void 0===e&&(e={}),this.check()&&(this.bigImgOption=o(this.bigImgOption,e),this.trigger=this.bigImgOption.trigger,this.bigImgCB=t)},O.prototype.listenHttpResource=function(t,e){void 0===e&&(e={}),this.check()&&(this.httpResOption=o(this.httpResOption,e),this.trigger=this.httpResOption.trigger,this.httpResCB=t)},O.prototype.listenSlowResource=function(t,e){void 0===e&&(e={}),this.check()&&(this.slowOption=o(this.slowOption,e),this.trigger=this.slowOption.trigger,this.slowResCB=t)},O.prototype.report=function(){var t,p=this,e=this.getMetric();e&&(t=e.metric,e=e.hostMetric,this.cb)&&this.cb(t,e),this.bigImgCB&&"function"==typeof window.requestIdleCallback&&Object.keys(this.bigImgList).length&&window.requestIdleCallback(function(){for(var t=0,e=Object.keys(p.bigImgList);t<e.length;t++)for(var i=e[t],o=0,n=p.bigImgList[i];o<n.length;o++){var r=n[o],s=r.timing,r=r.type;try{var a=document.body.querySelector('img[src="'+s.name+'"]');p.bigImgCB({msg:s.name,dur:s.duration,xpath:d(a).xpath,host:i,type:r})}catch(t){console.error(t)}}}),this.httpResCB&&"function"==typeof window.requestIdleCallback&&Object.keys(this.httpResList).length&&window.requestIdleCallback(function(){for(var t=0,e=Object.keys(p.httpResList);t<e.length;t++)for(var i=e[t],o=0,n=p.httpResList[i];o<n.length;o++){var r=n[o],s=r.timing,r=r.type;try{var a=document.body.querySelector('[src="'+s.name+'"]');p.httpResCB({msg:s.name,dur:s.duration,xpath:d(a).xpath,host:i,type:r})}catch(t){console.error(t)}}}),this.slowResCB&&"function"==typeof window.requestIdleCallback&&Object.keys(this.slowList).length&&window.requestIdleCallback(function(){for(var t,e=0,i=Object.keys(p.slowList);e<i.length;e++)for(var o=i[e],n=0,r=p.slowList[o];n<r.length;n++){var s=r[n],a=s.timing,s=s.type;try{var c=document.body.querySelector('[src="'+a.name+'"]'),h={wait:u((t=a).domainLookupStart-(t.navigationStart||t.fetchStart||t.startTime)),dns:u(t.domainLookupEnd-t.domainLookupStart),connect:u(t.connectEnd-t.connectStart),req:u(t.responseStart-t.requestStart),res:u(t.responseEnd-t.responseStart)};p.slowResCB(l(l({},h),{dur:a.duration,msg:a.name,xpath:d(c).xpath,host:o,type:s}))}catch(t){console.error(t)}}})},O.prototype.load=function(){var t=this;"load"===this.trigger&&this.check()&&setTimeout(function(){t.report()},500)},O.prototype.leave=function(){"leave"===this.trigger&&this.report()},O.prototype.push=function(t,e,i,o){T(o.pathname,this.resOption.ignorePaths||[])||(e.push(i),this.pushWithHost(t,this.hostList,i,o)),T(o.pathname,this.slowOption.ignorePaths||[])||i.duration>this.slowOption.threshold&&this.pushWithHost(t,this.slowList,i,o)},O.prototype.pushWithHost=function(t,e,i,o){o=o.host;e[o]||(e[o]=[]),e[o].push({timing:i,type:t})},O.prototype.collectHttpResInHttps=function(t,e,i){"https:"!==location.protocol||0!==e.name.indexOf("http://")||T(i.pathname,this.httpResOption.ignorePaths||[])||this.pushWithHost(t,this.httpResList,e,i)},O.prototype.addScript=function(t,e){"js"===e.ext&&0!==t.decodedBodySize&&this.push("js",this.jsList,t,e)},O.prototype.addResFromCss=function(t,e){e.ext&&S.hasOwnProperty(e.ext)?this.push("font",this.fontList,t,e):this.addImg(t,e)},O.prototype.addLink=function(t,e){"css"===e.ext?this.push("css",this.cssList,t,e):"js"===e.ext&&this.push("js",this.jsList,t,e)},O.prototype.addImg=function(t,e){this.push("img",this.imgList,t,e),t.decodedBodySize>(this.bigImgOption.maxSize||0)&&!T(e.pathname,this.bigImgOption.ignorePaths||[])&&this.pushWithHost("img",this.bigImgList,t,e)},O.prototype.handleTimings=function(t){for(var e=t.length,i=0;i<e;i++){var o=t[i],n=M(o.name);if(!T(n.pathname,V))switch(t[i].initiatorType){case"script":this.addScript(o,n);break;case"css":this.addResFromCss(o,n);break;case"img":this.addImg(o,n);break;case"link":this.addLink(o,n);break;case"audio":this.collectHttpResInHttps("audio",o,n);break;case"video":this.collectHttpResInHttps("video",o,n)}}},O.prototype.getNumAndSize=function(t,e){var i={},o=t+"Num",n=t+"Size",r=t+"TransferSize",s=t+"CacheRate",t=t+"Duration",a=(i[o]=0,i[n]=0,i[r]=0);return e.forEach(function(t){i[o]++,i[n]+=t.decodedBodySize/1024,i[r]+=t.transferSize/1024,a+=t.duration}),i[t]=C(0<i[o]?a/i[o]:0),i[n]&&(i[s]=C(0<=(e=i[n]-i[r])?100*e/i[n]:0)),i[n]=C(i[n]),i[r]=C(i[r]),i},O.prototype.getMetric=function(){var t=performance.getEntriesByType("navigation")[0],e=performance.getEntriesByType("resource");if(t&&e&&e.length){this.handleTimings(e);for(var e=l(l(l(l({},this.getNumAndSize(L.JS,this.jsList)),this.getNumAndSize(L.CSS,this.cssList)),this.getNumAndSize(L.IMG,this.imgList)),this.getNumAndSize(L.FONT,this.fontList)),i=(e.docSize=C(t.decodedBodySize/1024),e.docTransferSize=C(t.transferSize/1024),e.headerSize=C((t.transferSize-t.encodedBodySize||0)/1024),e.allSize=C(e.docSize+e.jsSize+e.cssSize+e.imgSize+e.fontSize),e.allTransferSize=C(e.docTransferSize+e.jsTransferSize+e.cssTransferSize+e.imgTransferSize+e.fontTransferSize),{}),o=0,n=Object.keys(this.hostList);o<n.length;o++){var r=n[o],s=this.hostList[r].map(function(t){return t.timing});i[r]=this.getNumAndSize("host",s)}return{metric:e,hostMetric:i}}};var Z=O;function O(){this.trigger="load",this.jsList=[],this.cssList=[],this.imgList=[],this.fontList=[],this.hostList={},this.bigImgList={},this.httpResList={},this.slowList={},this.resOption={ignorePaths:[],trigger:"load"},this.bigImgOption={ignorePaths:[],maxSize:153600,trigger:"load"},this.httpResOption={ignorePaths:[],trigger:"load"},this.slowOption={ignorePaths:[],trigger:"load",threshold:1e3}}var B=null,W=(window.performance&&window.performance.memory&&(B=window.performance.memory),R.prototype.listenMemory=function(t){this.cb=t},R.prototype.leave=function(){var t;!this.onceLeave&&B&&(this.onceLeave=!0,(t=window.performance.memory).usedJSHeapSize===B.usedJSHeapSize&&t.totalJSHeapSize===B.totalJSHeapSize||(t=window.performance.memory,this.cb&&this.cb({usedJSHeapSize:t.usedJSHeapSize/1024,totalJSHeapSize:t.totalJSHeapSize/1024,jsHeapSizeLimit:t.jsHeapSizeLimit/1024,usedJSHeapRate:100*t.usedJSHeapSize/t.totalJSHeapSize})))},R);function R(){this.onceLeave=!1}I.prototype.getNavigatorInfo=function(){var t={},e=navigator.connection;return"object"==typeof e&&(t={downlink:e.downlink,effectiveType:e.effectiveType,rtt:e.rtt,saveData:!!e.saveData}),navigator.deviceMemory&&(t.deviceMemory=navigator.deviceMemory),navigator.hardwareConcurrency&&(t.hardwareConcurrency=navigator.deviceMemory),t},I.prototype.load=function(){};var U=I;function I(){}var G,z,E,P=window.__spyHead,j="longtask",$=(x.prototype.check=function(){return window.PerformanceObserver&&performance&&performance.timing&&performance.timing.navigationStart},x.prototype.listenFSPLongTask=function(t){this.check()&&(this.fspCB=t)},x.prototype.listenLCPLongTask=function(t){this.check()&&(this.lcpCB=t)},x.prototype.listenLoadLongTask=function(t){this.check()&&(this.loadCB=t)},x.prototype.listenPageLongTask=function(t){this.check()&&(this.pageCB=t)},x.prototype.load=function(){var e,i=this;this.check()&&(e=this.getStatData(Date.now()),setTimeout(function(){var t;i.loadCB&&i.loadCB({loadLongtaskTime:e.time,loadTBT:e.tbt,loadTotalTime:e.totalTime,loadLongtaskRate:e.rate,loadLongtaskNum:e.num}),performance.timing&&performance.timing.domFirstScreenPaint&&(t=i.getStatData(performance.timing.domFirstScreenPaint),i.fspCB)&&i.fspCB({fspLongtaskTime:t.time,fspTBT:t.tbt,fspTotalTime:t.totalTime,fspLongtaskRate:t.rate,fspLongtaskNum:t.num}),m.lcp&&(t=i.getStatData(performance.timing.navigationStart+m.lcp),i.lcpCB)&&i.lcpCB({lcpLongtaskTime:t.time,lcpTBT:t.tbt,lcpTotalTime:t.totalTime,lcpLongtaskRate:t.rate,lcpLongtaskNum:t.num})},200))},x.prototype.leave=function(){var t;this.onceLeave||(this.onceLeave=!0,t=this.getStatData(Date.now()),this.pageCB&&this.pageCB({pageLongtaskTime:t.time,pageTBT:t.tbt,pageTotalTime:t.totalTime,pageLongtaskRate:t.rate,pageLongtaskNum:t.num,pageIframeLongtaskTime:t.iframeTime,pageIframeLongtaskRate:t.iframeRate,pageIframeLongtaskNum:t.iframeNum}))},x.prototype.destroy=function(){this.lts=[],this.observer&&this.observer.disconnect(),this.observer=null},x.prototype.getStatData=function(t){for(var e=performance.timing.navigationStart,i=0,o=0,n=0,r=0,s=0,a={},c=0;c<this.lts.length;c++){var h=this.lts[c],p=h.duration;e+h.startTime+p<t&&(i+=p,o+=0<p-50?p-50:0,n++,h.attribution)&&h.attribution[0]&&(h=h.attribution[0].containerSrc)&&h!==location.href&&(a[h]||(a[h]=[]),a[h].push(p),r+=p,s++)}var l=t-e;return{num:n,time:i,tbt:o,totalTime:l,rate:100*i/l,iframeTime:r,iframeNum:s,iframeRate:100*r/l,iframeLongtasks:a}},x);function x(){var e=this;this.lts=[],this.observer=null,this.onceLeave=!1,P&&P.entryMap&&P.entryMap[j]&&(this.lts=this.lts.concat(P.entryMap[j]));try{this.observer=new PerformanceObserver(function(t){e.lts=e.lts.concat(t.getEntries())}),this.observer.observe({entryTypes:[j]})}catch(t){}}function K(){this.constructor=z}function H(t){t=G.call(this,t)||this;return t.modules=[],t.register(new _),t.register(new F),t.register(new q),t.register(new D),t.register(new J),t.register(new Z),t.register(new W),t.register(new U),t.register(new $),t.visibilitychangeCB=t.visibilitychangeCB.bind(t),t.load=t.load.bind(t),t.leave=t.leave.bind(t),"complete"===document.readyState?t.load():window.addEventListener("load",t.load),document.addEventListener("visibilitychange",t.visibilitychangeCB),window.addEventListener("beforeunload",t.leave,!1),window.addEventListener("unload",t.leave,!1),t.handleHead(),t}return i(z=H,E=G=t),z.prototype=null===E?Object.create(E):(K.prototype=E.prototype,new K),H.prototype.handleHead=function(){var e=this;if(this.option.localCache){var t=window.__spyHead;if(t&&t.winerrors){for(var i=0;i<t.winerrors.length;i++){var o=t.winerrors[i];this.option.localCache.addLog(o)}t.interceptor=function(t){e.option.localCache.addLog(t)}}}},H.prototype.listenFID=function(t){this.invoke("listenFID",t)},H.prototype.listenLayoutShift=function(t){this.invoke("listenLayoutShift",t)},H.prototype.listenLCP=function(t){this.invoke("listenLCP",t)},H.prototype.listenFSPLongTask=function(t){this.invoke("listenFSPLongTask",t)},H.prototype.listenLCPLongTask=function(t){this.invoke("listenLCPLongTask",t)},H.prototype.listenLoadLongTask=function(t){this.invoke("listenLoadLongTask",t)},H.prototype.listenPageLongTask=function(t){this.invoke("listenPageLongTask",t)},H.prototype.listenMemory=function(t){this.invoke("listenMemory",t)},H.prototype.getNavigatorInfo=function(){return this.invoke("getNavigatorInfo")},H.prototype.listenResource=function(t,e){this.invoke("listenResource",t,e)},H.prototype.listenBigImg=function(t,e){this.invoke("listenBigImg",t,e)},H.prototype.listenHttpResource=function(t,e){this.invoke("listenHttpResource",t,e)},H.prototype.listenSlowResource=function(t,e){this.invoke("listenSlowResource",t,e)},H.prototype.listenTiming=function(t){this.invoke("listenTiming",t)},H.prototype.listenTTI=function(t,e){this.invoke("listenTTI",t,e)},H.prototype.invoke=function(t,e,i){for(var o=0;o<this.modules.length;o++){var n=this.modules[o];if("function"==typeof n[t])return n[t].apply(n,[e,i])}console.error("no method",t)},H.prototype.register=function(t){this.modules.push(t)},H.prototype.load=function(){for(var t=0;t<this.modules.length;t++){var e=this.modules[t];e.load&&e.load()}},H.prototype.leave=function(){for(var t=0;t<this.modules.length;t++){var e=this.modules[t];e.leave&&e.leave()}},H.prototype.destroy=function(){for(var t=0;t<this.modules.length;t++){var e=this.modules[t];e.destroy&&e.destroy()}document.removeEventListener("visibilitychange",this.visibilitychangeCB),window.removeEventListener("load",this.load),window.removeEventListener("beforeunload",this.leave),window.removeEventListener("unload",this.destroy)},H.prototype.visibilitychangeCB=function(){"hidden"===document.visibilityState&&this.leave()},H})();
|
package/dist/spy-client.js
CHANGED
|
@@ -2,21 +2,21 @@
|
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(factory) :
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.SpyClient = factory());
|
|
5
|
-
}(this, (function () { 'use strict';
|
|
5
|
+
})(this, (function () { 'use strict';
|
|
6
6
|
|
|
7
7
|
/*! *****************************************************************************
|
|
8
|
-
Copyright (c) Microsoft Corporation.
|
|
9
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
10
|
-
this file except in compliance with the License. You may obtain a copy of the
|
|
11
|
-
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
Copyright (c) Microsoft Corporation.
|
|
12
9
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
16
|
-
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
10
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
11
|
+
purpose with or without fee is hereby granted.
|
|
17
12
|
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
14
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
15
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
16
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
17
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
18
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
19
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
20
20
|
***************************************************************************** */
|
|
21
21
|
/* global Reflect, Promise */
|
|
22
22
|
|
|
@@ -147,7 +147,7 @@
|
|
|
147
147
|
var ver = navigator && navigator.userAgent ? navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/) : '';
|
|
148
148
|
var isLtIos14 = ver && ver[2] && (+ver[2] < 14);
|
|
149
149
|
function err(msg) {
|
|
150
|
-
console.error("[SpyClient_log]"
|
|
150
|
+
console.error("[SpyClient_log]".concat(msg));
|
|
151
151
|
// throw new Error(msg);
|
|
152
152
|
}
|
|
153
153
|
function stringify(obj) {
|
|
@@ -252,7 +252,7 @@
|
|
|
252
252
|
for (var _i = 0, _a = Object.keys(query.info); _i < _a.length; _i++) {
|
|
253
253
|
var infoKey = _a[_i];
|
|
254
254
|
if (!simpleReg.test(infoKey)) {
|
|
255
|
-
err("info."
|
|
255
|
+
err("info.".concat(infoKey, " is unexpected. ")
|
|
256
256
|
+ 'Length must be not more than 30. '
|
|
257
257
|
+ 'Supported chars: a-zA-Z0-9-_');
|
|
258
258
|
return false;
|
|
@@ -260,12 +260,12 @@
|
|
|
260
260
|
var infoVal = query.info[infoKey];
|
|
261
261
|
if (query.type === 'dist') {
|
|
262
262
|
if (infoVal.length > 30) {
|
|
263
|
-
err("info."
|
|
263
|
+
err("info.".concat(infoKey, " value length execeeds 30 when type == 'dist'"));
|
|
264
264
|
return false;
|
|
265
265
|
}
|
|
266
266
|
}
|
|
267
267
|
else if (typeof infoVal !== 'number') {
|
|
268
|
-
err("info."
|
|
268
|
+
err("info.".concat(infoKey, " value must be number"));
|
|
269
269
|
return false;
|
|
270
270
|
}
|
|
271
271
|
}
|
|
@@ -274,14 +274,14 @@
|
|
|
274
274
|
for (var _b = 0, _c = Object.keys(query.dim); _b < _c.length; _b++) {
|
|
275
275
|
var dimKey = _c[_b];
|
|
276
276
|
if (!simpleReg.test(dimKey)) {
|
|
277
|
-
err("dim key ["
|
|
277
|
+
err("dim key [".concat(dimKey, "] is unexpected. ")
|
|
278
278
|
+ 'Length must be not more than 30. '
|
|
279
279
|
+ 'Supported chars: a-zA-Z0-9-_');
|
|
280
280
|
return false;
|
|
281
281
|
}
|
|
282
282
|
var dimVal = query.dim[dimKey];
|
|
283
283
|
if (!/^[a-zA-Z0-9\-_\*\.\s\/#\+@\&\u4e00-\u9fa5]{0,30}$/.test(dimVal)) {
|
|
284
|
-
err("dim."
|
|
284
|
+
err("dim.".concat(dimKey, " value [").concat(dimVal, "] is unexpected. ")
|
|
285
285
|
+ 'Length must be not more than 30. '
|
|
286
286
|
+ 'Supported chars: a-zA-Z0-9-_*. /#+@& and Chinese');
|
|
287
287
|
return false;
|
|
@@ -1490,4 +1490,4 @@
|
|
|
1490
1490
|
|
|
1491
1491
|
return SpyClient;
|
|
1492
1492
|
|
|
1493
|
-
}))
|
|
1493
|
+
}));
|
package/dist/spy-client.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).SpyClient=e()}(this,function(){"use strict";var i=function(t,e){return(i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])})(t,e)};var u=function(){return(u=Object.assign||function(t){for(var e,i=1,o=arguments.length;i<o;i++)for(var n in e=arguments[i])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}).apply(this,arguments)};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,i=1,o=arguments.length;i<o;i++)for(var n in e=arguments[i])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}).apply(this,t)}function r(t){var e=function(t){if(URL&&t)try{var e=new URL(t);if(void 0!==e.host)return{protocol:e.protocol,host:e.host,pathname:e.pathname,ext:""}}catch(t){console.error(t)}}(t);if(!e){var i=document.createElement("a");i.href=t,e={protocol:i.protocol,host:i.host||location.host,pathname:i.pathname,ext:""}}var o=e.pathname.split(".");return e.ext=o[o.length-1],e}function f(t){return+t.toFixed(1)}function d(t){if(!t)return{xpath:""};for(var e=[];t&&1===t.nodeType&&t!==t.parentNode;){var i=t.tagName.toLowerCase();if(t.getAttribute("id")?i+="[#"+t.getAttribute("id")+"]":t.classList&&t.classList.length&&(i+="[."+t.classList[t.classList.length-1]+"]"),e.push(i),t===document.body)break;t=t.parentNode}return{xpath:e.join("<")}}var t=navigator&&navigator.userAgent?navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/):"",n=t&&t[2]&&+t[2]<14;function l(t){console.error("[SpyClient_log]"+t)}function a(i){return Object.keys(i).map(function(t){var e=i[t];return void 0===e?e="":"string"!=typeof e&&(e=JSON.stringify(e)),encodeURIComponent(t)+"="+encodeURIComponent(e)}).join("&")}function c(t){return"[object Array]"===Object.prototype.toString.call(t)}var e=(s.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}},s.prototype.send=function(t,e){void 0===e&&(e=!1);for(var i=[],o=0,n=c(t)?t:[t];o<n.length;o++){var r=n[o];if((r=this.handle(r))&&(i.push(r),!e)){var s=this.option.logServer+a(r);this.request(s)}}e&&this.sendPost(i)},s.prototype.check=function(t){if(!this.option.check)return!0;var e=["perf","except","dist","count"];if(-1===e.indexOf(t.type))return l("type only is one of "+e.join(", ")),!1;if(t.group&&30<t.group.length)return l("group length execeeds 30"),!1;var i=/^[a-zA-Z0-9-_]{0,30}$/;if("except"===t.type){if("string"!=typeof t.info.msg||!t.info.msg.length)return l("info.msg field must be not empty and is String"),!1}else for(var o=0,n=Object.keys(t.info);o<n.length;o++){var r=n[o];if(!i.test(r))return l("info."+r+" is unexpected. Length must be not more than 30. Supported chars: a-zA-Z0-9-_"),!1;var s=t.info[r];if("dist"===t.type){if(30<s.length)return l("info."+r+" value length execeeds 30 when type == 'dist'"),!1}else if("number"!=typeof s)return l("info."+r+" value must be number"),!1}if(t.dim)for(var a=0,c=Object.keys(t.dim);a<c.length;a++){var h=c[a];if(!i.test(h))return l("dim key ["+h+"] is unexpected. Length must be not more than 30. Supported chars: a-zA-Z0-9-_"),!1;var p=t.dim[h];if(!/^[a-zA-Z0-9\-_\*\.\s\/#\+@\&\u4e00-\u9fa5]{0,30}$/.test(p))return l("dim."+h+" value ["+p+"] is unexpected. Length must be not more than 30. Supported chars: a-zA-Z0-9-_*. /#+@& and Chinese"),!1}return!0},s.prototype.sendPerf=function(t){this.send(o({type:"perf"},t))},s.prototype.sendExcept=function(t){this.send(o({type:"except"},t))},s.prototype.sendDist=function(t){this.send(o({type:"dist"},t))},s.prototype.sendCount=function(t){this.send(o({type:"count"},t))},s.prototype.sendExceptForError=function(t,e){var i=o({},e);i.info=o({},e.info||{},{msg:t.message,stack:t.stack}),this.sendExcept(i)},s.prototype.startMark=function(t){this.markCache[t]={start:Date.now()}},s.prototype.endMark=function(t){return this.markCache[t]?(this.markCache[t].total=Date.now()-this.markCache[t].start,this.markCache[t].total):0},s.prototype.clearMark=function(t){this.markCache[t]&&delete this.markCache[t]},s.prototype.getAllMark=function(){for(var t={},e=0,i=Object.keys(this.markCache);e<i.length;e++){var o=i[e];t[o]=this.markCache[o].total}return t},s.prototype.clearAllMark=function(){this.markCache={}},s.prototype.sendPost=function(t){var e=(c(t)?t:[t])[0],i={pid:e.pid,type:e.type,group:e.group},o=this.option.logServer+a(i);this.request(o,t)},s.prototype.request=function(t,e){!n&&navigator&&navigator.sendBeacon&&navigator.sendBeacon(t,e?JSON.stringify(e):void 0)||(e?this.fetch(t,e):(new Image).src=t)},s.prototype.fetch=function(t,e){fetch?fetch(t,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}):l("Global fetch method doesn't exist")},s);function s(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?"}}var h=window.__spyHead,p="first-input",g=(m.prototype.listenFID=function(t){this.cb=t,this.callCB()},m.prototype.callCB=function(){void 0!==this.finalValue&&this.cb&&this.cb({fid:this.finalValue})},m.prototype.destroy=function(){this.observer&&this.observer.disconnect(),this.observer=null},m.prototype.handle=function(t){var e=t.pop();e&&(this.finalValue=e.duration,this.callCB(),this.destroy())},m);function m(){var e=this;if(this.observer=null,window.PerformanceObserver){h&&h.entryMap&&h.entryMap[p]&&this.handle(h.entryMap[p]);try{this.observer=new PerformanceObserver(function(t){e.handle(t.getEntries())}),this.observer.observe({entryTypes:[p]})}catch(t){}}}var v=window.__spyHead,y="layout-shift",b=(k.prototype.listenLayoutShift=function(t){this.cb=t},k.prototype.leave=function(){this.onceLeave||(this.onceLeave=!0,this.observer&&this.observer.takeRecords&&this.observer.takeRecords(),this.finalValue=this.value,this.callCB(),this.destroy())},k.prototype.callCB=function(){void 0!==this.finalValue&&this.cb&&this.cb({layoutShift:this.finalValue})},k.prototype.destroy=function(){this.observer&&this.observer.disconnect(),this.observer=null},k.prototype.handle=function(t){var e=this;t.map(function(t){t.hadRecentInput||(e.value=(e.value||0)+(t.value||0))})},k);function k(){var e=this;if(this.observer=null,this.onceLeave=!1,window.PerformanceObserver){v&&v.entryMap&&v.entryMap[y]&&this.handle(v.entryMap[y]);try{this.observer=new PerformanceObserver(function(t){e.handle(t.getEntries())}),this.observer.observe({entryTypes:[y]})}catch(t){}}}var L={};function S(t){return L[t]}var w=window.__spyHead,T="largest-contentful-paint",C=(O.prototype.listenLCP=function(t){this.cb=t,this.callCB()},O.prototype.callCB=function(){this.finalValue&&this.cb&&this.cb({lcp:this.finalValue})},O.prototype.load=function(){this.observer&&this.observer.takeRecords&&this.observer.takeRecords(),this.finalValue=this.value,function(t,e){L[t]=e}("lcp",this.value),this.callCB(),this.destroy()},O.prototype.destroy=function(){this.observer&&this.observer.disconnect(),this.observer=null},O.prototype.handle=function(t){var e=this;t.map(function(t){e.value=t.renderTime||t.loadTime})},O);function O(){var e=this;if(this.observer=null,window.PerformanceObserver){w&&w.entryMap&&w.entryMap[T]&&this.handle(w.entryMap[T]);try{this.observer=new PerformanceObserver(function(t){e.handle(t.getEntries())}),this.observer.observe({entryTypes:[T]})}catch(t){}}}function B(t){return t.name.indexOf(".gif?")<0}var R=(I.prototype.check=function(){return window.PerformanceObserver&&performance&&performance.timing&&performance.timing.navigationStart},I.prototype.listenTTI=function(t,e){this.check()&&(this.observeLongtask(2e4),this.cb=t,(e=e||{}).interval&&(this.interval=e.interval),e.filterRequest&&(this.filterRequest=e.filterRequest))},I.prototype.load=function(){this.check()&&(this.ttiTimer=setInterval(this.ttiCheck,this.interval))},I.prototype.ttiCheck=function(){if(this.cb){var t=performance.now();if(!(t-this.lastLongTask<this.interval)){var e=this.getNetworkSilenceAt();if(!1!==e&&!(t-e<this.interval)){clearTimeout(this.ttiTimer);var i=this.lastLongTask;i=i||performance.timing.domContentLoadedEventEnd-performance.timing.navigationStart,this.stopObserveLongTask(),this.cb({tti:i})}}}},I.prototype.observerCallback=function(t){var e=t.getEntries(),i=e[e.length-1];this.lastLongTask=i.startTime+i.duration},I.prototype.stopObserveLongTask=function(){this.observer&&(this.observer.disconnect(),this.observer=null),this.stopLongTaskTimeoutId&&clearTimeout(this.stopLongTaskTimeoutId)},I.prototype.getNetworkSilenceAt=function(){for(var t=0,e=0,i=performance.getEntriesByType("resource").filter(this.filterRequest);e<i.length;e++){var o=i[e];if(!o.responseEnd)return!1;o.responseEnd>t&&(t=o.responseEnd)}return t},I.prototype.observeLongtask=function(t){this.stopObserveLongTask();try{this.observer=new PerformanceObserver(this.observerCallback),this.observer.observe({entryTypes:["longtask"]}),this.stopLongTaskTimeoutId=setTimeout(this.stopObserveLongTask,t)}catch(t){}},I);function I(){this.lastLongTask=0,this.observer=null,this.interval=5e3,this.filterRequest=B,this.observerCallback=this.observerCallback.bind(this),this.ttiCheck=this.ttiCheck.bind(this)}var z,E,P,j,x=(H.prototype.listenTiming=function(t){window.performance&&window.performance.timing&&(this.cb=t)},H.prototype.load=function(){var t=this;setTimeout(function(){t.cb&&t.cb(t.getMetric())},500)},H.prototype.getMetric=function(){var r={},t=window.performance.timing,e=t.navigationStart;if(r.dns=t.domainLookupEnd-t.domainLookupStart,r.tcp=t.connectEnd-t.connectStart,r.request=t.responseStart-t.requestStart,r.response=t.responseEnd-t.responseStart,r.parseHtml=t.domInteractive-t.domLoading,r.domReady=t.domContentLoadedEventEnd-e,r.loadEventHandle=t.loadEventEnd-t.loadEventStart,r.load=t.loadEventEnd-e,performance.getEntriesByType){var i=performance.getEntriesByType("paint");i&&i.length&&i.forEach(function(t){var e=t.name,i=t.duration,o=t.startTime,n=Math.ceil(i+o);"first-paint"===e&&(r.fp=n),"first-contentful-paint"===e&&(r.fcp=n)})}return t.domFirstPaint&&(r.t7FirstPaint=t.domFirstPaint-e),t.domFirstScreenPaint&&(r.t7FirstScreen=t.domFirstScreenPaint-e),r},H);function H(){}(E=z=z||{}).JS="js",E.CSS="css",E.IMG="img",E.FONT="font",(j=P=P||{})[j.ttf=0]="ttf",j[j.eot=1]="eot",j[j.woff=2]="woff",j[j.woff2=3]="woff2";var M=["/mwb2.gif"];function N(t,e){for(var i=0,o=e;i<o.length;i++){var n=o[i];if(-1<t.indexOf(n))return!0}return!1}function _(t){return+t.toFixed(1)}var q=(F.prototype.check=function(){return performance&&performance.getEntriesByType},F.prototype.listenResource=function(t,e){void 0===e&&(e={}),this.check()&&(this.resOption=o(this.resOption,e),this.trigger=this.resOption.trigger,this.cb=t)},F.prototype.listenBigImg=function(t,e){void 0===e&&(e={}),this.check()&&(this.bigImgOption=o(this.bigImgOption,e),this.trigger=this.bigImgOption.trigger,this.bigImgCB=t)},F.prototype.listenHttpResource=function(t,e){void 0===e&&(e={}),this.check()&&(this.httpResOption=o(this.httpResOption,e),this.trigger=this.httpResOption.trigger,this.httpResCB=t)},F.prototype.listenSlowResource=function(t,e){void 0===e&&(e={}),this.check()&&(this.slowOption=o(this.slowOption,e),this.trigger=this.slowOption.trigger,this.slowResCB=t)},F.prototype.report=function(){var l=this,t=this.getMetric();if(t){var e=t.metric,i=t.hostMetric;this.cb&&this.cb(e,i)}this.bigImgCB&&"function"==typeof window.requestIdleCallback&&Object.keys(this.bigImgList).length&&window.requestIdleCallback(function(){for(var t=0,e=Object.keys(l.bigImgList);t<e.length;t++)for(var i=e[t],o=0,n=l.bigImgList[i];o<n.length;o++){var r=n[o],s=r.timing,a=r.type;try{var c=document.body.querySelector('img[src="'+s.name+'"]');l.bigImgCB({msg:s.name,dur:s.duration,xpath:d(c).xpath,host:i,type:a})}catch(t){console.error(t)}}}),this.httpResCB&&"function"==typeof window.requestIdleCallback&&Object.keys(this.httpResList).length&&window.requestIdleCallback(function(){for(var t=0,e=Object.keys(l.httpResList);t<e.length;t++)for(var i=e[t],o=0,n=l.httpResList[i];o<n.length;o++){var r=n[o],s=r.timing,a=r.type;try{var c=document.body.querySelector('[src="'+s.name+'"]');l.httpResCB({msg:s.name,dur:s.duration,xpath:d(c).xpath,host:i,type:a})}catch(t){console.error(t)}}}),this.slowResCB&&"function"==typeof window.requestIdleCallback&&Object.keys(this.slowList).length&&window.requestIdleCallback(function(){for(var t=0,e=Object.keys(l.slowList);t<e.length;t++)for(var i=e[t],o=0,n=l.slowList[i];o<n.length;o++){var r=n[o],s=r.timing,a=r.type;try{var c=document.body.querySelector('[src="'+s.name+'"]'),h={wait:f((p=s).domainLookupStart-(p.navigationStart||p.fetchStart||p.startTime)),dns:f(p.domainLookupEnd-p.domainLookupStart),connect:f(p.connectEnd-p.connectStart),req:f(p.responseStart-p.requestStart),res:f(p.responseEnd-p.responseStart)};l.slowResCB(u(u({},h),{dur:s.duration,msg:s.name,xpath:d(c).xpath,host:i,type:a}))}catch(t){console.error(t)}}var p})},F.prototype.load=function(){var t=this;"load"===this.trigger&&this.check()&&setTimeout(function(){t.report()},500)},F.prototype.leave=function(){"leave"===this.trigger&&this.report()},F.prototype.push=function(t,e,i,o){N(o.pathname,this.resOption.ignorePaths||[])||(e.push(i),this.pushWithHost(t,this.hostList,i,o)),N(o.pathname,this.slowOption.ignorePaths||[])||i.duration>this.slowOption.threshold&&this.pushWithHost(t,this.slowList,i,o)},F.prototype.pushWithHost=function(t,e,i,o){var n=o.host;e[n]||(e[n]=[]),e[n].push({timing:i,type:t})},F.prototype.collectHttpResInHttps=function(t,e,i){"https:"!==location.protocol||0!==e.name.indexOf("http://")||N(i.pathname,this.httpResOption.ignorePaths||[])||this.pushWithHost(t,this.httpResList,e,i)},F.prototype.addScript=function(t,e){"js"===e.ext&&0!==t.decodedBodySize&&this.push("js",this.jsList,t,e)},F.prototype.addResFromCss=function(t,e){e.ext&&P.hasOwnProperty(e.ext)?this.push("font",this.fontList,t,e):this.addImg(t,e)},F.prototype.addLink=function(t,e){"css"===e.ext?this.push("css",this.cssList,t,e):"js"===e.ext&&this.push("js",this.jsList,t,e)},F.prototype.addImg=function(t,e){this.push("img",this.imgList,t,e),t.decodedBodySize>(this.bigImgOption.maxSize||0)&&!N(e.pathname,this.bigImgOption.ignorePaths||[])&&this.pushWithHost("img",this.bigImgList,t,e)},F.prototype.handleTimings=function(t){for(var e=t.length,i=0;i<e;i++){var o=t[i],n=r(o.name);if(!N(n.pathname,M))switch(t[i].initiatorType){case"script":this.addScript(o,n);break;case"css":this.addResFromCss(o,n);break;case"img":this.addImg(o,n);break;case"link":this.addLink(o,n);break;case"audio":this.collectHttpResInHttps("audio",o,n);break;case"video":this.collectHttpResInHttps("video",o,n)}}},F.prototype.getNumAndSize=function(t,e){var i={},o=t+"Num",n=t+"Size",r=t+"TransferSize",s=t+"CacheRate",a=t+"Duration";i[o]=0,i[n]=0;var c=i[r]=0;if(e.forEach(function(t){i[o]++,i[n]+=t.decodedBodySize/1024,i[r]+=t.transferSize/1024,c+=t.duration}),i[a]=_(0<i[o]?c/i[o]:0),i[n]){var h=i[n]-i[r];i[s]=_(0<=h?100*h/i[n]:0)}return i[n]=_(i[n]),i[r]=_(i[r]),i},F.prototype.getMetric=function(){var t=performance.getEntriesByType("navigation")[0],e=performance.getEntriesByType("resource");if(t&&e&&e.length){this.handleTimings(e);var i=u(u(u(u({},this.getNumAndSize(z.JS,this.jsList)),this.getNumAndSize(z.CSS,this.cssList)),this.getNumAndSize(z.IMG,this.imgList)),this.getNumAndSize(z.FONT,this.fontList)),o=t;i.docSize=_(o.decodedBodySize/1024),i.docTransferSize=_(o.transferSize/1024),i.headerSize=_((o.transferSize-o.encodedBodySize||0)/1024),i.allSize=_(i.docSize+i.jsSize+i.cssSize+i.imgSize+i.fontSize),i.allTransferSize=_(i.docTransferSize+i.jsTransferSize+i.cssTransferSize+i.imgTransferSize+i.fontTransferSize);for(var n={},r=0,s=Object.keys(this.hostList);r<s.length;r++){var a=s[r],c=this.hostList[a].map(function(t){return t.timing});n[a]=this.getNumAndSize("host",c)}return{metric:i,hostMetric:n}}},F);function F(){this.trigger="load",this.jsList=[],this.cssList=[],this.imgList=[],this.fontList=[],this.hostList={},this.bigImgList={},this.httpResList={},this.slowList={},this.resOption={ignorePaths:[],trigger:"load"},this.bigImgOption={ignorePaths:[],maxSize:153600,trigger:"load"},this.httpResOption={ignorePaths:[],trigger:"load"},this.slowOption={ignorePaths:[],trigger:"load",threshold:1e3}}var A=null;window.performance&&window.performance.memory&&(A=window.performance.memory);var D=(J.prototype.listenMemory=function(t){this.cb=t},J.prototype.leave=function(){if(!this.onceLeave&&A){this.onceLeave=!0;var t=window.performance.memory;if(t.usedJSHeapSize===A.usedJSHeapSize&&t.totalJSHeapSize===A.totalJSHeapSize)return;var e=window.performance.memory;this.cb&&this.cb({usedJSHeapSize:e.usedJSHeapSize/1024,totalJSHeapSize:e.totalJSHeapSize/1024,jsHeapSizeLimit:e.jsHeapSizeLimit/1024,usedJSHeapRate:100*e.usedJSHeapSize/e.totalJSHeapSize})}},J);function J(){this.onceLeave=!1}var V=(Z.prototype.getNavigatorInfo=function(){var t={},e=navigator.connection;return"object"==typeof e&&(t={downlink:e.downlink,effectiveType:e.effectiveType,rtt:e.rtt,saveData:!!e.saveData}),navigator.deviceMemory&&(t.deviceMemory=navigator.deviceMemory),navigator.hardwareConcurrency&&(t.hardwareConcurrency=navigator.deviceMemory),t},Z.prototype.load=function(){},Z);function Z(){}var W,U,G,$=window.__spyHead,K="longtask",Q=(X.prototype.check=function(){return window.PerformanceObserver&&performance&&performance.timing&&performance.timing.navigationStart},X.prototype.listenFSPLongTask=function(t){this.check()&&(this.fspCB=t)},X.prototype.listenLCPLongTask=function(t){this.check()&&(this.lcpCB=t)},X.prototype.listenLoadLongTask=function(t){this.check()&&(this.loadCB=t)},X.prototype.listenPageLongTask=function(t){this.check()&&(this.pageCB=t)},X.prototype.load=function(){var i=this;if(this.check()){var o=this.getStatData(Date.now());setTimeout(function(){if(i.loadCB&&i.loadCB({loadLongtaskTime:o.time,loadTBT:o.tbt,loadTotalTime:o.totalTime,loadLongtaskRate:o.rate,loadLongtaskNum:o.num}),performance.timing&&performance.timing.domFirstScreenPaint){var t=i.getStatData(performance.timing.domFirstScreenPaint);i.fspCB&&i.fspCB({fspLongtaskTime:t.time,fspTBT:t.tbt,fspTotalTime:t.totalTime,fspLongtaskRate:t.rate,fspLongtaskNum:t.num})}if(S("lcp")){var e=i.getStatData(performance.timing.navigationStart+S("lcp"));i.lcpCB&&i.lcpCB({lcpLongtaskTime:e.time,lcpTBT:e.tbt,lcpTotalTime:e.totalTime,lcpLongtaskRate:e.rate,lcpLongtaskNum:e.num})}},200)}},X.prototype.leave=function(){if(!this.onceLeave){this.onceLeave=!0;var t=this.getStatData(Date.now());this.pageCB&&this.pageCB({pageLongtaskTime:t.time,pageTBT:t.tbt,pageTotalTime:t.totalTime,pageLongtaskRate:t.rate,pageLongtaskNum:t.num,pageIframeLongtaskTime:t.iframeTime,pageIframeLongtaskRate:t.iframeRate,pageIframeLongtaskNum:t.iframeNum})}},X.prototype.destroy=function(){this.lts=[],this.observer&&this.observer.disconnect(),this.observer=null},X.prototype.getStatData=function(t){for(var e=performance.timing.navigationStart,i=0,o=0,n=0,r=0,s=0,a={},c=0;c<this.lts.length;c++){var h=this.lts[c],p=h.duration;if(e+h.startTime+p<t&&(i+=p,o+=0<p-50?p-50:0,n++,h.attribution&&h.attribution[0])){var l=h.attribution[0].containerSrc;l&&l!==location.href&&(a[l]||(a[l]=[]),a[l].push(p),r+=p,s++)}}var u=t-e;return{num:n,time:i,tbt:o,totalTime:u,rate:100*i/u,iframeTime:r,iframeNum:s,iframeRate:100*r/u,iframeLongtasks:a}},X);function X(){var e=this;this.lts=[],this.observer=null,this.onceLeave=!1,$&&$.entryMap&&$.entryMap[K]&&(this.lts=this.lts.concat($.entryMap[K]));try{this.observer=new PerformanceObserver(function(t){e.lts=e.lts.concat(t.getEntries())}),this.observer.observe({entryTypes:[K]})}catch(t){}}function Y(){this.constructor=W}function tt(t){var e=G.call(this,t)||this;return e.modules=[],e.register(new g),e.register(new C),e.register(new b),e.register(new R),e.register(new x),e.register(new q),e.register(new D),e.register(new V),e.register(new Q),e.visibilitychangeCB=e.visibilitychangeCB.bind(e),e.load=e.load.bind(e),e.leave=e.leave.bind(e),"complete"===document.readyState?e.load():window.addEventListener("load",e.load),document.addEventListener("visibilitychange",e.visibilitychangeCB),window.addEventListener("beforeunload",e.leave,!1),window.addEventListener("unload",e.leave,!1),e.handleHead(),e}return i(W=tt,U=G=e),void(W.prototype=null===U?Object.create(U):(Y.prototype=U.prototype,new Y)),tt.prototype.handleHead=function(){var e=this;if(this.option.localCache){var t=window.__spyHead;if(t&&t.winerrors){for(var i=0;i<t.winerrors.length;i++){var o=t.winerrors[i];this.option.localCache.addLog(o)}t.interceptor=function(t){e.option.localCache.addLog(t)}}}},tt.prototype.listenFID=function(t){this.invoke("listenFID",t)},tt.prototype.listenLayoutShift=function(t){this.invoke("listenLayoutShift",t)},tt.prototype.listenLCP=function(t){this.invoke("listenLCP",t)},tt.prototype.listenFSPLongTask=function(t){this.invoke("listenFSPLongTask",t)},tt.prototype.listenLCPLongTask=function(t){this.invoke("listenLCPLongTask",t)},tt.prototype.listenLoadLongTask=function(t){this.invoke("listenLoadLongTask",t)},tt.prototype.listenPageLongTask=function(t){this.invoke("listenPageLongTask",t)},tt.prototype.listenMemory=function(t){this.invoke("listenMemory",t)},tt.prototype.getNavigatorInfo=function(){return this.invoke("getNavigatorInfo")},tt.prototype.listenResource=function(t,e){this.invoke("listenResource",t,e)},tt.prototype.listenBigImg=function(t,e){this.invoke("listenBigImg",t,e)},tt.prototype.listenHttpResource=function(t,e){this.invoke("listenHttpResource",t,e)},tt.prototype.listenSlowResource=function(t,e){this.invoke("listenSlowResource",t,e)},tt.prototype.listenTiming=function(t){this.invoke("listenTiming",t)},tt.prototype.listenTTI=function(t,e){this.invoke("listenTTI",t,e)},tt.prototype.invoke=function(t,e,i){for(var o=0;o<this.modules.length;o++){var n=this.modules[o];if("function"==typeof n[t])return n[t].apply(n,[e,i])}console.error("no method",t)},tt.prototype.register=function(t){this.modules.push(t)},tt.prototype.load=function(){for(var t=0;t<this.modules.length;t++){var e=this.modules[t];e.load&&e.load()}},tt.prototype.leave=function(){for(var t=0;t<this.modules.length;t++){var e=this.modules[t];e.leave&&e.leave()}},tt.prototype.destroy=function(){for(var t=0;t<this.modules.length;t++){var e=this.modules[t];e.destroy&&e.destroy()}document.removeEventListener("visibilitychange",this.visibilitychangeCB),window.removeEventListener("load",this.load),window.removeEventListener("beforeunload",this.leave),window.removeEventListener("unload",this.destroy)},tt.prototype.visibilitychangeCB=function(){"hidden"===document.visibilityState&&this.leave()},tt});
|
|
1
|
+
((t,e)=>{"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).SpyClient=e()})(this,function(){var i=function(t,e){return(i=Object.setPrototypeOf||({__proto__:[]}instanceof Array?function(t,e){t.__proto__=e}:function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])}))(t,e)};var l=function(){return(l=Object.assign||function(t){for(var e,i=1,o=arguments.length;i<o;i++)for(var n in e=arguments[i])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}).apply(this,arguments)};function o(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return(Object.assign||function(t){for(var e,i=1,o=arguments.length;i<o;i++)for(var n in e=arguments[i])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}).apply(this,t)}function M(t){var e,i=(t=>{if(URL&&t)try{var e=new URL(t);if(void 0!==e.host)return{protocol:e.protocol,host:e.host,pathname:e.pathname,ext:""}}catch(t){console.error(t)}})(t),t=(i||((e=document.createElement("a")).href=t,i={protocol:e.protocol,host:e.host||location.host,pathname:e.pathname,ext:""}),i.pathname.split("."));return i.ext=t[t.length-1],i}function u(t){return+t.toFixed(1)}function d(t){if(!t)return{xpath:""};for(var e=[];t&&1===t.nodeType&&t!==t.parentNode;){var i=t.tagName.toLowerCase();if(t.getAttribute("id")?i+="[#"+t.getAttribute("id")+"]":t.classList&&t.classList.length&&(i+="[."+t.classList[t.classList.length-1]+"]"),e.push(i),t===document.body)break;t=t.parentNode}return{xpath:e.join("<")}}var t=navigator&&navigator.userAgent?navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/):"",N=t&&t[2]&&+t[2]<14;function f(t){console.error("[SpyClient_log]".concat(t))}function s(i){return Object.keys(i).map(function(t){var e=i[t];return void 0===e?e="":"string"!=typeof e&&(e=JSON.stringify(e)),encodeURIComponent(t)+"="+encodeURIComponent(e)}).join("&")}function a(t){return"[object Array]"===Object.prototype.toString.call(t)}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 i=[],o=0,n=a(t)?t:[t];o<n.length;o++){var r=n[o];(r=this.handle(r))&&(i.push(r),e||(r=this.option.logServer+s(r),this.request(r)))}e&&this.sendPost(i)},e.prototype.check=function(t){if(this.option.check){var e=["perf","except","dist","count"];if(-1===e.indexOf(t.type))return f("type only is one of "+e.join(", ")),!1;if(t.group&&30<t.group.length)return f("group length execeeds 30"),!1;var i=/^[a-zA-Z0-9-_]{0,30}$/;if("except"===t.type){if("string"!=typeof t.info.msg||!t.info.msg.length)return f("info.msg field must be not empty and is String"),!1}else for(var o=0,n=Object.keys(t.info);o<n.length;o++){var r=n[o];if(!i.test(r))return f("info.".concat(r," is unexpected. ")+"Length must be not more than 30. Supported chars: a-zA-Z0-9-_"),!1;var s=t.info[r];if("dist"===t.type){if(30<s.length)return f("info.".concat(r," value length execeeds 30 when type == 'dist'")),!1}else if("number"!=typeof s)return f("info.".concat(r," value must be number")),!1}if(t.dim)for(var a=0,c=Object.keys(t.dim);a<c.length;a++){var h=c[a];if(!i.test(h))return f("dim key [".concat(h,"] is unexpected. ")+"Length must be not more than 30. Supported chars: a-zA-Z0-9-_"),!1;var p=t.dim[h];if(!/^[a-zA-Z0-9\-_\*\.\s\/#\+@\&\u4e00-\u9fa5]{0,30}$/.test(p))return f("dim.".concat(h," value [").concat(p,"] 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 i=o({},e);i.info=o({},e.info||{},{msg:t.message,stack:t.stack}),this.sendExcept(i)},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,i=Object.keys(this.markCache);e<i.length;e++){var o=i[e];t[o]=this.markCache[o].total}return t},e.prototype.clearAllMark=function(){this.markCache={}},e.prototype.sendPost=function(t){var e=(a(t)?t:[t])[0],e={pid:e.pid,type:e.type,group:e.group},e=this.option.logServer+s(e);this.request(e,t)},e.prototype.request=function(t,e){!N&&navigator&&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){fetch?fetch(t,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}):f("Global fetch method doesn't exist")};t=e;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?"}}var n=window.__spyHead,r="first-input",_=(c.prototype.listenFID=function(t){this.cb=t,this.callCB()},c.prototype.callCB=function(){void 0!==this.finalValue&&this.cb&&this.cb({fid:this.finalValue})},c.prototype.destroy=function(){this.observer&&this.observer.disconnect(),this.observer=null},c.prototype.handle=function(t){t=t.pop();t&&(this.finalValue=t.duration,this.callCB(),this.destroy())},c);function c(){var e=this;if(this.observer=null,window.PerformanceObserver){n&&n.entryMap&&n.entryMap[r]&&this.handle(n.entryMap[r]);try{this.observer=new PerformanceObserver(function(t){e.handle(t.getEntries())}),this.observer.observe({entryTypes:[r]})}catch(t){}}}var h=window.__spyHead,p="layout-shift",q=(g.prototype.listenLayoutShift=function(t){this.cb=t},g.prototype.leave=function(){this.onceLeave||(this.onceLeave=!0,this.observer&&this.observer.takeRecords&&this.observer.takeRecords(),this.finalValue=this.value,this.callCB(),this.destroy())},g.prototype.callCB=function(){void 0!==this.finalValue&&this.cb&&this.cb({layoutShift:this.finalValue})},g.prototype.destroy=function(){this.observer&&this.observer.disconnect(),this.observer=null},g.prototype.handle=function(t){var e=this;t.map(function(t){t.hadRecentInput||(e.value=(e.value||0)+(t.value||0))})},g);function g(){var e=this;if(this.observer=null,this.onceLeave=!1,window.PerformanceObserver){h&&h.entryMap&&h.entryMap[p]&&this.handle(h.entryMap[p]);try{this.observer=new PerformanceObserver(function(t){e.handle(t.getEntries())}),this.observer.observe({entryTypes:[p]})}catch(t){}}}var m={};var v=window.__spyHead,y="largest-contentful-paint",F=(b.prototype.listenLCP=function(t){this.cb=t,this.callCB()},b.prototype.callCB=function(){this.finalValue&&this.cb&&this.cb({lcp:this.finalValue})},b.prototype.load=function(){var t,e;this.observer&&this.observer.takeRecords&&this.observer.takeRecords(),this.finalValue=this.value,t="lcp",e=this.value,m[t]=e,this.callCB(),this.destroy()},b.prototype.destroy=function(){this.observer&&this.observer.disconnect(),this.observer=null},b.prototype.handle=function(t){var e=this;t.map(function(t){e.value=t.renderTime||t.loadTime})},b);function b(){var e=this;if(this.observer=null,window.PerformanceObserver){v&&v.entryMap&&v.entryMap[y]&&this.handle(v.entryMap[y]);try{this.observer=new PerformanceObserver(function(t){e.handle(t.getEntries())}),this.observer.observe({entryTypes:[y]})}catch(t){}}}function A(t){return t.name.indexOf(".gif?")<0}k.prototype.check=function(){return window.PerformanceObserver&&performance&&performance.timing&&performance.timing.navigationStart},k.prototype.listenTTI=function(t,e){this.check()&&(this.observeLongtask(2e4),this.cb=t,(e=e||{}).interval&&(this.interval=e.interval),e.filterRequest)&&(this.filterRequest=e.filterRequest)},k.prototype.load=function(){this.check()&&(this.ttiTimer=setInterval(this.ttiCheck,this.interval))},k.prototype.ttiCheck=function(){var t,e;!this.cb||(e=performance.now())-this.lastLongTask<this.interval||!1===(t=this.getNetworkSilenceAt())||e-t<this.interval||(clearTimeout(this.ttiTimer),e=(e=this.lastLongTask)||performance.timing.domContentLoadedEventEnd-performance.timing.navigationStart,this.stopObserveLongTask(),this.cb({tti:e}))},k.prototype.observerCallback=function(t){t=t.getEntries(),t=t[t.length-1];this.lastLongTask=t.startTime+t.duration},k.prototype.stopObserveLongTask=function(){this.observer&&(this.observer.disconnect(),this.observer=null),this.stopLongTaskTimeoutId&&clearTimeout(this.stopLongTaskTimeoutId)},k.prototype.getNetworkSilenceAt=function(){for(var t=0,e=0,i=performance.getEntriesByType("resource").filter(this.filterRequest);e<i.length;e++){var o=i[e];if(!o.responseEnd)return!1;t<o.responseEnd&&(t=o.responseEnd)}return t},k.prototype.observeLongtask=function(t){this.stopObserveLongTask();try{this.observer=new PerformanceObserver(this.observerCallback),this.observer.observe({entryTypes:["longtask"]}),this.stopLongTaskTimeoutId=setTimeout(this.stopObserveLongTask,t)}catch(t){}};var D=k;function k(){this.lastLongTask=0,this.observer=null,this.interval=5e3,this.filterRequest=A,this.observerCallback=this.observerCallback.bind(this),this.ttiCheck=this.ttiCheck.bind(this)}w.prototype.listenTiming=function(t){window.performance&&window.performance.timing&&(this.cb=t)},w.prototype.load=function(){var t=this;setTimeout(function(){t.cb&&t.cb(t.getMetric())},500)},w.prototype.getMetric=function(){var t,i={},e=window.performance.timing,o=e.navigationStart;return i.dns=e.domainLookupEnd-e.domainLookupStart,i.tcp=e.connectEnd-e.connectStart,i.request=e.responseStart-e.requestStart,i.response=e.responseEnd-e.responseStart,i.parseHtml=e.domInteractive-e.domLoading,i.domReady=e.domContentLoadedEventEnd-o,i.loadEventHandle=e.loadEventEnd-e.loadEventStart,i.load=e.loadEventEnd-o,performance.getEntriesByType&&(t=performance.getEntriesByType("paint"))&&t.length&&t.forEach(function(t){var e=t.name,t=Math.ceil(t.duration+t.startTime);"first-paint"===e&&(i.fp=t),"first-contentful-paint"===e&&(i.fcp=t)}),e.domFirstPaint&&(i.t7FirstPaint=e.domFirstPaint-o),e.domFirstScreenPaint&&(i.t7FirstScreen=e.domFirstScreenPaint-o),i};var L,S,J=w;function w(){}(E=L=L||{}).JS="js",E.CSS="css",E.IMG="img",E.FONT="font",(E=S=S||{})[E.ttf=0]="ttf",E[E.eot=1]="eot",E[E.woff=2]="woff",E[E.woff2=3]="woff2";var V=["/mwb2.gif"];function T(t,e){for(var i=0,o=e;i<o.length;i++){var n=o[i];if(-1<t.indexOf(n))return 1}}function C(t){return+t.toFixed(1)}O.prototype.check=function(){return performance&&performance.getEntriesByType},O.prototype.listenResource=function(t,e){void 0===e&&(e={}),this.check()&&(this.resOption=o(this.resOption,e),this.trigger=this.resOption.trigger,this.cb=t)},O.prototype.listenBigImg=function(t,e){void 0===e&&(e={}),this.check()&&(this.bigImgOption=o(this.bigImgOption,e),this.trigger=this.bigImgOption.trigger,this.bigImgCB=t)},O.prototype.listenHttpResource=function(t,e){void 0===e&&(e={}),this.check()&&(this.httpResOption=o(this.httpResOption,e),this.trigger=this.httpResOption.trigger,this.httpResCB=t)},O.prototype.listenSlowResource=function(t,e){void 0===e&&(e={}),this.check()&&(this.slowOption=o(this.slowOption,e),this.trigger=this.slowOption.trigger,this.slowResCB=t)},O.prototype.report=function(){var t,p=this,e=this.getMetric();e&&(t=e.metric,e=e.hostMetric,this.cb)&&this.cb(t,e),this.bigImgCB&&"function"==typeof window.requestIdleCallback&&Object.keys(this.bigImgList).length&&window.requestIdleCallback(function(){for(var t=0,e=Object.keys(p.bigImgList);t<e.length;t++)for(var i=e[t],o=0,n=p.bigImgList[i];o<n.length;o++){var r=n[o],s=r.timing,r=r.type;try{var a=document.body.querySelector('img[src="'+s.name+'"]');p.bigImgCB({msg:s.name,dur:s.duration,xpath:d(a).xpath,host:i,type:r})}catch(t){console.error(t)}}}),this.httpResCB&&"function"==typeof window.requestIdleCallback&&Object.keys(this.httpResList).length&&window.requestIdleCallback(function(){for(var t=0,e=Object.keys(p.httpResList);t<e.length;t++)for(var i=e[t],o=0,n=p.httpResList[i];o<n.length;o++){var r=n[o],s=r.timing,r=r.type;try{var a=document.body.querySelector('[src="'+s.name+'"]');p.httpResCB({msg:s.name,dur:s.duration,xpath:d(a).xpath,host:i,type:r})}catch(t){console.error(t)}}}),this.slowResCB&&"function"==typeof window.requestIdleCallback&&Object.keys(this.slowList).length&&window.requestIdleCallback(function(){for(var t,e=0,i=Object.keys(p.slowList);e<i.length;e++)for(var o=i[e],n=0,r=p.slowList[o];n<r.length;n++){var s=r[n],a=s.timing,s=s.type;try{var c=document.body.querySelector('[src="'+a.name+'"]'),h={wait:u((t=a).domainLookupStart-(t.navigationStart||t.fetchStart||t.startTime)),dns:u(t.domainLookupEnd-t.domainLookupStart),connect:u(t.connectEnd-t.connectStart),req:u(t.responseStart-t.requestStart),res:u(t.responseEnd-t.responseStart)};p.slowResCB(l(l({},h),{dur:a.duration,msg:a.name,xpath:d(c).xpath,host:o,type:s}))}catch(t){console.error(t)}}})},O.prototype.load=function(){var t=this;"load"===this.trigger&&this.check()&&setTimeout(function(){t.report()},500)},O.prototype.leave=function(){"leave"===this.trigger&&this.report()},O.prototype.push=function(t,e,i,o){T(o.pathname,this.resOption.ignorePaths||[])||(e.push(i),this.pushWithHost(t,this.hostList,i,o)),T(o.pathname,this.slowOption.ignorePaths||[])||i.duration>this.slowOption.threshold&&this.pushWithHost(t,this.slowList,i,o)},O.prototype.pushWithHost=function(t,e,i,o){o=o.host;e[o]||(e[o]=[]),e[o].push({timing:i,type:t})},O.prototype.collectHttpResInHttps=function(t,e,i){"https:"!==location.protocol||0!==e.name.indexOf("http://")||T(i.pathname,this.httpResOption.ignorePaths||[])||this.pushWithHost(t,this.httpResList,e,i)},O.prototype.addScript=function(t,e){"js"===e.ext&&0!==t.decodedBodySize&&this.push("js",this.jsList,t,e)},O.prototype.addResFromCss=function(t,e){e.ext&&S.hasOwnProperty(e.ext)?this.push("font",this.fontList,t,e):this.addImg(t,e)},O.prototype.addLink=function(t,e){"css"===e.ext?this.push("css",this.cssList,t,e):"js"===e.ext&&this.push("js",this.jsList,t,e)},O.prototype.addImg=function(t,e){this.push("img",this.imgList,t,e),t.decodedBodySize>(this.bigImgOption.maxSize||0)&&!T(e.pathname,this.bigImgOption.ignorePaths||[])&&this.pushWithHost("img",this.bigImgList,t,e)},O.prototype.handleTimings=function(t){for(var e=t.length,i=0;i<e;i++){var o=t[i],n=M(o.name);if(!T(n.pathname,V))switch(t[i].initiatorType){case"script":this.addScript(o,n);break;case"css":this.addResFromCss(o,n);break;case"img":this.addImg(o,n);break;case"link":this.addLink(o,n);break;case"audio":this.collectHttpResInHttps("audio",o,n);break;case"video":this.collectHttpResInHttps("video",o,n)}}},O.prototype.getNumAndSize=function(t,e){var i={},o=t+"Num",n=t+"Size",r=t+"TransferSize",s=t+"CacheRate",t=t+"Duration",a=(i[o]=0,i[n]=0,i[r]=0);return e.forEach(function(t){i[o]++,i[n]+=t.decodedBodySize/1024,i[r]+=t.transferSize/1024,a+=t.duration}),i[t]=C(0<i[o]?a/i[o]:0),i[n]&&(i[s]=C(0<=(e=i[n]-i[r])?100*e/i[n]:0)),i[n]=C(i[n]),i[r]=C(i[r]),i},O.prototype.getMetric=function(){var t=performance.getEntriesByType("navigation")[0],e=performance.getEntriesByType("resource");if(t&&e&&e.length){this.handleTimings(e);for(var e=l(l(l(l({},this.getNumAndSize(L.JS,this.jsList)),this.getNumAndSize(L.CSS,this.cssList)),this.getNumAndSize(L.IMG,this.imgList)),this.getNumAndSize(L.FONT,this.fontList)),i=(e.docSize=C(t.decodedBodySize/1024),e.docTransferSize=C(t.transferSize/1024),e.headerSize=C((t.transferSize-t.encodedBodySize||0)/1024),e.allSize=C(e.docSize+e.jsSize+e.cssSize+e.imgSize+e.fontSize),e.allTransferSize=C(e.docTransferSize+e.jsTransferSize+e.cssTransferSize+e.imgTransferSize+e.fontTransferSize),{}),o=0,n=Object.keys(this.hostList);o<n.length;o++){var r=n[o],s=this.hostList[r].map(function(t){return t.timing});i[r]=this.getNumAndSize("host",s)}return{metric:e,hostMetric:i}}};var Z=O;function O(){this.trigger="load",this.jsList=[],this.cssList=[],this.imgList=[],this.fontList=[],this.hostList={},this.bigImgList={},this.httpResList={},this.slowList={},this.resOption={ignorePaths:[],trigger:"load"},this.bigImgOption={ignorePaths:[],maxSize:153600,trigger:"load"},this.httpResOption={ignorePaths:[],trigger:"load"},this.slowOption={ignorePaths:[],trigger:"load",threshold:1e3}}var B=null,W=(window.performance&&window.performance.memory&&(B=window.performance.memory),R.prototype.listenMemory=function(t){this.cb=t},R.prototype.leave=function(){var t;!this.onceLeave&&B&&(this.onceLeave=!0,(t=window.performance.memory).usedJSHeapSize===B.usedJSHeapSize&&t.totalJSHeapSize===B.totalJSHeapSize||(t=window.performance.memory,this.cb&&this.cb({usedJSHeapSize:t.usedJSHeapSize/1024,totalJSHeapSize:t.totalJSHeapSize/1024,jsHeapSizeLimit:t.jsHeapSizeLimit/1024,usedJSHeapRate:100*t.usedJSHeapSize/t.totalJSHeapSize})))},R);function R(){this.onceLeave=!1}I.prototype.getNavigatorInfo=function(){var t={},e=navigator.connection;return"object"==typeof e&&(t={downlink:e.downlink,effectiveType:e.effectiveType,rtt:e.rtt,saveData:!!e.saveData}),navigator.deviceMemory&&(t.deviceMemory=navigator.deviceMemory),navigator.hardwareConcurrency&&(t.hardwareConcurrency=navigator.deviceMemory),t},I.prototype.load=function(){};var U=I;function I(){}var G,z,E,P=window.__spyHead,j="longtask",$=(x.prototype.check=function(){return window.PerformanceObserver&&performance&&performance.timing&&performance.timing.navigationStart},x.prototype.listenFSPLongTask=function(t){this.check()&&(this.fspCB=t)},x.prototype.listenLCPLongTask=function(t){this.check()&&(this.lcpCB=t)},x.prototype.listenLoadLongTask=function(t){this.check()&&(this.loadCB=t)},x.prototype.listenPageLongTask=function(t){this.check()&&(this.pageCB=t)},x.prototype.load=function(){var e,i=this;this.check()&&(e=this.getStatData(Date.now()),setTimeout(function(){var t;i.loadCB&&i.loadCB({loadLongtaskTime:e.time,loadTBT:e.tbt,loadTotalTime:e.totalTime,loadLongtaskRate:e.rate,loadLongtaskNum:e.num}),performance.timing&&performance.timing.domFirstScreenPaint&&(t=i.getStatData(performance.timing.domFirstScreenPaint),i.fspCB)&&i.fspCB({fspLongtaskTime:t.time,fspTBT:t.tbt,fspTotalTime:t.totalTime,fspLongtaskRate:t.rate,fspLongtaskNum:t.num}),m.lcp&&(t=i.getStatData(performance.timing.navigationStart+m.lcp),i.lcpCB)&&i.lcpCB({lcpLongtaskTime:t.time,lcpTBT:t.tbt,lcpTotalTime:t.totalTime,lcpLongtaskRate:t.rate,lcpLongtaskNum:t.num})},200))},x.prototype.leave=function(){var t;this.onceLeave||(this.onceLeave=!0,t=this.getStatData(Date.now()),this.pageCB&&this.pageCB({pageLongtaskTime:t.time,pageTBT:t.tbt,pageTotalTime:t.totalTime,pageLongtaskRate:t.rate,pageLongtaskNum:t.num,pageIframeLongtaskTime:t.iframeTime,pageIframeLongtaskRate:t.iframeRate,pageIframeLongtaskNum:t.iframeNum}))},x.prototype.destroy=function(){this.lts=[],this.observer&&this.observer.disconnect(),this.observer=null},x.prototype.getStatData=function(t){for(var e=performance.timing.navigationStart,i=0,o=0,n=0,r=0,s=0,a={},c=0;c<this.lts.length;c++){var h=this.lts[c],p=h.duration;e+h.startTime+p<t&&(i+=p,o+=0<p-50?p-50:0,n++,h.attribution)&&h.attribution[0]&&(h=h.attribution[0].containerSrc)&&h!==location.href&&(a[h]||(a[h]=[]),a[h].push(p),r+=p,s++)}var l=t-e;return{num:n,time:i,tbt:o,totalTime:l,rate:100*i/l,iframeTime:r,iframeNum:s,iframeRate:100*r/l,iframeLongtasks:a}},x);function x(){var e=this;this.lts=[],this.observer=null,this.onceLeave=!1,P&&P.entryMap&&P.entryMap[j]&&(this.lts=this.lts.concat(P.entryMap[j]));try{this.observer=new PerformanceObserver(function(t){e.lts=e.lts.concat(t.getEntries())}),this.observer.observe({entryTypes:[j]})}catch(t){}}function K(){this.constructor=z}function H(t){t=G.call(this,t)||this;return t.modules=[],t.register(new _),t.register(new F),t.register(new q),t.register(new D),t.register(new J),t.register(new Z),t.register(new W),t.register(new U),t.register(new $),t.visibilitychangeCB=t.visibilitychangeCB.bind(t),t.load=t.load.bind(t),t.leave=t.leave.bind(t),"complete"===document.readyState?t.load():window.addEventListener("load",t.load),document.addEventListener("visibilitychange",t.visibilitychangeCB),window.addEventListener("beforeunload",t.leave,!1),window.addEventListener("unload",t.leave,!1),t.handleHead(),t}return i(z=H,E=G=t),z.prototype=null===E?Object.create(E):(K.prototype=E.prototype,new K),H.prototype.handleHead=function(){var e=this;if(this.option.localCache){var t=window.__spyHead;if(t&&t.winerrors){for(var i=0;i<t.winerrors.length;i++){var o=t.winerrors[i];this.option.localCache.addLog(o)}t.interceptor=function(t){e.option.localCache.addLog(t)}}}},H.prototype.listenFID=function(t){this.invoke("listenFID",t)},H.prototype.listenLayoutShift=function(t){this.invoke("listenLayoutShift",t)},H.prototype.listenLCP=function(t){this.invoke("listenLCP",t)},H.prototype.listenFSPLongTask=function(t){this.invoke("listenFSPLongTask",t)},H.prototype.listenLCPLongTask=function(t){this.invoke("listenLCPLongTask",t)},H.prototype.listenLoadLongTask=function(t){this.invoke("listenLoadLongTask",t)},H.prototype.listenPageLongTask=function(t){this.invoke("listenPageLongTask",t)},H.prototype.listenMemory=function(t){this.invoke("listenMemory",t)},H.prototype.getNavigatorInfo=function(){return this.invoke("getNavigatorInfo")},H.prototype.listenResource=function(t,e){this.invoke("listenResource",t,e)},H.prototype.listenBigImg=function(t,e){this.invoke("listenBigImg",t,e)},H.prototype.listenHttpResource=function(t,e){this.invoke("listenHttpResource",t,e)},H.prototype.listenSlowResource=function(t,e){this.invoke("listenSlowResource",t,e)},H.prototype.listenTiming=function(t){this.invoke("listenTiming",t)},H.prototype.listenTTI=function(t,e){this.invoke("listenTTI",t,e)},H.prototype.invoke=function(t,e,i){for(var o=0;o<this.modules.length;o++){var n=this.modules[o];if("function"==typeof n[t])return n[t].apply(n,[e,i])}console.error("no method",t)},H.prototype.register=function(t){this.modules.push(t)},H.prototype.load=function(){for(var t=0;t<this.modules.length;t++){var e=this.modules[t];e.load&&e.load()}},H.prototype.leave=function(){for(var t=0;t<this.modules.length;t++){var e=this.modules[t];e.leave&&e.leave()}},H.prototype.destroy=function(){for(var t=0;t<this.modules.length;t++){var e=this.modules[t];e.destroy&&e.destroy()}document.removeEventListener("visibilitychange",this.visibilitychangeCB),window.removeEventListener("load",this.load),window.removeEventListener("beforeunload",this.leave),window.removeEventListener("unload",this.destroy)},H.prototype.visibilitychangeCB=function(){"hidden"===document.visibilityState&&this.leave()},H});
|
package/dist/spy-client.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/*! *****************************************************************************
|
|
2
|
-
Copyright (c) Microsoft Corporation.
|
|
3
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
4
|
-
this file except in compliance with the License. You may obtain a copy of the
|
|
5
|
-
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
2
|
+
Copyright (c) Microsoft Corporation.
|
|
6
3
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
10
|
-
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
4
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
+
purpose with or without fee is hereby granted.
|
|
11
6
|
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
9
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
11
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
12
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
14
14
|
***************************************************************************** */
|
|
15
15
|
/* global Reflect, Promise */
|
|
16
16
|
|
|
@@ -141,7 +141,7 @@ var defaultLogServer = 'https://sp1.baidu.com/5b1ZeDe5KgQFm2e88IuM_a/mwb2.gif?';
|
|
|
141
141
|
var ver = navigator && navigator.userAgent ? navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/) : '';
|
|
142
142
|
var isLtIos14 = ver && ver[2] && (+ver[2] < 14);
|
|
143
143
|
function err(msg) {
|
|
144
|
-
console.error("[SpyClient_log]"
|
|
144
|
+
console.error("[SpyClient_log]".concat(msg));
|
|
145
145
|
// throw new Error(msg);
|
|
146
146
|
}
|
|
147
147
|
function stringify(obj) {
|
|
@@ -246,7 +246,7 @@ var SpyClient$1 = /** @class */ (function () {
|
|
|
246
246
|
for (var _i = 0, _a = Object.keys(query.info); _i < _a.length; _i++) {
|
|
247
247
|
var infoKey = _a[_i];
|
|
248
248
|
if (!simpleReg.test(infoKey)) {
|
|
249
|
-
err("info."
|
|
249
|
+
err("info.".concat(infoKey, " is unexpected. ")
|
|
250
250
|
+ 'Length must be not more than 30. '
|
|
251
251
|
+ 'Supported chars: a-zA-Z0-9-_');
|
|
252
252
|
return false;
|
|
@@ -254,12 +254,12 @@ var SpyClient$1 = /** @class */ (function () {
|
|
|
254
254
|
var infoVal = query.info[infoKey];
|
|
255
255
|
if (query.type === 'dist') {
|
|
256
256
|
if (infoVal.length > 30) {
|
|
257
|
-
err("info."
|
|
257
|
+
err("info.".concat(infoKey, " value length execeeds 30 when type == 'dist'"));
|
|
258
258
|
return false;
|
|
259
259
|
}
|
|
260
260
|
}
|
|
261
261
|
else if (typeof infoVal !== 'number') {
|
|
262
|
-
err("info."
|
|
262
|
+
err("info.".concat(infoKey, " value must be number"));
|
|
263
263
|
return false;
|
|
264
264
|
}
|
|
265
265
|
}
|
|
@@ -268,14 +268,14 @@ var SpyClient$1 = /** @class */ (function () {
|
|
|
268
268
|
for (var _b = 0, _c = Object.keys(query.dim); _b < _c.length; _b++) {
|
|
269
269
|
var dimKey = _c[_b];
|
|
270
270
|
if (!simpleReg.test(dimKey)) {
|
|
271
|
-
err("dim key ["
|
|
271
|
+
err("dim key [".concat(dimKey, "] is unexpected. ")
|
|
272
272
|
+ 'Length must be not more than 30. '
|
|
273
273
|
+ 'Supported chars: a-zA-Z0-9-_');
|
|
274
274
|
return false;
|
|
275
275
|
}
|
|
276
276
|
var dimVal = query.dim[dimKey];
|
|
277
277
|
if (!/^[a-zA-Z0-9\-_\*\.\s\/#\+@\&\u4e00-\u9fa5]{0,30}$/.test(dimVal)) {
|
|
278
|
-
err("dim."
|
|
278
|
+
err("dim.".concat(dimKey, " value [").concat(dimVal, "] is unexpected. ")
|
|
279
279
|
+ 'Length must be not more than 30. '
|
|
280
280
|
+ 'Supported chars: a-zA-Z0-9-_*. /#+@& and Chinese');
|
|
281
281
|
return false;
|
package/dist/spy-head.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(factory) :
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.__spyHead = factory());
|
|
5
|
-
}(this, (function () { 'use strict';
|
|
5
|
+
})(this, (function () { 'use strict';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @file utils
|
|
@@ -117,8 +117,8 @@
|
|
|
117
117
|
return;
|
|
118
118
|
}
|
|
119
119
|
logServer = logServer || conf.logServer;
|
|
120
|
-
var logUrl = logServer
|
|
121
|
-
+
|
|
120
|
+
var logUrl = "".concat(logServer, "?pid=").concat(obj.pid, "&lid=").concat(obj.lid, "&ts=").concat(obj.ts)
|
|
121
|
+
+ "&type=".concat(obj.type, "&group=").concat(obj.group, "&info=").concat(encodeURIComponent(JSON.stringify(obj.info)));
|
|
122
122
|
if (obj.dim) {
|
|
123
123
|
logUrl += '&dim=' + encodeURIComponent(JSON.stringify(obj.dim));
|
|
124
124
|
}
|
|
@@ -177,7 +177,7 @@
|
|
|
177
177
|
var historys = [];
|
|
178
178
|
for (var index = 0; index < winerrors.length; index++) {
|
|
179
179
|
var item = winerrors[index];
|
|
180
|
-
var prefix = item.info.count > 1 ? "("
|
|
180
|
+
var prefix = item.info.count > 1 ? "(".concat(item.info.count, ")") : '';
|
|
181
181
|
historys.push(prefix + item.info.msg);
|
|
182
182
|
}
|
|
183
183
|
info.hisErrors = historys.join('----');
|
|
@@ -281,11 +281,11 @@
|
|
|
281
281
|
return false;
|
|
282
282
|
}
|
|
283
283
|
var pf = getResTiming(window.performance.timing);
|
|
284
|
-
var netStr = "&wait="
|
|
285
|
-
+
|
|
286
|
-
+
|
|
287
|
-
+
|
|
288
|
-
+
|
|
284
|
+
var netStr = "&wait=".concat(pf.wait)
|
|
285
|
+
+ "&dns=".concat(pf.dns)
|
|
286
|
+
+ "&connect=".concat(pf.connect)
|
|
287
|
+
+ "&requestTime=".concat(pf.req)
|
|
288
|
+
+ "&resoneTime=".concat(pf.res);
|
|
289
289
|
return netStr;
|
|
290
290
|
}
|
|
291
291
|
// 补充白屏信息:期间发生的JS Error 和 资源 Error
|
|
@@ -297,7 +297,7 @@
|
|
|
297
297
|
var historys = [];
|
|
298
298
|
for (var i = 0; i < errors.length; i++) {
|
|
299
299
|
var stack = (errors[i].info.stack || '').split('\n')[0];
|
|
300
|
-
historys.push("("
|
|
300
|
+
historys.push("(".concat(i, ")").concat(stack || errors[i].info.msg));
|
|
301
301
|
}
|
|
302
302
|
return historys.join(';;');
|
|
303
303
|
}
|
|
@@ -368,8 +368,9 @@
|
|
|
368
368
|
// 兼容全局变量定义的初始化方式
|
|
369
369
|
if (window.__spyclientConf) {
|
|
370
370
|
spyHead.init(window.__spyclientConf);
|
|
371
|
-
}
|
|
371
|
+
}
|
|
372
|
+
window.__spyHead = window.__spyHead || spyHead;
|
|
372
373
|
|
|
373
374
|
return spyHead;
|
|
374
375
|
|
|
375
|
-
}))
|
|
376
|
+
}));
|
package/dist/spy-head.min.js
CHANGED
|
@@ -1 +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 E(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 T={conf:{},winerrors:[],errorDestroy:function(){},observerDestroy:function(){},entryMap:{},init:function(e){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||{},m=e.jsError||{},g=Math.random()<(m.sample||0),w=Math.random()<(h.sample||0),v=T.winerrors,y=0;function n(e){try{var n=e.target,r={info:{},dim:{},group:""},t=r.info,o=e.srcElement,i=navigator.connection||{};if(t.downlink=i.downlink,t.effectiveType=i.effectiveType,t.rtt=i.rtt,t.deviceMemory=navigator.deviceMemory||0,t.hardwareConcurrency=navigator.hardwareConcurrency||0,o===window){r.group=m.group;for(var a,s=e.error||e.reason||{},c=(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")&&(a=t.msg.match(/^.*Hang:(.*); Miss:(.*)/))&&a[2]&&(t.msg="MODULE_TIMEOUT for miss:"+a[2]),[]),d=0;d<v.length;d++){var f=v[d],p=1<f.info.count?"(".concat(f.info.count,")"):"";c.push(p+f.info.msg)}t.hisErrors=c.join("----");var u=!0;!1!==(u=m.handler?m.handler(r):u)&&T.send(r,g)}else{r.group=h.group,r.dim.type=o.tagName.toLowerCase();var l=o.src||o.href||"";-1<l.indexOf("/mwb2.gif?")||(t.msg=l||"unknown load eror",r.dim.host=E(l).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),y&&(t.hisErrCount=y),!(u=!0)!==(u=h.handler?h.handler(r):u)&&T.send(r,w),y++)}}catch(e){console.error(e)}}window.addEventListener("error",n,!0),window.addEventListener("unhandledrejection",n,!0),T.errorDestroy=function(){window.removeEventListener("error",n,!0),window.removeEventListener("unhandledrejection",n,!0),T.winerrors=[]}}function t(e){var t=e.whiteScreenError||{},o=t.handler,i=t.selector,a=t.subSelector,e=t.timeout||6e3,s=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(a)&&!(r.clientHeight<2*window.innerHeight/3)||(r=!0,!((n={group:t.group,info:{msg:"",netTime:c(),hisErrors:(()=>{if(!T.winerrors)return!1;for(var e=T.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&&T&&T.send(n,s))},e)}return T.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=T.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)}});T.observerDestroy=function(){n.disconnect()};try{n.observe({entryTypes:["longtask","layout-shift","first-input","largest-contentful-paint"]})}catch(e){}}t(e)},window.__spyclientConf&&T.init(window.__spyclientConf),window.__spyHead=window.__spyHead||T,T});
|
package/dist/spy-local-cache.js
CHANGED
|
@@ -2,21 +2,21 @@
|
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(factory) :
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.SpyLocalCache = factory());
|
|
5
|
-
}(this, (function () { 'use strict';
|
|
5
|
+
})(this, (function () { 'use strict';
|
|
6
6
|
|
|
7
7
|
/*! *****************************************************************************
|
|
8
|
-
Copyright (c) Microsoft Corporation.
|
|
9
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
10
|
-
this file except in compliance with the License. You may obtain a copy of the
|
|
11
|
-
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
Copyright (c) Microsoft Corporation.
|
|
12
9
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
16
|
-
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
10
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
11
|
+
purpose with or without fee is hereby granted.
|
|
17
12
|
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
14
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
15
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
16
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
17
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
18
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
19
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
20
20
|
***************************************************************************** */
|
|
21
21
|
/* global Reflect, Promise */
|
|
22
22
|
|
|
@@ -749,4 +749,4 @@
|
|
|
749
749
|
|
|
750
750
|
return SpyLocalCache;
|
|
751
751
|
|
|
752
|
-
}))
|
|
752
|
+
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
((t,e)=>{"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).SpyLocalCache=e()})(this,function(){var r=function(t,e){return(r=Object.setPrototypeOf||({__proto__:[]}instanceof Array?function(t,e){t.__proto__=e}:function(t,e){for(var o in e)e.hasOwnProperty(o)&&(t[o]=e[o])}))(t,e)};function t(t,e){function o(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)}e.prototype.preOrder=function(t){t.push(this),this.left&&this.left.preOrder(t),this.right&&this.right.preOrder(t)};var c=e;function e(t,e){this.data=t,this.weight=e}function o(t){var n;return null==t?null:(n={},function t(e,o,r){r=[].concat(r);r.push(o),null!=e&&(null==e.data?(t(e.left,"0",r),t(e.right,"1",r)):n[e.data]=r.join(""))}(t,"",[]),n)}function n(t){var e=o((t=>{for(var e=function(t,e){return t.weight-e.weight};1<t.length;){t.sort(e);var o,r=t.shift(),n=t.shift();r&&n&&((o=new c(null,r.weight+n.weight)).left=r,o.right=n,t.unshift(o))}return t.shift()})((t=>{for(var e=[],o={},r=0,n=t;r<n.length;r++){var i=n[r];null==o[i]?o[i]=1:o[i]++}for(var a=0,s=Object.entries(o);a<s.length;a++){var u=s[a],h=u[0];e.push(new c(h,u[1]))}return e})(t)));return{result:(t=>{for(var e=t.join(""),t=Math.ceil(e.length/8),o=new Array(t+1),r=0,n="",i=0;i<e.length;i+=8)n=e.substring(i,i+8),o[r]=parseInt(n,2),r++;return o[r]=n.length,o})(((t,e)=>{for(var o=[],r=0,n=t;r<n.length;r++){var i=n[r];o.push(e[i])}return o})(t,e)),codes:e}}function i(t,e){for(var o,r,n=[],i=0;i<e.length-1;i++){var a=i!==e.length-2;n.push((o=a,r=e[i],o&&(r|=256),r=Number(r).toString(2),o?r.substring(r.length-8):r))}var s=e[e.length-1],s="00000000".substring(8-(s-(s=n[n.length-1]).length))+s;n[n.length-1]=s;for(var u={},h=0,c=Object.entries(t);h<c.length;h++){var l=c[h],p=l[0];u[l[1]]=p}for(var f=n.join(""),d=[],g=f.length,i=0;i<g;){for(var v=1,a=!0,y=null;a&&i+v<=g;){if(""===(p=f.substring(i,i+v)))break;(y=u[p])?a=!1:v++}d.push(parseInt(y,10)),i+=v}return d}function a(t){for(var e=[],o=0;o<t.length;o++)e.push(t.charCodeAt(o));return e}function s(t){for(var e="",o=0,r=t;o<r.length;o++){var n=r[o];e+=String.fromCharCode(n)}return e}h.prototype.set=function(t,e){},h.prototype.get=function(t,e){},h.prototype.rm=function(t){};var u=h;function h(){}t(f,l=u),f.isSupport=function(){return!!window.localStorage},f.prototype.set=function(t,e){try{localStorage.setItem(t,e)}catch(t){console.error(t)}},f.prototype.get=function(t,e){var o=null;try{o=localStorage.getItem(t)}catch(t){console.error(t)}e&&e(o)},f.prototype.rm=function(t){try{localStorage.removeItem(t)}catch(t){console.error(t)}};var l,p=f;function f(){return null!==l&&l.apply(this,arguments)||this}t(v,d=u),v.isSupport=function(){return!!window.indexedDB},v.prototype.set=function(t,e){this.db?this.db.transaction([this.databaseName],"readwrite").objectStore(this.databaseName).add({key:t,value:e}):this.setQueue.push({key:t,value:e})},v.prototype.get=function(t,e){var o;this.db?(o=this.db.transaction([this.databaseName]).objectStore(this.databaseName).get(t)).onsuccess=function(){var t=o.result||{value:""};e(t.value)}:this.getQueue.push({key:t,cb:e})},v.prototype.runQueueTask=function(){var e=this;this.setQueue.forEach(function(t){e.set(t.key,t.value)}),this.getQueue.forEach(function(t){e.get(t.key,t.cb)})};var d,g=v;function v(){var e=d.call(this)||this,t=(e.databaseName="spyLC",e.db=null,e.setQueue=[],e.getQueue=[],window.indexedDB.open(e.databaseName));return t.onupgradeneeded=function(t){e.db=t.target&&t.target.result,e.db&&!e.db.objectStoreNames.contains(e.databaseName)&&e.db.createObjectStore(e.databaseName,{keyPath:"key"}),e.runQueueTask()},t.onsuccess=function(){e.db=t.result,e.runQueueTask()},e}function y(t,e){if(!t)return"";(e=void 0===e?!1:e)||(t=(t=>{for(var e="",o=0;o<t.length;o++){var r=t.charCodeAt(o);r<128?e+=String.fromCharCode(r):e=127<r&&r<2048?(e+=String.fromCharCode(r>>6|192))+String.fromCharCode(63&r|128):(e=(e+=String.fromCharCode(r>>12|224))+String.fromCharCode(r>>6&63|128))+String.fromCharCode(63&r|128)}return e})(t));function o(){s.push(1<u.length?String.fromCharCode(a[u]):u)}var r,n,i,a={},s=[],u=t.charAt(0),h=u,c=h,l=256;for(e&&s.push(u),r=1;r<t.length;r++)n=t.charAt(r),e?(i=t.charCodeAt(r),u=i<256?n:a[i]||u+h,s.push(u),h=u.charAt(0),a[l++]=c+h,c=u):a.hasOwnProperty(u+n)?u+=n:(o(),a[u+n]=l++,u=n);e||o();var p=s.join("");return p=e?(t=>{for(var e,o,r="",n=0,i=0;n<t.length;)(e=t.charCodeAt(n))<128?(r+=String.fromCharCode(e),n++):191<e&&e<224?(i=t.charCodeAt(n+1),r+=String.fromCharCode((31&e)<<6|63&i),n+=2):(i=t.charCodeAt(n+1),o=t.charCodeAt(n+2),r+=String.fromCharCode((15&e)<<12|(63&i)<<6|63&o),n+=3);return r})(p):p}function m(t){void 0===t&&(t={}),this.tmpList=[],this.option=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return(Object.assign||function(t){for(var e,o=1,r=arguments.length;o<r;o++)for(var n in e=arguments[o])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}).apply(this,t)}({defaultTrigger:!0,compress:"lzw",key:"SpyLocalCache",interval:500,maxRecordLen:30,onFlush:function(){},onSave:function(){},onAdd:function(){return!0},storage:g.isSupport()?"indexedDB":p.isSupport()?"localstorage":"empty"},t),this.load=this.load.bind(this),this.init()}return m.prototype.init=function(){"indexedDB"===this.option.storage?this.storage=new g:"localstorage"===this.option.storage?this.storage=new p:this.storage=new u,"complete"===document.readyState?this.load():window.addEventListener("load",this.load)},m.prototype.load=function(){-1<location.search.indexOf("_FlushLogLocalCache=1")&&this.option.defaultTrigger&&this.flushLog()},m.prototype.addLog=function(t){var e=this;this.option.onAdd&&!this.option.onAdd(t)||(t=JSON.stringify(t),this.tmpList.push(t),this.timer&&clearTimeout(this.timer),this.timer=setTimeout(function(){e.save()},this.option.interval))},m.prototype.getData=function(r){var n=this;try{this.storage.get(this.option.key,function(o){o?n.storage.get(n.option.key+"Codes",function(t){var e=[];try{t=t&&JSON.parse(t);e=n.unzip(o,t).split("\n")}catch(t){console.error(t)}r(e)}):r([])})}catch(t){console.error(t),r([])}},m.prototype.save=function(){var a=this,s=Date.now();this.getData(function(t){var e=a.option.maxRecordLen-1,e=(t.length>e?t.slice(t.length-e,t.length):t).concat(a.tmpList),t=e.join("\n"),o=null,r=0;try{var n,i=a.zip(t);i.codes?(n=JSON.stringify(i.codes),a.storage.set(a.option.key+"Codes",n)):a.storage.rm(a.option.key+"Codes"),a.storage.set(a.option.key,i.result),r=i.result.length}catch(t){o=t,console.error(t)}a.tmpList=[],a.option.onSave&&a.option.onSave({cost:Date.now()-s,length:r/1024,list:e,error:o})})},m.prototype.flushLog=function(){var o=this;this.getData(function(e){try{for(var t=0;t<e.length;t++)e[t]=JSON.parse(e[t])}catch(t){e=[],o.storage.rm(o.option.key),console.error(t)}for(t=0;t<o.tmpList.length;t++)e.push(JSON.parse(o.tmpList[t]));o.option.onFlush&&o.option.onFlush(e)})},m.prototype.zip=function(t){var e,o;return"lzw"===this.option.compress?{codes:null,result:y(t)}:"huffman"===this.option.compress?(o=(e=n(a(e=t))).result,{codes:e.codes,result:s(o)}):{codes:null,result:t}},m.prototype.unzip=function(t,e){return"lzw"===this.option.compress?y(t,!0):"huffman"===this.option.compress?s(i(e,a(t))):t},m});
|