Skip to content

Internal locator('body') strict-mode check crashes every tool call on pages with malformed nested <body> markup #42100

Description

@nitrocode

Environment

  • playwright-mcp 0.0.78 (also reproduced on @playwright/mcp@latest via npx, and a
    second unrelated MCP server wrapping the same core)
  • macOS 25.5.0 (Darwin), arm64
  • Node v26.5.0
  • Reproduced with --isolated, --caps vision, and --snapshot-mode none — none of
    these flags change the behavior

Summary
Every tool call except browser_navigate fails with:

Error: strict mode violation: locator('body') resolved to 2 elements:
    1) <body>…</body> aka locator('body').first()
    2) <body>…</body> aka locator('body').nth(1)

on any page whose HTML has more than one element in the DOM (in our case,
a real-world SaaS app with invalid nested ... markup
in its page template — confirmed via a standalone Playwright script, independent
of playwright-mcp, that document.querySelectorAll('body') returns 2 connected
nodes on the affected page).

browser_navigate always succeeds (even navigating onto the affected page). Every
other tool (browser_take_screenshot, browser_close, browser_run_code_unsafe,
click, etc.) fails identically once that page is loaded, because whatever internal
readiness/snapshot check runs on each tool call resolves body via an implicit
strict-mode locator.

Ruled out during investigation

  • Stale install / version mismatch (npx cache, npm latest, Homebrew all pinned
    to 0.0.78)
  • Specific MCP server implementation (reproduced identically on two independent
    playwright-mcp-based servers)
  • Browser extensions (isolated automation profile launches Chrome with
    --disable-extensions explicitly; bug persists)
  • Stale profile/process state (cleared all profiles, used a fresh --isolated
    in-memory profile; bug persists)
  • Interaction mode (--caps vision uses coordinate-based tools instead of the
    accessibility tree; bug persists)
  • Response snapshot generation (--snapshot-mode none disables the AI-facing
    snapshot entirely; bug persists — confirming the body-locator check is part
    of core tool/action handling, not the optional snapshot feature)

Repro (works on other sites)

  • https://www.google.com — all tools work normally
  • https://www.yahoo.com — all tools work normally (despite 190+ console errors
    and many third-party ad iframes)
  • Affected page — every non-navigate tool call fails identically, every time

Suggested fix
Scope the internal body-resolution locator to .first() (matching the browser's
own document.body semantics) or catch the strict-mode violation and degrade
gracefully, rather than failing the entire tool call. A malformed page shouldn't
be able to make every tool call unusable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions