Skip to main content
Glama

playwright_custom_user_agent

Set a custom User Agent string for browser automation to simulate different devices or browsers during testing and web scraping.

Instructions

Set a custom User Agent for the browser

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
userAgentYesCustom User Agent for the Playwright browser instance

Implementation Reference

  • Handler function that validates the browser's current User-Agent matches the provided argument by evaluating navigator.userAgent on the page.
    async execute(args: CustomUserAgentArgs, context: ToolContext): Promise<ToolResponse> {
      return this.safeExecute(context, async (page) => {
        if (!args.userAgent) {
          return createErrorResponse("Missing required parameter: userAgent must be provided");
        }
    
        try {
          const currentUserAgent = await page.evaluate(() => navigator.userAgent);
    
          if (currentUserAgent !== args.userAgent) {
            const messages = [
              "Page was already initialized with a different User Agent.",
              `Requested: ${args.userAgent}`,
              `Current: ${currentUserAgent}`,
            ];
            return createErrorResponse(messages.join("\n"));
          }
    
          return createSuccessResponse("User Agent validation successful");
        } catch (error) {
          return createErrorResponse(`Failed to validate User Agent: ${(error as Error).message}`);
        }
      });
    }
  • Tool definition with input schema specifying the required 'userAgent' string parameter.
      name: "playwright_custom_user_agent",
      description: "Set a custom User Agent for the browser",
      inputSchema: {
        type: "object",
        properties: {
          userAgent: { type: "string", description: "Custom User Agent for the Playwright browser instance" },
        },
        required: ["userAgent"],
      },
    },
  • Switch case in main tool handler that routes calls to the CustomUserAgentTool instance.
    case "playwright_custom_user_agent":
      return await customUserAgentTool.execute(args, context);
  • Conditional logic that passes the userAgent argument to browser launch settings specifically for this tool.
    userAgent: name === "playwright_custom_user_agent" ? args.userAgent : undefined,
  • src/tools.ts:507-507 (registration)
    Inclusion in BROWSER_TOOLS array which triggers browser initialization for this tool.
    "playwright_custom_user_agent",
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states what the tool does but doesn't describe how it behaves: whether the User Agent persists across navigation, if it affects all tabs, what happens on errors, or if there are side effects. For a mutation tool (setting configuration) with zero annotation coverage, this leaves critical behavioral traits undocumented.

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?

The description is a single, clear sentence that directly states the tool's function with zero wasted words. It's appropriately sized for a simple configuration tool and front-loads the essential information immediately. Every word earns its place.

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?

Given this is a mutation tool (setting browser configuration) with no annotations and no output schema, the description is insufficiently complete. It doesn't cover behavioral aspects like persistence, scope, error handling, or what success looks like. For a tool that modifies browser state, more context is needed to use it safely and effectively.

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?

Schema description coverage is 100%, so the schema already fully documents the single parameter 'userAgent'. The description adds no additional semantic context about the parameter beyond what's in the schema (e.g., format examples, common values, or constraints). This meets the baseline for high schema coverage but doesn't enhance understanding.

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 the action ('Set') and resource ('custom User Agent for the browser'), making the purpose immediately understandable. It distinguishes itself from siblings by focusing on User Agent configuration rather than navigation, interaction, or session management. However, it doesn't specify whether this applies to the current browser instance or future ones, which prevents a perfect score.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., requires an active browser session), when it's appropriate (e.g., for testing different browsers or bypassing detection), or what other tools might be related (e.g., playwright_get for navigation after setting). Without any usage context, the agent must infer everything from the tool name alone.

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/aakashH242/mcp-playwright'

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