getPageText
Extract text content from web pages for web scraping, testing, and browser automation tasks using Playwright.
Instructions
Get the text content of the current page
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/controllers/playwright.ts:278-291 (handler)Implements the core logic to retrieve the text content from the current page's body element using Playwright.async getPageText(): Promise<string> { try { if (!this.isInitialized()) { throw new Error('Browser not initialized'); } this.log('Getting page text content'); const text = await this.state.page?.innerText('body'); this.log('Page text retrieved'); return text || ''; } catch (error: any) { console.error('Get page text error:', error); throw new BrowserError('Failed to get page text', 'Check if the page is loaded'); } }
- src/server.ts:93-101 (schema)Defines the tool schema for MCP, specifying name, description, and input schema (no parameters required).const GET_PAGE_TEXT_TOOL: Tool = { name: "getPageText", description: "Get the text content of the current page", inputSchema: { type: "object", properties: {}, required: [] } };
- src/server.ts:523-523 (registration)Registers the getPageText tool in the tools object that is passed to the MCP server's capabilities.getPageText: GET_PAGE_TEXT_TOOL,
- src/server.ts:686-690 (handler)MCP server request handler (dispatcher) that invokes the controller method and formats the response.case 'getPageText': { const text = await playwrightController.getPageText(); return { content: [{ type: "text", text }] };