Skip to main content
Glama
blackwhite084

Playwright Server MCP

playwright_get_html_content

Retrieve the HTML content of a specific web element using a CSS selector for web automation tasks on the Playwright Server MCP.

Instructions

Get the HTML content of the page

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
selectorYesCSS selector for the element

Implementation Reference

  • The handler class GetHtmlContentToolHandler that executes the tool: checks for active session, locates the element by selector, fetches its inner_html using Playwright, and returns the HTML content.
    class GetHtmlContentToolHandler(ToolHandler): async def handle(self, name: str, arguments: dict | None) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]: if not self._sessions: return [types.TextContent(type="text", text="No active session. Please create a new session first.")] session_id = list(self._sessions.keys())[-1] page = self._sessions[session_id]["page"] selector = arguments.get("selector") html_content = await page.locator(selector).inner_html() return [types.TextContent(type="text", text=f"HTML content of element with selector {selector}: {html_content}")]
  • Input schema definition for the tool, specifying a required 'selector' string parameter.
    types.Tool( name="playwright_get_html_content", description="Get the HTML content of the page", inputSchema={ "type": "object", "properties": { "selector": {"type": "string", "description": "CSS selector for the element"} }, "required": ["selector"] } )
  • Registration of the tool handler in the tool_handlers dictionary used by the call_tool handler.
    tool_handlers = { "playwright_navigate": NavigateToolHandler(), "playwright_screenshot": ScreenshotToolHandler(), "playwright_click": ClickToolHandler(), "playwright_fill": FillToolHandler(), "playwright_evaluate": EvaluateToolHandler(), "playwright_click_text": ClickTextToolHandler(), "playwright_get_text_content": GetTextContentToolHandler(), "playwright_get_html_content": GetHtmlContentToolHandler(), "playwright_new_session":NewSessionToolHandler(), }

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/blackwhite084/playwright-plus-python-mcp'

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