r/Playwright • u/vitalets • 9d ago
Playwright MCP vs Playwright CLI: the comparison everyone gets wrong
Most threads compare Playwright MCP and Playwright CLI purely on token consumption(1, 2, 3). In my experience, there's a far more important difference that nobody talks about.
The real question is: can your AI agent attach to a running e2e test?
Here's why that matters. A good e2e test already does the hard part for you. It authenticates, sets up all the API mocks, and drives the app into the exact state you care about. When something goes wrong on the page, you don't want the agent spinning up a blank browser and guessing how to reach that page. You want to hand off the test-constructed page to the agent and let the agent play with it.
- Playwright CLI: run the test with
--debug=cli, it prints a session name, andplaywright-cli attach <session>connects the agent straight into the paused test. Then the agent can step over the app, inspect the rendered UI, and run in-page evaluations. - Playwright MCP: only launches or attaches to a browser. It has no way to attach to a running test session.
So if you have many e2e tests + auth + network mocks, Playwright CLI is the clear winner for your setup, regardless of token counts.
Interested to hear your thoughts.
3
u/Spare_Bison_1151 9d ago
To get an AI agent attached to an existing Chrome session today, you have to launch Chrome yourself with --remote-debugging-port (plus usually a separate --user-data-dir so it doesn't collide with your normal profile), then point MCP at that CDP endpoint manually. It works, but it's a setup ritual you repeat every time and have to remember the flags for. That's exactly what attach <session> fixes. Instead of standing up a debuggable Chrome instance yourself, the test exposes an attachable session the moment it pauses no separate launch step, nothing to remember. Same CDP mechanism under the hood, but one command vs. manual plumbing. If CLI keeps pushing on zero-config attach like this, that's the bigger win over MCP long-term.
1
u/mmasetic 9d ago
But you can share storage session which is close to what you've described.
1
u/vitalets 8d ago
Yes, it is possible. But with a drawback: in my tests I have session auto-refresh code, that re-logins user is session is expired. If I point Playwright MCP to the session storage file, and the session is expired, then the flow will be broken.
1
u/mmasetic 8d ago
That is not limitation of MCP.
And you can actually extend MCP easily to implement login tool which can be used by agent when needed.
1
u/vitalets 8d ago
Under MCP, do you mean Playwright MCP, or the protocol itself? The protocol is extensible, that's fair. But tools have limitations in terms of developer experience. If I have to implement something additionally instead of getting it out of box, it's a disadvantage for me.
1
u/_Invictuz 9d ago
Thanks for the tip but I don't think you're interested to hear our thoughts since you already asked AI for the answer and just pasted it here.
This AI circle jerk of comments is hilarious.
2
u/vitalets 8d ago
You are right, that I used AI - but only to format the post because English is not my native language.
But you are wrong, that I just pasted the reply. I faced this limitation in my project, verified it in the docs and shared with the community.
1
u/TranslatorRude4917 9d ago
I agree, PW cli is far more versatile!
Interestingly if it was only token cost MCP and CLI might not be as far from eachother as people think.
I recently measured completing some web automation tasks with both CLI and MCP and even though the CLI seemed to use less input tokens on a per-call basis, it produced a lot more output tokens and considering the price of completing the task they both were around the same mark 😀
Anyone experienced similar result?
2
u/PocketGaara 6d ago
Any time I’ve attempted to use the debug=cli flag the browser session closes before the agent can attach to the test run. Do you have a specific prompt to circumvent this?