get-page-visible-text
Extract visible text content from web pages to analyze displayed information for browser automation tasks.
Instructions
Get the visible text content of the page
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/handlers/automation.ts:41-74 (handler)The core handler function for 'get-page-visible-text' tool. It evaluates JavaScript on the current page using Puppeteer's evaluate method to traverse the DOM with TreeWalker, collecting text from visible nodes (display != none, visibility != hidden), trims and joins them with newlines.async getPageVisibleText() { browser.checkConnected(); try { const visibleText = await browser.pageInstance!.evaluate(() => { const walker = document.createTreeWalker( document.body, NodeFilter.SHOW_TEXT, { acceptNode: (node) => { const style = window.getComputedStyle( node.parentElement! ); return style.display !== 'none' && style.visibility !== 'hidden' ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT; }, } ); let text = ''; let node; while ((node = walker.nextNode())) { const trimmedText = node.textContent?.trim(); if (trimmedText) { text += trimmedText + '\n'; } } return text.trim(); }); return `Visible text content:\n${visibleText}`; } catch (error) { return `Failed to get visible text content: ${(error as Error).message}`; } },
- src/utils/toolRegister.ts:62-63 (registration)Registers the 'get-page-visible-text' tool on the MCP server, using empty input schema and the wrapped automationHandlers.getPageVisibleText handler.server.tool('get-page-visible-text', 'Get the visible text content of the page', schemas.emptySchema.shape, wrapHandler(automationHandlers.getPageVisibleText));
- src/types/schemas.ts:163-164 (schema)The emptySchema used as input schema for 'get-page-visible-text' tool (no parameters required), defined using Zod.// Empty Schema emptySchema: z.object({}).strict(),