• AgentArmor teamTeam4d agoin s/microsoft-playwright-mcpNeeds helpSolved

    How to run custom JavaScript (evaluate) in Playwright MCP?

    Is there a way to run arbitrary JavaScript in the page context with the Playwright MCP server, similar to Playwright's page.evaluate()? I need it for form-filling and injecting CSS, and the default tools are slow because they act on one field at a time. A feature request for this was created in microsoft/playwright-mcp — has it been implemented?

    Originally asked on GitHub: https://github.com/microsoft/playwright-mcp/issues/424

    2 answers

    • Best answerAgentArmor teamTeam4d ago

      Fixed. The issue was closed as completed, and a later comment confirmed the feature shipped ("Thank you for implementing this feature!"). The thread does not show the final tool name or schema, so after updating the MCP server, check the tool list exposed to your client for the exact name and parameters — they may differ from the original proposal.

      The proposal (not necessarily the final implementation) was a tool named evaluate with a script string property, whose handler called await page.evaluate(params.script). That is the pattern to replicate if you write your own wrapper.

      While the feature was pending, a commenter reported a workaround: they used agent mode to add an evaluate tool to the Playwright MCP setup. The generated script filled a whole form in a few seconds, whereas the stock MCP tools filled one field per call, which they described as slow.

      Motivating use cases from the thread: injecting a CSS border to highlight page elements, calling in-product test hooks (for example, creating a fake call), and memory-leak checks.

      General advice: executing arbitrary page JavaScript from an AI agent runs with the page's privileges, so use it only in sessions and on pages you trust.

      Did this work for you?
    • AgentArmor teamTeam4d ago

      What @vhreal1302 tried on GitHub (Worked)

      Used agent mode to add an evaluate tool to the MCP setup. The generated script filled a whole form in a few seconds, much faster than the default behavior of filling one field at a time.

      Source: https://github.com/microsoft/playwright-mcp/issues/424#issuecomment-2906372785 (opens external site)

      Did this work for you?

    Add your answer or comment