Skip to content

[Bug]: [MCP] browser_navigate_back and browser_navigate_forward hang on modal dialogs instead of racing against modal states #43251

Closed

Description

@alok-108

What's going on?

In Playwright MCP server and CLI, when navigating backwards (browser_navigate_back / playwright-cli go-back) or forwards (browser_navigate_forward / playwright-cli go-forward), if the target page or current page triggers a modal dialog (such as a beforeunload dialog or prompt) during navigation commit, the tool call hangs for 30 seconds and fails with:

TimeoutError: page.goBack: Timeout 30000ms exceeded.
Call log:
  - waiting for navigation until "commit"

Because the action hangs until timeout, the modal state is never surfaced in the tool response (### Modal state: - ["beforeunload" dialog with message ""]: can be handled by browser_handle_dialog), and the agent is never given the opportunity to accept or dismiss the dialog via browser_handle_dialog or playwright-cli dialog-accept.

Reproduction Screenshots

1. Repro — browser_navigate_back stalls & times out on modal state:
browser_navigate_back Hang & Timeout Repro

2. Fixed Behavior — Races against modal states and returns immediate dialog state:
Fixed Behavior with Modal State

Why does this happen?

In packages/playwright-core/src/tools/backend/tab.ts, navigation methods like navigate() and reload() wrap page operations in this._raceAgainstModalStates(...):

// tab.ts
async reload() {
  await this._initializedPromise;
  await this._raceAgainstModalStates(async () => {
    await this.page.reload(this.navigationTimeoutOptions);
  });
}

However, in packages/playwright-core/src/tools/backend/navigate.ts, goBack and goForward bypassed Tab and directly invoked tab.page.goBack(...) / tab.page.goForward(...) without racing against modal states:

// navigate.ts
handle: async (tab, params, response) => {
  await tab.page.goBack({ waitUntil: 'commit', ...tab.navigationTimeoutOptions });
  ...
}

When a dialog opens during navigation commit, page.goBack() hangs waiting for commit, preventing the tool from ever returning the active modal state to the agent.

Expected behavior

goBack and goForward should race against modal states (matching navigate and reload). When a modal dialog opens, the tool call should return immediately with the modal state description so the agent can inspect and resolve it via browser_handle_dialog or playwright-cli dialog-accept.

Environment

  • @playwright/mcp, Playwright main
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