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.27-beta.1 to 0.0.27-beta.2

4

es/collector/resource/api.js
import _asyncToGenerator from"@babel/runtime/helpers/asyncToGenerator";import _extends from"@babel/runtime/helpers/extends";import _regeneratorRuntime from"@babel/runtime/regenerator";import{find,generateGUID,generateSpanId,generateTraceId,interceptFunction,isFunction,isString,makeTracingHeaders,matchList,parseTracingOptions,performDraw,RumEventType,ResourceStatus,startsWith,urlMatch}from"@arms/rum-core";import{calcResourceTimingData,getResourceSuccessByCode}from"../../utils/performance";import{fixRelativeUrl,getResourceName}from"../../utils/url";import{getCurrentTime,hackFunction}from"../../utils/base";import{global,location}from"../../utils/global";import{ApiType,reviseApiAttr}from"../../utils/api";var PerfObserver=global.PerformanceObserver,ApiCollector=/*#__PURE__*/function(){function a(){this.name="api-collector",this.entryTypes=Object.values(ApiType),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().collectors||{};!1===c.api||(this.sendEvent=b,this.ctx=a,this.perfObserver(),this.hackXhr(),this.hackFetch())},b.perfObserver=function perfObserver(){var a=this;if(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=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)&&startsWith(a,location.origin)},propagatorTypes:l});var p=find(m,function(b){return 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?generateGUID():generateTraceId(),u=r?generateGUID():generateSpanId(),v=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=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: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;interceptFunction(a,"open",function(a,c,d,e,f){var g=c+"",h=a.toUpperCase();if(!(urlMatch(g)||"HEAD"===h)){this.apiCache={type:ApiType.XHR,method:a,url:c,async:d,user:e,password:f,headers:{}};var i=b.ctx.session.getBaseEvent();this.apiAttr=_extends({},i,{url:fixRelativeUrl(g),method:h})}}),interceptFunction(a,"setRequestHeader",function(a,b){this.apiCache&&(this.apiCache.headers[a]=b)}),interceptFunction(a,"send",function(a){var c=this;if(this.apiAttr){var d=this.apiAttr;this.apiCache.data=a,b.injectTracing(this.apiAttr,function(a){Object.keys(a).forEach(function(b){c.setRequestHeader(b,a[b])})}),this.addEventListener("loadend",/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function a(){var e,f,g,h,i,j,k,l;return _regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(e=c.status,f=c.statusText,g=c.response,h=b.ctx.getConfig(),i=h.evaluateApi,d.status_code=e,d.message=f,isFunction(PerfObserver)||(j={name:c.apiAttr.url,entryType:ApiType.XHR,duration:getCurrentTime()-d.timestamp}),!isFunction(i)){a.next=16;break}return a.prev=6,d.success===ResourceStatus.Failed&&(k=new Error(ApiType.XHR+" error")),a.next=10,i(c.apiCache,g,k);case 10:l=a.sent,c.apiAttr=_extends({},c.apiAttr,reviseApiAttr(l)),a.next=16;break;case 14:a.prev=14,a.t0=a["catch"](6);case 16:b.mergeDataAndSend({attr:c.apiAttr,entry:j});case 17:case"end":return a.stop()}},a,null,[[6,14]])}))),this.addEventListener("error",function(){c.apiAttr.success=ResourceStatus.Failed})}})},b.hackFetch=function hackFetch(){var a=this;hackFunction(global,"fetch",function(b){return function(c,d){var e,f,g;void 0===d&&(d={});var h=c instanceof Request?c.url: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(urlMatch(h)||"HEAD"===i||"no-cors"===(null===(g=d)||void 0===g?void 0:g.mode))return b.call(global,c,d);var j,k,l=a.ctx.session.getBaseEvent(),m=_extends({},l,{url:fixRelativeUrl(h),type:ApiType.FETCH,method:i});return a.injectTracing(m,function(a){d.headers=d.headers||{},Object.keys(a).forEach(function(b){d.headers[b]=a[b]})}),b.call(global,c,d).then(/*#__PURE__*/function(){var a=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function b(a){var c,d,e;return _regeneratorRuntime.wrap(function(b){for(;;)switch(b.prev=b.next){case 0:return j=a.clone(),c=j,d=c.status,e=c.statusText,m.status_code=d,m.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=a,m.message=a+"",m.success=ResourceStatus.Failed,a})["finally"](/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function b(){var e,f,g,h;return _regeneratorRuntime.wrap(function(b){for(;;)switch(b.prev=b.next){case 0:if(e=a.ctx.getConfig(),f=e.evaluateApi,isFunction(PerfObserver)||(g={name:m.url,entryType:ApiType.FETCH,duration:getCurrentTime()-m.timestamp}),!isFunction(f)){b.next=12;break}return b.prev=3,b.next=6,f(_extends({url:c},d),j,k);case 6:h=b.sent,m=_extends({},m,reviseApiAttr(h)),b.next=12;break;case 10:b.prev=10,b.t0=b["catch"](3);case 12:a.mergeDataAndSend({attr:m,entry:g});case 13:case"end":return b.stop()}},b,null,[[3,10]])})))}})},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=getResourceSuccessByCode(g),j=calcResourceTimingData(c)||{duration:c.duration},k=_extends({event_type:RumEventType.RESOURCE,url:f,name: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}();export{ApiCollector as default};
},b.hackXhr=function hackXhr(){var a=XMLHttpRequest.prototype,b=this;interceptFunction(a,"open",function(a,c,d,e,f){var g=c+"",h=a.toUpperCase();if(!(urlMatch(g)||"HEAD"===h)){this.apiCache={type:ApiType.XHR,method:a,url:c,async:d,user:e,password:f,headers:{}};var i=b.ctx.session.getBaseEvent();this.apiAttr=_extends({},i,{url:fixRelativeUrl(g),method:h})}}),interceptFunction(a,"setRequestHeader",function(a,b){this.apiCache&&(this.apiCache.headers[a]=b)}),interceptFunction(a,"send",function(a){var c=this;if(this.apiAttr){var d=this.apiAttr;this.apiCache.data=a,b.injectTracing(this.apiAttr,function(a){Object.keys(a).forEach(function(b){c.setRequestHeader(b,a[b])})}),this.addEventListener("loadend",/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function a(){var e,f,g,h,i,j,k,l;return _regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(e=c.status,f=c.statusText,g=c.response,h=b.ctx.getConfig(),i=h.evaluateApi,d.status_code=e,d.message=f,isFunction(PerfObserver)||(j={name:c.apiAttr.url,entryType:ApiType.XHR,duration:getCurrentTime()-d.timestamp}),!isFunction(i)){a.next=16;break}return a.prev=6,d.success===ResourceStatus.Failed&&(k=new Error(ApiType.XHR+" error")),a.next=10,i(c.apiCache,g,k);case 10:l=a.sent,c.apiAttr=_extends({},c.apiAttr,reviseApiAttr(l)),a.next=16;break;case 14:a.prev=14,a.t0=a["catch"](6);case 16:b.mergeDataAndSend({attr:c.apiAttr,entry:j});case 17:case"end":return a.stop()}},a,null,[[6,14]])}))),this.addEventListener("error",function(){c.apiAttr.success=ResourceStatus.Failed})}})},b.hackFetch=function hackFetch(){var a=this;hackFunction(global,"fetch",function(b){return function(c,d){var e,f,g;function h(){return i.apply(this,arguments)}function i(){return i=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function b(){var e,f,g,h;return _regeneratorRuntime.wrap(function(b){for(;;)switch(b.prev=b.next){case 0:if(e=a.ctx.getConfig(),f=e.evaluateApi,isFunction(PerfObserver)||(g={name:o.url,entryType:ApiType.FETCH,duration:getCurrentTime()-o.timestamp}),!isFunction(f)){b.next=12;break}return b.prev=3,b.next=6,f(_extends({url:c},d),l,m);case 6:h=b.sent,o=_extends({},o,reviseApiAttr(h)),b.next=12;break;case 10:b.prev=10,b.t0=b["catch"](3);case 12:a.mergeDataAndSend({attr:o,entry:g});case 13:case"end":return b.stop()}},b,null,[[3,10]])})),i.apply(this,arguments)}void 0===d&&(d={});var j=c instanceof Request?c.url:isString(c)?c:c.toString(),k=(null===(e=d)||void 0===e||null===(f=e.method)||void 0===f?void 0:f.toUpperCase())||"GET";// method: 'HEAD' 或 mode: 'no-cors' 的请求不监听
if(urlMatch(j)||"HEAD"===k||"no-cors"===(null===(g=d)||void 0===g?void 0:g.mode))return b.call(global,c,d);var l,m,n=a.ctx.session.getBaseEvent(),o=_extends({},n,{url:fixRelativeUrl(j),type:ApiType.FETCH,method:k});return a.injectTracing(o,function(a){d.headers=d.headers||{},Object.keys(a).forEach(function(b){d.headers[b]=a[b]})}),b.call(global,c,d).then(function(a){l=a.clone();var b=l,c=b.status,d=b.statusText;return o.status_code=c,o.message=d,h().then(),a})["catch"](function(a){throw m=a,o.message=a+"",o.success=ResourceStatus.Failed,h().then(),a})}})},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=getResourceSuccessByCode(g),j=calcResourceTimingData(c)||{duration:c.duration},k=_extends({event_type:RumEventType.RESOURCE,url:f,name: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);this.cachedEntries=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);this.cachedApiAttrs=f.filter(function(a){return a.url!==i.url}),c(i,e)}}catch(a){}},a}();export{ApiCollector as default};

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

export var global=window;export var document=window.document;export var location=window.location;export var history=window.history;export var VERSION='0.0.27-beta.1';
export var global=window;export var document=window.document;export var location=window.location;export var history=window.history;export var VERSION='0.0.27-beta.2';
"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.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().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){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;-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;(0,_rumCore.interceptFunction)(a,"open",function(a,c,d,e,f){var g=c+"",h=a.toUpperCase();if(!((0,_rumCore.urlMatch)(g)||"HEAD"===h)){this.apiCache={type:_api.ApiType.XHR,method:a,url:c,async:d,user:e,password:f,headers:{}};var i=b.ctx.session.getBaseEvent();this.apiAttr=(0,_extends2["default"])({},i,{url:(0,_url.fixRelativeUrl)(g),method:h})}}),(0,_rumCore.interceptFunction)(a,"setRequestHeader",function(a,b){this.apiCache&&(this.apiCache.headers[a]=b)}),(0,_rumCore.interceptFunction)(a,"send",function(a){var c=this;if(this.apiAttr){var d=this.apiAttr;this.apiCache.data=a,b.injectTracing(this.apiAttr,function(a){Object.keys(a).forEach(function(b){c.setRequestHeader(b,a[b])})}),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=c.status,f=c.statusText,g=c.response,h=b.ctx.getConfig(),i=h.evaluateApi,d.status_code=e,d.message=f,(0,_rumCore.isFunction)(PerfObserver)||(j={name:c.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(c.apiCache,g,k);case 10:l=a.sent,c.apiAttr=(0,_extends2["default"])({},c.apiAttr,(0,_api.reviseApiAttr)(l)),a.next=16;break;case 14:a.prev=14,a.t0=a["catch"](6);case 16:b.mergeDataAndSend({attr:c.apiAttr,entry:j});case 17:case"end":return a.stop()}},a,null,[[6,14]])}))),this.addEventListener("error",function(){c.apiAttr.success=_rumCore.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,k,l=a.ctx.session.getBaseEvent(),m=(0,_extends2["default"])({},l,{url:(0,_url.fixRelativeUrl)(h),type:_api.ApiType.FETCH,method:i});return a.injectTracing(m,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 j=a.clone(),c=j,d=c.status,e=c.statusText,m.status_code=d,m.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=a,m.message=a+"",m.success=_rumCore.ResourceStatus.Failed,a})["finally"](/*#__PURE__*/(0,_asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function b(){var e,f,g,h;return _regenerator["default"].wrap(function(b){for(;;)switch(b.prev=b.next){case 0:if(e=a.ctx.getConfig(),f=e.evaluateApi,(0,_rumCore.isFunction)(PerfObserver)||(g={name:m.url,entryType:_api.ApiType.FETCH,duration:(0,_base.getCurrentTime)()-m.timestamp}),!(0,_rumCore.isFunction)(f)){b.next=12;break}return b.prev=3,b.next=6,f((0,_extends2["default"])({url:c},d),j,k);case 6:h=b.sent,m=(0,_extends2["default"])({},m,(0,_api.reviseApiAttr)(h)),b.next=12;break;case 10:b.prev=10,b.t0=b["catch"](3);case 12:a.mergeDataAndSend({attr:m,entry:g});case 13:case"end":return b.stop()}},b,null,[[3,10]])})))}})},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.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},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}();
},b.hackXhr=function hackXhr(){var a=XMLHttpRequest.prototype,b=this;(0,_rumCore.interceptFunction)(a,"open",function(a,c,d,e,f){var g=c+"",h=a.toUpperCase();if(!((0,_rumCore.urlMatch)(g)||"HEAD"===h)){this.apiCache={type:_api.ApiType.XHR,method:a,url:c,async:d,user:e,password:f,headers:{}};var i=b.ctx.session.getBaseEvent();this.apiAttr=(0,_extends2["default"])({},i,{url:(0,_url.fixRelativeUrl)(g),method:h})}}),(0,_rumCore.interceptFunction)(a,"setRequestHeader",function(a,b){this.apiCache&&(this.apiCache.headers[a]=b)}),(0,_rumCore.interceptFunction)(a,"send",function(a){var c=this;if(this.apiAttr){var d=this.apiAttr;this.apiCache.data=a,b.injectTracing(this.apiAttr,function(a){Object.keys(a).forEach(function(b){c.setRequestHeader(b,a[b])})}),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=c.status,f=c.statusText,g=c.response,h=b.ctx.getConfig(),i=h.evaluateApi,d.status_code=e,d.message=f,(0,_rumCore.isFunction)(PerfObserver)||(j={name:c.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(c.apiCache,g,k);case 10:l=a.sent,c.apiAttr=(0,_extends2["default"])({},c.apiAttr,(0,_api.reviseApiAttr)(l)),a.next=16;break;case 14:a.prev=14,a.t0=a["catch"](6);case 16:b.mergeDataAndSend({attr:c.apiAttr,entry:j});case 17:case"end":return a.stop()}},a,null,[[6,14]])}))),this.addEventListener("error",function(){c.apiAttr.success=_rumCore.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;function h(){return i.apply(this,arguments)}function i(){return i=(0,_asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function b(){var e,f,g,h;return _regenerator["default"].wrap(function(b){for(;;)switch(b.prev=b.next){case 0:if(e=a.ctx.getConfig(),f=e.evaluateApi,(0,_rumCore.isFunction)(PerfObserver)||(g={name:o.url,entryType:_api.ApiType.FETCH,duration:(0,_base.getCurrentTime)()-o.timestamp}),!(0,_rumCore.isFunction)(f)){b.next=12;break}return b.prev=3,b.next=6,f((0,_extends2["default"])({url:c},d),l,m);case 6:h=b.sent,o=(0,_extends2["default"])({},o,(0,_api.reviseApiAttr)(h)),b.next=12;break;case 10:b.prev=10,b.t0=b["catch"](3);case 12:a.mergeDataAndSend({attr:o,entry:g});case 13:case"end":return b.stop()}},b,null,[[3,10]])})),i.apply(this,arguments)}void 0===d&&(d={});var j=c instanceof Request?c.url:(0,_rumCore.isString)(c)?c:c.toString(),k=(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)(j)||"HEAD"===k||"no-cors"===(null===(g=d)||void 0===g?void 0:g.mode))return b.call(_global.global,c,d);var l,m,n=a.ctx.session.getBaseEvent(),o=(0,_extends2["default"])({},n,{url:(0,_url.fixRelativeUrl)(j),type:_api.ApiType.FETCH,method:k});return a.injectTracing(o,function(a){d.headers=d.headers||{},Object.keys(a).forEach(function(b){d.headers[b]=a[b]})}),b.call(_global.global,c,d).then(function(a){l=a.clone();var b=l,c=b.status,d=b.statusText;return o.status_code=c,o.message=d,h().then(),a})["catch"](function(a){throw m=a,o.message=a+"",o.success=_rumCore.ResourceStatus.Failed,h().then(),a})}})},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.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},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);this.cachedEntries=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);this.cachedApiAttrs=f.filter(function(a){return a.url!==i.url}),c(i,e)}}catch(a){}},a}();

@@ -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='0.0.27-beta.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='0.0.27-beta.2';
{
"name": "@arms/rum-browser",
"version": "0.0.27-beta.1",
"version": "0.0.27-beta.2",
"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