Skip to main content
Glama
jomon003

PlayMCP Browser Automation Server

by jomon003

getElementContent

Extract HTML and text content from web elements using CSS selectors for web scraping and automation tasks.

Instructions

Get the HTML and text content of a specific element

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
selectorYes

Implementation Reference

  • The core handler function in PlaywrightController that retrieves the HTML and text content of an element using document.querySelector and returns it as an object.
    async getElementContent(selector: string): Promise<{html: string, text: string}> { try { if (!this.isInitialized()) { throw new Error('Browser not initialized'); } this.log('Getting element content for selector:', selector); const content = await this.state.page?.evaluate((sel) => { const element = document.querySelector(sel); if (!element) { throw new Error(`Element not found: ${sel}`); } return { html: element.innerHTML, text: element.textContent || '' }; }, selector); this.log('Element content retrieved'); return content || {html: '', text: ''}; } catch (error: any) { console.error('Get element content error:', error); throw new BrowserError('Failed to get element content', 'Check if the element exists'); } }
  • Tool schema definition specifying the input as an object with a required 'selector' string property.
    const GET_ELEMENT_CONTENT_TOOL: Tool = { name: "getElementContent", description: "Get the HTML and text content of a specific element", inputSchema: { type: "object", properties: { selector: { type: "string" } }, required: ["selector"] } };
  • src/server.ts:532-532 (registration)
    Registration of the tool in the tools object passed to the MCP server capabilities.
    getElementContent: GET_ELEMENT_CONTENT_TOOL,
  • MCP server request handler case that validates input, calls the controller handler, and returns the result as JSON.
    case 'getElementContent': { if (!args.selector) { return { content: [{ type: "text", text: "Selector is required" }], isError: true }; } const content = await playwrightController.getElementContent(args.selector as string); return { content: [{ type: "text", text: JSON.stringify(content, null, 2) }] }; }

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/jomon003/PlayMCP'

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