Skip to main content
Glama

browser_get_element_text

Extract text content from a specified HTML element using a selector and instance ID within a concurrent browser environment. Supports custom timeouts for reliable results.

Instructions

Get element text content

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
instanceIdYesInstance ID
selectorYesElement selector
timeoutNoTimeout in milliseconds

Implementation Reference

  • Core implementation of the browser_get_element_text tool. Retrieves the text content of the specified element using Playwright's page.textContent method, with instance validation and error handling.
    private async getElementText(instanceId: string, selector: string, timeout: number): Promise<ToolResult> { const instance = this.browserManager.getInstance(instanceId); if (!instance) { return { success: false, error: `Instance ${instanceId} not found` }; } try { const text = await instance.page.textContent(selector, { timeout }); return { success: true, data: { selector, text }, instanceId }; } catch (error) { return { success: false, error: `Get element text failed: ${error instanceof Error ? error.message : error}`, instanceId }; } }
  • Input schema definition for the browser_get_element_text tool, specifying parameters like instanceId, selector, and optional timeout.
    { name: 'browser_get_element_text', description: 'Get element text content', inputSchema: { type: 'object', properties: { instanceId: { type: 'string', description: 'Instance ID' }, selector: { type: 'string', description: 'Element selector', }, timeout: { type: 'number', description: 'Timeout in milliseconds', default: 30000 } }, required: ['instanceId', 'selector'] }
  • src/tools.ts:556-557 (registration)
    Dispatch registration in the executeTools switch statement, mapping the tool name to its handler function.
    case 'browser_get_element_text': return await this.getElementText(args.instanceId, args.selector, args.timeout || 30000);
  • src/server.ts:40-45 (registration)
    MCP server handler for listing tools, which includes browser_get_element_text via BrowserTools.getTools().
    this.server.setRequestHandler(ListToolsRequestSchema, async () => { const tools = this.browserTools.getTools(); return { tools: tools, }; });
  • src/server.ts:48-75 (registration)
    MCP server handler for calling tools, delegating to BrowserTools.executeTools which handles browser_get_element_text.
    this.server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; try { const result = await this.browserTools.executeTools(name, args || {}); if (result.success) { return { content: [ { type: 'text', text: JSON.stringify(result.data, null, 2), }, ], }; } else { throw new McpError(ErrorCode.InternalError, result.error || 'Tool execution failed'); } } catch (error) { if (error instanceof McpError) { throw error; } throw new McpError( ErrorCode.InternalError, `Tool execution failed: ${error instanceof Error ? error.message : error}` ); } });

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/sailaoda/concurrent-browser-mcp'

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