/** * Console Capture Utility * * Shared console capturing logic used by both GlobalDevBar and SweetlinkBridge. * Provides consistent console interception and log formatting. */ import type { ConsoleLog } from '../types.js'; /** Maximum number of console logs to retain */ export declare const MAX_CONSOLE_LOGS = 100; /** * Original console methods stored for restoration */ export interface OriginalConsoleMethods { log: typeof console.log; error: typeof console.error; warn: typeof console.warn; info: typeof console.info; } /** * Console capture state */ export interface ConsoleCaptureState { logs: ConsoleLog[]; errorCount: number; warningCount: number; originalConsole: OriginalConsoleMethods | null; isPatched: boolean; } /** * Configuration for console capture */ export interface ConsoleCaptureConfig { maxLogs?: number; trackCounts?: boolean; onLog?: (log: ConsoleLog) => void; } /** * Listener callback for log count changes */ export type LogChangeListener = (errorCount: number, warningCount: number, infoCount: number) => void; /** * Format a single argument for logging */ export declare function formatArg(arg: unknown): string; /** * Format multiple arguments into a single message string */ export declare function formatArgs(args: unknown[]): string; /** * ConsoleCapture - Captures console output and stores logs */ export declare class ConsoleCapture { private logs; private errorCount; private warningCount; private infoCount; private originalConsole; private isPatched; private maxLogs; private trackCounts; private onLog?; private listeners; constructor(config?: ConsoleCaptureConfig); /** * Trim logs to maxLogs and adjust counts for any evicted entries. */ private trimLogs; /** * Start capturing console output */ start(): void; /** * Stop capturing and restore original console methods */ stop(): void; /** * Get all captured logs */ getLogs(): ConsoleLog[]; /** * Get filtered logs */ getFilteredLogs(filter: string): ConsoleLog[]; /** * Get error count */ getErrorCount(): number; /** * Get warning count */ getWarningCount(): number; /** * Get info count */ getInfoCount(): number; /** * Add a listener for log count changes */ addListener(listener: LogChangeListener): void; /** * Remove a listener */ removeListener(listener: LogChangeListener): void; private notifyListeners; /** * Get current state */ getState(): ConsoleCaptureState; /** * Recompute the cached counts from the current buffer. Use after any * batch operation (importLogs, clear-then-add) to guarantee counts can * never drift from the actual buffer contents. */ private recomputeCounts; /** * Import logs from another source (e.g., early capture). * Counts are recomputed from the buffer afterward — a batch import is * not subject to the same incremental accounting as the per-message * capture path, so this is the safe form. */ importLogs(logs: ConsoleLog[]): void; /** * Import early logs from window.__sweetlinkEarlyLogs (set by EARLY_CONSOLE_CAPTURE_SCRIPT) * and clear the global array. Converts ISO timestamp strings to epoch milliseconds. */ importEarlyLogs(): void; /** * Push a log entry directly (used by error/rejection handlers) */ addLog(log: ConsoleLog): void; /** * Start listening for uncaught errors, unhandled rejections, * resource load failures, and CSP violations. */ startErrorHandlers(): () => void; /** * Clear all logs and reset counts */ clear(): void; } //# sourceMappingURL=consoleCapture.d.ts.map