get_rendered_html
Fetch fully rendered HTML content from web pages requiring JavaScript execution, including single-page applications and dynamic content.
Instructions
Fetches fully rendered HTML content using a headless browser, including JavaScript-generated content. Essential for modern web applications, single-page applications (SPAs), or any content that requires client-side rendering to be complete.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | URL of the target web page that requires JavaScript execution or dynamic content rendering. |
Implementation Reference
- src/index.ts:68-81 (registration)Registers the get_rendered_html tool with its description and input schema (requires 'url').{ name: "get_rendered_html", description: "Fetches fully rendered HTML content using a headless browser, including JavaScript-generated content. Essential for modern web applications, single-page applications (SPAs), or any content that requires client-side rendering to be complete.", inputSchema: { type: "object", properties: { url: { type: "string", description: "URL of the target web page that requires JavaScript execution or dynamic content rendering." } }, required: ["url"] } },
- src/index.ts:135-142 (handler)Tool handler case in CallToolRequestSchema that fetches rendered HTML via getHtmlString and returns it as text content.case "get_rendered_html": { return { content: [{ type: "text", text: (await getHtmlString(url)) }] }; }
- src/index.ts:174-210 (handler)Executes the tool logic: launches headless Chromium browser with Playwright, navigates to URL, waits for DOM content loaded, retrieves full HTML content, handles errors and cleanup.async function getHtmlString(request_url: string): Promise<string> { let browser: Browser | null = null; let page: Page | null = null; try { browser = await chromium.launch({ headless: true, // args: ['--single-process'], }); const context = await browser.newContext(); page = await context.newPage(); await page.goto(request_url, { waitUntil: 'domcontentloaded', timeout: TIMEOUT, }); const htmlString = await page.content(); return htmlString; } catch (error) { console.error(`Failed to fetch HTML for ${request_url}:`, error); return ""; } finally { if (page) { try { await page.close(); } catch (e) { console.error("Error closing page:", e); } } if (browser) { try { await browser.close(); } catch (error) { console.error('Error closing browser:', error); } } } }
- src/index.ts:71-80 (schema)Input schema defining the required 'url' parameter as a string.inputSchema: { type: "object", properties: { url: { type: "string", description: "URL of the target web page that requires JavaScript execution or dynamic content rendering." } }, required: ["url"] }