Skip to main content
Glama
devskido

Playwright MCP Server

by devskido

playwright_custom_user_agent

Set a custom User Agent for browser automation within the Playwright MCP Server, enabling tailored web interactions for scraping, testing, or simulating specific devices.

Instructions

Set a custom User Agent for the browser

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
userAgentYesCustom User Agent for the Playwright browser instance

Implementation Reference

  • Implementation of CustomUserAgentTool: validates that the browser context was launched with the specified userAgent by checking navigator.userAgent.
    import { BrowserToolBase } from './base.js'; import type { ToolContext, ToolResponse } from '../common/types.js'; import { createSuccessResponse, createErrorResponse } from '../common/types.js'; interface CustomUserAgentArgs { userAgent: string; } /** * Tool for validating custom User Agent settings */ 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: defines 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"], }, },
  • Tool dispatch/registration in main handleToolCall switch statement.
    case "playwright_custom_user_agent": return await customUserAgentTool.execute(args, context);
  • Special handling: passes userAgent from args to browser launch context when this tool is called.
    const browserSettings = { viewport: { width: args.width, height: args.height }, userAgent: name === "playwright_custom_user_agent" ? args.userAgent : undefined, headless: args.headless, browserType: args.browserType || 'chromium'
  • src/tools.ts:464-464 (registration)
    Added to BROWSER_TOOLS array, triggering browser launch before execution.
    "playwright_custom_user_agent",

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/devskido/customed-playwright'

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