feat: add console output file option for debugging and monitoring

Add comprehensive console logging to file functionality:
- CLI option --console-output-file to specify output file path
- Environment variable PLAYWRIGHT_MCP_CONSOLE_OUTPUT_FILE support
- Session configuration via browser_configure_snapshots tool
- Real-time structured logging with timestamp, session ID, and URL
- Automatic directory creation and graceful error handling
- Captures all console message types (log, error, warn, page errors)

Useful for debugging browser interactions and monitoring console activity
during automated sessions.
This commit is contained in:
Ryan Malloy 2025-08-24 14:12:00 -06:00
parent ec8b0c24b5
commit 7de63b5bab
6 changed files with 64 additions and 2 deletions

View file

@ -31,6 +31,7 @@ export type CLIOptions = {
caps?: string[];
cdpEndpoint?: string;
config?: string;
consoleOutputFile?: string;
device?: string;
executablePath?: string;
headless?: boolean;
@ -93,6 +94,7 @@ export type FullConfig = Config & {
includeSnapshots: boolean;
maxSnapshotTokens: number;
differentialSnapshots: boolean;
consoleOutputFile?: string;
};
export async function resolveConfig(config: Config): Promise<FullConfig> {
@ -212,6 +214,7 @@ export function configFromCLIOptions(cliOptions: CLIOptions): Config {
includeSnapshots: cliOptions.includeSnapshots,
maxSnapshotTokens: cliOptions.maxSnapshotTokens,
differentialSnapshots: cliOptions.differentialSnapshots,
consoleOutputFile: cliOptions.consoleOutputFile,
};
return result;
@ -238,6 +241,7 @@ function configFromEnv(): Config {
options.includeSnapshots = envToBoolean(process.env.PLAYWRIGHT_MCP_INCLUDE_SNAPSHOTS);
options.maxSnapshotTokens = envToNumber(process.env.PLAYWRIGHT_MCP_MAX_SNAPSHOT_TOKENS);
options.differentialSnapshots = envToBoolean(process.env.PLAYWRIGHT_MCP_DIFFERENTIAL_SNAPSHOTS);
options.consoleOutputFile = envToString(process.env.PLAYWRIGHT_MCP_CONSOLE_OUTPUT_FILE);
options.sandbox = envToBoolean(process.env.PLAYWRIGHT_MCP_SANDBOX);
options.outputDir = envToString(process.env.PLAYWRIGHT_MCP_OUTPUT_DIR);
options.port = envToNumber(process.env.PLAYWRIGHT_MCP_PORT);