Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@arms/rum-browser

Package Overview
Dependencies
Maintainers
0
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@arms/rum-browser - npm Package Compare versions

Comparing version 0.0.31 to 0.0.32

2

lib/collector/longtask/index.js

@@ -1,1 +0,1 @@

"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=!0,exports["default"]=void 0;var _extends2=_interopRequireDefault(require("@babel/runtime/helpers/extends")),_rumCore=require("@arms/rum-core"),_base=require("../../utils/base"),_view=require("../../utils/view");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}var raf=global.requestAnimationFrame,cancelRaf=global.cancelAnimationFrame,LongTaskCollector=exports["default"]=/*#__PURE__*/function(){function a(){this.name="longtask-collecor",this.ctx=void 0,this.sendEvent=void 0,this.CONTINUOUS_FRAME_GAP=17,this.REPORT_CONTINUOUS_FRAME_TIMESHOLD=150,this.LONG_FRAME_THRESHOLD=50,this.loafPerfObserver=void 0,this.ltPerfObserver=void 0,this.loafSeqCache=void 0,this.loafTimer=void 0,this.ltPerfCache=[],this.rafRequestId=void 0,this.rafTimerMap=new Map}var b=a.prototype;return b.setup=function setup(a,b){var c=a.getConfig(),d=c.useRaf,e=c.collectors,f=void 0===e?{}:e;if(!1!==f.longtask&&(this.ctx=a,this.sendEvent=b,this.loafPerfObserver=(0,_base.initPerfObserver)("long-animation-frame",this.loafHandler.bind(this)),!this.loafPerfObserver&&void 0!==d&&d)){if(!(0,_rumCore.isFunction)(raf)||!(0,_rumCore.isFunction)(cancelRaf))return;this.ltPerfObserver=(0,_base.initPerfObserver)("longtask",this.ltHandler.bind(this)),raf(this.initRafObserver.bind(this))}},b.loafHandler=function loafHandler(a){var b=this;a.forEach(function(a){var c=a.startTime,d=a.duration,e=a.scripts,f=void 0===e?[]:e,g=c+d;if(b.clearLoafTimer(),b.loafSeqCache&&c-b.loafSeqCache.endTime<b.CONTINUOUS_FRAME_GAP?(b.loafSeqCache.frameCount++,b.loafSeqCache.endTime=g,b.loafSeqCache.attribution=[].concat(b.loafSeqCache.attribution,f)):b.loafSeqCache={view:(0,_view.getCurView)(b.ctx),source:"LoAF",startTime:c,endTime:g,frameCount:1,attribution:f},b.loafSeqCache.endTime-b.loafSeqCache.startTime>=b.REPORT_CONTINUOUS_FRAME_TIMESHOLD){var h=(0,_extends2["default"])({},b.loafSeqCache);b.loafTimer=setTimeout(function(){try{b.sendLongTask(h),b.loafTimer=null}catch(a){}},200)}})},b.clearLoafTimer=function clearLoafTimer(){this.loafTimer&&(clearTimeout(this.loafTimer),this.loafTimer=null)},b.ltHandler=function ltHandler(a){var b=this;a.forEach(function(a){return b.ltPerfCache.push(a)})},b.initRafObserver=function initRafObserver(){var a,b=this,c=(0,_base.getCurrentTime)(),d=function(){var e=(0,_base.getCurrentTime)();if(e-c>=b.LONG_FRAME_THRESHOLD)a?(a.frameCount++,a.endTime=e):a={view:(0,_view.getCurView)(b.ctx),source:"rAF",startTime:c,endTime:e,frameCount:1,attribution:[]};else if(a&&a.endTime-a.startTime>=b.LONG_FRAME_THRESHOLD){var f=(0,_extends2["default"])({},a),g=setTimeout(function(){try{b.mergeLtPerf(f),b.rafTimerMap["delete"](c)}catch(a){}},200);b.rafTimerMap.set(c,g),a=null}c=e,b.rafRequestId=raf(d)};raf(d)},b.mergeLtPerf=function mergeLtPerf(a){for(var b,c=-1,d=_createForOfIteratorHelperLoose(this.ltPerfCache.entries());!(b=d()).done;){var e=b.value,f=e[0],g=e[1],h=g.startTime,i=g.attribution,j=void 0===i?[]:i,k=(0,_base.getCurrentTime)(h);if(a.endTime<k)break;a.startTime<k&&(a.attribution=[].concat(a.attribution,j),c=f)}this.ltPerfCache.splice(0,c+1),this.sendLongTask(a)},b.sendLongTask=function sendLongTask(a){a=this.loafSequenceFilter(a);var b=a,c=b.view,d=b.source,e=b.startTime,f=b.endTime,g=b.frameCount,h=b.attribution,i=f-e,j=Math.round(1e3/(i/g)),k=this.ctx.session.getBaseEvent(),l=(0,_extends2["default"])({},k,c,{event_type:_rumCore.RumEventType.LONG_TASK,type:"fps",source:d,timestamp:e,duration:i,fps:j,snapshots:JSON.stringify(h)});this.sendEvent(l)},b.loafSequenceFilter=function loafSequenceFilter(a){var b=a.source,c=a.attribution;return"rAF"===b&&(c=c.filter(function(a){return"unknown"!==a.name})),5<=c.length&&(c=c.sort(function(c,a){return a.duration-c.duration}).slice(0,5)),a.attribution=c,a},b.clearLoafObserver=function clearLoafObserver(){this.loafPerfObserver&&(this.loafPerfObserver.disconnect(),this.loafPerfObserver=null),this.clearLoafTimer(),this.loafSeqCache=null},b.clearLtObserver=function clearLtObserver(){this.ltPerfObserver&&(this.ltPerfObserver.disconnect(),this.ltPerfObserver=null),this.ltPerfCache=null},b.clearRafObserver=function clearRafObserver(){this.rafRequestId&&(cancelRaf(this.rafRequestId),this.rafRequestId=null),this.rafTimerMap.forEach(function(a){return clearTimeout(a)}),this.rafTimerMap=null},b.destroy=function destroy(){this.clearLoafObserver(),this.clearLtObserver(),this.clearRafObserver()},a}();
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=!0,exports["default"]=void 0;var _extends2=_interopRequireDefault(require("@babel/runtime/helpers/extends")),_rumCore=require("@arms/rum-core"),_base=require("../../utils/base"),_view=require("../../utils/view"),_global=require("../../utils/global");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}var raf=_global.global.requestAnimationFrame,cancelRaf=_global.global.cancelAnimationFrame,LongTaskCollector=exports["default"]=/*#__PURE__*/function(){function a(){this.name="longtask-collecor",this.ctx=void 0,this.sendEvent=void 0,this.CONTINUOUS_FRAME_GAP=17,this.REPORT_CONTINUOUS_FRAME_TIMESHOLD=150,this.LONG_FRAME_THRESHOLD=50,this.loafPerfObserver=void 0,this.ltPerfObserver=void 0,this.loafSeqCache=void 0,this.loafTimer=void 0,this.ltPerfCache=[],this.rafRequestId=void 0,this.rafTimerMap=new Map}var b=a.prototype;return b.setup=function setup(a,b){var c=a.getConfig(),d=c.useRaf,e=c.collectors,f=void 0===e?{}:e;if(!1!==f.longtask&&(this.ctx=a,this.sendEvent=b,this.loafPerfObserver=(0,_base.initPerfObserver)("long-animation-frame",this.loafHandler.bind(this)),!this.loafPerfObserver&&void 0!==d&&d)){if(!(0,_rumCore.isFunction)(raf)||!(0,_rumCore.isFunction)(cancelRaf))return;this.ltPerfObserver=(0,_base.initPerfObserver)("longtask",this.ltHandler.bind(this)),raf(this.initRafObserver.bind(this))}},b.loafHandler=function loafHandler(a){var b=this;a.forEach(function(a){var c=a.startTime,d=a.duration,e=a.scripts,f=void 0===e?[]:e,g=c+d;if(b.clearLoafTimer(),b.loafSeqCache&&c-b.loafSeqCache.endTime<b.CONTINUOUS_FRAME_GAP?(b.loafSeqCache.frameCount++,b.loafSeqCache.endTime=g,b.loafSeqCache.attribution=[].concat(b.loafSeqCache.attribution,f)):b.loafSeqCache={view:(0,_view.getCurView)(b.ctx),source:"LoAF",startTime:c,endTime:g,frameCount:1,attribution:f},b.loafSeqCache.endTime-b.loafSeqCache.startTime>=b.REPORT_CONTINUOUS_FRAME_TIMESHOLD){var h=(0,_extends2["default"])({},b.loafSeqCache);b.loafTimer=setTimeout(function(){try{b.sendLongTask(h),b.loafTimer=null}catch(a){}},200)}})},b.clearLoafTimer=function clearLoafTimer(){this.loafTimer&&(clearTimeout(this.loafTimer),this.loafTimer=null)},b.ltHandler=function ltHandler(a){var b=this;a.forEach(function(a){return b.ltPerfCache.push(a)})},b.initRafObserver=function initRafObserver(){var a,b=this,c=(0,_base.getCurrentTime)(),d=function(){var e=(0,_base.getCurrentTime)();if(e-c>=b.LONG_FRAME_THRESHOLD)a?(a.frameCount++,a.endTime=e):a={view:(0,_view.getCurView)(b.ctx),source:"rAF",startTime:c,endTime:e,frameCount:1,attribution:[]};else if(a&&a.endTime-a.startTime>=b.LONG_FRAME_THRESHOLD){var f=(0,_extends2["default"])({},a),g=setTimeout(function(){try{b.mergeLtPerf(f),b.rafTimerMap["delete"](c)}catch(a){}},200);b.rafTimerMap.set(c,g),a=null}c=e,b.rafRequestId=raf(d)};raf(d)},b.mergeLtPerf=function mergeLtPerf(a){for(var b,c=-1,d=_createForOfIteratorHelperLoose(this.ltPerfCache.entries());!(b=d()).done;){var e=b.value,f=e[0],g=e[1],h=g.startTime,i=g.attribution,j=void 0===i?[]:i,k=(0,_base.getCurrentTime)(h);if(a.endTime<k)break;a.startTime<k&&(a.attribution=[].concat(a.attribution,j),c=f)}this.ltPerfCache.splice(0,c+1),this.sendLongTask(a)},b.sendLongTask=function sendLongTask(a){a=this.loafSequenceFilter(a);var b=a,c=b.view,d=b.source,e=b.startTime,f=b.endTime,g=b.frameCount,h=b.attribution,i=f-e,j=Math.round(1e3/(i/g)),k=this.ctx.session.getBaseEvent(),l=(0,_extends2["default"])({},k,c,{event_type:_rumCore.RumEventType.LONG_TASK,type:"fps",source:d,timestamp:e,duration:i,fps:j,snapshots:JSON.stringify(h)});this.sendEvent(l)},b.loafSequenceFilter=function loafSequenceFilter(a){var b=a.source,c=a.attribution;return"rAF"===b&&(c=c.filter(function(a){return"unknown"!==a.name})),5<=c.length&&(c=c.sort(function(c,a){return a.duration-c.duration}).slice(0,5)),a.attribution=c,a},b.clearLoafObserver=function clearLoafObserver(){this.loafPerfObserver&&(this.loafPerfObserver.disconnect(),this.loafPerfObserver=null),this.clearLoafTimer(),this.loafSeqCache=null},b.clearLtObserver=function clearLtObserver(){this.ltPerfObserver&&(this.ltPerfObserver.disconnect(),this.ltPerfObserver=null),this.ltPerfCache=null},b.clearRafObserver=function clearRafObserver(){this.rafRequestId&&(cancelRaf(this.rafRequestId),this.rafRequestId=null),this.rafTimerMap.forEach(function(a){return clearTimeout(a)}),this.rafTimerMap=null},b.destroy=function destroy(){this.clearLoafObserver(),this.clearLtObserver(),this.clearRafObserver()},a}();
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=!0,exports["default"]=void 0;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator")),_asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")),_extends2=_interopRequireDefault(require("@babel/runtime/helpers/extends")),_rumCore=require("@arms/rum-core"),_performance=require("../../utils/performance"),_url=require("../../utils/url"),_base=require("../../utils/base"),_global=require("../../utils/global"),_api=require("../../utils/api"),PerfObserver=_global.global.PerformanceObserver,ApiCollector=exports["default"]=/*#__PURE__*/function(){function a(){this.name="api-collector",this.entryTypes=Object.values(_api.ApiType),this.entryCacheMap={},this.ctx=void 0,this.sendEvent=void 0}var b=a.prototype;return b.setup=function setup(a,b){var c=a.getConfig().collectors||{};!1===c.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){var c=b.name;a.entryCacheMap[c]?a.entryCacheMap[c].push(b):a.entryCacheMap[c]=[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;-1<q.indexOf("sw8")&&(q=["sw8"],r=!0);var s=this.ctx.session,t=r?(0,_rumCore.generateGUID)():(0,_rumCore.generateTraceId)(),u=r?(0,_rumCore.generateGUID)():(0,_rumCore.generateSpanId)(),v=(0,_rumCore.performDraw)(k),w=s.getUserId(),x=s.getSessionId(),y=void 0===n||n?"rum=v2&browser&"+f+"&"+x+"&"+w:void 0,z=void 0!==o&&o?"rum=v2,appType=browser,pid="+f+",sid="+x+",uid="+w:void 0,A=(0,_rumCore.makeTracingHeaders)(t,u,v,q,{tracestate:y,baggage:z,appId:f,appVersion:h,viewName:null===(c=a.view)||void 0===c?void 0:c.name,host:_global.location.host});v&&(a.trace_id=t,a.trace_data=JSON.stringify({spanId:u,sample:k,sampled:v,headers:A})),b(A)}}// Browser 情况下一直允许同域请求的trace
},b.hackXhr=function hackXhr(){var a=XMLHttpRequest.prototype,b=this.ctx.getConfig().filters||{},c=this;(0,_rumCore.interceptFunction)(a,"open",function(a,d,e,f,g){var h=d+"",i=a.toUpperCase();// chrome 对 URL 的最大长度为 8182 个字符
if(!((0,_rumCore.urlMatch)(h,b.resource)||"HEAD"===i||8182<h.length)){this.apiCache={type:_api.ApiType.XHR,method:a,url:d,async:e,user:f,password:g,headers:{}};var j=c.ctx.session.getBaseEvent();this.apiAttr=(0,_extends2["default"])({},j,{url:(0,_url.fixRelativeUrl)(h),method:i})}}),(0,_rumCore.interceptFunction)(a,"setRequestHeader",function(a,b){this.apiCache&&(this.apiCache.headers[a]=b)}),(0,_rumCore.interceptFunction)(a,"send",function(a){var b=this;if(this.apiAttr){var d=this.apiAttr;this.apiCache.data=a,c.injectTracing(this.apiAttr,function(a){Object.keys(a).forEach(function(c){b.setRequestHeader(c,a[c])})}),this.addEventListener("loadend",/*#__PURE__*/(0,_asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function a(){var e,f,g,h,i,j,k,l;return _regenerator["default"].wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(e=b.status,f=b.statusText,g=b.response,h=c.ctx.getConfig(),i=h.evaluateApi,d.status_code=e,d.message=f,j={name:b.apiAttr.url,entryType:_api.ApiType.XHR,duration:(0,_base.getCurrentTime)()-d.timestamp},!(0,_rumCore.isFunction)(i)){a.next=16;break}return a.prev=6,d.success===_rumCore.ResourceStatus.Failed&&(k=new Error(_api.ApiType.XHR+" error")),a.next=10,i(b.apiCache,g,k);case 10:l=a.sent,b.apiAttr=d=(0,_extends2["default"])({},d,(0,_api.reviseApiAttr)(l)),a.next=16;break;case 14:a.prev=14,a.t0=a["catch"](6);case 16:c.delayHandle({attr:d,entry:j});case 17:case"end":return a.stop()}},a,null,[[6,14]])}))),this.addEventListener("error",function(){b.apiAttr.success=_rumCore.ResourceStatus.Failed})}})},b.hackFetch=function hackFetch(){var a=this,b=this.ctx.getConfig().filters||{};(0,_base.hackFunction)(_global.global,"fetch",function(c){return function(d,e){var f,g,h;function i(){return j.apply(this,arguments)}function j(){return j=(0,_asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function b(){var c,f,g,h;return _regenerator["default"].wrap(function(b){for(;;)switch(b.prev=b.next){case 0:if(c=a.ctx.getConfig(),f=c.evaluateApi,g={name:p.url,entryType:_api.ApiType.FETCH,duration:(0,_base.getCurrentTime)()-p.timestamp},!(0,_rumCore.isFunction)(f)){b.next=12;break}return b.prev=3,b.next=6,f((0,_extends2["default"])({url:d},e),m,n);case 6:h=b.sent,p=(0,_extends2["default"])({},p,(0,_api.reviseApiAttr)(h)),b.next=12;break;case 10:b.prev=10,b.t0=b["catch"](3);case 12:a.delayHandle({attr:p,entry:g});case 13:case"end":return b.stop()}},b,null,[[3,10]])})),j.apply(this,arguments)}void 0===e&&(e={});var k=d instanceof Request?d.url:(0,_rumCore.isString)(d)?d:d.toString(),l=(null===(f=e)||void 0===f||null===(g=f.method)||void 0===g?void 0:g.toUpperCase())||"GET";// method: 'HEAD' 或 mode: 'no-cors' 的请求不监听
if((0,_rumCore.urlMatch)(k,b.resource)||"HEAD"===l||"no-cors"===(null===(h=e)||void 0===h?void 0:h.mode)||8182<k.length)return c.call(_global.global,d,e);var m,n,o=a.ctx.session.getBaseEvent(),p=(0,_extends2["default"])({},o,{url:(0,_url.fixRelativeUrl)(k),type:_api.ApiType.FETCH,method:l});return a.injectTracing(p,function(a){var b=e.headers;b instanceof Headers||(b=new Headers((0,_rumCore.isObject)(e.headers)?b:{})),Object.keys(a).forEach(function(c){b.set(c,a[c])}),e.headers=b}),c.call(_global.global,d,e).then(function(a){if(a||(0,_rumCore.isFunction)(a.clone)){m=a.clone();var b=m,c=b.status,d=b.statusText;p.status_code=c,p.message=d,i().then()}return a})["catch"](function(a){throw n=a,p.message=a+"",p.success=_rumCore.ResourceStatus.Failed,i().then(),a})}})},b.delayHandle=function delayHandle(a){var b=this;(0,_rumCore.delay)(function(){b.mergeEntry(a)},200)},b.mergeEntry=function mergeEntry(a){var b=a.attr,c=a.entry;c=this.findRealEntry(c);var d=this.ctx.getConfig(),e=d.parseResourceName,f=b.url,g=b.status_code,h=b.view;b.name=(0,_url.getResourceName)(f,e);var i=(0,_performance.getResourceSuccessByCode)(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},b,{timing_data:JSON.stringify(c)},j,{view:h});this.sendEvent(k)},b.findRealEntry=function findRealEntry(a){var b=a.name,c=this.entryCacheMap[b]||[],d=c.shift();return c.length||delete this.entryCacheMap[b],d||a},a}();
if(!((0,_rumCore.urlMatch)(h,b.resource)||"HEAD"===i||8182<h.length)){this.apiCache={type:_api.ApiType.XHR,method:a,url:d,async:e,user:f,password:g,headers:{}};var j=c.ctx.session.getBaseEvent();this.apiAttr=(0,_extends2["default"])({},j,{url:(0,_url.fixRelativeUrl)(h),method:i})}}),(0,_rumCore.interceptFunction)(a,"setRequestHeader",function(a,b){this.apiCache&&(this.apiCache.headers[a]=b)}),(0,_rumCore.interceptFunction)(a,"send",function(a){var b=this;if(this.apiAttr){var d=this.apiAttr;this.apiCache.data=a,c.injectTracing(this.apiAttr,function(a){Object.keys(a).forEach(function(c){b.setRequestHeader(c,a[c])})}),this.addEventListener("loadend",/*#__PURE__*/(0,_asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function a(){var e,f,g,h,i,j,k,l;return _regenerator["default"].wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(e=b.status,f=b.statusText,g=b.response,h=c.ctx.getConfig(),i=h.evaluateApi,d.status_code=e,d.message=f,j={name:b.apiAttr.url,entryType:_api.ApiType.XHR,duration:(0,_base.getCurrentTime)()-d.timestamp},!(0,_rumCore.isFunction)(i)){a.next=16;break}return a.prev=6,d.success===_rumCore.ResourceStatus.Failed&&(k=new Error(_api.ApiType.XHR+" error")),a.next=10,i(b.apiCache,g,k);case 10:l=a.sent,b.apiAttr=d=(0,_extends2["default"])({},d,(0,_api.reviseApiAttr)(l)),a.next=16;break;case 14:a.prev=14,a.t0=a["catch"](6);case 16:c.delayHandle({attr:d,entry:j});case 17:case"end":return a.stop()}},a,null,[[6,14]])}))),this.addEventListener("error",function(){b.apiAttr.success=_rumCore.ResourceStatus.Failed})}})},b.hackFetch=function hackFetch(){var a=this,b=this.ctx.getConfig().filters||{};(0,_base.hackFunction)(_global.global,"fetch",function(c){return function(d,e){var f;function g(){return h.apply(this,arguments)}function h(){return h=(0,_asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function b(){var c,f,g,h;return _regenerator["default"].wrap(function(b){for(;;)switch(b.prev=b.next){case 0:if(c=a.ctx.getConfig(),f=c.evaluateApi,g={name:p.url,entryType:_api.ApiType.FETCH,duration:(0,_base.getCurrentTime)()-p.timestamp},!(0,_rumCore.isFunction)(f)){b.next=12;break}return b.prev=3,b.next=6,f((0,_extends2["default"])({url:d},e),m,n);case 6:h=b.sent,p=(0,_extends2["default"])({},p,(0,_api.reviseApiAttr)(h)),b.next=12;break;case 10:b.prev=10,b.t0=b["catch"](3);case 12:a.delayHandle({attr:p,entry:g});case 13:case"end":return b.stop()}},b,null,[[3,10]])})),h.apply(this,arguments)}void 0===e&&(e={});var i=d instanceof Request,j=i?d.url:(0,_rumCore.isString)(d)?d:d.toString(),k=e.method,l=e.headers;if(i&&(!k&&(k=d.method),!l&&(l=d.headers)),k=k?k.toUpperCase():"GET",l||(e.headers=l=new Headers),(0,_rumCore.urlMatch)(j,b.resource)||"HEAD"===k||"no-cors"===(null===(f=e)||void 0===f?void 0:f.mode)||8182<j.length)return c.call(_global.global,d,e);var m,n,o=a.ctx.session.getBaseEvent(),p=(0,_extends2["default"])({},o,{url:(0,_url.fixRelativeUrl)(j),type:_api.ApiType.FETCH,method:k});return a.injectTracing(p,function(a){Object.keys(a).forEach(function(b){l instanceof Headers?l.set(b,a[b]):l[b]=a[b]})}),c.call(_global.global,d,e).then(function(a){if(a||(0,_rumCore.isFunction)(a.clone)){m=a.clone();var b=m,c=b.status,d=b.statusText;p.status_code=c,p.message=d,g().then()}return a})["catch"](function(a){throw n=a,p.message=a+"",p.success=_rumCore.ResourceStatus.Failed,g().then(),a})}})},b.delayHandle=function delayHandle(a){var b=this;(0,_rumCore.delay)(function(){b.mergeEntry(a)},200)},b.mergeEntry=function mergeEntry(a){var b=a.attr,c=a.entry;c=this.findRealEntry(c);var d=this.ctx.getConfig(),e=d.parseResourceName,f=b.url,g=b.status_code,h=b.view;b.name=(0,_url.getResourceName)(f,e);var i=(0,_performance.getResourceSuccessByCode)(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},b,{timing_data:JSON.stringify(c)},j,{view:h});this.sendEvent(k)},b.findRealEntry=function findRealEntry(a){var b=a.name,c=this.entryCacheMap[b]||[],d=c.shift();return c.length||delete this.entryCacheMap[b],d||a},a}();

@@ -1,12 +0,3 @@

"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"),_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){var c,d=a.getConfig();b.app.type=_rumCore.AppType.browser,b.net.model=(null===(c=navigator.connection)||void 0===c?void 0:c.effectiveType)||"",b._v=_global.VERSION;var e=JSON.stringify(b),f=new Blob([e]).size,g=new XMLHttpRequest;// let mark: boolean;
// if (size < 6e4) {
// try {
// mark = navigator.sendBeacon(config.endpoint, reqBody);
// } catch (error) {
// mark = false;
// }
// }
// if (!mark) {
g.open("POST",d.endpoint,!0),g.setRequestHeader("Content-Type","text/plain"),g.send(e)},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"),_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){var c,d=a.getConfig(),e=navigator||{};b.app.type=_rumCore.AppType.browser,b.net.model=(null===(c=e.connection)||void 0===c?void 0:c.effectiveType)||"",b._v=_global.VERSION;var f=JSON.stringify(b),g=!1;if((0,_rumCore.isFunction)(e.sendBeacon)){var h=new Blob([f]).size;if(6e4>h){g=!0;try{e.sendBeacon(d.endpoint,f)}catch(a){g=!1}}}if(!g){var i=new XMLHttpRequest;i.open("POST",d.endpoint,!0),i.setRequestHeader("Content-Type","text/plain"),i.send(f)}},b}(_rumCore.Reporter),_default=exports["default"]=BrowserReporter;/**
* browser reporter
*/

@@ -1,1 +0,1 @@

"use strict";exports.__esModule=!0,exports.location=exports.history=exports.global=exports.document=exports.VERSION=void 0;var global=exports.global=window,document=exports.document=window.document,location=exports.location=window.location,history=exports.history=window.history,VERSION=exports.VERSION='npm-0.0.31';
"use strict";exports.__esModule=!0,exports.location=exports.history=exports.global=exports.document=exports.VERSION=void 0;var global=exports.global=window,document=exports.document=window.document,location=exports.location=window.location,history=exports.history=window.history,VERSION=exports.VERSION='npm-0.0.32';
{
"name": "@arms/rum-browser",
"version": "0.0.31",
"version": "0.0.32",
"description": "arms rum javascript sdk for browser",

@@ -5,0 +5,0 @@ "author": "guangli.fj <guangli.fj@alibaba-inc.com>",

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc