Skip to main content
Glama

playwright_custom_user_agent

Set a custom User Agent for Playwright browser automation to simulate different browsers or devices, enhancing web testing and interaction scenarios.

Instructions

Set a custom User Agent for the browser

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
userAgentYesCustom User Agent for the Playwright browser instance

Implementation Reference

  • CustomUserAgentTool class with execute method: validates current browser user agent matches the requested one after setting during browser launch.
    export class CustomUserAgentTool extends BrowserToolBase {
      /**
       * Execute the custom user agent tool
       */
      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 schema definition: name, description, and inputSchema requiring userAgent string.
      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"],
      },
    },
  • Dispatch in handleToolCall switch statement calling the tool's execute method.
    case "playwright_custom_user_agent":
      return await customUserAgentTool.execute(args, context);
  • Instantiation of CustomUserAgentTool instance.
    if (!customUserAgentTool) customUserAgentTool = new CustomUserAgentTool(server);
  • Special handling in ensureBrowser to set userAgent only when this tool is called.
    userAgent: name === "playwright_custom_user_agent" ? args.userAgent : undefined,
    headless: args.headless,
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states what the tool does but lacks details on effects (e.g., does it apply to all subsequent requests, require browser restart, or have side effects on other tools). This is a significant gap for a mutation tool with zero annotation coverage.

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, efficient sentence that directly states the tool's function without any wasted words. It is appropriately sized and front-loaded, making it easy to parse quickly.

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 the tool's mutation nature and lack of annotations or output schema, the description is incomplete. It doesn't cover behavioral aspects like persistence, scope, or error handling, which are crucial for an agent to use it correctly in a Playwright context with many sibling tools.

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, with the 'userAgent' parameter clearly documented in the schema. The description adds no additional semantic context beyond implying the parameter's purpose, so it meets the baseline of 3 where the schema does the heavy lifting.

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 target ('custom User Agent for the browser'), making the tool's purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'playwright_navigate' or 'playwright_get', which might also involve browser configuration, though the specific focus on User Agent is reasonably distinct.

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 or in what context it's appropriate. For example, it doesn't mention if this should be set before navigation or if it overrides default User Agents, leaving the agent to infer usage from the 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

Related 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/BhanuTJ93/MCP'

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