getConsoleMessages
Extract and retrieve console messages from a browser for debugging, monitoring, or logging purposes using Playwright-based automation on the PlayMCP server.
Instructions
Get console messages from the browser
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/controllers/playwright.ts:746-767 (handler)The core handler function that sets up a listener for console events on the Playwright page and collects formatted console messages.async getConsoleMessages(): Promise<string[]> { try { if (!this.isInitialized() || !this.state.page) { throw new Error('Browser not initialized'); } this.log('Getting console messages'); const messages: string[] = []; // Listen to console events this.state.page.on('console', msg => { messages.push(`[${msg.type().toUpperCase()}] ${msg.text()}`); }); // Return collected messages this.log('Console messages retrieved'); return messages; } catch (error: any) { console.error('Get console messages error:', error); throw new BrowserError('Failed to get console messages', 'Browser console monitoring error'); } }
- src/server.ts:391-399 (schema)Defines the tool's metadata including name, description, and input schema (no parameters required).const GET_CONSOLE_MESSAGES_TOOL: Tool = { name: "getConsoleMessages", description: "Get console messages from the browser", inputSchema: { type: "object", properties: {}, required: [] } };
- src/server.ts:544-544 (registration)Registers the getConsoleMessages tool in the server's tools dictionary.getConsoleMessages: GET_CONSOLE_MESSAGES_TOOL,
- src/server.ts:555-565 (registration)Registers the tools dictionary (including getConsoleMessages) with the MCP server via capabilities.const server = new Server( { name: "playmcp-browser", version: "1.0.0", }, { capabilities: { tools, }, } );
- src/server.ts:899-904 (helper)Dispatches incoming tool calls to the controller's getConsoleMessages method and formats the response.case 'getConsoleMessages': { const messages = await playwrightController.getConsoleMessages(); return { content: [{ type: "text", text: JSON.stringify(messages, null, 2) }] }; }