spy-client 2.1.9 → 2.1.12

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/dist/spy-head.js CHANGED
@@ -158,8 +158,10 @@
158
158
  if (srcElement === window) {
159
159
  obj.group = jsError.group;
160
160
  // 异常信息
161
- var error = event.error || {};
162
- info.msg = event.message;
161
+ // promise错误从reason取
162
+ var error = (event.error || event.reason) || {};
163
+ // promise错误从error.message取
164
+ info.msg = event.message || error.message || '';
163
165
  info.file = event.filename;
164
166
  info.ln = event.lineno;
165
167
  info.col = event.colno;
@@ -192,6 +194,10 @@
192
194
  obj.group = resourceError.group;
193
195
  obj.dim.type = srcElement.tagName.toLowerCase();
194
196
  var url = srcElement.src || srcElement.href || '';
197
+ // 日志本身失败,要忽略
198
+ if (url.indexOf('/mwb2.gif?') > -1) {
199
+ return;
200
+ }
195
201
  info.msg = url || 'unknown load eror';
196
202
  obj.dim.host = getUrlInfo(url).host;
197
203
  if (el && el.tagName === 'IMG') {
@@ -215,8 +221,11 @@
215
221
  }
216
222
  }
217
223
  window.addEventListener('error', spyListenError, true);
224
+ // Promise未处理拒绝监控
225
+ window.addEventListener('unhandledrejection', spyListenError, true);
218
226
  spyHead.errorDestroy = function () {
219
227
  window.removeEventListener('error', spyListenError, true);
228
+ window.removeEventListener('unhandledrejection', spyListenError, true);
220
229
  spyHead.winerrors = [];
221
230
  };
222
231
  }
@@ -1 +1 @@
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&&e)try{var r=new URL(e);if(void 0!==r.host)return{protocol:r.protocol,host:r.host,pathname:r.pathname,ext:""}}catch(e){console.error(e)}}(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});
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&&e)try{var r=new URL(e);if(void 0!==r.host)return{protocol:r.protocol,host:r.host,pathname:r.pathname,ext:""}}catch(e){console.error(e)}}(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||e.reason||{};if(t.msg=e.message||a.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||"";if(-1<l.indexOf("/mwb2.gif?"))return;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),window.addEventListener("unhandledrejection",r,!0),T.errorDestroy=function(){window.removeEventListener("error",r,!0),window.removeEventListener("unhandledrejection",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});
@@ -5,7 +5,6 @@
5
5
  <title>SPY Client Test</title>
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
7
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
8
- <meta http-equiv="refresh" content="2;URL=http://localhost:8000/example/local-cache.html">
9
8
  <script src="/dist/spy-head.js"></script>
10
9
  <script>
11
10
  // 配置
@@ -47,13 +46,15 @@
47
46
  <div id="main">
48
47
  <div>open devtool</div>
49
48
 
49
+ <div style="height: 100px;width: 100%; background-image: url('');"></div>
50
+
50
51
  <button type="button" onclick="gettiming()" style="width:300px;">点此更新performance timing</button>
51
52
  <pre id="text"></pre>
52
53
  <p>
53
54
  TypeScriptJavaScriptJavaScript 的超集用于解决大型项目的代码复杂性一种脚本语言,用于创建动态网页。可以在编译期间发现并纠正错误作为一种解释型语言,只能在运行时发现错误强类型,支持静态和动态类型弱类型,没有静态类型选项最终被编译成 JavaScript 代码,使浏览器可以理解可以直接在浏览器中使用支持模块、泛型和接口不支持模块,泛型或接口支持 ES3,ES4,ES5 和 ES6 等不支持编译其他 ES3,ES4,ES5 或 ES6 功能社区的支持仍在增长,而且还不是很大大量的社区支持以及大量文档和解决问题的支持
54
55
  </p>
55
56
  <img src="https://t7.baidu.com/it/u=1211001202,1148572269&fm=193&app=53&size=w414&n=0&g=0n&f=jpeg?sec=1594890084&t=cde9e5bcd0b06de0c989741a7853bd06&a=1" alt="">
56
- <img class="bigimg" src="https://expertimg.cdn.bcebos.com/expertcms/med/zhongyao.jpg" alt="">
57
+ <img class="bigimg" src="https://app-center.cdn.bcebos.com/appcenter/sts/pcfile/5944066977/2507de0a4ceaa97eedbc0421776a69a7.png" alt="">
57
58
  <script>window.perfFirstScreen = performance.now();</script>
58
59
  </div>
59
60
  <script src="https://mss0.bdstatic.com/se/static/js/iphone/zbios/zbiosT_f69.js"></script>
@@ -328,6 +329,10 @@ window.onload = function () {
328
329
  document.dispatchEvent(new Event('visibilitychange'));
329
330
 
330
331
  }, 2000);
332
+
333
+ new Promise((resolve, reject) => {
334
+ reject(new Error('Something went wrong in Promise!'));
335
+ });
331
336
  };
332
337
  </script>
333
338
  </body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spy-client",
3
- "version": "2.1.9",
3
+ "version": "2.1.12",
4
4
  "description": "spy client",
5
5
  "main": "dist/spy-client.js",
6
6
  "module": "dist/spy-client.esm.js",
@@ -16,7 +16,7 @@
16
16
  "example": "npm run dev && echo 'open url http://localhost:8000/example' && python -m SimpleHTTPServer 8000 ",
17
17
  "test": "karma start karma.conf.js",
18
18
  "release_pre": "rm -fr dist && npm run build && npm run lint && npm run test",
19
- "release": "npm version patch && npm publish",
19
+ "release": "npm version patch && npm publish --registry=https://registry.npmjs.org",
20
20
  "release_post": "git push origin master && git push origin --tags"
21
21
  },
22
22
  "directories": {