Skip to main content
Glama

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

TableJSON Schema
NameRequiredDescriptionDefault
refYesElement ref or CSS selector

Implementation Reference

  • 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 };
        }
      }
    );

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/TacosyHorchata/Pilot'

If you have feedback or need assistance with the MCP directory API, please join our Discord server