/** Console log levels supported by standard console methods */ export type ConsoleLogLevel = 'log' | 'info' | 'warn' | 'error' | 'debug' | 'trace'; /** Represents a single console operation with its type, arguments, and timestamp */ export type ConsoleEntry = { type: ConsoleLogLevel | 'count' | 'time' | 'timeEnd' | 'group' | 'groupEnd' | 'clear' | 'assert' | 'dir' | 'table' | 'timeLog'; args: unknown[]; timestamp: number; }; /** * Event handlers for console operations in the sandbox * * This interface provides callbacks for all standard console operations. * Implement the callbacks you need to handle console output from sandboxed code. * All callbacks are optional - if not provided, the operation will still be recorded * internally and included in the `onFinish` callback if provided. */ export type ConsoleEventHandler = { /** Called when any log method (log, info, warn, error, debug, trace) is invoked */ onLog?: (level: ConsoleLogLevel, ...args: unknown[]) => void; /** Called when console.count() is invoked with the label and current count */ onCount?: (label: string, count: number) => void; /** Called when console.timeEnd() is invoked with the timer label and elapsed time in ms */ onTime?: (label: string, duration: number) => void; /** Called when console.timeLog() is invoked with the timer label, elapsed time and arguments */ onTimeLog?: (label: string, duration: number, ...args: unknown[]) => void; /** Called when console.group() or console.groupCollapsed() is invoked */ onGroup?: (label?: string, collapsed?: boolean) => void; /** Called when console.groupEnd() is invoked */ onGroupEnd?: () => void; /** Called when console.clear() is invoked */ onClear?: () => void; /** Called when console.assert() fails (condition is falsy) */ onAssert?: (condition: boolean, ...args: unknown[]) => void; /** Called when console.dir() is invoked with the object and options */ onDir?: (obj: unknown, options?: object) => void; /** Called when console.table() is invoked with tabular data and optional properties */ onTable?: (tabularData: unknown, properties?: string[]) => void; /** Called when script execution completes with all recorded console entries */ onFinish?: (entries: ConsoleEntry[]) => void; }; /** * Creates a complete console module implementation for the sandbox * * This module provides all standard console methods as specified in the JavaScript specification, * including logging, timers, counters, groups, and assertions. It maintains proper state for methods * that require it (like console.count and console.time). * * The module records all console operations and can report them back via callbacks and a final * onFinish event when script execution completes. * * @param eventHandler - Optional object containing callback functions for console operations * @returns A CageModule that implements the console API in the sandbox * * @example * ```typescript * const cage = await FaradayCage.createFromQJSWasmLocation(wasmUrl); * * const logs: string[] = []; * * await cage.runCode(code, [ * console({ * onLog: (level, ...args) => { * logs.push(`[${level}] ${args.join(' ')}`); * }, * onFinish: (entries) => { * console.log(`Script produced ${entries.length} console entries`); * } * }) * ]); * ``` */ declare const _default: (eventHandler?: ConsoleEventHandler) => import("./_mod_authoring").CageModule; export default _default;