@arms/rum-browser
Advanced tools
Comparing version 0.0.24-beta.6 to 0.0.25-beta.7
@@ -1,3 +0,3 @@ | ||
"use strict";exports.__esModule=!0,exports["default"]=void 0;var _rumCore=require("@arms/rum-core"),_base=require("../../utils/base"),_dom=require("../../utils/dom"),_global=require("../../utils/global"),ClickCollector=exports["default"]=/*#__PURE__*/function(){function a(){this.name="click-collector",this.DELAY_TIME=300}var b=a.prototype;return b.setup=function setup(a,b){var c=a.getConfig(),d=c.collectors,e=void 0===d?{}:d;!1===e.action||_global.document.addEventListener("click",function(a){var c=(0,_base.getCurrentTime)(a.timeStamp),d=(0,_base.formatNumber)(performance.now()-a.timeStamp),e=a.target;if(e instanceof HTMLElement){// 根据元素过滤,仅当被关注的元素所嵌套时才会采集数据(默认为 button、a 和表单元素) | ||
"use strict";exports.__esModule=!0,exports["default"]=void 0;var _rumCore=require("@arms/rum-core"),_base=require("../../utils/base"),_dom=require("../../utils/dom"),_global=require("../../utils/global"),ClickCollector=exports["default"]=/*#__PURE__*/function(){function a(){this.name="click-collector",this.DELAY_TIME=300}var b=a.prototype;return b.setup=function setup(a,b){var c=a.getConfig(),d=c.collectors,e=void 0===d?{}:d;!1===e.action||_global.document.addEventListener("click",function(a){var c=(0,_base.getCurrentTime)(a.timeStamp),d=(0,_rumCore.formatNumber)(performance.now()-a.timeStamp),e=a.target;if(e instanceof HTMLElement){// 根据元素过滤,仅当被关注的元素所嵌套时才会采集数据(默认为 button、a 和表单元素) | ||
var f=(0,_dom.getClosestTargetAncestorElement)(e,["button","a","input","select","option","textarea"]);if(f){// 获取语义化的描述 | ||
var g=f.localName,h=f.nodeName,i=f.innerText,j=(g||h).toLowerCase(),k=f.getAttribute("type"),l=i&&": "+(20<i.length?i.slice(0,20)+"...":i),m="click on "+((k?k+"-":"")+j)+l,n={event_type:_rumCore.RumEventType.ACTION,type:"click",name:m,target_name:(0,_dom.getElementXpath)(e),duration:d,times:1,timestamp:c};b(n)}}},!0)},a}(); |
import { ICollector, IContext, IViewData, RumEvent, ITracingHeaders } from '@arms/rum-core'; | ||
import { ResourceStatus } from '../../utils/performance'; | ||
interface IApiAttr { | ||
@@ -11,2 +12,3 @@ view: IViewData; | ||
duration?: number; | ||
success?: ResourceStatus; | ||
} | ||
@@ -13,0 +15,0 @@ declare global { |
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=!0,exports["default"]=void 0;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator")),_extends2=_interopRequireDefault(require("@babel/runtime/helpers/extends")),_asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")),_rumCore=require("@arms/rum-core"),_performance=require("../../utils/performance"),_url=require("../../utils/url"),_view=require("../../utils/view"),_base=require("../../utils/base"),_global=require("../../utils/global"),_uuid=require("../../utils/uuid"),PerfObserver=_global.global.PerformanceObserver,ApiCollector=exports["default"]=/*#__PURE__*/function(){function a(){this.name="api-collector",this.entryTypes=["xmlhttprequest","fetch"],this.cachedEntries=[],this.cachedApiAttrs=[],this.ctx=void 0,this.sendEvent=void 0}var b=a.prototype;return b.setup=function setup(a,b){var c=a.getConfig(),d=c.collectors,e=void 0===d?{}:d;!1===e.api||(this.sendEvent=b,this.ctx=a,this.perfObserver(),this.hackXhr(),this.hackFetch())},b.perfObserver=function perfObserver(){var a=this;if((0,_rumCore.isFunction)(PerfObserver)){var b=new PerformanceObserver(function(b){var c=b.getEntries().filter(function(b){return a.entryTypes.includes(b.initiatorType)});c&&c.length&&c.forEach(function(b){a.mergeDataAndSend({entry:b})})});b.observe({entryTypes:["resource"]})}},b.injectTracing=function injectTracing(a,b){var c,d=this.ctx.getConfig(),e=d.tracing,f=d.pid,g=d.version,h=void 0===g?"1.0.0":g,i=(0,_rumCore.parseTracingOptions)(e),j=i.enable,k=i.sample,l=i.propagatorTypes,m=i.allowedUrls,n=i.tracestate,o=i.baggage;if(j){m.push({match:function match(a){return /^https?:\/\/*/.test(a)&&(0,_rumCore.startsWith)(a,_global.location.origin)},propagatorTypes:l});var p=(0,_rumCore.find)(m,function(b){return(0,_rumCore.matchList)([b.match],a.url)});if(p){var q=p.propagatorTypes;0===q.length&&(q=l);// skywalking | ||
var r=!1;q.includes("sw8")&&(q=["sw8"],r=!0);var s=r?(0,_rumCore.generateGUID)():(0,_rumCore.generateTraceId)(),t=r?(0,_rumCore.generateGUID)():(0,_rumCore.generateSpanId)(),u=(0,_rumCore.performDraw)(k),v=(0,_uuid.getUserID)(),w=(0,_uuid.getSessionID)(),x=void 0===n||n?"rum=v2&browser&"+f+"&"+w+"&"+v:void 0,y=void 0!==o&&o?"rum=v2,appType=browser,pid="+f+",sid="+w+",uid="+v:void 0,z=(0,_rumCore.makeTracingHeaders)(s,t,u,q,{tracestate:x,baggage:y,appId:f,appVersion:h,viewName:null===(c=a.view)||void 0===c?void 0:c.name,host:_global.location.host});u&&(a.trace_id=s,a.trace_data=JSON.stringify({spanId:t,sample:k,sampled:u,headers:z})),b(z)}}// Browser 情况下一直允许同域请求的trace | ||
},b.hackXhr=function hackXhr(){var a=XMLHttpRequest.prototype,b=this;(0,_rumCore.interceptFunction)(a,"open",function(a,c){var d=c+"",e=a.toUpperCase();(0,_rumCore.urlMatch)(d)||"HEAD"===e||(// 异步过程 保证 view_id view_name 正确 | ||
this.apiAttr={},this.apiAttr.url=(0,_url.fixRelativeUrl)(d),this.apiAttr.method=e,this.apiAttr.view=(0,_view.getCurView)(b.ctx),this._start_time=(0,_base.getCurrentTime)())}),(0,_rumCore.interceptFunction)(a,"send",function(){var a=this;this.apiAttr&&b.injectTracing(this.apiAttr,function(b){Object.keys(b).forEach(function(c){a.setRequestHeader(c,b[c])})}),this.addEventListener("loadend",function(){if(a.apiAttr){var c,d=a.status,e=a.statusText,f=a.response;a.apiAttr.status_code=d,a.apiAttr.message=e,(0,_rumCore.isFunction)(PerfObserver)||(c={name:a.apiAttr.url,entryType:"xmlhttprequest",duration:(0,_base.getCurrentTime)()-a._start_time}),b.mergeDataAndSend({attr:a.apiAttr,entry:c})}})})},b.hackFetch=function hackFetch(){var a=this;(0,_base.hackFunction)(_global.global,"fetch",function(b){return function(c,d){var e,f,g;void 0===d&&(d={});var h=c instanceof Request?c.url:(0,_rumCore.isString)(c)?c:c.toString(),i=(null===(e=d)||void 0===e||null===(f=e.method)||void 0===f?void 0:f.toUpperCase())||"GET";// method: 'HEAD' 或 mode: 'no-cors' 的请求不监听 | ||
if((0,_rumCore.urlMatch)(h)||"HEAD"===i||"no-cors"===(null===(g=d)||void 0===g?void 0:g.mode))return b.call(_global.global,c,d);var j=(0,_base.getCurrentTime)(),k={};return k.url=(0,_url.fixRelativeUrl)(h),k.method=i,k.view=(0,_view.getCurView)(a.ctx),a.injectTracing(k,function(a){d.headers=d.headers||{},Object.keys(a).forEach(function(b){d.headers[b]=a[b]})}),b.call(_global.global,c,d).then(/*#__PURE__*/function(){var a=(0,_asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function b(a){var c,d,e;return _regenerator["default"].wrap(function(b){for(;;)switch(b.prev=b.next){case 0:return c=a.clone(),d=c.status,e=c.statusText,k.status_code=d,k.message=e,b.abrupt("return",a);case 5:case"end":return b.stop()}},b)}));return function(){return a.apply(this,arguments)}}(),function(a){throw k.message=a+"",a})["finally"](function(){var b;(0,_rumCore.isFunction)(PerfObserver)||(b={name:k.url,entryType:"fetch",duration:(0,_base.getCurrentTime)()-j}),a.mergeDataAndSend({attr:k,entry:b})})}})},b.mergeDataAndSend=function mergeDataAndSend(a){var b=this;try{var c=function(a,c){var d=b.ctx.getConfig(),e=d.parseResourceName,f=a.url,g=a.status_code,h=a.view,i=(0,_performance.getResourceStatusByCode)(g);b.sendEvent((0,_extends2["default"])({event_type:_rumCore.RumEventType.RESOURCE,url:f,name:(0,_url.getResourceName)(f,e),type:c.initiatorType||c.entryType,success:i},a,(0,_performance.calcResourceTimingData)(c),{view:h}))},d=a.attr,e=a.entry;if(d&&e)return void c(d,e);var f=this.cachedApiAttrs,g=this.cachedEntries;if(d){var h=g.find(function(a){return a.name===d.url});if(!h)return void f.push(d);g=g.filter(function(a){return a.name!==h.name}),c(d,h)}if(e){var i=f.find(function(a){return a.url===e.name});if(!i)return void g.push(e);f=f.filter(function(a){return a.url!==i.url}),c(i,e)}}catch(a){}},a}(); | ||
this.apiAttr={},this.apiAttr.url=(0,_url.fixRelativeUrl)(d),this.apiAttr.method=e,this.apiAttr.view=(0,_view.getCurView)(b.ctx),this._start_time=(0,_base.getCurrentTime)())}),(0,_rumCore.interceptFunction)(a,"send",function(){var a=this;this.apiAttr&&b.injectTracing(this.apiAttr,function(b){Object.keys(b).forEach(function(c){a.setRequestHeader(c,b[c])})}),this.addEventListener("loadend",function(){if(a.apiAttr){var c,d=a.status,e=a.statusText,f=a.response;a.apiAttr.status_code=d,a.apiAttr.message=e,(0,_rumCore.isFunction)(PerfObserver)||(c={name:a.apiAttr.url,entryType:"xmlhttprequest",duration:(0,_base.getCurrentTime)()-a._start_time}),b.mergeDataAndSend({attr:a.apiAttr,entry:c})}}),this.addEventListener("error",function(){a.apiAttr.success=_performance.ResourceStatus.Failed})})},b.hackFetch=function hackFetch(){var a=this;(0,_base.hackFunction)(_global.global,"fetch",function(b){return function(c,d){var e,f,g;void 0===d&&(d={});var h=c instanceof Request?c.url:(0,_rumCore.isString)(c)?c:c.toString(),i=(null===(e=d)||void 0===e||null===(f=e.method)||void 0===f?void 0:f.toUpperCase())||"GET";// method: 'HEAD' 或 mode: 'no-cors' 的请求不监听 | ||
if((0,_rumCore.urlMatch)(h)||"HEAD"===i||"no-cors"===(null===(g=d)||void 0===g?void 0:g.mode))return b.call(_global.global,c,d);var j=(0,_base.getCurrentTime)(),k={};return k.url=(0,_url.fixRelativeUrl)(h),k.method=i,k.view=(0,_view.getCurView)(a.ctx),a.injectTracing(k,function(a){d.headers=d.headers||{},Object.keys(a).forEach(function(b){d.headers[b]=a[b]})}),b.call(_global.global,c,d).then(/*#__PURE__*/function(){var a=(0,_asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function b(a){var c,d,e;return _regenerator["default"].wrap(function(b){for(;;)switch(b.prev=b.next){case 0:return c=a.clone(),d=c.status,e=c.statusText,k.status_code=d,k.message=e,b.abrupt("return",a);case 5:case"end":return b.stop()}},b)}));return function(){return a.apply(this,arguments)}}(),function(a){throw k.message=a+"",a})["catch"](function(){k.success=_performance.ResourceStatus.Failed})["finally"](function(){var b;(0,_rumCore.isFunction)(PerfObserver)||(b={name:k.url,entryType:"fetch",duration:(0,_base.getCurrentTime)()-j}),a.mergeDataAndSend({attr:k,entry:b})})}})},b.mergeDataAndSend=function mergeDataAndSend(a){var b=this;try{var c=function(a,c){var d=b.ctx.getConfig(),e=d.parseResourceName,f=a.url,g=a.status_code,h=a.view,i=(0,_performance.getResourceStatusByCode)(g),j=(0,_performance.calcResourceTimingData)(c)||{duration:c.duration},k=(0,_extends2["default"])({event_type:_rumCore.RumEventType.RESOURCE,url:f,name:(0,_url.getResourceName)(f,e),type:c.initiatorType||c.entryType,success:i},a,{timing_data:JSON.stringify(c)},j,{view:h});b.sendEvent(k)},d=a.attr,e=a.entry;if(d&&e)return void c(d,e);var f=this.cachedApiAttrs,g=this.cachedEntries;if(d){var h=g.find(function(a){return a.name===d.url});if(!h)return void f.push(d);g=g.filter(function(a){return a.name!==h.name}),c(d,h)}if(e){var i=f.find(function(a){return a.url===e.name});if(!i)return void g.push(e);f=f.filter(function(a){return a.url!==i.url}),c(i,e)}}catch(a){}},a}(); |
@@ -1,3 +0,3 @@ | ||
"use strict";exports.__esModule=!0,exports["default"]=void 0;var _rumCore=require("@arms/rum-core"),_base=require("../../utils/base"),_url=require("../../utils/url"),_global=require("../../utils/global"),_view=require("../../utils/view"),PerfObserver=_global.global.PerformanceObserver,MAX_DELAY=600000,PerfCollector=exports["default"]=/*#__PURE__*/function(){function a(){var a=this;this.name="perf-collector",this.ctx=void 0,this.sendEvent=void 0,this.perfObserver=void 0,this.eventCache=void 0,this.perfHandler=function(b){var c=b.getEntries(),d=a.eventCache;if(!d){var e=(0,_view.getCurView)(a.ctx);d=a.eventCache={event_type:_rumCore.RumEventType.VIEW,type:"perf",url:(0,_url.getCurrentURL)(),referrer:_global.document.referrer||"",// 异步任务,保证 view_id view_name 正确 | ||
view:e}}for(var f=0;f<c.length;f++)try{var g=c[f];switch(g.entryType){case"navigation":var h=g.fetchStart,j=g.domInteractive,k=g.domContentLoadedEventEnd,l=g.domComplete,m=g.loadEventEnd;d.dom_interactive=(0,_base.formatNumber)(j-h),d.dom_content_loaded=(0,_base.formatNumber)(k-h),d.dom_complete=(0,_base.formatNumber)(l-h),d.load_event=(0,_base.formatNumber)(m-h),a.sendPerf();break;case"paint":"first-paint"===g.name&&g.startTime<MAX_DELAY?d.first_paint=(0,_base.formatNumber)(g.startTime):"first-contentful-paint"===g.name&&g.startTime<MAX_DELAY&&(d.first_contentful_paint=(0,_base.formatNumber)(g.startTime));break;// 放入 web-vitals 里面处理 与 first_input_delay 一起处理 | ||
"use strict";exports.__esModule=!0,exports["default"]=void 0;var _rumCore=require("@arms/rum-core"),_url=require("../../utils/url"),_global=require("../../utils/global"),_view=require("../../utils/view"),PerfObserver=_global.global.PerformanceObserver,MAX_DELAY=600000,PerfCollector=exports["default"]=/*#__PURE__*/function(){function a(){var a=this;this.name="perf-collector",this.ctx=void 0,this.sendEvent=void 0,this.perfObserver=void 0,this.eventCache=void 0,this.perfHandler=function(b){var c=b.getEntries(),d=a.eventCache;if(!d){var e=(0,_view.getCurView)(a.ctx);d=a.eventCache={event_type:_rumCore.RumEventType.VIEW,type:"perf",url:(0,_url.getCurrentURL)(),referrer:_global.document.referrer||"",// 异步任务,保证 view_id view_name 正确 | ||
view:e}}for(var f=0;f<c.length;f++)try{var g=c[f];switch(g.entryType){case"navigation":var h=g.fetchStart,j=g.responseEnd,k=g.domInteractive,l=g.domContentLoadedEventEnd,m=g.domComplete,n=g.loadEventEnd;d.dom_interactive=(0,_rumCore.formatNumber)(k-h),d.dom_content_loaded=(0,_rumCore.formatNumber)(l-h),d.dom_complete=(0,_rumCore.formatNumber)(m-h),d.load_event=(0,_rumCore.formatNumber)(n-h),d.first_paint=(0,_rumCore.formatNumber)(j-h);break;case"paint":console.log("paint",g),"first-paint"===g.name&&g.startTime<MAX_DELAY?d.first_paint=(0,_rumCore.formatNumber)(g.startTime):"first-contentful-paint"===g.name&&g.startTime<MAX_DELAY&&(d.first_contentful_paint=(0,_rumCore.formatNumber)(g.startTime));break;// 放入 web-vitals 里面处理 与 first_input_delay 一起处理 | ||
// case 'first-input': | ||
@@ -8,2 +8,2 @@ // if (entry.startTime < MAX_DELAY) { | ||
// break | ||
default:return}}catch(a){console.warn("RUM-perfHandler",a)}},this.sendPerf=function(){a.eventCache&&(a.sendEvent(a.eventCache),a.eventCache=null,a.perfObserver.disconnect(),a.perfObserver=null)}}var b=a.prototype;return b.setup=function setup(a,b){var c=this,d=a.getConfig(),e=d.collectors,f=void 0===e?{}:e;!1!==f.perf&&(this.ctx=a,this.sendEvent=b,(0,_rumCore.isFunction)(PerfObserver)&&(this.perfObserver=new PerfObserver(function(a){setTimeout(function(){c.perfHandler(a)},15)}),this.perfObserver.observe({entryTypes:["navigation","paint"]})))},a}();// 10分钟 | ||
default:return}}catch(a){console.warn("RUM-perfHandler",a)}a.sendPerf()},this.sendPerf=function(){a.eventCache&&(console.log("event",a.eventCache),a.sendEvent(a.eventCache),a.eventCache=null,a.perfObserver.disconnect(),a.perfObserver=null)}}var b=a.prototype;return b.setup=function setup(a,b){var c=this,d=a.getConfig(),e=d.collectors,f=void 0===e?{}:e;!1!==f.perf&&(this.ctx=a,this.sendEvent=b,this.sendPerf=(0,_rumCore.debounce)(this.sendPerf,20),(0,_rumCore.isFunction)(PerfObserver)&&(this.perfObserver=new PerfObserver(function(a){(0,_rumCore.delay)(c.perfHandler,20,a)}),this.perfObserver.observe({entryTypes:["navigation","paint"]})))},a}();// 10分钟 |
@@ -1,7 +0,7 @@ | ||
"use strict";exports.__esModule=!0,exports["default"]=void 0;var _rumCore=require("@arms/rum-core"),_base=require("../../utils/base"),_url=require("../../utils/url"),_view=require("../../utils/view"),_webVitals=require("web-vitals"),_global=require("../../utils/global"),WebVitalsCollector=exports["default"]=/*#__PURE__*/function(){function a(){this.name="web-vitals-collector",this.ctx=void 0,this.sendEvent=void 0}var b=a.prototype;return b.setup=function setup(a,b){var c=a.getConfig(),d=c.collectors,e=void 0===d?{}:d;!1===e.webVitals||(this.ctx=a,this.sendEvent=b,this.sendWebvitals())},b.sendWebvitals=function sendWebvitals(){var a=this,b=(0,_view.getCurView)(this.ctx);(0,_webVitals.onLCP)(function(c){a.sendEvent({event_type:_rumCore.RumEventType.VIEW,type:"webvitals",url:(0,_url.getCurrentURL)(),referrer:_global.document.referrer||"",loading_type:"initial_load",// Measure | ||
largest_contentful_paint:(0,_base.formatNumber)(c.value),// 保证 viewId 正确 | ||
"use strict";exports.__esModule=!0,exports["default"]=void 0;var _rumCore=require("@arms/rum-core"),_url=require("../../utils/url"),_view=require("../../utils/view"),_webVitals=require("web-vitals"),_global=require("../../utils/global"),WebVitalsCollector=exports["default"]=/*#__PURE__*/function(){function a(){this.name="web-vitals-collector",this.ctx=void 0,this.sendEvent=void 0}var b=a.prototype;return b.setup=function setup(a,b){var c=a.getConfig(),d=c.collectors,e=void 0===d?{}:d;!1===e.webVitals||(this.ctx=a,this.sendEvent=b,this.sendWebvitals())},b.sendWebvitals=function sendWebvitals(){var a=this,b=(0,_view.getCurView)(this.ctx);(0,_webVitals.onLCP)(function(c){a.sendEvent({event_type:_rumCore.RumEventType.VIEW,type:"webvitals",url:(0,_url.getCurrentURL)(),referrer:_global.document.referrer||"",loading_type:"initial_load",// Measure | ||
largest_contentful_paint:(0,_rumCore.formatNumber)(c.value),// 保证 viewId 正确 | ||
view:b})}),(0,_webVitals.onFID)(function(c){var d={event_type:_rumCore.RumEventType.VIEW,type:"webvitals",url:(0,_url.getCurrentURL)(),referrer:_global.document.referrer||"",loading_type:"initial_load",// Measure | ||
first_input_delay:(0,_base.formatNumber)(c.value),// 保证 viewId 正确 | ||
view:b};(0,_rumCore.isArray)(c.entries)&&c.entries.forEach(function(a){a&&"first-input"===a.entryType&&(d.first_input_time=(0,_base.formatNumber)(a.startTime))}),a.sendEvent(d)}),(0,_webVitals.onCLS)(function(c){a.sendEvent({event_type:_rumCore.RumEventType.VIEW,type:"webvitals",url:(0,_url.getCurrentURL)(),referrer:_global.document.referrer||"",loading_type:"initial_load",// Measure | ||
cumulative_layout_shift:(0,_base.formatNumber)(c.value),// 保证 viewId 正确 | ||
first_input_delay:(0,_rumCore.formatNumber)(c.value),// 保证 viewId 正确 | ||
view:b};(0,_rumCore.isArray)(c.entries)&&c.entries.forEach(function(a){a&&"first-input"===a.entryType&&(d.first_input_time=(0,_rumCore.formatNumber)(a.startTime))}),a.sendEvent(d)}),(0,_webVitals.onCLS)(function(c){a.sendEvent({event_type:_rumCore.RumEventType.VIEW,type:"webvitals",url:(0,_url.getCurrentURL)(),referrer:_global.document.referrer||"",loading_type:"initial_load",// Measure | ||
cumulative_layout_shift:(0,_rumCore.formatNumber)(c.value),// 保证 viewId 正确 | ||
view:b})})},a}(); |
@@ -1,3 +0,4 @@ | ||
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=!0,exports["default"]=void 0;var _extends2=_interopRequireDefault(require("@babel/runtime/helpers/extends")),_inheritsLoose2=_interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose")),_rumCore=require("@arms/rum-core"),_uuid=require("../utils/uuid"),_global=require("../utils/global"),BrowserReporter=/*#__PURE__*/function(a){function b(){for(var b,c=arguments.length,d=Array(c),e=0;e<c;e++)d[e]=arguments[e];return b=a.call.apply(a,[this].concat(d))||this,b.name="browser-reporter",b}(0,_inheritsLoose2["default"])(b,a);var c=b.prototype;return c.init=function init(){var a=this;_global.document.addEventListener("visibilitychange",function(){"hidden"===_global.document.visibilityState&&a.flushEventQueue()})},c.request=function request(a,b,c){var d,e=a.getConfig(),f=e.pid,g=e.env,h=void 0===g?"prod":g,i=e.version,j=e.endpoint,k=e.beforeReport,l=e.user,m=void 0===l?{}:l,n={app:{id:f,env:h,version:i,type:_rumCore.AppType.browser},user:(0,_extends2["default"])({id:(0,_uuid.getUserID)()},m),session:{id:(0,_uuid.getSessionID)()},view:c,net:{model:(null===(d=navigator.connection)||void 0===d?void 0:d.effectiveType)||""},events:b};if(!("function"==typeof k&&(n=k(n),!n)))try{navigator.sendBeacon(j,JSON.stringify(n))}catch(a){}},b}(_rumCore.Reporter),_default=exports["default"]=BrowserReporter;/** | ||
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=!0,exports["default"]=void 0;var _inheritsLoose2=_interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose")),_rumCore=require("@arms/rum-core"),_uuid=require("../utils/uuid"),_global=require("../utils/global"),BrowserReporter=/*#__PURE__*/function(a){function b(){for(var b,c=arguments.length,d=Array(c),e=0;e<c;e++)d[e]=arguments[e];return b=a.call.apply(a,[this].concat(d))||this,b.name="browser-reporter",b}(0,_inheritsLoose2["default"])(b,a);var c=b.prototype;return c.init=function init(){var a=this;_global.document.addEventListener("visibilitychange",function(){"hidden"===_global.document.visibilityState&&a.flushEventQueue()})},c.request=function request(a,b,c){var d,e=a.getConfig(),f={app:{id:e.pid,env:e.env||"prod",version:e.version,type:_rumCore.AppType.browser},user:{id:(0,_uuid.getUserID)()},session:{id:(0,_uuid.getSessionID)()},view:c,net:{model:(null===(d=navigator.connection)||void 0===d?void 0:d.effectiveType)||""},events:b};if(["app","user","device","os","geo","isp","net"].forEach(function(a){var b=e[a];(0,_rumCore.isObject)(b)&&Object.keys(b).forEach(function(c){var d=b[c];// user 的 id 不能被覆盖 | ||
"user"===a&&"id"===c||((0,_rumCore.isString)(d)||(0,_rumCore.isNumber)(d))&&(!(a in f)&&(f[a]={}),f[a][c]=d)})}),!("function"==typeof e.beforeReport&&(f=e.beforeReport(f),!f)))try{navigator.sendBeacon(e.endpoint,JSON.stringify(f))}catch(a){}},b}(_rumCore.Reporter),_default=exports["default"]=BrowserReporter;/** | ||
* browser reporter | ||
*/ |
@@ -6,10 +6,2 @@ /** | ||
/** | ||
* 保留指定位数的小数 | ||
* @param num 原数据 | ||
* @param decimal 小数位数 | ||
* @param min 限制最小值,否则返回undefined | ||
* @returns | ||
*/ | ||
export declare function formatNumber(num: number, decimal?: number, min?: number): number; | ||
/** | ||
* 获取当前时间 | ||
@@ -16,0 +8,0 @@ * @returns |
@@ -1,12 +0,6 @@ | ||
"use strict";exports.__esModule=!0,exports.formatNumber=formatNumber,exports.getCurrentTime=getCurrentTime,exports.hackFunction=hackFunction;/** | ||
"use strict";exports.__esModule=!0,exports.getCurrentTime=getCurrentTime,exports.hackFunction=hackFunction;/** | ||
* 劫持函数 | ||
*/function hackFunction(a,b,c){if("object"==typeof a&&"function"==typeof a[b]){var d=a[b],e=c(d);a[b]=e}}/** | ||
* 保留指定位数的小数 | ||
* @param num 原数据 | ||
* @param decimal 小数位数 | ||
* @param min 限制最小值,否则返回undefined | ||
* @returns | ||
*/function formatNumber(a,b,c){if(void 0===b&&(b=3),void 0===c&&(c=0),!a)return a;var d=a.toString(),e=d.indexOf(".");d=-1===e?d.substring(0):d.substring(0,b+e+1);var f=parseFloat(d);return f>=c?f:void 0}/** | ||
* 获取当前时间 | ||
* @returns | ||
*/function getCurrentTime(a){var b,c;return null!==(b=performance)&&void 0!==b&&b.timeOrigin&&null!==(c=performance)&&void 0!==c&&c.now?Math.round(performance.timeOrigin+(a?a:performance.now())):Date.now()} |
@@ -44,6 +44,2 @@ /** | ||
download_duration: number; | ||
/** | ||
* PerformanceResourceTiming 的 JSONString | ||
*/ | ||
timing_data?: string; | ||
} | ||
@@ -50,0 +46,0 @@ /** |
@@ -1,2 +0,2 @@ | ||
"use strict";var _base=require("./base");exports.__esModule=!0,exports.ResourceType=exports.ResourceStatus=exports.RESOURCE_TYPES=exports.FAKE_INITIAL_DOCUMENT=void 0,exports.calcResourceTimingData=calcResourceTimingData,exports.getResourceStatusByCode=getResourceStatusByCode,exports.getResourceType=getResourceType;function _createForOfIteratorHelperLoose(a,b){var c="undefined"!=typeof Symbol&&a[Symbol.iterator]||a["@@iterator"];if(c)return(c=c.call(a)).next.bind(c);if(Array.isArray(a)||(c=_unsupportedIterableToArray(a))||b&&a&&"number"==typeof a.length){c&&(a=c);var d=0;return function(){return d>=a.length?{done:!0}:{done:!1,value:a[d++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(a,b){if(a){if("string"==typeof a)return _arrayLikeToArray(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);return"Object"===c&&a.constructor&&(c=a.constructor.name),"Map"===c||"Set"===c?Array.from(a):"Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?_arrayLikeToArray(a,b):void 0}}function _arrayLikeToArray(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);c<b;c++)d[c]=a[c];return d}/** | ||
"use strict";var _rumCore=require("@arms/rum-core");exports.__esModule=!0,exports.ResourceType=exports.ResourceStatus=exports.RESOURCE_TYPES=exports.FAKE_INITIAL_DOCUMENT=void 0,exports.calcResourceTimingData=calcResourceTimingData,exports.getResourceStatusByCode=getResourceStatusByCode,exports.getResourceType=getResourceType;function _createForOfIteratorHelperLoose(a,b){var c="undefined"!=typeof Symbol&&a[Symbol.iterator]||a["@@iterator"];if(c)return(c=c.call(a)).next.bind(c);if(Array.isArray(a)||(c=_unsupportedIterableToArray(a))||b&&a&&"number"==typeof a.length){c&&(a=c);var d=0;return function(){return d>=a.length?{done:!0}:{done:!1,value:a[d++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(a,b){if(a){if("string"==typeof a)return _arrayLikeToArray(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);return"Object"===c&&a.constructor&&(c=a.constructor.name),"Map"===c||"Set"===c?Array.from(a):"Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?_arrayLikeToArray(a,b):void 0}}function _arrayLikeToArray(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);c<b;c++)d[c]=a[c];return d}/** | ||
* 枚举值,表示资源是否加载成功 | ||
@@ -20,2 +20,2 @@ */var ResourceStatus=exports.ResourceStatus=/*#__PURE__*/function(a){return a[a.Failed=0]="Failed",a[a.Success=1]="Success",a}({});/** | ||
if(c>n)return}// Firefox 以及其他不提供对跨原点请求的重定向计时。提供一个默认值。 | ||
f<c&&(f=c),g<c&&(g=d);var q=(0,_base.formatNumber)(g-f),r=(0,_base.formatNumber)(i-h),s=(0,_base.formatNumber)(l-j),t=(0,_base.formatNumber)(n-m),u=(0,_base.formatNumber)(o-n),v={duration:p,redirect_duration:q,dns_duration:r,connect_duration:s,first_byte_duration:t,download_duration:u};return b||(v.size=(0,_base.formatNumber)(e)),k&&(v.ssl_duration=(0,_base.formatNumber)(l-k)),v}var ResourceType=exports.ResourceType=/*#__PURE__*/function(a){return a.DOCUMENT="document",a.XHR="xmlhttprequest",a.BEACON="beacon",a.FETCH="fetch",a.CSS="css",a.JS="js",a.IMAGE="image",a.FONT="font",a.MEDIA="media",a.OTHER="other",a}({}),FAKE_INITIAL_DOCUMENT=exports.FAKE_INITIAL_DOCUMENT="initial_document",RESOURCE_TYPES=exports.RESOURCE_TYPES=[[ResourceType.DOCUMENT,function(a){return FAKE_INITIAL_DOCUMENT===a}],[ResourceType.XHR,function(a){return"xmlhttprequest"===a}],[ResourceType.FETCH,function(a){return"fetch"===a}],[ResourceType.BEACON,function(a){return"beacon"===a}],[ResourceType.CSS,function(a,b){return /\.css$/i.test(b)}],[ResourceType.JS,function(a,b){return /\.js$/i.test(b)}],[ResourceType.IMAGE,function(a,b){return["image","img","icon"].includes(a)||null!==/\.(gif|jpg|jpeg|tiff|png|svg|ico)$/i.exec(b)}],[ResourceType.FONT,function(a,b){return null!==/\.(woff|eot|woff2|ttf)$/i.exec(b)}],[ResourceType.MEDIA,function(a,b){return["audio","video"].includes(a)||null!==/\.(mp3|mp4)$/i.exec(b)}]];function getResourceType(a,b){var c;try{c=new URL(a)}catch(a){return ResourceType.OTHER}for(var d,e=c.pathname,f=_createForOfIteratorHelperLoose(RESOURCE_TYPES);!(d=f()).done;){var g=d.value,h=g[0],i=g[1];if(i(b,e))return h}return ResourceType.OTHER} | ||
f<c&&(f=c),g<c&&(g=d);var q=(0,_rumCore.formatNumber)(g-f),r=(0,_rumCore.formatNumber)(i-h),s=(0,_rumCore.formatNumber)(l-j),t=(0,_rumCore.formatNumber)(n-m),u=(0,_rumCore.formatNumber)(o-n),v={duration:p,redirect_duration:q,dns_duration:r,connect_duration:s,first_byte_duration:t,download_duration:u};return b||(v.size=(0,_rumCore.formatNumber)(e)),k&&(v.ssl_duration=(0,_rumCore.formatNumber)(l-k)),v}var ResourceType=exports.ResourceType=/*#__PURE__*/function(a){return a.DOCUMENT="document",a.XHR="xmlhttprequest",a.BEACON="beacon",a.FETCH="fetch",a.CSS="css",a.JS="js",a.IMAGE="image",a.FONT="font",a.MEDIA="media",a.OTHER="other",a}({}),FAKE_INITIAL_DOCUMENT=exports.FAKE_INITIAL_DOCUMENT="initial_document",RESOURCE_TYPES=exports.RESOURCE_TYPES=[[ResourceType.DOCUMENT,function(a){return FAKE_INITIAL_DOCUMENT===a}],[ResourceType.XHR,function(a){return"xmlhttprequest"===a}],[ResourceType.FETCH,function(a){return"fetch"===a}],[ResourceType.BEACON,function(a){return"beacon"===a}],[ResourceType.CSS,function(a,b){return /\.css$/i.test(b)}],[ResourceType.JS,function(a,b){return /\.js$/i.test(b)}],[ResourceType.IMAGE,function(a,b){return["image","img","icon"].includes(a)||null!==/\.(gif|jpg|jpeg|tiff|png|svg|ico)$/i.exec(b)}],[ResourceType.FONT,function(a,b){return null!==/\.(woff|eot|woff2|ttf)$/i.exec(b)}],[ResourceType.MEDIA,function(a,b){return["audio","video"].includes(a)||null!==/\.(mp3|mp4)$/i.exec(b)}]];function getResourceType(a,b){var c;try{c=new URL(a)}catch(a){return ResourceType.OTHER}for(var d,e=c.pathname,f=_createForOfIteratorHelperLoose(RESOURCE_TYPES);!(d=f()).done;){var g=d.value,h=g[0],i=g[1];if(i(b,e))return h}return ResourceType.OTHER} |
{ | ||
"name": "@arms/rum-browser", | ||
"version": "0.0.24-beta.6", | ||
"version": "0.0.25-beta.7", | ||
"description": "arms rum javascript sdk for browser", | ||
@@ -26,3 +26,3 @@ "author": "guangli.fj <guangli.fj@alibaba-inc.com>", | ||
"dependencies": { | ||
"@arms/rum-core": "0.0.23", | ||
"@arms/rum-core": "0.0.25-beta.7", | ||
"web-vitals": "3.5.2" | ||
@@ -29,0 +29,0 @@ }, |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 2 instances in 1 package
188761
759
+ Added@arms/rum-core@0.0.25-beta.7(transitive)
- Removed@arms/rum-core@0.0.23(transitive)
Updated@arms/rum-core@0.0.25-beta.7