question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Playwright throws exception "Browser closed" when testing against MS Edge

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mxschmittcommented, Sep 19, 2022

This was really helpful! Turns out the UserDataDir policy breaks Google Chrome and Microsoft Edge if you run the browser headed, this ends up in getting the Opening in existing browser session. when launching the browser. I’ll talk with our team later today what to do then, but most likely nothing we can fix on our side.

I’d recommend contacting your IT to move this group policy from Microsoft Edge to Microsoft Edge - Default Settings (users can override). So the setting is not enforced, and Playwright can change it.

0reactions
arc95commented, Sep 21, 2022

Thanks, @mxschmitt, for working on this. Your help is much appreciated.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[BUG] Playwright throws exception "Browser closed" when ...
Context: Playwright Version: 1.25.0 Operating System: Windows 10 x64 . ... throws exception "Browser closed" when testing against MS Edge # ...
Read more >
Playwright throws exception "Browser closed" when testing ...
Found the issue: I was running Visual Studio without admin privileges. Once I chose, "Run as administrator", the local MS Edge launched and ......
Read more >
Handle pop-ups, permissions, and notifications - BrowserStack
Learn how to manage pop-ups, permissions, and notifications in different browsers when running your Selenium tests on BrowserStack Automate.
Read more >
What to do if Microsoft Edge isn't working
If you can't open Microsoft Edge, or if it opens briefly and then closes, or if you're unable to open specific webpages, here...
Read more >
Error Messages During Test Execution - LambdaTest
Here is a list of various error messages that may happen during test execution.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found