Issue 1:
System info

Playwright Version: [v1.35]

Operating System: Windows 10

Browser: Chromium

Other info: Tested in both .NET 6 and .NET 7 project in Visual Studio 2022 17.6.4

Source code

[TestFixture]
public class PlaywrightPOCTest
{
private static IPlaywright playwright;
private static IBrowser browser;
private static IBrowserContext context;
private static IPage page;

[OneTimeSetUp]
public static async Task DownloadBrowsers()
{
var exitCode = Microsoft.Playwright.Program.Main(new[] { "install" });
if (exitCode != 0)
{
throw new Exception($"Playwright exited with code {exitCode}");
}

playwright = await Playwright.CreateAsync();
}

[OneTimeSetUp]
public static async Task EdgeDriverInitialize()
{
browser = await playwright.Chromium.LaunchAsync(
new BrowserTypeLaunchOptions
{ Channel = "msedge", Headless = true, /*SlowMo = 2000 */}
);

context = await browser.NewContextAsync();

page = await context.NewPageAsync();
}

[Test]
public static async Task PlaywrightFileUpload()
{
var frame = page.MainFrame;

await frame.GotoAsync(@"http://www.fileconvoy.com/");
Console.Log($"Memory usage before upload: {System.Diagnostics.Process.GetCurrentProcess().PrivateMemorySize64}");
await frame.Locator("id=upfile_0").SetInputFilesAsync(@"C:\Users\testuser\Downloads\19588.pdf");
Console.Log($"Memory usage after upload: {System.Diagnostics.Process.GetCurrentProcess().PrivateMemorySize64}");
await frame.Locator("id=readTermsOfUse").CheckAsync();
await frame.GetByRole(AriaRole.Button).GetByText("Upload").ClickAsync();
Console.Log($"Memory usage after page navigation: {System.Diagnostics.Process.GetCurrentProcess().PrivateMemorySize64}");
}

[OneTimeTearDown]
public static async Task EdgeDriverCleanup()
{
await context?.CloseAsync();
await browser?.CloseAsync();
playwright.Dispose();
}
}

I provided exact source code that allows reproducing the issue locally.

Steps

Download this ~30MB PDF from here: https://research.nhm.org/pdfs/19588/19588.pdf

Update path in SetInputFilesAsync() method to your file location

Run PlaywrightFileUpload() test

Expected

I would expect memory usage to increase temporarily by the uploaded filesize (~30MB) and then go away or be cleaned up fairly soon after page navigation occurs.

Actual

Memory usage jumps from about 40MB to >700MB just from the file upload and persists for quite a long time in other tests which do not involve file uploads. Sometimes I can get it to drop by forcing a GC using GC.Collect() several minutes later, but I definitely should not be doing that.

This has had an impact on long running scenarios where we are doing a file upload as the first dependency and then running several tests on a web app after the upload. It also affects concurrent runs in our framework due to out of memory issues. Fwiw, I took a memory snapshot inside VS, and it shows up as a large number of dead char[] objects which are outside of my code.

Issue 2:
System info

Playwright Version: 1.35.1

Operating System: macOs 13.4 (22F66)

Browser: Chrome

Other info: UI mode

Source code

Config file

// playwright.config.ts
import type { PlaywrightTestConfig } from '@playwright/test';

const config: PlaywrightTestConfig = {
testDir: 'tests',
};

export default config;

(edited to add export default config; which I forgot to copy across initially)

Test file (self-contained)

test.only('exceptions inside a test are swallowed', async () => {
expect(1).toBe(1); // this is reached and displayed in UI mode
try {
undefinedVariable1 = 'this throws an exception';
} catch (e) {
expect(e).toBeTruthy(); // this is reached and displayed in UI mode
}
undefinedVariable1 = 'this throws an exception';
expect(1).toBe(1); // never reached, no indication of what went wrong
});

Steps

Run the test in UI mode

Observe that the test fails

Observe that you are not told why it fails

Expected

Ideally:

We should see that the test itself threw an exception

We should see the content of the exception (eg ReferenceError: undefinedVariable1 is not defined)

We should see the line of code where the exception was thrown

Note: if you run the tests on the command line, you do get helpful output:

Actual

The test is marked as failing

But, there is no explanation why it failed