get_console_logs
Retrieve console logs from web pages to debug JavaScript errors, inspect warnings, and verify code execution. Filter by log level and clear logs after reading.
Instructions
Get all console messages from the page (console.log, console.error, warnings, etc.). Use this to debug JavaScript errors, see what the page is logging, or verify your code is running.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| level | No | Filter logs: "error" for errors only, "warn" for warnings, "all" for everything (default) | |
| clear | No | Clear all logs after reading so you only get new messages next time | |
| tabId | No | Target tab ID (defaults to active tab) | |
| apiKey | No | API key for authentication if enabled |
Implementation Reference
- src/tools/devtools-console.ts:16-27 (handler)The handler function for the 'get_console_logs' tool. Sends a command via WebSocket bridge to the Chrome extension to retrieve console messages, with optional filtering by level and clearing after read.
async ({ level, clear, tabId, apiKey }) => { const result = await bridge.sendCommand({ command: 'get_console_logs', params: { level, clear }, tabId, apiKey, }); if (!result.success) { return { content: [{ type: 'text', text: `Error: ${result.error?.message}` }], isError: true }; } return { content: [{ type: 'text', text: JSON.stringify(result.data, null, 2) }] }; } - src/tools/devtools-console.ts:9-15 (schema)Zod schema defining the input parameters for 'get_console_logs': level (enum filter), clear (boolean flag), tabId, and apiKey (all optional).
{ level: z.enum(['log', 'warn', 'error', 'info', 'debug', 'all']).optional() .describe('Filter logs: "error" for errors only, "warn" for warnings, "all" for everything (default)'), clear: z.boolean().optional().describe('Clear all logs after reading so you only get new messages next time'), tabId: z.number().optional().describe('Target tab ID (defaults to active tab)'), apiKey: z.string().optional().describe('API key for authentication if enabled'), }, - src/tools/devtools-console.ts:6-28 (registration)Registration of the 'get_console_logs' tool via server.tool() in the registerDevtoolsConsoleTools function. Called from registerAllTools in tools/index.ts.
server.tool( 'get_console_logs', 'Get all console messages from the page (console.log, console.error, warnings, etc.). Use this to debug JavaScript errors, see what the page is logging, or verify your code is running.', { level: z.enum(['log', 'warn', 'error', 'info', 'debug', 'all']).optional() .describe('Filter logs: "error" for errors only, "warn" for warnings, "all" for everything (default)'), clear: z.boolean().optional().describe('Clear all logs after reading so you only get new messages next time'), tabId: z.number().optional().describe('Target tab ID (defaults to active tab)'), apiKey: z.string().optional().describe('API key for authentication if enabled'), }, async ({ level, clear, tabId, apiKey }) => { const result = await bridge.sendCommand({ command: 'get_console_logs', params: { level, clear }, tabId, apiKey, }); if (!result.success) { return { content: [{ type: 'text', text: `Error: ${result.error?.message}` }], isError: true }; } return { content: [{ type: 'text', text: JSON.stringify(result.data, null, 2) }] }; } ); - src/websocket-bridge.ts:63-103 (helper)The sendCommand method on WebSocketBridge that the handler calls. Sends the 'get_console_logs' command over WebSocket to the Chrome extension and returns the response.
async sendCommand(cmd: BridgeCommand): Promise<BridgeResponse> { if (!this.isConnected()) { return { success: false, error: { code: 'NOT_CONNECTED', message: 'Chrome extension is not connected. Ensure the extension is installed, enabled, and the browser is running.', }, }; } const id = crypto.randomUUID(); const timeout = cmd.timeout ?? DEFAULT_TIMEOUT; return new Promise<BridgeResponse>((resolve, reject) => { const timer = setTimeout(() => { this.pending.delete(id); resolve({ success: false, error: { code: 'TIMEOUT', message: `Command '${cmd.command}' timed out after ${timeout}ms`, }, }); }, timeout); this.pending.set(id, { resolve, reject, timer }); const message = { id, type: 'request', command: cmd.command, params: cmd.params, tabId: cmd.tabId, apiKey: cmd.apiKey, timestamp: Date.now(), }; this.client!.send(JSON.stringify(message)); }); }