Skip to main content
Glama
BrowserGenie

BrowserGenie MCP Server

by BrowserGenie

force_pseudo_state

Force CSS pseudo-states (hover, focus, active, visited, focus-within, focus-visible) on an element and retrieve computed styles for testing state styles without actual interaction.

Instructions

Force a CSS pseudo-state (hover, focus, active, visited, focus-within, focus-visible) on an element and read the resulting computed styles. Useful for testing CSS state styles without actual interaction.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
selectorYesCSS selector for the element
pseudoStateYesPseudo-state to force
tabIdNoTarget tab ID (defaults to currently active tab)
apiKeyNoAPI key for authentication if enabled

Implementation Reference

  • The handler for the force_pseudo_state tool. It sends a 'force_pseudo_state' command via WebSocket bridge with CSS selector and pseudo-state parameters, then returns the resulting computed styles.
    server.tool(
      'force_pseudo_state',
      'Force a CSS pseudo-state (hover, focus, active, visited, focus-within, focus-visible) on an element and read the resulting computed styles. Useful for testing CSS state styles without actual interaction.',
      {
        selector: z.string().describe('CSS selector for the element'),
        pseudoState: z.enum(['hover', 'focus', 'active', 'visited', 'focus-within', 'focus-visible']).describe('Pseudo-state to force'),
        tabId: z.number().optional().describe('Target tab ID (defaults to currently active tab)'),
        apiKey: z.string().optional().describe('API key for authentication if enabled'),
      },
      async ({ selector, pseudoState, tabId, apiKey }) => {
        const result = await bridge.sendCommand({
          command: 'force_pseudo_state',
          params: { selector, pseudoState },
          tabId,
          apiKey,
          timeout: LONG_TIMEOUT,
        });
        if (!result.success) {
          return { content: [{ type: 'text', text: `Error: ${result.error?.message}` }], isError: true };
        }
        return { content: [{ type: 'text', text: JSON.stringify(result.data, null, 2) }] };
      }
    );
  • Zod schema defining input validation: selector (string), pseudoState (enum of hover/focus/active/visited/focus-within/focus-visible), optional tabId (number), optional apiKey (string).
    {
      selector: z.string().describe('CSS selector for the element'),
      pseudoState: z.enum(['hover', 'focus', 'active', 'visited', 'focus-within', 'focus-visible']).describe('Pseudo-state to force'),
      tabId: z.number().optional().describe('Target tab ID (defaults to currently active tab)'),
      apiKey: z.string().optional().describe('API key for authentication if enabled'),
    },
  • Registration of the interaction tools (including force_pseudo_state) via registerInteractionTools called in registerAllTools.
    registerInteractionTools(server, bridge);
  • The registerInteractionTools function that registers force_pseudo_state (and hover_and_inspect, get_tooltip_text) as an MCP tool on the server.
    export function registerInteractionTools(server: McpServer, bridge: WebSocketBridge) {
      server.tool(
        'hover_and_inspect',
        'Hover over an element and capture any resulting DOM or style changes. Useful for testing dropdown menus, tooltips, and hover effects.',
        {
          target: targetSchema.describe('Element or position to hover over'),
          captureChanges: z.boolean().optional().default(true).describe('Capture and return DOM/style changes after hover'),
          tabId: z.number().optional().describe('Target tab ID (defaults to currently active tab)'),
          apiKey: z.string().optional().describe('API key for authentication if enabled'),
        },
        async ({ target, captureChanges, tabId, apiKey }) => {
          const result = await bridge.sendCommand({
            command: 'hover_and_inspect',
            params: { target, captureChanges },
            tabId,
            apiKey,
            timeout: LONG_TIMEOUT,
          });
          if (!result.success) {
            return { content: [{ type: 'text', text: `Error: ${result.error?.message}` }], isError: true };
          }
          return { content: [{ type: 'text', text: JSON.stringify(result.data, null, 2) }] };
        }
      );
    
      server.tool(
        'force_pseudo_state',
        'Force a CSS pseudo-state (hover, focus, active, visited, focus-within, focus-visible) on an element and read the resulting computed styles. Useful for testing CSS state styles without actual interaction.',
        {
          selector: z.string().describe('CSS selector for the element'),
          pseudoState: z.enum(['hover', 'focus', 'active', 'visited', 'focus-within', 'focus-visible']).describe('Pseudo-state to force'),
          tabId: z.number().optional().describe('Target tab ID (defaults to currently active tab)'),
          apiKey: z.string().optional().describe('API key for authentication if enabled'),
        },
        async ({ selector, pseudoState, tabId, apiKey }) => {
          const result = await bridge.sendCommand({
            command: 'force_pseudo_state',
            params: { selector, pseudoState },
            tabId,
            apiKey,
            timeout: LONG_TIMEOUT,
          });
          if (!result.success) {
            return { content: [{ type: 'text', text: `Error: ${result.error?.message}` }], isError: true };
          }
          return { content: [{ type: 'text', text: JSON.stringify(result.data, null, 2) }] };
        }
      );
    
      server.tool(
        'get_tooltip_text',
        'Hover over an element and extract any tooltip text. Checks title attribute, aria-describedby, aria-labelledby, CSS tooltips, and custom tooltip components.',
        {
          target: targetSchema.describe('Element or position to hover over'),
          waitForTooltip: z.number().optional().default(200).describe('Time to wait after hover for tooltip animations (ms)'),
          tabId: z.number().optional().describe('Target tab ID (defaults to currently active tab)'),
          apiKey: z.string().optional().describe('API key for authentication if enabled'),
        },
        async ({ target, waitForTooltip, tabId, apiKey }) => {
          const result = await bridge.sendCommand({
            command: 'get_tooltip_text',
            params: { target, waitForTooltip },
            tabId,
            apiKey,
            timeout: LONG_TIMEOUT,
          });
          if (!result.success) {
            return { content: [{ type: 'text', text: `Error: ${result.error?.message}` }], isError: true };
          }
          return { content: [{ type: 'text', text: JSON.stringify(result.data, null, 2) }] };
        }
      );
    }
  • WebSocketBridge.sendCommand helper used by the handler to dispatch the force_pseudo_state command and await the response.
    async sendCommand(cmd: BridgeCommand): Promise<BridgeResponse> {
      if (!this.isConnected()) {
        return {
          success: false,
          error: {
            code: 'NOT_CONNECTED',
            message: 'Chrome extension is not connected. Ensure the extension is installed, enabled, and the browser is running.',
          },
        };
      }
    
      const id = crypto.randomUUID();
      const timeout = cmd.timeout ?? DEFAULT_TIMEOUT;
    
      return new Promise<BridgeResponse>((resolve, reject) => {
        const timer = setTimeout(() => {
          this.pending.delete(id);
          resolve({
            success: false,
            error: {
              code: 'TIMEOUT',
              message: `Command '${cmd.command}' timed out after ${timeout}ms`,
            },
          });
        }, timeout);
    
        this.pending.set(id, { resolve, reject, timer });
    
        const message = {
          id,
          type: 'request',
          command: cmd.command,
          params: cmd.params,
          tabId: cmd.tabId,
          apiKey: cmd.apiKey,
          timestamp: Date.now(),
        };
    
        this.client!.send(JSON.stringify(message));
      });
    }
Behavior3/5

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

No annotations are provided, so the description carries the full burden. It explains the core behavior (forcing a state and reading styles) but lacks details on side effects (e.g., whether the state is temporary, if it affects other elements, or cleanup). The apiKey parameter suggests authentication needs, but this is not addressed.

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

Conciseness5/5

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

Two sentences: the first states the action and resources, the second states the use case. Every word serves a purpose, and the most important information is front-loaded. No redundant or vague phrasing.

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

Completeness3/5

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

The description covers the core action well but does not specify the return value format or structure (no output schema). It also does not explain the optional parameters (tabId, apiKey) or their defaults. For a tool that returns computed styles, additional context about the output would be helpful.

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?

The input schema has 100% description coverage for all parameters. The description adds overall purpose but does not elaborate on individual parameters beyond what the schema provides. Baseline 3 is appropriate as the schema already documents each parameter.

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

Purpose5/5

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

The description clearly states it forces a CSS pseudo-state and reads computed styles. It lists specific pseudo-states and the use case for testing state styles without interaction, distinguishing it from siblings like hover_element and get_computed_styles.

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

Usage Guidelines4/5

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

The description implies when to use the tool ('testing CSS state styles without actual interaction'), providing clear context. However, it does not explicitly mention when not to use it or alternatives, though the sibling tools make these evident.

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/BrowserGenie/mcp'

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