Skip to content

[Bug]: Attempting to launch Microsoft Edge browser will crash the program for the first time, but subsequent executions of the program work as expected #3155

Open
@xxvwmtws

Description

@xxvwmtws

Version

1.51.0

Steps to reproduce

Example steps:

  1. Create a fresh C# ASP.NET console program
  2. Paste the following code into the main function:
var playwright = await Playwright.CreateAsync();

var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
{
    Channel = "msedge",
    ExecutablePath = @"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe",
    Headless = false,
    ChromiumSandbox = true,
    Timeout = 60000
});

var context = await browser.NewContextAsync(new BrowserNewContextOptions
{
    ViewportSize = new ViewportSize { Width = 1920, Height = 1080 },
    JavaScriptEnabled = true
});

var page = await context.NewPageAsync();
page.SetDefaultTimeout(60000);
page.SetDefaultNavigationTimeout(60000);

await page.GotoAsync("https://github.com/", new PageGotoOptions
{
    Timeout = 60000,
    WaitUntil = WaitUntilState.DOMContentLoaded
});
  1. Compile the program (with either Debug or Release config)
  2. Copy the compiled program, along with all the applicable dll files, to another directory on the local disk
  3. Double-click the exe file to run the program. During the first round of running, the program will crash. Close the program and double-click it to run again, no more issues will be observed starting from now

Expected behavior

No crash and the code can run without throwing any exception

Actual behavior

The program crashes with the following exception thrown:

Unhandled Exception: Microsoft.Playwright.TargetClosedException: Target page, context or browser has been closed
Browser logs:

<launching> C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe --disable-field-trial-config --disable-background-networking --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-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=AcceptCHFrame,AutoExpandDetailsElement,AvoidUnnecessaryBeforeUnloadCheckSync,CertificateTransparencyComponentUpdater,DeferRendererTasksAfterInput,DestroyProfileOnBrowserClose,DialMediaRouteProvider,ExtensionManifestV2Disabled,GlobalMediaControls,HttpsUpgrades,ImprovedCookieControls,LazyFrameLoading,LensOverlay,MediaRouter,PaintHolding,ThirdPartyStoragePartitioning,Translate --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf --disable-search-engine-choice-screen --unsafely-disable-devtools-self-xss-warnings --user-data-dir=C:\Windows\Temp\playwright_chromiumdev_profile-aBc123 --remote-debugging-pipe --no-startup-window
<launched> pid=9876
Call log:
  -   - <launching> C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe --disable-field-trial-config --disable-background-networking --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-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=AcceptCHFrame,AutoExpandDetailsElement,AvoidUnnecessaryBeforeUnloadCheckSync,CertificateTransparencyComponentUpdater,DeferRendererTasksAfterInput,DestroyProfileOnBrowserClose,DialMediaRouteProvider,ExtensionManifestV2Disabled,GlobalMediaControls,HttpsUpgrades,ImprovedCookieControls,LazyFrameLoading,LensOverlay,MediaRouter,PaintHolding,ThirdPartyStoragePartitioning,Translate --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf --disable-search-engine-choice-screen --unsafely-disable-devtools-self-xss-warnings --user-data-dir=C:\Windows\Temp\playwright_chromiumdev_profile-aBc123 --remote-debugging-pipe --no-startup-window
  -   - <launched> pid=9876
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at Microsoft.Playwright.Transport.Connection.<InnerSendMessageToServerAsync>d__40`1.MoveNext() at /_/src/Playwright/Transport/Connection.cs: Line 206
--- Stack trace of previously thrown exception ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at Microsoft.Playwright.Transport.Connection.<WrapApiCallAsync>d__52`1.MoveNext() at /_/src/Playwright/Transport/Connection.cs: Line 535
--- Stack trace of previously thrown exception ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Playwright.Core.BrowserType.<LaunchAsync>d__10.MoveNext() at /_/src/Playwright/Core/BrowserType.cs: Line 56
--- Stack trace of previously thrown exception ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at MyTestCode.Program.<Main>d__7.MoveNext() at C:\MyProjects\MyTestCode\MyTestCode\Program.cs: 行 37
--- Stack trace of previously thrown exception ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at MyTestCode.Program.<Main>(String[] args)

The above call log reveals that the exception comes from the var browser = await playwright.Chromium.LaunchAsync() line in the code.

Subsequent executions of exactly the same compiled program work without issues though.

Additional context

I have tested the aforesaid await playwright.Chromium.LaunchAsync() function with both Microsoft Edge and Google Chrome browsers. And no exceptions were ever observed for the Chrome browser; whereas for Edge, this bug can be constantly reproduced (need to re-build the program each time as this issue happens only during the first time of running)

Environment

- Operating System: [Windows 10 PC]
- CPU: [Intel x64]
- Browser: [Microsoft Edge (latest stable channel)]
- .NET Version (TFM): [net4.8]
- Other info:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions