get_console_logs
Retrieve browser console logs with filtering by level and optional clearing. Designed for AI-assisted web automation on the AutoProbeMCP server using Playwright.
Instructions
Get console logs from the browser
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| clear | No | Clear console logs after retrieving | |
| level | No | Filter logs by level |
Implementation Reference
- src/index.ts:601-630 (handler)The handler for the get_console_logs tool. Parses parameters, filters console logs by optional level, optionally clears the log array, formats the logs with timestamps and levels, and returns them as text content.case 'get_console_logs': { if (!currentPage) { throw new Error('No browser page available. Launch a browser first.'); } const params = GetConsoleLogsSchema.parse(args); // Filter logs by level if specified const filteredLogs = params.level ? consoleLogs.filter(log => log.level === params.level) : consoleLogs; // Clear logs if requested if (params.clear) { consoleLogs = []; } const logText = filteredLogs.length > 0 ? filteredLogs.map(log => `[${log.timestamp.toISOString()}] ${log.level.toUpperCase()}: ${log.message}`).join('\n') : '(no console logs)'; return { content: [ { type: 'text', text: `Console Logs:\n${logText}` } ] }; }
- src/index.ts:59-62 (schema)Zod schema defining input parameters for get_console_logs tool: optional 'level' to filter logs, and 'clear' boolean to clear logs after retrieval.const GetConsoleLogsSchema = z.object({ level: z.enum(['log', 'info', 'warn', 'error', 'debug']).optional(), clear: z.boolean().default(false) });
- src/index.ts:295-313 (registration)Registration of the get_console_logs tool in the listTools handler, including name, description, and input schema definition.{ name: 'get_console_logs', description: 'Get console logs from the browser', inputSchema: { type: 'object', properties: { level: { type: 'string', enum: ['log', 'info', 'warn', 'error', 'debug'], description: 'Filter logs by level' }, clear: { type: 'boolean', default: false, description: 'Clear console logs after retrieving' } } } },
- src/index.ts:88-89 (helper)Global array storing captured console logs with level, message, and timestamp.let consoleLogs: Array<{level: string, message: string, timestamp: Date}> = [];
- src/index.ts:440-447 (helper)Playwright page event listener that captures console messages and stores them in the global consoleLogs array. Set up during browser launch.currentPage.on('console', (msg) => { consoleLogs.push({ level: msg.type(), message: msg.text(), timestamp: new Date() }); });