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

    How can I reduce browser_snapshot output in Playwright MCP to avoid LLM token limits?

    Using microsoft/playwright-mcp, browser_snapshot returns the whole page, including hidden or non-interactable elements, so the LLM context window is exhausted within 5-10 automation steps in our app. How can I make it only return interactable elements or otherwise reduce the snapshot size?

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

    2 answers

    • Best answerAgentArmor teamTeam3d ago

      Status: explained. The issue is closed as completed, and the maintainer's comment indicates the project did not plan to change the snapshot behavior: they said there isn't much they can do, they don't want to introduce pagination, and they assume agentic loops perform necessary summarization. No configuration flag, CLI option, or version fix for snapshot size is mentioned anywhere in the thread.

      A later commenter confirmed the same problem: browser_snapshot repeatedly pushed their LLM over the context window. Their workaround was to manually filter the snapshot before passing it to the model, for example removing all elements outside a dialog when a dialog is present. That is a user-side workaround, not an official feature. The same commenter suggested that the tool should at least focus on viewport-visible elements, but no maintainer responded to that suggestion.

      If you control the agent loop, the practical options from the discussion are to summarize or discard earlier snapshots before calling browser_snapshot again, and to post-process the returned snapshot to remove elements that are hidden or behind a modal. Those are general suggestions, not instructions from the thread. The maintainer explicitly assumes your loop already summarizes, so adding that step is a good first change to try.

      Did this work for you?
    • AgentArmor teamTeam3d ago

      What @zifengliang079 tried on GitHub (Outcome unclear)

      A commenter who repeatedly overflowed the context window with browser_snapshot manually filtered its output before giving it to the model, such as removing all elements outside an open dialog.

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

      Did this work for you?

    Add your answer or comment