@apmplus/integrations
Advanced tools
Comparing version 2.0.2 to 2.0.3
@@ -151,3 +151,7 @@ declare type ReportEventFromClient<C extends AnyClient> = C extends { | ||
getSubject: (key: string) => SafeObservable<any> | undefined; | ||
privateSubject: SubjectMap; | ||
}; | ||
declare type SubjectMap = { | ||
[key: string]: SafeObservable<any> | undefined; | ||
}; | ||
@@ -816,3 +820,2 @@ /** 公共筛选条件 */ | ||
declare const TTI_MONITOR_PLUGIN_NAME = "tti"; | ||
interface TTIMonitorPluginConfig { | ||
@@ -1068,3 +1071,3 @@ [TTI_MONITOR_PLUGIN_NAME]?: boolean | Record<string, unknown>; | ||
declare type WebClient = Client<BrowserReportEvent, any, any, any, any, any, BrowserConfig>; | ||
declare type WebClient = WithSubject<Client<BrowserReportEvent, any, any, any, any, any, BrowserConfig>>; | ||
declare const actionPlugin: (config?: ActionMonitorConfig | undefined) => { | ||
@@ -1071,0 +1074,0 @@ name: string; |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var __assign=function(){return(__assign=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function __read(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,o,i=r.call(t),a=[];try{for(;(void 0===e||0<e--)&&!(n=i.next()).done;)a.push(n.value)}catch(t){o={error:t}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return a}function __spreadArray(t,e,r){if(r||2===arguments.length)for(var n,o=0,i=e.length;o<i;o++)!n&&o in e||((n=n||Array.prototype.slice.call(e,0,o))[o]=e[o]);return t.concat(n||Array.prototype.slice.call(e))}var noop=function(){return{}};function isObject(t){return"object"==typeof t&&null!==t}var objProto=Object.prototype;function isArray(t){return"[object Array]"===objProto.toString.call(t)}function isFunction(t){return"function"==typeof t}function arrayIncludes(t,e){if(!isArray(t))return!1;if(0===t.length)return!1;for(var r=0;r<t.length;){if(t[r]===e)return!0;r++}return!1}var applyRecord=function(){var r={};return[r,function(t,e){return r[t]=e},function(t){return delete r[t]}]},hookMethodDangerously=function(i,a,u){return function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];if(!i)return noop;var r=i[a],n=u.apply(void 0,__spreadArray([r],__read(t),!1)),o=n;return isFunction(o)&&(o=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return n.apply(this,t)}),i[a]=o,function(){o===i[a]?i[a]=r:n=r}}};function mathRNG(){for(var t=new Array(16),e=0,r=0;r<16;r++)0==(3&r)&&(e=4294967296*Math.random()),t[r]=e>>>((3&r)<<3)&255;return t}function bytesToUuid(t){for(var e=[],r=0;r<256;++r)e[r]=(r+256).toString(16).substr(1);var n=0,o=e;return[o[t[n++]],o[t[n++]],o[t[n++]],o[t[n++]],"-",o[t[n++]],o[t[n++]],"-",o[t[n++]],o[t[n++]],"-",o[t[n++]],o[t[n++]],"-",o[t[n++]],o[t[n++]],o[t[n++]],o[t[n++]],o[t[+n]],o[t[15]]].join("")}function uuid(){var t=mathRNG();return t[6]=15&t[6]|64,t[8]=63&t[8]|128,bytesToUuid(t)}function getDefaultBrowser(){if("object"==typeof window&&isObject(window))return window}function getDefaultDocument(){if("object"==typeof document&&isObject(document))return document}function getDefaultPerformance(){if(getDefaultBrowser()&&isObject(window.performance))return window.performance}function getDefaultXMLHttpRequest(){if("function"==typeof XMLHttpRequest&&isFunction(XMLHttpRequest))return XMLHttpRequest}function getDefaultMutationObserver(){if(getDefaultBrowser()&&isFunction(window.MutationObserver))return window.MutationObserver}var getGlobalRegistry=function(t){if(t)return t.__SLARDAR_REGISTRY__||(t.__SLARDAR_REGISTRY__={Slardar:{plugins:[],errors:[],subject:{}}}),t.__SLARDAR_REGISTRY__.Slardar},reportSelfError=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var r=getGlobalRegistry(getDefaultBrowser());r&&(r.errors||(r.errors=[]),r.errors.push(t))},applyMutationObserver=function(t,e){var r=t&&new t(e);return[function(t,e){r&&t&&r.observe(t,e)},function(){return r&&r.disconnect()}]},applyPerformance=function(r){var t=r&&r.timing||void 0;return[t,function(){return r&&r.now?r.now():(Date.now?Date.now():+new Date)-(t&&t.navigationStart||0)},function(t){var e=(r||{}).getEntriesByType;return isFunction(e)&&e.call(r,t)||[]},function(){var t=(r||{}).clearResourceTimings;isFunction(t)&&t.call(r)},function(t){var e=(r||{}).getEntriesByName;return isFunction(e)&&e.call(r,t)||[]}]},applyMonitor=function(t,e,r,n){void 0===e&&(e={}),void 0===n&&(n=[]);try{var o=t.apply(void 0,__spreadArray([],__read(n),!1));return o&&o(e,r)||[]}catch(t){return reportSelfError(t),[]}},now=function(){return Date.now()},PAGE_ACTIVITY_DELAY=100,MAX_PAGE_ACTIVITY_DELAY=1e4,ROOT_TAGS=["BODY","HTML","HEAD"],hookXHRSend=function(r,o,i){var a=0;return function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=a+=2;return o(n,now()),hookMethodDangerously(this,"onreadystatechange",function(r){return function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return 4===this.readyState&&i(n),r&&r.apply(this,t)}})(),r.apply(this,t)}},hookFetch=function(o,i,a){var u=1;return function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var r=o.apply(void 0,__spreadArray([],__read(t),!1)),n=u+=2;i(n,now());return r.then(function(){a(n)},function(){a(n)}),r}},applyIncompleteReq=function(t,e){var r=__read(applyRecord(),3),n=r[0],o=r[1],r=r[2];return e&&hookMethodDangerously(e.prototype,"send",hookXHRSend)(o,r),t&&hookMethodDangerously(t,"fetch",hookFetch)(o,r),[n]},waitActionComplete=function(t,e,r){function n(){r.clearTimeout(o),o=r.setTimeout(function(){t()},PAGE_ACTIVITY_DELAY)}var o,i;return[function(){r.clearTimeout(i),i=r.setTimeout(function(){t(),e()},MAX_PAGE_ACTIVITY_DELAY),n()},n,function(){r.clearTimeout(o),r.clearTimeout(i)}]},getDomPath=function(t){var e=t,r=[];try{for(;null!==e.parentNode;){for(var n=0,o=0,i=0;i<e.parentNode.childNodes.length;i++){var a=e.parentNode.childNodes[i];a.nodeName===e.nodeName&&(a===e&&(o=n),n++)}e.hasAttribute("id")&&""!==e.id?r.unshift(e.nodeName+"#"+e.id):1<n?r.unshift(e.nodeName+":eq("+o+")"):r.unshift(e.nodeName),e=e.parentNode}return r.slice(1).join(">")}catch(t){return}},isSupportsElementClosest=function(){var t;return function(){return void 0===t?t="closest"in HTMLElement.prototype:t}}(),findElementWithAttributeByParents=function(t,e,r){void 0===r&&(r=10);for(var n=t,o=0;o<r&&n;o++){if(~ROOT_TAGS.indexOf(n.nodeName))return;if(n.hasAttribute(e))return n;n=n.parentElement}},getActionNameByAttribute=function(t,e){t=isSupportsElementClosest()?t.closest("["+e+"]"):findElementWithAttributeByParents(t,e);if(t)return t.getAttribute(e).trim()},getActionName=function(t,e){return getActionNameByAttribute(t,e)||t.innerText},ACTION_EV_TYPE="action",HTTP_EV_TYPE="http",LONGTASK_RV_TYPE="performance_longtask",JS_ERROR_EV_TYPE="js_error",RESOURCE_EV_TYPE="resource",RELATED_EV_TYPES=[LONGTASK_RV_TYPE,HTTP_EV_TYPE,JS_ERROR_EV_TYPE,RESOURCE_EV_TYPE],SUPPORT_TYPES=["click"],EVENT_LISTENER_OPTIONS={capture:!0},DEFAULT_ATTR_NAME="data-apm-action",ActionMonitor=function(m,g,A,h,R){if(void 0===m&&(m=getDefaultBrowser()),void 0===g&&(g=getDefaultDocument()),void 0===A&&(A=getDefaultXMLHttpRequest()),void 0===h&&(h=getDefaultMutationObserver()),void 0===R&&(R=getDefaultPerformance()),g&&m)return function(t,r){var e=t.types,n=t.pure,o=[],i=null,a=[],u=0,c=__read(applyPerformance(R),2)[1],f=__read(applyIncompleteReq(m,A),1)[0],s=function(){var t,e;i&&(n||Object.keys(i.metrics).length)&&!Object.keys(f).length&&(i.metrics[LONGTASK_RV_TYPE]&&(i.metrics[LONGTASK_RV_TYPE].duration=u),t=0<a.length?Math.max.apply(Math,__spreadArray([],__read(a),!1))-Math.min.apply(Math,__spreadArray([],__read(a),!1)):0,i.metrics[HTTP_EV_TYPE]&&(i.metrics[HTTP_EV_TYPE].duration=t),e=c()-i.start_time,r&&r({ev_type:ACTION_EV_TYPE,payload:__assign(__assign({},i),{duration:e,frontend_time:e-t})}),l())},l=function(){y(),i=null,a=[],u=0},_=__read(waitActionComplete(s,l,m),3),p=_[0],d=_[1],y=_[2],t=__read(applyMutationObserver(h,d),2),_=t[0],E=t[1];_();function T(t){var e;s(),l(),t.target instanceof HTMLElement&&((e=getActionName(t.target,DEFAULT_ATTR_NAME))&&(v({name:e,path:getDomPath(t.target)},t.type),p()))}var v=function(t,e){var r=uuid(),n=__read(applyPerformance(R),2)[1];i={start_time:n(),id:r,type:e,target:t,metrics:{}}};e&&e.forEach(function(t){arrayIncludes(SUPPORT_TYPES,t)&&(g.addEventListener(t,T,EVENT_LISTENER_OPTIONS),o.push(function(){return g.removeEventListener(t,T,EVENT_LISTENER_OPTIONS)}))});return[function(){o.forEach(function(t){return t()}),E()},function(t){if(i&&arrayIncludes(RELATED_EV_TYPES,t.ev_type)){if(d(),t.ev_type===HTTP_EV_TYPE){if(!t.payload.response.timing)return;var e=t.payload.response.timing,r=e.startTime,e=e.duration;if(r<i.start_time)return;a.push(r,r+e)}else if(t.ev_type===LONGTASK_RV_TYPE){if(!t.payload.longtasks.length||t.payload.longtasks[0].startTime<i.start_time)return;t.payload.longtasks.forEach(function(t){u+=t.duration})}else if(t.ev_type===RESOURCE_EV_TYPE&&t.payload.startTime<i.start_time)return;return i.metrics[t.ev_type]={count:(null!==(t=null===(t=i.metrics[t.ev_type])||void 0===t?void 0:t.count)&&void 0!==t?t:0)+1},i.id}},function(t,e){s(),l(),v({name:t},e),p()}]}},ACTION_MONITOR_PLUGIN_NAME="action",defaultConfig={types:["click"]};function ActionMonitorBasePlugin(t,e){function r(t){var e=o(t);return e&&t.extra&&(t.extra.action_id=e),t}var e=__read(applyMonitor(ActionMonitor,e=void 0===e?defaultConfig:e,t.report.bind(t)),3),n=e[0],o=e[1],e=e[2];t.on("report",r),t.provide("startAction",e),t.on("beforeDestroy",function(){n(),t.off("report",r)})}var actionPlugin=function(e){return{name:ACTION_MONITOR_PLUGIN_NAME,setup:function(t){ActionMonitorBasePlugin(t,e)}}};exports.actionPlugin=actionPlugin; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var __assign=function(){return(__assign=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function __read(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),a=[];try{for(;(void 0===e||0<e--)&&!(r=i.next()).done;)a.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a}function __spreadArray(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||((r=r||Array.prototype.slice.call(e,0,o))[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}var noop=function(){return{}};function isObject(t){return"object"==typeof t&&null!==t}var objProto=Object.prototype;function isArray(t){return"[object Array]"===objProto.toString.call(t)}function isFunction(t){return"function"==typeof t}function arrayIncludes(t,e){if(!isArray(t))return!1;if(0===t.length)return!1;for(var n=0;n<t.length;){if(t[n]===e)return!0;n++}return!1}var applyRecord=function(){var n={};return[n,function(t,e){return n[t]=e},function(t){return delete n[t]}]},hookMethodDangerously=function(i,a,u){return function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];if(!i)return noop;var n=i[a],r=u.apply(void 0,__spreadArray([n],__read(t),!1)),o=r;return isFunction(o)&&(o=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return r.apply(this,t)}),i[a]=o,function(){o===i[a]?i[a]=n:r=n}}};function mathRNG(){for(var t=new Array(16),e=0,n=0;n<16;n++)0==(3&n)&&(e=4294967296*Math.random()),t[n]=e>>>((3&n)<<3)&255;return t}function bytesToUuid(t){for(var e=[],n=0;n<256;++n)e[n]=(n+256).toString(16).substr(1);var r=0,o=e;return[o[t[r++]],o[t[r++]],o[t[r++]],o[t[r++]],"-",o[t[r++]],o[t[r++]],"-",o[t[r++]],o[t[r++]],"-",o[t[r++]],o[t[r++]],"-",o[t[r++]],o[t[r++]],o[t[r++]],o[t[r++]],o[t[+r]],o[t[15]]].join("")}function uuid(){var t=mathRNG();return t[6]=15&t[6]|64,t[8]=63&t[8]|128,bytesToUuid(t)}function initSubjectInGlobal(t,e){return t.initSubject(e)}function getDefaultBrowser(){if("object"==typeof window&&isObject(window))return window}function getDefaultDocument(){if("object"==typeof document&&isObject(document))return document}var applyMutationObserver=function(t,e){var n=t&&new t(e);return[function(t,e){n&&t&&n.observe(t,e)},function(){return n&&n.disconnect()}]},applyPerformance=function(n){var t=n&&n.timing||void 0;return[t,function(){return n&&n.now?n.now():(Date.now?Date.now():+new Date)-(t&&t.navigationStart||0)},function(t){var e=(n||{}).getEntriesByType;return isFunction(e)&&e.call(n,t)||[]},function(){var t=(n||{}).clearResourceTimings;isFunction(t)&&t.call(n)},function(t){var e=(n||{}).getEntriesByName;return isFunction(e)&&e.call(n,t)||[]}]},now=function(){return Date.now()},XHR_SUBJECT_NAME="xhr_0",hookOpen=function(r){return function(){for(var t,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return t=__read(e,2),this._method=t[0],this._url=t[1],r.apply(this,e)}},hookSetHeader=function(o){return function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this._reqHeaders=this._reqHeaders||{};var n=__read(t,2),r=n[0],n=n[1];return this._reqHeaders[r]=n,o&&o.apply(this,t)}},hookOnreadystatechange=function(r,o){return hookMethodDangerously(r,"onreadystatechange",function(n){return function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return 4===this.readyState&&o(r),n&&n.apply(this,t)}})},hookSend=function(r,o){return function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this._start=now(),this._data=null==t?void 0:t[0];var n=o([this._method,this._url,this._start,this]);return hookOnreadystatechange(this,n)(),r.apply(this,t)}},applyXHR=function(r){return function(t,e){var n;r&&((n=[]).push(hookMethodDangerously(r,"open",hookOpen)()),n.push(hookMethodDangerously(r,"setRequestHeader",hookSetHeader)()),n.push(hookMethodDangerously(r,"send",hookSend)(t)),e(function(){n.forEach(function(t){return t()})}))}},FETCH_SUBJECT_NAME="fetch_0",hookFetch=function(r,o){return function(t,e){var n=o([t,e=void 0===e?{}:e]),e=r(t,e);return e.then(function(t){n(t)},function(){n(void 0)}),e}},observeFetch=function(t,e){var n,r=getDefaultBrowser();r&&fetch&&((n=[]).push(hookMethodDangerously(r,"fetch",hookFetch)(t)),e(function(){n.forEach(function(t){return t()})}))},fetchSubject=[FETCH_SUBJECT_NAME,observeFetch],PAGE_ACTIVITY_DELAY=100,MAX_PAGE_ACTIVITY_DELAY=1e4,ROOT_TAGS=["BODY","HTML","HEAD"],waitActionComplete=function(t,e,n){function r(){n.clearTimeout(o),a&&(o=n.setTimeout(function(){t()},PAGE_ACTIVITY_DELAY))}var o,i,a=!1;return[function(){a=!0,n.clearTimeout(i),i=n.setTimeout(function(){t(),e()},MAX_PAGE_ACTIVITY_DELAY),r()},r,function(){a=!1,n.clearTimeout(o),n.clearTimeout(i)}]},getDomPath=function(t){var e=t,n=[];try{for(;null!==e.parentNode;){for(var r=0,o=0,i=0;i<e.parentNode.childNodes.length;i++){var a=e.parentNode.childNodes[i];a.nodeName===e.nodeName&&(a===e&&(o=r),r++)}e.hasAttribute("id")&&""!==e.id?n.unshift(e.nodeName+"#"+e.id):1<r?n.unshift(e.nodeName+":eq("+o+")"):n.unshift(e.nodeName),e=e.parentNode}return n.slice(1).join(">")}catch(t){return}},isSupportsElementClosest=function(){var t;return function(){return void 0===t?t="closest"in HTMLElement.prototype:t}}(),findElementWithAttributeByParents=function(t,e,n){void 0===n&&(n=10);for(var r=t,o=0;o<n&&r;o++){if(~ROOT_TAGS.indexOf(r.nodeName))return;if(r.hasAttribute(e))return r;r=r.parentElement}},getActionNameByAttribute=function(t,e){t=isSupportsElementClosest()?t.closest("["+e+"]"):findElementWithAttributeByParents(t,e);if(t)return t.getAttribute(e).trim()},getActionName=function(t,e){return getActionNameByAttribute(t,e)||t.innerText},ACTION_EV_TYPE="action",HTTP_EV_TYPE="http",LONGTASK_RV_TYPE="performance_longtask",JS_ERROR_EV_TYPE="js_error",RESOURCE_EV_TYPE="resource",RELATED_EV_TYPES=[LONGTASK_RV_TYPE,HTTP_EV_TYPE,JS_ERROR_EV_TYPE,RESOURCE_EV_TYPE],SUPPORT_TYPES=["click"],EVENT_LISTENER_OPTIONS={capture:!0},DEFAULT_ATTR_NAME="data-apm-action",applyIncompleteReq=function(t,e,n){var r=__read(e,2),o=r[0],i=r[1],e=__read(applyRecord(),3),r=e[0],a=e[1],u=e[2],c=0;return t.push(o[0](function(t){__read(t,1)[0];var e=c+=1;return a(e,now()),n(),function(){u(e),n()}})),t.push(i[0](function(){var t=c+=1;return a(t,now()),n(),function(){u(t),n()}})),r},actionGetterWithFetchObserver=function(n,e,t,r){function o(){var t,e;s&&(c||Object.keys(s.metrics).length)&&!Object.keys(E).length&&(s.metrics[LONGTASK_RV_TYPE]&&(s.metrics[LONGTASK_RV_TYPE].duration=_),t=0<f.length?Math.max.apply(Math,__spreadArray([],__read(f),!1))-Math.min.apply(Math,__spreadArray([],__read(f),!1)):0,s.metrics[HTTP_EV_TYPE]&&(s.metrics[HTTP_EV_TYPE].duration=t),e=l()-s.start_time,n({ev_type:ACTION_EV_TYPE,payload:__assign(__assign({},s),{duration:e,frontend_time:e-t})}),i())}function i(){h(),s=null,f=[],_=0}var a=__read(t,2),u=a[0],t=a[1],a=r.types,c=r.pure,s=null,f=[],_=0,l=__read(applyPerformance(performance),2)[1],r=__read(waitActionComplete(o,i,window),3),p=r[0],d=r[1],h=r[2],E=applyIncompleteReq(e,[u,t],d),u=__read(applyMutationObserver(MutationObserver,d),2),t=u[0],u=u[1];t(),e.push(u);function T(t,e){var n=uuid(),r=__read(applyPerformance(performance),2)[1];s={start_time:r(),id:n,type:e,target:t,metrics:{}},p()}function y(t){var e;o(),i(),t.target instanceof HTMLElement&&((e=getActionName(t.target,DEFAULT_ATTR_NAME))&&T({name:e,path:getDomPath(t.target)},t.type))}a&&a.forEach(function(t){arrayIncludes(SUPPORT_TYPES,t)&&(document.addEventListener(t,y,EVENT_LISTENER_OPTIONS),e.push(function(){return document.removeEventListener(t,y,EVENT_LISTENER_OPTIONS)}))});return[function(t){if(s&&arrayIncludes(RELATED_EV_TYPES,t.ev_type)){if(d(),t.ev_type===HTTP_EV_TYPE){if(!t.payload.response.timing)return;var e=t.payload.response.timing,n=e.startTime,e=e.duration;if(n<s.start_time)return;f.push(n,n+e)}else if(t.ev_type===LONGTASK_RV_TYPE){if(!t.payload.longtasks.length||t.payload.longtasks[0].startTime<s.start_time)return;t.payload.longtasks.forEach(function(t){_+=t.duration})}else if(t.ev_type===RESOURCE_EV_TYPE&&t.payload.startTime<s.start_time)return;return s.metrics[t.ev_type]={count:(null!==(t=null===(t=s.metrics[t.ev_type])||void 0===t?void 0:t.count)&&void 0!==t?t:0)+1},s.id}},function(t,e){o(),i(),T({name:t},e)}]},ACTION_MONITOR_PLUGIN_NAME="action",defaultConfig={types:["click"]};function ActionMonitorBasePlugin(t,e){void 0===e&&(e=defaultConfig);var n,r,o=[],i=getDefaultDocument(),a=getDefaultBrowser();i&&a&&(e=__read(actionGetterWithFetchObserver(t.report.bind(t),o,[initSubjectInGlobal(t,[XHR_SUBJECT_NAME,applyXHR(XMLHttpRequest&&XMLHttpRequest.prototype)]),initSubjectInGlobal(t,fetchSubject)],e),2),n=e[0],e=e[1],t.on("report",r=function(t){var e=n(t);return e&&t.extra&&(t.extra.action_id=e),t}),t.provide("startAction",e),t.on("beforeDestroy",function(){o.forEach(function(t){return t()}),t.off("report",r)}))}var actionPlugin=function(e){return{name:ACTION_MONITOR_PLUGIN_NAME,setup:function(t){ActionMonitorBasePlugin(t,e)}}};exports.actionPlugin=actionPlugin; |
@@ -151,3 +151,7 @@ declare type ReportEventFromClient<C extends AnyClient> = C extends { | ||
getSubject: (key: string) => SafeObservable<any> | undefined; | ||
privateSubject: SubjectMap; | ||
}; | ||
declare type SubjectMap = { | ||
[key: string]: SafeObservable<any> | undefined; | ||
}; | ||
@@ -816,3 +820,2 @@ /** 公共筛选条件 */ | ||
declare const TTI_MONITOR_PLUGIN_NAME = "tti"; | ||
interface TTIMonitorPluginConfig { | ||
@@ -819,0 +822,0 @@ [TTI_MONITOR_PLUGIN_NAME]?: boolean | Record<string, unknown>; |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var __assign=function(){return(__assign=Object.assign||function(e){for(var n,r=1,t=arguments.length;r<t;r++)for(var o in n=arguments[r])Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o]);return e}).apply(this,arguments)};function __read(e,n){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var t,o,i=r.call(e),a=[];try{for(;(void 0===n||0<n--)&&!(t=i.next()).done;)a.push(t.value)}catch(e){o={error:e}}finally{try{t&&!t.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return a}function __spreadArray(e,n,r){if(r||2===arguments.length)for(var t,o=0,i=n.length;o<i;o++)!t&&o in n||((t=t||Array.prototype.slice.call(n,0,o))[o]=n[o]);return e.concat(t||Array.prototype.slice.call(n))}function isObject(e){return"object"==typeof e&&null!==e}function isFunction(e){return"function"==typeof e}function getDefaultBrowser(){if("object"==typeof window&&isObject(window))return window}function getDefaultDocument(){if("object"==typeof document&&isObject(document))return document}function getDefaultPerformance(){if(getDefaultBrowser()&&isObject(window.performance))return window.performance}function getDefaultPromise(){if(getDefaultBrowser()&&"Promise"in window)return Promise}function getDefaultMutationObserver(){if(getDefaultBrowser()&&isFunction(window.MutationObserver))return window.MutationObserver}function getDefaultPerformanceObserver(){if(getDefaultBrowser()&&isFunction(window.PerformanceObserver))return window.PerformanceObserver}var getGlobalRegistry=function(e){if(e)return e.__SLARDAR_REGISTRY__||(e.__SLARDAR_REGISTRY__={Slardar:{plugins:[],errors:[],subject:{}}}),e.__SLARDAR_REGISTRY__.Slardar},reportSelfError=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var r=getGlobalRegistry(getDefaultBrowser());r&&(r.errors||(r.errors=[]),r.errors.push(e))},applyMutationObserver=function(e,n){var r=e&&new e(n);return[function(e,n){r&&e&&r.observe(e,n)},function(){return r&&r.disconnect()}]},applyPerformance=function(r){var e=r&&r.timing||void 0;return[e,function(){return r&&r.now?r.now():(Date.now?Date.now():+new Date)-(e&&e.navigationStart||0)},function(e){var n=(r||{}).getEntriesByType;return isFunction(n)&&n.call(r,e)||[]},function(){var e=(r||{}).clearResourceTimings;isFunction(e)&&e.call(r)},function(e){var n=(r||{}).getEntriesByName;return isFunction(n)&&n.call(r,e)||[]}]},applyPerformanceObserver=function(r,o,n,i){var t=r&&new r(function(e,t){e.getEntries?e.getEntries().forEach(function(e,n,r){return o(e,n,r,t)}):i&&i(),n&&t.disconnect()});return[function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];if(!r||!t)return i&&i();try{n.forEach(function(e){-1<r.supportedEntryTypes.indexOf(e)&&t.observe({type:e,buffered:!1})})}catch(e){try{t.observe({entryTypes:n})}catch(e){return i&&i()}}},function(){return t&&t.disconnect()}]},applyMonitor=function(e,n,r,t){void 0===n&&(n={}),void 0===t&&(t=[]);try{var o=e.apply(void 0,__spreadArray([],__read(t),!1));return o&&o(n,r)||[]}catch(e){return reportSelfError(e),[]}},applyRequestIdleCallback=function(n){return n.requestIdleCallback||function(e){return n.setTimeout(e,1)}},now=function(){return Date.now()};function onDOMContentLoaded(e){var n=getDefaultBrowser(),r=getDefaultDocument();n&&r&&("loading"!==r.readyState?e():n.addEventListener("DOMContentLoaded",function(){setTimeout(function(){e()},0)},!1))}var invokeCallbackOnce=function(n){var r=!1;return[function(e){r||(r=!0,n&&n(e))}]},onPageUnload=function(e){var n=__read(invokeCallbackOnce(e),1)[0];["unload","beforeunload","pagehide"].forEach(function(e){addEventListener(e,n)})},getConfig=function(e,n){return isObject(e)?__assign(__assign({},n),e):!!e&&n};function getPluginConfig(e,n,r){n=null===(e=e.config())||void 0===e?void 0:e.plugins[n];return getConfig(n,r)}var DEFAULT_IGNORE_TAGS=["SCRIPT","STYLE","META","HEAD"],ERROR_RELATED_TYPE=["js_error","http","resource_error"],DEFAULT_THRESHOLD=1.5,MAX_RENDER_TIME=1e4,MAX_CHECK_TIME=8e3,DEFAULT_CHECK_TIME=2e3,MAX_RELATED_TIME=1e4,DEFAULT_T0_DATA_URL_QUALITY=.1,CHECK_EXCLUSIVE_EV_TYPES=["performance","performance_longtask","performance_timing","custom"],isSkipBeforeCheck=function(e){return~CHECK_EXCLUSIVE_EV_TYPES.indexOf(e.ev_type)},blankErrorCompare=function(e,n){if(-1===ERROR_RELATED_TYPE.indexOf(n.ev_type))return e;if("http"===n.ev_type&&n.payload.response.status<400)return e;if(e&&ERROR_RELATED_TYPE.indexOf(e.type)<ERROR_RELATED_TYPE.indexOf(n.ev_type))return e;var r="";switch(n.ev_type){case"js_error":r=n.payload.error.message;break;case"http":r=n.payload.request.url;break;case"resource_error":r=n.payload.url}return{type:n.ev_type,message:r,timestamp:now()}},measure=function(r,t,e,o,i){if(void 0===t&&(t=0),void 0===e&&(e=0),void 0===o&&(o=DEFAULT_THRESHOLD),void 0===i&&(i=DEFAULT_IGNORE_TAGS),!r||-1<i.indexOf(r.tagName)||o<=e||4<t)return e;var n=function(){if(!t)return 0;var e=r.getBoundingClientRect(),n=e.top,e=e.height;return n>innerHeight||e<=0?0:1/Math.pow(2,t-1)}();return[].reduceRight.call(r.children,function(e,n){return measure(n,t+1,e,o,i)},e+n)},screenshot=function(e){var n=e.cb,r=e.screenshotUrl,t=e.window,o=e.document,i=e.mask,a=e.partialShot,u=e.quality,c=e.rootSelector;if(getDefaultPromise()&&t&&o){if(t.html2canvas)return l();e=o.createElement("script");e.src=r,null!==(r=o.head)&&void 0!==r&&r.appendChild(e),e.onload=l}function l(){applyRequestIdleCallback(t)(function(){t.html2canvas&&t.html2canvas(a&&c&&o.querySelector(c)||o.body,{scale:360/t.innerWidth,mask:i}).then(function(e){n(e.toDataURL("image/jpeg",u))})})}},BlankScreenMonitor=function(O,L,C,M,P){if(void 0===O&&(O=getDefaultBrowser()),void 0===L&&(L=getDefaultDocument()),void 0===C&&(C=getDefaultPerformanceObserver()),void 0===M&&(M=getDefaultMutationObserver()),void 0===P&&(P=getDefaultPerformance()),L&&O)return function(e,n){var r,t,o,i,a,u,c=e.threshold,l=e.screenshot,f=e.rootSelector,s=e.autoDetect,_=e.ssUrl,d=e.quality,p=e.mask,E=e.partialShot,v=applyRequestIdleCallback(O),g=__read(applyPerformance(P),2)[1],m=0,y=!1,D=function(e){r&&n&&n({ev_type:"blank_screen",payload:{timestamp:r[0],score:r[1],screenshot:e,error:t}})},T=(i=function(){r&&!y&&(y=!0,R(),l?screenshot({cb:D,screenshotUrl:_,window:O,document:L,mask:p,partialShot:E,quality:d,rootSelector:f}):D())},function(){a||(u=now(),a=O.setTimeout(function(){a=0,u<m||i()},g()>MAX_RENDER_TIME?DEFAULT_CHECK_TIME:MAX_CHECK_TIME))});onPageUnload(function(){!y&&t&&D()});function b(){o&&clearTimeout(o),o=O.setTimeout(function(){v(function(){O.requestAnimationFrame(function(){var e=f?L.querySelector(f):L.body;e&&((e=measure(e,0,0,c))<c?(r=[now(),e],T()):r=void 0)})})},1e3)}var R=function(){clearTimeout(o),w&&w(),A&&A()},e=__read(applyMutationObserver(M,b),2),h=e[0],w=e[1],e=__read(applyPerformanceObserver(C,function(e,n,r){return o&&1<r.length&&b()}),2),S=e[0],A=e[1];return s&&onDOMContentLoaded(function(){var e;h(null===(e=getDefaultDocument())||void 0===e?void 0:e.body,{subtree:!0,childList:!0}),S("longtask","resource"),b()}),[R,function(e){y||isSkipBeforeCheck(e)||(m=now(),t&&m-t.timestamp>MAX_RELATED_TIME&&(t=void 0),t=blankErrorCompare(t,e))},b]}},BLANK_SCREEN_MONITOR_PLUGIN_NAME="blankScreen";function BlankScreenMonitorBasePlugin(o,i,a){o.on("init",function(){var e,n,r,t=getPluginConfig(o,BLANK_SCREEN_MONITOR_PLUGIN_NAME,i)||getConfig(a,i);t&&(t=__read(applyMonitor(BlankScreenMonitor,t,o.report.bind(o)),3),e=t[0],n=t[1],t=t[2],o.on("report",r=function(e){return n(e),e}),o.on("beforeDestroy",function(){e(),o.off("report",r)}),o.provide("detectBlankScreen",t))})}var defaultVolConfig={autoDetect:!0,threshold:DEFAULT_THRESHOLD,screenshot:!0,ssUrl:"https://apm.volccdn.com/mars-web/apmplus/web/html2canvas.min.js",mask:!1,partialShot:!1,quality:DEFAULT_T0_DATA_URL_QUALITY};function BlankScreenMonitorVolPlugin(e,n){BlankScreenMonitorBasePlugin(e,defaultVolConfig,n)}var blankScreenPlugin=function(n){return{name:BLANK_SCREEN_MONITOR_PLUGIN_NAME,setup:function(e){BlankScreenMonitorVolPlugin(e,n)}}};exports.blankScreenPlugin=blankScreenPlugin; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var __assign=function(){return(__assign=Object.assign||function(e){for(var n,r=1,t=arguments.length;r<t;r++)for(var o in n=arguments[r])Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o]);return e}).apply(this,arguments)};function __read(e,n){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var t,o,i=r.call(e),a=[];try{for(;(void 0===n||0<n--)&&!(t=i.next()).done;)a.push(t.value)}catch(e){o={error:e}}finally{try{t&&!t.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return a}function __spreadArray(e,n,r){if(r||2===arguments.length)for(var t,o=0,i=n.length;o<i;o++)!t&&o in n||((t=t||Array.prototype.slice.call(n,0,o))[o]=n[o]);return e.concat(t||Array.prototype.slice.call(n))}function isObject(e){return"object"==typeof e&&null!==e}function isFunction(e){return"function"==typeof e}function getDefaultBrowser(){if("object"==typeof window&&isObject(window))return window}function getDefaultDocument(){if("object"==typeof document&&isObject(document))return document}function getDefaultPerformance(){if(getDefaultBrowser()&&isObject(window.performance))return window.performance}function getDefaultPromise(){if(getDefaultBrowser()&&"Promise"in window)return Promise}function getDefaultMutationObserver(){if(getDefaultBrowser()&&isFunction(window.MutationObserver))return window.MutationObserver}function getDefaultPerformanceObserver(){if(getDefaultBrowser()&&isFunction(window.PerformanceObserver))return window.PerformanceObserver}var getGlobalRegistry=function(e){if(e)return e.__SLARDAR_REGISTRY__||(e.__SLARDAR_REGISTRY__={Slardar:{plugins:[],errors:[],subject:{}}}),e.__SLARDAR_REGISTRY__.Slardar},reportSelfError=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var r=getGlobalRegistry(getDefaultBrowser());r&&(r.errors||(r.errors=[]),r.errors.push(e))},applyMutationObserver=function(e,n){var r=e&&new e(n);return[function(e,n){r&&e&&r.observe(e,n)},function(){return r&&r.disconnect()}]},applyPerformance=function(r){var e=r&&r.timing||void 0;return[e,function(){return r&&r.now?r.now():(Date.now?Date.now():+new Date)-(e&&e.navigationStart||0)},function(e){var n=(r||{}).getEntriesByType;return isFunction(n)&&n.call(r,e)||[]},function(){var e=(r||{}).clearResourceTimings;isFunction(e)&&e.call(r)},function(e){var n=(r||{}).getEntriesByName;return isFunction(n)&&n.call(r,e)||[]}]},applyPerformanceObserver=function(r,o,n,i){var t=r&&new r(function(e,t){e.getEntries?e.getEntries().forEach(function(e,n,r){return o(e,n,r,t)}):i&&i(),n&&t.disconnect()});return[function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];if(!r||!t)return i&&i();try{n.forEach(function(e){-1<r.supportedEntryTypes.indexOf(e)&&t.observe({type:e,buffered:!1})})}catch(e){try{t.observe({entryTypes:n})}catch(e){return i&&i()}}},function(){return t&&t.disconnect()}]},applyMonitor=function(e,n,r,t){void 0===n&&(n={}),void 0===t&&(t=[]);try{var o=e.apply(void 0,__spreadArray([],__read(t),!1));return o&&o(n,r)||[]}catch(e){return reportSelfError(e),[]}},applyRequestIdleCallback=function(n){return n.requestIdleCallback||function(e){return n.setTimeout(e,1)}},now=function(){return Date.now()};function onDOMContentLoaded(e){var n=getDefaultBrowser(),r=getDefaultDocument();n&&r&&("loading"!==r.readyState?e():n.addEventListener("DOMContentLoaded",function(){setTimeout(function(){e()},0)},!1))}var invokeCallbackOnce=function(n){var r=!1;return[function(e){r||(r=!0,n&&n(e))}]},onPageUnload=function(e){var n,r=getDefaultBrowser();r&&(n=__read(invokeCallbackOnce(e),1)[0],["unload","beforeunload","pagehide"].forEach(function(e){r.addEventListener(e,n)}))},getConfig=function(e,n){return isObject(e)?__assign(__assign({},n),e):!!e&&n};function getPluginConfig(e,n,r){n=null===(e=e.config())||void 0===e?void 0:e.plugins[n];return getConfig(n,r)}var DEFAULT_IGNORE_TAGS=["SCRIPT","STYLE","META","HEAD"],ERROR_RELATED_TYPE=["js_error","http","resource_error"],DEFAULT_THRESHOLD=1.5,MAX_RENDER_TIME=1e4,MAX_CHECK_TIME=8e3,DEFAULT_CHECK_TIME=2e3,MAX_RELATED_TIME=1e4,DEFAULT_T0_DATA_URL_QUALITY=.1,CHECK_EXCLUSIVE_EV_TYPES=["performance","performance_longtask","performance_timing","custom"],isSkipBeforeCheck=function(e){return~CHECK_EXCLUSIVE_EV_TYPES.indexOf(e.ev_type)},blankErrorCompare=function(e,n){if(-1===ERROR_RELATED_TYPE.indexOf(n.ev_type))return e;if("http"===n.ev_type&&n.payload.response.status<400)return e;if(e&&ERROR_RELATED_TYPE.indexOf(e.type)<ERROR_RELATED_TYPE.indexOf(n.ev_type))return e;var r="";switch(n.ev_type){case"js_error":r=n.payload.error.message;break;case"http":r=n.payload.request.url;break;case"resource_error":r=n.payload.url}return{type:n.ev_type,message:r,timestamp:now()}},measure=function(r,t,e,o,i){if(void 0===t&&(t=0),void 0===e&&(e=0),void 0===o&&(o=DEFAULT_THRESHOLD),void 0===i&&(i=DEFAULT_IGNORE_TAGS),!r||-1<i.indexOf(r.tagName)||o<=e||4<t)return e;var n=function(){if(!t)return 0;var e=r.getBoundingClientRect(),n=e.top,e=e.height;return n>innerHeight||e<=0?0:1/Math.pow(2,t-1)}();return[].reduceRight.call(r.children,function(e,n){return measure(n,t+1,e,o,i)},e+n)},screenshot=function(e){var n=e.cb,r=e.screenshotUrl,t=e.window,o=e.document,i=e.mask,a=e.partialShot,u=e.quality,c=e.rootSelector;if(getDefaultPromise()&&t&&o){if(t.html2canvas)return l();e=o.createElement("script");e.src=r,null!==(r=o.head)&&void 0!==r&&r.appendChild(e),e.onload=l}function l(){applyRequestIdleCallback(t)(function(){t.html2canvas&&t.html2canvas(a&&c&&o.querySelector(c)||o.body,{scale:360/t.innerWidth,mask:i}).then(function(e){n(e.toDataURL("image/jpeg",u))})})}},BlankScreenMonitor=function(O,L,C,M,P){if(void 0===O&&(O=getDefaultBrowser()),void 0===L&&(L=getDefaultDocument()),void 0===C&&(C=getDefaultPerformanceObserver()),void 0===M&&(M=getDefaultMutationObserver()),void 0===P&&(P=getDefaultPerformance()),L&&O)return function(e,n){var r,t,o,i,a,u,c=e.threshold,l=e.screenshot,f=e.rootSelector,s=e.autoDetect,_=e.ssUrl,d=e.quality,p=e.mask,E=e.partialShot,v=applyRequestIdleCallback(O),g=__read(applyPerformance(P),2)[1],m=0,y=!1,D=function(e){r&&n&&n({ev_type:"blank_screen",payload:{timestamp:r[0],score:r[1],screenshot:e,error:t}})},T=(i=function(){r&&!y&&(y=!0,R(),l?screenshot({cb:D,screenshotUrl:_,window:O,document:L,mask:p,partialShot:E,quality:d,rootSelector:f}):D())},function(){a||(u=now(),a=O.setTimeout(function(){a=0,u<m||i()},g()>MAX_RENDER_TIME?DEFAULT_CHECK_TIME:MAX_CHECK_TIME))});onPageUnload(function(){!y&&t&&D()});function b(){o&&clearTimeout(o),o=O.setTimeout(function(){v(function(){O.requestAnimationFrame(function(){var e=f?L.querySelector(f):L.body;e&&((e=measure(e,0,0,c))<c?(r=[now(),e],T()):r=void 0)})})},1e3)}var R=function(){clearTimeout(o),w&&w(),A&&A()},e=__read(applyMutationObserver(M,b),2),h=e[0],w=e[1],e=__read(applyPerformanceObserver(C,function(e,n,r){return o&&1<r.length&&b()}),2),S=e[0],A=e[1];return s&&onDOMContentLoaded(function(){var e;h(null===(e=getDefaultDocument())||void 0===e?void 0:e.body,{subtree:!0,childList:!0}),S("longtask","resource"),b()}),[R,function(e){y||isSkipBeforeCheck(e)||(m=now(),t&&m-t.timestamp>MAX_RELATED_TIME&&(t=void 0),t=blankErrorCompare(t,e))},b]}},BLANK_SCREEN_MONITOR_PLUGIN_NAME="blankScreen";function BlankScreenMonitorBasePlugin(o,i,a){o.on("init",function(){var e,n,r,t=getPluginConfig(o,BLANK_SCREEN_MONITOR_PLUGIN_NAME,i)||getConfig(a,i);t&&(t=__read(applyMonitor(BlankScreenMonitor,t,o.report.bind(o)),3),e=t[0],n=t[1],t=t[2],o.on("report",r=function(e){return n(e),e}),o.on("beforeDestroy",function(){e(),o.off("report",r)}),o.provide("detectBlankScreen",t))})}var defaultVolConfig={autoDetect:!0,threshold:DEFAULT_THRESHOLD,screenshot:!0,ssUrl:"https://apm.volccdn.com/mars-web/apmplus/web/html2canvas.min.js",mask:!1,partialShot:!1,quality:DEFAULT_T0_DATA_URL_QUALITY};function BlankScreenMonitorVolPlugin(e,n){BlankScreenMonitorBasePlugin(e,defaultVolConfig,n)}var blankScreenPlugin=function(n){return{name:BLANK_SCREEN_MONITOR_PLUGIN_NAME,setup:function(e){BlankScreenMonitorVolPlugin(e,n)}}};exports.blankScreenPlugin=blankScreenPlugin; |
@@ -151,3 +151,7 @@ declare type ReportEventFromClient<C extends AnyClient> = C extends { | ||
getSubject: (key: string) => SafeObservable<any> | undefined; | ||
privateSubject: SubjectMap; | ||
}; | ||
declare type SubjectMap = { | ||
[key: string]: SafeObservable<any> | undefined; | ||
}; | ||
@@ -816,3 +820,2 @@ /** 公共筛选条件 */ | ||
declare const TTI_MONITOR_PLUGIN_NAME = "tti"; | ||
interface TTIMonitorPluginConfig { | ||
@@ -819,0 +822,0 @@ [TTI_MONITOR_PLUGIN_NAME]?: boolean | Record<string, unknown>; |
@@ -151,3 +151,7 @@ declare type ReportEventFromClient<C extends AnyClient> = C extends { | ||
getSubject: (key: string) => SafeObservable<any> | undefined; | ||
privateSubject: SubjectMap; | ||
}; | ||
declare type SubjectMap = { | ||
[key: string]: SafeObservable<any> | undefined; | ||
}; | ||
@@ -816,3 +820,2 @@ /** 公共筛选条件 */ | ||
declare const TTI_MONITOR_PLUGIN_NAME = "tti"; | ||
interface TTIMonitorPluginConfig { | ||
@@ -819,0 +822,0 @@ [TTI_MONITOR_PLUGIN_NAME]?: boolean | Record<string, unknown>; |
@@ -151,3 +151,7 @@ declare type ReportEventFromClient<C extends AnyClient> = C extends { | ||
getSubject: (key: string) => SafeObservable<any> | undefined; | ||
privateSubject: SubjectMap; | ||
}; | ||
declare type SubjectMap = { | ||
[key: string]: SafeObservable<any> | undefined; | ||
}; | ||
@@ -816,3 +820,2 @@ /** 公共筛选条件 */ | ||
declare const TTI_MONITOR_PLUGIN_NAME = "tti"; | ||
interface TTIMonitorPluginConfig { | ||
@@ -819,0 +822,0 @@ [TTI_MONITOR_PLUGIN_NAME]?: boolean | Record<string, unknown>; |
@@ -151,3 +151,7 @@ declare type ReportEventFromClient<C extends AnyClient> = C extends { | ||
getSubject: (key: string) => SafeObservable<any> | undefined; | ||
privateSubject: SubjectMap; | ||
}; | ||
declare type SubjectMap = { | ||
[key: string]: SafeObservable<any> | undefined; | ||
}; | ||
@@ -655,3 +659,3 @@ /** 公共筛选条件 */ | ||
declare type WebClient$2 = Client<WebReportEvent, any, any, any, any, any, WebConfig>; | ||
declare type WebClient$3 = Client<WebReportEvent, any, any, any, any, any, WebConfig>; | ||
@@ -694,3 +698,3 @@ declare type Cb = (ev: HttpReport) => void; | ||
declare const BREADCRUMB_MONITOR_PLUGIN_NAME = "breadcrumb"; | ||
declare type WithBreadcrumb<C extends WebClient$2> = C & { | ||
declare type WithBreadcrumb<C extends WebClient$3> = C & { | ||
getBreadcrumbs?: GetBreadcrumbs; | ||
@@ -719,3 +723,3 @@ addBreadcrumb?: AddBreadcrumb; | ||
declare const JS_ERROR_MONITOR_PLUGIN_NAME = "jsError"; | ||
declare type WithCaptureException<C extends WebClient$2> = C & { | ||
declare type WithCaptureException<C extends WebClient$3> = C & { | ||
captureException?: ReportJsError; | ||
@@ -743,3 +747,3 @@ }; | ||
declare const PAGEVIEW_MONITOR_PLUGIN_NAME = "pageview"; | ||
declare type WithSendPageview<C extends WithSubject<WebClient$2>> = C & { | ||
declare type WithSendPageview<C extends WithSubject<WebClient$3>> = C & { | ||
sendPageview?: SendPageview; | ||
@@ -779,3 +783,3 @@ }; | ||
declare const RESOURCE_ERROR_MONITOR_PLUGIN_NAME = "resourceError"; | ||
declare type WithReportResourceError<C extends WebClient$2> = C & { | ||
declare type WithReportResourceError<C extends WebClient$3> = C & { | ||
reportResourceError?: ReportResourceError; | ||
@@ -811,3 +815,3 @@ }; | ||
declare type CustomPerformancePayload = Partial<Omit<PerformancePayload, 'name' | 'value'>> & Pick<PerformancePayload, 'name' | 'value'>; | ||
declare type WithSendPerformance<C extends WebClient$2> = C & { | ||
declare type WithSendPerformance<C extends WebClient$3> = C & { | ||
sendCustomPerfMetric?: (metric: CustomPerformancePayload) => void; | ||
@@ -822,3 +826,2 @@ performanceInit?: PerformanceInit; | ||
declare const TTI_MONITOR_PLUGIN_NAME = "tti"; | ||
interface TTIMonitorPluginConfig { | ||
@@ -855,3 +858,3 @@ [TTI_MONITOR_PLUGIN_NAME]?: boolean | Record<string, unknown>; | ||
declare const BLANK_SCREEN_MONITOR_PLUGIN_NAME = "blankScreen"; | ||
declare type WithDetectBlankScreen<C extends WebClient$2> = C & { | ||
declare type WithDetectBlankScreen<C extends WebClient$3> = C & { | ||
detectBlankScreen?: DetectBlankScreen; | ||
@@ -1090,14 +1093,20 @@ }; | ||
declare type WebClient$1 = Client<BrowserReportEvent, any, any, any, any, any, BrowserConfig>; | ||
declare type WebClient$2 = Client<BrowserReportEvent, any, any, any, any, any, BrowserConfig>; | ||
declare const jsErrorPlugin: () => { | ||
name: string; | ||
setup: (client: WebClient$1) => void; | ||
setup: (client: WebClient$2) => void; | ||
}; | ||
declare type WebClient = Client<BrowserReportEvent, any, any, any, any, any, BrowserConfig>; | ||
declare type WebClient$1 = WithSubject<Client<BrowserReportEvent, any, any, any, any, any, BrowserConfig>>; | ||
declare const actionPlugin: (config?: ActionMonitorConfig | undefined) => { | ||
name: string; | ||
setup: (client: WebClient$1) => void; | ||
}; | ||
declare type WebClient = WithSubject<Client<BrowserReportEvent, any, any, any, any, any, BrowserConfig>>; | ||
declare const SPALoadPlugin: () => { | ||
name: string; | ||
setup: (client: WebClient) => void; | ||
}; | ||
export { actionPlugin, captureConsole, jsErrorPlugin, refreshPreStartContext }; | ||
export { SPALoadPlugin, actionPlugin, captureConsole, jsErrorPlugin, refreshPreStartContext }; |
@@ -151,2 +151,14 @@ /*! ***************************************************************************** | ||
} | ||
var arrayRemove = function (arr, e) { | ||
if (!isArray(arr)) { | ||
return arr; | ||
} | ||
var i = arr.indexOf(e); | ||
if (i >= 0) { | ||
var arr_ = arr.slice(); | ||
arr_.splice(i, 1); | ||
return arr_; | ||
} | ||
return arr; | ||
}; | ||
var applyRecord = function () { | ||
@@ -359,2 +371,107 @@ var record = {}; | ||
var BUFFER_TIME = 300000; // 5分钟 | ||
var applyBufferTimer = function (checkIfNeedCancel, cb, bufferTime) { | ||
var tid = 0; | ||
if (bufferTime === -1) | ||
return noop; | ||
return function () { | ||
if (checkIfNeedCancel()) { | ||
tid && clearTimeout(tid); | ||
tid = 0; | ||
return; | ||
} | ||
tid === 0 && (tid = setTimeout(cb, bufferTime)); | ||
}; | ||
}; | ||
/* eslint-disable @typescript-eslint/no-invalid-void-type */ | ||
var nextLink = function (args, cb) { | ||
var nextCbs = []; | ||
try { | ||
nextCbs = cb.reduce(function (sum, s) { | ||
try { | ||
var nextCb = s(args); | ||
typeof nextCb === 'function' && sum.push(nextCb); | ||
} | ||
catch (_a) { | ||
// do nothing | ||
} | ||
return sum; | ||
}, []); | ||
} | ||
catch (_a) { | ||
// do nothing | ||
} | ||
return function (nextArgs) { return nextLink(nextArgs, nextCbs); }; | ||
}; | ||
var toObservable = function (bufferTime) { | ||
if (bufferTime === void 0) { bufferTime = BUFFER_TIME; } | ||
var subscribers = []; | ||
var __complete = []; | ||
var closed = false; | ||
var attachCb; | ||
// 暂缓的自动销毁机制,比如5min 没有人订阅就自动销毁 | ||
var setCloseIfNeed = applyBufferTimer(function () { return !!subscribers.length; }, function () { | ||
closed = true; | ||
attachCb && attachCb[0](); | ||
__complete.forEach(function (e) { return e(); }); | ||
__complete.length = 0; | ||
attachCb = undefined; | ||
}, bufferTime); | ||
var unsubscribe = function (o) { | ||
subscribers = arrayRemove(subscribers, o); | ||
!closed && setCloseIfNeed(); | ||
}; | ||
return { | ||
next: function (args) { | ||
return nextLink(args, subscribers); | ||
}, | ||
complete: function (cb) { | ||
__complete.push(cb); | ||
}, | ||
attach: function (disconnect, onSubscribe) { | ||
attachCb = [disconnect, onSubscribe]; | ||
}, | ||
subscribe: function (o) { | ||
if (closed) | ||
throw new Error('Observer is closed'); | ||
subscribers.push(o); | ||
attachCb && attachCb[1] && attachCb[1](o); | ||
setCloseIfNeed(); | ||
return function () { return unsubscribe(o); }; | ||
}, | ||
unsubscribe: unsubscribe, | ||
}; | ||
}; | ||
var createSafeObserver = function (observer, completeCb, bufferTime) { | ||
var cur = toObservable(bufferTime); | ||
try { | ||
observer(cur.next, cur.attach); | ||
completeCb && cur.complete(completeCb); | ||
} | ||
catch (_a) { | ||
// | ||
} | ||
return [cur.subscribe, cur.unsubscribe]; | ||
}; | ||
/** | ||
* 由于 Observer 带有自动销毁机制,意味着subject 只支持同步注册并使用 | ||
*/ | ||
function initSubjectInGlobal(client, args) { | ||
return client.initSubject(args); | ||
} | ||
/** | ||
* 此方法不会挂载到全局对象上,同时只支持同步注册并使用 | ||
*/ | ||
function initPrivateSubject(client, _a, bufferTime) { | ||
var _b = __read(_a, 2), subjectKey = _b[0], observer = _b[1]; | ||
var subjectMap = client.privateSubject || {}; | ||
if (!subjectMap[subjectKey]) | ||
subjectMap[subjectKey] = createSafeObserver(observer, function () { | ||
subjectMap[subjectKey] = undefined; | ||
}, bufferTime); | ||
return subjectMap[subjectKey]; | ||
} | ||
function getDefaultBrowser() { | ||
@@ -368,5 +485,4 @@ if (typeof window === 'object' && isObject(window)) | ||
} | ||
function getDefaultPerformance() { | ||
if (getDefaultBrowser() && isObject(window.performance)) | ||
return window.performance; | ||
function getDefaultLocation() { | ||
return getDefaultBrowser() && window.location; | ||
} | ||
@@ -381,2 +497,6 @@ function getDefaultXMLHttpRequest() { | ||
} | ||
function getDefaultPerformanceObserver() { | ||
if (getDefaultBrowser() && isFunction(window.PerformanceObserver)) | ||
return window.PerformanceObserver; | ||
} | ||
@@ -461,2 +581,7 @@ // 获取全局注册表 | ||
function getLocationUrl() { | ||
var location = getDefaultBrowser() && getDefaultLocation(); | ||
return location === null || location === void 0 ? void 0 : location.href; | ||
} | ||
var getConfig = function (c, defaultConfig) { | ||
@@ -471,2 +596,151 @@ if (isObject(c)) { | ||
var XHR_SUBJECT_NAME = 'xhr_0'; | ||
var hookOpen = function (open) { | ||
return function () { | ||
var _a; | ||
var openOptions = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
openOptions[_i] = arguments[_i]; | ||
} | ||
_a = __read(openOptions, 2), this._method = _a[0], this._url = _a[1]; | ||
return open.apply(this, openOptions); | ||
}; | ||
}; | ||
var hookSetHeader = function (setRequestHeader) { | ||
return function () { | ||
var setOptions = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
setOptions[_i] = arguments[_i]; | ||
} | ||
this._reqHeaders = this._reqHeaders || {}; | ||
var _a = __read(setOptions, 2), name = _a[0], value = _a[1]; | ||
this._reqHeaders[name] = value; | ||
return setRequestHeader && setRequestHeader.apply(this, setOptions); | ||
}; | ||
}; | ||
var hookOnreadystatechange = function (xhr, endNext) { | ||
return hookMethodDangerously(xhr, 'onreadystatechange', function (origin) { | ||
return function () { | ||
var ev = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
ev[_i] = arguments[_i]; | ||
} | ||
// @ts-expect-error | ||
this.readyState === 4 && endNext(xhr); | ||
return origin && origin.apply(this, ev); | ||
}; | ||
}); | ||
}; | ||
var hookSend = function (send, next) { | ||
return function () { | ||
var sendOptions = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
sendOptions[_i] = arguments[_i]; | ||
} | ||
this._start = now(); | ||
this._data = sendOptions === null || sendOptions === void 0 ? void 0 : sendOptions[0]; | ||
var endNext = next([this._method, this._url, this._start, this]); | ||
hookOnreadystatechange(this, endNext)(); | ||
return send.apply(this, sendOptions); | ||
}; | ||
}; | ||
var applyXHR = function (xhr) { | ||
return function (next, tearDown) { | ||
if (!xhr) | ||
return; | ||
var tearDownGroup = []; | ||
tearDownGroup.push(hookMethodDangerously(xhr, 'open', hookOpen)()); | ||
tearDownGroup.push(hookMethodDangerously(xhr, 'setRequestHeader', hookSetHeader)()); | ||
tearDownGroup.push(hookMethodDangerously(xhr, 'send', hookSend)(next)); | ||
tearDown(function () { | ||
tearDownGroup.forEach(function (e) { return e(); }); | ||
}); | ||
}; | ||
}; | ||
var FETCH_SUBJECT_NAME = 'fetch_0'; | ||
var hookFetch = function (_fetch, next) { | ||
return function (req, options) { | ||
if (options === void 0) { options = {}; } | ||
var endNext = next([req, options]); | ||
var fetchPromise = _fetch(req, options); | ||
fetchPromise.then(function (res) { | ||
// @ts-expect-error | ||
endNext(res); | ||
}, function () { | ||
// @ts-expect-error | ||
endNext(undefined); | ||
}); | ||
return fetchPromise; | ||
}; | ||
}; | ||
var observeFetch = function (next, tearDown) { | ||
var global = getDefaultBrowser(); | ||
if (!global || !fetch) | ||
return; | ||
var tearDownGroup = []; | ||
tearDownGroup.push(hookMethodDangerously(global, 'fetch', hookFetch)(next)); | ||
tearDown(function () { | ||
tearDownGroup.forEach(function (e) { return e(); }); | ||
}); | ||
}; | ||
var fetchSubject = [FETCH_SUBJECT_NAME, observeFetch]; | ||
var RESOURCE_TYPE = ['resource']; // used by resourceMonitor / resourceErrorMonitor / HttpMonitor | ||
var LONGTASK_TYPE = ['longtask']; // used by ttiMonitor / longtaskMonitor / actionMonitor / mpfidMonitor | ||
var applyPerformanceObserver = function (PerformanceObserver, callback, onFail) { | ||
var observer = PerformanceObserver && | ||
new PerformanceObserver(function (list, ob) { | ||
if (list.getEntries) { | ||
list.getEntries().forEach(function (val, i, arr) { return callback(val, i, arr, ob); }); | ||
} | ||
else { | ||
onFail && onFail(); | ||
} | ||
}); | ||
var observe = function (types) { | ||
if (!PerformanceObserver || !observer) | ||
return onFail && onFail(); | ||
try { | ||
observer.observe({ entryTypes: types }); | ||
} | ||
catch (_a) { | ||
return onFail && onFail(); | ||
} | ||
}; | ||
var bufferedObserver = function (type) { | ||
if (!PerformanceObserver || !observer) | ||
return onFail && onFail(); | ||
try { | ||
observer.observe({ type: type, buffered: true }); | ||
} | ||
catch (_a) { | ||
return onFail && onFail(); | ||
} | ||
observer.observe({ type: type, buffered: false }); | ||
}; | ||
var disconnect = function () { return observer && observer.disconnect(); }; | ||
return [observe, bufferedObserver, disconnect]; | ||
}; | ||
var observePerf = function (Ob, pipe, types) { | ||
var _a = __read(applyPerformanceObserver(Ob, pipe), 3), observe = _a[0], disconnect = _a[2]; | ||
observe(types); | ||
return disconnect; | ||
}; | ||
var LONGTASK_SUBJECT_NAME = 'longtask_0'; | ||
var observeLongtask = function (next, tearDown) { | ||
var PerformanceObserver = getDefaultPerformanceObserver(); | ||
if (!PerformanceObserver) | ||
return; | ||
tearDown(observePerf(PerformanceObserver, next, LONGTASK_TYPE)); | ||
}; | ||
var longtaskSubject = [LONGTASK_SUBJECT_NAME, observeLongtask]; | ||
var RESOURCE_SUBJECT_NAME = 'resource_0'; | ||
var observeResource = function (next, tearDown) { | ||
var PerformanceObserver = getDefaultPerformanceObserver(); | ||
if (!PerformanceObserver) | ||
return; | ||
tearDown(observePerf(PerformanceObserver, next, RESOURCE_TYPE)); | ||
}; | ||
var resourceSubject = [RESOURCE_SUBJECT_NAME, observeResource]; | ||
function getPluginConfig(client, pluginName, defaultConfig) { | ||
@@ -776,66 +1050,60 @@ var _a; | ||
var PAGE_ACTIVITY_DELAY = 100; | ||
var MAX_PAGE_ACTIVITY_DELAY = 10000; | ||
var ROOT_TAGS = ['BODY', 'HTML', 'HEAD']; | ||
// TODO pengli 可以先独立hook, 然后再设计一个插件通信机制 | ||
/** | ||
* 劫持 XHR.send 方法,回调 uniqId 为偶数 | ||
*/ | ||
var hookXHRSend = function (send, before, after) { | ||
var uniqId = 0; | ||
return function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
var requestId = (uniqId += 2); | ||
before(requestId, now()); | ||
hookMethodDangerously(this, 'onreadystatechange', function (origin) { | ||
return function () { | ||
var ev = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
ev[_i] = arguments[_i]; | ||
} | ||
this.readyState === 4 && after(requestId); | ||
return origin && origin.apply(this, ev); | ||
}; | ||
})(); | ||
return send.apply(this, args); | ||
var getOverrides = function (config) { | ||
return { | ||
pid: config.pid, | ||
view_id: config.viewId, | ||
url: getLocationUrl(), | ||
}; | ||
}; | ||
var PV_SUBJECT_NAME = 'view_0'; | ||
/** | ||
* 劫持 fetch,回调 uniqId 为奇数 | ||
* 由于跟当前实例强相关 所以不能挂在global上 | ||
*/ | ||
var hookFetch = function (_fetch, before, after) { | ||
var uniqId = 1; | ||
return function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
var fetchPromise = _fetch.apply(void 0, __spreadArray([], __read(args), false)); | ||
var requestId = (uniqId += 2); | ||
before(requestId, now()); | ||
var onResolve = function () { | ||
after(requestId); | ||
var applyPV = function (client) { | ||
return function (next, tearDown) { | ||
var currentOverrides = getOverrides(client.config()); | ||
var handleConfig = function (newConfig) { | ||
var _a; | ||
if (newConfig.viewId && newConfig.viewId !== ((_a = client.config()) === null || _a === void 0 ? void 0 : _a.viewId)) { | ||
next(currentOverrides); | ||
currentOverrides = getOverrides(newConfig); | ||
} | ||
}; | ||
var onReject = function () { | ||
after(requestId); | ||
}; | ||
fetchPromise.then(onResolve, onReject); | ||
return fetchPromise; | ||
client.on('beforeConfig', handleConfig); | ||
tearDown(function () { | ||
client.off('beforeConfig', handleConfig); | ||
}); | ||
}; | ||
}; | ||
/** | ||
* 劫持 XHR 和 fetch,监听当前页面未完成的 请求数量 | ||
*/ | ||
var applyIncompleteReq = function (global, XMLHttpRequest) { | ||
var _a = __read(applyRecord(), 3), incompleteReq = _a[0], before = _a[1], after = _a[2]; | ||
XMLHttpRequest && hookMethodDangerously(XMLHttpRequest.prototype, 'send', hookXHRSend)(before, after); | ||
global && hookMethodDangerously(global, 'fetch', hookFetch)(before, after); | ||
return [incompleteReq]; | ||
var defaultMetricContext = { | ||
isSupport: true, | ||
isPolyfill: false, | ||
isBounced: false, | ||
isCustom: false, | ||
type: 'perf', | ||
}; | ||
var initMetric = function (name, value) { | ||
return __assign({ name: name, value: value }, defaultMetricContext); | ||
}; | ||
var SINGLE_METRIC_EV_TYPE = 'performance'; | ||
var wrapPerformanceMetric = function (metric, overrides) { return ({ | ||
ev_type: SINGLE_METRIC_EV_TYPE, | ||
payload: metric, | ||
overrides: overrides, | ||
}); }; | ||
var applyReportMetric = function (report) { | ||
return function (metric, overrides) { | ||
report(wrapPerformanceMetric(metric, overrides)); | ||
}; | ||
}; | ||
var SPA_LOAD_METRIC_NAME = 'spa_load'; | ||
var PAGE_ACTIVITY_DELAY = 100; | ||
var MAX_PAGE_ACTIVITY_DELAY = 10000; | ||
var ROOT_TAGS = ['BODY', 'HTML', 'HEAD']; | ||
/** | ||
* 控制等待策略和强制结算 | ||
* 结算策略: 没有进行中的请求, 没有dom变更, 没有resource or longtask | ||
* 结算策略: 没有进行中的请求, 没有dom变更, 没有resource or longTask | ||
*/ | ||
@@ -845,9 +1113,12 @@ var waitActionComplete = function (cb, forceClear, win) { | ||
var maxIdleTimer; | ||
var started = false; | ||
var notify = function () { | ||
win.clearTimeout(idleTimer); | ||
idleTimer = win.setTimeout(function () { | ||
cb(); | ||
}, PAGE_ACTIVITY_DELAY); | ||
started && | ||
(idleTimer = win.setTimeout(function () { | ||
cb(); | ||
}, PAGE_ACTIVITY_DELAY)); | ||
}; | ||
var start = function () { | ||
started = true; | ||
win.clearTimeout(maxIdleTimer); | ||
@@ -861,2 +1132,3 @@ maxIdleTimer = win.setTimeout(function () { | ||
var complete = function () { | ||
started = false; | ||
win.clearTimeout(idleTimer); | ||
@@ -952,137 +1224,149 @@ win.clearTimeout(maxIdleTimer); | ||
var DEFAULT_ATTR_NAME = 'data-apm-action'; | ||
var ActionMonitor = function (win, document, xhr, MutationObserver, performance) { | ||
if (win === void 0) { win = getDefaultBrowser(); } | ||
if (document === void 0) { document = getDefaultDocument(); } | ||
if (xhr === void 0) { xhr = getDefaultXMLHttpRequest(); } | ||
if (MutationObserver === void 0) { MutationObserver = getDefaultMutationObserver(); } | ||
if (performance === void 0) { performance = getDefaultPerformance(); } | ||
if (!document || !win) { | ||
return; | ||
} | ||
return function (_a, cb) { | ||
var types = _a.types, pure = _a.pure; | ||
var restoreFns = []; | ||
var currentPayload = null; | ||
var requestStartAndEnd = []; | ||
var longtaskDuration = 0; | ||
var _b = __read(applyPerformance(performance), 2), now = _b[1]; | ||
var _c = __read(applyIncompleteReq(win, xhr), 1), incompleteReq = _c[0]; | ||
// 结算 | ||
var reportActionIfAllowed = function () { | ||
// 不存在action上下文 || 未收集到相关payload || 依然有进行中的请求 | ||
if (!currentPayload || | ||
(!pure && !Object.keys(currentPayload.metrics).length) || | ||
Object.keys(incompleteReq).length) { | ||
return; | ||
} | ||
// longtask duration | ||
currentPayload.metrics[LONGTASK_RV_TYPE] && | ||
(currentPayload.metrics[LONGTASK_RV_TYPE].duration = longtaskDuration); | ||
// request duration | ||
var requestDuration = requestStartAndEnd.length > 0 ? Math.max.apply(Math, __spreadArray([], __read(requestStartAndEnd), false)) - Math.min.apply(Math, __spreadArray([], __read(requestStartAndEnd), false)) : 0; | ||
currentPayload.metrics[HTTP_EV_TYPE] && (currentPayload.metrics[HTTP_EV_TYPE].duration = requestDuration); | ||
// end time | ||
var actionDuration = now() - currentPayload.start_time; | ||
cb && | ||
cb({ | ||
ev_type: ACTION_EV_TYPE, | ||
payload: __assign(__assign({}, currentPayload), { duration: actionDuration, frontend_time: actionDuration - requestDuration }), | ||
}); | ||
// 上报后重置数据 | ||
resetAction(); | ||
/** | ||
* 劫持 XHR 和 fetch,监听当前页面未完成的 请求数量 | ||
*/ | ||
var applyIncompleteReq = function (tearDownGroup, _a, notify) { | ||
var _b = __read(_a, 2), xhrObserver = _b[0], fetchObserver = _b[1]; | ||
var _c = __read(applyRecord(), 3), incompleteReq = _c[0], before = _c[1], after = _c[2]; | ||
var uniqId = 0; | ||
tearDownGroup.push(xhrObserver[0](function (_a) { | ||
var _b = __read(_a, 1); _b[0]; | ||
var requestId = (uniqId += 1); | ||
before(requestId, now()); | ||
notify(); | ||
return function () { | ||
after(requestId); | ||
notify(); | ||
}; | ||
var resetAction = function () { | ||
complete(); | ||
currentPayload = null; | ||
requestStartAndEnd = []; | ||
longtaskDuration = 0; | ||
})); | ||
tearDownGroup.push(fetchObserver[0](function () { | ||
var requestId = (uniqId += 1); | ||
before(requestId, now()); | ||
notify(); | ||
return function () { | ||
after(requestId); | ||
notify(); | ||
}; | ||
var _d = __read(waitActionComplete(reportActionIfAllowed, resetAction, win), 3), start = _d[0], notify = _d[1], complete = _d[2]; | ||
var _e = __read(applyMutationObserver(MutationObserver, notify), 2), observe = _e[0], disconnect = _e[1]; | ||
observe(); | ||
// 补充数据 | ||
var applyOtherReport = function (ev) { | ||
var _a, _b; | ||
if (!currentPayload) { | ||
})); | ||
return incompleteReq; | ||
}; | ||
var actionGetterWithFetchObserver = function (report, tearDownGroup, _a, config) { | ||
var _b = __read(_a, 2), xhrObserver = _b[0], fetchObserver = _b[1]; | ||
var types = config.types, pure = config.pure; | ||
var currentPayload = null; | ||
var requestStartAndEnd = []; | ||
var longtaskDuration = 0; | ||
var _c = __read(applyPerformance(performance), 2), now = _c[1]; | ||
// 结算 | ||
var reportActionIfAllowed = function () { | ||
// 不存在action上下文 || 未收集到相关payload || 依然有进行中的请求 | ||
if (!currentPayload || | ||
(!pure && !Object.keys(currentPayload.metrics).length) || | ||
Object.keys(incompleteReq).length) { | ||
return; | ||
} | ||
// longtask duration | ||
currentPayload.metrics[LONGTASK_RV_TYPE] && (currentPayload.metrics[LONGTASK_RV_TYPE].duration = longtaskDuration); | ||
// request duration | ||
var requestDuration = requestStartAndEnd.length > 0 ? Math.max.apply(Math, __spreadArray([], __read(requestStartAndEnd), false)) - Math.min.apply(Math, __spreadArray([], __read(requestStartAndEnd), false)) : 0; | ||
currentPayload.metrics[HTTP_EV_TYPE] && (currentPayload.metrics[HTTP_EV_TYPE].duration = requestDuration); | ||
// end time | ||
var actionDuration = now() - currentPayload.start_time; | ||
report({ | ||
ev_type: ACTION_EV_TYPE, | ||
payload: __assign(__assign({}, currentPayload), { duration: actionDuration, frontend_time: actionDuration - requestDuration }), | ||
}); | ||
// 上报后重置数据 | ||
resetAction(); | ||
}; | ||
var resetAction = function () { | ||
complete(); | ||
currentPayload = null; | ||
requestStartAndEnd = []; | ||
longtaskDuration = 0; | ||
}; | ||
var _d = __read(waitActionComplete(reportActionIfAllowed, resetAction, window), 3), start = _d[0], notify = _d[1], complete = _d[2]; | ||
var incompleteReq = applyIncompleteReq(tearDownGroup, [xhrObserver, fetchObserver], notify); | ||
var _e = __read(applyMutationObserver(MutationObserver, notify), 2), observe = _e[0], disconnect = _e[1]; | ||
observe(); | ||
tearDownGroup.push(disconnect); | ||
// 补充数据 | ||
var applyOtherReport = function (ev) { | ||
var _a, _b; | ||
if (!currentPayload) { | ||
return; | ||
} | ||
if (!arrayIncludes(RELATED_EV_TYPES, ev.ev_type)) { | ||
return; | ||
} | ||
// 通知监听,有相关变更 | ||
notify(); | ||
if (ev.ev_type === HTTP_EV_TYPE) { | ||
if (!ev.payload.response.timing) { | ||
return; | ||
} | ||
if (!arrayIncludes(RELATED_EV_TYPES, ev.ev_type)) { | ||
var _c = ev.payload.response.timing, startTime = _c.startTime, duration = _c.duration; | ||
if (startTime < currentPayload.start_time) { | ||
return; | ||
} | ||
// 通知监听,有相关变更 | ||
notify(); | ||
if (ev.ev_type === HTTP_EV_TYPE) { | ||
if (!ev.payload.response.timing) { | ||
return; | ||
} | ||
var _c = ev.payload.response.timing, startTime = _c.startTime, duration = _c.duration; | ||
if (startTime < currentPayload.start_time) { | ||
return; | ||
} | ||
requestStartAndEnd.push(startTime, startTime + duration); | ||
} | ||
else if (ev.ev_type === LONGTASK_RV_TYPE) { | ||
if (!ev.payload.longtasks.length || ev.payload.longtasks[0].startTime < currentPayload.start_time) { | ||
return; | ||
} | ||
ev.payload.longtasks.forEach(function (e) { | ||
longtaskDuration = longtaskDuration + e.duration; | ||
}); | ||
// eslint-disable-next-line sonarjs/no-collapsible-if | ||
} | ||
else if (ev.ev_type === RESOURCE_EV_TYPE) { | ||
if (ev.payload.startTime < currentPayload.start_time) { | ||
return; | ||
} | ||
} | ||
currentPayload.metrics[ev.ev_type] = { | ||
count: ((_b = (_a = currentPayload.metrics[ev.ev_type]) === null || _a === void 0 ? void 0 : _a.count) !== null && _b !== void 0 ? _b : 0) + 1, | ||
}; | ||
return currentPayload.id; | ||
}; | ||
var initAction = function (target, type) { | ||
// refresh action id in common | ||
var actionId = uuid(); | ||
var _a = __read(applyPerformance(performance), 2), now = _a[1]; | ||
// init payload | ||
currentPayload = { | ||
start_time: now(), | ||
id: actionId, | ||
type: type, | ||
target: target, | ||
metrics: {}, | ||
}; | ||
}; | ||
var handleEvent = function (e) { | ||
reportActionIfAllowed(); | ||
resetAction(); | ||
if (!(e.target instanceof HTMLElement)) { | ||
requestStartAndEnd.push(startTime, startTime + duration); | ||
} | ||
else if (ev.ev_type === LONGTASK_RV_TYPE) { | ||
if (!ev.payload.longtasks.length || ev.payload.longtasks[0].startTime < currentPayload.start_time) { | ||
return; | ||
} | ||
var name = getActionName(e.target, DEFAULT_ATTR_NAME); | ||
if (!name) { | ||
ev.payload.longtasks.forEach(function (e) { | ||
longtaskDuration = longtaskDuration + e.duration; | ||
}); | ||
// eslint-disable-next-line sonarjs/no-collapsible-if | ||
} | ||
else if (ev.ev_type === RESOURCE_EV_TYPE) { | ||
if (ev.payload.startTime < currentPayload.start_time) { | ||
return; | ||
} | ||
initAction({ name: name, path: getDomPath(e.target) }, e.type); | ||
start(); | ||
} | ||
currentPayload.metrics[ev.ev_type] = { | ||
count: ((_b = (_a = currentPayload.metrics[ev.ev_type]) === null || _a === void 0 ? void 0 : _a.count) !== null && _b !== void 0 ? _b : 0) + 1, | ||
}; | ||
types && | ||
types.forEach(function (t) { | ||
if (arrayIncludes(SUPPORT_TYPES, t)) { | ||
document.addEventListener(t, handleEvent, EVENT_LISTENER_OPTIONS); | ||
restoreFns.push(function () { return document.removeEventListener(t, handleEvent, EVENT_LISTENER_OPTIONS); }); | ||
} | ||
}); | ||
var teardown = function () { | ||
restoreFns.forEach(function (fn) { return fn(); }); | ||
disconnect(); | ||
return currentPayload.id; | ||
}; | ||
var initAction = function (target, type) { | ||
// refresh action id in common | ||
var actionId = uuid(); | ||
var _a = __read(applyPerformance(performance), 2), now = _a[1]; | ||
// init payload | ||
currentPayload = { | ||
start_time: now(), | ||
id: actionId, | ||
type: type, | ||
target: target, | ||
metrics: {}, | ||
}; | ||
var startAction = function (name, type) { | ||
reportActionIfAllowed(); | ||
resetAction(); | ||
initAction({ name: name }, type); | ||
start(); | ||
}; | ||
return [teardown, applyOtherReport, startAction]; | ||
start(); | ||
}; | ||
var handleEvent = function (e) { | ||
reportActionIfAllowed(); | ||
resetAction(); | ||
if (!(e.target instanceof HTMLElement)) { | ||
return; | ||
} | ||
var name = getActionName(e.target, DEFAULT_ATTR_NAME); | ||
if (!name) { | ||
return; | ||
} | ||
initAction({ name: name, path: getDomPath(e.target) }, e.type); | ||
}; | ||
types && | ||
types.forEach(function (t) { | ||
if (arrayIncludes(SUPPORT_TYPES, t)) { | ||
document.addEventListener(t, handleEvent, EVENT_LISTENER_OPTIONS); | ||
tearDownGroup.push(function () { return document.removeEventListener(t, handleEvent, EVENT_LISTENER_OPTIONS); }); | ||
} | ||
}); | ||
var startAction = function (name, type) { | ||
reportActionIfAllowed(); | ||
resetAction(); | ||
initAction({ name: name }, type); | ||
}; | ||
return [applyOtherReport, startAction]; | ||
}; | ||
@@ -1096,3 +1380,11 @@ | ||
if (config === void 0) { config = defaultConfig; } | ||
var _a = __read(applyMonitor(ActionMonitor, config, client.report.bind(client)), 3), tearDown = _a[0], applyOtherReport = _a[1], startAction = _a[2]; | ||
var tearDownGroup = []; | ||
var document = getDefaultDocument(); | ||
var window = getDefaultBrowser(); | ||
if (!document || !window) | ||
return; | ||
var _a = __read(actionGetterWithFetchObserver(client.report.bind(client), tearDownGroup, [ | ||
initSubjectInGlobal(client, [XHR_SUBJECT_NAME, applyXHR(XMLHttpRequest && XMLHttpRequest.prototype)]), | ||
initSubjectInGlobal(client, fetchSubject), | ||
], config), 2), applyOtherReport = _a[0], startAction = _a[1]; | ||
var listenOtherReport = function (ev) { | ||
@@ -1106,3 +1398,3 @@ var actionId = applyOtherReport(ev); | ||
client.on('beforeDestroy', function () { | ||
tearDown(); | ||
tearDownGroup.forEach(function (e) { return e(); }); | ||
client.off('report', listenOtherReport); | ||
@@ -1112,2 +1404,73 @@ }); | ||
var getSPA = function (report, tearDownGroup, _a) { | ||
var _b = __read(_a, 6), pvObserver = _b[0], xhrObserver = _b[1], fetchObserver = _b[2], resourceObserver = _b[3], longtaskObserver = _b[4], MutationObserver = _b[5]; | ||
var spa_load_start = 0; | ||
var reportMetric = applyReportMetric(report); | ||
var startSPA = function () { | ||
spa_load_start = now(); | ||
observe(document, { | ||
childList: true, | ||
subtree: true, | ||
}); | ||
start(); | ||
}; | ||
var reportSPAIfAllowed = function () { | ||
if (Object.keys(incompleteReq).length || !spa_load_start) { | ||
return; | ||
} | ||
reportMetric(initMetric(SPA_LOAD_METRIC_NAME, now() - spa_load_start)); | ||
endSPA(); | ||
}; | ||
var endSPA = function () { | ||
complete(); | ||
spa_load_start = 0; | ||
disconnect(); | ||
}; | ||
var _c = __read(waitActionComplete(reportSPAIfAllowed, endSPA, window), 3), start = _c[0], notify = _c[1], complete = _c[2]; | ||
// request | ||
var incompleteReq = applyIncompleteReq(tearDownGroup, [xhrObserver, fetchObserver], notify); | ||
// resource | ||
tearDownGroup.push(resourceObserver[0](notify)); | ||
// longtask | ||
tearDownGroup.push(longtaskObserver[0](notify)); | ||
// dom | ||
var _d = __read(applyMutationObserver(MutationObserver, notify), 2), observe = _d[0], disconnect = _d[1]; | ||
tearDownGroup.push(disconnect); | ||
var isFirstPV = true; | ||
// start SPA when PV change | ||
tearDownGroup.push(pvObserver[0](function () { | ||
if (isFirstPV) { | ||
isFirstPV = false; | ||
return; | ||
} | ||
// force end last SPA if not report | ||
endSPA(); | ||
// start a new SPA metric | ||
startSPA(); | ||
})); | ||
// reset SPA status when tear down | ||
tearDownGroup.push(endSPA); | ||
}; | ||
function SPALoadMonitorPlugin(client) { | ||
client.on('init', function () { | ||
var tearDownGroup = []; | ||
var document = getDefaultDocument(); | ||
var MutationObserver = getDefaultMutationObserver(); | ||
if (!document || !MutationObserver) | ||
return; | ||
getSPA(client.report.bind(client), tearDownGroup, [ | ||
initPrivateSubject(client, [PV_SUBJECT_NAME, applyPV(client)]), | ||
initSubjectInGlobal(client, [XHR_SUBJECT_NAME, applyXHR(XMLHttpRequest && XMLHttpRequest.prototype)]), | ||
initSubjectInGlobal(client, fetchSubject), | ||
initSubjectInGlobal(client, resourceSubject), | ||
initSubjectInGlobal(client, longtaskSubject), | ||
MutationObserver, | ||
]); | ||
client.on('beforeDestroy', function () { | ||
tearDownGroup.forEach(function (e) { return e(); }); | ||
}); | ||
}); | ||
} | ||
var captureConsole = function (_a) { | ||
@@ -1164,2 +1527,9 @@ var _b = _a.levels, levels = _b === void 0 ? ['log', 'info', 'warn', 'error', 'debug', 'assert'] : _b; | ||
export { actionPlugin, captureConsole, jsErrorPlugin, refreshPreStartContext }; | ||
var SPALoadPlugin = function () { return ({ | ||
name: 'spa_load', | ||
setup: function (client) { | ||
SPALoadMonitorPlugin(client); | ||
}, | ||
}); }; | ||
export { SPALoadPlugin, actionPlugin, captureConsole, jsErrorPlugin, refreshPreStartContext }; |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var __assign=function(){return(__assign=Object.assign||function(r){for(var t,e=1,n=arguments.length;e<n;e++)for(var o in t=arguments[e])Object.prototype.hasOwnProperty.call(t,o)&&(r[o]=t[o]);return r}).apply(this,arguments)};function __read(r,t){var e="function"==typeof Symbol&&r[Symbol.iterator];if(!e)return r;var n,o,i=e.call(r),a=[];try{for(;(void 0===t||0<t--)&&!(n=i.next()).done;)a.push(n.value)}catch(r){o={error:r}}finally{try{n&&!n.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return a}function __spreadArray(r,t,e){if(e||2===arguments.length)for(var n,o=0,i=t.length;o<i;o++)!n&&o in t||((n=n||Array.prototype.slice.call(t,0,o))[o]=t[o]);return r.concat(n||Array.prototype.slice.call(t))}var refreshPreStartContext=function(){return{name:"refreshPreStartContext",setup:function(n){n.on("start",function(){var e=n.getPreStartQueue();e.forEach(function(r,t){e[t]=__assign(__assign({},r),{overrides:__assign(__assign({},null!==(r=r.overrides)&&void 0!==r?r:{}),{context:(null===(r=n.context)||void 0===r?void 0:r.toString())||{}})})})})}}},noop=function(){return{}};function isObject(r){return"object"==typeof r&&null!==r}function isInstanceOf(r,t){try{return r instanceof t}catch(r){return!1}}var objProto=Object.prototype;function isPlainObject(r){if(isObject(r)){if("function"!=typeof Object.getPrototypeOf)return"[object Object]"===objProto.toString.call(r);r=Object.getPrototypeOf(r);return r===objProto||null===r}return!1}function isArray(r){return"[object Array]"===objProto.toString.call(r)}function isFunction(r){return"function"==typeof r}function isString(r){return"string"==typeof r}function isError(r){switch(Object.prototype.toString.call(r)){case"[object Error]":case"[object Exception]":case"[object DOMError]":case"[object DOMException]":return!0;default:return r instanceof Error}}function isEvent(r){return"undefined"!=typeof Event&&isInstanceOf(r,Event)}function isErrorEvent(r){return"[object ErrorEvent]"===Object.prototype.toString.call(r)}function isPromiseRejectionEvent(r){return"[object PromiseRejectionEvent]"===Object.prototype.toString.call(r)}function arrayIncludes(r,t){if(!isArray(r))return!1;if(0===r.length)return!1;for(var e=0;e<r.length;){if(r[e]===t)return!0;e++}return!1}var applyRecord=function(){var e={};return[e,function(r,t){return e[r]=t},function(r){return delete e[r]}]},pick=function(e,r){return e&&isObject(e)?r.reduce(function(r,t){return r[t]=e[t],r},{}):e};function getRegexp(r){return isArray(r)&&r.length?joinRegExp(r):null}function joinRegExp(r){for(var t=[],e=r.length,n=0;n<e;n++){var o=r[n];isString(o)?t.push(o.replace(/([.*+?^=!:${}()|[\]/\\])/g,"\\$1")):o&&o.source&&t.push(o.source)}return new RegExp(t.join("|"),"i")}function safeStringify(r){try{return isString(r)?r:JSON.stringify(r)}catch(r){return"[FAILED_TO_STRINGIFY]:"+String(r)}}function safeJoin(r,t){if(!isArray(r))return"";for(var e=[],n=0;n<r.length;n++)try{e.push(String(r[n]))}catch(r){e.push("[value cannot be serialized]")}return e.join(t)}var hookObjectProperty=function(i,a,u,c){return void 0===c&&(c=!0),function(){for(var r=[],t=0;t<arguments.length;t++)r[t]=arguments[t];if(!i)return noop;var e=i[a],n=u.apply(void 0,__spreadArray([e],__read(r),!1)),o=n;return isFunction(o)&&c&&(o=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];try{return n.apply(this,t)}catch(r){return isFunction(e)&&e.apply(this,t)}}),i[a]=o,function(r){r||(o===i[a]?i[a]=e:n=e)}}},hookMethodDangerously=function(i,a,u){return function(){for(var r=[],t=0;t<arguments.length;t++)r[t]=arguments[t];if(!i)return noop;var e=i[a],n=u.apply(void 0,__spreadArray([e],__read(r),!1)),o=n;return isFunction(o)&&(o=function(){for(var r=[],t=0;t<arguments.length;t++)r[t]=arguments[t];return n.apply(this,r)}),i[a]=o,function(){o===i[a]?i[a]=e:n=e}}};function mathRNG(){for(var r=new Array(16),t=0,e=0;e<16;e++)0==(3&e)&&(t=4294967296*Math.random()),r[e]=t>>>((3&e)<<3)&255;return r}function bytesToUuid(r){for(var t=[],e=0;e<256;++e)t[e]=(e+256).toString(16).substr(1);var n=0,o=t;return[o[r[n++]],o[r[n++]],o[r[n++]],o[r[n++]],"-",o[r[n++]],o[r[n++]],"-",o[r[n++]],o[r[n++]],"-",o[r[n++]],o[r[n++]],"-",o[r[n++]],o[r[n++]],o[r[n++]],o[r[n++]],o[r[+n]],o[r[15]]].join("")}function uuid(){var r=mathRNG();return r[6]=15&r[6]|64,r[8]=63&r[8]|128,bytesToUuid(r)}function getDefaultBrowser(){if("object"==typeof window&&isObject(window))return window}function getDefaultDocument(){if("object"==typeof document&&isObject(document))return document}function getDefaultPerformance(){if(getDefaultBrowser()&&isObject(window.performance))return window.performance}function getDefaultXMLHttpRequest(){if("function"==typeof XMLHttpRequest&&isFunction(XMLHttpRequest))return XMLHttpRequest}function getDefaultMutationObserver(){if(getDefaultBrowser()&&isFunction(window.MutationObserver))return window.MutationObserver}var getGlobalRegistry=function(r){if(r)return r.__SLARDAR_REGISTRY__||(r.__SLARDAR_REGISTRY__={Slardar:{plugins:[],errors:[],subject:{}}}),r.__SLARDAR_REGISTRY__.Slardar},reportSelfError=function(){for(var r=[],t=0;t<arguments.length;t++)r[t]=arguments[t];var e=getGlobalRegistry(getDefaultBrowser());e&&(e.errors||(e.errors=[]),e.errors.push(r))},applyMutationObserver=function(r,t){var e=r&&new r(t);return[function(r,t){e&&r&&e.observe(r,t)},function(){return e&&e.disconnect()}]},applyPerformance=function(e){var r=e&&e.timing||void 0;return[r,function(){return e&&e.now?e.now():(Date.now?Date.now():+new Date)-(r&&r.navigationStart||0)},function(r){var t=(e||{}).getEntriesByType;return isFunction(t)&&t.call(e,r)||[]},function(){var r=(e||{}).clearResourceTimings;isFunction(r)&&r.call(e)},function(r){var t=(e||{}).getEntriesByName;return isFunction(t)&&t.call(e,r)||[]}]},applyMonitor=function(r,t,e,n){void 0===t&&(t={}),void 0===n&&(n=[]);try{var o=r.apply(void 0,__spreadArray([],__read(n),!1));return o&&o(t,e)||[]}catch(r){return reportSelfError(r),[]}},now=function(){return Date.now()},getConfig=function(r,t){return isObject(r)?__assign(__assign({},t),r):!!r&&t};function getPluginConfig(r,t,e){t=null===(r=r.config())||void 0===r?void 0:r.plugins[t];return getConfig(t,e)}var ERROR_FIELDS=["name","message","stack","filename","lineno","colno"],normalize=function(r){var t;return isError(r)?t=pick(r,ERROR_FIELDS):(isPlainObject(r)||isEvent(r)||isString(r))&&(t={message:safeStringify(r)}),t},normalizeError=function(r){return normalize(r.error)},normalizeException=function(r){var t;try{var e=void 0;if("reason"in r?e=r.reason:"detail"in r&&"reason"in r.detail&&(e=r.detail.reason),e){var n=normalize(e);return __assign(__assign({},n),{name:null!==(t=n&&n.name)&&void 0!==t?t:"UnhandledRejection"})}}catch(r){}},normalizeUnknownError=function(r){return(isErrorEvent(r)?normalizeError:isPromiseRejectionEvent(r)?normalizeException:normalize)(r)},DEFAULT_EVENT_TARGET=["EventTarget","Window","Node","ApplicationCache","ChannelMergerNode","EventSource","FileReader","HTMLUnknownElement","IDBDatabase","IDBRequest","IDBTransaction","MessagePort","Notification","SVGElementInstance","Screen","TextTrack","TextTrackCue","TextTrackList","WebSocket","Worker","XMLHttpRequest","XMLHttpRequestEventTarget","XMLHttpRequestUpload"],DEFAULT_TIME_FUNCTION=["setTimeout","setInterval","requestAnimationFrame","requestIdleCallback"],xmlHttpRequestProps=["onload","onerror","onprogress","onreadystatechange"],ADD_EVENT_LISTENER="addEventListener",REMOVE_EVENT_LISTENER="removeEventListener",DEFAULT_SOURCE_TYPE="capture-global",hookGlobalAsync=function(o,t,r){void 0===t&&(t=getDefaultBrowser()),void 0===r&&(r=getDefaultXMLHttpRequest());function a(r,e){if(!isFunction(r))return r;var n={type:DEFAULT_SOURCE_TYPE,data:__assign({},e)},t=r._w_||(r._w_=function(){try{return(r.handleEvent&&isFunction(r.handleEvent)?r.handleEvent:r).apply(this,[].map.call(arguments,function(r){return a(r,e)}))}catch(r){var t=normalize(r);throw t&&o({error:t,source:n}),r}});return t._hook_=!0,t}var e=[];return t&&e.push.apply(e,__spreadArray([],__read(DEFAULT_TIME_FUNCTION.filter(function(r){return t[r]}).map(function(o){return hookObjectProperty(t,o,function(n){return function(r){for(var t=[],e=1;e<arguments.length;e++)t[e-1]=arguments[e];return n&&n.call.apply(n,__spreadArray([this,a(r,{function:o})],__read(t),!1))}},!1)()})),!1)),r&&r.prototype&&e.push(hookObjectProperty(r.prototype,"send",function(n){return function(){for(var t=this,r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];return xmlHttpRequestProps.filter(function(r){return t[r]&&!t[r]._hook_}).forEach(function(r){t[r]=a(t[r],{function:r})}),n.apply(this,r)}},!1)()),DEFAULT_EVENT_TARGET.forEach(function(i){var r=t[i]&&t[i].prototype;r&&r[ADD_EVENT_LISTENER]&&(e.push(hookObjectProperty(r,ADD_EVENT_LISTENER,function(o){return function(r,t,e){try{var n=t.handleEvent;isFunction(n)&&(t.handleEvent=a(n,{function:"handleEvent",target:i}))}catch(r){}return o&&o.call(this,r,a(t,{function:ADD_EVENT_LISTENER,target:i}),e)}},!1)()),e.push(hookObjectProperty(r,REMOVE_EVENT_LISTENER,function(n){return function(r,t,e){return null!=t&&t._w_&&n.call(this,r,t._w_,e),n.call(this,r,t,e)}},!1)()))}),e},isSameErrorString=function(r,t){return r&&t&&r===t},shouldDropEvent=function(r,t){return!(!r||!t)&&!(!isSameErrorString(r.message,t.message)||!isSameErrorString(r.stack,t.stack))},dedupe=function(){var t;return function(r){try{if(shouldDropEvent(r,t))return void(t=r)}catch(r){reportSelfError(r)}return t=r}},JS_ERROR_EV_TYPE$1="js_error",JsErrorMonitor=function(p){if(p=void 0===p?getDefaultBrowser():p)return function(r,o){var t,e,n=r.ignoreErrors,i=r.onerror,a=r.onunhandledrejection,u=r.dedupe,r=r.captureGlobalAsync,c=getRegexp(n),s=[],f=dedupe(),l=function(r){var t=r.error,e=r.extra,n=r.react,r=r.source,t=u?f(t):t;o&&t&&(c&&c.test(t.message)||o({ev_type:JS_ERROR_EV_TYPE$1,payload:{error:t,breadcrumbs:[],extra:e,react:n,source:r}}))};i&&(p.addEventListener("error",t=function(r){return l({error:normalizeError(r),source:{type:"onerror"}})}),s.push(function(){return p.removeEventListener("error",t)})),a&&(p.addEventListener("unhandledrejection",e=function(r){return l({error:normalizeException(r),source:{type:"onunhandledrejection"}})}),s.push(function(){return p.removeEventListener("unhandledrejection",e)})),r&&s.push.apply(s,__spreadArray([],__read(hookGlobalAsync(l)),!1));return[function(r,t,e){return l({error:normalizeUnknownError(r),extra:t,react:e,source:{type:"manual"}})},function(){s.forEach(function(r){return r()})}]}},JS_ERROR_MONITOR_PLUGIN_NAME="jsError",defaultConfig$1={ignoreErrors:[],onerror:!0,onunhandledrejection:!0,captureGlobalAsync:!1,dedupe:!0};function JsErrorMonitorPlugin(e){e.on("init",function(){window.removeEventListener("error",e.pcErr,!0),window.removeEventListener("unhandledrejection",e.pcRej,!0);var r,t=getPluginConfig(e,JS_ERROR_MONITOR_PLUGIN_NAME,defaultConfig$1);t&&(t=(r=__read(applyMonitor(JsErrorMonitor,t,function(r){e.getBreadcrumbs&&(r.payload.breadcrumbs=e.getBreadcrumbs()),e.report(r)}),2))[0],r=r[1],e.on("beforeDestroy",r),e.provide("captureException",t))})}var PAGE_ACTIVITY_DELAY=100,MAX_PAGE_ACTIVITY_DELAY=1e4,ROOT_TAGS=["BODY","HTML","HEAD"],hookXHRSend=function(e,o,i){var a=0;return function(){for(var r=[],t=0;t<arguments.length;t++)r[t]=arguments[t];var n=a+=2;return o(n,now()),hookMethodDangerously(this,"onreadystatechange",function(e){return function(){for(var r=[],t=0;t<arguments.length;t++)r[t]=arguments[t];return 4===this.readyState&&i(n),e&&e.apply(this,r)}})(),e.apply(this,r)}},hookFetch=function(o,i,a){var u=1;return function(){for(var r=[],t=0;t<arguments.length;t++)r[t]=arguments[t];var e=o.apply(void 0,__spreadArray([],__read(r),!1)),n=u+=2;i(n,now());return e.then(function(){a(n)},function(){a(n)}),e}},applyIncompleteReq=function(r,t){var e=__read(applyRecord(),3),n=e[0],o=e[1],e=e[2];return t&&hookMethodDangerously(t.prototype,"send",hookXHRSend)(o,e),r&&hookMethodDangerously(r,"fetch",hookFetch)(o,e),[n]},waitActionComplete=function(r,t,e){function n(){e.clearTimeout(o),o=e.setTimeout(function(){r()},PAGE_ACTIVITY_DELAY)}var o,i;return[function(){e.clearTimeout(i),i=e.setTimeout(function(){r(),t()},MAX_PAGE_ACTIVITY_DELAY),n()},n,function(){e.clearTimeout(o),e.clearTimeout(i)}]},getDomPath=function(r){var t=r,e=[];try{for(;null!==t.parentNode;){for(var n=0,o=0,i=0;i<t.parentNode.childNodes.length;i++){var a=t.parentNode.childNodes[i];a.nodeName===t.nodeName&&(a===t&&(o=n),n++)}t.hasAttribute("id")&&""!==t.id?e.unshift(t.nodeName+"#"+t.id):1<n?e.unshift(t.nodeName+":eq("+o+")"):e.unshift(t.nodeName),t=t.parentNode}return e.slice(1).join(">")}catch(r){return}},isSupportsElementClosest=function(){var r;return function(){return void 0===r?r="closest"in HTMLElement.prototype:r}}(),findElementWithAttributeByParents=function(r,t,e){void 0===e&&(e=10);for(var n=r,o=0;o<e&&n;o++){if(~ROOT_TAGS.indexOf(n.nodeName))return;if(n.hasAttribute(t))return n;n=n.parentElement}},getActionNameByAttribute=function(r,t){r=isSupportsElementClosest()?r.closest("["+t+"]"):findElementWithAttributeByParents(r,t);if(r)return r.getAttribute(t).trim()},getActionName=function(r,t){return getActionNameByAttribute(r,t)||r.innerText},ACTION_EV_TYPE="action",HTTP_EV_TYPE="http",LONGTASK_RV_TYPE="performance_longtask",JS_ERROR_EV_TYPE="js_error",RESOURCE_EV_TYPE="resource",RELATED_EV_TYPES=[LONGTASK_RV_TYPE,HTTP_EV_TYPE,JS_ERROR_EV_TYPE,RESOURCE_EV_TYPE],SUPPORT_TYPES=["click"],EVENT_LISTENER_OPTIONS={capture:!0},DEFAULT_ATTR_NAME="data-apm-action",ActionMonitor=function(h,T,m,R,A){if(void 0===h&&(h=getDefaultBrowser()),void 0===T&&(T=getDefaultDocument()),void 0===m&&(m=getDefaultXMLHttpRequest()),void 0===R&&(R=getDefaultMutationObserver()),void 0===A&&(A=getDefaultPerformance()),T&&h)return function(r,e){var t=r.types,n=r.pure,o=[],i=null,a=[],u=0,c=__read(applyPerformance(A),2)[1],s=__read(applyIncompleteReq(h,m),1)[0],f=function(){var r,t;i&&(n||Object.keys(i.metrics).length)&&!Object.keys(s).length&&(i.metrics[LONGTASK_RV_TYPE]&&(i.metrics[LONGTASK_RV_TYPE].duration=u),r=0<a.length?Math.max.apply(Math,__spreadArray([],__read(a),!1))-Math.min.apply(Math,__spreadArray([],__read(a),!1)):0,i.metrics[HTTP_EV_TYPE]&&(i.metrics[HTTP_EV_TYPE].duration=r),t=c()-i.start_time,e&&e({ev_type:ACTION_EV_TYPE,payload:__assign(__assign({},i),{duration:t,frontend_time:t-r})}),l())},l=function(){d(),i=null,a=[],u=0},p=__read(waitActionComplete(f,l,h),3),_=p[0],E=p[1],d=p[2],r=__read(applyMutationObserver(R,E),2),p=r[0],v=r[1];p();function g(r){var t;f(),l(),r.target instanceof HTMLElement&&((t=getActionName(r.target,DEFAULT_ATTR_NAME))&&(y({name:t,path:getDomPath(r.target)},r.type),_()))}var y=function(r,t){var e=uuid(),n=__read(applyPerformance(A),2)[1];i={start_time:n(),id:e,type:t,target:r,metrics:{}}};t&&t.forEach(function(r){arrayIncludes(SUPPORT_TYPES,r)&&(T.addEventListener(r,g,EVENT_LISTENER_OPTIONS),o.push(function(){return T.removeEventListener(r,g,EVENT_LISTENER_OPTIONS)}))});return[function(){o.forEach(function(r){return r()}),v()},function(r){if(i&&arrayIncludes(RELATED_EV_TYPES,r.ev_type)){if(E(),r.ev_type===HTTP_EV_TYPE){if(!r.payload.response.timing)return;var t=r.payload.response.timing,e=t.startTime,t=t.duration;if(e<i.start_time)return;a.push(e,e+t)}else if(r.ev_type===LONGTASK_RV_TYPE){if(!r.payload.longtasks.length||r.payload.longtasks[0].startTime<i.start_time)return;r.payload.longtasks.forEach(function(r){u+=r.duration})}else if(r.ev_type===RESOURCE_EV_TYPE&&r.payload.startTime<i.start_time)return;return i.metrics[r.ev_type]={count:(null!==(r=null===(r=i.metrics[r.ev_type])||void 0===r?void 0:r.count)&&void 0!==r?r:0)+1},i.id}},function(r,t){f(),l(),y({name:r},t),_()}]}},ACTION_MONITOR_PLUGIN_NAME="action",defaultConfig={types:["click"]};function ActionMonitorBasePlugin(r,t){function e(r){var t=o(r);return t&&r.extra&&(r.extra.action_id=t),r}var t=__read(applyMonitor(ActionMonitor,t=void 0===t?defaultConfig:t,r.report.bind(r)),3),n=t[0],o=t[1],t=t[2];r.on("report",e),r.provide("startAction",t),r.on("beforeDestroy",function(){n(),r.off("report",e)})}var captureConsole=function(r){var r=r.levels,e=void 0===r?["log","info","warn","error","debug","assert"]:r;return{name:"captureConsole",setup:function(n){var t,o=getDefaultBrowser();o&&o.console&&(t=[],e.forEach(function(r){r in o.console&&t.push(hookMethodDangerously(o.console,r,function(e){return function(){for(var r=[],t=0;t<arguments.length;t++)r[t]=arguments[t];try{e&&e.call.apply(e,__spreadArray([o.console],__read(r),!1))}finally{n("captureException",safeJoin(r," "))}}})())}),n.on("beforeDestroy",function(){t.forEach(function(r){return r()})}))}}},jsErrorPlugin=function(){return{name:JS_ERROR_MONITOR_PLUGIN_NAME,setup:function(r){JsErrorMonitorPlugin(r)}}},actionPlugin=function(t){return{name:ACTION_MONITOR_PLUGIN_NAME,setup:function(r){ActionMonitorBasePlugin(r,t)}}};exports.actionPlugin=actionPlugin,exports.captureConsole=captureConsole,exports.jsErrorPlugin=jsErrorPlugin,exports.refreshPreStartContext=refreshPreStartContext; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var __assign=function(){return(__assign=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function __read(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,o,i=r.call(e),u=[];try{for(;(void 0===t||0<t--)&&!(n=i.next()).done;)u.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return u}function __spreadArray(e,t,r){if(r||2===arguments.length)for(var n,o=0,i=t.length;o<i;o++)!n&&o in t||((n=n||Array.prototype.slice.call(t,0,o))[o]=t[o]);return e.concat(n||Array.prototype.slice.call(t))}var refreshPreStartContext=function(){return{name:"refreshPreStartContext",setup:function(n){n.on("start",function(){var r=n.getPreStartQueue();r.forEach(function(e,t){r[t]=__assign(__assign({},e),{overrides:__assign(__assign({},null!==(e=e.overrides)&&void 0!==e?e:{}),{context:(null===(e=n.context)||void 0===e?void 0:e.toString())||{}})})})})}}},noop=function(){return{}};function isObject(e){return"object"==typeof e&&null!==e}function isInstanceOf(e,t){try{return e instanceof t}catch(e){return!1}}var objProto=Object.prototype;function isPlainObject(e){if(isObject(e)){if("function"!=typeof Object.getPrototypeOf)return"[object Object]"===objProto.toString.call(e);e=Object.getPrototypeOf(e);return e===objProto||null===e}return!1}function isArray(e){return"[object Array]"===objProto.toString.call(e)}function isFunction(e){return"function"==typeof e}function isString(e){return"string"==typeof e}function isError(e){switch(Object.prototype.toString.call(e)){case"[object Error]":case"[object Exception]":case"[object DOMError]":case"[object DOMException]":return!0;default:return e instanceof Error}}function isEvent(e){return"undefined"!=typeof Event&&isInstanceOf(e,Event)}function isErrorEvent(e){return"[object ErrorEvent]"===Object.prototype.toString.call(e)}function isPromiseRejectionEvent(e){return"[object PromiseRejectionEvent]"===Object.prototype.toString.call(e)}function arrayIncludes(e,t){if(!isArray(e))return!1;if(0===e.length)return!1;for(var r=0;r<e.length;){if(e[r]===t)return!0;r++}return!1}var arrayRemove=function(e,t){if(!isArray(e))return e;var r=e.indexOf(t);if(0<=r){t=e.slice();return t.splice(r,1),t}return e},applyRecord=function(){var r={};return[r,function(e,t){return r[e]=t},function(e){return delete r[e]}]},pick=function(r,e){return r&&isObject(r)?e.reduce(function(e,t){return e[t]=r[t],e},{}):r};function getRegexp(e){return isArray(e)&&e.length?joinRegExp(e):null}function joinRegExp(e){for(var t=[],r=e.length,n=0;n<r;n++){var o=e[n];isString(o)?t.push(o.replace(/([.*+?^=!:${}()|[\]/\\])/g,"\\$1")):o&&o.source&&t.push(o.source)}return new RegExp(t.join("|"),"i")}function safeStringify(e){try{return isString(e)?e:JSON.stringify(e)}catch(e){return"[FAILED_TO_STRINGIFY]:"+String(e)}}function safeJoin(e,t){if(!isArray(e))return"";for(var r=[],n=0;n<e.length;n++)try{r.push(String(e[n]))}catch(e){r.push("[value cannot be serialized]")}return r.join(t)}var hookObjectProperty=function(i,u,a,c){return void 0===c&&(c=!0),function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];if(!i)return noop;var r=i[u],n=a.apply(void 0,__spreadArray([r],__read(e),!1)),o=n;return isFunction(o)&&c&&(o=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];try{return n.apply(this,t)}catch(e){return isFunction(r)&&r.apply(this,t)}}),i[u]=o,function(e){e||(o===i[u]?i[u]=r:n=r)}}},hookMethodDangerously=function(i,u,a){return function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];if(!i)return noop;var r=i[u],n=a.apply(void 0,__spreadArray([r],__read(e),!1)),o=n;return isFunction(o)&&(o=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return n.apply(this,e)}),i[u]=o,function(){o===i[u]?i[u]=r:n=r}}};function mathRNG(){for(var e=new Array(16),t=0,r=0;r<16;r++)0==(3&r)&&(t=4294967296*Math.random()),e[r]=t>>>((3&r)<<3)&255;return e}function bytesToUuid(e){for(var t=[],r=0;r<256;++r)t[r]=(r+256).toString(16).substr(1);var n=0,o=t;return[o[e[n++]],o[e[n++]],o[e[n++]],o[e[n++]],"-",o[e[n++]],o[e[n++]],"-",o[e[n++]],o[e[n++]],"-",o[e[n++]],o[e[n++]],"-",o[e[n++]],o[e[n++]],o[e[n++]],o[e[n++]],o[e[+n]],o[e[15]]].join("")}function uuid(){var e=mathRNG();return e[6]=15&e[6]|64,e[8]=63&e[8]|128,bytesToUuid(e)}var BUFFER_TIME=3e5,applyBufferTimer=function(e,t,r){var n=0;return-1===r?noop:function(){if(e())return n&&clearTimeout(n),void(n=0);0===n&&(n=setTimeout(t,r))}},nextLink=function(n,e){var t=[];try{t=e.reduce(function(e,t){try{var r=t(n);"function"==typeof r&&e.push(r)}catch(e){}return e},[])}catch(e){}return function(e){return nextLink(e,t)}},toObservable=function(e){function t(e){n=arrayRemove(n,e),i||u()}var r,n=[],o=[],i=!1,u=applyBufferTimer(function(){return!!n.length},function(){i=!0,r&&r[0](),o.forEach(function(e){return e()}),o.length=0,r=void 0},e=void 0===e?BUFFER_TIME:e);return{next:function(e){return nextLink(e,n)},complete:function(e){o.push(e)},attach:function(e,t){r=[e,t]},subscribe:function(e){if(i)throw new Error("Observer is closed");return n.push(e),r&&r[1]&&r[1](e),u(),function(){return t(e)}},unsubscribe:t}},createSafeObserver=function(e,t,r){r=toObservable(r);try{e(r.next,r.attach),t&&r.complete(t)}catch(e){}return[r.subscribe,r.unsubscribe]};function initSubjectInGlobal(e,t){return e.initSubject(t)}function initPrivateSubject(e,t,r){var t=__read(t,2),n=t[0],t=t[1],o=e.privateSubject||{};return o[n]||(o[n]=createSafeObserver(t,function(){o[n]=void 0},r)),o[n]}function getDefaultBrowser(){if("object"==typeof window&&isObject(window))return window}function getDefaultDocument(){if("object"==typeof document&&isObject(document))return document}function getDefaultLocation(){return getDefaultBrowser()&&window.location}function getDefaultXMLHttpRequest(){if("function"==typeof XMLHttpRequest&&isFunction(XMLHttpRequest))return XMLHttpRequest}function getDefaultMutationObserver(){if(getDefaultBrowser()&&isFunction(window.MutationObserver))return window.MutationObserver}function getDefaultPerformanceObserver(){if(getDefaultBrowser()&&isFunction(window.PerformanceObserver))return window.PerformanceObserver}var getGlobalRegistry=function(e){if(e)return e.__SLARDAR_REGISTRY__||(e.__SLARDAR_REGISTRY__={Slardar:{plugins:[],errors:[],subject:{}}}),e.__SLARDAR_REGISTRY__.Slardar},reportSelfError=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var r=getGlobalRegistry(getDefaultBrowser());r&&(r.errors||(r.errors=[]),r.errors.push(e))},applyMutationObserver=function(e,t){var r=e&&new e(t);return[function(e,t){r&&e&&r.observe(e,t)},function(){return r&&r.disconnect()}]},applyPerformance=function(r){var e=r&&r.timing||void 0;return[e,function(){return r&&r.now?r.now():(Date.now?Date.now():+new Date)-(e&&e.navigationStart||0)},function(e){var t=(r||{}).getEntriesByType;return isFunction(t)&&t.call(r,e)||[]},function(){var e=(r||{}).clearResourceTimings;isFunction(e)&&e.call(r)},function(e){var t=(r||{}).getEntriesByName;return isFunction(t)&&t.call(r,e)||[]}]},applyMonitor=function(e,t,r,n){void 0===t&&(t={}),void 0===n&&(n=[]);try{var o=e.apply(void 0,__spreadArray([],__read(n),!1));return o&&o(t,r)||[]}catch(e){return reportSelfError(e),[]}},now=function(){return Date.now()};function getLocationUrl(){var e=getDefaultBrowser()&&getDefaultLocation();return null==e?void 0:e.href}var getConfig=function(e,t){return isObject(e)?__assign(__assign({},t),e):!!e&&t},XHR_SUBJECT_NAME="xhr_0",hookOpen=function(n){return function(){for(var e,t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return e=__read(t,2),this._method=e[0],this._url=e[1],n.apply(this,t)}},hookSetHeader=function(o){return function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._reqHeaders=this._reqHeaders||{};var r=__read(e,2),n=r[0],r=r[1];return this._reqHeaders[n]=r,o&&o.apply(this,e)}},hookOnreadystatechange=function(n,o){return hookMethodDangerously(n,"onreadystatechange",function(r){return function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return 4===this.readyState&&o(n),r&&r.apply(this,e)}})},hookSend=function(n,o){return function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._start=now(),this._data=null==e?void 0:e[0];var r=o([this._method,this._url,this._start,this]);return hookOnreadystatechange(this,r)(),n.apply(this,e)}},applyXHR=function(n){return function(e,t){var r;n&&((r=[]).push(hookMethodDangerously(n,"open",hookOpen)()),r.push(hookMethodDangerously(n,"setRequestHeader",hookSetHeader)()),r.push(hookMethodDangerously(n,"send",hookSend)(e)),t(function(){r.forEach(function(e){return e()})}))}},FETCH_SUBJECT_NAME="fetch_0",hookFetch=function(n,o){return function(e,t){var r=o([e,t=void 0===t?{}:t]),t=n(e,t);return t.then(function(e){r(e)},function(){r(void 0)}),t}},observeFetch=function(e,t){var r,n=getDefaultBrowser();n&&fetch&&((r=[]).push(hookMethodDangerously(n,"fetch",hookFetch)(e)),t(function(){r.forEach(function(e){return e()})}))},fetchSubject=[FETCH_SUBJECT_NAME,observeFetch],RESOURCE_TYPE=["resource"],LONGTASK_TYPE=["longtask"],applyPerformanceObserver=function(t,o,r){var n=t&&new t(function(e,n){e.getEntries?e.getEntries().forEach(function(e,t,r){return o(e,t,r,n)}):r&&r()});return[function(e){if(!t||!n)return r&&r();try{n.observe({entryTypes:e})}catch(e){return r&&r()}},function(e){if(!t||!n)return r&&r();try{n.observe({type:e,buffered:!0})}catch(e){return r&&r()}n.observe({type:e,buffered:!1})},function(){return n&&n.disconnect()}]},observePerf=function(e,t,r){e=__read(applyPerformanceObserver(e,t),3),t=e[0],e=e[2];return t(r),e},LONGTASK_SUBJECT_NAME="longtask_0",observeLongtask=function(e,t){var r=getDefaultPerformanceObserver();r&&t(observePerf(r,e,LONGTASK_TYPE))},longtaskSubject=[LONGTASK_SUBJECT_NAME,observeLongtask],RESOURCE_SUBJECT_NAME="resource_0",observeResource=function(e,t){var r=getDefaultPerformanceObserver();r&&t(observePerf(r,e,RESOURCE_TYPE))},resourceSubject=[RESOURCE_SUBJECT_NAME,observeResource];function getPluginConfig(e,t,r){t=null===(e=e.config())||void 0===e?void 0:e.plugins[t];return getConfig(t,r)}var ERROR_FIELDS=["name","message","stack","filename","lineno","colno"],normalize=function(e){var t;return isError(e)?t=pick(e,ERROR_FIELDS):(isPlainObject(e)||isEvent(e)||isString(e))&&(t={message:safeStringify(e)}),t},normalizeError=function(e){return normalize(e.error)},normalizeException=function(e){var t;try{var r=void 0;if("reason"in e?r=e.reason:"detail"in e&&"reason"in e.detail&&(r=e.detail.reason),r){var n=normalize(r);return __assign(__assign({},n),{name:null!==(t=n&&n.name)&&void 0!==t?t:"UnhandledRejection"})}}catch(e){}},normalizeUnknownError=function(e){return(isErrorEvent(e)?normalizeError:isPromiseRejectionEvent(e)?normalizeException:normalize)(e)},DEFAULT_EVENT_TARGET=["EventTarget","Window","Node","ApplicationCache","ChannelMergerNode","EventSource","FileReader","HTMLUnknownElement","IDBDatabase","IDBRequest","IDBTransaction","MessagePort","Notification","SVGElementInstance","Screen","TextTrack","TextTrackCue","TextTrackList","WebSocket","Worker","XMLHttpRequest","XMLHttpRequestEventTarget","XMLHttpRequestUpload"],DEFAULT_TIME_FUNCTION=["setTimeout","setInterval","requestAnimationFrame","requestIdleCallback"],xmlHttpRequestProps=["onload","onerror","onprogress","onreadystatechange"],ADD_EVENT_LISTENER="addEventListener",REMOVE_EVENT_LISTENER="removeEventListener",DEFAULT_SOURCE_TYPE="capture-global",hookGlobalAsync=function(o,t,e){void 0===t&&(t=getDefaultBrowser()),void 0===e&&(e=getDefaultXMLHttpRequest());function u(e,r){if(!isFunction(e))return e;var n={type:DEFAULT_SOURCE_TYPE,data:__assign({},r)},t=e._w_||(e._w_=function(){try{return(e.handleEvent&&isFunction(e.handleEvent)?e.handleEvent:e).apply(this,[].map.call(arguments,function(e){return u(e,r)}))}catch(e){var t=normalize(e);throw t&&o({error:t,source:n}),e}});return t._hook_=!0,t}var r=[];return t&&r.push.apply(r,__spreadArray([],__read(DEFAULT_TIME_FUNCTION.filter(function(e){return t[e]}).map(function(o){return hookObjectProperty(t,o,function(n){return function(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];return n&&n.call.apply(n,__spreadArray([this,u(e,{function:o})],__read(t),!1))}},!1)()})),!1)),e&&e.prototype&&r.push(hookObjectProperty(e.prototype,"send",function(n){return function(){for(var t=this,e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return xmlHttpRequestProps.filter(function(e){return t[e]&&!t[e]._hook_}).forEach(function(e){t[e]=u(t[e],{function:e})}),n.apply(this,e)}},!1)()),DEFAULT_EVENT_TARGET.forEach(function(i){var e=t[i]&&t[i].prototype;e&&e[ADD_EVENT_LISTENER]&&(r.push(hookObjectProperty(e,ADD_EVENT_LISTENER,function(o){return function(e,t,r){try{var n=t.handleEvent;isFunction(n)&&(t.handleEvent=u(n,{function:"handleEvent",target:i}))}catch(e){}return o&&o.call(this,e,u(t,{function:ADD_EVENT_LISTENER,target:i}),r)}},!1)()),r.push(hookObjectProperty(e,REMOVE_EVENT_LISTENER,function(n){return function(e,t,r){return null!=t&&t._w_&&n.call(this,e,t._w_,r),n.call(this,e,t,r)}},!1)()))}),r},isSameErrorString=function(e,t){return e&&t&&e===t},shouldDropEvent=function(e,t){return!(!e||!t)&&!(!isSameErrorString(e.message,t.message)||!isSameErrorString(e.stack,t.stack))},dedupe=function(){var t;return function(e){try{if(shouldDropEvent(e,t))return void(t=e)}catch(e){reportSelfError(e)}return t=e}},JS_ERROR_EV_TYPE$1="js_error",JsErrorMonitor=function(p){if(p=void 0===p?getDefaultBrowser():p)return function(e,o){var t,r,n=e.ignoreErrors,i=e.onerror,u=e.onunhandledrejection,a=e.dedupe,e=e.captureGlobalAsync,c=getRegexp(n),s=[],f=dedupe(),l=function(e){var t=e.error,r=e.extra,n=e.react,e=e.source,t=a?f(t):t;o&&t&&(c&&c.test(t.message)||o({ev_type:JS_ERROR_EV_TYPE$1,payload:{error:t,breadcrumbs:[],extra:r,react:n,source:e}}))};i&&(p.addEventListener("error",t=function(e){return l({error:normalizeError(e),source:{type:"onerror"}})}),s.push(function(){return p.removeEventListener("error",t)})),u&&(p.addEventListener("unhandledrejection",r=function(e){return l({error:normalizeException(e),source:{type:"onunhandledrejection"}})}),s.push(function(){return p.removeEventListener("unhandledrejection",r)})),e&&s.push.apply(s,__spreadArray([],__read(hookGlobalAsync(l)),!1));return[function(e,t,r){return l({error:normalizeUnknownError(e),extra:t,react:r,source:{type:"manual"}})},function(){s.forEach(function(e){return e()})}]}},JS_ERROR_MONITOR_PLUGIN_NAME="jsError",defaultConfig$1={ignoreErrors:[],onerror:!0,onunhandledrejection:!0,captureGlobalAsync:!1,dedupe:!0};function JsErrorMonitorPlugin(r){r.on("init",function(){window.removeEventListener("error",r.pcErr,!0),window.removeEventListener("unhandledrejection",r.pcRej,!0);var e,t=getPluginConfig(r,JS_ERROR_MONITOR_PLUGIN_NAME,defaultConfig$1);t&&(t=(e=__read(applyMonitor(JsErrorMonitor,t,function(e){r.getBreadcrumbs&&(e.payload.breadcrumbs=r.getBreadcrumbs()),r.report(e)}),2))[0],e=e[1],r.on("beforeDestroy",e),r.provide("captureException",t))})}var getOverrides=function(e){return{pid:e.pid,view_id:e.viewId,url:getLocationUrl()}},PV_SUBJECT_NAME="view_0",applyPV=function(o){return function(r,e){function t(e){var t;e.viewId&&e.viewId!==(null===(t=o.config())||void 0===t?void 0:t.viewId)&&(r(n),n=getOverrides(e))}var n=getOverrides(o.config());o.on("beforeConfig",t),e(function(){o.off("beforeConfig",t)})}},defaultMetricContext={isSupport:!0,isPolyfill:!1,isBounced:!1,isCustom:!1,type:"perf"},initMetric=function(e,t){return __assign({name:e,value:t},defaultMetricContext)},SINGLE_METRIC_EV_TYPE="performance",wrapPerformanceMetric=function(e,t){return{ev_type:SINGLE_METRIC_EV_TYPE,payload:e,overrides:t}},applyReportMetric=function(r){return function(e,t){r(wrapPerformanceMetric(e,t))}},SPA_LOAD_METRIC_NAME="spa_load",PAGE_ACTIVITY_DELAY=100,MAX_PAGE_ACTIVITY_DELAY=1e4,ROOT_TAGS=["BODY","HTML","HEAD"],waitActionComplete=function(e,t,r){function n(){r.clearTimeout(o),u&&(o=r.setTimeout(function(){e()},PAGE_ACTIVITY_DELAY))}var o,i,u=!1;return[function(){u=!0,r.clearTimeout(i),i=r.setTimeout(function(){e(),t()},MAX_PAGE_ACTIVITY_DELAY),n()},n,function(){u=!1,r.clearTimeout(o),r.clearTimeout(i)}]},getDomPath=function(e){var t=e,r=[];try{for(;null!==t.parentNode;){for(var n=0,o=0,i=0;i<t.parentNode.childNodes.length;i++){var u=t.parentNode.childNodes[i];u.nodeName===t.nodeName&&(u===t&&(o=n),n++)}t.hasAttribute("id")&&""!==t.id?r.unshift(t.nodeName+"#"+t.id):1<n?r.unshift(t.nodeName+":eq("+o+")"):r.unshift(t.nodeName),t=t.parentNode}return r.slice(1).join(">")}catch(e){return}},isSupportsElementClosest=function(){var e;return function(){return void 0===e?e="closest"in HTMLElement.prototype:e}}(),findElementWithAttributeByParents=function(e,t,r){void 0===r&&(r=10);for(var n=e,o=0;o<r&&n;o++){if(~ROOT_TAGS.indexOf(n.nodeName))return;if(n.hasAttribute(t))return n;n=n.parentElement}},getActionNameByAttribute=function(e,t){e=isSupportsElementClosest()?e.closest("["+t+"]"):findElementWithAttributeByParents(e,t);if(e)return e.getAttribute(t).trim()},getActionName=function(e,t){return getActionNameByAttribute(e,t)||e.innerText},ACTION_EV_TYPE="action",HTTP_EV_TYPE="http",LONGTASK_RV_TYPE="performance_longtask",JS_ERROR_EV_TYPE="js_error",RESOURCE_EV_TYPE="resource",RELATED_EV_TYPES=[LONGTASK_RV_TYPE,HTTP_EV_TYPE,JS_ERROR_EV_TYPE,RESOURCE_EV_TYPE],SUPPORT_TYPES=["click"],EVENT_LISTENER_OPTIONS={capture:!0},DEFAULT_ATTR_NAME="data-apm-action",applyIncompleteReq=function(e,t,r){var n=__read(t,2),o=n[0],i=n[1],t=__read(applyRecord(),3),n=t[0],u=t[1],a=t[2],c=0;return e.push(o[0](function(e){__read(e,1)[0];var t=c+=1;return u(t,now()),r(),function(){a(t),r()}})),e.push(i[0](function(){var e=c+=1;return u(e,now()),r(),function(){a(e),r()}})),n},actionGetterWithFetchObserver=function(r,t,e,n){function o(){var e,t;s&&(c||Object.keys(s.metrics).length)&&!Object.keys(v).length&&(s.metrics[LONGTASK_RV_TYPE]&&(s.metrics[LONGTASK_RV_TYPE].duration=l),e=0<f.length?Math.max.apply(Math,__spreadArray([],__read(f),!1))-Math.min.apply(Math,__spreadArray([],__read(f),!1)):0,s.metrics[HTTP_EV_TYPE]&&(s.metrics[HTTP_EV_TYPE].duration=e),t=p()-s.start_time,r({ev_type:ACTION_EV_TYPE,payload:__assign(__assign({},s),{duration:t,frontend_time:t-e})}),i())}function i(){d(),s=null,f=[],l=0}var u=__read(e,2),a=u[0],e=u[1],u=n.types,c=n.pure,s=null,f=[],l=0,p=__read(applyPerformance(performance),2)[1],n=__read(waitActionComplete(o,i,window),3),_=n[0],E=n[1],d=n[2],v=applyIncompleteReq(t,[a,e],E),a=__read(applyMutationObserver(MutationObserver,E),2),e=a[0],a=a[1];e(),t.push(a);function h(e,t){var r=uuid(),n=__read(applyPerformance(performance),2)[1];s={start_time:n(),id:r,type:t,target:e,metrics:{}},_()}function g(e){var t;o(),i(),e.target instanceof HTMLElement&&((t=getActionName(e.target,DEFAULT_ATTR_NAME))&&h({name:t,path:getDomPath(e.target)},e.type))}u&&u.forEach(function(e){arrayIncludes(SUPPORT_TYPES,e)&&(document.addEventListener(e,g,EVENT_LISTENER_OPTIONS),t.push(function(){return document.removeEventListener(e,g,EVENT_LISTENER_OPTIONS)}))});return[function(e){if(s&&arrayIncludes(RELATED_EV_TYPES,e.ev_type)){if(E(),e.ev_type===HTTP_EV_TYPE){if(!e.payload.response.timing)return;var t=e.payload.response.timing,r=t.startTime,t=t.duration;if(r<s.start_time)return;f.push(r,r+t)}else if(e.ev_type===LONGTASK_RV_TYPE){if(!e.payload.longtasks.length||e.payload.longtasks[0].startTime<s.start_time)return;e.payload.longtasks.forEach(function(e){l+=e.duration})}else if(e.ev_type===RESOURCE_EV_TYPE&&e.payload.startTime<s.start_time)return;return s.metrics[e.ev_type]={count:(null!==(e=null===(e=s.metrics[e.ev_type])||void 0===e?void 0:e.count)&&void 0!==e?e:0)+1},s.id}},function(e,t){o(),i(),h({name:e},t)}]},ACTION_MONITOR_PLUGIN_NAME="action",defaultConfig={types:["click"]};function ActionMonitorBasePlugin(e,t){void 0===t&&(t=defaultConfig);var r,n,o=[],i=getDefaultDocument(),u=getDefaultBrowser();i&&u&&(t=__read(actionGetterWithFetchObserver(e.report.bind(e),o,[initSubjectInGlobal(e,[XHR_SUBJECT_NAME,applyXHR(XMLHttpRequest&&XMLHttpRequest.prototype)]),initSubjectInGlobal(e,fetchSubject)],t),2),r=t[0],t=t[1],e.on("report",n=function(e){var t=r(e);return t&&e.extra&&(e.extra.action_id=t),e}),e.provide("startAction",t),e.on("beforeDestroy",function(){o.forEach(function(e){return e()}),e.off("report",n)}))}var getSPA=function(e,t,r){function n(){_(),f=0,v()}var o=__read(r,6),i=o[0],u=o[1],a=o[2],c=o[3],s=o[4],r=o[5],f=0,l=applyReportMetric(e),o=__read(waitActionComplete(function(){!Object.keys(E).length&&f&&(l(initMetric(SPA_LOAD_METRIC_NAME,now()-f)),n())},n,window),3),p=o[0],e=o[1],_=o[2],E=applyIncompleteReq(t,[u,a],e);t.push(c[0](e)),t.push(s[0](e));var e=__read(applyMutationObserver(r,e),2),d=e[0],v=e[1];t.push(v);var h=!0;t.push(i[0](function(){h?h=!1:(n(),f=now(),d(document,{childList:!0,subtree:!0}),p())})),t.push(n)};function SPALoadMonitorPlugin(n){n.on("init",function(){var e=[],t=getDefaultDocument(),r=getDefaultMutationObserver();t&&r&&(getSPA(n.report.bind(n),e,[initPrivateSubject(n,[PV_SUBJECT_NAME,applyPV(n)]),initSubjectInGlobal(n,[XHR_SUBJECT_NAME,applyXHR(XMLHttpRequest&&XMLHttpRequest.prototype)]),initSubjectInGlobal(n,fetchSubject),initSubjectInGlobal(n,resourceSubject),initSubjectInGlobal(n,longtaskSubject),r]),n.on("beforeDestroy",function(){e.forEach(function(e){return e()})}))})}var captureConsole=function(e){var e=e.levels,r=void 0===e?["log","info","warn","error","debug","assert"]:e;return{name:"captureConsole",setup:function(n){var t,o=getDefaultBrowser();o&&o.console&&(t=[],r.forEach(function(e){e in o.console&&t.push(hookMethodDangerously(o.console,e,function(r){return function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];try{r&&r.call.apply(r,__spreadArray([o.console],__read(e),!1))}finally{n("captureException",safeJoin(e," "))}}})())}),n.on("beforeDestroy",function(){t.forEach(function(e){return e()})}))}}},jsErrorPlugin=function(){return{name:JS_ERROR_MONITOR_PLUGIN_NAME,setup:function(e){JsErrorMonitorPlugin(e)}}},actionPlugin=function(t){return{name:ACTION_MONITOR_PLUGIN_NAME,setup:function(e){ActionMonitorBasePlugin(e,t)}}},SPALoadPlugin=function(){return{name:"spa_load",setup:function(e){SPALoadMonitorPlugin(e)}}};exports.SPALoadPlugin=SPALoadPlugin,exports.actionPlugin=actionPlugin,exports.captureConsole=captureConsole,exports.jsErrorPlugin=jsErrorPlugin,exports.refreshPreStartContext=refreshPreStartContext; |
@@ -151,3 +151,7 @@ declare type ReportEventFromClient<C extends AnyClient> = C extends { | ||
getSubject: (key: string) => SafeObservable<any> | undefined; | ||
privateSubject: SubjectMap; | ||
}; | ||
declare type SubjectMap = { | ||
[key: string]: SafeObservable<any> | undefined; | ||
}; | ||
@@ -816,3 +820,2 @@ /** 公共筛选条件 */ | ||
declare const TTI_MONITOR_PLUGIN_NAME = "tti"; | ||
interface TTIMonitorPluginConfig { | ||
@@ -819,0 +822,0 @@ [TTI_MONITOR_PLUGIN_NAME]?: boolean | Record<string, unknown>; |
@@ -151,3 +151,7 @@ declare type ReportEventFromClient<C extends AnyClient> = C extends { | ||
getSubject: (key: string) => SafeObservable<any> | undefined; | ||
privateSubject: SubjectMap; | ||
}; | ||
declare type SubjectMap = { | ||
[key: string]: SafeObservable<any> | undefined; | ||
}; | ||
@@ -816,3 +820,2 @@ /** 公共筛选条件 */ | ||
declare const TTI_MONITOR_PLUGIN_NAME = "tti"; | ||
interface TTIMonitorPluginConfig { | ||
@@ -819,0 +822,0 @@ [TTI_MONITOR_PLUGIN_NAME]?: boolean | Record<string, unknown>; |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var __assign=function(){return(__assign=Object.assign||function(n){for(var t,e=1,r=arguments.length;e<r;e++)for(var o in t=arguments[e])Object.prototype.hasOwnProperty.call(t,o)&&(n[o]=t[o]);return n}).apply(this,arguments)};function __read(n,t){var e="function"==typeof Symbol&&n[Symbol.iterator];if(!e)return n;var r,o,i=e.call(n),u=[];try{for(;(void 0===t||0<t--)&&!(r=i.next()).done;)u.push(r.value)}catch(n){o={error:n}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u}function __spreadArray(n,t,e){if(e||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||((r=r||Array.prototype.slice.call(t,0,o))[o]=t[o]);return n.concat(r||Array.prototype.slice.call(t))}var noop=function(){return{}};function isObject(n){return"object"==typeof n&&null!==n}function isFunction(n){return"function"==typeof n}var hookObjectProperty=function(i,u,a,c){return void 0===c&&(c=!0),function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];if(!i)return noop;var e=i[u],r=a.apply(void 0,__spreadArray([e],__read(n),!1)),o=r;return isFunction(o)&&c&&(o=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];try{return r.apply(this,t)}catch(n){return isFunction(e)&&e.apply(this,t)}}),i[u]=o,function(n){n||(o===i[u]?i[u]=e:r=e)}}};function getDefaultBrowser(){if("object"==typeof window&&isObject(window))return window}function getDefaultDocument(){if("object"==typeof document&&isObject(document))return document}function getDefaultHistory(){return getDefaultBrowser()&&window.history}var now=function(){return Date.now()};function parseUrl(n){var t=getDefaultDocument();if(!t||!n)return{url:n,protocol:"",domain:"",query:"",path:"",hash:""};t=t.createElement("a");t.href=n;n=t.pathname||"/";return"/"!==n[0]&&(n="/"+n),{url:t.href,protocol:t.protocol.slice(0,-1),domain:t.hostname,query:t.search.substring(1),path:n,hash:t.hash}}var getConfig=function(n,t){return isObject(n)?__assign(__assign({},t),n):!!n&&t};function getPluginConfig(n,t,e){t=null===(n=n.config())||void 0===n?void 0:n.plugins[t];return getConfig(t,e)}var HISTORY_SUBJECT_NAME="history_0",HASH_SUBJECT_NAME="hash_0",observeHistory=function(n,t){var e,r,o,i=getDefaultHistory();i&&(r=function(){return n(location.href)},(e=[]).push(hookObjectProperty(i,"pushState",o=function(e){return function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];try{e.apply(i,n)}finally{r()}}})(),hookObjectProperty(i,"replaceState",o)()),window.addEventListener("popstate",r,!0),e.push(function(){return window.removeEventListener("popstate",r,!0)}),t(function(){e.forEach(function(n){return n()})}))},observeHash=function(n,t){var e,r=getDefaultBrowser();r&&(r.addEventListener("hashchange",e=function(){return n(location.href)},!0),t(function(){return r.removeEventListener("hashchange",e,!0)}))},hashSubject=[HASH_SUBJECT_NAME,observeHash],historySubject=[HISTORY_SUBJECT_NAME,observeHistory],getDefaultExtractor=function(e){return function(n){var t;return"hash"===e?(null===(t=parseUrl(n).hash)||void 0===t?void 0:t.replace(/^#/,""))||"/":parseUrl(n).path}},applyOnPidChange=function(r,n,t,o){var i=t,u=n;o&&o(n);return[function(n,t,e){"user_set"!==n&&t!==i?(i=t,u=null!=e?e:i,o&&o(u),r(n,u)):"user_set"===n&&t!==u&&(u=t,o&&o(u),r(n,u))},function(){n&&r("init",n)}]},applyOnUrlChange=function(e,n){var r=n;return[function(n,t){t!==r&&e(n,r=t)}]},wrapPageview=function(n,t){return{ev_type:"pageview",payload:{pid:t,source:n}}},applyReportPageview=function(e){return function(n,t){e(wrapPageview(n,t))}},isManualMode=function(n){return"manual"===n},pvGetterWithRouteObserver=function(n,t,e,r){var o,i,u,a=__read(e,1)[0],c=r.sendInit,f=r.initPid,s=r.routeMode,e=r.extractPid,r=r.onPidUpdate,l=isManualMode(s)?function(){return""}:getDefaultExtractor(s),p=e||function(){},r=__read(applyOnPidChange(applyReportPageview(n),f||(o=location.href,null!==(i=p(o))&&void 0!==i?i:l(o)),l(location.href),r),2),h=r[0],r=r[1];return isManualMode(s)||(u=__read(applyOnUrlChange(function(n,t){return h(n,l(t),p(t))},""),1)[0],a&&t.push(a[0](function(n){return u(s,n)}))),c&&r(),[h.bind(null,"user_set")]},PAGEVIEW_MONITOR_PLUGIN_NAME="pageview",defaultConfig={sendInit:!0,routeMode:"history"};function PageviewMonitorPlugin(o){o.on("init",function(){var n,t,e,r=getPluginConfig(o,PAGEVIEW_MONITOR_PLUGIN_NAME,defaultConfig);r&&location&&(n=[],t=r.routeMode,e=__read(pvGetterWithRouteObserver(o.report.bind(o),n,isManualMode(t)?[]:[o.initSubject("hash"===t?hashSubject:historySubject)],__assign(__assign({},r),{initPid:null===(r=o.config())||void 0===r?void 0:r.pid,onPidUpdate:function(n){o.set({pid:n,viewId:n+"_"+now(),actionId:void 0})}})),1)[0],o.on("config",function(){e(o.config().pid)}),o.on("beforeDestroy",function(){n.forEach(function(n){return n()})}),o.provide("sendPageview",e))})}var pageviewPlugin=function(){return{name:PAGEVIEW_MONITOR_PLUGIN_NAME,setup:function(n){PageviewMonitorPlugin(n)}}};exports.pageviewPlugin=pageviewPlugin; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var __assign=function(){return(__assign=Object.assign||function(n){for(var t,e=1,r=arguments.length;e<r;e++)for(var o in t=arguments[e])Object.prototype.hasOwnProperty.call(t,o)&&(n[o]=t[o]);return n}).apply(this,arguments)};function __read(n,t){var e="function"==typeof Symbol&&n[Symbol.iterator];if(!e)return n;var r,o,i=e.call(n),u=[];try{for(;(void 0===t||0<t--)&&!(r=i.next()).done;)u.push(r.value)}catch(n){o={error:n}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u}function __spreadArray(n,t,e){if(e||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||((r=r||Array.prototype.slice.call(t,0,o))[o]=t[o]);return n.concat(r||Array.prototype.slice.call(t))}var noop=function(){return{}};function isObject(n){return"object"==typeof n&&null!==n}var objProto=Object.prototype;function isArray(n){return"[object Array]"===objProto.toString.call(n)}function isFunction(n){return"function"==typeof n}var arrayRemove=function(n,t){if(!isArray(n))return n;var e=n.indexOf(t);if(0<=e){t=n.slice();return t.splice(e,1),t}return n},hookObjectProperty=function(i,u,a,c){return void 0===c&&(c=!0),function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];if(!i)return noop;var e=i[u],r=a.apply(void 0,__spreadArray([e],__read(n),!1)),o=r;return isFunction(o)&&c&&(o=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];try{return r.apply(this,t)}catch(n){return isFunction(e)&&e.apply(this,t)}}),i[u]=o,function(n){n||(o===i[u]?i[u]=e:r=e)}}},BUFFER_TIME=3e5,applyBufferTimer=function(n,t,e){var r=0;return-1===e?noop:function(){if(n())return r&&clearTimeout(r),void(r=0);0===r&&(r=setTimeout(t,e))}},nextLink=function(r,n){var t=[];try{t=n.reduce(function(n,t){try{var e=t(r);"function"==typeof e&&n.push(e)}catch(n){}return n},[])}catch(n){}return function(n){return nextLink(n,t)}},toObservable=function(n){function t(n){r=arrayRemove(r,n),i||u()}var e,r=[],o=[],i=!1,u=applyBufferTimer(function(){return!!r.length},function(){i=!0,e&&e[0](),o.forEach(function(n){return n()}),o.length=0,e=void 0},n=void 0===n?BUFFER_TIME:n);return{next:function(n){return nextLink(n,r)},complete:function(n){o.push(n)},attach:function(n,t){e=[n,t]},subscribe:function(n){if(i)throw new Error("Observer is closed");return r.push(n),e&&e[1]&&e[1](n),u(),function(){return t(n)}},unsubscribe:t}},createSafeObserver=function(n,t,e){e=toObservable(e);try{n(e.next,e.attach),t&&e.complete(t)}catch(n){}return[e.subscribe,e.unsubscribe]};function initPrivateSubject(n,t,e){var t=__read(t,2),r=t[0],t=t[1],o=n.privateSubject||{};return o[r]||(o[r]=createSafeObserver(t,function(){o[r]=void 0},e)),o[r]}function getDefaultBrowser(){if("object"==typeof window&&isObject(window))return window}function getDefaultDocument(){if("object"==typeof document&&isObject(document))return document}function getDefaultLocation(){return getDefaultBrowser()&&window.location}function getDefaultHistory(){return getDefaultBrowser()&&window.history}var now=function(){return Date.now()};function parseUrl(n){var t=getDefaultDocument();if(!t||!n)return{url:n,protocol:"",domain:"",query:"",path:"",hash:""};t=t.createElement("a");t.href=n;n=t.pathname||"/";return"/"!==n[0]&&(n="/"+n),{url:t.href,protocol:t.protocol.slice(0,-1),domain:t.hostname,query:t.search.substring(1),path:n,hash:t.hash}}function getLocationUrl(){var n=getDefaultBrowser()&&getDefaultLocation();return null==n?void 0:n.href}var getConfig=function(n,t){return isObject(n)?__assign(__assign({},t),n):!!n&&t};function getPluginConfig(n,t,e){t=null===(n=n.config())||void 0===n?void 0:n.plugins[t];return getConfig(t,e)}var getOverrides=function(n){return{pid:n.pid,view_id:n.viewId,url:getLocationUrl()}},FIRST_PV_SUBJECT_NAME="f_view_0",applyFirstPV=function(r){return function(n,t){var e=getOverrides(r.config());t(noop,function(n){e&&n(e)})}},HISTORY_SUBJECT_NAME="history_0",HASH_SUBJECT_NAME="hash_0",observeHistory=function(n,t){var e,r,o,i=getDefaultHistory();i&&(r=function(){return n(location.href)},(e=[]).push(hookObjectProperty(i,"pushState",o=function(e){return function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];try{e.apply(i,n)}finally{r()}}})(),hookObjectProperty(i,"replaceState",o)()),window.addEventListener("popstate",r,!0),e.push(function(){return window.removeEventListener("popstate",r,!0)}),t(function(){e.forEach(function(n){return n()})}))},observeHash=function(n,t){var e,r=getDefaultBrowser();r&&(r.addEventListener("hashchange",e=function(){return n(location.href)},!0),t(function(){return r.removeEventListener("hashchange",e,!0)}))},hashSubject=[HASH_SUBJECT_NAME,observeHash],historySubject=[HISTORY_SUBJECT_NAME,observeHistory],getDefaultExtractor=function(e){return function(n){var t;return"hash"===e?(null===(t=parseUrl(n).hash)||void 0===t?void 0:t.replace(/^#/,""))||"/":parseUrl(n).path}},applyOnPidChange=function(r,n,t,o){var i=t,u=n;o&&o(n);return[function(n,t,e){"user_set"!==n&&t!==i?(i=t,u=null!=e?e:i,o&&o(u),r(n,u)):"user_set"===n&&t!==u&&(u=t,o&&o(u),r(n,u))},function(){n&&r("init",n)}]},applyOnUrlChange=function(e,n){var r=n;return[function(n,t){t!==r&&e(n,r=t)}]},wrapPageview=function(n,t){return{ev_type:"pageview",payload:{pid:t,source:n}}},applyReportPageview=function(e){return function(n,t){e(wrapPageview(n,t))}},isManualMode=function(n){return"manual"===n},pvGetterWithRouteObserver=function(n,t,e,r){var o,i,u,a=r.sendInit,c=r.initPid,f=r.routeMode,s=r.extractPid,r=r.onPidUpdate,l=isManualMode(f)?function(){return""}:getDefaultExtractor(f),p=s||function(){},r=__read(applyOnPidChange(applyReportPageview(n),c||(o=location.href,null!==(i=p(o))&&void 0!==i?i:l(o)),l(location.href),r),2),v=r[0],r=r[1];return isManualMode(f)||(u=__read(applyOnUrlChange(function(n,t){return v(n,l(t),p(t))},""),1)[0],e.length&&e.forEach(function(n){return t.push(n[0](function(n){return u(f,n)}))})),a&&r(),[v.bind(null,"user_set")]},PAGEVIEW_MONITOR_PLUGIN_NAME="pageview",defaultConfig={sendInit:!0,routeMode:"history"};function PageviewMonitorPlugin(o){o.on("init",function(){var n,t,e,r=getPluginConfig(o,PAGEVIEW_MONITOR_PLUGIN_NAME,defaultConfig);r&&location&&(n=[],t=r.routeMode,e=__read(pvGetterWithRouteObserver(o.report.bind(o),n,isManualMode(t)?[]:[o.initSubject(hashSubject),o.initSubject(historySubject)],__assign(__assign({},r),{initPid:null===(r=o.config())||void 0===r?void 0:r.pid,onPidUpdate:function(n){o.set({pid:n,viewId:n+"_"+now(),actionId:void 0})}})),1)[0],initPrivateSubject(o,[FIRST_PV_SUBJECT_NAME,applyFirstPV(o)],-1),o.on("config",function(){e(o.config().pid)}),o.on("beforeDestroy",function(){n.forEach(function(n){return n()})}),o.provide("sendPageview",e))})}var pageviewPlugin=function(){return{name:PAGEVIEW_MONITOR_PLUGIN_NAME,setup:function(n){PageviewMonitorPlugin(n)}}};exports.pageviewPlugin=pageviewPlugin; |
@@ -151,3 +151,7 @@ declare type ReportEventFromClient<C extends AnyClient> = C extends { | ||
getSubject: (key: string) => SafeObservable<any> | undefined; | ||
privateSubject: SubjectMap; | ||
}; | ||
declare type SubjectMap = { | ||
[key: string]: SafeObservable<any> | undefined; | ||
}; | ||
@@ -816,3 +820,2 @@ /** 公共筛选条件 */ | ||
declare const TTI_MONITOR_PLUGIN_NAME = "tti"; | ||
interface TTIMonitorPluginConfig { | ||
@@ -819,0 +822,0 @@ [TTI_MONITOR_PLUGIN_NAME]?: boolean | Record<string, unknown>; |
{ | ||
"name": "@apmplus/integrations", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "APMPlus Integrations", | ||
@@ -113,3 +113,3 @@ "main": "dist/index.js", | ||
}, | ||
"gitHead": "b389be6b739ce4107ecd7bd93a4b7ec7ddda4f05" | ||
"gitHead": "070c00aa7c2fbb75896746a28658674eca3f6158" | ||
} |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
469220
25
12334
4