Skip to content

[Question]: "The reaction to the self-closing of a window using JavaScript." #1903

@skn78

Description

@skn78

Your question

JavaScript closes the window using the close() call.
I'm trying to determine the moment when a window is closed. page.is_closed() doesn't work, it shows False both before and after the window is closed.
I found a way to determine this using the following code:

with new_page.expect_event("close") as event_info:
          pass

This code snippet waits for the window to close on its own, but during execution, a message is displayed on the screen:

Future exception was never retrieved
future: <Future finished exception=Error('Target page, context or browser has been closed')>
playwright._impl._api_types.Error: Target page, context or browser has been closed

What is the correct way to track window closing? How can I avoid the error messages in my code?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions