Skip to content

--extension can hang indefinitely when connect.html lands in another Chrome profile #1732

Closed
microsoft/playwright
#42525

Description

@noagogo

Summary

With --extension on a multi-profile Chrome setup, the first browser tool call can wait indefinitely when connect.html lands in a different profile from the one whose extension token was configured.

This is especially reproducible when a person is using Chrome at the same time: starting a fresh MCP/client session resets the stuck server-side promise, but does not remove the race over which Chrome profile/window receives the connect page.

Environment

  • macOS, Chrome with multiple profiles
  • One account per Chrome profile
  • Playwright extension installed in multiple profiles, with a different extension token per profile
  • @playwright/mcp 0.0.79
  • Invocation uses --extension

Observed behavior

On the first browser tool call, MCP launches Chrome with a chrome-extension://.../connect.html URL and waits for _extensionConnectionPromise.

When that URL is opened in the last-active Chrome profile/window rather than the intended profile:

  1. The extension token does not match.
  2. The WebSocket connection is never established.
  3. No extension disconnect event fires because there was no connection to disconnect.
  4. The promise has no timeout, so the tool call neither succeeds nor returns an explicit error.
  5. Retrying in the same session waits on the same unresolved promise.

In one run today this failed three times in a row:

  1. Initial tool call in an interactive session.
  2. Retry in the same session.
  3. A new client session (claude -p) and a new MCP server session.

The new session cleared the previously stuck server state, but the connect page again landed in the wrong profile while Chrome was being actively used.

Expected behavior

Either:

  1. Allow the extension profile to be selected explicitly, for example with --profile-directory / --browser-profile (or a config/environment equivalent), and pass it through deterministically; or
  2. Put a finite timeout around the extension connection wait and return a clear error such as "Playwright extension did not connect; check the selected Chrome profile and extension token."

Ideally both would be supported. Explicit profile selection prevents the race; a timeout makes remaining failures diagnosable and lets the client recover.

Why this differs from related reports

Related: #1712, which fixed false-positive profile detection caused by leftovers from an uninstalled extension and also requested explicit profile selection.

This case does not depend on uninstall leftovers: the extension is genuinely installed in multiple profiles. The ambiguity is therefore real, and a human changing the active Chrome profile can make repeated fresh sessions lose in the same way.

Operational impact

A client-level 120-second timeout only stops the caller from waiting; it does not resolve the server-side connection promise. Without an explicit profile selector or a server-side timeout/error, the session is effectively unrecoverable and the next fresh session can immediately hit the same race again.

Activity

  1. noagogo commented on Sep 3, 2026

    @noagogo
    Author

    Thank you for the incredibly fast turnaround, Yury Semikhatsky (@yury-s) — both PRs land exactly on the two failure modes I hit:

    • #42525 (30s timeout + a hint naming the launched profile) fixes the "hangs every retry forever" case. With a token set there is genuinely no human in the loop, so the silent-forever behavior was the worst part; failing fast and naming the profile is exactly right.
    • #42527 (--profile-dir-name / PLAYWRIGHT_MCP_PROFILE_DIR_NAME) fixes the root cause — I run several Chrome profiles that each have the extension installed with a per-identity token, and the connect page landing in the "last used" profile instead of the token's profile was the trigger.

    This is a daily config for me, so both are very welcome. Thanks again.

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

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