Skip to main content
Glama

playwright_console_logs

Retrieve and filter browser console logs with customizable options like log type, search text, and limit. Automatically clear logs post-retrieval if needed. Essential for debugging and monitoring web interactions.

Instructions

Retrieve console logs from the browser with filtering options

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
clearNoWhether to clear logs after retrieval (default: false)
limitNoMaximum number of logs to return
searchNoText to search for in logs (handles text with square brackets)
typeNoType of logs to retrieve (all, error, warning, log, info, debug, exception)

Implementation Reference

  • The execute method in ConsoleLogsTool that implements the core logic for retrieving, filtering, and optionally clearing browser console logs based on input parameters.
    async execute(args: any, context: ToolContext): Promise<ToolResponse> {
      // No need to use safeExecute here as we don't need to interact with the page
      // We're just filtering and returning logs that are already stored
      
      let logs = [...this.consoleLogs];
      
      // Filter by type if specified
      if (args.type && args.type !== 'all') {
        logs = logs.filter(log => log.startsWith(`[${args.type}]`));
      }
      
      // Filter by search text if specified
      if (args.search) {
        logs = logs.filter(log => log.includes(args.search));
      }
      
      // Limit the number of logs if specified
      if (args.limit && args.limit > 0) {
        logs = logs.slice(-args.limit);
      }
      
      // Clear logs if requested
      if (args.clear) {
        this.consoleLogs = [];
      }
      
      // Format the response
      if (logs.length === 0) {
        return createSuccessResponse("No console logs matching the criteria");
      } else {
        return createSuccessResponse([
          `Retrieved ${logs.length} console log(s):`,
          ...logs
        ]);
      }
    }
  • The tool definition including name, description, and input schema for validation in createToolDefinitions().
    {
      name: "playwright_console_logs",
      description: "Retrieve console logs from the browser with filtering options",
      inputSchema: {
        type: "object",
        properties: {
          type: {
            type: "string",
            description: "Type of logs to retrieve (all, error, warning, log, info, debug, exception)",
            enum: ["all", "error", "warning", "log", "info", "debug", "exception"]
          },
          search: {
            type: "string",
            description: "Text to search for in logs (handles text with square brackets)"
          },
          limit: {
            type: "number",
            description: "Maximum number of logs to return"
          },
          clear: {
            type: "boolean",
            description: "Whether to clear logs after retrieval (default: false)"
          }
        },
        required: [],
      },
    },
  • Switch case in handleToolCall function that registers and dispatches execution to the consoleLogsTool for the 'playwright_console_logs' tool.
    case "playwright_console_logs":
      return await consoleLogsTool.execute(args, context);
  • Instantiation of the ConsoleLogsTool instance in the initializeTools function.
    if (!consoleLogsTool) consoleLogsTool = new ConsoleLogsTool(server);
  • The registerConsoleMessage function that sets up Playwright page event listeners to capture and register console messages, errors, and unhandled rejections into the tool's log storage.
    async function registerConsoleMessage(page) {
      page.on("console", (msg) => {
        if (consoleLogsTool) {
          const type = msg.type();
          const text = msg.text();
    
          // "Unhandled Rejection In Promise" we injected
          if (text.startsWith("[Playwright]")) {
            const payload = text.replace("[Playwright]", "");
            consoleLogsTool.registerConsoleMessage("exception", payload);
          } else {
            consoleLogsTool.registerConsoleMessage(type, text);
          }
        }
      });
    
      // Uncaught exception
      page.on("pageerror", (error) => {
        if (consoleLogsTool) {
          const message = error.message;
          const stack = error.stack || "";
          consoleLogsTool.registerConsoleMessage("exception", `${message}\n${stack}`);
        }
      });
    
      // Unhandled rejection in promise
      await page.addInitScript(() => {
        window.addEventListener("unhandledrejection", (event) => {
          const reason = event.reason;
          const message = typeof reason === "object" && reason !== null
              ? reason.message || JSON.stringify(reason)
              : String(reason);
    
          const stack = reason?.stack || "";
          // Use console.error get "Unhandled Rejection In Promise"
          console.error(`[Playwright][Unhandled Rejection In Promise] ${message}\n${stack}`);
        });
      });
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions 'retrieve' and 'filtering options', but fails to disclose critical traits: whether this is a read-only operation, if it requires specific browser states, potential side effects (e.g., clearing logs as per the 'clear' parameter), or error handling. For a tool with no annotation coverage, this is a significant gap in transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core action ('retrieve console logs') and mentions key capabilities ('filtering options') without unnecessary words. It earns its place by being direct and to the point, making it easy for an agent to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of browser interaction tools and the lack of annotations and output schema, the description is insufficient. It doesn't explain return values (e.g., log format, structure), error conditions, or dependencies on other tools (like requiring a started session). For a tool with 4 parameters and no structured output information, more contextual detail is needed to guide effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, meaning all parameters are documented in the schema itself. The description adds minimal value beyond the schema by hinting at 'filtering options', but doesn't elaborate on parameter interactions or provide additional context. With high schema coverage, the baseline score of 3 is appropriate as the description doesn't compensate with extra semantic insights.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'retrieve' and the resource 'console logs from the browser', making the purpose evident. It also mentions 'filtering options' which hints at capabilities. However, it doesn't explicitly distinguish this tool from potential sibling tools that might also retrieve logs or handle browser interactions, keeping it from a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., requiring an active browser session), exclusions, or compare it to sibling tools like 'playwright_get_visible_text' or 'playwright_evaluate' that might overlap in debugging contexts. This lack of context leaves the agent guessing about optimal usage scenarios.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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/executeautomation/mcp-playwright'

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