Skip to main content
Glama
b3nw
by b3nw

Get HTML Content

browser_get_html

Extract HTML content from web pages or specific elements to retrieve structured data for analysis, testing, or automation workflows.

Instructions

Extract HTML content from the page or a specific element

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
selectorNo

Implementation Reference

  • The asynchronous handler function that implements the core logic for the 'browser_get_html' tool. It validates input, ensures Playwright connection, retrieves the page, extracts HTML from the full page or specified selector using page.content() or element.innerHTML(), and returns the HTML or an error response.
      async (params: any) => {
        try {
          const input = z.object({
            selector: z.string().optional()
          }).parse(params);
          await this.playwright.ensureConnected();
          
          const page = this.playwright.getPage();
          let html: string;
          
          if (input.selector) {
            const element = await page.locator(input.selector);
            html = await element.innerHTML();
          } else {
            html = await page.content();
          }
          
          return {
            content: [{
              type: 'text',
              text: html
            }]
          };
        } catch (error) {
          return {
            content: [{
              type: 'text',
              text: `HTML extraction failed: ${error instanceof Error ? error.message : String(error)}`
            }],
            isError: true
          };
        }
      }
    );
  • src/server.ts:110-118 (registration)
    The registration call for the 'browser_get_html' tool in the MCP server, specifying the tool name, metadata (title, description), and inline input schema before passing the handler function.
    this.server.registerTool(
      'browser_get_html',
      {
        title: 'Get HTML Content',
        description: 'Extract HTML content from the page or a specific element',
        inputSchema: {
          selector: z.string().optional()
        }
      },
  • Zod input schema definition for the browser_get_html tool, defining optional 'selector' parameter for targeting specific elements.
    export const BrowserGetHtmlInputSchema = z.object({
      selector: z.string().optional()
    });
  • TypeScript type definition inferred from BrowserGetHtmlInputSchema for type-safe input handling.
    export type BrowserGetHtmlInput = z.infer<typeof BrowserGetHtmlInputSchema>;
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the action ('Extract HTML content') but lacks details on permissions, rate limits, error handling, or output format. This leaves significant gaps for a tool that interacts with browser content.

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 extremely concise and front-loaded in a single sentence, with no wasted words. Every part ('Extract HTML content from the page or a specific element') directly contributes to understanding the tool's function.

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 interactions, no annotations, no output schema, and low parameter coverage, the description is incomplete. It doesn't address how HTML is returned, potential errors, or interaction with sibling tools, making it inadequate for safe and effective use.

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

Parameters2/5

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

The input schema has 1 parameter with 0% description coverage, and the description doesn't add any meaning beyond the schema. It mentions 'a specific element' but doesn't explain the 'selector' parameter's purpose, format, or examples, failing to compensate for the low schema coverage.

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 tool's purpose with a specific verb ('Extract') and resource ('HTML content'), and distinguishes the scope ('from the page or a specific element'). However, it doesn't explicitly differentiate from sibling tools like 'browser_evaluate' which might also retrieve content, 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?

No guidance is provided on when to use this tool versus alternatives. The description mentions extracting from 'the page or a specific element,' but it doesn't specify scenarios, prerequisites, or exclusions, such as when to use 'browser_evaluate' for dynamic content instead.

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

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