Skip to main content
Glama

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
NameRequiredDescriptionDefault
limitNo
sinceNo
tabIdNo

Implementation Reference

  • 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) }] }; }
  • 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 } } } },
  • Dispatcher switch case that routes calls to the getWebSocketMessages handler.
    case 'get_websocket_messages': return await this.getWebSocketMessages(args);
  • 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 } }
  • 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 }); }); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/JediLuke/firefox-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server