web-performance-monitor-sdk
Version:
A modern, lightweight performance monitoring SDK for web applications. Monitor Core Web Vitals (LCP, FCP, FID, CLS, TTFB) with sendBeacon support.
91 lines • 2.05 kB
TypeScript
/**
* 性能监控主类
*/
import { PerformanceMonitorConfig, PerformanceMetrics } from './types';
declare class PerformanceMonitor {
private config;
private metricsCollector?;
private errorTracker?;
private isInitialized;
private sessionId;
private autoReportTimer?;
constructor(config?: PerformanceMonitorConfig);
/**
* 验证配置参数
*/
private validateConfig;
/**
* 初始化性能监控
*/
private init;
/**
* 生成会话ID
*/
private generateSessionId;
/**
* 获取设备信息
* 只检测主流现代浏览器:Chrome、Safari、Firefox、Edge
*/
private getDeviceInfo;
/**
* 获取网络信息
* 只支持现代浏览器的 Network Information API
*/
private getNetworkInfo;
/**
* 获取资源加载时间
*/
private getResourceTiming;
/**
* 启动自动上报
*/
private startAutoReport;
/**
* 设置页面卸载时上报
*/
private setupUnloadReporter;
/**
* 获取当前性能指标
*/
getMetrics(): PerformanceMetrics;
/**
* 获取详细的性能指标信息
*/
getDetailedMetrics(): Record<string, import("./types").MetricDetail>;
/**
* 获取错误统计
*/
getErrorCount(): number;
/**
* 手动报告性能指标
*/
reportMetrics(): void;
/**
* 停止监控
*/
disconnect(): void;
/**
* 检查是否已初始化
*/
isReady(): boolean;
/**
* 更新配置
*/
updateConfig(newConfig: Partial<PerformanceMonitorConfig>): void;
/**
* 通过sendBeacon发送数据
* sendBeacon 是最可靠的方式,即使在页面卸载时也能发送数据
*/
private sendViaBeacon;
/**
* 通过fetch发送数据
*/
private sendViaFetch;
/**
* 调试日志
*/
private log;
}
export { PerformanceMonitor };
export default PerformanceMonitor;
//# sourceMappingURL=index.d.ts.map