playwright_console_logs
Extract and filter browser console logs by type, search text, or limit results. Optionally clear logs after retrieval for efficient debugging in Playwright MCP Server.
Instructions
Retrieve console logs from the browser with filtering options
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| clear | No | Whether to clear logs after retrieval (default: false) | |
| limit | No | Maximum number of logs to return | |
| search | No | Text to search for in logs (handles text with square brackets) | |
| type | No | Type of logs to retrieve (all, error, warning, log, info, debug) |
Implementation Reference
- src/tools/browser/console.ts:22-57 (handler)The execute method implements the core tool logic: filters stored console logs by type, search term, and limit; optionally clears them; and returns formatted response.async execute(args: any, context: ToolContext): Promise<ToolResponse> { // No need to use safeExecute here as we don't need to interact with the page // We're just filtering and returning logs that are already stored let logs = [...this.consoleLogs]; // Filter by type if specified if (args.type && args.type !== 'all') { logs = logs.filter(log => log.startsWith(`[${args.type}]`)); } // Filter by search text if specified if (args.search) { logs = logs.filter(log => log.includes(args.search)); } // Limit the number of logs if specified if (args.limit && args.limit > 0) { logs = logs.slice(-args.limit); } // Clear logs if requested if (args.clear) { this.consoleLogs = []; } // Format the response if (logs.length === 0) { return createSuccessResponse("No console logs matching the criteria"); } else { return createSuccessResponse([ `Retrieved ${logs.length} console log(s):`, ...logs ]); } }
- src/tools.ts:182-208 (schema)Defines the tool's input schema, description, and name for MCP protocol validation.{ name: "playwright_console_logs", description: "Retrieve console logs from the browser with filtering options", inputSchema: { type: "object", properties: { type: { type: "string", description: "Type of logs to retrieve (all, error, warning, log, info, debug)", enum: ["all", "error", "warning", "log", "info", "debug"] }, search: { type: "string", description: "Text to search for in logs (handles text with square brackets)" }, limit: { type: "number", description: "Maximum number of logs to return" }, clear: { type: "boolean", description: "Whether to clear logs after retrieval (default: false)" } }, required: [], }, },
- src/toolHandler.ts:465-466 (registration)Registers the tool in the main handleToolCall switch by dispatching execution to the ConsoleLogsTool instance.case "playwright_console_logs": return await consoleLogsTool.execute(args, context);
- src/toolHandler.ts:289-289 (registration)Instantiates the ConsoleLogsTool class instance used for handling the tool calls.if (!consoleLogsTool) consoleLogsTool = new ConsoleLogsTool(server);
- src/tools/browser/console.ts:10-17 (helper)Helper method called by page console event listener to store incoming console messages for later retrieval./** * Register a console message * @param type The type of console message * @param text The text content of the message */ registerConsoleMessage(type: string, text: string): void { this.consoleLogs.push(`[${type}] ${text}`); }