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

es/collector/action/click.d.ts

6

lib/collector/action/click.js

@@ -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,_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={};["id","name","className","href","src"].forEach(function(a){var b=f[a];b&&(n[a]=b)});var o=Object.keys(n).length?JSON.stringify(n).substring(0,1e3):void 0,p={event_type:_rumCore.RumEventType.ACTION,type:"click",name:m,target_name:(0,_dom.getElementXpath)(e),duration:d,times:1,timestamp:c,snapshots:o};b(p)}}},!0)},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"),_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().collectors||{};!1===c.action||_global.document.addEventListener("click",function(c){var d=(0,_base.getCurrentTime)(c.timeStamp),e=(0,_rumCore.formatNumber)(performance.now()-c.timeStamp),f=c.target;if(f instanceof HTMLElement){// 根据元素过滤,仅当被关注的元素所嵌套时才会采集数据(默认为 button、a 和表单元素)
var g=(0,_dom.getClosestTargetAncestorElement)(f,["button","a","input","select","option","textarea"]);if(g){// 获取语义化的描述
var h=g.localName,i=g.nodeName,j=g.innerText,k=(h||i).toLowerCase(),l=g.getAttribute("type"),m=j&&": "+(20<j.length?j.slice(0,20)+"...":j),n="click on "+((l?l+"-":"")+k)+m,o={};["id","name","className","href","src"].forEach(function(a){var b=g[a];b&&(o[a]=b)});var p=Object.keys(o).length?JSON.stringify(o).substring(0,1e3):void 0,q=a.session.getBaseEvent(),r=(0,_extends2["default"])({},q,{timestamp:d,event_type:_rumCore.RumEventType.ACTION,type:"click",name:n,target_name:(0,_dom.getElementXpath)(f),duration:e,snapshots:p});b(r)}}},!0)},a}();
import { ICollector, IContext, RumEvent } from '@arms/rum-core';
import { WhiteScreenRule } from '../../utils/blank';
import { WhiteScreenRule, CheckMoment } from '../../utils/blank/index';
export default class WhiteScreenCollector implements ICollector {

@@ -10,4 +10,4 @@ name: string;

abort: () => void;
blankHandler: ({ target, tester, delay, configOptions }: WhiteScreenRule, when: any) => Promise<void>;
blankHandler: ({ target, tester, delay, configOptions, ignoreUrlList }: WhiteScreenRule, when: CheckMoment) => Promise<void>;
destroy(): void;
}

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

"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")),_objectWithoutPropertiesLoose2=_interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose")),_asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")),_rumCore=require("@arms/rum-core"),_blank=require("../../utils/blank"),_global=require("../../utils/global"),_excluded=["result"],cancelList=[],eventRegistrationMap={LEAVE:function LEAVE(a){// TODO: 可能会替换为pagehide
return _global.document.addEventListener("beforeunload",a),function(){return _global.document.removeEventListener("beforeunload",a)}},ROUTE_CHANGE:function ROUTE_CHANGE(a,b){return!0===b||"hash"===b?(_global.global.addEventListener("hashchange",a),function(){return _global.global.removeEventListener("hashchange",a)}):((0,_rumCore.interceptFunction)(_global.global.history,"pushState",a),(0,_rumCore.interceptFunction)(_global.global.history,"replaceState",a),_global.global.addEventListener("popstate",a),function(){_global.global.removeEventListener("popstate",a)})},ERROR:function ERROR(a){return _global.global.addEventListener("error",a),function(){return _global.global.removeEventListener("error",a)}},LOAD:function LOAD(a){return"complete"===_global.document.readyState?(setTimeout(a,0),function(){}):(_global.global.addEventListener("load",a),function(){return _global.global.removeEventListener("load",a)})}},WhiteScreenCollector=exports["default"]=/*#__PURE__*/function(){function a(){var a=this;this.name="white-screen-collector",this.observers=[],this.ctx=void 0,this.sendEvent=void 0,this.abort=function(){a.observers.forEach(function(a){return a()}),a.observers=[]},this.blankHandler=/*#__PURE__*/function(){var b=(0,_asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function d(b,c){var e,f,g,h,i,j,k,l,m,n,o,p,q;return _regenerator["default"].wrap(function(d){for(;;)switch(d.prev=d.next){case 0:if(e=b.target,f=b.tester,g=b.delay,h=void 0===g?0:g,i=b.configOptions,j=void 0===i?{}:i,"LEAVE"===c&&"ERROR"===c){d.next=4;break}return d.next=4,new Promise(function(a){return setTimeout(a,h)});case 4:if(k=_global.document.querySelector(e),k&&f){d.next=7;break}return d.abrupt("return");case 7:d.t0=typeof f,d.next="function"===d.t0?10:"string"===d.t0?13:29;break;case 10:return l=f(k),m={when:c,method:"CUSTOM"},d.abrupt("break",30);case 13:d.t1=f,d.next="HAS_CONTENT"===d.t1?16:"SCREENSHOT"===d.t1?19:27;break;case 16:return l=null!==k&&void 0!==k&&k.textContent,m={when:c,method:"HAS_CONTENT"},d.abrupt("break",28);case 19:return d.next=21,(0,_blank.performScreenshotCheck)(k,j);case 21:return n=d.sent,o=n.result,p=(0,_objectWithoutPropertiesLoose2["default"])(n,_excluded),l=o,m=(0,_extends2["default"])({when:c,method:"SCREENSHOT"},p),d.abrupt("break",28);case 27:console.warn("[RUM] Unsupported tester: "+f);case 28:return d.abrupt("break",30);case 29:console.warn("[RUM] Invalid tester type. Expected either a function or a string.");case 30:if(!l){d.next=32;break}return d.abrupt("return");case 32:q={event_type:_rumCore.RumEventType.EXCEPTION,name:"A white screen occurs at "+c,message:""+("SCREENSHOT"===m.method?"The white screen occurrence rate is "+m.rate+", exceeding the threshold of "+m.threshold+". A total of "+m.checkPoints+" detection points were set, and "+m.whitePixels+" of them were hit.":""),type:"blank",snapshots:JSON.stringify((0,_extends2["default"])({},m))},a.sendEvent(q),a.abort();case 35:case"end":return d.stop()}},d)}));return function(){return b.apply(this,arguments)}}()}var b=a.prototype;return b.setup=function setup(a,b){var c=this;this.ctx=a,this.sendEvent=b;var d=a.getConfig(),e=d.whiteScreen,f=d.spaMode;if(e){// 开启白屏监控
"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"),_index=require("../../utils/blank/index"),_global=require("../../utils/global"),cancelList=[],eventRegistrationMap={LEAVE:function LEAVE(a){// TODO: 可能会替换为pagehide
return _global.document.addEventListener("beforeunload",a),function(){return _global.document.removeEventListener("beforeunload",a)}},ROUTE_CHANGE:function ROUTE_CHANGE(a,b){return"hash"===b?(_global.global.addEventListener("hashchange",a),function(){return _global.global.removeEventListener("hashchange",a)}):((0,_rumCore.interceptFunction)(_global.global.history,"pushState",a),(0,_rumCore.interceptFunction)(_global.global.history,"replaceState",a),_global.global.addEventListener("popstate",a),function(){_global.global.removeEventListener("popstate",a)})},ERROR:function ERROR(a){return _global.global.addEventListener("error",a),function(){return _global.global.removeEventListener("error",a)}},LOAD:function LOAD(a){return"complete"===_global.document.readyState?(setTimeout(a,0),function(){}):(_global.global.addEventListener("load",a),function(){return _global.global.removeEventListener("load",a)})}},WhiteScreenCollector=exports["default"]=/*#__PURE__*/function(){function a(){var a=this;this.name="white-screen-collector",this.observers=[],this.ctx=void 0,this.sendEvent=void 0,this.abort=function(){a.observers.forEach(function(a){return a()}),a.observers=[]},this.blankHandler=/*#__PURE__*/function(){var b=(0,_asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function d(b,c){var e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t;return _regenerator["default"].wrap(function(d){for(;;)switch(d.prev=d.next){case 0:if(e=b.target,f=b.tester,g=b.delay,h=void 0===g?0:g,i=b.configOptions,j=void 0===i?{}:i,k=b.ignoreUrlList,l=void 0===k?[]:k,!(l.includes(_global.location.pathname)||l.includes(_global.location.hash))){d.next=3;break}return d.abrupt("return");case 3:if("LEAVE"===c||"ERROR"===c){d.next=6;break}return d.next=6,new Promise(function(a){return setTimeout(a,h)});case 6:if(m=_global.document.querySelector(e),m&&f){d.next=9;break}return d.abrupt("return");case 9:if((0,_index.testerValidator)(f)){d.next=12;break}return console.warn("[RUM] Invalid tester type. Expected either a function or a string."),d.abrupt("return");case 12:return d.next=14,(0,_index.blankCheck)(f,m,j);case 14:if(n=d.sent,o=n.hasContent,p=n.message,q=void 0===p?"":p,r=n.snapshot,!o){d.next=21;break}return d.abrupt("return");case 21:s=a.ctx.session.getBaseEvent(),t=(0,_extends2["default"])({},s,{event_type:_rumCore.RumEventType.EXCEPTION,name:"A white screen occurs at "+c,type:"blank",message:q,snapshots:JSON.stringify((0,_extends2["default"])({},r,{when:c}))}),a.sendEvent(t),a.abort();case 25:case"end":return d.stop()}},d)}));return function(){return b.apply(this,arguments)}}()}var b=a.prototype;return b.setup=function setup(a,b){var c=this;this.ctx=a,this.sendEvent=b;var d=a.getConfig(),e=d.whiteScreen,f=d.spaMode;if(e){// 开启白屏监控
var g=e.detectionRules;Array.isArray(g)&&g.length&&g.forEach(function(a){a.test_when.forEach(function(b){var d=function handler(){cancelList.forEach(function(a){return clearTimeout(a)}),cancelList=[];var d=setTimeout(function(){try{c.blankHandler(a,b)}catch(a){console.warn("[RUM] Failed to inject blank handler: ",a)}},a.delay);cancelList.push(d)},e=eventRegistrationMap[b];if(e){var g=e(d,f);c.observers.push(g)}})})}},b.destroy=function destroy(){this.abort()},a}();

@@ -1,4 +0,3 @@

"use strict";exports.__esModule=!0,exports["default"]=void 0;var _rumCore=require("@arms/rum-core"),_global=require("../../utils/global"),ExceptionCollector=exports["default"]=/*#__PURE__*/function(){function a(){this.name="exception-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;this.ctx=a,this.sendEvent=b;var f=this;!1!==e.consoleError&&(0,_rumCore.interceptFunction)(_global.global.console,"error",function(){for(var a=arguments.length,b=Array(a),c=0;c<a;c++)b[c]=arguments[c];(b||[]).forEach(function(a){return f.onError("console.error",a)})}),!1!==e.jsError&&(_global.global.addEventListener("error",this.onError.bind(this,"onError"),!0),_global.global.addEventListener("unhandledrejection",this.onError.bind(this,"onUnhandledRejection"),!0))},b.onError=function onError(a,b){if((0,_rumCore.isObject)(b)){// @ts-ignore
"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"),_global=require("../../utils/global"),ExceptionCollector=exports["default"]=/*#__PURE__*/function(){function a(){this.name="exception-collector",this.ctx=void 0,this.sendEvent=void 0}var b=a.prototype;return b.setup=function setup(a,b){var c=a.getConfig().collectors||{};this.ctx=a,this.sendEvent=b;var d=this;!1!==c.consoleError&&(0,_rumCore.interceptFunction)(_global.global.console,"error",function(){for(var a=arguments.length,b=Array(a),c=0;c<a;c++)b[c]=arguments[c];(b||[]).forEach(function(a){return d.onError("console.error",a)})}),!1!==c.jsError&&(_global.global.addEventListener("error",this.onError.bind(this,"onError"),!0),_global.global.addEventListener("unhandledrejection",this.onError.bind(this,"onUnhandledRejection"),!0))},b.onError=function onError(a,b){if((0,_rumCore.isObject)(b)){// @ts-ignore
var c=b.target||b.srcElement;if(!(c&&c.nodeName&&1===c.nodeType))// 过滤资源错误
{var d,e,f,g;if(b instanceof PromiseRejectionEvent?d=b.reason:b instanceof ErrorEvent?(d=b.error,e=b.colno,f=b.lineno,g=b.filename):d=b,!!(0,_rumCore.isObject)(d)){var h=d,i=h.name,j=h.message,k=h.stack;i&&j&&!this.errorFilter(d)&&this.sendEvent({event_type:_rumCore.RumEventType.EXCEPTION,type:"error",source:a,name:i,message:j,stack:k,file:g,line:f,column:e,// Measure
times:1})}}}},b.errorFilter=function errorFilter(a){var b,c=this.ctx.getConfig(),d=c.filters,e=void 0===d?{}:d,f=e.exception;if(!f)b=[];else if((0,_rumCore.isMatchOption)(f))b=[f];else if((0,_rumCore.isArray)(f))b=f;else return!1;b&&!(0,_rumCore.isArray)(b)&&(b=[b]);var g=[].concat(b,[/^Script error\.?$/,/failed[\w\s]+fetch/i]);return(0,_rumCore.matchList)(g,a.message,!0)},a}();
{var d,e,f,g;if(b instanceof PromiseRejectionEvent?d=b.reason:b instanceof ErrorEvent?(d=b.error,e=b.colno,f=b.lineno,g=b.filename):d=b,!!(0,_rumCore.isObject)(d)){var h=d,i=h.name,j=h.message,k=h.stack;if(i&&j&&!this.errorFilter(d)){var l=this.ctx.session.getBaseEvent();this.sendEvent((0,_extends2["default"])({},l,{event_type:_rumCore.RumEventType.EXCEPTION,type:"error",source:a,name:i,message:j,stack:k,file:g,line:f,column:e}))}}}}},b.errorFilter=function errorFilter(a){var b,c=this.ctx.getConfig().filters||{},d=c.exception;if(!d)b=[];else if((0,_rumCore.isMatchOption)(d))b=[d];else if((0,_rumCore.isArray)(d))b=d;else return!1;b&&!(0,_rumCore.isArray)(b)&&(b=[b]);var e=[].concat(b,[/^Script error\.?$/,/failed[\w\s]+fetch/i]);return(0,_rumCore.matchList)(e,a.message,!0)},a}();

@@ -1,6 +0,4 @@

"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"),_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(),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=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();(0,_rumCore.urlMatch)(g)||"HEAD"===h||(this.apiCache={type:_api.ApiType.XHR,method:a,url:c,async:d,user:e,password:f,headers:{}},this.apiAttr={timestamp:(0,_base.getCurrentTime)(),url:(0,_url.fixRelativeUrl)(g),method:h,// 异步过程 保证 view_id view_name 正确
view:(0,_view.getCurView)(b.ctx)})}),(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===_performance.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=_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,k,l={timestamp:(0,_base.getCurrentTime)(),url:(0,_url.fixRelativeUrl)(h),type:_api.ApiType.FETCH,method:i,// 异步过程 保证 view_id view_name 正确
view:(0,_view.getCurView)(a.ctx)};return a.injectTracing(l,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,l.status_code=d,l.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,l.message=a+"",l.success=_performance.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:l.url,entryType:_api.ApiType.FETCH,duration:(0,_base.getCurrentTime)()-l.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,l=(0,_extends2["default"])({},l,(0,_api.reviseApiAttr)(h)),b.next=12;break;case 10:b.prev=10,b.t0=b["catch"](3);case 12:a.mergeDataAndSend({attr:l,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}();
"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}();

@@ -1,6 +0,5 @@

"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"),_performance=require("../../utils/performance"),_url=require("../../utils/url"),_view=require("../../utils/view"),_global=require("../../utils/global"),_base=require("../../utils/base"),PerfObserver=_global.global.PerformanceObserver,StaticResourceCollector=exports["default"]=/*#__PURE__*/function(){function a(){var a=this;this.name="static-resource-collector",this.entryTypes=["audio","video","track","script","css","img","image","link","other"],this.errorsCache=[],this.WAIT_FOR_ERROR_TIME=1e3,this.perfObserver=void 0,this.sendEvent=void 0,this.ctx=void 0,this.sendResource=function(b,c){var d=a.ctx.getConfig(),e=d.parseResourceName,f=b.responseStatus,g=b.name,h=(0,_performance.getResourceType)(g,b.initiatorType),i=a.checkError(g),j=i?_performance.ResourceStatus.Failed:(0,_performance.getResourceSuccessByCode)(f),k=(0,_performance.calcResourceTimingData)(b,j===_performance.ResourceStatus.Failed);// If the value of the responseStatus property is 0, the resource might be a cross-origin request.
"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"),_performance=require("../../utils/performance"),_url=require("../../utils/url"),_view=require("../../utils/view"),_global=require("../../utils/global"),_base=require("../../utils/base"),PerfObserver=_global.global.PerformanceObserver,StaticResourceCollector=exports["default"]=/*#__PURE__*/function(){function a(){var a=this;this.name="static-resource-collector",this.entryTypes=["audio","video","track","script","css","img","image","link","other"],this.errorsCache=[],this.WAIT_FOR_ERROR_TIME=1e3,this.perfObserver=void 0,this.sendEvent=void 0,this.ctx=void 0,this.sendResource=function(b){var c=a.ctx.getConfig(),d=c.parseResourceName,e=b.responseStatus,f=b.name,g=(0,_performance.getResourceType)(f,b.initiatorType),h=a.checkError(f),i=h?_rumCore.ResourceStatus.Failed:(0,_performance.getResourceStatus)(b),j=(0,_performance.calcResourceTimingData)(b,h);// If the value of the responseStatus property is 0, the resource might be a cross-origin request.
// To allow seeing cross-origin response status codes, the CORS Access-Control-Allow-Origin HTTP
// response header needs to be set.
if(k){var l=(0,_extends2["default"])({event_type:_rumCore.RumEventType.RESOURCE,url:g,name:(0,_url.getResourceName)(g,e),type:h,method:"GET",status_code:f,success:j},k,{timing_data:JSON.stringify(b),// 异步任务,保证 view_id view_name 正确
view:c});(0,_rumCore.urlMatch)(l.url)||a.sendEvent(l)}},this.errorHandler=function(b){var c=b.target||b.srcElement,d=c&&c.nodeName&&1===c.nodeType,e=c.src||c.href;d&&e&&0===e.indexOf("http")&&a.errorsCache.push({src:e,timeStamp:(0,_base.getCurrentTime)()})},this.perfHandler=function(b){var c=b.getEntries().filter(function(b){return a.entryTypes.includes(b.initiatorType)});if(c&&c.length){var d=(0,_view.getCurView)(a.ctx);// 延迟 1 s 看是否加载失败
setTimeout(function(){c.forEach(function(b){a.sendResource(b,d)})},a.WAIT_FOR_ERROR_TIME)}}}var b=a.prototype;return b.setup=function setup(a,b){var c=a.getConfig(),d=c.collectors,e=void 0===d?{}:d;if((this.ctx=a,this.sendEvent=b,!1!==e.staticResource)&&(0,_rumCore.isFunction)(PerfObserver)){var f;try{f=new PerfObserver(this.perfHandler),f.observe({type:"resource",buffered:!0})}catch(a){f=new PerfObserver(this.perfHandler),f.observe({entryTypes:["resource"]})}this.perfObserver=f,_global.global.addEventListener("error",this.errorHandler,!0)}},b.checkError=function checkError(a){var b=!1,c=(0,_base.getCurrentTime)();return this.errorsCache=this.errorsCache.filter(function(d){return a===d.src?(b=!0,!0):!!(1e4<c-d.timeStamp)}),b},b.destroy=function destroy(){this.perfObserver&&(_global.global.removeEventListener("error",this.errorHandler),this.perfObserver.disconnect(),this.perfObserver=null)},a}();
if(j){var k=a.ctx.session.getBaseEvent(),l=(0,_extends2["default"])({},k,{event_type:_rumCore.RumEventType.RESOURCE,url:f,name:(0,_url.getResourceName)(f,d),type:g,method:"GET",status_code:e,success:i},j,{timing_data:JSON.stringify(b)});(0,_rumCore.urlMatch)(l.url)||a.sendEvent(l)}},this.errorHandler=function(b){var c=b.target||b.srcElement,d=c&&c.nodeName&&1===c.nodeType,e=c.src||c.href;d&&e&&0===e.indexOf("http")&&a.errorsCache.push({src:e,timeStamp:(0,_base.getCurrentTime)()})},this.perfHandler=function(b){var c=b.getEntries().filter(function(b){return-1<a.entryTypes.indexOf(b.initiatorType)});if(c&&c.length){var d=(0,_view.getCurView)(a.ctx);// 延迟 1 s 看是否加载失败
setTimeout(function(){c.forEach(function(b){a.sendResource(b,d)})},a.WAIT_FOR_ERROR_TIME)}}}var b=a.prototype;return b.setup=function setup(a,b){var c=a.getConfig().collectors||{};if((this.ctx=a,this.sendEvent=b,!1!==c.staticResource)&&(0,_rumCore.isFunction)(PerfObserver)){var d;try{d=new PerfObserver(this.perfHandler),d.observe({type:"resource",buffered:!0})}catch(a){d=new PerfObserver(this.perfHandler),d.observe({entryTypes:["resource"]})}this.perfObserver=d,_global.global.addEventListener("error",this.errorHandler,!0)}},b.checkError=function checkError(a){var b=!1,c=(0,_base.getCurrentTime)();return this.errorsCache=this.errorsCache.filter(function(d){return a===d.src?(b=!0,!0):!!(1e4<c-d.timeStamp)}),b},b.destroy=function destroy(){this.perfObserver&&(_global.global.removeEventListener("error",this.errorHandler),this.perfObserver.disconnect(),this.perfObserver=null)},a}();

@@ -1,3 +0,13 @@

"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),a.sendPerf();break;case"paint":"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 一起处理
"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"),_url=require("../../utils/url"),_global=require("../../utils/global"),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){// if (!event) {
// const view = getCurView(this.ctx);
// event = this.eventCache = {
// event_type: RumEventType.VIEW,
// type: 'perf',
// url: getCurrentURL(),
// referrer: document.referrer || '',
// // 异步任务,保证 view_id view_name 正确
// view
// }
// }
for(var c=b.getEntries(),d=a.eventCache,e=0;e<c.length;e++)try{var f=c[e];switch(f.entryType){case"navigation":var g=f.fetchStart,h=f.responseEnd,j=f.domInteractive,k=f.domContentLoadedEventEnd,l=f.domComplete,m=f.loadEventEnd;d.dom_interactive=(0,_rumCore.formatNumber)(j-g),d.dom_content_loaded=(0,_rumCore.formatNumber)(k-g),d.dom_complete=(0,_rumCore.formatNumber)(l-g),d.load_event=(0,_rumCore.formatNumber)(m-g),d.first_paint=(0,_rumCore.formatNumber)(h-g),a.sendPerf();break;case"paint":"first-paint"===f.name&&f.startTime<MAX_DELAY?d.first_paint=(0,_rumCore.formatNumber)(f.startTime):"first-contentful-paint"===f.name&&f.startTime<MAX_DELAY&&(d.first_contentful_paint=(0,_rumCore.formatNumber)(f.startTime));break;// 放入 web-vitals 里面处理 与 first_input_delay 一起处理
// case 'first-input':

@@ -9,2 +19,2 @@ // if (entry.startTime < MAX_DELAY) {

default:return}}catch(a){// console.warn('RUM-perfHandler', e)
}},this.sendPerf=function(){a.eventCache&&a.perfObserver&&(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,200),(0,_rumCore.isFunction)(PerfObserver)&&(this.perfObserver=new PerfObserver(function(a){(0,_rumCore.delay)(c.perfHandler,200,a)}),this.perfObserver.observe({entryTypes:["navigation","paint"]})))},a}();// 10分钟
}},this.sendPerf=function(){a.eventCache&&a.perfObserver&&(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().collectors||{};if(!1!==d.perf&&(this.ctx=a,this.sendEvent=b,this.sendPerf=(0,_rumCore.debounce)(this.sendPerf,200),!!(0,_rumCore.isFunction)(PerfObserver))){this.perfObserver=new PerfObserver(function(a){(0,_rumCore.delay)(c.perfHandler,200,a)}),this.perfObserver.observe({entryTypes:["navigation","paint"]});var e=this.ctx.session.getBaseEvent();this.eventCache=(0,_extends2["default"])({},e,{event_type:_rumCore.RumEventType.VIEW,type:"perf",url:(0,_url.getCurrentURL)(),referrer:_global.document.referrer||""})}},a}();// 10分钟

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

"use strict";exports.__esModule=!0,exports["default"]=void 0;var _rumCore=require("@arms/rum-core"),_url=require("../../utils/url"),_global=require("../../utils/global"),supportsHistory=_global.history&&!!_global.history.pushState&&!!_global.history.replaceState,PvCollector=exports["default"]=/*#__PURE__*/function(){function a(){var a=this;this.name="pv-collector",this.ctx=void 0,this.sendEvent=void 0,this.prevUrl=void 0,this.sendPv=function(b,c,d){void 0===d&&(d="route_change");var e=a.getViewName(b),f=a.prevUrl;// 如果两次的view.name相同,判断为没有pv发生
a.prevUrl=b,f&&e===a.getViewName(f)||(a.ctx.addView({id:a.ctx.session.getViewId(),name:e}),a.sendEvent({event_type:_rumCore.RumEventType.VIEW,type:"pv",name:e,url:b,referrer:c,loading_type:d}))},this.historyFn=function(){var b=2<arguments.length?2>=arguments.length?void 0:arguments[2]:void 0;if(b){var c=_global.location.origin+b,d=a.prevUrl;a.sendPv(c,d)}},this.popstateFn=function(){var b=(0,_url.getCurrentURL)(),c=a.prevUrl;a.sendPv(b,c)}}var b=a.prototype;return b.setup=function setup(a,b){this.ctx=a,this.sendEvent=b,this.sendPv((0,_url.getCurrentURL)(),_global.document.referrer||"","initial_load");var c=this.getSpaMode();supportsHistory&&c&&((0,_rumCore.interceptFunction)(_global.global.history,"pushState",this.historyFn),(0,_rumCore.interceptFunction)(_global.global.history,"replaceState",this.historyFn),_global.global.addEventListener("popstate",this.popstateFn))},b.getSpaMode=function getSpaMode(){var a=this.ctx.getConfig().spaMode;return(0,_rumCore.isUndefined)(a)&&(a=!0),!!a&&("history"!==a&&"hash"!==a?"history":a)},b.getViewName=function getViewName(a){var b=this.ctx.getConfig(),c=this.getSpaMode(),d=(0,_url.getPathByURL)(a,"hash"===c);return(0,_rumCore.isFunction)(b.parseViewName)&&(d=b.parseViewName(a)),d},b.destroy=function destroy(){supportsHistory&&_global.global.removeEventListener("popstate",this.popstateFn)},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"),_url=require("../../utils/url"),_global=require("../../utils/global"),supportsHistory=_global.history&&!!_global.history.pushState&&!!_global.history.replaceState,PvCollector=exports["default"]=/*#__PURE__*/function(){function a(){var a=this;this.name="pv-collector",this.ctx=void 0,this.sendEvent=void 0,this.prevUrl=void 0,this.sendPv=function(b,c,d){void 0===d&&(d="route_change");var e=a.getViewName(b),f=a.prevUrl;// 如果两次的view.name相同,判断为没有pv发生
if(a.prevUrl=b,!(f&&e===a.getViewName(f))){a.ctx.addView({id:a.ctx.session.getViewId(),name:e});var g=a.ctx.session.getBaseEvent();a.sendEvent((0,_extends2["default"])({},g,{event_type:_rumCore.RumEventType.VIEW,type:"pv",name:e,url:b,referrer:c,loading_type:d}))}},this.historyFn=function(){var b=2<arguments.length?2>=arguments.length?void 0:arguments[2]:void 0;if(b){var c=_global.location.origin+b,d=a.prevUrl;a.sendPv(c,d)}},this.popstateFn=function(){var b=(0,_url.getCurrentURL)(),c=a.prevUrl;a.sendPv(b,c)}}var b=a.prototype;return b.setup=function setup(a,b){this.ctx=a,this.sendEvent=b,this.sendPv((0,_url.getCurrentURL)(),_global.document.referrer||"","initial_load");var c=this.getSpaMode();supportsHistory&&c&&((0,_rumCore.interceptFunction)(_global.global.history,"pushState",this.historyFn),(0,_rumCore.interceptFunction)(_global.global.history,"replaceState",this.historyFn),_global.global.addEventListener("popstate",this.popstateFn))},b.getSpaMode=function getSpaMode(){var a=this.ctx.getConfig().spaMode;return(0,_rumCore.isUndefined)(a)&&(a=!0),!!a&&("history"!==a&&"hash"!==a?"history":a)},b.getViewName=function getViewName(a){var b=this.ctx.getConfig(),c=this.getSpaMode(),d=(0,_url.getPathByURL)(a,"hash"===c);return(0,_rumCore.isFunction)(b.parseViewName)&&(d=b.parseViewName(a)),d},b.destroy=function destroy(){supportsHistory&&_global.global.removeEventListener("popstate",this.popstateFn)},a}();

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

"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=!0,exports["default"]=void 0;var _extends3=_interopRequireDefault(require("@babel/runtime/helpers/extends")),_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,this.baseEvent=void 0,this.measures={},this.timer=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.baseEvent={event_type:_rumCore.RumEventType.VIEW,type:"webvitals",referrer:_global.document.referrer||"",view:(0,_view.getCurView)(this.ctx)},this.onWebVitals())},b.sendWebVitals=function sendWebVitals(a,b){var c,d=this;clearTimeout(this.timer),this.measures=(0,_extends3["default"])({},this.measures,(c={},c[a]=b,c)),this.timer=setTimeout(function(){d.sendEvent((0,_extends3["default"])({},d.baseEvent,d.measures,{url:(0,_url.getCurrentURL)()})),d.measures={}},200)},b.onWebVitals=function onWebVitals(){var a=this;(0,_webVitals.onLCP)(function(b){return a.sendWebVitals("largest_contentful_paint",(0,_rumCore.formatNumber)(b.value))}),(0,_webVitals.onFID)(function(b){a.sendWebVitals("first_input_delay",(0,_rumCore.formatNumber)(b.value)),(0,_rumCore.isArray)(b.entries)&&b.entries.forEach(function(b){b&&"first-input"===b.entryType&&a.sendWebVitals("first_input_time",(0,_rumCore.formatNumber)(b.startTime))})}),(0,_webVitals.onCLS)(function(b){return a.sendWebVitals("cumulative_layout_shift",(0,_rumCore.formatNumber)(b.value))}),(0,_webVitals.onINP)(function(b){return a.sendWebVitals("interaction_to_next_paint",(0,_rumCore.formatNumber)(b.value))})},a}();
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=!0,exports["default"]=void 0;var _extends3=_interopRequireDefault(require("@babel/runtime/helpers/extends")),_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,this.baseEvent=void 0,this.measures={},this.timer=void 0}var b=a.prototype;return b.setup=function setup(a,b){var c=a.getConfig().collectors||{};!1===c.webVitals||(this.ctx=a,this.sendEvent=b,this.baseEvent={event_type:_rumCore.RumEventType.VIEW,type:"webvitals",referrer:_global.document.referrer||"",view:(0,_view.getCurView)(this.ctx)},this.onWebVitals())},b.sendWebVitals=function sendWebVitals(a,b){var c,d=this;clearTimeout(this.timer),this.measures=(0,_extends3["default"])({},this.measures,(c={},c[a]=b,c)),this.timer=setTimeout(function(){var a=d.ctx.session.getBaseEvent();d.sendEvent((0,_extends3["default"])({},a,d.baseEvent,d.measures,{url:(0,_url.getCurrentURL)()})),d.measures={}},200)},b.onWebVitals=function onWebVitals(){var a=this;(0,_webVitals.onLCP)(function(b){return a.sendWebVitals("largest_contentful_paint",(0,_rumCore.formatNumber)(b.value))}),(0,_webVitals.onFID)(function(b){a.sendWebVitals("first_input_delay",(0,_rumCore.formatNumber)(b.value)),(0,_rumCore.isArray)(b.entries)&&b.entries.forEach(function(b){b&&"first-input"===b.entryType&&a.sendWebVitals("first_input_time",(0,_rumCore.formatNumber)(b.startTime))})}),(0,_webVitals.onCLS)(function(b){return a.sendWebVitals("cumulative_layout_shift",(0,_rumCore.formatNumber)(b.value))}),(0,_webVitals.onINP)(function(b){return a.sendWebVitals("interaction_to_next_paint",(0,_rumCore.formatNumber)(b.value))})},a}();

@@ -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")),_base=require("../utils/base"),_view=require("../utils/view"),DefaultProcessor=exports["default"]=/*#__PURE__*/function(){function a(){this.name="default-processor"}var b=a.prototype;return b.process=function process(a){var b=a.getRumEvent(),c=(0,_view.getCurView)(a),d=(0,_extends2["default"])({timestamp:(0,_base.getCurrentTime)(),event_id:a.session.getEventId(),view:c},b);return d},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")),_base=require("../utils/base"),_view=require("../utils/view"),DefaultProcessor=exports["default"]=/*#__PURE__*/function(){function a(){this.name="default-processor"}var b=a.prototype;return b.process=function process(a){var b=a.getRumEvent(),c=(0,_view.getCurView)(a),d=(0,_extends2["default"])({timestamp:(0,_base.getCurrentTime)(),session_id:a.session.getSessionId(),event_id:a.session.getEventId(),view:c},b);return d},a}();

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

"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,c){var d,e=a.getConfig(),f=a.session,g={app:{id:e.pid,env:e.env||"prod",version:e.version,type:_rumCore.AppType.browser},user:{id:f.getUserId()},session:{id:f.getSessionId()},view:c,net:{model:(null===(d=navigator.connection)||void 0===d?void 0:d.effectiveType)||""},events:b,_v:_global.VERSION};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 g)&&(g[a]={}),g[a][c]=d)})}),!("function"==typeof e.beforeReport&&(g=e.beforeReport(g),!g))){var h,i=JSON.stringify(g),j=new Blob([i]).size;if(6e4>j)try{h=navigator.sendBeacon(e.endpoint,i)}catch(a){h=!1}if(!h){var k=new XMLHttpRequest;k.open("POST",e.endpoint,!0),k.setRequestHeader("Content-Type","text/plain"),k.send(i)}}},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,c){var d,e=a.getConfig(),f=a.session,g=f.getSessionId();b.forEach(function(a){a.session_id===g&&delete a.session_id});var h={app:{id:e.pid,env:e.env||"prod",version:e.version,type:_rumCore.AppType.browser},user:{id:f.getUserId()},session:{id:g},view:c,net:{model:(null===(d=navigator.connection)||void 0===d?void 0:d.effectiveType)||""},events:b,_v:_global.VERSION};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 h)&&(h[a]={}),h[a][c]=d)})}),!("function"==typeof e.beforeReport&&(h=e.beforeReport(h),!h))){var i,j=JSON.stringify(h),k=new Blob([j]).size;if(6e4>k)try{i=navigator.sendBeacon(e.endpoint,j)}catch(a){i=!1}if(!i){var l=new XMLHttpRequest;l.open("POST",e.endpoint,!0),l.setRequestHeader("Content-Type","text/plain"),l.send(j)}}},b}(_rumCore.Reporter),_default=exports["default"]=BrowserReporter;/**
* browser reporter
*/
import { IConfiguration, ITracingOption } from "@arms/rum-core";
import { IApiBaseAttr } from "../utils/api";
import { IApiAttr } from "../utils/api";
export interface IBrowserConfig extends IConfiguration {

@@ -23,3 +23,3 @@ /**

*/
evaluateApi?(request: any, response: any, error?: Error): Promise<IApiBaseAttr>;
evaluateApi?(request: any, response: any, error?: Error): Promise<IApiAttr>;
}

@@ -1,3 +0,2 @@

import { IViewData } from "@arms/rum-core";
import { ResourceStatus } from "./performance";
import { IViewData, ResourceStatus, RumEvent } from "@arms/rum-core";
export declare const ApiType: {

@@ -7,3 +6,3 @@ XHR: string;

};
export interface IApiBaseAttr {
export interface IApiAttr extends RumEvent {
name?: string;

@@ -15,8 +14,6 @@ message?: string;

snapshots?: string;
}
export interface IApiAttr extends IApiBaseAttr {
view: IViewData;
url: string;
method: string;
timestamp: number;
view?: IViewData;
url?: string;
method?: string;
timestamp?: number;
trace_id?: string;

@@ -35,2 +32,2 @@ trace_data?: string;

}
export declare function reviseApiAttr(attrs: IApiBaseAttr): IApiBaseAttr;
export declare function reviseApiAttr(attrs: IApiAttr): IApiAttr;

@@ -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.26';
"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';

@@ -0,10 +1,3 @@

import { ResourceStatus } from '@arms/rum-core';
/**
* 枚举值,表示资源是否加载成功
*/
export declare enum ResourceStatus {
Unknown = -1,
Failed = 0,
Success = 1
}
/**
* Resource 事件的时间度量

@@ -16,3 +9,3 @@ */

*/
duration: number;
duration?: number;
/**

@@ -23,5 +16,9 @@ * 资源大小(字节数)

/**
* 实际网络传输大小
*/
transfer_size?: number;
/**
* 与服务器建立连接花费的时间
*/
connect_duration: number;
connect_duration?: number;
/**

@@ -34,15 +31,15 @@ * TLS 握手花费的时间

*/
dns_duration: number;
dns_duration?: number;
/**
* 重定向 HTTP 请求花费的时间
*/
redirect_duration: number;
redirect_duration?: number;
/**
* 等待接收响应的第一个字节所花费的时间
*/
first_byte_duration: number;
first_byte_duration?: number;
/**
* 下载响应所用的时间
*/
download_duration: number;
download_duration?: number;
}

@@ -56,2 +53,8 @@ /**

/**
* 判断成功还是失败
* @param status_code
* @returns
*/
export declare function getResourceStatus(entry: PerformanceResourceTiming): ResourceStatus;
/**
* 根据 performance timing 对象计算 Resource 事件的时间度量

@@ -58,0 +61,0 @@ * @param pt 通过 performance API 获取的性能对象

@@ -1,4 +0,2 @@

"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.getResourceSuccessByCode=getResourceSuccessByCode,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}/**
* 枚举值,表示资源是否加载成功
*/var ResourceStatus=exports.ResourceStatus=/*#__PURE__*/function(a){return a[a.Unknown=-1]="Unknown",a[a.Failed=0]="Failed",a[a.Success=1]="Success",a}({});/**
"use strict";var _rumCore=require("@arms/rum-core");exports.__esModule=!0,exports.ResourceType=exports.RESOURCE_TYPES=exports.FAKE_INITIAL_DOCUMENT=void 0,exports.calcResourceTimingData=calcResourceTimingData,exports.getResourceStatus=getResourceStatus,exports.getResourceSuccessByCode=getResourceSuccessByCode,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}/**
* Resource 事件的时间度量

@@ -9,13 +7,17 @@ */ /**

* @returns
*/function getResourceSuccessByCode(a){var b,c=[200,300];return b=a?a>=c[0]&&a<c[1]?ResourceStatus.Success:ResourceStatus.Failed:ResourceStatus.Unknown,b}function areInOrder(){for(var a=1;a<arguments.length;a+=1)if((0>a-1||arguments.length<=a-1?void 0:arguments[a-1])>(0>a||arguments.length<=a?void 0:arguments[a]))return!1;return!0}// function hasRedirection(entry: PerformanceNavigationTiming) {
// // The only time fetchStart is different than startTime is if a redirection occurred.
// return entry.fetchStart !== entry.startTime
// }
/**
*/function getResourceSuccessByCode(a){var b,c=[200,300];return b=a?a>=c[0]&&a<c[1]?_rumCore.ResourceStatus.Success:_rumCore.ResourceStatus.Failed:_rumCore.ResourceStatus.Unknown,b}/**
* 判断成功还是失败
* @param status_code
* @returns
*/function getResourceStatus(a){var b,c=a.responseStatus,d=a.transferSize,e=a.encodedBodySize,f=a.decodedBodySize,g=a.responseEnd,h=a.startTime;return b=c?getResourceSuccessByCode(c):0===d&&0===e&&0===f?_rumCore.ResourceStatus.Failed:g>h&&(0<d||0<e||0<f)?_rumCore.ResourceStatus.Success:_rumCore.ResourceStatus.Unknown,b}function areInOrder(){for(var a=1;a<arguments.length;a+=1)if((0>a-1||arguments.length<=a-1?void 0:arguments[a-1])>(0>a||arguments.length<=a?void 0:arguments[a]))return!1;return!0}/**
* 根据 performance timing 对象计算 Resource 事件的时间度量
* @param pt 通过 performance API 获取的性能对象
*/function calcResourceTimingData(a,b){void 0===b&&(b=!1);var c=a.startTime,d=a.fetchStart,e=a.decodedBodySize,f=a.redirectStart,g=a.redirectEnd,h=a.domainLookupStart,i=a.domainLookupEnd,j=a.connectStart,k=a.secureConnectionStart,l=a.connectEnd,m=a.requestStart,n=a.responseStart,o=a.responseEnd,p=a.duration;// 失败情况下不进行过滤
*/function calcResourceTimingData(a,b){void 0===b&&(b=!1);var c=a.startTime,d=a.fetchStart,e=a.transferSize,f=a.encodedBodySize,g=a.decodedBodySize,h=a.redirectStart,i=a.redirectEnd,j=a.domainLookupStart,k=a.domainLookupEnd,l=a.connectStart,m=a.secureConnectionStart,n=a.connectEnd,o=a.requestStart,p=a.responseStart,q=a.responseEnd,r=a.duration;// 失败情况下不进行过滤
if(!b){// 确保时间的顺序正确。除了过滤潜在的资源时间之外,它将忽略无法收集时间的请求的条目,例如没有 "Timing-Allow-Origin" 允许请求头的跨域请求。
if(!areInOrder(c,d,h,i,j,l,m,n,o))return;// 请确保实际发生了一个请求
if(c>n)return}// Firefox 以及其他不提供对跨原点请求的重定向计时。提供一个默认值。
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}
if(!areInOrder(c,d,j,k,l,n,o,p,q))return;// 请确保实际发生了一个请求
if(0===r||// 没有耗时
0===p||c>p||// 没有发起请求
0===e&&0<f&&0<g||// 命中缓存
"cache"===a.deliveryType// 命中缓存
)return}// Firefox 以及其他不提供对跨原点请求的重定向计时。提供一个默认值。
h<c&&(h=c),i<c&&(i=d);var s={duration:r};return n&&(s.connect_duration=(0,_rumCore.formatNumber)(n-l)),k&&(s.dns_duration=(0,_rumCore.formatNumber)(k-j)),i&&(s.redirect_duration=(0,_rumCore.formatNumber)(i-h)),p&&(s.download_duration=(0,_rumCore.formatNumber)(q-p),s.first_byte_duration=(0,_rumCore.formatNumber)(p-o)),g&&(s.size=(0,_rumCore.formatNumber)(g)),e&&(s.transfer_size=(0,_rumCore.formatNumber)(e)),m&&(s.ssl_duration=(0,_rumCore.formatNumber)(n-m)),s}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}

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

import { IContext, SessionConfig, IRumSession } from "@arms/rum-core";
import { IContext, SessionConfig, IRumSession, RumEvent } from "@arms/rum-core";
import { IBrowserConfig } from "../types/client";

@@ -25,3 +25,4 @@ interface SessionInfo {

private fixSessionConfig;
getBaseEvent(): RumEvent;
}
export {};

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

"use strict";exports.__esModule=!0,exports.RumSession=void 0;var _rumCore=require("@arms/rum-core"),_base=require("./base"),USER_ID="_arms_uid",RUM_SESSION="_arms_session",RumSession=exports.RumSession=/*#__PURE__*/function(){function a(){this.ctx=void 0,this.sessionConfig=void 0}var b=a.prototype;return b.init=function init(a){this.sessionConfig=this.fixSessionConfig(a.sessionConfig)},b.getSessionId=function getSessionId(){return this.getSessionInfo().sessionId},b.getSampled=function getSampled(){return this.getSessionInfo().sampled},b.checkSession=function checkSession(a){var b=this.sessionConfig,c=b.overtime,d=b.maxDuration,e=(0,_base.getCurrentTime)();return!(a.startTime+d<e||a.lastTime+c<e)},b.updateSession=function updateSession(){var a=this.getSessionInfo();if(!a.isNew){var b=a.startTime,c=(0,_base.getCurrentTime)(),d=a.sampled?1:0;localStorage.setItem(RUM_SESSION,a.sessionId+"-"+d+"-"+b+"-"+c)}},b.getSessionInfo=function getSessionInfo(){var a=(localStorage.getItem(RUM_SESSION)||"").split("-"),b=a[0],c=a[1],d=a[2],e=a[3],f={sessionId:b,sampled:"0"!==c,startTime:parseInt(d||"")||0,lastTime:parseInt(e||"")||0};return this.checkSession(f)||(f=this.resetSession()),f},b.getEventId=function getEventId(){return(0,_rumCore.generateEventId)(this.getSessionId())},b.getViewId=function getViewId(){return this.getUUID()},b.getUserId=function getUserId(){var a=localStorage.getItem(USER_ID);return a&&0===a.indexOf("user_")&&(a=""),a||(a="uid_"+(0,_rumCore.generateSpanId)(16,36),localStorage.setItem(USER_ID,a)),a},b.resetSession=function resetSession(){var a=this.sessionConfig.sampleRate,b=this.getUUID(),c=(0,_base.getCurrentTime)(),d=(0,_rumCore.performDraw)(100*a),e=b+"-"+(d?1:0)+"-"+c+"-"+c;return localStorage.setItem(RUM_SESSION,e),{sessionId:b,sampled:d,startTime:c,lastTime:c,isNew:!0}},b.getUUID=function getUUID(){return(0,_rumCore.generateGUID)().replace(/-/g,"")},b.fixSessionConfig=function fixSessionConfig(a){void 0===a&&(a={});var b=a,c=b.sampleRate,d=b.maxDuration,e=b.overtime;return(!(0,_rumCore.isNumber)(c)||0>c||1<c)&&(c=1),(!(0,_rumCore.isNumber)(d)||d<4*_rumCore.ONE_HOUR||d>_rumCore.ONE_DAY)&&(d=_rumCore.ONE_DAY),(!(0,_rumCore.isNumber)(e)||e>_rumCore.ONE_HOUR||e<10*_rumCore.ONE_MINUTE)&&(e=_rumCore.ONE_HOUR),{sampleRate:c,maxDuration:d,overtime:e}},a}();// 存储userID的键名
"use strict";exports.__esModule=!0,exports.RumSession=void 0;var _rumCore=require("@arms/rum-core"),_base=require("./base"),_view=require("./view"),USER_ID="_arms_uid",RUM_SESSION="_arms_session",RumSession=exports.RumSession=/*#__PURE__*/function(){function a(){this.ctx=void 0,this.sessionConfig=void 0}var b=a.prototype;return b.init=function init(a){this.sessionConfig=this.fixSessionConfig(a.sessionConfig)},b.getSessionId=function getSessionId(){return this.getSessionInfo().sessionId},b.getSampled=function getSampled(){return this.getSessionInfo().sampled},b.checkSession=function checkSession(a){var b=this.sessionConfig,c=b.overtime,d=b.maxDuration,e=(0,_base.getCurrentTime)();return!(a.startTime+d<e||a.lastTime+c<e)},b.updateSession=function updateSession(){var a=this.getSessionInfo();if(!a.isNew){var b=a.startTime,c=(0,_base.getCurrentTime)(),d=a.sampled?1:0;localStorage.setItem(RUM_SESSION,a.sessionId+"-"+d+"-"+b+"-"+c)}},b.getSessionInfo=function getSessionInfo(){var a=(localStorage.getItem(RUM_SESSION)||"").split("-"),b=a[0],c=a[1],d=a[2],e=a[3],f={sessionId:b,sampled:"0"!==c,startTime:parseInt(d||"")||0,lastTime:parseInt(e||"")||0};return this.checkSession(f)||(f=this.resetSession()),f},b.getEventId=function getEventId(){return(0,_rumCore.generateEventId)(this.getSessionId())},b.getViewId=function getViewId(){return this.getUUID()},b.getUserId=function getUserId(){var a=localStorage.getItem(USER_ID);return a&&0===a.indexOf("user_")&&(a=""),a||(a="uid_"+(0,_rumCore.generateSpanId)(16,36),localStorage.setItem(USER_ID,a)),a},b.resetSession=function resetSession(){var a=this.sessionConfig.sampleRate,b=this.getUUID(),c=(0,_base.getCurrentTime)(),d=(0,_rumCore.performDraw)(100*a),e=b+"-"+(d?1:0)+"-"+c+"-"+c;return localStorage.setItem(RUM_SESSION,e),{sessionId:b,sampled:d,startTime:c,lastTime:c,isNew:!0}},b.getUUID=function getUUID(){return(0,_rumCore.generateGUID)().replace(/-/g,"")},b.fixSessionConfig=function fixSessionConfig(a){void 0===a&&(a={});var b=a,c=b.sampleRate,d=b.maxDuration,e=b.overtime;return(!(0,_rumCore.isNumber)(c)||0>c||1<c)&&(c=1),(!(0,_rumCore.isNumber)(d)||d<4*_rumCore.ONE_HOUR||d>_rumCore.ONE_DAY)&&(d=_rumCore.ONE_DAY),(!(0,_rumCore.isNumber)(e)||e>_rumCore.ONE_HOUR||e<10*_rumCore.ONE_MINUTE)&&(e=_rumCore.ONE_HOUR),{sampleRate:c,maxDuration:d,overtime:e}},b.getBaseEvent=function getBaseEvent(){var a={timestamp:(0,_base.getCurrentTime)(),session_id:this.getSessionId(),event_id:this.getEventId(),view:this.ctx?(0,_view.getCurView)(this.ctx):void 0,times:1};return a},a}();// 存储userID的键名
// 存储session
{
"name": "@arms/rum-browser",
"version": "0.0.26",
"version": "0.0.27-beta.1",
"description": "arms rum javascript sdk for browser",

@@ -8,2 +8,3 @@ "author": "guangli.fj <guangli.fj@alibaba-inc.com>",

"main": "lib/index.js",
"module": "esm/index.js",
"directories": {

@@ -15,2 +16,3 @@ "lib": "lib",

"lib",
"es",
"dist"

@@ -28,3 +30,3 @@ ],

"dependencies": {
"@arms/rum-core": "0.0.25-beta.14",
"@arms/rum-core": "0.0.25-beta.16",
"web-vitals": "3.5.2"

@@ -31,0 +33,0 @@ },

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