Skip to content

[REQUEST] codegen for MCP? #42338

Closed

Description

What's going on?

Could we support codegen in MCP ? Or, better yet, can we allow attaching to the browser extension from the existing npx playwright codegen?

Version

No response

Activity

  1. github-actions commented on Aug 20, 2026

    @github-actions
    Contributor

    Hi, I'm the Playwright bot and I took a first look at this.

    Both of these are already possible today with the Playwright MCP server (npx playwright run-mcp-server / @playwright/mcp) — it's not the classic npx playwright codegen recorder, but it covers the two things you're asking for.

    • Codegen in MCP: every browser action the agent takes comes back with a "Ran Playwright code" section containing the generated Playwright code. It's on by default (TypeScript), and you pick the language with --codegen <typescript|python|java|csharp|none>. On top of that, the @playwright/test MCP backend has a dedicated test-generation flow — generator_setup_page → generator_read_log → generator_write_test — that records what happened and writes a real spec file.
    • Attaching to the extension: the MCP server can drive a running Chrome/Edge via --extension (needs the "Playwright Extension" installed). So you get the "attach to my real browser and generate code" workflow, just from the MCP side rather than the codegen CLI.
    Where this lives in the source
    • --codegen option and the "Ran Playwright code" rendering: packages/playwright-core/src/tools/backend/codegen.ts and response.ts (config field codegen?: 'typescript' | 'python' | 'java' | 'csharp' | 'none').
    • Test generator tools: packages/playwright/src/mcp/test/generatorTools.ts.
    • --extension (attach to a running Edge/Chrome via the Playwright Extension): packages/playwright-core/src/tools/mcp/program.ts.

    So the "codegen for MCP" ask is largely covered. The one genuinely new thing here would be teaching the standalone npx playwright codegen recorder to attach to the extension the same way MCP does — worth clarifying whether that specific UI is what you're after, or whether the MCP --codegen / generator flow already gets you what you need.

    Triaged by the Playwright bot - agent run

  2. lowlyocean commented on Aug 20, 2026

    @lowlyocean
    Author

    I want Playwright to attach to my existing Chrome tab, record what I do, wait for me to tell it I'm finished, and then generate a sequence of playwright commands reflecting my actions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions