getConsoleMessages
Retrieve browser console messages for debugging web applications, monitoring JavaScript errors, and capturing log outputs during automation tasks.
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 main handler function that sets up console event listening and collects browser 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)Tool schema definition including name, description, and empty 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:514-552 (registration)Registration of the tool in the capabilities.tools dictionary for listTools endpoint.const tools = { openBrowser: OPEN_BROWSER_TOOL, navigate: NAVIGATE_TOOL, type: TYPE_TOOL, click: CLICK_TOOL, moveMouse: MOVE_MOUSE_TOOL, scroll: SCROLL_TOOL, screenshot: SCREENSHOT_TOOL, getPageSource: GET_PAGE_SOURCE_TOOL, getPageText: GET_PAGE_TEXT_TOOL, getPageTitle: GET_PAGE_TITLE_TOOL, getPageUrl: GET_PAGE_URL_TOOL, getScripts: GET_SCRIPTS_TOOL, getStylesheets: GET_STYLESHEETS_TOOL, getMetaTags: GET_META_TAGS_TOOL, getLinks: GET_LINKS_TOOL, getImages: GET_IMAGES_TOOL, getForms: GET_FORMS_TOOL, getElementContent: GET_ELEMENT_CONTENT_TOOL, getElementHierarchy: GET_ELEMENT_HIERARCHY_TOOL, executeJavaScript: EXECUTE_JAVASCRIPT_TOOL, goForward: GO_FORWARD_TOOL, hover: HOVER_TOOL, dragAndDrop: DRAG_AND_DROP_TOOL, selectOption: SELECT_OPTION_TOOL, pressKey: PRESS_KEY_TOOL, waitForText: WAIT_FOR_TEXT_TOOL, waitForSelector: WAIT_FOR_SELECTOR_TOOL, resize: RESIZE_TOOL, handleDialog: HANDLE_DIALOG_TOOL, getConsoleMessages: GET_CONSOLE_MESSAGES_TOOL, getNetworkRequests: GET_NETWORK_REQUESTS_TOOL, uploadFiles: UPLOAD_FILES_TOOL, evaluateWithReturn: EVALUATE_WITH_RETURN_TOOL, takeScreenshot: TAKE_SCREENSHOT_TOOL, mouseMove: MOUSE_MOVE_TOOL, mouseClick: MOUSE_CLICK_TOOL, mouseDrag: MOUSE_DRAG_TOOL, closeBrowser: CLOSE_BROWSER_TOOL
- src/server.ts:899-904 (registration)Tool call handler in the server's callTool request handler switch statement, which invokes the controller method and returns the result.case 'getConsoleMessages': { const messages = await playwrightController.getConsoleMessages(); return { content: [{ type: "text", text: JSON.stringify(messages, null, 2) }] }; }