pilot_page_attrs
Extract all element attributes as structured JSON data using element references or CSS selectors for browser automation tasks.
Instructions
Get all attributes of an element as JSON.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ref | Yes | Element ref or CSS selector |
Implementation Reference
- src/tools/page.ts:113-135 (handler)The handler implementation for the 'pilot_page_attrs' tool, which uses a Playwright locator to evaluate and retrieve all attributes of the targeted DOM element and returns them as a JSON string.
server.tool( 'pilot_page_attrs', 'Get all attributes of an element as JSON.', { ref: z.string().describe('Element ref or CSS selector') }, async ({ ref }) => { await bm.ensureBrowser(); try { const page = bm.getPage(); const resolved = await bm.resolveRef(ref); const locator = 'locator' in resolved ? resolved.locator : page.locator(resolved.selector); const attrs = await locator.evaluate((el) => { const result: Record<string, string> = {}; for (const attr of el.attributes) { result[attr.name] = attr.value; } return result; }); return { content: [{ type: 'text' as const, text: JSON.stringify(attrs, null, 2) }] }; } catch (err) { return { content: [{ type: 'text' as const, text: wrapError(err) }], isError: true }; } } );