Skip to main content
Glama

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>;

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