perf-observer-kit
Version:
A lightweight, flexible library for monitoring web performance metrics including Core Web Vitals, resource loading performance, long tasks, and navigation timing.
57 lines (56 loc) • 1.64 kB
JavaScript
/*
* PerfObserverKit Light Version (v0.0.6)
* A minimal version of PerfObserverKit with only core functionality
*/
(function(global,factory){
typeof exports==='object'&&typeof module!=='undefined'?factory(exports):
typeof define==='function'&&define.amd?define(['exports'],factory):
(global=global||self,factory(global.PerfObserverKit={}));
}(this,function(exports){'use strict';
var PerfObserverKit=function(options){
this.options=options||{};
this.metrics={
coreWebVitals:{},
resources:[],
longTasks:[],
navigation:{},
browserInfo:{}
};
this.isRunning=false;
if(this.options.autoStart){this.start();}
};
PerfObserverKit.prototype.start=function(){
this.isRunning=true;
return this;
};
PerfObserverKit.prototype.stop=function(){
this.isRunning=false;
return this;
};
PerfObserverKit.prototype.getMetrics=function(){
return this.metrics;
};
PerfObserverKit.prototype.clearMetrics=function(){
this.metrics={
coreWebVitals:{},
resources:[],
longTasks:[],
navigation:{},
browserInfo:{}
};
return this;
};
exports.PerfObserverKit=PerfObserverKit;
exports.MetricType={
WEB_VITALS:'coreWebVitals',
RESOURCES:'resources',
LONG_TASKS:'longTasks',
NAVIGATION:'navigation',
BROWSER_INFO:'browserInfo'
};
exports.default={
PerfObserverKit:PerfObserverKit,
MetricType:exports.MetricType
};
Object.defineProperty(exports,'__esModule',{value:true});
}));