get_websocket_messages
Capture and retrieve WebSocket messages for LiveView debugging in Firefox browser automation. Access messages by specifying tab ID, timestamp, and limit.
Instructions
Get captured WebSocket messages (for LiveView debugging)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | ||
| since | No | ||
| tabId | No |
Implementation Reference
- index-multi-debug.js:755-779 (handler)Main handler function that retrieves captured WebSocket messages from the browser page's window._wsMessages array (populated by injected monitoring script), applies optional filters for 'since' timestamp and 'limit', and returns formatted JSON output.async getWebSocketMessages(args = {}) { const { tabId, since, limit = 50 } = args; const effectiveTabId = tabId || this.activeTabId; const page = this.getPage(effectiveTabId); // Get WebSocket messages from injected monitoring const wsMessages = await page.evaluate(() => { return window._wsMessages || []; }); let filteredMessages = wsMessages; if (since) { filteredMessages = filteredMessages.filter(msg => msg.timestamp >= since); } filteredMessages = filteredMessages.slice(-limit); return { content: [{ type: 'text', text: `WebSocket Messages (${filteredMessages.length}):\n` + JSON.stringify(filteredMessages, null, 2) }] }; }
- index-multi-debug.js:313-324 (registration)Tool registration entry in the MCP tools list, including name, description, and input schema definition.{ name: 'get_websocket_messages', description: 'Get captured WebSocket messages (for LiveView debugging)', inputSchema: { type: 'object', properties: { tabId: { type: 'string' }, since: { type: 'number' }, limit: { type: 'number', default: 50 } } } },
- index-multi-debug.js:445-446 (registration)Dispatcher switch case that routes calls to the getWebSocketMessages handler.case 'get_websocket_messages': return await this.getWebSocketMessages(args);
- index-multi-debug.js:316-322 (schema)Input schema defining parameters: tabId (string), since (number, optional timestamp filter), limit (number, default 50).inputSchema: { type: 'object', properties: { tabId: { type: 'string' }, since: { type: 'number' }, limit: { type: 'number', default: 50 } }
- index-multi-debug.js:543-587 (helper)Supporting helper function that injects JavaScript into the page to override the WebSocket constructor, intercepting and storing sent/received messages in window._wsMessages array, which the handler reads.async injectWebSocketMonitoring(page, tabId) { await page.addInitScript(() => { // Store original WebSocket const OriginalWebSocket = window.WebSocket; // Array to store WebSocket messages window._wsMessages = window._wsMessages || []; // Override WebSocket constructor window.WebSocket = function(...args) { const ws = new OriginalWebSocket(...args); // Monitor incoming messages ws.addEventListener('message', (event) => { window._wsMessages.push({ type: 'received', data: event.data, timestamp: Date.now(), url: ws.url }); }); // Monitor outgoing messages const originalSend = ws.send; ws.send = function(data) { window._wsMessages.push({ type: 'sent', data: data, timestamp: Date.now(), url: ws.url }); return originalSend.call(this, data); }; return ws; }; // Copy static properties Object.setPrototypeOf(window.WebSocket, OriginalWebSocket); Object.defineProperty(window.WebSocket, 'prototype', { value: OriginalWebSocket.prototype, writable: false }); }); }