pilot_page_html
Get innerHTML of a CSS selector or ref; returns full page HTML if no selector given.
Instructions
Get innerHTML of a selector/ref, or full page HTML if none provided.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ref | No | Element ref or CSS selector | |
| max_chars | No | Max characters to return (default: 20000) |
Implementation Reference
- src/tools/page.ts:48-74 (handler)The actual handler implementation of pilot_page_html tool. Invoked by server.tool('pilot_page_html', ...). Gets innerHTML of a selector/ref, or full page HTML if no ref provided. Uses truncate() helper to cap output.
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'), max_chars: z.number().optional().describe('Max characters to return (default: 20000)'), }, async ({ ref, max_chars }) => { 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: truncate(html, max_chars) }] }; } const html = await page.innerHTML(resolved.selector); return { content: [{ type: 'text' as const, text: truncate(html, max_chars) }] }; } const html = await page.content(); return { content: [{ type: 'text' as const, text: truncate(html, max_chars) }] }; } catch (err) { return { content: [{ type: 'text' as const, text: wrapError(err) }], isError: true }; } } ); - src/tools/page.ts:48-54 (schema)The schema for pilot_page_html: defines optional 'ref' (string) and 'max_chars' (number) parameters via Zod.
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'), max_chars: z.number().optional().describe('Max characters to return (default: 20000)'), }, - src/tools/register.ts:73-80 (registration)Registration of all tools including pilot_page_html via registerPageTools(effectiveServer, bm) called inside registerAllTools.
export function registerAllTools(server: McpServer, bm: BrowserManager, profile: ToolProfile = 'full'): void { const allowed = PROFILE_TOOLS[profile]; const effectiveServer = allowed ? createFilteredServer(server, allowed) : server; registerNavigationTools(effectiveServer, bm); registerSnapshotTools(effectiveServer, bm); registerInteractionTools(effectiveServer, bm); registerPageTools(effectiveServer, bm); - src/tools/register.ts:44-46 (registration)Tool listed in STANDARD_TOOLS set (and thus available in 'standard' and 'full' profiles).
// page reading 'pilot_page_text', 'pilot_page_html', // visual - src/tools/page.ts:22-28 (helper)The truncate() helper function used by pilot_page_html to cap output at max_chars (default 20000).
function truncate(text: string, maxChars?: number): string { const limit = maxChars || DEFAULT_MAX_CHARS; if (text.length <= limit) return text; const truncated = text.slice(0, limit); const remaining = text.length - limit; return truncated + `\n\n── truncated: ${remaining} chars not shown (use max_chars to increase) ──`; }