spy-client 2.1.1 → 2.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -3
- package/coverage/Chrome 92.0.4515.159 (Mac OS 10.15.7)/html/base.css +224 -0
- package/coverage/Chrome 92.0.4515.159 (Mac OS 10.15.7)/html/basicSpec.ts.html +740 -0
- package/coverage/Chrome 92.0.4515.159 (Mac OS 10.15.7)/html/block-navigation.js +79 -0
- package/coverage/Chrome 92.0.4515.159 (Mac OS 10.15.7)/html/checkSpec.ts.html +479 -0
- package/coverage/Chrome 92.0.4515.159 (Mac OS 10.15.7)/html/favicon.png +0 -0
- package/coverage/Chrome 92.0.4515.159 (Mac OS 10.15.7)/html/headSpec.ts.html +695 -0
- package/coverage/Chrome 92.0.4515.159 (Mac OS 10.15.7)/html/index.html +171 -0
- package/coverage/Chrome 92.0.4515.159 (Mac OS 10.15.7)/html/markSpec.ts.html +284 -0
- package/coverage/Chrome 92.0.4515.159 (Mac OS 10.15.7)/html/metricSpec.ts.html +977 -0
- package/coverage/Chrome 92.0.4515.159 (Mac OS 10.15.7)/html/prettify.css +1 -0
- package/coverage/Chrome 92.0.4515.159 (Mac OS 10.15.7)/html/prettify.js +2 -0
- package/coverage/Chrome 92.0.4515.159 (Mac OS 10.15.7)/html/sort-arrow-sprite.png +0 -0
- package/coverage/Chrome 92.0.4515.159 (Mac OS 10.15.7)/html/sorter.js +170 -0
- package/coverage/Chrome 95.0.4638.69 (Mac OS 10.15.7)/html/base.css +224 -0
- package/coverage/Chrome 95.0.4638.69 (Mac OS 10.15.7)/html/basicSpec.ts.html +740 -0
- package/coverage/Chrome 95.0.4638.69 (Mac OS 10.15.7)/html/block-navigation.js +79 -0
- package/coverage/Chrome 95.0.4638.69 (Mac OS 10.15.7)/html/checkSpec.ts.html +479 -0
- package/coverage/Chrome 95.0.4638.69 (Mac OS 10.15.7)/html/favicon.png +0 -0
- package/coverage/Chrome 95.0.4638.69 (Mac OS 10.15.7)/html/headSpec.ts.html +695 -0
- package/coverage/Chrome 95.0.4638.69 (Mac OS 10.15.7)/html/index.html +171 -0
- package/coverage/Chrome 95.0.4638.69 (Mac OS 10.15.7)/html/markSpec.ts.html +284 -0
- package/coverage/Chrome 95.0.4638.69 (Mac OS 10.15.7)/html/metricSpec.ts.html +977 -0
- package/coverage/Chrome 95.0.4638.69 (Mac OS 10.15.7)/html/prettify.css +1 -0
- package/coverage/Chrome 95.0.4638.69 (Mac OS 10.15.7)/html/prettify.js +2 -0
- package/coverage/Chrome 95.0.4638.69 (Mac OS 10.15.7)/html/sort-arrow-sprite.png +0 -0
- package/coverage/Chrome 95.0.4638.69 (Mac OS 10.15.7)/html/sorter.js +170 -0
- package/coverage/Chrome 96.0.4664.55 (Mac OS 10.15.7)/html/base.css +224 -0
- package/coverage/Chrome 96.0.4664.55 (Mac OS 10.15.7)/html/basicSpec.ts.html +740 -0
- package/coverage/Chrome 96.0.4664.55 (Mac OS 10.15.7)/html/block-navigation.js +79 -0
- package/coverage/Chrome 96.0.4664.55 (Mac OS 10.15.7)/html/checkSpec.ts.html +479 -0
- package/coverage/Chrome 96.0.4664.55 (Mac OS 10.15.7)/html/favicon.png +0 -0
- package/coverage/Chrome 96.0.4664.55 (Mac OS 10.15.7)/html/headSpec.ts.html +695 -0
- package/coverage/Chrome 96.0.4664.55 (Mac OS 10.15.7)/html/index.html +171 -0
- package/coverage/Chrome 96.0.4664.55 (Mac OS 10.15.7)/html/markSpec.ts.html +284 -0
- package/coverage/Chrome 96.0.4664.55 (Mac OS 10.15.7)/html/metricSpec.ts.html +977 -0
- package/coverage/Chrome 96.0.4664.55 (Mac OS 10.15.7)/html/prettify.css +1 -0
- package/coverage/Chrome 96.0.4664.55 (Mac OS 10.15.7)/html/prettify.js +2 -0
- package/coverage/Chrome 96.0.4664.55 (Mac OS 10.15.7)/html/sort-arrow-sprite.png +0 -0
- package/coverage/Chrome 96.0.4664.55 (Mac OS 10.15.7)/html/sorter.js +170 -0
- package/dist/head/base.d.ts +12 -7
- package/dist/lib/interface.d.ts +4 -0
- package/dist/spy-client-basic.d.ts +5 -1
- package/dist/spy-client-basic.esm.js +82 -21
- package/dist/spy-client-basic.iife.js +82 -21
- package/dist/spy-client-basic.iife.min.js +1 -1
- package/dist/spy-client-basic.js +82 -21
- package/dist/spy-client-basic.min.js +1 -1
- package/dist/spy-client-basic.mjs +82 -21
- package/dist/spy-client.d.ts +1 -0
- package/dist/spy-client.esm.js +109 -31
- package/dist/spy-client.iife.js +109 -31
- package/dist/spy-client.iife.min.js +1 -1
- package/dist/spy-client.js +109 -31
- package/dist/spy-client.min.js +1 -1
- package/dist/spy-client.mjs +109 -31
- package/dist/spy-head.js +46 -34
- package/dist/spy-head.min.js +1 -1
- package/dist/spy-local-cache.js +126 -64
- package/dist/spy-local-cache.min.js +1 -1
- package/example/local-cache.html +77 -15
- package/package.json +4 -12
- package/src/head/base.ts +37 -4
- package/src/head/error.ts +9 -19
- package/src/head/whitescreen.ts +14 -14
- package/src/lib/huffman.ts +37 -56
- package/src/lib/interface.ts +5 -0
- package/src/spy-client-basic.ts +95 -26
- package/src/spy-client.ts +19 -1
- package/src/spy-local-cache.ts +103 -10
package/dist/spy-client.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/*! *****************************************************************************
|
|
2
|
-
Copyright (c) Microsoft Corporation.
|
|
2
|
+
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
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
|
|
3
6
|
|
|
4
|
-
|
|
5
|
-
|
|
7
|
+
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
8
|
+
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
|
9
|
+
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
10
|
+
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
6
11
|
|
|
7
|
-
|
|
8
|
-
|
|
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.
|
|
12
|
+
See the Apache Version 2.0 License for specific language governing permissions
|
|
13
|
+
and limitations under the License.
|
|
14
14
|
***************************************************************************** */
|
|
15
15
|
/* global Reflect, Promise */
|
|
16
16
|
|
|
@@ -132,7 +132,8 @@ function getxpath(el) {
|
|
|
132
132
|
* @author kaivean
|
|
133
133
|
*/
|
|
134
134
|
var defaultLogServer = 'https://sp1.baidu.com/5b1ZeDe5KgQFm2e88IuM_a/mwb2.gif?';
|
|
135
|
-
var
|
|
135
|
+
var ver = navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/);
|
|
136
|
+
var isLtIos14 = ver && ver[2] && (+ver[2] < 14);
|
|
136
137
|
function err(msg) {
|
|
137
138
|
console.error("[SpyClient_log]" + msg);
|
|
138
139
|
// throw new Error(msg);
|
|
@@ -149,6 +150,9 @@ function stringify(obj) {
|
|
|
149
150
|
return encodeURIComponent(key) + '=' + encodeURIComponent(value);
|
|
150
151
|
}).join('&');
|
|
151
152
|
}
|
|
153
|
+
function isArray(arr) {
|
|
154
|
+
return Object.prototype.toString.call(arr) === '[object Array]';
|
|
155
|
+
}
|
|
152
156
|
var SpyClient$1 = /** @class */ (function () {
|
|
153
157
|
function SpyClient(option) {
|
|
154
158
|
this.sample = {};
|
|
@@ -161,38 +165,55 @@ var SpyClient$1 = /** @class */ (function () {
|
|
|
161
165
|
lid: option.lid,
|
|
162
166
|
check: option.check !== false,
|
|
163
167
|
sample: option.sample,
|
|
168
|
+
localCache: option.localCache,
|
|
164
169
|
logServer: option.logServer || defaultLogServer,
|
|
165
170
|
};
|
|
166
171
|
}
|
|
167
|
-
SpyClient.prototype.
|
|
168
|
-
if (!this.check(
|
|
172
|
+
SpyClient.prototype.handle = function (logItem) {
|
|
173
|
+
if (!this.check(logItem)) {
|
|
169
174
|
return;
|
|
170
175
|
}
|
|
176
|
+
logItem = assign({
|
|
177
|
+
pid: this.option.pid,
|
|
178
|
+
lid: this.option.lid,
|
|
179
|
+
ts: Date.now(),
|
|
180
|
+
group: 'common',
|
|
181
|
+
}, logItem);
|
|
182
|
+
if (this.option.localCache) {
|
|
183
|
+
this.option.localCache.addLog(logItem);
|
|
184
|
+
}
|
|
171
185
|
// 当前api设置了抽样,
|
|
172
|
-
if (typeof
|
|
173
|
-
if (Math.random() >
|
|
186
|
+
if (typeof logItem.sample === 'number') {
|
|
187
|
+
if (Math.random() > logItem.sample) {
|
|
174
188
|
return;
|
|
175
189
|
}
|
|
176
190
|
}
|
|
177
191
|
else if (typeof this.option.sample === 'number' && Math.random() > this.option.sample) { // 否则,用全局抽样
|
|
178
192
|
return;
|
|
179
193
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
var
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
194
|
+
delete logItem.sample;
|
|
195
|
+
return logItem;
|
|
196
|
+
};
|
|
197
|
+
SpyClient.prototype.send = function (data, post) {
|
|
198
|
+
if (post === void 0) { post = false; }
|
|
199
|
+
var logItems = isArray(data) ? data : [data];
|
|
200
|
+
var postData = [];
|
|
201
|
+
for (var _i = 0, logItems_1 = logItems; _i < logItems_1.length; _i++) {
|
|
202
|
+
var logItem = logItems_1[_i];
|
|
203
|
+
logItem = this.handle(logItem);
|
|
204
|
+
if (!logItem) {
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
postData.push(logItem);
|
|
208
|
+
// 期望通过post方式上传日志
|
|
209
|
+
if (post) {
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
var url = this.option.logServer + stringify(logItem);
|
|
213
|
+
this.request(url);
|
|
214
|
+
}
|
|
215
|
+
if (post) {
|
|
216
|
+
this.sendPost(postData);
|
|
196
217
|
}
|
|
197
218
|
};
|
|
198
219
|
SpyClient.prototype.check = function (query) {
|
|
@@ -334,6 +355,46 @@ var SpyClient$1 = /** @class */ (function () {
|
|
|
334
355
|
SpyClient.prototype.clearAllMark = function () {
|
|
335
356
|
this.markCache = {};
|
|
336
357
|
};
|
|
358
|
+
// send(data, true) 也能以post发送,但是会有严格校验
|
|
359
|
+
// sendPost能以post发送,但没有校验
|
|
360
|
+
SpyClient.prototype.sendPost = function (data) {
|
|
361
|
+
var logItems = isArray(data) ? data : [data];
|
|
362
|
+
var first = logItems[0];
|
|
363
|
+
// 需要在页面暴漏出来pid等基本信息,方式调试查看基本信息与兼容目前的监控
|
|
364
|
+
var query = {
|
|
365
|
+
pid: first.pid,
|
|
366
|
+
type: first.type,
|
|
367
|
+
group: first.group,
|
|
368
|
+
};
|
|
369
|
+
var url = this.option.logServer + stringify(query);
|
|
370
|
+
this.request(url, data);
|
|
371
|
+
};
|
|
372
|
+
// 有data时,意味着要用post发送请求
|
|
373
|
+
SpyClient.prototype.request = function (url, data) {
|
|
374
|
+
if (!(!isLtIos14
|
|
375
|
+
&& navigator.sendBeacon
|
|
376
|
+
&& navigator.sendBeacon(url, data ? JSON.stringify(data) : undefined))) {
|
|
377
|
+
if (data) {
|
|
378
|
+
this.fetch(url, data);
|
|
379
|
+
}
|
|
380
|
+
else {
|
|
381
|
+
(new Image()).src = url;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
SpyClient.prototype.fetch = function (url, data) {
|
|
386
|
+
if (!window.fetch) {
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
fetch(url, {
|
|
390
|
+
method: 'POST',
|
|
391
|
+
credentials: 'include',
|
|
392
|
+
headers: {
|
|
393
|
+
'Content-Type': 'application/json',
|
|
394
|
+
},
|
|
395
|
+
body: JSON.stringify(data),
|
|
396
|
+
});
|
|
397
|
+
};
|
|
337
398
|
return SpyClient;
|
|
338
399
|
}());
|
|
339
400
|
|
|
@@ -1307,8 +1368,25 @@ var SpyClient = /** @class */ (function (_super) {
|
|
|
1307
1368
|
document.addEventListener('visibilitychange', _this.visibilitychangeCB);
|
|
1308
1369
|
window.addEventListener('beforeunload', _this.leave, false);
|
|
1309
1370
|
window.addEventListener('unload', _this.leave, false);
|
|
1371
|
+
_this.handleHead();
|
|
1310
1372
|
return _this;
|
|
1311
1373
|
}
|
|
1374
|
+
SpyClient.prototype.handleHead = function () {
|
|
1375
|
+
var _this = this;
|
|
1376
|
+
if (this.option.localCache) {
|
|
1377
|
+
var spyHead = window.__spyHead;
|
|
1378
|
+
if (spyHead && spyHead.winerrors) {
|
|
1379
|
+
for (var index = 0; index < spyHead.winerrors.length; index++) {
|
|
1380
|
+
var obj = spyHead.winerrors[index];
|
|
1381
|
+
this.option.localCache.addLog(obj);
|
|
1382
|
+
}
|
|
1383
|
+
// Head发送的异常,也保存一份到本地,主要是JS错误和资源加载异常
|
|
1384
|
+
spyHead.interceptor = function (obj) {
|
|
1385
|
+
_this.option.localCache.addLog(obj);
|
|
1386
|
+
};
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
};
|
|
1312
1390
|
SpyClient.prototype.listenFID = function (cb) {
|
|
1313
1391
|
this.invoke('listenFID', cb);
|
|
1314
1392
|
};
|
package/dist/spy-head.js
CHANGED
|
@@ -87,11 +87,32 @@
|
|
|
87
87
|
init: function (conf) {
|
|
88
88
|
this.conf = conf;
|
|
89
89
|
},
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
addError: function (obj) {
|
|
91
|
+
// 有些错误一下出现很多次,都聚合都一个错误,加上次数
|
|
92
|
+
if (this.winerrors.length > 0) {
|
|
93
|
+
var lastObj = this.winerrors[this.winerrors.length - 1];
|
|
94
|
+
if (obj.info.msg === lastObj.info.msg) {
|
|
95
|
+
lastObj.info.count += (lastObj.info.count || 0);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (this.winerrors.length < 1000) {
|
|
100
|
+
this.winerrors.push(obj);
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
send: function (obj, isSend, logServer) {
|
|
92
104
|
var conf = this.conf;
|
|
105
|
+
obj.type = obj.type || 'except';
|
|
106
|
+
obj.pid = conf.pid;
|
|
107
|
+
obj.lid = conf.lid;
|
|
108
|
+
obj.ts = Date.now();
|
|
109
|
+
this.addError(obj);
|
|
110
|
+
this.interceptor && this.interceptor(obj);
|
|
111
|
+
if (isSend === false) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
93
114
|
logServer = logServer || conf.logServer;
|
|
94
|
-
var logUrl = logServer + "?pid=" +
|
|
115
|
+
var logUrl = logServer + "?pid=" + obj.pid + "&lid=" + obj.lid + "&ts=" + obj.ts
|
|
95
116
|
+ ("&type=" + obj.type + "&group=" + obj.group + "&info=" + encodeURIComponent(JSON.stringify(obj.info)));
|
|
96
117
|
if (obj.dim) {
|
|
97
118
|
logUrl += '&dim=' + encodeURIComponent(JSON.stringify(obj.dim));
|
|
@@ -147,18 +168,18 @@
|
|
|
147
168
|
}
|
|
148
169
|
// 历史错误
|
|
149
170
|
var historys = [];
|
|
150
|
-
for (var index = 0; index <
|
|
151
|
-
var item =
|
|
152
|
-
var prefix = item.count > 1 ? "(" + item.count + ")" : '';
|
|
153
|
-
historys.push(prefix + item.msg);
|
|
171
|
+
for (var index = 0; index < winerrors.length; index++) {
|
|
172
|
+
var item = winerrors[index];
|
|
173
|
+
var prefix = item.info.count > 1 ? "(" + item.info.count + ")" : '';
|
|
174
|
+
historys.push(prefix + item.info.msg);
|
|
154
175
|
}
|
|
155
176
|
info.hisErrors = historys.join('----');
|
|
156
177
|
var allow = true;
|
|
157
178
|
if (jsError.handler) {
|
|
158
179
|
allow = jsError.handler(obj);
|
|
159
180
|
}
|
|
160
|
-
if (allow !== false
|
|
161
|
-
spyHead.send(obj);
|
|
181
|
+
if (allow !== false) {
|
|
182
|
+
spyHead.send(obj, isSendJserror);
|
|
162
183
|
}
|
|
163
184
|
}
|
|
164
185
|
// 资源错误
|
|
@@ -178,20 +199,11 @@
|
|
|
178
199
|
if (resourceError.handler) {
|
|
179
200
|
allow = resourceError.handler(obj);
|
|
180
201
|
}
|
|
181
|
-
if (allow !== false
|
|
182
|
-
spyHead.send(obj);
|
|
202
|
+
if (allow !== false) {
|
|
203
|
+
spyHead.send(obj, isSendResource);
|
|
183
204
|
}
|
|
184
205
|
resourceErrorCount++;
|
|
185
206
|
}
|
|
186
|
-
// 有些错误一下出现很多次,都聚合都一个错误,加上次数
|
|
187
|
-
if (winerrors.length > 0) {
|
|
188
|
-
var lastInfo = winerrors[winerrors.length - 1];
|
|
189
|
-
if (info.msg === lastInfo.msg) {
|
|
190
|
-
lastInfo.count += (lastInfo.count || 0);
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
winerrors.push(info);
|
|
195
207
|
}
|
|
196
208
|
catch (e) {
|
|
197
209
|
console.error(e);
|
|
@@ -200,7 +212,7 @@
|
|
|
200
212
|
window.addEventListener('error', spyListenError, true);
|
|
201
213
|
spyHead.errorDestroy = function () {
|
|
202
214
|
window.removeEventListener('error', spyListenError, true);
|
|
203
|
-
spyHead.winerrors =
|
|
215
|
+
spyHead.winerrors = [];
|
|
204
216
|
};
|
|
205
217
|
}
|
|
206
218
|
|
|
@@ -270,8 +282,8 @@
|
|
|
270
282
|
var errors = spyHead.winerrors;
|
|
271
283
|
var historys = [];
|
|
272
284
|
for (var i = 0; i < errors.length; i++) {
|
|
273
|
-
var stack = (errors[i].stack || '').split('\n')[0];
|
|
274
|
-
historys.push("(" + i + ")" + (stack || errors[i].msg));
|
|
285
|
+
var stack = (errors[i].info.stack || '').split('\n')[0];
|
|
286
|
+
historys.push("(" + i + ")" + (stack || errors[i].info.msg));
|
|
275
287
|
}
|
|
276
288
|
return historys.join(';;');
|
|
277
289
|
}
|
|
@@ -301,25 +313,25 @@
|
|
|
301
313
|
}
|
|
302
314
|
return false;
|
|
303
315
|
}
|
|
304
|
-
if (
|
|
316
|
+
if (selector) {
|
|
305
317
|
setTimeout(function () {
|
|
306
|
-
var obj = {
|
|
307
|
-
group: whiteScreenError.group,
|
|
308
|
-
info: {
|
|
309
|
-
msg: '',
|
|
310
|
-
netTime: getNetTime(),
|
|
311
|
-
hisErrors: getHisError(),
|
|
312
|
-
deviceInfo: getDeviceInfo(),
|
|
313
|
-
},
|
|
314
|
-
};
|
|
315
318
|
if (isWhiteScreen()) {
|
|
319
|
+
var obj = {
|
|
320
|
+
group: whiteScreenError.group,
|
|
321
|
+
info: {
|
|
322
|
+
msg: '',
|
|
323
|
+
netTime: getNetTime(),
|
|
324
|
+
hisErrors: getHisError(),
|
|
325
|
+
deviceInfo: getDeviceInfo(),
|
|
326
|
+
},
|
|
327
|
+
};
|
|
316
328
|
obj.info.msg = 'WhiteScren Error';
|
|
317
329
|
var allow = true;
|
|
318
330
|
if (handler) {
|
|
319
331
|
allow = handler(obj);
|
|
320
332
|
}
|
|
321
333
|
if (allow !== false && obj.info.msg) {
|
|
322
|
-
spyHead && spyHead.send(obj);
|
|
334
|
+
spyHead && spyHead.send(obj, isSend);
|
|
323
335
|
}
|
|
324
336
|
}
|
|
325
337
|
}, timeout);
|
package/dist/spy-head.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,
|
|
1
|
+
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e="undefined"!=typeof globalThis?globalThis:e||self).__spyHead=r()}(this,function(){"use strict";function E(e){var r=function(e){if(URL){var r=new URL(e);if(void 0!==r.host)return{protocol:r.protocol,host:r.host,pathname:r.pathname,ext:""}}}(e);if(!r){var n=document.createElement("a");n.href=e,r={protocol:n.protocol,host:n.host||location.host,pathname:n.pathname,ext:""}}var t=r.pathname.split(".");return r.ext=t[t.length-1],r}function c(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 r=this.winerrors[this.winerrors.length-1];if(e.info.msg===r.info.msg)return void(r.info.count+=r.info.count||0)}this.winerrors.length<1e3&&this.winerrors.push(e)},send:function(e,r,n){var t=this.conf;if(e.type=e.type||"except",e.pid=t.pid,e.lid=t.lid,e.ts=Date.now(),this.addError(e),this.interceptor&&this.interceptor(e),!1!==r){var o=(n=n||t.logServer)+"?pid="+e.pid+"&lid="+e.lid+"&ts="+e.ts+"&type="+e.type+"&group="+e.group+"&info="+encodeURIComponent(JSON.stringify(e.info));e.dim&&(o+="&dim="+encodeURIComponent(JSON.stringify(e.dim)));var i=new Image;i.src=o,i.onload=i.onerror=function(){i=null}}}};function r(e){var h=e.resourceError||{},m=e.jsError||{},g=Math.random()<(m.sample?m.sample:0),v=Math.random()<(h.sample?h.sample:0),w=T.winerrors,y=0;function r(e){try{var r=e.target,n={info:{},dim:{},group:""},t=n.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){n.group=m.group;var a=e.error||{};if(t.msg=e.message,t.file=e.filename,t.ln=e.lineno,t.col=e.colno,t.stack=(a.stack||"").split("\n").slice(0,3).join("\n"),-1!==t.msg.indexOf("MODULE_TIMEOUT")){var s=t.msg.match(/^.*Hang:(.*); Miss:(.*)/);s&&s[2]&&(t.msg="MODULE_TIMEOUT for miss:"+s[2])}for(var c=[],f=0;f<w.length;f++){var d=w[f],u=1<d.info.count?"("+d.info.count+")":"";c.push(u+d.info.msg)}t.hisErrors=c.join("----");var p=!0;m.handler&&(p=m.handler(n)),!1!==p&&T.send(n,g)}else{n.group=h.group,n.dim.type=o.tagName.toLowerCase();var l=o.src||o.href;t.msg=l||"unknown load eror",n.dim.host=E(l).host,r&&"IMG"===r.tagName&&(t.xpath=function(e){if(!e)return{xpath:""};for(var r=[];e&&1===e.nodeType&&e!==e.parentNode;){var n=e.tagName.toLowerCase();if(e.getAttribute("id")?n+="[#"+e.getAttribute("id")+"]":e.classList&&e.classList.length&&(n+="[."+e.classList[e.classList.length-1]+"]"),r.push(n),e===document.body)break;e=e.parentNode}return{xpath:r.join("<")}}(r).xpath),y&&(t.hisErrCount=y);p=!0;h.handler&&(p=h.handler(n)),!1!==p&&T.send(n,v),y++}}catch(e){console.error(e)}}window.addEventListener("error",r,!0),T.errorDestroy=function(){window.removeEventListener("error",r,!0),T.winerrors=[]}}function n(e){var n=e.whiteScreenError||{},t=n.handler,o=n.selector,i=n.subSelector,r=n.timeout||6e3,a=Math.random()<(n.sample?n.sample:0);function s(){if(!window.performance)return!1;var e=function(e){return{wait:c(e.domainLookupStart-(e.navigationStart||e.fetchStart||e.startTime)),dns:c(e.domainLookupEnd-e.domainLookupStart),connect:c(e.connectEnd-e.connectStart),req:c(e.responseStart-e.requestStart),res:c(e.responseEnd-e.responseStart)}}(window.performance.timing);return"&wait="+e.wait+"&dns="+e.dns+"&connect="+e.connect+"&requestTime="+e.req+"&resoneTime="+e.res}o&&setTimeout(function(){if(function(){var e=document.querySelector(o);return!e||(!e.querySelector(i)||e.clientHeight<2*window.innerHeight/3)}()){var e={group:n.group,info:{msg:"",netTime:s(),hisErrors:function(){if(!T.winerrors)return!1;for(var e=T.winerrors,r=[],n=0;n<e.length;n++){var t=(e[n].info.stack||"").split("\n")[0];r.push("("+n+")"+(t||e[n].info.msg))}return r.join(";;")}(),deviceInfo:function(){var e={},r=navigator.connection||{};return e.downlink=r.downlink,e.effectiveType=r.effectiveType,e.rtt=r.rtt,e.deviceMemory=navigator.deviceMemory||0,e.hardwareConcurrency=navigator.hardwareConcurrency||0,e}()}};e.info.msg="WhiteScren Error";var r=!0;t&&(r=t(e)),!1!==r&&e.info.msg&&T&&T.send(e,a)}},r)}return T.init=function(e){e.logServer||(e.logServer="https://sp1.baidu.com/5b1ZeDe5KgQFm2e88IuM_a/mwb2.gif"),r(this.conf=e),function(){if(window.PerformanceObserver){var e=new window.PerformanceObserver(function(e){for(var r=T.entryMap,n=e.getEntries(),t=0;t<n.length;t++){var o=n[t];r[o.entryType]||(r[o.entryType]=[]),r[o.entryType].push(o)}});T.observerDestroy=function(){e.disconnect()};try{e.observe({entryTypes:["longtask","layout-shift","first-input","largest-contentful-paint"]})}catch(e){}}}(),n(e)},window.__spyclientConf&&T.init(window.__spyclientConf),T});
|