microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
66.41k stars 3.63k forks source link

[BUG] Unable to launch MS Edge browser #22016

Closed priyanshu92 closed 1 year ago

priyanshu92 commented 1 year ago

System info

Source code

using Microsoft.Playwright;

using var playwright = await Playwright.CreateAsync();
await using var browser = await playwright.Chromium.LaunchAsync(new() { Channel = "msedge", Headless = false });
var page = await browser.NewPageAsync();
await page.GotoAsync("https://playwright.dev/dotnet");
await page.ScreenshotAsync(new()
{
    Path = "screenshot.png"
});

Expected

MS Edge should be launched.

Actual

Browser fails to launch with the following exception:

Unhandled exception. Microsoft.Playwright.PlaywrightException: Browser closed.
==================== Browser output: ====================
<launching> 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-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 --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\<User Id>\AppData\Local\Temp\playwright_chromiumdev_profile-RA89d8 --remote-debugging-pipe --no-startup-window
<launched> pid=5708
[pid=5708][err] [5708:10068:0328/130624.697:ERROR:sitelist_downloader.cc(131)] No primary account. Unable to fetch access token.
   at Microsoft.Playwright.Transport.Connection.InnerSendMessageToServerAsync[T](String guid, String method, Dictionary`2 dictionary) in /_/src/Playwright/Transport/Connection.cs:line 143
   at Microsoft.Playwright.Transport.Connection.WrapApiCallAsync[T](Func`1 action, Boolean isInternal) in /_/src/Playwright/Transport/Connection.cs:line 465
   at Microsoft.Playwright.Core.BrowserContext.NewPageAsync() in /_/src/Playwright/Core/BrowserContext.cs:line 285
   at Microsoft.Playwright.Core.Browser.NewPageAsync(BrowserNewPageOptions options) in /_/src/Playwright/Core/Browser.cs:line 186
   at Program.<Main>$(String[] args) in C:\src\PlaywrightMSEdge\PlaywrightMSEdge\Program.cs:line 5
   at Program.<Main>$(String[] args) in C:\src\PlaywrightMSEdge\PlaywrightMSEdge\Program.cs:line 7
   at Program.<Main>(String[] args)

Logs with DEBUG: pw:browser,pw:protocol,pw:api

2023-03-28T07:57:51.753Z pw:browser <launching> 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-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 --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\<User Id>\AppData\Local\Temp\playwright_chromiumdev_profile-yeCyZw --remote-debugging-pipe --no-startup-window
2023-03-28T07:57:51.763Z pw:browser <launched> pid=5536
2023-03-28T07:57:51.764Z pw:protocol SEND Γû║ {"id":1,"method":"Browser.getVersion"}
2023-03-28T07:57:51.960Z pw:protocol ΓùÇ RECV {"id":1,"result":{"protocolVersion":"1.3","product":"Edg/111.0.1661.54","revision":"@9e410ec23a36266fd1bd72da1ffa52ca0cbfab78","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1661.54","jsVersion":"11.1.24.7"}}
2023-03-28T07:57:51.961Z pw:protocol SEND Γû║ {"id":2,"method":"Target.setAutoAttach","params":{"autoAttach":true,"waitForDebuggerOnStart":true,"flatten":true}}
2023-03-28T07:57:51.968Z pw:browser [pid=5536][err] [5536:25064:0328/132751.967:ERROR:sitelist_downloader.cc(131)] No primary account. Unable to fetch access token.
2023-03-28T07:57:51.969Z pw:protocol ΓùÇ RECV {"id":2,"result":{}}
2023-03-28T07:57:51.985Z pw:protocol SEND Γû║ {"id":3,"method":"Target.createBrowserContext","params":{"disposeOnDetach":true}}
2023-03-28T07:57:51.996Z pw:protocol ΓùÇ RECV {"id":3,"result":{"browserContextId":"EBFA0FAEFFC517F01F3C9513061EDAF2"}}
2023-03-28T07:57:51.998Z pw:protocol SEND Γû║ {"id":4,"method":"Browser.setDownloadBehavior","params":{"behavior":"allowAndName","browserContextId":"EBFA0FAEFFC517F01F3C9513061EDAF2","downloadPath":"C:\\Users\\<User Id>\\AppData\\Local\\Temp\\playwright-artifacts-1fvKAo","eventsEnabled":true}}
2023-03-28T07:57:52.004Z pw:protocol ΓùÇ RECV {"id":4,"result":{}}
2023-03-28T07:57:52.026Z pw:protocol SEND Γû║ {"id":5,"method":"Target.createTarget","params":{"url":"about:blank","browserContextId":"EBFA0FAEFFC517F01F3C9513061EDAF2"}}
2023-03-28T07:57:54.127Z pw:browser [pid=5536] <gracefully close start>
2023-03-28T07:57:54.127Z pw:browser [pid=5536] <kill>
2023-03-28T07:57:54.127Z pw:browser [pid=5536] <will force kill>
2023-03-28T07:57:54.234Z pw:browser [pid=5536] taskkill stderr: ERROR: The process "5536" not found.

2023-03-28T07:57:54.235Z pw:browser [pid=5536] <process did exit: exitCode=3221225477, signal=null>
2023-03-28T07:57:54.235Z pw:browser [pid=5536] starting temporary directories cleanup
2023-03-28T07:58:07.306Z pw:browser [pid=5536] finished temporary directories cleanup
2023-03-28T07:58:07.306Z pw:browser [pid=5536] <gracefully close end>
Unhandled exception. Microsoft.Playwright.PlaywrightException: Browser closed.
==================== Browser output: ====================
<launching> 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-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 --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\<User Id>\AppData\Local\Temp\playwright_chromiumdev_profile-yeCyZw --remote-debugging-pipe --no-startup-window
<launched> pid=5536
[pid=5536][err] [5536:25064:0328/132751.967:ERROR:sitelist_downloader.cc(131)] No primary account. Unable to fetch access token.
   at Microsoft.Playwright.Transport.Connection.InnerSendMessageToServerAsync[T](String guid, String method, Dictionary`2 dictionary) in /_/src/Playwright/Transport/Connection.cs:line 180
   at Microsoft.Playwright.Transport.Connection.WrapApiCallAsync[T](Func`1 action, Boolean isInternal) in /_/src/Playwright/Transport/Connection.cs:line 502
   at Microsoft.Playwright.Core.BrowserContext.NewPageAsync() in /_/src/Playwright/Core/BrowserContext.cs:line 293
   at Microsoft.Playwright.Core.Browser.NewPageAsync(BrowserNewPageOptions options) in /_/src/Playwright/Core/Browser.cs:line 174
   at Program.<Main>$(String[] args) in C:\src\PlaywrightMSEdge\PlaywrightMSEdge\Program.cs:line 5
   at Program.<Main>$(String[] args) in C:\src\PlaywrightMSEdge\PlaywrightMSEdge\Program.cs:line 7
   at Program.<Main>(String[] args)

C:\src\PlaywrightMSEdge\PlaywrightMSEdge\bin\Debug\net7.0\PlaywrightMSEdge.exe (process 24300) exited with code -532462766.

Edge Policies

{
   "chromeMetadata": {
      "OS": "Windows 11 Version 22H2 (Build 22621.1413)",
      "application": "Microsoft Edge",
      "revision": "9e410ec23a36266fd1bd72da1ffa52ca0cbfab78",
      "version": "111.0.1661.54 (Official build) (64-bit)"
   },
   "edgePolicies": {
      "BrowserSignin": {
         "level": "mandatory",
         "scope": "user",
         "source": "platform",
         "value": 2
      },
      "ClickOnceEnabled": {
         "level": "mandatory",
         "scope": "machine",
         "source": "platform",
         "value": true
      },
      "DoNotSilentlyBlockProtocolsFromOrigins": {
         "level": "mandatory",
         "scope": "machine",
         "source": "platform",
         "value": [ {
            "allowed_origins": [ "teams.microsoft.com", "http://teams.microsoft.com:8080" ],
            "protocol": "spotify"
         }, {
            "allowed_origins": [ "teams.microsoft.com", "https://.mail.microsoft.com" ],
            "protocol": "msteams"
         }, {
            "allowed_origins": [ "*" ],
            "protocol": "msoutlook"
         } ]
      },
      "ExperimentationAndConfigurationServiceControl": {
         "level": "mandatory",
         "scope": "machine",
         "source": "platform",
         "value": 2
      },
      "ExtensionInstallBlocklist": {
         "level": "mandatory",
         "scope": "machine",
         "source": "platform",
         "value": [  ]
      },
      "ForceSync": {
         "level": "mandatory",
         "scope": "user",
         "source": "platform",
         "value": true
      },
      "InternetExplorerIntegrationCloudSiteList": {
         "level": "mandatory",
         "scope": "machine",
         "source": "platform",
         "value": "80f5ad94-bb13-4c0c-9fb3-d1920d9cbfaf"
      },
      "InternetExplorerIntegrationLevel": {
         "level": "mandatory",
         "scope": "machine",
         "source": "platform",
         "value": 1
      },
      "InternetExplorerIntegrationSiteList": {
         "level": "mandatory",
         "scope": "machine",
         "source": "platform",
         "value": ""
      },
      "SleepingTabsBlockedForUrls": {
         "level": "recommended",
         "scope": "user",
         "source": "platform",
         "value": [ "[*.]microsoft.com", "[*.]office.com", "[*.]microsoftonline.com", "[*.]outlook.com" ]
      },
      "SleepingTabsEnabled": {
         "level": "recommended",
         "scope": "user",
         "source": "platform",
         "value": true
      },
      "SleepingTabsTimeout": {
         "level": "recommended",
         "scope": "user",
         "source": "platform",
         "value": 1800
      },
      "SmartScreenEnabled": {
         "level": "mandatory",
         "scope": "machine",
         "source": "platform",
         "value": true
      },
      "SmartScreenForTrustedDownloadsEnabled": {
         "level": "mandatory",
         "scope": "machine",
         "source": "platform",
         "value": false
      },
      "SmartScreenPuaEnabled": {
         "level": "mandatory",
         "scope": "machine",
         "source": "platform",
         "value": true
      },
      "StartupBoostEnabled": {
         "level": "recommended",
         "scope": "user",
         "source": "platform",
         "value": true
      }
   },
   "extensionPolicies": {
   },
   "status": {
      "updater": {
         "policyDescriptionKey": "statusUpdater",
         "timeSinceLastRefresh": "8 hours ago",
         "version": "1.3.173.53"
      },
      "user": {
      }
   }
}

Things tried

Other browsers are working fine.

yury-s commented 1 year ago

Looks like it is caused by one of the policies that you have on your machine, InternetExplorerIntegrationCloudSiteList looks most relevant to the error message you get in the logs. Can you try launching the browser without playwright and see if you get the same error?

Something like this:

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-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 --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=new_profile_dir

See also this page, there is not much we can do if the browser cannot start in incognito mode with the system policies.

priyanshu92 commented 1 year ago

Can you try launching the browser without playwright and see if you get the same error?

I don't see the error but getting the below popup

image

yury-s commented 1 year ago

So this is likely BrowserSignin policy which prevents Playwright from launching the browser without signing in. Try changing the value (contact your admin?) to remove the requirement on the machine where you want to run the tests, playwright cannot override such policy settings.

thirupathireddy-rs commented 1 year ago

So this is likely BrowserSignin policy which prevents Playwright from launching the browser without signing in. Try changing the value (contact your admin?) to remove the requirement on the machine where you want to run the tests, playwright cannot override such policy settings.

Can you suggest what exact value we need to change...!?

bc3tech commented 4 months ago

JFYI quick thing you can do is put some code in place that changes HKEY_CURRENT_USER\Software\Policies\Microsoft\Edge\BrowserSignin to 1 if it is currently set to 2

I, personally, wrapped this in a #if DEBUG statement and a try/catch{} so it won't except out.