Skip to main content
Glama
blackwhite084

Playwright Server MCP

playwright_evaluate

Execute JavaScript code directly in the browser console to automate web interactions, extract data, or manipulate page elements during web automation tasks.

Instructions

Execute JavaScript in the browser console

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scriptYesJavaScript code to execute

Implementation Reference

  • The EvaluateToolHandler class provides the core implementation for executing JavaScript code in the browser context using Playwright's page.evaluate method.
    class EvaluateToolHandler(ToolHandler): async def handle(self, name: str, arguments: dict | None) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]: if not self._sessions: return [types.TextContent(type="text", text="No active session. Please create a new session first.")] session_id = list(self._sessions.keys())[-1] page = self._sessions[session_id]["page"] script = arguments.get("script") result = await page.evaluate(script) return [types.TextContent(type="text", text=f"Evaluated script, result: {result}")]
  • The input schema defines the expected arguments for the playwright_evaluate tool, requiring a 'script' string.
    types.Tool( name="playwright_evaluate", description="Execute JavaScript in the browser console", inputSchema={ "type": "object", "properties": { "script": {"type": "string", "description": "JavaScript code to execute"} }, "required": ["script"] } ),
  • The tool_handlers dictionary registers an instance of EvaluateToolHandler for the 'playwright_evaluate' tool name, used by the call_tool handler.
    tool_handlers = { "playwright_navigate": NavigateToolHandler(), "playwright_screenshot": ScreenshotToolHandler(), "playwright_click": ClickToolHandler(), "playwright_fill": FillToolHandler(), "playwright_evaluate": EvaluateToolHandler(), "playwright_click_text": ClickTextToolHandler(), "playwright_get_text_content": GetTextContentToolHandler(), "playwright_get_html_content": GetHtmlContentToolHandler(), "playwright_new_session":NewSessionToolHandler(), }

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/blackwhite084/playwright-plus-python-mcp'

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