Skip to content

[Bug]: Remote browser close should reject pending waiters before disconnect events #3097

@rohan-patnaik

Description

@rohan-patnaik

Version

main branch as of 2026-06-09

Steps to reproduce

  1. Start a remote browser server.
  2. Connect with browser_type.connect(...).
  3. Start a pending waiter, for example page.wait_for_event("download").
  4. Close the remote browser or stop the remote server.

This is already called out in the Python source with a TODO that points to the upstream Playwright fix: microsoft/playwright@d8d5289

Expected behavior

Pending page/context API waiters should reject before browser.close() returns or before the browser disconnected event is emitted.

Actual behavior

Python still has the old remote-close ordering path in playwright/_impl/_browser_type.py. It closes page/context/browser objects synchronously and only then cleans up the connection.

Additional context

This is a small backport/parity fix. The upstream tests are:

  • should reject waitForEvent before browser.close finishes
  • should reject waitForEvent before browser.onDisconnect fires

Potential fix direction

Port the upstream ordering change to Python: clean up/reject the remote connection first, then schedule page/context/browser close notifications on the next event-loop turn. Add focused async tests for both close and remote-server-disconnect paths.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions