Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: HAR file not being saved #1841

Closed
StevenDenman opened this issue Nov 26, 2021 · 2 comments · Fixed by #1863
Closed

[Bug]: HAR file not being saved #1841

StevenDenman opened this issue Nov 26, 2021 · 2 comments · Fixed by #1863
Assignees

Comments

@StevenDenman
Copy link

Playwright version

1.17.0

Operating system

Windows

What browsers are you seeing the problem on?

Chromium, Firefox

Other information

No response

What happened? / Describe the bug

I am trying to record a HAR file with Playwright.

According to the docs, all you need to do is pass RecordHarPath in the BrowserContextOptions and call CloseAsync on the BrowserContext.

With Firefox, this is not creating any HAR file.
With Chromium, it hangs on CloseAsync and never completes.

Code snippet to reproduce your bug

static async Task Main()
{
    var playwright = await Playwright.CreateAsync();

    var currentDir = Directory.GetCurrentDirectory();

    Console.WriteLine("Trying Firefox");
    var firefox = await playwright.Firefox.LaunchAsync(new BrowserTypeLaunchOptions { Headless = false});
    await TryWith(firefox, Path.Combine(currentDir, "firefoxHar.har"));

    Console.WriteLine("Trying Chromium");
    var chromium = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions { Headless = false });
    await TryWith(chromium, Path.Combine(currentDir, "chromium.har"));
}

static async Task TryWith(IBrowser browser, string harPath)
{
    var context = await browser.NewContextAsync(new BrowserNewContextOptions()
    {
        RecordHarPath = harPath
    });

    var page = await context.NewPageAsync();
    await page.GotoAsync("https://www.microsoft.com");
    var link = await page.QuerySelectorAsync("a#uhf-shopping-cart");
    await link.ClickAsync();

    Console.WriteLine("Closing Context");
    await context.CloseAsync();
    Console.WriteLine("Closing Browser");
    await browser.CloseAsync();
}

Relevant log output

No response

@infinitejest69
Copy link

Came to report the same Issue, also not seeing any HAR file, Tried multiple browsers including Chrome and Chromium and tried with and without video recording which does work and saves on CloseAsync. also tried with Dev tools open. would be nice to solve this.
Thanks

@mxschmitt mxschmitt added the v1.18 label Dec 4, 2021
@mxschmitt
Copy link
Member

Was able to repro. Seems like the "HAR saving logic" is missing when the browser context gets closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants