playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Bug]: Target page, context or browser has been closed Browser

Open maneet057 opened this issue 6 months ago • 6 comments

Version

1.50.1

Steps to reproduce

Get msedge package from following command:

 npx [email protected] install --force msedge

Launching msedge:

  var args = new List<string> {
                    "--no-sandbox",
                    "--disable-setuid-sandbox",
                    "--disable-dev-shm-usage",
                    "--disable-accelerated-2d-canvas",
                    "--no-first-run",
                    "--no-zygote",
                    "--process-per-site",
                    "--start-maximized",
                    "--disable-gpu"
                    };
                    if (launchChromeIncognitoMode)
                    {
                        args.Add("--incognito");
                    }
                    launchOptions.Args = args.ToArray();
                    var message = string.Empty;
                    if (browserType.IsAnaheim())
                    {
                        message = ".MicrosoftEdge";
                        launchOptions.ExecutablePath = Path.Combine(browsersPath, "msedge", "msedge-win", "msedge.exe");
                    }
                    browser = await playwright.Chromium.LaunchAsync(launchOptions);
}

Expected behavior

Msedge browser launching without exceptions.

Actual behavior

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

  <launching> D:\app\Playwright.Browsers\msedge\msedge-win\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=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,DialMediaRouteProvider,AcceptCHFrame,AutoExpandDetailsElement,CertificateTransparencyComponentUpdater,AvoidUnnecessaryBeforeUnloadCheckSync,Translate,HttpsUpgrades,PaintHolding,ThirdPartyStoragePartitioning,LensOverlay,PlzDedicatedWorker --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 --headless --hide-scrollbars --mute-audio --blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4 --no-sandbox --no-sandbox --disable-setuid-sandbox --disable-dev-shm-usage --disable-accelerated-2d-canvas --no-first-run --no-zygote --process-per-site --start-maximized --disable-gpu --incognito --user-data-dir=D:\data --remote-debugging-pipe --no-startup-window
  <launched> pid=11032
  Call log:
    -   - <launching> D:\app\Playwright.Browsers\msedge\msedge-win\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=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,DialMediaRouteProvider,AcceptCHFrame,AutoExpandDetailsElement,CertificateTransparencyComponentUpdater,AvoidUnnecessaryBeforeUnloadCheckSync,Translate,HttpsUpgrades,PaintHolding,ThirdPartyStoragePartitioning,LensOverlay,PlzDedicatedWorker --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 --headless --hide-scrollbars --mute-audio --blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4 --no-sandbox --no-sandbox --disable-setuid-sandbox --disable-dev-shm-usage --disable-accelerated-2d-canvas --no-first-run --no-zygote --process-per-site --start-maximized --disable-gpu --incognito --user-data-dir=D:\data --remote-debugging-pipe --no-startup-window
    -   - <launched> pid=11032
    at Microsoft.Playwright.Transport.Connection.InnerSendMessageToServerAsync[T](ChannelOwner object, String method, Dictionary`2 dictionary, Boolean keepNulls) in /_/src/Playwright/Transport/Connection.cs:206
    at Microsoft.Playwright.Transport.Connection.WrapApiCallAsync[T](Func`1 action, Boolean isInternal) in /_/src/Playwright/Transport/Connection.cs:535
    at Microsoft.Playwright.Core.BrowserType.LaunchAsync(BrowserTypeLaunchOptions options) in /_/src/Playwright/Core/BrowserType.cs:56
    at Turanga.SessionManager.Providers.PlaywrightBrowserFactory.GetPlaywrightAndBrowser(String autopilotDeploymentToken, String mockUserAgent, BrowserType browserType, TestContext testContext, Boolean headless, Boolean launchChromeIncognitoMode, Int32 loadTimeoutInMilliseconds)

Additional context

No response

Environment

Windows

maneet057 avatar Jun 19 '25 15:06 maneet057

Does it work without specifying any args/executablePath? Why do you have msedge in a different location?

mxschmitt avatar Jun 19 '25 15:06 mxschmitt

Tried using Channel = "msedge" to launch edge window and it is throwing "threw exception: Microsoft.Playwright.PlaywrightException: Chromium distribution 'msedge' is not found" exception. Is there anything else that can help?

maneet057 avatar Jun 20 '25 20:06 maneet057

You can install Edge via npx playwright install msedge - what does this yield to?

mxschmitt avatar Jun 21 '25 16:06 mxschmitt

We are running test on an Azure VM with D series, and if needed we can login into machine to debug.

maneet057 avatar Jun 23 '25 06:06 maneet057

This does not answer the question - why does npx playwright install msedge not work / what does it yield to?

mxschmitt avatar Jun 23 '25 06:06 mxschmitt

When trying to install using npx playwright install msedge I can see latest msedge binaries in C:\Program Files (x86)\Microsoft\Edge\Application and the following message:

║ ATTENTION: "msedge" is already installed on the system! ║ ║ ║ ║ "msedge" installation is not hermetic; installing newer version ║ ║ requires removal of a current installation first. ║ ║ ║ ║ To uninstall current version and re-install latest "msedge": ║ ║ ║ ║ - Close all running instances of "msedge", if any ║ ║ - Use "--force" to install browser: ║ ║ ║ ║ npx playwright install --force msedge ║ ║ ║ ║ <3 Playwright Team

maneet057 avatar Jun 23 '25 07:06 maneet057

I'll close it for now since it was verified in a private conversation that a normal fresh "npm init playwright" project with Edge works. So this is most likely related to the environment or way how you bundle Edge. This is outside of the scope for Playwright. We only look at global installed Edge versions.

mxschmitt avatar Jun 25 '25 11:06 mxschmitt