pilot_page_html
Extract HTML content from web pages using CSS selectors or retrieve full page HTML for web scraping and automation tasks.
Instructions
Get innerHTML of a selector/ref, or full page HTML if none provided.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ref | No | Element ref or CSS selector |
Implementation Reference
- src/tools/page.ts:36-58 (handler)The handler function for the `pilot_page_html` tool, which retrieves either a specific element's innerHTML or the full page content using Playwright.
server.tool( 'pilot_page_html', 'Get innerHTML of a selector/ref, or full page HTML if none provided.', { ref: z.string().optional().describe('Element ref or CSS selector') }, async ({ ref }) => { await bm.ensureBrowser(); try { const page = bm.getPage(); if (ref) { const resolved = await bm.resolveRef(ref); if ('locator' in resolved) { const html = await resolved.locator.innerHTML({ timeout: 5000 }); return { content: [{ type: 'text' as const, text: html }] }; } const html = await page.innerHTML(resolved.selector); return { content: [{ type: 'text' as const, text: html }] }; } const html = await page.content(); return { content: [{ type: 'text' as const, text: html }] }; } catch (err) { return { content: [{ type: 'text' as const, text: wrapError(err) }], isError: true }; } }