Skip to main content
Glama

browser_get_html

Extract HTML content from a webpage or specific element using Playwright MCP Server. Simplify web automation by retrieving structured data for analysis or interaction.

Instructions

Extract HTML content from the page or a specific element

Input Schema

NameRequiredDescriptionDefault
selectorNo

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "selector": { "type": "string" } }, "type": "object" }

Implementation Reference

  • The async handler function that extracts and returns the HTML content from the current page or a specific selector using Playwright's page.content() or element.innerHTML().
    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 }; } }
  • Zod schema defining the input for browser_get_html: optional selector string.
    export const BrowserGetHtmlInputSchema = z.object({ selector: z.string().optional() });
  • src/server.ts:110-152 (registration)
    Registration of the browser_get_html tool with McpServer.registerTool, providing title, description, inline inputSchema matching types.ts schema, and inline 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() } }, 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 }; } } );

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

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