UNPKG

web-see-monitor

Version:

前端监控 SDK,包含性能监控、错误监控和用户行为监控

119 lines (109 loc) 2.79 kB
declare abstract class BasePlugin { protected config: BasePluginConfig; report?: (data: ReportData) => void; abstract name: string; setConfig(config: BasePluginConfig): void; setReport(report: (data: ReportData) => void): void; abstract init(): void; abstract destroy(): void; } interface PerformanceConfig { enable?: boolean; slowResourceTime?: number; slowPageLoadTime?: number; } interface PerformanceData { type: 'performance'; subType: 'page-load' | 'resource'; name?: string; initiatorType?: string; duration?: number; transferSize?: number; dnsTime?: number; tcpTime?: number; whiteScreenTime?: number; domReadyTime?: number; loadTime?: number; isTimeout?: boolean; } interface ErrorData { type: 'error'; subType: 'javascript' | 'promise'; message: string; filename?: string; position?: string; stack?: string; } interface BehaviorData { type: 'behavior'; subType: 'pv' | 'click'; url?: string; referer?: string; path?: string; } interface MonitorConfig { appId: string; userId?: string; reportUrl: string; plugins?: Array<new () => BasePlugin>; enable?: boolean; sampling?: number; maxCache?: number; reportInterval?: number; ignoreErrors?: RegExp[]; } type MockType = 'mock'; type MockSubType = 'test' | `test-${number}`; type ReportData = (PerformanceData | ErrorData | BehaviorData | { type: MockType; subType: MockSubType; }) & { timestamp?: number; }; interface BasePluginConfig { enable?: boolean; [key: string]: any; } declare class Monitor { private config; private plugins; private cache; private timer; private readonly MAX_CACHE_LENGTH; private readonly REPORT_INTERVAL; constructor(config: MonitorConfig); private init; destroy(): void; private addCache; private report; } declare class PerformancePlugin extends BasePlugin { name: string; private performanceObserver?; init(): void; destroy(): void; private monitorPageLoad; private monitorResourceLoad; } declare class ErrorPlugin extends BasePlugin { name: string; private errorHandler; private rejectionHandler; constructor(); init(): void; destroy(): void; private shouldIgnoreError; private handleError; private handleRejection; } declare class BehaviorPlugin extends BasePlugin { name: string; private clickHandler; constructor(); init(): void; destroy(): void; private monitorPV; private handleClick; private getElementPath; } export { BehaviorData, BehaviorPlugin, ErrorData, ErrorPlugin, Monitor, MonitorConfig, PerformanceConfig, PerformanceData, PerformancePlugin, ReportData };