Skip to main content
Glama
devskido

Playwright MCP Server

by devskido

playwright_get_visible_text

Extract visible text content from web pages for web scraping, content analysis, or accessibility testing using browser automation.

Instructions

Get the visible text content of the current page

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Core handler logic for 'playwright_get_visible_text': Uses TreeWalker to extract visible text nodes from the page body, filters by CSS display/visibility, concatenates trimmed text, applies truncation, and returns the result.
    async execute(args: any, context: ToolContext): Promise<ToolResponse> {
      // Check if browser is available
      if (!context.browser || !context.browser.isConnected()) {
        // If browser is not connected, we need to reset the state to force recreation
        resetBrowserState();
        return createErrorResponse(
          "Browser is not connected. The connection has been reset - please retry your navigation."
        );
      }
    
      // Check if page is available and not closed
      if (!context.page || context.page.isClosed()) {
        return createErrorResponse(
          "Page is not available or has been closed. Please retry your navigation."
        );
      }
      return this.safeExecute(context, async (page) => {
        try {
          const visibleText = await page!.evaluate(() => {
            const walker = document.createTreeWalker(
              document.body,
              NodeFilter.SHOW_TEXT,
              {
                acceptNode: (node) => {
                  const style = window.getComputedStyle(node.parentElement!);
                  return (style.display !== "none" && style.visibility !== "hidden")
                    ? NodeFilter.FILTER_ACCEPT
                    : NodeFilter.FILTER_REJECT;
                },
              }
            );
            let text = "";
            let node;
            while ((node = walker.nextNode())) {
              const trimmedText = node.textContent?.trim();
              if (trimmedText) {
                text += trimmedText + "\n";
              }
            }
            return text.trim();
          });
          // Truncate logic
          const maxLength = typeof args.maxLength === 'number' ? args.maxLength : 20000;
          let output = visibleText;
          let truncated = false;
          if (output.length > maxLength) {
            output = output.slice(0, maxLength) + '\n[Output truncated due to size limits]';
            truncated = true;
          }
          return createSuccessResponse(`Visible text content:\n${output}`);
        } catch (error) {
          return createErrorResponse(`Failed to get visible text content: ${(error as Error).message}`);
        }
      });
    }
  • Tool schema definition including name, description, and empty input schema.
      name: "playwright_get_visible_text",
      description: "Get the visible text content of the current page",
      inputSchema: {
        type: "object",
        properties: {},
        required: [],
      },
    },
  • Dispatch registration in handleToolCall switch statement routing to visibleTextTool.execute.
    case "playwright_get_visible_text":
      return await visibleTextTool.execute(args, context);
  • Instantiation of VisibleTextTool instance used for handling the tool call.
    if (!visibleTextTool) visibleTextTool = new VisibleTextTool(server);
  • src/tools.ts:465-465 (registration)
    Inclusion in BROWSER_TOOLS array for conditional browser launching.
    "playwright_get_visible_text",
Behavior2/5

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

With no annotations provided, the description carries full burden but only states what the tool does without behavioral details. It doesn't mention performance aspects, error handling, or that it might return only visible text (excluding hidden elements), leaving gaps in understanding how it behaves in practice.

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, direct sentence that efficiently conveys the core functionality without any fluff. It's front-loaded and appropriately sized for a simple tool, making it easy to parse quickly.

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

Completeness3/5

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

Given the tool's simplicity (0 parameters, no output schema, no annotations), the description is adequate but minimal. It covers the basic purpose but lacks details on output format, error cases, or integration with sibling tools, which could help in more complex scenarios.

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

Parameters4/5

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

The input schema has 0 parameters with 100% coverage, so no parameter documentation is needed. The description appropriately doesn't add unnecessary param details, but since there are no parameters, it doesn't provide any semantic value beyond the baseline, which is a 4 for zero parameters.

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 action ('Get') and target ('visible text content of the current page'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'playwright_get_visible_html', which retrieves HTML rather than text, so it misses the highest 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, such as 'playwright_get_visible_html' for HTML content or other text-extraction methods. It lacks context about prerequisites, like needing an active page session, which is implied but not stated.

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

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/devskido/customed-playwright'

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