Issue 1:
System info

Playwright Version: [v1.31.2]

Operating System: [macOS 13.2.1]

Browser: [Chromium]

Other info: [Node 16.16.0]

Source code

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

Test file (self-contained)

const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch({
devtools: true
});
const context = await browser.newContext();
const page = await context.newPage();

await page.goto('https://example.com');

page.on('dialog', async dialog => {
console.log(`Found dialog. Type: ${dialog.type()}, message: ${dialog.message()}`); // get dialog type and message
// await dialog.dismiss(); // Does not close the dialog and does not navigate
await dialog.accept(); // Does not close the dialog but allows the navigation
})

await page.addScriptTag({ content: 'window.onbeforeunload = (evt) => { evt.preventDefault(); evt.returnValue = ""}' })

await page.locator('body').click(); // chromium requires a user gesture to enable beforeunload

await page.evaluate('window.location="https://www.iana.org/domains/reserved"')

await page.waitForTimeout(3000) // wait to check if the dialog disappears

await context.close();
await browser.close();
})();

Steps

[Run the script]

Expected

If the dialog is dismissed, the dialog should close and the navigation should fail and the browser closes

If the dialog is accepted, the dialog should close and the navigation should occur and the browser closes

Actual

If the dialog is dismissed, the dialog does NOT close. The navigation does not occur and the browser does NOT close

If the dialog is accepted, the dialog does NOT close, although the navigation does occur and the browser does close

Issue 2:
Context:

Playwright Version: 1.25.0

Operating System: Windows 10 x64

.NET version: .NET 6

Browser: MS Edge

Extra: Visual Studio Enterprise 17.3.2

Code Snippet

[TestMethod]
public async Task LoadPlaywrightPage()
{
var playwright = await Playwright.CreateAsync();
var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
{
Headless = false,
Channel = "msedge"
});
var context = await browser.NewContextAsync();
var page = await context.NewPageAsync();
await page.GotoAsync("https://playwright.dev/dotnet/");

Assert.IsTrue((await page.TitleAsync()).Contains("Playwright .NET"));
}

Describe the bug

Running Visual Studio Enterprise in non-admin, the above code throws this exception:

Test method PlaywrightTests.PlaywrightTests.LoadPlaywrightPage threw exception:
Microsoft.Playwright.PlaywrightException: Browser closed.
==================== Browser output: ====================
C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe --disable-field-trial-config --disable-background-networking
--enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling
--disable-backgrounding-occluded-windows --disable-back-forward-cache --disable-breakpad
--disable-client-side-phishing-detection --disable-component-extensions-with-background-pages
--disable-default-apps --disable-dev-shm-usage --disable-extensions
--disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,
MediaRouter,DialMediaRouteProvider,AcceptCHFrame,AutoExpandDetailsElement,
CertificateTransparencyComponentUpdater,AvoidUnnecessaryBeforeUnloadCheckSync,Translate
--allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking
--disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb
--metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain
--no-service-autorun --export-tagged-pdf --no-sandbox
--user-data-dir=C:\Users\MyUserId\AppData\Local\Temp\1\playwright_chromiumdev_profile-XJmwuh
--remote-debugging-pipe --no-startup-window pid=35316 [pid=35316][out] Opening in existing browser session.
=========================== logs ===========================
C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe --disable-field-trial-config --disable-background-networking
--enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling
--disable-backgrounding-occluded-windows --disable-back-forward-cache --disable-breakpad
--disable-client-side-phishing-detection --disable-component-extensions-with-background-pages
--disable-default-apps --disable-dev-shm-usage --disable-extensions
--disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,
MediaRouter,DialMediaRouteProvider,AcceptCHFrame,AutoExpandDetailsElement,
CertificateTransparencyComponentUpdater,AvoidUnnecessaryBeforeUnloadCheckSync,Translate
--allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking
--disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb
--metrics-recording-only --no-first-run --enable-automation --password-store=basic
--use-mock-keychain --no-service-autorun --export-tagged-pdf --no-sandbox
--user-data-dir=C:\Users\MyUserId\AppData\Local\Temp\1\playwright_chromiumdev_profile-XJmwuh
--remote-debugging-pipe --no-startup-window pid=35316 [pid=35316][out] Opening in existing browser session.
============================================================
at Microsoft.Playwright.Transport.Connection.InnerSendMessageToServerAsync[T](String guid, String method, Object args) in
//src/Playwright/Transport/Connection.cs:line 167 at Microsoft.Playwright.Transport.Connection.WrapApiCallAsync[T](Func`1
action, Boolean isInternal) at Microsoft.Playwright.Core.BrowserType.LaunchAsync(BrowserTypeLaunchOptions options) in
//src/Playwright/Core/BrowserType.cs:line 61 at PlaywrightTests.PlaywrightTests.LoadPlaywrightPage() in
C:\MyProjects\PlaywrightPlayground\PlaywrightTests\PlaywrightTests.cs:line 115 at
Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.ThreadOperations.ExecuteWithAbortSafety(Action action)

If I open Visual Studio with "Run as administrator", the test runs fine and MS Edge opens successfully. I have a Stack Overflow post about this here: https://stackoverflow.com/questions/73651755/playwright-throws-exception-browser-closed-when-testing-against-ms-edge/

Thank you.