Skip to main content
Glama

get_console_logs

Retrieve and filter browser console logs by level (log, info, warn, error, debug) with an option to clear logs afterward. Enhances debugging and monitoring capabilities in Playwright-based browser automation.

Instructions

Get console logs from the browser

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
clearNoClear console logs after retrieving
levelNoFilter logs by level

Implementation Reference

  • Main handler function for the get_console_logs tool, which filters console logs by optional level, formats them with timestamps, returns as text response, and optionally clears the log storage.
    case 'get_console_logs': {
      if (!currentPage) {
        throw new Error('No browser page available. Launch a browser first.');
      }
    
      const params = GetConsoleLogsSchema.parse(args);
      
      // Filter logs by level if specified
      const filteredLogs = params.level 
        ? consoleLogs.filter(log => log.level === params.level)
        : consoleLogs;
    
      // Clear logs if requested
      if (params.clear) {
        consoleLogs = [];
      }
    
      const logText = filteredLogs.length > 0 
        ? filteredLogs.map(log => `[${log.timestamp.toISOString()}] ${log.level.toUpperCase()}: ${log.message}`).join('\n')
        : '(no console logs)';
    
      return {
        content: [
          {
            type: 'text',
            text: `Console Logs:\n${logText}`
          }
        ]
      };
    }
  • Zod schema for validating input parameters: optional level filter and clear flag.
    const GetConsoleLogsSchema = z.object({
      level: z.enum(['log', 'info', 'warn', 'error', 'debug']).optional(),
      clear: z.boolean().default(false)
    });
  • src/index.ts:295-313 (registration)
    Registration of the tool in the ListTools response, providing name, description, and JSON input schema.
    {
      name: 'get_console_logs',
      description: 'Get console logs from the browser',
      inputSchema: {
        type: 'object',
        properties: {
          level: {
            type: 'string',
            enum: ['log', 'info', 'warn', 'error', 'debug'],
            description: 'Filter logs by level'
          },
          clear: {
            type: 'boolean',
            default: false,
            description: 'Clear console logs after retrieving'
          }
        }
      }
    },
  • Global storage array for console logs captured from the browser page.
    let consoleLogs: Array<{level: string, message: string, timestamp: Date}> = [];
  • Page event listener that captures console messages and stores them in the global consoleLogs array. Set up during browser launch.
    currentPage.on('console', (msg) => {
      consoleLogs.push({
        level: msg.type(),
        message: msg.text(),
        timestamp: new Date()
      });
    });
Install Server

Other Tools

Related Tools

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/Wladastic/mcp-browser-server'

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