Skip to content

[Bug]: 1.62.0 regresion - "Future exception was never retrieved" error when locator method raises a TypeError #42232

Closed

Description

@DetachHead

Version

1.62.0

Steps to reproduce

from playwright.sync_api import Page
from pytest import raises


def test_foo(page: Page):
    with raises(TypeError):
        page.locator("asdf").highlight(style=object())

Expected behavior

test passes and no errors about futures are logged

Actual behavior

==================================================================================================== 1 passed in 3.00s =====================================================================================================
Future exception was never retrieved
future: <Future finished exception=TargetClosedError('Target page, context or browser has been closed')>
playwright._impl._errors.TargetClosedError: Target page, context or browser has been closed

Additional context

i'm not sure how often this would come up in a real test, but there seem to be other cases where this happens but this is the only one i've been able to minify.

this specific example came from a unit test where we test our own customized reporting on playwright errors

Environment

- Operating System: windows 11, ubuntu (whatever version the playwright docker image uses)
- CPU: x86_64
- Browser: chromium
- Python Version: 3.14.6

Activity

  1. Skn0tt commented on Aug 3, 2026

    @Skn0tt
    Contributor

    Thanks for the report. I can reproduce on earlier versions as well, the trigger seems to be that object() can't be json-serialized. Let me see how we can surface that error better.

  2. DetachHead commented on Aug 3, 2026

    @DetachHead
    ContributorAuthor

    hmm, i can reproduce this on 1.61.0 as well actually. though something definitely has changed because my CI only started failing since updating to 1.62.0, and disabling this test seemed to fix it. so i have no idea why this only started happening now

  3. Skn0tt commented on Aug 3, 2026

    @Skn0tt
    Contributor

    Interesting, I believe we're looking at a different error then. Future exception was never retrieved is the equivalent of Node.js unhandled rejection and it's a very generic error that can have all kinds of underlying causes. If you could share more about the shape of the 1.61-1.62 regression, even if you can't reduce it to a minimal repro, that'd be much appreciated. I wanna make sure we didn't break something gravely here.

  4. DetachHead commented on Aug 3, 2026

    @DetachHead
    ContributorAuthor

    here's a much simpler repro that only happens on 1.62.0:

    from playwright.sync_api import sync_playwright
    
    with sync_playwright() as pw:
        ...
    Task was destroyed but it is pending!
    task: <Task cancelling name='Task-3' coro=<Connection.run.<locals>.init() running at C:\Users\user\project\.venv\Lib\site-packages\playwright\_impl\_connection.py:344> wait_for=<Future finished result=None>>
    Future exception was never retrieved
    future: <Future finished exception=TargetClosedError('Target page, context or browser has been closed')>
    playwright._impl._errors.TargetClosedError: Target page, context or browser has been closed
    
  5. Rafiot commented on Aug 4, 2026

    @Rafiot

    Yep, was about to open an issue, that's my repro:

    Image

    I "fixed" it by making the code async, and it works just fine.

  6. Skn0tt commented on Aug 12, 2026

    @Skn0tt
    Contributor

    Fixes landed and will be released in 1.63.

  7. DetachHead commented on Aug 13, 2026

    @DetachHead
    ContributorAuthor

    it looks like those specific cases are working now, however since updating to python 3.14.7 more of our tests have started failing due to "Future exception was never retrieved" errors, even on the latest version from main (154f67ced51ada646b0fcf8574897d96c9712aa3)

    i'll investigate further and try to get a minimal repro, but it's difficult because it seems to only happen intermittently and only in CI but not locally :(

  8. pavelfeldman commented on Aug 14, 2026

    @pavelfeldman
    Member

    I'll close this issue as addressed by microsoft/playwright-python#3167. DetachHead send your repro our way and we'll fix it.

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

Metadata

Metadata

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