You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Regression]: pytest.fail() inside an event handler closes the connection #3360
0 TargetClosedError Page.evaluate: Target page, context or browser has been closed
1 TargetClosedError Playwright connection closed
The Failed is gone and the connection is dead. The error listener is not called either.
With a plain Exception (e.g. assert False) it still works, so it's only BaseException subclasses — which is what pytest.fail(), pytest.skip() and pytest.xfail() raise. The listener error handling in the dispatch path now catches Exception; before the port it was BaseException.
Additional context
No response
Environment
- Operating System: macOS 27.2
- CPU: arm64
- Browser: Chromium
- Python Version: 3.14
- Other info: sync API
Reproduced on current main in Chromium, Firefox, and WebKit; a focused fix is proposed.pytest.fail() escapes both Exception catches in the event path. This stops the pipe reader and closes the connection. The fix sends the outcome to the error listener, or raises it on the next API call if no error listener exists. Cancellation and exit exceptions still pass through.
The linked PR #3364 also passes the independent repro.
Repro and verification
The regression extends test_console_repr. Its unhandled case is:
Proposed fix, same driver a018f24a4fc76e2120d3b35d2415f1e5bd4b073e
Chromium, Firefox, WebKit
Regression passes; connection remains usable
With the proposed fix, the sync Python and console-event files passed 119 cases; the async listener, lifecycle, cancellation, and console-event files passed 80. Each run had one existing Firefox skip. mypy playwright passed. Full scripts/lint.sh passed using Python 3.13 because the pinned Pyright cannot parse Python 3.14's standard-library t-strings. No source or dependency changes were needed for that lint issue.
Source history identifies #3280, commit 36d698e1776181c8c7d31bc9fdc32af072cab081, as the change from BaseException to Exception. Its first release tag is v1.65.0. Published v1.64.0 and v1.65.0 packages were not run.
Activity
microsoft-playwright-automation commentedon Nov 23, 2026
microsoft-playwright-automation commentedon Nov 23, 2026
Hi, I'm the Playwright bot and I reproduced this.
Reproduced on current main in Chromium, Firefox, and WebKit; a focused fix is proposed.
pytest.fail()escapes bothExceptioncatches in the event path. This stops the pipe reader and closes the connection. The fix sends the outcome to theerrorlistener, or raises it on the next API call if no error listener exists. Cancellation and exit exceptions still pass through.The linked PR #3364 also passes the independent repro.
Repro and verification
The regression extends
test_console_repr. Its unhandled case is:The same test first checks that an
errorlistener receives the pytest outcome.All runs used macOS 26.7.2, Python 3.14.10, and headless browsers:
de03c865f5738c2291a6a58c8b5c20346d8e70f2(1.66.0-next)259b19d731b93d1203d5c74a714f33f0e0bfbb09a018f24a4fc76e2120d3b35d2415f1e5bd4b073eWith the proposed fix, the sync Python and console-event files passed 119 cases; the async listener, lifecycle, cancellation, and console-event files passed 80. Each run had one existing Firefox skip.
mypy playwrightpassed. Fullscripts/lint.shpassed using Python 3.13 because the pinned Pyright cannot parse Python 3.14's standard-library t-strings. No source or dependency changes were needed for that lint issue.Source history identifies #3280, commit
36d698e1776181c8c7d31bc9fdc32af072cab081, as the change fromBaseExceptiontoException. Its first release tag is v1.65.0. Published v1.64.0 and v1.65.0 packages were not run.Draft PR: #3366
Triaged on macOS by the Playwright bot - agent run
fix(events): preserve pytest outcomes without closing the connection