Skip to content

[Bug]: No HAR is recorded in persistent context when awaiting exit event #3034

@fwdekker

Description

@fwdekker

Version

1.58.0

Steps to reproduce

  1. Clone my repo at https://github.com/fwdekker/playwright-python-har-bug
  2. pip install -r requirements.txt
  3. python main.py
  4. After the web page is loaded, manually close the browser window. Either close the tab, or close the window.
  5. Check the contents of the out/ directory.

Expected behavior

The file out/recording.har is created.

Actual behavior

The file out/recording.har is not created.

Additional context

I understand that the context must be closed gracefully in order to ensure the .har is created. I expected await context.close() to be sufficient, but apparently adding an event listener for close changes things.

I do not encounter this bug when using the equivalent code on a non-persistent context.

Removing the line await event.wait() results in the recording.har being created correctly. However, this line is necessary to allow the user to manually decide when to close the window.

Environment

- Operating System: Windows 11
- CPU: amd64
- Browser: Chromium and Firefox. Not tested on Webkit
- Python Version: 3.14

Metadata

Metadata

Assignees

No one assigned

    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