Skip to main content
Glama

safari_get_console_logs

Retrieve browser console logs from Safari for debugging web applications. Filter logs by severity level to identify JavaScript errors and warnings.

Instructions

Get browser console logs for debugging

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sessionIdYesSession identifier
logLevelNoFilter logs by level

Implementation Reference

  • Primary handler logic for retrieving Safari console logs. Injects JavaScript to override console.log/warn/error/info/debug methods to capture logs in window.__safariMCPConsoleLogs array, retrieves them, filters by logLevel if specified, and returns structured ConsoleLogEntry objects.
    async getConsoleLogs(sessionId: string, logLevel: LogLevel = 'ALL'): Promise<ConsoleLogEntry[]> { const session = this.getSession(sessionId); if (!session) { throw new Error(`Session ${sessionId} not found`); } try { // First, inject console logging capture if not already present await session.driver.executeScript(` if (!window.__safariMCPConsoleLogs) { window.__safariMCPConsoleLogs = []; // Store original console methods const originalConsole = { log: console.log, warn: console.warn, error: console.error, info: console.info, debug: console.debug }; // Override console methods to capture logs ['log', 'warn', 'error', 'info', 'debug'].forEach(method => { console[method] = function(...args) { const message = args.map(arg => typeof arg === 'object' ? JSON.stringify(arg) : String(arg) ).join(' '); window.__safariMCPConsoleLogs.push({ level: method.toUpperCase(), message: message, timestamp: Date.now(), source: 'browser' }); // Still call original method originalConsole[method].apply(console, args); }; }); } `); // Retrieve captured logs const logs = await session.driver.executeScript(` return window.__safariMCPConsoleLogs || []; `); const filteredLogs = logLevel === 'ALL' ? logs : logs.filter((log: any) => log.level === logLevel); return filteredLogs.map((log: any) => ({ level: log.level, message: log.message, timestamp: log.timestamp, source: log.source || 'browser' })); } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : String(error); throw new Error(`Failed to get console logs: ${errorMessage}`); } }
  • MCP server wrapper handler for 'safari_get_console_logs' tool. Extracts arguments, calls SafariDriverManager.getConsoleLogs, and returns formatted text response with JSON-serialized logs.
    private async getConsoleLogs(args: Record<string, any>): Promise<Array<{ type: string; text: string }>> { const { sessionId, logLevel = 'ALL' } = args; const logs = await this.driverManager.getConsoleLogs(sessionId, logLevel as LogLevel); return [ { type: 'text', text: `Console Logs (${logs.length} entries):\n\n${JSON.stringify(logs, null, 2)}` } ]; }
  • Schema definition for the 'safari_get_console_logs' tool, including input schema with required 'sessionId' and optional 'logLevel' enum.
    { name: 'safari_get_console_logs', description: 'Get browser console logs for debugging', inputSchema: { type: 'object', properties: { sessionId: { type: 'string', description: 'Session identifier' }, logLevel: { type: 'string', enum: ['ALL', 'DEBUG', 'INFO', 'WARNING', 'SEVERE'], description: 'Filter logs by level' } }, required: ['sessionId'] } },
  • Tool handler registration/dispatch in the handleToolCall switch statement.
    case 'safari_get_console_logs': return await this.getConsoleLogs(args);

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/lxman/safari-mcp-server'

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