cwj_monitoring 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -29,7 +29,7 @@ npm i cwj_monitoring
29
29
  引入
30
30
 
31
31
  ```js
32
- import { init, emit } from "cwj_monitoring";
32
+ import { init } from "cwj_monitoring";
33
33
 
34
34
  //使用 init 全局进行初始化
35
35
  init({
@@ -38,6 +38,6 @@ init({
38
38
  time: 60000, //可选参数,最大缓存时间,即超过最大缓存时间立即上传,默认30s
39
39
  });
40
40
 
41
- //无论vue的全局错误捕获,还是react的错误边界,都可使用emit手动上传错误
42
- emit(type,data)
41
+ //无论vue的全局错误捕获,还是react的错误边界,都可使用window.$track.emit手动上传错误
42
+ window.$track.emit(type,data)
43
43
  ```
package/dist/index.d.ts CHANGED
@@ -4,13 +4,10 @@ type Options = {
4
4
  time?: number;
5
5
  };
6
6
 
7
- declare function emit(type: string, data?: any): void;
8
-
9
7
  declare const init: (options: Options) => void;
10
8
 
11
9
  declare const _default: {
12
10
  init: (options: Options) => void;
13
- emit: typeof emit;
14
11
  };
15
12
 
16
- export { _default as default, emit, init };
13
+ export { _default as default, init };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- function e(){var e;window.onerror=(e,t,r,n,i)=>{I("js_error",{msg:e,url:t,line:r,column:n,error:i})},window.addEventListener("error",(function(e){const t=e.target;t&&(t.src||t.href)&&I("resource_error",t.src||t.href)}),!0),e=window.console.error,window.console.error=function(t){I("console_error",t),e.apply(window.console,arguments)},window.addEventListener("unhandledrejection",(function(e){I("promise_error",e.error.stack)}))}function t(){window.addEventListener("hashchange",(function(){I("hashchange")})),function(){const e=window.history.pushState,t=window.history.replaceState;window.history.pushState=function(){e.apply(window.history,arguments),I("historychange")},window.history.replaceState=function(){t.apply(window.history,arguments),I("historychange")},window.addEventListener("popstate",(function(){I("historychange")}))}()}function r(){!function(){let e;window.addEventListener("click",(t=>{clearTimeout(e),e=setTimeout((()=>{console.log(t),I("click",t.target.innerHTML)}),500)}))}()}function n(){!function(){const e=new PerformanceObserver((t=>{for(const r of t.getEntries())"first-paint"===r.name&&(e.disconnect(),I("fp",r.startTime))}));e.observe({type:"paint",buffered:!0})}(),window.addEventListener("DOMContentLoaded",(function(e){I("DOMContentLoaded",e.timeStamp)})),window.addEventListener("load",(function(e){I("load",e.timeStamp)}))}let i=0,s=0,o=performance.now();function a(e){s++;const t=e-o;if(t>=1e3){Math.round(s/(t/1e3))<20?(i++,i>=3&&(I("fps","卡顿"),i=0)):(i--,i<0&&(i=0)),s=0,o=e}requestAnimationFrame(a)}var u,c=new Uint8Array(16);function d(){if(!u&&!(u="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return u(c)}for(var f=[],l=0;l<256;++l)f.push((l+256).toString(16).slice(1));var h={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function g(e,t,r){if(h.randomUUID&&!t&&!e)return h.randomUUID();var n=(e=e||{}).random||(e.rng||d)();if(n[6]=15&n[6]|64,n[8]=63&n[8]|128,t){r=r||0;for(var i=0;i<16;++i)t[r+i]=n[i];return t}return function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return(f[e[t+0]]+f[e[t+1]]+f[e[t+2]]+f[e[t+3]]+"-"+f[e[t+4]]+f[e[t+5]]+"-"+f[e[t+6]]+f[e[t+7]]+"-"+f[e[t+8]]+f[e[t+9]]+"-"+f[e[t+10]]+f[e[t+11]]+f[e[t+12]]+f[e[t+13]]+f[e[t+14]]+f[e[t+15]]).toLowerCase()}(n)}function v(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function m(e){return m="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},m(e)}function p(e){var t=function(e,t){if("object"!==m(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!==m(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"===m(t)?t:String(t)}function b(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,p(n.key),n)}}function w(e,t,r){return t&&b(e.prototype,t),r&&b(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}var y={"Amazon Silk":"amazon_silk","Android Browser":"android",Bada:"bada",BlackBerry:"blackberry",Chrome:"chrome",Chromium:"chromium",Electron:"electron",Epiphany:"epiphany",Firefox:"firefox",Focus:"focus",Generic:"generic","Google Search":"google_search",Googlebot:"googlebot","Internet Explorer":"ie","K-Meleon":"k_meleon",Maxthon:"maxthon","Microsoft Edge":"edge","MZ Browser":"mz","NAVER Whale Browser":"naver",Opera:"opera","Opera Coast":"opera_coast",PhantomJS:"phantomjs",Puffin:"puffin",QupZilla:"qupzilla",QQ:"qq",QQLite:"qqlite",Safari:"safari",Sailfish:"sailfish","Samsung Internet for Android":"samsung_internet",SeaMonkey:"seamonkey",Sleipnir:"sleipnir",Swing:"swing",Tizen:"tizen","UC Browser":"uc",Vivaldi:"vivaldi","WebOS Browser":"webos",WeChat:"wechat","Yandex Browser":"yandex",Roku:"roku"},M={amazon_silk:"Amazon Silk",android:"Android Browser",bada:"Bada",blackberry:"BlackBerry",chrome:"Chrome",chromium:"Chromium",electron:"Electron",epiphany:"Epiphany",firefox:"Firefox",focus:"Focus",generic:"Generic",googlebot:"Googlebot",google_search:"Google Search",ie:"Internet Explorer",k_meleon:"K-Meleon",maxthon:"Maxthon",edge:"Microsoft Edge",mz:"MZ Browser",naver:"NAVER Whale Browser",opera:"Opera",opera_coast:"Opera Coast",phantomjs:"PhantomJS",puffin:"Puffin",qupzilla:"QupZilla",qq:"QQ Browser",qqlite:"QQ Browser Lite",safari:"Safari",sailfish:"Sailfish",samsung_internet:"Samsung Internet for Android",seamonkey:"SeaMonkey",sleipnir:"Sleipnir",swing:"Swing",tizen:"Tizen",uc:"UC Browser",vivaldi:"Vivaldi",webos:"WebOS Browser",wechat:"WeChat",yandex:"Yandex Browser"},S={tablet:"tablet",mobile:"mobile",desktop:"desktop",tv:"tv"},k={WindowsPhone:"Windows Phone",Windows:"Windows",MacOS:"macOS",iOS:"iOS",Android:"Android",WebOS:"WebOS",BlackBerry:"BlackBerry",Bada:"Bada",Tizen:"Tizen",Linux:"Linux",ChromeOS:"Chrome OS",PlayStation4:"PlayStation 4",Roku:"Roku"},F={EdgeHTML:"EdgeHTML",Blink:"Blink",Trident:"Trident",Presto:"Presto",Gecko:"Gecko",WebKit:"WebKit"},B=function(){function e(){v(this,e)}return w(e,null,[{key:"getFirstMatch",value:function(e,t){var r=t.match(e);return r&&r.length>0&&r[1]||""}},{key:"getSecondMatch",value:function(e,t){var r=t.match(e);return r&&r.length>1&&r[2]||""}},{key:"matchAndReturnConst",value:function(e,t,r){if(e.test(t))return r}},{key:"getWindowsVersionName",value:function(e){switch(e){case"NT":return"NT";case"XP":case"NT 5.1":return"XP";case"NT 5.0":return"2000";case"NT 5.2":return"2003";case"NT 6.0":return"Vista";case"NT 6.1":return"7";case"NT 6.2":return"8";case"NT 6.3":return"8.1";case"NT 10.0":return"10";default:return}}},{key:"getMacOSVersionName",value:function(e){var t=e.split(".").splice(0,2).map((function(e){return parseInt(e,10)||0}));if(t.push(0),10===t[0])switch(t[1]){case 5:return"Leopard";case 6:return"Snow Leopard";case 7:return"Lion";case 8:return"Mountain Lion";case 9:return"Mavericks";case 10:return"Yosemite";case 11:return"El Capitan";case 12:return"Sierra";case 13:return"High Sierra";case 14:return"Mojave";case 15:return"Catalina";default:return}}},{key:"getAndroidVersionName",value:function(e){var t=e.split(".").splice(0,2).map((function(e){return parseInt(e,10)||0}));if(t.push(0),!(1===t[0]&&t[1]<5))return 1===t[0]&&t[1]<6?"Cupcake":1===t[0]&&t[1]>=6?"Donut":2===t[0]&&t[1]<2?"Eclair":2===t[0]&&2===t[1]?"Froyo":2===t[0]&&t[1]>2?"Gingerbread":3===t[0]?"Honeycomb":4===t[0]&&t[1]<1?"Ice Cream Sandwich":4===t[0]&&t[1]<4?"Jelly Bean":4===t[0]&&t[1]>=4?"KitKat":5===t[0]?"Lollipop":6===t[0]?"Marshmallow":7===t[0]?"Nougat":8===t[0]?"Oreo":9===t[0]?"Pie":void 0}},{key:"getVersionPrecision",value:function(e){return e.split(".").length}},{key:"compareVersions",value:function(t,r){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=e.getVersionPrecision(t),s=e.getVersionPrecision(r),o=Math.max(i,s),a=0,u=e.map([t,r],(function(t){var r=o-e.getVersionPrecision(t),n=t+new Array(r+1).join(".0");return e.map(n.split("."),(function(e){return new Array(20-e.length).join("0")+e})).reverse()}));for(n&&(a=o-Math.min(i,s)),o-=1;o>=a;){if(u[0][o]>u[1][o])return 1;if(u[0][o]===u[1][o]){if(o===a)return 0;o-=1}else if(u[0][o]<u[1][o])return-1}}},{key:"map",value:function(e,t){var r,n=[];if(Array.prototype.map)return Array.prototype.map.call(e,t);for(r=0;r<e.length;r+=1)n.push(t(e[r]));return n}},{key:"find",value:function(e,t){var r,n;if(Array.prototype.find)return Array.prototype.find.call(e,t);for(r=0,n=e.length;r<n;r+=1){var i=e[r];if(t(i,r))return i}}},{key:"assign",value:function(e){for(var t,r,n=e,i=arguments.length,s=new Array(i>1?i-1:0),o=1;o<i;o++)s[o-1]=arguments[o];if(Object.assign)return Object.assign.apply(Object,[e].concat(s));var a=function(){var e=s[t];"object"===m(e)&&null!==e&&Object.keys(e).forEach((function(t){n[t]=e[t]}))};for(t=0,r=s.length;t<r;t+=1)a();return e}},{key:"getBrowserAlias",value:function(e){return y[e]}},{key:"getBrowserTypeByAlias",value:function(e){return M[e]||""}}]),e}(),O=/version\/(\d+(\.?_?\d+)+)/i,_=[{test:[/googlebot/i],describe:function(e){var t={name:"Googlebot"},r=B.getFirstMatch(/googlebot\/(\d+(\.\d+))/i,e)||B.getFirstMatch(O,e);return r&&(t.version=r),t}},{test:[/opera/i],describe:function(e){var t={name:"Opera"},r=B.getFirstMatch(O,e)||B.getFirstMatch(/(?:opera)[\s/](\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/opr\/|opios/i],describe:function(e){var t={name:"Opera"},r=B.getFirstMatch(/(?:opr|opios)[\s/](\S+)/i,e)||B.getFirstMatch(O,e);return r&&(t.version=r),t}},{test:[/SamsungBrowser/i],describe:function(e){var t={name:"Samsung Internet for Android"},r=B.getFirstMatch(O,e)||B.getFirstMatch(/(?:SamsungBrowser)[\s/](\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/Whale/i],describe:function(e){var t={name:"NAVER Whale Browser"},r=B.getFirstMatch(O,e)||B.getFirstMatch(/(?:whale)[\s/](\d+(?:\.\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/MZBrowser/i],describe:function(e){var t={name:"MZ Browser"},r=B.getFirstMatch(/(?:MZBrowser)[\s/](\d+(?:\.\d+)+)/i,e)||B.getFirstMatch(O,e);return r&&(t.version=r),t}},{test:[/focus/i],describe:function(e){var t={name:"Focus"},r=B.getFirstMatch(/(?:focus)[\s/](\d+(?:\.\d+)+)/i,e)||B.getFirstMatch(O,e);return r&&(t.version=r),t}},{test:[/swing/i],describe:function(e){var t={name:"Swing"},r=B.getFirstMatch(/(?:swing)[\s/](\d+(?:\.\d+)+)/i,e)||B.getFirstMatch(O,e);return r&&(t.version=r),t}},{test:[/coast/i],describe:function(e){var t={name:"Opera Coast"},r=B.getFirstMatch(O,e)||B.getFirstMatch(/(?:coast)[\s/](\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/opt\/\d+(?:.?_?\d+)+/i],describe:function(e){var t={name:"Opera Touch"},r=B.getFirstMatch(/(?:opt)[\s/](\d+(\.?_?\d+)+)/i,e)||B.getFirstMatch(O,e);return r&&(t.version=r),t}},{test:[/yabrowser/i],describe:function(e){var t={name:"Yandex Browser"},r=B.getFirstMatch(/(?:yabrowser)[\s/](\d+(\.?_?\d+)+)/i,e)||B.getFirstMatch(O,e);return r&&(t.version=r),t}},{test:[/ucbrowser/i],describe:function(e){var t={name:"UC Browser"},r=B.getFirstMatch(O,e)||B.getFirstMatch(/(?:ucbrowser)[\s/](\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/Maxthon|mxios/i],describe:function(e){var t={name:"Maxthon"},r=B.getFirstMatch(O,e)||B.getFirstMatch(/(?:Maxthon|mxios)[\s/](\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/epiphany/i],describe:function(e){var t={name:"Epiphany"},r=B.getFirstMatch(O,e)||B.getFirstMatch(/(?:epiphany)[\s/](\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/puffin/i],describe:function(e){var t={name:"Puffin"},r=B.getFirstMatch(O,e)||B.getFirstMatch(/(?:puffin)[\s/](\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/sleipnir/i],describe:function(e){var t={name:"Sleipnir"},r=B.getFirstMatch(O,e)||B.getFirstMatch(/(?:sleipnir)[\s/](\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/k-meleon/i],describe:function(e){var t={name:"K-Meleon"},r=B.getFirstMatch(O,e)||B.getFirstMatch(/(?:k-meleon)[\s/](\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/micromessenger/i],describe:function(e){var t={name:"WeChat"},r=B.getFirstMatch(/(?:micromessenger)[\s/](\d+(\.?_?\d+)+)/i,e)||B.getFirstMatch(O,e);return r&&(t.version=r),t}},{test:[/qqbrowser/i],describe:function(e){var t={name:/qqbrowserlite/i.test(e)?"QQ Browser Lite":"QQ Browser"},r=B.getFirstMatch(/(?:qqbrowserlite|qqbrowser)[/](\d+(\.?_?\d+)+)/i,e)||B.getFirstMatch(O,e);return r&&(t.version=r),t}},{test:[/msie|trident/i],describe:function(e){var t={name:"Internet Explorer"},r=B.getFirstMatch(/(?:msie |rv:)(\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/\sedg\//i],describe:function(e){var t={name:"Microsoft Edge"},r=B.getFirstMatch(/\sedg\/(\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/edg([ea]|ios)/i],describe:function(e){var t={name:"Microsoft Edge"},r=B.getSecondMatch(/edg([ea]|ios)\/(\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/vivaldi/i],describe:function(e){var t={name:"Vivaldi"},r=B.getFirstMatch(/vivaldi\/(\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/seamonkey/i],describe:function(e){var t={name:"SeaMonkey"},r=B.getFirstMatch(/seamonkey\/(\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/sailfish/i],describe:function(e){var t={name:"Sailfish"},r=B.getFirstMatch(/sailfish\s?browser\/(\d+(\.\d+)?)/i,e);return r&&(t.version=r),t}},{test:[/silk/i],describe:function(e){var t={name:"Amazon Silk"},r=B.getFirstMatch(/silk\/(\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/phantom/i],describe:function(e){var t={name:"PhantomJS"},r=B.getFirstMatch(/phantomjs\/(\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/slimerjs/i],describe:function(e){var t={name:"SlimerJS"},r=B.getFirstMatch(/slimerjs\/(\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/blackberry|\bbb\d+/i,/rim\stablet/i],describe:function(e){var t={name:"BlackBerry"},r=B.getFirstMatch(O,e)||B.getFirstMatch(/blackberry[\d]+\/(\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/(web|hpw)[o0]s/i],describe:function(e){var t={name:"WebOS Browser"},r=B.getFirstMatch(O,e)||B.getFirstMatch(/w(?:eb)?[o0]sbrowser\/(\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/bada/i],describe:function(e){var t={name:"Bada"},r=B.getFirstMatch(/dolfin\/(\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/tizen/i],describe:function(e){var t={name:"Tizen"},r=B.getFirstMatch(/(?:tizen\s?)?browser\/(\d+(\.?_?\d+)+)/i,e)||B.getFirstMatch(O,e);return r&&(t.version=r),t}},{test:[/qupzilla/i],describe:function(e){var t={name:"QupZilla"},r=B.getFirstMatch(/(?:qupzilla)[\s/](\d+(\.?_?\d+)+)/i,e)||B.getFirstMatch(O,e);return r&&(t.version=r),t}},{test:[/firefox|iceweasel|fxios/i],describe:function(e){var t={name:"Firefox"},r=B.getFirstMatch(/(?:firefox|iceweasel|fxios)[\s/](\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/electron/i],describe:function(e){var t={name:"Electron"},r=B.getFirstMatch(/(?:electron)\/(\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/MiuiBrowser/i],describe:function(e){var t={name:"Miui"},r=B.getFirstMatch(/(?:MiuiBrowser)[\s/](\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/chromium/i],describe:function(e){var t={name:"Chromium"},r=B.getFirstMatch(/(?:chromium)[\s/](\d+(\.?_?\d+)+)/i,e)||B.getFirstMatch(O,e);return r&&(t.version=r),t}},{test:[/chrome|crios|crmo/i],describe:function(e){var t={name:"Chrome"},r=B.getFirstMatch(/(?:chrome|crios|crmo)\/(\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/GSA/i],describe:function(e){var t={name:"Google Search"},r=B.getFirstMatch(/(?:GSA)\/(\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:function(e){var t=!e.test(/like android/i),r=e.test(/android/i);return t&&r},describe:function(e){var t={name:"Android Browser"},r=B.getFirstMatch(O,e);return r&&(t.version=r),t}},{test:[/playstation 4/i],describe:function(e){var t={name:"PlayStation 4"},r=B.getFirstMatch(O,e);return r&&(t.version=r),t}},{test:[/safari|applewebkit/i],describe:function(e){var t={name:"Safari"},r=B.getFirstMatch(O,e);return r&&(t.version=r),t}},{test:[/.*/i],describe:function(e){var t=-1!==e.search("\\(")?/^(.*)\/(.*)[ \t]\((.*)/:/^(.*)\/(.*) /;return{name:B.getFirstMatch(t,e),version:B.getSecondMatch(t,e)}}}],A=[{test:[/Roku\/DVP/],describe:function(e){var t=B.getFirstMatch(/Roku\/DVP-(\d+\.\d+)/i,e);return{name:k.Roku,version:t}}},{test:[/windows phone/i],describe:function(e){var t=B.getFirstMatch(/windows phone (?:os)?\s?(\d+(\.\d+)*)/i,e);return{name:k.WindowsPhone,version:t}}},{test:[/windows /i],describe:function(e){var t=B.getFirstMatch(/Windows ((NT|XP)( \d\d?.\d)?)/i,e),r=B.getWindowsVersionName(t);return{name:k.Windows,version:t,versionName:r}}},{test:[/Macintosh(.*?) FxiOS(.*?)\//],describe:function(e){var t={name:k.iOS},r=B.getSecondMatch(/(Version\/)(\d[\d.]+)/,e);return r&&(t.version=r),t}},{test:[/macintosh/i],describe:function(e){var t=B.getFirstMatch(/mac os x (\d+(\.?_?\d+)+)/i,e).replace(/[_\s]/g,"."),r=B.getMacOSVersionName(t),n={name:k.MacOS,version:t};return r&&(n.versionName=r),n}},{test:[/(ipod|iphone|ipad)/i],describe:function(e){var t=B.getFirstMatch(/os (\d+([_\s]\d+)*) like mac os x/i,e).replace(/[_\s]/g,".");return{name:k.iOS,version:t}}},{test:function(e){var t=!e.test(/like android/i),r=e.test(/android/i);return t&&r},describe:function(e){var t=B.getFirstMatch(/android[\s/-](\d+(\.\d+)*)/i,e),r=B.getAndroidVersionName(t),n={name:k.Android,version:t};return r&&(n.versionName=r),n}},{test:[/(web|hpw)[o0]s/i],describe:function(e){var t=B.getFirstMatch(/(?:web|hpw)[o0]s\/(\d+(\.\d+)*)/i,e),r={name:k.WebOS};return t&&t.length&&(r.version=t),r}},{test:[/blackberry|\bbb\d+/i,/rim\stablet/i],describe:function(e){var t=B.getFirstMatch(/rim\stablet\sos\s(\d+(\.\d+)*)/i,e)||B.getFirstMatch(/blackberry\d+\/(\d+([_\s]\d+)*)/i,e)||B.getFirstMatch(/\bbb(\d+)/i,e);return{name:k.BlackBerry,version:t}}},{test:[/bada/i],describe:function(e){var t=B.getFirstMatch(/bada\/(\d+(\.\d+)*)/i,e);return{name:k.Bada,version:t}}},{test:[/tizen/i],describe:function(e){var t=B.getFirstMatch(/tizen[/\s](\d+(\.\d+)*)/i,e);return{name:k.Tizen,version:t}}},{test:[/linux/i],describe:function(){return{name:k.Linux}}},{test:[/CrOS/],describe:function(){return{name:k.ChromeOS}}},{test:[/PlayStation 4/],describe:function(e){var t=B.getFirstMatch(/PlayStation 4[/\s](\d+(\.\d+)*)/i,e);return{name:k.PlayStation4,version:t}}}],E=[{test:[/googlebot/i],describe:function(){return{type:"bot",vendor:"Google"}}},{test:[/huawei/i],describe:function(e){var t=B.getFirstMatch(/(can-l01)/i,e)&&"Nova",r={type:S.mobile,vendor:"Huawei"};return t&&(r.model=t),r}},{test:[/nexus\s*(?:7|8|9|10).*/i],describe:function(){return{type:S.tablet,vendor:"Nexus"}}},{test:[/ipad/i],describe:function(){return{type:S.tablet,vendor:"Apple",model:"iPad"}}},{test:[/Macintosh(.*?) FxiOS(.*?)\//],describe:function(){return{type:S.tablet,vendor:"Apple",model:"iPad"}}},{test:[/kftt build/i],describe:function(){return{type:S.tablet,vendor:"Amazon",model:"Kindle Fire HD 7"}}},{test:[/silk/i],describe:function(){return{type:S.tablet,vendor:"Amazon"}}},{test:[/tablet(?! pc)/i],describe:function(){return{type:S.tablet}}},{test:function(e){var t=e.test(/ipod|iphone/i),r=e.test(/like (ipod|iphone)/i);return t&&!r},describe:function(e){var t=B.getFirstMatch(/(ipod|iphone)/i,e);return{type:S.mobile,vendor:"Apple",model:t}}},{test:[/nexus\s*[0-6].*/i,/galaxy nexus/i],describe:function(){return{type:S.mobile,vendor:"Nexus"}}},{test:[/[^-]mobi/i],describe:function(){return{type:S.mobile}}},{test:function(e){return"blackberry"===e.getBrowserName(!0)},describe:function(){return{type:S.mobile,vendor:"BlackBerry"}}},{test:function(e){return"bada"===e.getBrowserName(!0)},describe:function(){return{type:S.mobile}}},{test:function(e){return"windows phone"===e.getBrowserName()},describe:function(){return{type:S.mobile,vendor:"Microsoft"}}},{test:function(e){var t=Number(String(e.getOSVersion()).split(".")[0]);return"android"===e.getOSName(!0)&&t>=3},describe:function(){return{type:S.tablet}}},{test:function(e){return"android"===e.getOSName(!0)},describe:function(){return{type:S.mobile}}},{test:function(e){return"macos"===e.getOSName(!0)},describe:function(){return{type:S.desktop,vendor:"Apple"}}},{test:function(e){return"windows"===e.getOSName(!0)},describe:function(){return{type:S.desktop}}},{test:function(e){return"linux"===e.getOSName(!0)},describe:function(){return{type:S.desktop}}},{test:function(e){return"playstation 4"===e.getOSName(!0)},describe:function(){return{type:S.tv}}},{test:function(e){return"roku"===e.getOSName(!0)},describe:function(){return{type:S.tv}}}],P=[{test:function(e){return"microsoft edge"===e.getBrowserName(!0)},describe:function(e){if(/\sedg\//i.test(e))return{name:F.Blink};var t=B.getFirstMatch(/edge\/(\d+(\.?_?\d+)+)/i,e);return{name:F.EdgeHTML,version:t}}},{test:[/trident/i],describe:function(e){var t={name:F.Trident},r=B.getFirstMatch(/trident\/(\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:function(e){return e.test(/presto/i)},describe:function(e){var t={name:F.Presto},r=B.getFirstMatch(/presto\/(\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:function(e){var t=e.test(/gecko/i),r=e.test(/like gecko/i);return t&&!r},describe:function(e){var t={name:F.Gecko},r=B.getFirstMatch(/gecko\/(\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/(apple)?webkit\/537\.36/i],describe:function(){return{name:F.Blink}}},{test:[/(apple)?webkit/i],describe:function(e){var t={name:F.WebKit},r=B.getFirstMatch(/webkit\/(\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}}],N=function(){function e(t){var r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(v(this,e),null==t||""===t)throw new Error("UserAgent parameter can't be empty");this._ua=t,this.parsedResult={},!0!==r&&this.parse()}return w(e,[{key:"getUA",value:function(){return this._ua}},{key:"test",value:function(e){return e.test(this._ua)}},{key:"parseBrowser",value:function(){var e=this;this.parsedResult.browser={};var t=B.find(_,(function(t){if("function"==typeof t.test)return t.test(e);if(t.test instanceof Array)return t.test.some((function(t){return e.test(t)}));throw new Error("Browser's test function is not valid")}));return t&&(this.parsedResult.browser=t.describe(this.getUA())),this.parsedResult.browser}},{key:"getBrowser",value:function(){return this.parsedResult.browser?this.parsedResult.browser:this.parseBrowser()}},{key:"getBrowserName",value:function(e){return e?String(this.getBrowser().name).toLowerCase()||"":this.getBrowser().name||""}},{key:"getBrowserVersion",value:function(){return this.getBrowser().version}},{key:"getOS",value:function(){return this.parsedResult.os?this.parsedResult.os:this.parseOS()}},{key:"parseOS",value:function(){var e=this;this.parsedResult.os={};var t=B.find(A,(function(t){if("function"==typeof t.test)return t.test(e);if(t.test instanceof Array)return t.test.some((function(t){return e.test(t)}));throw new Error("Browser's test function is not valid")}));return t&&(this.parsedResult.os=t.describe(this.getUA())),this.parsedResult.os}},{key:"getOSName",value:function(e){var t=this.getOS().name;return e?String(t).toLowerCase()||"":t||""}},{key:"getOSVersion",value:function(){return this.getOS().version}},{key:"getPlatform",value:function(){return this.parsedResult.platform?this.parsedResult.platform:this.parsePlatform()}},{key:"getPlatformType",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=this.getPlatform().type;return e?String(t).toLowerCase()||"":t||""}},{key:"parsePlatform",value:function(){var e=this;this.parsedResult.platform={};var t=B.find(E,(function(t){if("function"==typeof t.test)return t.test(e);if(t.test instanceof Array)return t.test.some((function(t){return e.test(t)}));throw new Error("Browser's test function is not valid")}));return t&&(this.parsedResult.platform=t.describe(this.getUA())),this.parsedResult.platform}},{key:"getEngine",value:function(){return this.parsedResult.engine?this.parsedResult.engine:this.parseEngine()}},{key:"getEngineName",value:function(e){return e?String(this.getEngine().name).toLowerCase()||"":this.getEngine().name||""}},{key:"parseEngine",value:function(){var e=this;this.parsedResult.engine={};var t=B.find(P,(function(t){if("function"==typeof t.test)return t.test(e);if(t.test instanceof Array)return t.test.some((function(t){return e.test(t)}));throw new Error("Browser's test function is not valid")}));return t&&(this.parsedResult.engine=t.describe(this.getUA())),this.parsedResult.engine}},{key:"parse",value:function(){return this.parseBrowser(),this.parseOS(),this.parsePlatform(),this.parseEngine(),this}},{key:"getResult",value:function(){return B.assign({},this.parsedResult)}},{key:"satisfies",value:function(e){var t=this,r={},n=0,i={},s=0;if(Object.keys(e).forEach((function(t){var o=e[t];"string"==typeof o?(i[t]=o,s+=1):"object"===m(o)&&(r[t]=o,n+=1)})),n>0){var o=Object.keys(r),a=B.find(o,(function(e){return t.isOS(e)}));if(a){var u=this.satisfies(r[a]);if(void 0!==u)return u}var c=B.find(o,(function(e){return t.isPlatform(e)}));if(c){var d=this.satisfies(r[c]);if(void 0!==d)return d}}if(s>0){var f=Object.keys(i),l=B.find(f,(function(e){return t.isBrowser(e,!0)}));if(void 0!==l)return this.compareVersion(i[l])}}},{key:"isBrowser",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=this.getBrowserName().toLowerCase(),n=e.toLowerCase(),i=B.getBrowserTypeByAlias(n);return t&&i&&(n=i.toLowerCase()),n===r}},{key:"compareVersion",value:function(e){var t=[0],r=e,n=!1,i=this.getBrowserVersion();if("string"==typeof i)return">"===e[0]||"<"===e[0]?(r=e.substr(1),"="===e[1]?(n=!0,r=e.substr(2)):t=[],">"===e[0]?t.push(1):t.push(-1)):"="===e[0]?r=e.substr(1):"~"===e[0]&&(n=!0,r=e.substr(1)),t.indexOf(B.compareVersions(i,r,n))>-1}},{key:"isOS",value:function(e){return this.getOSName(!0)===String(e).toLowerCase()}},{key:"isPlatform",value:function(e){return this.getPlatformType(!0)===String(e).toLowerCase()}},{key:"isEngine",value:function(e){return this.getEngineName(!0)===String(e).toLowerCase()}},{key:"is",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return this.isBrowser(e,t)||this.isOS(e)||this.isPlatform(e)}},{key:"some",value:function(){var e=this;return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:[]).some((function(t){return e.is(t)}))}}]),e}(),x=function(){function e(){v(this,e)}return w(e,null,[{key:"getParser",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if("string"!=typeof e)throw new Error("UserAgent should be a string");return new N(e,t)}},{key:"parse",value:function(e){return new N(e).getResult()}},{key:"BROWSER_MAP",get:function(){return M}},{key:"ENGINE_MAP",get:function(){return F}},{key:"OS_MAP",get:function(){return k}},{key:"PLATFORMS_MAP",get:function(){return S}}]),e}();const R="uuid";var C=new class{device;uuid;constructor(){this.device=x.parse(window.navigator.userAgent),localStorage.getItem(R)?this.uuid=localStorage.getItem(R):(this.uuid=g(),localStorage.setItem(R,this.uuid))}};const L=navigator.sendBeacon?(e,t)=>{navigator.sendBeacon(e,JSON.stringify(t))}:(e,t)=>{let r=new XMLHttpRequest;r.open("POST",e),r.send(JSON.stringify(t))};let T,V="",j=0,W=0,z=[],q=Date.now();function U(){z.length&&(L(V,z),z.splice(0,z.length))}function I(e,t){const r=Date.now(),n=Object.assign({},C,{type:e,data:t,date:r,url:window.location.href,referrer:document.referrer,uuid:localStorage.getItem(R)});"hashchange"!==e&&"historychange"!==e||(Object.assign(n,{duration:r-q}),q=r),z.push(n),clearTimeout(T),z.length>=j?U():T=setTimeout((()=>{U()}),W)}function G(i){i.url?(V=i.url,j=i.max||5,W=i.time||3e4,n(),a(),e(),t(),r(),window.addEventListener("beforeunload",U,!0)):console.log("@web-tracing: ","缺少参数url")}const Q=function(){let e=!1;return function(t){e||(G(t),e=!0)}}();var D={init:Q,emit:I};export{D as default,I as emit,Q as init};
1
+ function e(){var e;window.onerror=(e,r,t,o,n)=>{x.emit("error_js",{msg:e,url:r,line:t,column:o,error:n})},window.addEventListener("error",(function(e){const{target:r}=e;if(r instanceof HTMLLinkElement||r instanceof HTMLScriptElement||r instanceof HTMLImageElement||r instanceof HTMLAudioElement||r instanceof HTMLVideoElement||r instanceof HTMLIFrameElement){const e=r.src||r.href;x.emit("error_resource",e)}}),!0),e=window.console.error,window.console.error=function(r){x.emit("error_console",r),e.apply(window.console,arguments)},window.addEventListener("unhandledrejection",(function(e){x.emit("error_promise",e.error.stack)}))}function r(){window.addEventListener("hashchange",(function(){x.emit("hashchange")})),function(){const e=window.history.pushState,r=window.history.replaceState;window.history.pushState=function(){e.apply(window.history,arguments),x.emit("historychange")},window.history.replaceState=function(){r.apply(window.history,arguments),x.emit("historychange")},window.addEventListener("popstate",(function(){x.emit("historychange")}))}()}function t(){!function(){const e=new PerformanceObserver((r=>{for(const t of r.getEntries())"first-paint"===t.name&&(e.disconnect(),x.emit("performance_fp",t.startTime))}));e.observe({type:"paint",buffered:!0})}(),window.addEventListener("DOMContentLoaded",(function(e){x.emit("performance_DOMContentLoaded",e.timeStamp)})),window.addEventListener("load",(function(e){x.emit("performance_load",e.timeStamp)}))}let o=0,n=0,i=performance.now();function s(e){n++;const r=e-i;if(r>=1e3){Math.round(n/(r/1e3))<20?(o++,o>=3&&(x.emit("fps","卡顿"),o=0)):(o--,o<0&&(o=0)),n=0,i=e}requestAnimationFrame(s)}var a,c=new Uint8Array(16);function d(){if(!a&&!(a="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return a(c)}for(var m=[],u=0;u<256;++u)m.push((u+256).toString(16).slice(1));var w={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function h(e,r,t){if(w.randomUUID&&!r&&!e)return w.randomUUID();var o=(e=e||{}).random||(e.rng||d)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,r){t=t||0;for(var n=0;n<16;++n)r[t+n]=o[n];return r}return function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return(m[e[r+0]]+m[e[r+1]]+m[e[r+2]]+m[e[r+3]]+"-"+m[e[r+4]]+m[e[r+5]]+"-"+m[e[r+6]]+m[e[r+7]]+"-"+m[e[r+8]]+m[e[r+9]]+"-"+m[e[r+10]]+m[e[r+11]]+m[e[r+12]]+m[e[r+13]]+m[e[r+14]]+m[e[r+15]]).toLowerCase()}(o)}const f="uuid";let l=()=>{const e=(()=>{let e=navigator.userAgent.toLowerCase();return e.indexOf("opera")>-1||e.indexOf("opr")>-1?{browser:"Opera",browser_version:e.match(/ope?ra?\/([\d.]+)/)?.[1]}:e.indexOf("compatible")>-1&&e.indexOf("msie")>-1?{browser:"IE",browser_version:e.match(/(msie\s|trident.*rv:)([\w.]+)/)?.[2]||"IE"}:e.indexOf("edg")>-1?{browser:"Edge",browser_version:e.match(/edge?\/([\d.]+)/)?.[1]}:e.indexOf("firefox")>-1?{browser:"Firefox",browser_version:e.match(/firefox\/([\d.]+)/)?.[1]}:function(){var e=!1;for(var r in navigator.mimeTypes)if("application/360softmgrplugin"===navigator.mimeTypes[r].type)return!e;return e}()&&e.indexOf("safari")>-1?{browser:"360浏览器",browser_version:"Chromium browser"}:e.includes("2345explorer")?{browser:"2345浏览器",browser_version:e.match(/2345explorer\/([\d.]+)/)?.[1]||"Chromium browser"}:e.indexOf("bidubrowser")>-1?{browser:"百度浏览器",browser_version:e.match(/bidubrowser\/([\d.]+)/)?.[1]||"Chromium browser"}:e.indexOf("se 2.x")>-1?{browser:"搜狗浏览器",browser_version:"Chromium browser"}:e.indexOf("safari")>-1&&-1===e.indexOf("chrome")?{browser:"Safari",browser_version:e.match(/version\/([\d.]+)/)?.[1]}:/qqbrowser/.test(e)?{browser:"QQ浏览器",browser_version:e.match(/qqbrowser\/([\d.]+)/)?.[1]}:/micromessenger/i.test(e)?{browser:"微信浏览器",browser_version:e.match(/micromessenger\/([\d.]+)/)?.[1]}:e.indexOf("chrome")>-1&&e.indexOf("safari")>-1?{browser:"Chrome",browser_version:e.match(/chrome\/([\d.]+)/)?.[1]}:{browser:"未检测到的浏览器",browser_version:void 0}})();return l=()=>e,e};function g(){let e=0,r=window.screen,t=navigator.userAgent.toLowerCase();return void 0!==window.devicePixelRatio?e=window.devicePixelRatio:~t.indexOf("msie")?r.deviceXDPI&&r.logicalXDPI&&(e=r.deviceXDPI/r.logicalXDPI):void 0!==window.outerWidth&&void 0!==window.innerWidth&&(e=window.outerWidth/window.innerWidth),e&&(e=Math.round(100*e)),e}var p=new class{device;uuid;constructor(){this.device=Object.assign({},l(),{width:window.screen.width,height:window.screen.height},{ratio:g(),os:(navigator.userAgent.match(/[(](.*?)[)]/)?.[0]||"").replace(/[()]/g,"")}),localStorage.getItem(f)?this.uuid=localStorage.getItem(f):(this.uuid=h(),localStorage.setItem(f,this.uuid))}};const v=navigator.sendBeacon?(e,r)=>{navigator.sendBeacon(e,JSON.stringify(r))}:(e,r)=>{let t=new XMLHttpRequest;t.open("POST",e),t.send(JSON.stringify(r))};var b=new class{cache;constructor(){this.cache=[]}getCacheLength(){return this.cache.length}addCache(e){this.cache.push(e)}clearCache(){this.cache.length=0}};class y{url;max;time;timer;visitTime;constructor(e){this.url=e.url,this.max=e.max||5,this.time=e.time||3e4,this.timer,this.visitTime=Date.now()}formatter(e,r){const t=Date.now(),o=Object.assign({},p,{type:e,data:r,date:t,url:window.location.href,referrer:document.referrer,uuid:localStorage.getItem(f),duration:t-this.visitTime});return this.visitTime=t,o}send(){b.getCacheLength()&&(v(this.url,b.cache),b.clearCache())}emit(e,r){const t=this.formatter(e,r);b.addCache(t),clearTimeout(this.timer),b.getCacheLength()>=this.max?this.send():this.timer=setTimeout((()=>{this.send()}),this.time)}}let x;function L(o){o.url?(x=new y(o),window.$track=x,t(),s(),e(),r(),["click"].forEach((function(e){let r;document.addEventListener(e,(t=>{clearTimeout(r),r=setTimeout((()=>{const r=t.target;r instanceof HTMLButtonElement&&x.emit(e,r.textContent)}),300)}),!0)})),window.addEventListener("beforeunload",x.send,!0)):console.log("@web-tracing: ","缺少参数url")}const O=function(){let e=!1;return function(r){e||(L(r),e=!0)}}();var E={init:O};export{E as default,O as init};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cwj_monitoring",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "基于 JS 适用Web端的插件,为前端项目提供【 行为、性能、异常 】监控手段",
5
5
  "main": "dist",
6
6
  "module": "dist",
@@ -44,7 +44,6 @@
44
44
  "typescript": "^5.1.6"
45
45
  },
46
46
  "dependencies": {
47
- "bowser": "^2.11.0",
48
47
  "uuid": "^9.0.0"
49
48
  }
50
49
  }