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

@arms/rum-browser

Package Overview
Dependencies
Maintainers
5
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.3 to 0.0.4

lib/processor/filter-processor.d.ts

2

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"),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.click||document.addEventListener("click",function(a){var c=(0,_base.getCurrentTime)(a.timeStamp),d=(0,_base.formatNumber)(performance.now()-a.timeStamp),e=a.target;if(e instanceof HTMLElement){// 根据元素过滤,仅当被关注的元素所嵌套时才会采集数据(默认为 button、a 和表单元素)
"use strict";exports.__esModule=!0,exports["default"]=void 0;var _rumCore=require("@arms/rum-core"),_base=require("../../utils/base"),_dom=require("../../utils/dom"),_global=require("../../utils/global"),ClickCollector=exports["default"]=/*#__PURE__*/function(){function a(){this.name="click-collector",this.DELAY_TIME=300}var b=a.prototype;return b.setup=function setup(a,b){var c=a.getConfig(),d=c.collectors,e=void 0===d?{}:d;!1===e.click||_global.document.addEventListener("click",function(a){var c=(0,_base.getCurrentTime)(a.timeStamp),d=(0,_base.formatNumber)(performance.now()-a.timeStamp),e=a.target;if(e instanceof HTMLElement){// 根据元素过滤,仅当被关注的元素所嵌套时才会采集数据(默认为 button、a 和表单元素)
var f=(0,_dom.getClosestTargetAncestorElement)(e,["button","a","input","select","option","textarea"]);if(f){// 获取语义化的描述
var g=f.localName,h=f.nodeName,i=f.innerText,j=(g||h).toLowerCase(),k=f.getAttribute("type"),l=i&&": "+(20<i.length?i.slice(0,20)+"...":i),m="click on "+((k?k+"-":"")+j)+l,n={event_type:_rumCore.RumEventType.ACTION,type:"click",name:m,target_name:(0,_dom.getElementXpath)(e),duration:d,times:1,timestamp:c};b(n)}}},!0)},a}();

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

"use strict";exports.__esModule=!0,exports["default"]=void 0;var _rumCore=require("@arms/rum-core"),_exception=require("../../utils/exception"),ExceptionCollector=exports["default"]=/*#__PURE__*/function(){function a(){this.name="exception-collector",this.MAX_STACK_NUM=5}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.consoleError&&(0,_rumCore.interceptFunction)(window.console,"error",function(){for(var a=arguments.length,c=Array(a),d=0;d<a;d++)c[d]=arguments[d];(c||[]).forEach(function(a){"object"==typeof a&&a.stack&&b({event_type:_rumCore.RumEventType.EXCEPTION,source:"console",type:"error",name:(0,_exception.getErrorNameByMessage)(a.stack),message:a.message,stack:a.stack,// Measure
times:1})})}),!1!==e.jsError&&window.addEventListener("error",function(a){a.preventDefault();var c=a.colno,d=a.lineno,e=a.filename,f=a.error,g=a.message;"object"==typeof f&&f.stack&&b({event_type:_rumCore.RumEventType.EXCEPTION,source:"event",type:"error",name:f.name||(0,_exception.getErrorNameByMessage)(g),message:f.message||g,file:e,stack:f.stack,line:d,column:c,// Measure
times:1})}),window.addEventListener("unhandledrejection",function(a){a.preventDefault();var c=a.reason;"object"==typeof c&&c.stack&&b({event_type:_rumCore.RumEventType.EXCEPTION,source:"event",type:"error",name:(0,_exception.getErrorNameByMessage)(c.stack),message:c.message,stack:c.stack,// Measure
"use strict";exports.__esModule=!0,exports["default"]=void 0;var _rumCore=require("@arms/rum-core"),_exception=require("../../utils/exception"),_global=require("../../utils/global"),ExceptionCollector=exports["default"]=/*#__PURE__*/function(){function a(){this.name="exception-collector",this.MAX_STACK_NUM=5}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.consoleError&&(0,_rumCore.interceptFunction)(_global.global.console,"error",function(){for(var a=arguments.length,c=Array(a),d=0;d<a;d++)c[d]=arguments[d];(c||[]).forEach(function(a){"object"==typeof a&&a.stack&&b({event_type:_rumCore.RumEventType.EXCEPTION,source:"console",type:"error",name:(0,_exception.getErrorNameByMessage)(a.stack),message:a.message,stack:a.stack,// Measure
times:1})})}),!1!==e.jsError&&_global.global.addEventListener("error",function(a){a.preventDefault();var c=a.colno,d=a.lineno,e=a.filename,f=a.error,g=a.message;"object"==typeof f&&f.stack&&b({event_type:_rumCore.RumEventType.EXCEPTION,source:"event",type:"error",name:f.name||(0,_exception.getErrorNameByMessage)(g),message:f.message||g,file:e,stack:f.stack,line:d,column:c,// Measure
times:1})}),_global.global.addEventListener("unhandledrejection",function(a){a.preventDefault();var c=a.reason;"object"==typeof c&&c.stack&&b({event_type:_rumCore.RumEventType.EXCEPTION,source:"event",type:"error",name:(0,_exception.getErrorNameByMessage)(c.stack),message:c.message,stack:c.stack,// Measure
times:1})})},a}();

@@ -8,2 +8,3 @@ import { ICollector, IContext, IViewData, RumEvent } from '@arms/rum-core';

message: string;
trace_id: string;
}

@@ -17,5 +18,4 @@ declare global {

name: string;
private ignoreUrs;
private entryTypes;
private cachedEntrys;
private cachedEntries;
private cachedApiAttrs;

@@ -22,0 +22,0 @@ setup(ctx: IContext, sendEvent: (payload: RumEvent) => void): void;

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

"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"),ApiCollector=exports["default"]=/*#__PURE__*/function(){function a(){this.name="api-collector",this.ignoreUrs=[],this.entryTypes=["xmlhttprequest","fetch"],this.cachedEntrys=[],this.cachedApiAttrs=[]}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;if(!1!==f.api){var g=a.getConfig(),h=g.endpoint;this.ignoreUrs.push(h),new PerformanceObserver(function(a){var d=a.getEntries().filter(function(a){return c.entryTypes.includes(a.initiatorType)});d&&d.length&&d.forEach(function(a){j(b,{entry:a})})}).observe({type:"resource",buffered:!0});var i=XMLHttpRequest.prototype;(0,_rumCore.interceptFunction)(i,"open",function(b,c){this.apiAttr={},this.apiAttr.url=c+"",this.apiAttr.method=b.toUpperCase();// 异步过程 保证 view_id view_name 正确
var d=(0,_view.getCurView)(a);this.apiAttr.view=d}),(0,_rumCore.interceptFunction)(i,"send",function(){var a=this;this.addEventListener("loadend",function(){var c=a.status,d=a.statusText,e=a.response;a.apiAttr.status_code=c,a.apiAttr.message=d,j(b,{attr:a.apiAttr})})}),(0,_base.hackFunction)(window,"fetch",function(c){return function(d,e){var f,g={},h=new URL((0,_url.getCurrentURL)()),i=h.protocol,k=h.host;g.url=(0,_url.completeURL)(d+"",i,k),g.method=(null===e||void 0===e||null===(f=e.method)||void 0===f?void 0:f.toUpperCase())||"GET";// 异步过程 保证 view_id view_name 正确
var l=(0,_view.getCurView)(a);return g.view=l,c.call(window,d,e).then(/*#__PURE__*/function(){var a=(0,_asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function b(a){var c,d,e;return _regenerator["default"].wrap(function(b){for(;;)switch(b.prev=b.next){case 0:return c=a.clone(),d=c.status,e=c.statusText,g.status_code=d,g.message=e,b.abrupt("return",a);case 5:case"end":return b.stop()}},b)}));return function(){return a.apply(this,arguments)}}(),function(a){throw g.message=a+"",a})["finally"](function(){j(b,{attr:g})})}});var j=function(a,b){try{var d=function(b,c){var d=b.method,e=b.url,f=b.status_code,g=b.message,h=b.view,i=(0,_performance.getResourceStatusByCode)(f);a((0,_extends2["default"])({event_type:_rumCore.RumEventType.RESOURCE,url:e,name:(0,_url.getPathByURL)(e),type:c.initiatorType||c.entryType,method:d,status_code:f,message:g,success:i},(0,_performance.calcResourceTimingData)(c),{view:h}))},e=b.attr,f=b.entry,g=c.cachedApiAttrs,h=c.cachedEntrys;if(e){var i=h.find(function(a){return a.name===e.url});if(!i)return void g.push(e);h=h.filter(function(a){return a.name!==i.name}),d(e,i)}if(f){var j=g.find(function(a){return a.url===f.name});if(!j)return void h.push(f);g=g.filter(function(a){return a.url!==j.url}),d(j,f)}}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")),_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"),ApiCollector=exports["default"]=/*#__PURE__*/function(){function a(){this.name="api-collector",this.entryTypes=["xmlhttprequest","fetch"],this.cachedEntries=[],this.cachedApiAttrs=[]}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;if(!1!==f.api){new PerformanceObserver(function(a){var d=a.getEntries().filter(function(a){return c.entryTypes.includes(a.initiatorType)});d&&d.length&&d.forEach(function(a){h(b,{entry:a})})}).observe({type:"resource",buffered:!0});var g=XMLHttpRequest.prototype;(0,_rumCore.interceptFunction)(g,"open",function(b,c){this.apiAttr={},this.apiAttr.url=c+"",this.apiAttr.method=b.toUpperCase(),this.apiAttr.view=(0,_view.getCurView)(a)}),(0,_rumCore.interceptFunction)(g,"send",function(){var a=this;this.addEventListener("loadend",function(){var c=a.status,d=a.statusText,e=a.response;a.apiAttr.status_code=c,a.apiAttr.message=d,h(b,{attr:a.apiAttr})})}),(0,_base.hackFunction)(global,"fetch",function(c){return function(d,e){var f,g={},i=new URL((0,_url.getCurrentURL)()),j=i.protocol,k=i.host;return g.url=(0,_url.completeURL)(d+"",j,k),g.method=(null===e||void 0===e||null===(f=e.method)||void 0===f?void 0:f.toUpperCase())||"GET",g.view=(0,_view.getCurView)(a),c.call(global,d,e).then(/*#__PURE__*/function(){var a=(0,_asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function b(a){var c,d,e;return _regenerator["default"].wrap(function(b){for(;;)switch(b.prev=b.next){case 0:return c=a.clone(),d=c.status,e=c.statusText,g.status_code=d,g.message=e,b.abrupt("return",a);case 5:case"end":return b.stop()}},b)}));return function(){return a.apply(this,arguments)}}(),function(a){throw g.message=a+"",a})["finally"](function(){h(b,{attr:g})})}});var h=function(a,b){try{var d=function(b,c){var d=b.method,e=b.url,f=b.status_code,g=b.message,h=b.view,i=(0,_performance.getResourceStatusByCode)(f);a((0,_extends2["default"])({event_type:_rumCore.RumEventType.RESOURCE,url:e,name:(0,_url.getPathByURL)(e),type:c.initiatorType||c.entryType,method:d,status_code:f,message:g,success:i},(0,_performance.calcResourceTimingData)(c),{view:h}))},e=b.attr,f=b.entry,g=c.cachedApiAttrs,h=c.cachedEntries;if(e){var i=h.find(function(a){return a.name===e.url});if(!i)return void g.push(e);h=h.filter(function(a){return a.name!==i.name}),d(e,i)}if(f){var j=g.find(function(a){return a.url===f.name});if(!j)return void h.push(f);g=g.filter(function(a){return a.url!==j.url}),d(j,f)}}catch(a){}}}},a}();// import { getUberTraceId } from "../../utils/trace";

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

"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");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 StaticResourceCollector=exports["default"]=/*#__PURE__*/function(){function a(){this.name="static-resource-collector",this.entryTypes=["audio","video","track","script","css","img","image","link","other"],this.cachedErrors=[],this.WAIT_FOR_ERROR_TIME=1e3}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;if(!1!==f.staticResource){document.addEventListener("error",function(a){c.cachedErrors.push(a)},!0),new PerformanceObserver(function(b){var d=b.getEntries().filter(function(a){return c.entryTypes.includes(a.initiatorType)});if(d&&d.length){var e=(0,_view.getCurView)(a);d.forEach(function(a){setTimeout(function(){g(a,e)},c.WAIT_FOR_ERROR_TIME)})}}).observe({type:"resource",buffered:!0});var g=function(a,d){// responseStatus 若为 0,则先设成 200
"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");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 StaticResourceCollector=exports["default"]=/*#__PURE__*/function(){function a(){this.name="static-resource-collector",this.entryTypes=["audio","video","track","script","css","img","image","link","other"],this.cachedErrors=[],this.WAIT_FOR_ERROR_TIME=1e3}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;if(!1!==f.staticResource){_global.document.addEventListener("error",function(a){c.cachedErrors.push(a)},!0),new PerformanceObserver(function(b){var d=b.getEntries().filter(function(a){return c.entryTypes.includes(a.initiatorType)});if(d&&d.length){var e=(0,_view.getCurView)(a);d.forEach(function(a){setTimeout(function(){g(a,e)},c.WAIT_FOR_ERROR_TIME)})}}).observe({type:"resource",buffered:!0});var g=function(a,d){// responseStatus 若为 0,则先设成 200
// @ts-ignore

@@ -3,0 +3,0 @@ for(var e,f=a.responseStatus||200,g=a.name,h=a.initiatorType||a.entryType,i=(0,_performance.getResourceStatusByCode)(f),j=(0,_extends2["default"])({event_type:_rumCore.RumEventType.RESOURCE,url:g,name:(0,_url.getPathByURL)(g),type:h,method:"GET",status_code:f,success:i},(0,_performance.calcResourceTimingData)(a),{// 异步任务,保证 view_id view_name 正确

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

"use strict";exports.__esModule=!0,exports["default"]=void 0;var _rumCore=require("@arms/rum-core"),_base=require("../../utils/base"),_url=require("../../utils/url"),PerfCollector=exports["default"]=/*#__PURE__*/function(){function a(){var a=this;this.name="perf-collector",this.ctx=void 0,this.sendEvent=void 0,this.sendPerf=function(){var b=performance.getEntriesByType("navigation")[0],c=b.loadEventEnd,d=b.domInteractive,e=b.domContentLoadedEventEnd,f=b.domComplete,g=performance.getEntriesByType("paint").find(function(a){var b=a.name;return"first-contentful-paint"===b})||{},h=g.startTime;a.sendEvent({event_type:_rumCore.RumEventType.VIEW,type:"perf",url:(0,_url.getCurrentURL)(),referrer:document.referrer||"",loading_type:"initial_load",timing_data:JSON.stringify(b),// Measure
loading_time:(0,_base.formatNumber)(c),first_contentful_paint:(0,_base.formatNumber)(h),dom_interactive:(0,_base.formatNumber)(d),dom_content_loaded:(0,_base.formatNumber)(e),dom_complete:(0,_base.formatNumber)(f)})}}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.perf||(this.ctx=a,this.sendEvent=b,window.addEventListener("load",this.sendPerf))},b.destroy=function destroy(){window.removeEventListener("load",this.sendPerf)},a}();
"use strict";exports.__esModule=!0,exports["default"]=void 0;var _rumCore=require("@arms/rum-core"),_base=require("../../utils/base"),_url=require("../../utils/url"),_global=require("../../utils/global"),PerfCollector=exports["default"]=/*#__PURE__*/function(){function a(){var a=this;this.name="perf-collector",this.ctx=void 0,this.sendEvent=void 0,this.sendPerf=function(){var b=performance.getEntriesByType("navigation")[0],c=b.loadEventEnd,d=b.domInteractive,e=b.domContentLoadedEventEnd,f=b.domComplete,g=performance.getEntriesByType("paint").find(function(a){var b=a.name;return"first-contentful-paint"===b})||{},h=g.startTime;a.sendEvent({event_type:_rumCore.RumEventType.VIEW,type:"perf",url:(0,_url.getCurrentURL)(),referrer:_global.document.referrer||"",loading_type:"initial_load",timing_data:JSON.stringify(b),// Measure
loading_time:(0,_base.formatNumber)(c),first_contentful_paint:(0,_base.formatNumber)(h),dom_interactive:(0,_base.formatNumber)(d),dom_content_loaded:(0,_base.formatNumber)(e),dom_complete:(0,_base.formatNumber)(f)})}}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.perf||(this.ctx=a,this.sendEvent=b,_global.global.addEventListener("load",this.sendPerf))},b.destroy=function destroy(){_global.global.removeEventListener("load",this.sendPerf)},a}();

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

"use strict";exports.__esModule=!0,exports["default"]=void 0;var _rumCore=require("@arms/rum-core"),_url=require("../../utils/url"),_uuid=require("../../utils/uuid"),supportsHistory=window&&!!window.history.pushState&&!!window.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,e===a.getViewName(f)||(a.ctx.addView({id:(0,_uuid.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=window.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.prevUrl=(0,_url.getCurrentURL)(),this.sendPv(this.prevUrl,document.referrer||"","initial_load");var c=this.getSpaMode();supportsHistory&&c&&((0,_rumCore.interceptFunction)(window.history,"pushState",this.historyFn),(0,_rumCore.interceptFunction)(window.history,"replaceState",this.historyFn),window.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&&window.removeEventListener("popstate",this.popstateFn)},a}();
"use strict";exports.__esModule=!0,exports["default"]=void 0;var _rumCore=require("@arms/rum-core"),_url=require("../../utils/url"),_uuid=require("../../utils/uuid"),_global=require("../../utils/global"),supportsHistory=_global.global&&!!_global.global.history.pushState&&!!_global.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&&"initial_load"!==d&&e===a.getViewName(f)||(a.ctx.addView({id:(0,_uuid.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.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.prevUrl=(0,_url.getCurrentURL)(),this.sendPv(this.prevUrl,_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,7 +0,7 @@

"use strict";exports.__esModule=!0,exports["default"]=void 0;var _rumCore=require("@arms/rum-core"),_base=require("../../utils/base"),_url=require("../../utils/url"),_view=require("../../utils/view"),_webVitals=require("web-vitals"),WebVitalsCollector=exports["default"]=/*#__PURE__*/function(){function a(){this.name="web-vitals-collector",this.ctx=void 0,this.sendEvent=void 0}var b=a.prototype;return b.setup=function setup(a,b){var c=a.getConfig(),d=c.collectors,e=void 0===d?{}:d;!1===e.webVitals||(this.ctx=a,this.sendEvent=b,this.sendWebvitals())},b.sendWebvitals=function sendWebvitals(){var a=this,b=(0,_view.getCurView)(this.ctx);(0,_webVitals.onLCP)(function(c){a.sendEvent({event_type:_rumCore.RumEventType.VIEW,type:"webvitals",url:(0,_url.getCurrentURL)(),referrer:document.referrer||"",loading_type:"initial_load",// Measure
"use strict";exports.__esModule=!0,exports["default"]=void 0;var _rumCore=require("@arms/rum-core"),_base=require("../../utils/base"),_url=require("../../utils/url"),_view=require("../../utils/view"),_webVitals=require("web-vitals"),_global=require("../../utils/global"),WebVitalsCollector=exports["default"]=/*#__PURE__*/function(){function a(){this.name="web-vitals-collector",this.ctx=void 0,this.sendEvent=void 0}var b=a.prototype;return b.setup=function setup(a,b){var c=a.getConfig(),d=c.collectors,e=void 0===d?{}:d;!1===e.webVitals||(this.ctx=a,this.sendEvent=b,this.sendWebvitals())},b.sendWebvitals=function sendWebvitals(){var a=this,b=(0,_view.getCurView)(this.ctx);(0,_webVitals.onLCP)(function(c){a.sendEvent({event_type:_rumCore.RumEventType.VIEW,type:"webvitals",url:(0,_url.getCurrentURL)(),referrer:_global.document.referrer||"",loading_type:"initial_load",// Measure
largest_contentful_paint:(0,_base.formatNumber)(c.value),// 保证 viewId 正确
view:b})}),(0,_webVitals.onFID)(function(c){a.sendEvent({event_type:_rumCore.RumEventType.VIEW,type:"webvitals",url:(0,_url.getCurrentURL)(),referrer:document.referrer||"",loading_type:"initial_load",// Measure
view:b})}),(0,_webVitals.onFID)(function(c){a.sendEvent({event_type:_rumCore.RumEventType.VIEW,type:"webvitals",url:(0,_url.getCurrentURL)(),referrer:_global.document.referrer||"",loading_type:"initial_load",// Measure
first_input_delay:(0,_base.formatNumber)(c.value),// 保证 viewId 正确
view:b})}),(0,_webVitals.onCLS)(function(c){a.sendEvent({event_type:_rumCore.RumEventType.VIEW,type:"webvitals",url:(0,_url.getCurrentURL)(),referrer:document.referrer||"",loading_type:"initial_load",// Measure
view:b})}),(0,_webVitals.onCLS)(function(c){a.sendEvent({event_type:_rumCore.RumEventType.VIEW,type:"webvitals",url:(0,_url.getCurrentURL)(),referrer:_global.document.referrer||"",loading_type:"initial_load",// Measure
cumulative_layout_shift:(0,_base.formatNumber)(c.value),// 保证 viewId 正确
view:b})})},a}();

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

"use strict";exports.__esModule=!0,exports["default"]=void 0;var _uuid=require("../utils/uuid"),_base=require("../utils/base"),SessionProcessor=exports["default"]=/*#__PURE__*/function(){function a(){this.name="session-processor",this.lastTime=(0,_base.getCurrentTime)(),this.sessionOvertime=1800000}var b=a.prototype;return b.process=function process(a){var b=(0,_base.getCurrentTime)();// 30 分钟内不上报更新session
return b-this.lastTime>this.sessionOvertime&&((0,_uuid.setSessionID)(),this.lastTime=b),a.getRumEvent()},a}();
"use strict";exports.__esModule=!0,exports["default"]=void 0;var _uuid=require("../utils/uuid"),_base=require("../utils/base"),SessionProcessor=exports["default"]=/*#__PURE__*/function(){function a(){this.name="session-processor",this.lastTime=(0,_base.getCurrentTime)(),this.sessionOvertime=3600000}var b=a.prototype;return b.process=function process(a){var b=(0,_base.getCurrentTime)();// 30 分钟内不上报更新session
return b-this.lastTime>this.sessionOvertime&&(0,_uuid.setSessionID)(),this.lastTime=b,a.getRumEvent()},a}();

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

"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=!0,exports["default"]=void 0;var _extends2=_interopRequireDefault(require("@babel/runtime/helpers/extends")),_inheritsLoose2=_interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose")),_rumCore=require("@arms/rum-core"),_uuid=require("../utils/uuid"),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;document.addEventListener("visibilitychange",function(){"hidden"===document.visibilityState&&a.flushEventQueue()})},c.request=function request(a,b,c){var d,e=a.getConfig(),f=e.pid,g=e.env,h=void 0===g?"prod":g,i=e.version,j=e.endpoint,k=e.beforeReport,l=e.user,m=void 0===l?{}:l,n={app:{id:f,env:h,version:i,type:_rumCore.AppType.broswer},user:(0,_extends2["default"])({id:(0,_uuid.getUserID)()},m),session:{id:(0,_uuid.getSessionID)()},view:c,net:{model:(null===(d=navigator.connection)||void 0===d?void 0:d.effectiveType)||""},events:b};if(!("function"==typeof k&&(n=k(n),!n)))try{navigator.sendBeacon(j,JSON.stringify(n))}catch(a){}},b}(_rumCore.Reporter),_default=exports["default"]=BrowserReporter;/**
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=!0,exports["default"]=void 0;var _extends2=_interopRequireDefault(require("@babel/runtime/helpers/extends")),_inheritsLoose2=_interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose")),_rumCore=require("@arms/rum-core"),_uuid=require("../utils/uuid"),_global=require("../utils/global"),BrowserReporter=/*#__PURE__*/function(a){function b(){for(var b,c=arguments.length,d=Array(c),e=0;e<c;e++)d[e]=arguments[e];return b=a.call.apply(a,[this].concat(d))||this,b.name="browser-reporter",b}(0,_inheritsLoose2["default"])(b,a);var c=b.prototype;return c.init=function init(){var a=this;_global.document.addEventListener("visibilitychange",function(){"hidden"===_global.document.visibilityState&&a.flushEventQueue()})},c.request=function request(a,b,c){var d,e=a.getConfig(),f=e.pid,g=e.env,h=void 0===g?"prod":g,i=e.version,j=e.endpoint,k=e.beforeReport,l=e.user,m=void 0===l?{}:l,n={app:{id:f,env:h,version:i,type:_rumCore.AppType.broswer},user:(0,_extends2["default"])({id:(0,_uuid.getUserID)()},m),session:{id:(0,_uuid.getSessionID)()},view:c,net:{model:(null===(d=navigator.connection)||void 0===d?void 0:d.effectiveType)||""},events:b};if(!("function"==typeof k&&(n=k(n),!n)))try{navigator.sendBeacon(j,JSON.stringify(n))}catch(a){}},b}(_rumCore.Reporter),_default=exports["default"]=BrowserReporter;/**
* browser reporter
*/

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

"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=!0,exports["default"]=exports.ArmsRum=void 0;var _extends3=_interopRequireDefault(require("@babel/runtime/helpers/extends")),_rumCore=require("@arms/rum-core"),_pv=_interopRequireDefault(require("./collector/view/pv")),_exception=_interopRequireDefault(require("./collector/exception")),_perf=_interopRequireDefault(require("./collector/view/perf")),_webvitals=_interopRequireDefault(require("./collector/view/webvitals")),_api=_interopRequireDefault(require("./collector/resource/api")),_staticResource=_interopRequireDefault(require("./collector/resource/static-resource")),_click=_interopRequireDefault(require("./collector/action/click")),_defaultProcessor=_interopRequireDefault(require("./processor/default-processor")),_sessionProcessor=_interopRequireDefault(require("./processor/session-processor")),_reporter=_interopRequireDefault(require("./reporter")),ArmsRum=exports.ArmsRum=/*#__PURE__*/function(){function a(){this.client=void 0;var a=window.__rum;a&&this.init(a)}var b=a.prototype;return b.init=function init(a){this.client=new _rumCore.Client,this.client.useCollectors([new _pv["default"],new _perf["default"],new _webvitals["default"],new _exception["default"],new _api["default"],new _staticResource["default"],new _click["default"]]),this.client.useProcessors([new _defaultProcessor["default"],new _sessionProcessor["default"]]),this.client.useReporter(new _reporter["default"]),this.client.init(a)},b.sendEvent=function sendEvent(a){this.client.sendEvent(a)},b.getConfig=function getConfig(){return this.client.getContext().getConfig()},b.setConfig=function setConfig(){var a=this.client.getContext();if(2===arguments.length){var b,c=this.client.getContext(),d=c.getConfig();c.setConfig((0,_extends3["default"])({},d,(b={},b[0>=arguments.length?void 0:arguments[0]]=1>=arguments.length?void 0:arguments[1],b)))}else a.setConfig(0>=arguments.length?void 0:arguments[0])},a}(),_default=exports["default"]=new ArmsRum;/**
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=!0,exports["default"]=exports.ArmsRum=void 0;var _extends3=_interopRequireDefault(require("@babel/runtime/helpers/extends")),_rumCore=require("@arms/rum-core"),_pv=_interopRequireDefault(require("./collector/view/pv")),_exception=_interopRequireDefault(require("./collector/exception")),_perf=_interopRequireDefault(require("./collector/view/perf")),_webvitals=_interopRequireDefault(require("./collector/view/webvitals")),_api=_interopRequireDefault(require("./collector/resource/api")),_staticResource=_interopRequireDefault(require("./collector/resource/static-resource")),_click=_interopRequireDefault(require("./collector/action/click")),_defaultProcessor=_interopRequireDefault(require("./processor/default-processor")),_sessionProcessor=_interopRequireDefault(require("./processor/session-processor")),_filterProcessor=_interopRequireDefault(require("./processor/filter-processor")),_reporter=_interopRequireDefault(require("./reporter")),_global=require("./utils/global"),ArmsRum=exports.ArmsRum=/*#__PURE__*/function(){function a(){this.client=void 0;var a=_global.global.__rum;a&&this.init(a)}var b=a.prototype;return b.init=function init(a){this.client=new _rumCore.Client,this.client.useCollectors([new _pv["default"],new _perf["default"],new _webvitals["default"],new _exception["default"],new _api["default"],new _staticResource["default"],new _click["default"]]),this.client.useProcessors([new _defaultProcessor["default"],new _sessionProcessor["default"],new _filterProcessor["default"]]),this.client.useReporter(new _reporter["default"]),this.client.init(a)},b.sendEvent=function sendEvent(a){this.client.sendEvent(a)},b.getConfig=function getConfig(){return this.client.getContext().getConfig()},b.setConfig=function setConfig(){var a=this.client.getContext();if(2===arguments.length){var b,c=this.client.getContext(),d=c.getConfig();c.setConfig((0,_extends3["default"])({},d,(b={},b[0>=arguments.length?void 0:arguments[0]]=1>=arguments.length?void 0:arguments[1],b)))}else a.setConfig(0>=arguments.length?void 0:arguments[0])},a}(),_default=exports["default"]=new ArmsRum;/**
* browser sdk
*/

@@ -17,1 +17,8 @@ /**

export declare function getCurrentTime(timeOffset?: number): number;
export declare function safetyCall(fn: Function, args: Array<any>, defaultValue: any): any;
type Rule = string | RegExp | Function;
/**
* @description: 根据过滤规则过滤page/api/error(指定规则的页面、API、错误不上报)
*/
export declare const ignoreByRules: (str: any, rules: Rule[]) => boolean;
export {};

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

"use strict";exports.__esModule=!0,exports.formatNumber=formatNumber,exports.getCurrentTime=getCurrentTime,exports.hackFunction=hackFunction;/**
"use strict";var _rumCore=require("@arms/rum-core");exports.__esModule=!0,exports.formatNumber=formatNumber,exports.getCurrentTime=getCurrentTime,exports.hackFunction=hackFunction,exports.ignoreByRules=void 0,exports.safetyCall=safetyCall;/**
* 劫持函数

@@ -11,2 +11,12 @@ */function hackFunction(a,b,c){if("object"==typeof a&&"function"==typeof a[b]){var d=a[b],e=c(d);a[b]=e}}/**

* @returns
*/function getCurrentTime(a){var b,c;return null!==(b=performance)&&void 0!==b&&b.timeOrigin&&null!==(c=performance)&&void 0!==c&&c.now?Math.round(performance.timeOrigin+(a?a:performance.now())):Date.now()}
*/function getCurrentTime(a){var b,c;return null!==(b=performance)&&void 0!==b&&b.timeOrigin&&null!==(c=performance)&&void 0!==c&&c.now?Math.round(performance.timeOrigin+(a?a:performance.now())):Date.now()}function safetyCall(a,b,c){if((0,_rumCore.isFunction)(a))return c;try{return a.apply(this,b)}catch(a){return c}}/**
* @description: 根据过滤规则过滤page/api/error(指定规则的页面、API、错误不上报)
*/var ignoreByRules=exports.ignoreByRules=function(a,b){if(!a||!(0,_rumCore.isArray)(b))return!1;// Combine an array of regular expressions and strings into one large regexp
for(var c,d=[],e=0,f=b.length;e<f;e++)if(c=b[e],(0,_rumCore.isString)(c))// If it's a string, we need to escape it
// Taken from: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
d.push(c.replace(/([.*+?^=!:${}()|\[\]\/\\])/g,"\\$1"));else if((0,_rumCore.isRegExp)(c))// If it's a regexp already, we want to extract the source
// @ts-ignore
d.push(c.source);else if((0,_rumCore.isFunction)(c)&&!0===safetyCall(c,[a],!1))// 如果命中, 直接返回true.
// 方法必须返回Boolean值, 严格等于true才算命中规则
// @ts-ignore
return!0;var g=new RegExp(d.join("|"),"i");return d.length&&!!g.test&&g.test(a)};

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

"use strict";exports.__esModule=!0,exports.getClosestTargetAncestorElement=getClosestTargetAncestorElement,exports.getElementXpath=getElementXpath;// 与DOM有关的工具函数
"use strict";var _global=require("./global");exports.__esModule=!0,exports.getClosestTargetAncestorElement=getClosestTargetAncestorElement,exports.getElementXpath=getElementXpath;// 与DOM有关的工具函数
/**

@@ -6,3 +6,3 @@ * 根据过滤条件获取元素及其父元素中最近的指定元素

* @param tagNames 过滤条件,HTML5元素的名称集合
*/function getClosestTargetAncestorElement(a,b){for(var c=a;c!==document.documentElement;){var d=c,e=d.localName,f=d.nodeName,g=d.parentElement;if(b.includes((e||f).toLocaleLowerCase()))return c;if(!g)break;c=g}return null}/**
*/function getClosestTargetAncestorElement(a,b){for(var c=a;c!==_global.document.documentElement;){var d=c,e=d.localName,f=d.nodeName,g=d.parentElement;if(b.includes((e||f).toLocaleLowerCase()))return c;if(!g)break;c=g}return null}/**
* 获取指定元素的xpath

@@ -9,0 +9,0 @@ * @param element

@@ -12,2 +12,6 @@ "use strict";exports.__esModule=!0,exports.completeURL=completeURL,exports.getCurrentURL=getCurrentURL,exports.getPathByURL=getPathByURL;/**

* @param host 主机名
*/function completeURL(a,b,c){var d=/^https?:\/\//i.test(a);if(d)return a;var e=/^\/\//i.test(a);if(e)return""+b+a;var f=/^\//i.test(a);return b+"//"+c+(f?"":"/")+a}
*/function completeURL(a,b,c){var d=/^https?:\/\//i.test(a);if(d)return a;var e=/^\/\//i.test(a);if(e)return""+b+a;var f=/^\//i.test(a);return b+"//"+c+(f?"":"/")+a}// export function get(url: string) {
// const urlObj = new URL(url);
// const params = new URLSearchParams(urlObj.search);
// return params;
// }

@@ -5,3 +5,3 @@ export declare function getUUID(prefix?: string): string;

*/
export declare function getSessionID(): string;
export declare function getSessionID(): any;
/**

@@ -14,4 +14,4 @@ * 设置唯一的sessionID

*/
export declare function getUserID(): string;
export declare function getUserID(): any;
export declare function getEventId(): string;
export declare function getViewId(): string;

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

"use strict";exports.__esModule=!0,exports.getEventId=getEventId,exports.getSessionID=getSessionID,exports.getUUID=getUUID,exports.getUserID=getUserID,exports.getViewId=getViewId,exports.setSessionID=setSessionID;var _rumCore=require("@arms/rum-core"),SESSION_ID="ARMS_SESSION_ID",USER_ID="ARMS_USER_ID",UID_BASE=Date.now();// 存储sessionID的键名
"use strict";exports.__esModule=!0,exports.getEventId=getEventId,exports.getSessionID=getSessionID,exports.getUUID=getUUID,exports.getUserID=getUserID,exports.getViewId=getViewId,exports.setSessionID=setSessionID;var _rumCore=require("@arms/rum-core"),_global=require("./global"),SESSION_ID="_arms_sid",SESSION_ID_EXP="_arms_sid_exp",USER_ID="_arms_uid",localStorage=_global.global.localStorage,UID_BASE=Date.now();// 存储sessionID的键名
// 存储sessionID的过期id
// 存储userID的键名

@@ -7,6 +8,6 @@ /**

* 获取唯一的sessionID
*/function getSessionID(){var a=sessionStorage.getItem(SESSION_ID);return a||(a=setSessionID()),a}/**
*/function getSessionID(){var a=localStorage.getItem(SESSION_ID),b=new Date(localStorage.getItem(SESSION_ID_EXP));return a&&b.valueOf()&&!(b<new Date)||(a=setSessionID()),a}/**
* 设置唯一的sessionID
*/function setSessionID(){var a=(0,_rumCore.generateGUID)();return sessionStorage.setItem(SESSION_ID,a),a}/**
*/function setSessionID(){var a=(0,_rumCore.generateGUID)();return localStorage.setItem(SESSION_ID,a),localStorage.setItem(SESSION_ID_EXP,new Date(Date.now()+86400000).toString()),a}/**
* 获取唯一的userID
*/function getUserID(){var a=localStorage.getItem(USER_ID);return a||(a=getUUID("user"),localStorage.setItem(USER_ID,a)),a}function getEventId(){return(0,_rumCore.generateGUID)()}function getViewId(){return(0,_rumCore.generateGUID)()}
{
"name": "@arms/rum-browser",
"version": "0.0.3",
"version": "0.0.4",
"description": "arms rum javascript sdk for browser",

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

"dependencies": {
"@arms/rum-core": "^0.0.3",
"@arms/rum-core": "^0.0.4",
"web-vitals": "^3.4.0"

@@ -28,0 +28,0 @@ },

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