Skip to main content
Glama
devskido

Playwright MCP Server

by devskido

playwright_evaluate

Execute JavaScript code directly in the browser console to automate web interactions, scrape content, or test functionality using Playwright MCP Server.

Instructions

Execute JavaScript in the browser console

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scriptYesJavaScript code to execute

Implementation Reference

  • The EvaluateTool class which contains the execute method that runs page.evaluate(args.script) on the browser page, handles the result, and returns a formatted response. This is the core handler logic for the tool.
    export class EvaluateTool extends BrowserToolBase { /** * Execute the evaluate tool */ async execute(args: any, context: ToolContext): Promise<ToolResponse> { return this.safeExecute(context, async (page) => { const result = await page.evaluate(args.script); // Convert result to string for display let resultStr: string; try { resultStr = JSON.stringify(result, null, 2); } catch (error) { resultStr = String(result); } return createSuccessResponse([ `Executed JavaScript:`, `${args.script}`, `Result:`, `${resultStr}` ]); }); } }
  • The JSON schema definition for the playwright_evaluate tool, specifying the input parameters (script: string). Part of the createToolDefinitions() array.
    { name: "playwright_evaluate", description: "Execute JavaScript in the browser console", inputSchema: { type: "object", properties: { script: { type: "string", description: "JavaScript code to execute" }, }, required: ["script"], }, },
  • Registration in the main handleToolCall switch statement that dispatches calls to the EvaluateTool instance.
    case "playwright_evaluate": return await evaluateTool.execute(args, context);
  • Instantiation of the EvaluateTool class instance in the initializeTools function.
    if (!evaluateTool) evaluateTool = new EvaluateTool(server);
  • src/tools.ts:460-460 (registration)
    Inclusion in the BROWSER_TOOLS array, used to determine browser requirements.
    "playwright_evaluate",

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