getConsoleErrors
Identify and analyze browser console errors to troubleshoot webpage issues. Utilizes a Chrome extension via the BrowserTools MCP server for efficient error monitoring and reporting.
Instructions
Check our browsers console errors
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- browser-tools-mcp/mcp-server.ts:195-214 (handler)Handler function for the 'getConsoleErrors' MCP tool. It uses withServerConnection to fetch console errors from the browser connector server at /console-errors endpoint and returns the JSON response as text.server.tool( "getConsoleErrors", "Check our browsers console errors", async () => { return await withServerConnection(async () => { const response = await fetch( `http://${discoveredHost}:${discoveredPort}/console-errors` ); const json = await response.json(); return { content: [ { type: "text", text: JSON.stringify(json, null, 2), }, ], }; }); } );
- browser-tools-mcp/mcp-server.ts:195-214 (registration)Registration of the 'getConsoleErrors' tool on the MCP server using server.tool() with description and inline handler.server.tool( "getConsoleErrors", "Check our browsers console errors", async () => { return await withServerConnection(async () => { const response = await fetch( `http://${discoveredHost}:${discoveredPort}/console-errors` ); const json = await response.json(); return { content: [ { type: "text", text: JSON.stringify(json, null, 2), }, ], }; }); } );
- Shared helper function used by getConsoleErrors (and other tools) to ensure connection to the browser server is established before making API calls, with automatic discovery and retry logic.async function withServerConnection<T>( apiCall: () => Promise<T> ): Promise<T | any> { // Attempt to discover server if not already discovered if (!serverDiscovered) { const discovered = await discoverServer(); if (!discovered) { return { content: [ { type: "text", text: "Failed to discover browser connector server. Please ensure it's running.", }, ], isError: true, }; } } // Now make the actual API call with discovered host/port try { return await apiCall(); } catch (error: any) { // If the request fails, try rediscovering the server once console.error( `API call failed: ${error.message}. Attempting rediscovery...` ); serverDiscovered = false; if (await discoverServer()) { console.error("Rediscovery successful. Retrying API call..."); try { // Retry the API call with the newly discovered connection return await apiCall(); } catch (retryError: any) { console.error(`Retry failed: ${retryError.message}`); return { content: [ { type: "text", text: `Error after reconnection attempt: ${retryError.message}`, }, ], isError: true, }; } } else { console.error("Rediscovery failed. Could not reconnect to server."); return { content: [ { type: "text", text: `Failed to reconnect to server: ${error.message}`, }, ], isError: true, }; } } }