import { ConsoleLogEvent } from '@hawk.so/types'; /** * Console catcher class for intercepting and capturing console logs. * * This singleton class wraps native console methods to capture all console output with accurate * stack traces. When developers click on console messages in DevTools, they are taken to the * original call site in their code, not to the interceptor's code. */ export declare class ConsoleCatcher { /** * Singleton instance */ private static instance; /** * Console output buffer */ private readonly consoleOutput; /** * Initialization flag */ private isInitialized; /** * Private constructor to enforce singleton pattern */ private constructor(); /** * Get singleton instance */ static getInstance(): ConsoleCatcher; /** * Converts any argument to its string representation * * @param arg - Value to convert to string * @throws Error if the argument can not be stringified, for example by such reason: * SecurityError: Failed to read a named property 'toJSON' from 'Window': Blocked a frame with origin "https://codex.so" from accessing a cross-origin frame. */ private stringifyArg; /** * Formats console arguments handling %c directives * * @param args - Console arguments that may include style directives */ private formatConsoleArgs; /** * Extracts user code stack trace from the full stack trace. * * Dynamic stack frame identification: * - Problem: Fixed slice(2) doesn't work reliably because the number of internal frames * varies based on code structure (arrow functions, class methods, TS→JS transforms, etc.). * - Solution: Find the first stack frame that doesn't belong to consoleCatcher module. * This ensures DevTools will navigate to the user's code, not the interceptor's code. * * @param errorStack - Full stack trace string from Error.stack * @returns {object} Object with userStack (full stack from user code) and fileLine (first frame for DevTools link) */ private extractUserStack; /** * Adds a console log event to the output buffer * * @param logEvent - The console log event to be added to the output buffer */ private addToConsoleOutput; /** * Creates a console log event from an error or promise rejection * * @param event - The error event or promise rejection event to convert */ private createConsoleEventFromError; /** * Initializes the console interceptor by overriding default console methods. * * Wraps native console methods to intercept all calls, capture their context, and generate * accurate stack traces that point to the original call site (not the interceptor). */ init(): void; /** * Handles error events by converting them to console log events * * @param event - The error or promise rejection event to handle */ addErrorEvent(event: ErrorEvent | PromiseRejectionEvent): void; /** * Returns the current console output buffer */ getConsoleLogStack(): ConsoleLogEvent[]; }