Repository navigation
Description
Version
Playwright Python: 0.1.dev1199+g8b4525108.d20261124
Steps to reproduce
Scenario 1: Errors from unrelated events are suppressed
- Create an
EventEmitterinstance. - Register an asynchronous listener for event
a. - Register another asynchronous listener for event
b. - Make both listeners wait on an asynchronous future/event before raising an exception.
- Call
remove_all_listeners("a", "ignoreErrors")while both handlers are still pending. - Release both handlers so they raise exceptions.
- Observe which errors are reported.
Scenario 2: Errors from listeners added later are suppressed
- Create an
EventEmitterinstance. - Call
remove_all_listeners("a", "ignoreErrors"). - Register a new asynchronous listener for event
b. - Make the listener raise an exception.
- Trigger event
b. - Observe whether the listener error is reported.
Validation
The regression tests demonstrate both scenarios.
After the fix, the following tests pass:
python -m pytest tests/async/test_event_emitter.py -qResult: 6 passed
Related regression tests:
python -m pytest tests/async/test_event_emitter.py tests/async/library/test_unroute_behavior.py -qResult: 54 passed
Expected behavior
ignoreErrorsshould suppress errors only from the asynchronous handlers that were already pending for the event(s) being removed whenremove_all_listenerswas called.- Errors from pending handlers belonging to unrelated events should still be reported.
- Errors from listeners registered after
remove_all_listeners(..., "ignoreErrors")should not be suppressed. - The behavior should be scoped to the relevant pending handler futures rather than applied globally.
Actual behavior
The current rejection-handling mechanism uses a global error-suppression handler/state.
As a result:
- Calling
remove_all_listeners("a", "ignoreErrors")can suppress errors from pending handlers belonging to eventb. - Errors from listeners registered after the removal operation can also be suppressed unexpectedly.
This causes unrelated listener failures to go unreported.
Additional context
The issue appears to be related to how asynchronous listener errors are tracked and suppressed inside the Python EventEmitter implementation.
The suppression should be associated with individual pending handler futures instead of using a global rejection handler.
The behavior is particularly problematic when multiple event types have asynchronous handlers running concurrently.
Environment
- OS: Linux (Ubuntu)
- Python: 3.12.3
- pytest: 7.4.4
- pytest-asyncio: 1.5.0
- Browsers tested: Chromium, Firefox, WebKit
- Repository: `microsoft/playwright-python`
Activity
microsoft-playwright-automation commentedon Dec 2, 2026
microsoft-playwright-automation commentedon Dec 2, 2026
Hi, I'm the Playwright bot. I reproduced this in both Python and Node.js on Linux.
The existing fix in microsoft/playwright#44452 passes the independent regression test. This is the same bug as microsoft/playwright#44430: the emitter-wide rejection handler suppresses unrelated and later listener errors. The fix tracks only the selected pending promises.
Python main is still affected. I did not propose a second fix: the upstream PR is still a draft, and Python needs to port the change after it merges.
Reproduction and checks
The regression starts pending handlers for
aandb, removesawithignoreErrors, then registers and emits a newahandler. All three handlers reject. Only the originalaerror should be suppressed; both main branches report no errors instead.dac790d8533c819a6fba44438999c4e067aea32d088896797a4c2db1eab12a68d293d2306895f1821ccfd514654a25046ff5686da864d5312abac631(1.66.0-next)EE-032, Chromium project4dae51dc122e2d35d88b74acd08fd0fb0af4cb83These are emitter-only checks: no browser is launched. The runtimes were Python 3.12.3 and Node.js 24.22.3. The upstream PR build passed after restoring its locked dependencies.
Triaged on Linux by the Playwright bot - agent run