spy-client 2.1.7 → 2.1.9

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.
Files changed (80) hide show
  1. package/README.md +54 -11
  2. package/dist/spy-client-basic.esm.js +5 -2
  3. package/dist/spy-client-basic.iife.js +5 -2
  4. package/dist/spy-client-basic.iife.min.js +1 -1
  5. package/dist/spy-client-basic.js +5 -2
  6. package/dist/spy-client-basic.min.js +1 -1
  7. package/dist/spy-client-basic.mjs +5 -2
  8. package/dist/spy-client.esm.js +19 -11
  9. package/dist/spy-client.iife.js +19 -11
  10. package/dist/spy-client.iife.min.js +1 -1
  11. package/dist/spy-client.js +19 -11
  12. package/dist/spy-client.min.js +1 -1
  13. package/dist/spy-client.mjs +19 -11
  14. package/dist/spy-head.js +15 -10
  15. package/dist/spy-head.min.js +1 -1
  16. package/example/index.html +2 -0
  17. package/package.json +1 -1
  18. package/coverage/Chrome 92.0.4515.159 (Mac OS 10.15.7)/html/base.css +0 -224
  19. package/coverage/Chrome 92.0.4515.159 (Mac OS 10.15.7)/html/basicSpec.ts.html +0 -740
  20. package/coverage/Chrome 92.0.4515.159 (Mac OS 10.15.7)/html/block-navigation.js +0 -79
  21. package/coverage/Chrome 92.0.4515.159 (Mac OS 10.15.7)/html/checkSpec.ts.html +0 -479
  22. package/coverage/Chrome 92.0.4515.159 (Mac OS 10.15.7)/html/favicon.png +0 -0
  23. package/coverage/Chrome 92.0.4515.159 (Mac OS 10.15.7)/html/headSpec.ts.html +0 -695
  24. package/coverage/Chrome 92.0.4515.159 (Mac OS 10.15.7)/html/index.html +0 -171
  25. package/coverage/Chrome 92.0.4515.159 (Mac OS 10.15.7)/html/markSpec.ts.html +0 -284
  26. package/coverage/Chrome 92.0.4515.159 (Mac OS 10.15.7)/html/metricSpec.ts.html +0 -977
  27. package/coverage/Chrome 92.0.4515.159 (Mac OS 10.15.7)/html/prettify.css +0 -1
  28. package/coverage/Chrome 92.0.4515.159 (Mac OS 10.15.7)/html/prettify.js +0 -2
  29. package/coverage/Chrome 92.0.4515.159 (Mac OS 10.15.7)/html/sort-arrow-sprite.png +0 -0
  30. package/coverage/Chrome 92.0.4515.159 (Mac OS 10.15.7)/html/sorter.js +0 -170
  31. package/coverage/Chrome 95.0.4638.69 (Mac OS 10.15.7)/html/base.css +0 -224
  32. package/coverage/Chrome 95.0.4638.69 (Mac OS 10.15.7)/html/basicSpec.ts.html +0 -740
  33. package/coverage/Chrome 95.0.4638.69 (Mac OS 10.15.7)/html/block-navigation.js +0 -79
  34. package/coverage/Chrome 95.0.4638.69 (Mac OS 10.15.7)/html/checkSpec.ts.html +0 -479
  35. package/coverage/Chrome 95.0.4638.69 (Mac OS 10.15.7)/html/favicon.png +0 -0
  36. package/coverage/Chrome 95.0.4638.69 (Mac OS 10.15.7)/html/headSpec.ts.html +0 -695
  37. package/coverage/Chrome 95.0.4638.69 (Mac OS 10.15.7)/html/index.html +0 -171
  38. package/coverage/Chrome 95.0.4638.69 (Mac OS 10.15.7)/html/markSpec.ts.html +0 -284
  39. package/coverage/Chrome 95.0.4638.69 (Mac OS 10.15.7)/html/metricSpec.ts.html +0 -977
  40. package/coverage/Chrome 95.0.4638.69 (Mac OS 10.15.7)/html/prettify.css +0 -1
  41. package/coverage/Chrome 95.0.4638.69 (Mac OS 10.15.7)/html/prettify.js +0 -2
  42. package/coverage/Chrome 95.0.4638.69 (Mac OS 10.15.7)/html/sort-arrow-sprite.png +0 -0
  43. package/coverage/Chrome 95.0.4638.69 (Mac OS 10.15.7)/html/sorter.js +0 -170
  44. package/coverage/Chrome 96.0.4664.55 (Mac OS 10.15.7)/html/base.css +0 -224
  45. package/coverage/Chrome 96.0.4664.55 (Mac OS 10.15.7)/html/basicSpec.ts.html +0 -740
  46. package/coverage/Chrome 96.0.4664.55 (Mac OS 10.15.7)/html/block-navigation.js +0 -79
  47. package/coverage/Chrome 96.0.4664.55 (Mac OS 10.15.7)/html/checkSpec.ts.html +0 -479
  48. package/coverage/Chrome 96.0.4664.55 (Mac OS 10.15.7)/html/favicon.png +0 -0
  49. package/coverage/Chrome 96.0.4664.55 (Mac OS 10.15.7)/html/headSpec.ts.html +0 -695
  50. package/coverage/Chrome 96.0.4664.55 (Mac OS 10.15.7)/html/index.html +0 -171
  51. package/coverage/Chrome 96.0.4664.55 (Mac OS 10.15.7)/html/markSpec.ts.html +0 -284
  52. package/coverage/Chrome 96.0.4664.55 (Mac OS 10.15.7)/html/metricSpec.ts.html +0 -977
  53. package/coverage/Chrome 96.0.4664.55 (Mac OS 10.15.7)/html/prettify.css +0 -1
  54. package/coverage/Chrome 96.0.4664.55 (Mac OS 10.15.7)/html/prettify.js +0 -2
  55. package/coverage/Chrome 96.0.4664.55 (Mac OS 10.15.7)/html/sort-arrow-sprite.png +0 -0
  56. package/coverage/Chrome 96.0.4664.55 (Mac OS 10.15.7)/html/sorter.js +0 -170
  57. package/src/head/base.ts +0 -69
  58. package/src/head/error.ts +0 -118
  59. package/src/head/observer.ts +0 -40
  60. package/src/head/readme.md +0 -1
  61. package/src/head/whitescreen.ts +0 -105
  62. package/src/lib/data.ts +0 -14
  63. package/src/lib/huffman.ts +0 -307
  64. package/src/lib/interface.ts +0 -331
  65. package/src/lib/spyHeadInterface.ts +0 -40
  66. package/src/lib/util.ts +0 -101
  67. package/src/module/fid.ts +0 -56
  68. package/src/module/layoutShift.ts +0 -71
  69. package/src/module/lcp.ts +0 -63
  70. package/src/module/longtask.ts +0 -193
  71. package/src/module/memory.ts +0 -43
  72. package/src/module/navigatorInfo.ts +0 -61
  73. package/src/module/resource.ts +0 -433
  74. package/src/module/timing.ts +0 -75
  75. package/src/module/tti.ts +0 -139
  76. package/src/spy-client-basic.ts +0 -387
  77. package/src/spy-client.ts +0 -198
  78. package/src/spy-head.ts +0 -31
  79. package/src/spy-local-cache.ts +0 -478
  80. package/src/types/globals.d.ts +0 -93
package/README.md CHANGED
@@ -3,10 +3,12 @@
3
3
  ## 介绍
4
4
  日志采集模块,提供一系列方便的api供使用
5
5
 
6
- ## 安装
6
+ 1. 新版2.x部分API不再兼容1.x
7
+ 2. 从2.1.0版本开始,不再兼容IE8及以下IE浏览器
8
+ 3. 从2.1.8版本开始,兼容小程序环境(new Image类发送);通过继承类,覆盖request方法,可以支持Node.js/跨端框架/小程序环境
9
+
7
10
 
8
- 新版2.x部分API不再兼容1.x
9
- 从2.1.0版本开始,不再兼容IE8及以下IE浏览器
11
+ ## 安装
10
12
 
11
13
  ```
12
14
  npm install spy-client --save
@@ -18,13 +20,13 @@ CDN方式
18
20
 
19
21
  ```html
20
22
  <!--增强版SDK-->
21
- <script src="https://code.bdstatic.com/npm/spy-client@2.1.4/dist/spy-client.min.js" type="text/javascript"></script>
23
+ <script src="https://code.bdstatic.com/npm/spy-client@2.1.8/dist/spy-client.min.js" type="text/javascript"></script>
22
24
 
23
25
  <!--增强版SDK spy-head-->
24
- <script src="https://code.bdstatic.com/npm/spy-client@2.1.4/dist/spy-head.min.js" type="text/javascript"></script>
26
+ <script src="https://code.bdstatic.com/npm/spy-client@2.1.8/dist/spy-head.min.js" type="text/javascript"></script>
25
27
 
26
28
  <!--基础版SDK-->
27
- <script src="https://code.bdstatic.com/npm/spy-client@2.1.4/dist/spy-client-basic.min.js" type="text/javascript"></script>
29
+ <script src="https://code.bdstatic.com/npm/spy-client@2.1.8/dist/spy-client-basic.min.js" type="text/javascript"></script>
28
30
 
29
31
  ```
30
32
 
@@ -180,6 +182,42 @@ spy.clearAllMark(); // 清除所有mark的信息
180
182
 
181
183
  ```
182
184
 
185
+ 基础版可支持小程序/Node.js/跨端框架环境
186
+
187
+ 1 . 小程序
188
+ 不用做任何修改,就支持采用new Image发送日志。
189
+
190
+ 2 . Node.js/跨端框架环境
191
+
192
+ Node.js,跨端框架,以及小程序环境中若采用`spy.send(xxx, true)`方式,则需要继承SpyClient类,覆盖request方法.
193
+ 如果是Node.js,需要服务器有外网权限
194
+
195
+ ```javascript
196
+ const SpyClient = require('spy-client/dist/spy-client-basic');
197
+ // 若环境编译不支持umd,则可以导入es module
198
+ // const SpyClient = require('spy-client/dist/spy-client-basic.esm');
199
+
200
+ class SpyClientNode from SpyClient {
201
+ request(url: string, data?: any) {
202
+ axios({
203
+ method: data ? 'post' : 'get',
204
+ url,
205
+ data: data ? JSON.stringify(data) : data,
206
+ });
207
+ }
208
+ }
209
+
210
+ const spy = new SpyClientNode({
211
+ pid: '1_1000', // 必须
212
+ lid: '', // 可选,页面的logid
213
+ sample: 1 // 可选,默认为1, 全局抽样,取值:[0-1], 所有发送接口都受到该抽样,单个发送接口的sample配置会覆盖该抽样。
214
+ });
215
+ spy.sendPerf({
216
+ info: {
217
+ responseTime: 200
218
+ }
219
+ });
220
+ ```
183
221
 
184
222
  ## 增强版SDK
185
223
 
@@ -194,6 +232,8 @@ spy.clearAllMark(); // 清除所有mark的信息
194
232
  * 异常:包含大于150K的大图片采集、HTTPS环境下HTTP资源采集
195
233
  * 辅助方式: mark系列辅助方法
196
234
 
235
+ > 增强版SDK仅支持浏览器环境
236
+
197
237
  ### spy-head使用
198
238
 
199
239
  spy-head JS可以视情况通过script内联或嵌入其他JS里
@@ -885,13 +925,16 @@ npm run build
885
925
  # development编译,产出到dist
886
926
  npm run dev
887
927
 
888
- # 发布npm包
928
+ # 发布
929
+ # 1. 构建测试
889
930
  npm run release_pre
890
-
891
- git add . && git commit -m "xx"
892
-
931
+ # 2. 提交代码
932
+ git add . && git commit -m "升级/Fix"
933
+ # 3. 发布npm包,增加tag
893
934
  npm run release
894
935
 
895
- # 修改文档等,把代码push
936
+ # 4. 修改Readme文档里版本号
937
+ git add . && git commit -m "修改文档版本"
938
+ # 5. 把代码push到远程
896
939
  npm run release_post
897
940
  ```
@@ -27,7 +27,8 @@ function assign() {
27
27
  * @author kaivean
28
28
  */
29
29
  var defaultLogServer = 'https://sp1.baidu.com/5b1ZeDe5KgQFm2e88IuM_a/mwb2.gif?';
30
- var ver = navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/);
30
+ // 基础版本兼容非浏览器环境
31
+ var ver = navigator && navigator.userAgent ? navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/) : '';
31
32
  var isLtIos14 = ver && ver[2] && (+ver[2] < 14);
32
33
  function err(msg) {
33
34
  console.error("[SpyClient_log]" + msg);
@@ -267,6 +268,7 @@ var SpyClient = /** @class */ (function () {
267
268
  // 有data时,意味着要用post发送请求
268
269
  SpyClient.prototype.request = function (url, data) {
269
270
  if (!(!isLtIos14
271
+ && navigator
270
272
  && navigator.sendBeacon
271
273
  && navigator.sendBeacon(url, data ? JSON.stringify(data) : undefined))) {
272
274
  if (data) {
@@ -278,7 +280,8 @@ var SpyClient = /** @class */ (function () {
278
280
  }
279
281
  };
280
282
  SpyClient.prototype.fetch = function (url, data) {
281
- if (!window.fetch) {
283
+ if (!fetch) {
284
+ err('Global fetch method doesn\'t exist');
282
285
  return;
283
286
  }
284
287
  fetch(url, {
@@ -30,7 +30,8 @@ var SpyClient = (function () {
30
30
  * @author kaivean
31
31
  */
32
32
  var defaultLogServer = 'https://sp1.baidu.com/5b1ZeDe5KgQFm2e88IuM_a/mwb2.gif?';
33
- var ver = navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/);
33
+ // 基础版本兼容非浏览器环境
34
+ var ver = navigator && navigator.userAgent ? navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/) : '';
34
35
  var isLtIos14 = ver && ver[2] && (+ver[2] < 14);
35
36
  function err(msg) {
36
37
  console.error("[SpyClient_log]" + msg);
@@ -270,6 +271,7 @@ var SpyClient = (function () {
270
271
  // 有data时,意味着要用post发送请求
271
272
  SpyClient.prototype.request = function (url, data) {
272
273
  if (!(!isLtIos14
274
+ && navigator
273
275
  && navigator.sendBeacon
274
276
  && navigator.sendBeacon(url, data ? JSON.stringify(data) : undefined))) {
275
277
  if (data) {
@@ -281,7 +283,8 @@ var SpyClient = (function () {
281
283
  }
282
284
  };
283
285
  SpyClient.prototype.fetch = function (url, data) {
284
- if (!window.fetch) {
286
+ if (!fetch) {
287
+ err('Global fetch method doesn\'t exist');
285
288
  return;
286
289
  }
287
290
  fetch(url, {
@@ -1 +1 @@
1
- var SpyClient=function(){"use strict";function o(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return(Object.assign||function(t){for(var e=void 0,n=1,o=arguments.length;n<o;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,t)}var t=navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/),n=t&&t[2]&&+t[2]<14;function u(t){console.error("[SpyClient_log]"+t)}function a(n){return Object.keys(n).map(function(t){var e=n[t];return void 0===e?e="":"string"!=typeof e&&(e=JSON.stringify(e)),encodeURIComponent(t)+"="+encodeURIComponent(e)}).join("&")}function p(t){return"[object Array]"===Object.prototype.toString.call(t)}function e(t){if(this.sample={},this.markCache={},!t.pid)throw new Error("pid is required");this.option={pid:t.pid,lid:t.lid,check:!1!==t.check,sample:t.sample,localCache:t.localCache,logServer:t.logServer||"https://sp1.baidu.com/5b1ZeDe5KgQFm2e88IuM_a/mwb2.gif?"}}return e.prototype.handle=function(t){if(this.check(t)){if(t=o({pid:this.option.pid,lid:this.option.lid,ts:Date.now(),group:"common"},t),this.option.localCache&&this.option.localCache.addLog(t),"number"==typeof t.sample){if(Math.random()>t.sample)return}else if("number"==typeof this.option.sample&&Math.random()>this.option.sample)return;return delete t.sample,t}},e.prototype.send=function(t,e){void 0===e&&(e=!1);for(var n=[],o=0,r=p(t)?t:[t];o<r.length;o++){var i=r[o];if((i=this.handle(i))&&(n.push(i),!e)){var s=this.option.logServer+a(i);this.request(s)}}e&&this.sendPost(n)},e.prototype.check=function(t){if(!this.option.check)return!0;var e=["perf","except","dist","count"];if(-1===e.indexOf(t.type))return u("type only is one of "+e.join(", ")),!1;if(t.group&&30<t.group.length)return u("group length execeeds 30"),!1;var n=/^[a-zA-Z0-9-_]{0,30}$/;if("except"===t.type){if("string"!=typeof t.info.msg||!t.info.msg.length)return u("info.msg field must be not empty and is String"),!1}else for(var o=0,r=Object.keys(t.info);o<r.length;o++){var i=r[o];if(!n.test(i))return u("info."+i+" is unexpected. Length must be not more than 30. Supported chars: a-zA-Z0-9-_"),!1;var s=t.info[i];if("dist"===t.type){if(30<s.length)return u("info."+i+" value length execeeds 30 when type == 'dist'"),!1}else if("number"!=typeof s)return u("info."+i+" value must be number"),!1}if(t.dim)for(var a=0,p=Object.keys(t.dim);a<p.length;a++){var c=p[a];if(!n.test(c))return u("dim key ["+c+"] is unexpected. Length must be not more than 30. Supported chars: a-zA-Z0-9-_"),!1;var h=t.dim[c];if(!/^[a-zA-Z0-9\-_\*\.\s\/#\+@\&\u4e00-\u9fa5]{0,30}$/.test(h))return u("dim."+c+" value ["+h+"] is unexpected. Length must be not more than 30. Supported chars: a-zA-Z0-9-_*. /#+@& and Chinese"),!1}return!0},e.prototype.sendPerf=function(t){this.send(o({type:"perf"},t))},e.prototype.sendExcept=function(t){this.send(o({type:"except"},t))},e.prototype.sendDist=function(t){this.send(o({type:"dist"},t))},e.prototype.sendCount=function(t){this.send(o({type:"count"},t))},e.prototype.sendExceptForError=function(t,e){var n=o({},e);n.info=o({},e.info||{},{msg:t.message,stack:t.stack}),this.sendExcept(n)},e.prototype.startMark=function(t){this.markCache[t]={start:Date.now()}},e.prototype.endMark=function(t){return this.markCache[t]?(this.markCache[t].total=Date.now()-this.markCache[t].start,this.markCache[t].total):0},e.prototype.clearMark=function(t){this.markCache[t]&&delete this.markCache[t]},e.prototype.getAllMark=function(){for(var t={},e=0,n=Object.keys(this.markCache);e<n.length;e++){var o=n[e];t[o]=this.markCache[o].total}return t},e.prototype.clearAllMark=function(){this.markCache={}},e.prototype.sendPost=function(t){var e=(p(t)?t:[t])[0],n={pid:e.pid,type:e.type,group:e.group},o=this.option.logServer+a(n);this.request(o,t)},e.prototype.request=function(t,e){!n&&navigator.sendBeacon&&navigator.sendBeacon(t,e?JSON.stringify(e):void 0)||(e?this.fetch(t,e):(new Image).src=t)},e.prototype.fetch=function(t,e){window.fetch&&fetch(t,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})},e}();
1
+ var SpyClient=function(){"use strict";function o(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return(Object.assign||function(t){for(var e=void 0,n=1,o=arguments.length;n<o;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,t)}var t=navigator&&navigator.userAgent?navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/):"",n=t&&t[2]&&+t[2]<14;function u(t){console.error("[SpyClient_log]"+t)}function s(n){return Object.keys(n).map(function(t){var e=n[t];return void 0===e?e="":"string"!=typeof e&&(e=JSON.stringify(e)),encodeURIComponent(t)+"="+encodeURIComponent(e)}).join("&")}function p(t){return"[object Array]"===Object.prototype.toString.call(t)}function e(t){if(this.sample={},this.markCache={},!t.pid)throw new Error("pid is required");this.option={pid:t.pid,lid:t.lid,check:!1!==t.check,sample:t.sample,localCache:t.localCache,logServer:t.logServer||"https://sp1.baidu.com/5b1ZeDe5KgQFm2e88IuM_a/mwb2.gif?"}}return e.prototype.handle=function(t){if(this.check(t)){if(t=o({pid:this.option.pid,lid:this.option.lid,ts:Date.now(),group:"common"},t),this.option.localCache&&this.option.localCache.addLog(t),"number"==typeof t.sample){if(Math.random()>t.sample)return}else if("number"==typeof this.option.sample&&Math.random()>this.option.sample)return;return delete t.sample,t}},e.prototype.send=function(t,e){void 0===e&&(e=!1);for(var n=[],o=0,r=p(t)?t:[t];o<r.length;o++){var i=r[o];if((i=this.handle(i))&&(n.push(i),!e)){var a=this.option.logServer+s(i);this.request(a)}}e&&this.sendPost(n)},e.prototype.check=function(t){if(!this.option.check)return!0;var e=["perf","except","dist","count"];if(-1===e.indexOf(t.type))return u("type only is one of "+e.join(", ")),!1;if(t.group&&30<t.group.length)return u("group length execeeds 30"),!1;var n=/^[a-zA-Z0-9-_]{0,30}$/;if("except"===t.type){if("string"!=typeof t.info.msg||!t.info.msg.length)return u("info.msg field must be not empty and is String"),!1}else for(var o=0,r=Object.keys(t.info);o<r.length;o++){var i=r[o];if(!n.test(i))return u("info."+i+" is unexpected. Length must be not more than 30. Supported chars: a-zA-Z0-9-_"),!1;var a=t.info[i];if("dist"===t.type){if(30<a.length)return u("info."+i+" value length execeeds 30 when type == 'dist'"),!1}else if("number"!=typeof a)return u("info."+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 ["+c+"] is unexpected. Length must be not more than 30. Supported chars: a-zA-Z0-9-_"),!1;var h=t.dim[c];if(!/^[a-zA-Z0-9\-_\*\.\s\/#\+@\&\u4e00-\u9fa5]{0,30}$/.test(h))return u("dim."+c+" value ["+h+"] is unexpected. Length must be not more than 30. Supported chars: a-zA-Z0-9-_*. /#+@& and Chinese"),!1}return!0},e.prototype.sendPerf=function(t){this.send(o({type:"perf"},t))},e.prototype.sendExcept=function(t){this.send(o({type:"except"},t))},e.prototype.sendDist=function(t){this.send(o({type:"dist"},t))},e.prototype.sendCount=function(t){this.send(o({type:"count"},t))},e.prototype.sendExceptForError=function(t,e){var n=o({},e);n.info=o({},e.info||{},{msg:t.message,stack:t.stack}),this.sendExcept(n)},e.prototype.startMark=function(t){this.markCache[t]={start:Date.now()}},e.prototype.endMark=function(t){return this.markCache[t]?(this.markCache[t].total=Date.now()-this.markCache[t].start,this.markCache[t].total):0},e.prototype.clearMark=function(t){this.markCache[t]&&delete this.markCache[t]},e.prototype.getAllMark=function(){for(var t={},e=0,n=Object.keys(this.markCache);e<n.length;e++){var o=n[e];t[o]=this.markCache[o].total}return t},e.prototype.clearAllMark=function(){this.markCache={}},e.prototype.sendPost=function(t){var e=(p(t)?t:[t])[0],n={pid:e.pid,type:e.type,group:e.group},o=this.option.logServer+s(n);this.request(o,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}();
@@ -33,7 +33,8 @@
33
33
  * @author kaivean
34
34
  */
35
35
  var defaultLogServer = 'https://sp1.baidu.com/5b1ZeDe5KgQFm2e88IuM_a/mwb2.gif?';
36
- var ver = navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/);
36
+ // 基础版本兼容非浏览器环境
37
+ var ver = navigator && navigator.userAgent ? navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/) : '';
37
38
  var isLtIos14 = ver && ver[2] && (+ver[2] < 14);
38
39
  function err(msg) {
39
40
  console.error("[SpyClient_log]" + msg);
@@ -273,6 +274,7 @@
273
274
  // 有data时,意味着要用post发送请求
274
275
  SpyClient.prototype.request = function (url, data) {
275
276
  if (!(!isLtIos14
277
+ && navigator
276
278
  && navigator.sendBeacon
277
279
  && navigator.sendBeacon(url, data ? JSON.stringify(data) : undefined))) {
278
280
  if (data) {
@@ -284,7 +286,8 @@
284
286
  }
285
287
  };
286
288
  SpyClient.prototype.fetch = function (url, data) {
287
- if (!window.fetch) {
289
+ if (!fetch) {
290
+ err('Global fetch method doesn\'t exist');
288
291
  return;
289
292
  }
290
293
  fetch(url, {
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).SpyClient=t()}(this,function(){"use strict";function o(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return(Object.assign||function(e){for(var t=void 0,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,e)}var e=navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/),n=e&&e[2]&&+e[2]<14;function f(e){console.error("[SpyClient_log]"+e)}function a(n){return Object.keys(n).map(function(e){var t=n[e];return void 0===t?t="":"string"!=typeof t&&(t=JSON.stringify(t)),encodeURIComponent(e)+"="+encodeURIComponent(t)}).join("&")}function p(e){return"[object Array]"===Object.prototype.toString.call(e)}function t(e){if(this.sample={},this.markCache={},!e.pid)throw new Error("pid is required");this.option={pid:e.pid,lid:e.lid,check:!1!==e.check,sample:e.sample,localCache:e.localCache,logServer:e.logServer||"https://sp1.baidu.com/5b1ZeDe5KgQFm2e88IuM_a/mwb2.gif?"}}return t.prototype.handle=function(e){if(this.check(e)){if(e=o({pid:this.option.pid,lid:this.option.lid,ts:Date.now(),group:"common"},e),this.option.localCache&&this.option.localCache.addLog(e),"number"==typeof e.sample){if(Math.random()>e.sample)return}else if("number"==typeof this.option.sample&&Math.random()>this.option.sample)return;return delete e.sample,e}},t.prototype.send=function(e,t){void 0===t&&(t=!1);for(var n=[],o=0,r=p(e)?e:[e];o<r.length;o++){var i=r[o];if((i=this.handle(i))&&(n.push(i),!t)){var s=this.option.logServer+a(i);this.request(s)}}t&&this.sendPost(n)},t.prototype.check=function(e){if(!this.option.check)return!0;var t=["perf","except","dist","count"];if(-1===t.indexOf(e.type))return f("type only is one of "+t.join(", ")),!1;if(e.group&&30<e.group.length)return f("group length execeeds 30"),!1;var n=/^[a-zA-Z0-9-_]{0,30}$/;if("except"===e.type){if("string"!=typeof e.info.msg||!e.info.msg.length)return f("info.msg field must be not empty and is String"),!1}else for(var o=0,r=Object.keys(e.info);o<r.length;o++){var i=r[o];if(!n.test(i))return f("info."+i+" is unexpected. Length must be not more than 30. Supported chars: a-zA-Z0-9-_"),!1;var s=e.info[i];if("dist"===e.type){if(30<s.length)return f("info."+i+" value length execeeds 30 when type == 'dist'"),!1}else if("number"!=typeof s)return f("info."+i+" value must be number"),!1}if(e.dim)for(var a=0,p=Object.keys(e.dim);a<p.length;a++){var c=p[a];if(!n.test(c))return f("dim key ["+c+"] is unexpected. Length must be not more than 30. Supported chars: a-zA-Z0-9-_"),!1;var h=e.dim[c];if(!/^[a-zA-Z0-9\-_\*\.\s\/#\+@\&\u4e00-\u9fa5]{0,30}$/.test(h))return f("dim."+c+" value ["+h+"] is unexpected. Length must be not more than 30. Supported chars: a-zA-Z0-9-_*. /#+@& and Chinese"),!1}return!0},t.prototype.sendPerf=function(e){this.send(o({type:"perf"},e))},t.prototype.sendExcept=function(e){this.send(o({type:"except"},e))},t.prototype.sendDist=function(e){this.send(o({type:"dist"},e))},t.prototype.sendCount=function(e){this.send(o({type:"count"},e))},t.prototype.sendExceptForError=function(e,t){var n=o({},t);n.info=o({},t.info||{},{msg:e.message,stack:e.stack}),this.sendExcept(n)},t.prototype.startMark=function(e){this.markCache[e]={start:Date.now()}},t.prototype.endMark=function(e){return this.markCache[e]?(this.markCache[e].total=Date.now()-this.markCache[e].start,this.markCache[e].total):0},t.prototype.clearMark=function(e){this.markCache[e]&&delete this.markCache[e]},t.prototype.getAllMark=function(){for(var e={},t=0,n=Object.keys(this.markCache);t<n.length;t++){var o=n[t];e[o]=this.markCache[o].total}return e},t.prototype.clearAllMark=function(){this.markCache={}},t.prototype.sendPost=function(e){var t=(p(e)?e:[e])[0],n={pid:t.pid,type:t.type,group:t.group},o=this.option.logServer+a(n);this.request(o,e)},t.prototype.request=function(e,t){!n&&navigator.sendBeacon&&navigator.sendBeacon(e,t?JSON.stringify(t):void 0)||(t?this.fetch(e,t):(new Image).src=e)},t.prototype.fetch=function(e,t){window.fetch&&fetch(e,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})},t});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).SpyClient=t()}(this,function(){"use strict";function o(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return(Object.assign||function(e){for(var t=void 0,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,e)}var e=navigator&&navigator.userAgent?navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/):"",n=e&&e[2]&&+e[2]<14;function f(e){console.error("[SpyClient_log]"+e)}function a(n){return Object.keys(n).map(function(e){var t=n[e];return void 0===t?t="":"string"!=typeof t&&(t=JSON.stringify(t)),encodeURIComponent(e)+"="+encodeURIComponent(t)}).join("&")}function p(e){return"[object Array]"===Object.prototype.toString.call(e)}function t(e){if(this.sample={},this.markCache={},!e.pid)throw new Error("pid is required");this.option={pid:e.pid,lid:e.lid,check:!1!==e.check,sample:e.sample,localCache:e.localCache,logServer:e.logServer||"https://sp1.baidu.com/5b1ZeDe5KgQFm2e88IuM_a/mwb2.gif?"}}return t.prototype.handle=function(e){if(this.check(e)){if(e=o({pid:this.option.pid,lid:this.option.lid,ts:Date.now(),group:"common"},e),this.option.localCache&&this.option.localCache.addLog(e),"number"==typeof e.sample){if(Math.random()>e.sample)return}else if("number"==typeof this.option.sample&&Math.random()>this.option.sample)return;return delete e.sample,e}},t.prototype.send=function(e,t){void 0===t&&(t=!1);for(var n=[],o=0,r=p(e)?e:[e];o<r.length;o++){var i=r[o];if((i=this.handle(i))&&(n.push(i),!t)){var s=this.option.logServer+a(i);this.request(s)}}t&&this.sendPost(n)},t.prototype.check=function(e){if(!this.option.check)return!0;var t=["perf","except","dist","count"];if(-1===t.indexOf(e.type))return f("type only is one of "+t.join(", ")),!1;if(e.group&&30<e.group.length)return f("group length execeeds 30"),!1;var n=/^[a-zA-Z0-9-_]{0,30}$/;if("except"===e.type){if("string"!=typeof e.info.msg||!e.info.msg.length)return f("info.msg field must be not empty and is String"),!1}else for(var o=0,r=Object.keys(e.info);o<r.length;o++){var i=r[o];if(!n.test(i))return f("info."+i+" is unexpected. Length must be not more than 30. Supported chars: a-zA-Z0-9-_"),!1;var s=e.info[i];if("dist"===e.type){if(30<s.length)return f("info."+i+" value length execeeds 30 when type == 'dist'"),!1}else if("number"!=typeof s)return f("info."+i+" value must be number"),!1}if(e.dim)for(var a=0,p=Object.keys(e.dim);a<p.length;a++){var c=p[a];if(!n.test(c))return f("dim key ["+c+"] is unexpected. Length must be not more than 30. Supported chars: a-zA-Z0-9-_"),!1;var h=e.dim[c];if(!/^[a-zA-Z0-9\-_\*\.\s\/#\+@\&\u4e00-\u9fa5]{0,30}$/.test(h))return f("dim."+c+" value ["+h+"] is unexpected. Length must be not more than 30. Supported chars: a-zA-Z0-9-_*. /#+@& and Chinese"),!1}return!0},t.prototype.sendPerf=function(e){this.send(o({type:"perf"},e))},t.prototype.sendExcept=function(e){this.send(o({type:"except"},e))},t.prototype.sendDist=function(e){this.send(o({type:"dist"},e))},t.prototype.sendCount=function(e){this.send(o({type:"count"},e))},t.prototype.sendExceptForError=function(e,t){var n=o({},t);n.info=o({},t.info||{},{msg:e.message,stack:e.stack}),this.sendExcept(n)},t.prototype.startMark=function(e){this.markCache[e]={start:Date.now()}},t.prototype.endMark=function(e){return this.markCache[e]?(this.markCache[e].total=Date.now()-this.markCache[e].start,this.markCache[e].total):0},t.prototype.clearMark=function(e){this.markCache[e]&&delete this.markCache[e]},t.prototype.getAllMark=function(){for(var e={},t=0,n=Object.keys(this.markCache);t<n.length;t++){var o=n[t];e[o]=this.markCache[o].total}return e},t.prototype.clearAllMark=function(){this.markCache={}},t.prototype.sendPost=function(e){var t=(p(e)?e:[e])[0],n={pid:t.pid,type:t.type,group:t.group},o=this.option.logServer+a(n);this.request(o,e)},t.prototype.request=function(e,t){!n&&navigator&&navigator.sendBeacon&&navigator.sendBeacon(e,t?JSON.stringify(t):void 0)||(t?this.fetch(e,t):(new Image).src=e)},t.prototype.fetch=function(e,t){fetch?fetch(e,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}):f("Global fetch method doesn't exist")},t});
@@ -27,7 +27,8 @@ function assign() {
27
27
  * @author kaivean
28
28
  */
29
29
  var defaultLogServer = 'https://sp1.baidu.com/5b1ZeDe5KgQFm2e88IuM_a/mwb2.gif?';
30
- var ver = navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/);
30
+ // 基础版本兼容非浏览器环境
31
+ var ver = navigator && navigator.userAgent ? navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/) : '';
31
32
  var isLtIos14 = ver && ver[2] && (+ver[2] < 14);
32
33
  function err(msg) {
33
34
  console.error("[SpyClient_log]" + msg);
@@ -267,6 +268,7 @@ var SpyClient = /** @class */ (function () {
267
268
  // 有data时,意味着要用post发送请求
268
269
  SpyClient.prototype.request = function (url, data) {
269
270
  if (!(!isLtIos14
271
+ && navigator
270
272
  && navigator.sendBeacon
271
273
  && navigator.sendBeacon(url, data ? JSON.stringify(data) : undefined))) {
272
274
  if (data) {
@@ -278,7 +280,8 @@ var SpyClient = /** @class */ (function () {
278
280
  }
279
281
  };
280
282
  SpyClient.prototype.fetch = function (url, data) {
281
- if (!window.fetch) {
283
+ if (!fetch) {
284
+ err('Global fetch method doesn\'t exist');
282
285
  return;
283
286
  }
284
287
  fetch(url, {
@@ -62,15 +62,20 @@ function assign() {
62
62
  return __assign.apply(this, args);
63
63
  }
64
64
  function getUrlInfoFromURL(url) {
65
- if (URL) {
66
- var obj = new URL(url);
67
- if (obj.host !== undefined) {
68
- return {
69
- protocol: obj.protocol,
70
- host: obj.host,
71
- pathname: obj.pathname,
72
- ext: '',
73
- };
65
+ if (URL && url) {
66
+ try {
67
+ var obj = new URL(url);
68
+ if (obj.host !== undefined) {
69
+ return {
70
+ protocol: obj.protocol,
71
+ host: obj.host,
72
+ pathname: obj.pathname,
73
+ ext: '',
74
+ };
75
+ }
76
+ }
77
+ catch (e) {
78
+ console.error(e);
74
79
  }
75
80
  }
76
81
  return;
@@ -132,7 +137,8 @@ function getxpath(el) {
132
137
  * @author kaivean
133
138
  */
134
139
  var defaultLogServer = 'https://sp1.baidu.com/5b1ZeDe5KgQFm2e88IuM_a/mwb2.gif?';
135
- var ver = navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/);
140
+ // 基础版本兼容非浏览器环境
141
+ var ver = navigator && navigator.userAgent ? navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/) : '';
136
142
  var isLtIos14 = ver && ver[2] && (+ver[2] < 14);
137
143
  function err(msg) {
138
144
  console.error("[SpyClient_log]" + msg);
@@ -372,6 +378,7 @@ var SpyClient$1 = /** @class */ (function () {
372
378
  // 有data时,意味着要用post发送请求
373
379
  SpyClient.prototype.request = function (url, data) {
374
380
  if (!(!isLtIos14
381
+ && navigator
375
382
  && navigator.sendBeacon
376
383
  && navigator.sendBeacon(url, data ? JSON.stringify(data) : undefined))) {
377
384
  if (data) {
@@ -383,7 +390,8 @@ var SpyClient$1 = /** @class */ (function () {
383
390
  }
384
391
  };
385
392
  SpyClient.prototype.fetch = function (url, data) {
386
- if (!window.fetch) {
393
+ if (!fetch) {
394
+ err('Global fetch method doesn\'t exist');
387
395
  return;
388
396
  }
389
397
  fetch(url, {
@@ -65,15 +65,20 @@ var SpyClient = (function () {
65
65
  return __assign.apply(this, args);
66
66
  }
67
67
  function getUrlInfoFromURL(url) {
68
- if (URL) {
69
- var obj = new URL(url);
70
- if (obj.host !== undefined) {
71
- return {
72
- protocol: obj.protocol,
73
- host: obj.host,
74
- pathname: obj.pathname,
75
- ext: '',
76
- };
68
+ if (URL && url) {
69
+ try {
70
+ var obj = new URL(url);
71
+ if (obj.host !== undefined) {
72
+ return {
73
+ protocol: obj.protocol,
74
+ host: obj.host,
75
+ pathname: obj.pathname,
76
+ ext: '',
77
+ };
78
+ }
79
+ }
80
+ catch (e) {
81
+ console.error(e);
77
82
  }
78
83
  }
79
84
  return;
@@ -135,7 +140,8 @@ var SpyClient = (function () {
135
140
  * @author kaivean
136
141
  */
137
142
  var defaultLogServer = 'https://sp1.baidu.com/5b1ZeDe5KgQFm2e88IuM_a/mwb2.gif?';
138
- var ver = navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/);
143
+ // 基础版本兼容非浏览器环境
144
+ var ver = navigator && navigator.userAgent ? navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/) : '';
139
145
  var isLtIos14 = ver && ver[2] && (+ver[2] < 14);
140
146
  function err(msg) {
141
147
  console.error("[SpyClient_log]" + msg);
@@ -375,6 +381,7 @@ var SpyClient = (function () {
375
381
  // 有data时,意味着要用post发送请求
376
382
  SpyClient.prototype.request = function (url, data) {
377
383
  if (!(!isLtIos14
384
+ && navigator
378
385
  && navigator.sendBeacon
379
386
  && navigator.sendBeacon(url, data ? JSON.stringify(data) : undefined))) {
380
387
  if (data) {
@@ -386,7 +393,8 @@ var SpyClient = (function () {
386
393
  }
387
394
  };
388
395
  SpyClient.prototype.fetch = function (url, data) {
389
- if (!window.fetch) {
396
+ if (!fetch) {
397
+ err('Global fetch method doesn\'t exist');
390
398
  return;
391
399
  }
392
400
  fetch(url, {
@@ -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){var e=new URL(t);if(void 0!==e.host)return{protocol:e.protocol,host:e.host,pathname:e.pathname,ext:""}}}(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.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.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){window.fetch&&fetch(t,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})},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 w={};function L(t){return w[t]}var S=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){w[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){S&&S.entryMap&&S.entryMap[T]&&this.handle(S.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,H=(M.prototype.listenTiming=function(t){window.performance&&window.performance.timing&&(this.cb=t)},M.prototype.load=function(){var t=this;setTimeout(function(){t.cb&&t.cb(t.getMetric())},500)},M.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},M);function M(){}(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 x=["/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,x))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(L("lcp")){var e=i.getStatData(performance.timing.navigationStart+L("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 H),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=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}();
@@ -68,15 +68,20 @@
68
68
  return __assign.apply(this, args);
69
69
  }
70
70
  function getUrlInfoFromURL(url) {
71
- if (URL) {
72
- var obj = new URL(url);
73
- if (obj.host !== undefined) {
74
- return {
75
- protocol: obj.protocol,
76
- host: obj.host,
77
- pathname: obj.pathname,
78
- ext: '',
79
- };
71
+ if (URL && url) {
72
+ try {
73
+ var obj = new URL(url);
74
+ if (obj.host !== undefined) {
75
+ return {
76
+ protocol: obj.protocol,
77
+ host: obj.host,
78
+ pathname: obj.pathname,
79
+ ext: '',
80
+ };
81
+ }
82
+ }
83
+ catch (e) {
84
+ console.error(e);
80
85
  }
81
86
  }
82
87
  return;
@@ -138,7 +143,8 @@
138
143
  * @author kaivean
139
144
  */
140
145
  var defaultLogServer = 'https://sp1.baidu.com/5b1ZeDe5KgQFm2e88IuM_a/mwb2.gif?';
141
- var ver = navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/);
146
+ // 基础版本兼容非浏览器环境
147
+ var ver = navigator && navigator.userAgent ? navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/) : '';
142
148
  var isLtIos14 = ver && ver[2] && (+ver[2] < 14);
143
149
  function err(msg) {
144
150
  console.error("[SpyClient_log]" + msg);
@@ -378,6 +384,7 @@
378
384
  // 有data时,意味着要用post发送请求
379
385
  SpyClient.prototype.request = function (url, data) {
380
386
  if (!(!isLtIos14
387
+ && navigator
381
388
  && navigator.sendBeacon
382
389
  && navigator.sendBeacon(url, data ? JSON.stringify(data) : undefined))) {
383
390
  if (data) {
@@ -389,7 +396,8 @@
389
396
  }
390
397
  };
391
398
  SpyClient.prototype.fetch = function (url, data) {
392
- if (!window.fetch) {
399
+ if (!fetch) {
400
+ err('Global fetch method doesn\'t exist');
393
401
  return;
394
402
  }
395
403
  fetch(url, {