Skip to main content
Glama

get-element-properties

Retrieve specific properties and state of a DOM element using a CSS selector and property names array, enabling inspection of live updates during development.

Instructions

Retrieves properties and state information of a specific element

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
selectorYesCSS selector of the element to inspect
propertiesYesArray of property names to retrieve (e.g., ['value', 'checked', 'textContent'])

Implementation Reference

  • Registration of the 'get-element-properties' tool via server.tool() call
    server.tool(
      'get-element-properties',
      'Retrieves properties and state information of a specific element',
  • Full handler implementation for 'get-element-properties' tool - takes CSS selector and properties array, evaluates in browser via page.evaluate(), returns element properties as JSON
    server.tool(
      'get-element-properties',
      'Retrieves properties and state information of a specific element',
      {
        selector: z.string().describe('CSS selector of the element to inspect'),
        properties: z.array(z.string()).describe("Array of property names to retrieve (e.g., ['value', 'checked', 'textContent'])")
      },
      async ({ selector, properties }) => {
        try {
          // Check browser status
          const browserStatus = getContextForOperation();
          if (!browserStatus.isStarted) {
            return browserStatus.error;
          }
    
          // Get current checkpoint ID
          const checkpointId = await getCurrentCheckpointId(browserStatus.page);
    
          // Check if element exists
          await browserStatus.page.waitForSelector(selector, { state: 'visible', timeout: 5000 });
    
          // Retrieve element properties
          const elementProperties = await browserStatus.page.evaluate(({ selector, propertiesToGet }: { selector: string; propertiesToGet: string[] }) => {
            const element = document.querySelector(selector);
            if (!element) return null;
    
            const result: Record<string, unknown> = {};
            propertiesToGet.forEach((prop: string) => {
              result[prop] = (element as unknown as Record<string, unknown>)[prop];
            });
            return result;
          }, { selector, propertiesToGet: properties });
    
          if (!elementProperties) {
            return {
              content: [
                {
                  type: 'text',
                  text: `Element with selector "${selector}" not found`
                }
              ],
              isError: true
            };
          }
    
          // Result message construction
          const resultMessage = {
            selector,
            properties: elementProperties,
            checkpointId
          };
    
          return {
            content: [
              {
                type: 'text',
                text: JSON.stringify(resultMessage, null, 2)
              }
            ]
          };
        } catch (error) {
          const errorMessage = error instanceof Error ? error.message : String(error);
          Logger.error(`Failed to get element properties: ${errorMessage}`);
          return {
            content: [
              {
                type: 'text',
                text: `Failed to get element properties: ${errorMessage}`
              }
            ],
            isError: true
          };
        }
      }
    );
  • Zod input schema for the tool: selector (string) and properties (array of strings)
    {
      selector: z.string().describe('CSS selector of the element to inspect'),
      properties: z.array(z.string()).describe("Array of property names to retrieve (e.g., ['value', 'checked', 'textContent'])")
    },
  • Helper function getContextForOperation used by the handler to retrieve browser context
    const getContextForOperation = (contextId?: string): BrowserStatus => {
      let contextInstance;
      
      if (contextId) {
        contextInstance = contextManager.getContext(contextId);
        if (!contextInstance) {
          return {
            isStarted: false,
            error: {
              content: [
                {
                  type: 'text',
                  text: `Browser '${contextId}' not found. Use 'list-browsers' to see available browsers or 'start-browser' to create one.`
                }
              ],
              isError: true
            }
          };
        }
      } else {
        contextInstance = contextManager.getMostRecentContext();
        if (!contextInstance) {
          return {
            isStarted: false,
            error: {
              content: [
                {
                  type: 'text',
                  text: 'No active browsers found. Use \'start-browser\' to create a browser first.'
                }
              ],
              isError: true
            }
          };
        }
      }
    
      // Note: contextInstance.page is now always defined (never null)
    
      return { isStarted: true, page: contextInstance.page };
    };
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden of behavioral disclosure. It only states 'retrieves' without mentioning side effects, prerequisites (e.g., element must exist on page), or error behavior. For a getter, minimal behavioral context is needed, but the description is still sparse.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence, making it concise and front-loaded. No unnecessary words, but it could benefit from slight elaboration on scope (e.g., current page context).

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The tool lacks an output schema and annotations, and the description provides no information about return format or behavior. Given its simplicity and the presence of many sibling tools, the description is too brief to be complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Both parameters are fully described in the input schema (selector and properties). The description adds no additional meaning beyond the schema, so baseline 3 applies given 100% schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states it retrieves properties and state information of a specific element. However, it does not differentiate from sibling tools like get-element-dimensions or get-element-styles, leaving ambiguity about what 'properties and state information' specifically includes.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. Sibling tools include other element inspection tools (e.g., get-element-html, get-element-styles), and the description lacks any context about preferred use cases or limitations.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/ESnark/blowback'

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