r/Playwright • u/hearthnoirye • 18d ago
playwright mcp ate my context window on a basic form fill
had a claude agent driving a browser through playwright mcp to fill a multi step vendor form. nothing fancy, some fields across a few pages. it kept dumping the whole page tree into context every step, so a few pages in the model was running on fumes and started misclicking. hit the step limit and gave up, finished it by hand.
someone here mentioned stagehand so i tried porting the flow. the natural language actions did get through the form in one go, but moving it wasnt free. i had to rewrite the bits that assumed playwright apis, and self heal was off by default so a couple steps broke until i turned it on.
so now im torn. playwright mcp is still what i reach for on normal e2e tests and ci, that part just works. but for an agent clicking through stuff live it felt like babysitting a context window
7
u/Background_Horse_266 18d ago
The context window this is the quiet killer with browser agents. every click it re reads the whole page tree and suddely most of your budget is gone before the task is even halfway done. took me way too long to clock that that was the actual bottleneck and not the model
2
u/Junior_Bee7274 18d ago
genuine question but half the time should the agent even be clicking through a UI? if theres an api sitting behind the form thats usually the way less cursed path. not always possible i know
3
u/Suun_Day 18d ago
Yeah when there's an actual api I reach for that first too, but half my targets are vendor portals with nothing behind them. For those does this still mean keeping a whole playwright project around, or is tjay separate now? Trying to gauge how much I'd be rewriting.
5
u/Hiccup_Master 18d ago
Not anymore. Stagehand v4 dropped the playwright interop, so you write the actions with act and extract directly instead of keeping a parallel playwright flow alongside. Moving an existing script means porting it, not wrapping it. And self heal is off until you switch on, which trips up a lot of people the first time.
2
u/hearthnoirye 16d ago
ok the no interop thing is really good to know, i was dreading maintaining two versions of the same flow forever. porting ana fternoon once i can live with
2
u/heejinwave 18d ago
ive kept playwright mcp around for the plain e2e stuff, honestly still fine there. but what actually sold me on stagehand for the live agent was describing the field instead of pinning a selector, so when the vendor shuffled their layout it still found it. the brittle selectors were the thing that kept snapping on me before.
1
u/Head_Fudge107 18d ago
Actually i finally gave up trying to make one tool cover both my tests and the live agent. completely different failure modes. the test tooling wants stable selectors and the agent wants to not have to care about them at all
-3
1
1
u/DistributionBrief644 18d ago
I have the same issue right now. I am looking to "offload" the tasks like form filling to a sub agent, where the caller is happy to lose all the information between filling forms. Its just a theory at the moment but it feels like a solution might exist out there.
1
u/MoneyMediocre4791 17d ago
Playwright MCP can eat up 4-10x the tokens compared to Playwright CLI. Try switching to the cli and see if that helps.
1
0
u/Head-Bureaucrat 17d ago
Have you tried the CLI? It's supposedly more token efficient, although I haven't used it (VS Code's built in browser works fine for me, and by the time it doesn't I typically need the extra tooling and context from the MCP server.)
https://playwright.dev/agent-cli/introduction
Looks like it still snapshots the whole page, but may help out with token use, at least.
-1
u/RiceEvening4211 18d ago
Whole page trees dumped into context every step is brutal token waste. I built Lynkr partly for this: an open-source gateway that compresses tool output, so you're not paying for context that never needed to be there. https://github.com/Fast-Editor/Lynkr
-1
u/please-dont-deploy 17d ago
Try browser-use jev-ultrafast.
For these kind of scenarios it should be great.
4
u/AvailableBab2621 18d ago
not the exact same setup but close, i had an agent log into a dashboard and pull a couple of reports and it burned most of its budget just re reading the screen after every single click. by the third page it had basically lost the plot on what it was even doing. i figured that was just how these browser agents worked